diff --git a/src/DiIiS-NA/BGS-Server/AccountsSystem/Account.cs b/src/DiIiS-NA/BGS-Server/AccountsSystem/Account.cs index b77d441..a86e689 100644 --- a/src/DiIiS-NA/BGS-Server/AccountsSystem/Account.cs +++ b/src/DiIiS-NA/BGS-Server/AccountsSystem/Account.cs @@ -1,5 +1,4 @@ -//Blizzless Project 2022 -using DiIiS_NA.LoginServer.Objects; +using DiIiS_NA.LoginServer.Objects; using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DiIiS-NA/BGS-Server/AccountsSystem/AccountManager.cs b/src/DiIiS-NA/BGS-Server/AccountsSystem/AccountManager.cs index 575406e..3b871ae 100644 --- a/src/DiIiS-NA/BGS-Server/AccountsSystem/AccountManager.cs +++ b/src/DiIiS-NA/BGS-Server/AccountsSystem/AccountManager.cs @@ -1,5 +1,4 @@ -//Blizzless Project 2022 -using DiIiS_NA.Core.Extensions; +using DiIiS_NA.Core.Extensions; using DiIiS_NA.Core.Logging; using DiIiS_NA.Core.Storage; using DiIiS_NA.Core.Storage.AccountDataBase.Entities; @@ -90,7 +89,7 @@ namespace DiIiS_NA.LoginServer.AccountsSystem Logger.Warn("GetAccountByDiscordId {0}: DBAccount is null!", discordId); return null; } - return GetAccountByDBAccount(dbAcc.First()); + return GetDatabaseAccountByPersistentID(dbAcc.First()); } public static bool GenerateReferralCode(string email) @@ -143,7 +142,7 @@ namespace DiIiS_NA.LoginServer.AccountsSystem } Logger.MethodTrace($"id - {dbAcc.First().Id}"); - return GetAccountByDBAccount(dbAcc.First()); + return GetDatabaseAccountByPersistentID(dbAcc.First()); } } @@ -172,7 +171,7 @@ namespace DiIiS_NA.LoginServer.AccountsSystem } //else //Logger.Debug("GetAccountByBattletag \"{0}\"", battletag); - return GetAccountByDBAccount(dbAcc.First()); + return GetDatabaseAccountByPersistentID(dbAcc.First()); } public static Account GetAccountByName(string btname) //pretty bad to use it @@ -183,7 +182,7 @@ namespace DiIiS_NA.LoginServer.AccountsSystem Logger.Warn("$[olive]$GetAccountByName(\"{0}\")$[/]$: DBAccount is null!", btname); return null; } - return GetAccountByDBAccount(dbAcc.First()); + return GetDatabaseAccountByPersistentID(dbAcc.First()); } public static Account GetAccountByPersistentID(ulong persistentId) @@ -192,11 +191,11 @@ namespace DiIiS_NA.LoginServer.AccountsSystem return LoadedAccounts[persistentId]; else { - return GetAccountByDBAccount(DBSessions.SessionGet(persistentId)); + return GetDatabaseAccountByPersistentID(DBSessions.SessionGet(persistentId)); } } - public static Account GetAccountByDBAccount(DBAccount dbAccount) + public static Account GetDatabaseAccountByPersistentID(DBAccount dbAccount) { if (dbAccount == null) return null; diff --git a/src/DiIiS-NA/BGS-Server/AccountsSystem/GameAccount.cs b/src/DiIiS-NA/BGS-Server/AccountsSystem/GameAccount.cs index 034440b..8e9a86e 100644 --- a/src/DiIiS-NA/BGS-Server/AccountsSystem/GameAccount.cs +++ b/src/DiIiS-NA/BGS-Server/AccountsSystem/GameAccount.cs @@ -1,57 +1,51 @@ -//Blizzless Project 2022 -//Blizzless Project 2022 - -using System; -//Blizzless Project 2022 +using System; using System.Collections.Generic; -//Blizzless Project 2022 +using System.Collections.Immutable; using System.Linq; -//Blizzless Project 2022 +using System.Reflection; +using System.Reflection.Emit; +using System.Runtime.CompilerServices; using bgs.protocol.presence.v1; -//Blizzless Project 2022 using D3.Account; -//Blizzless Project 2022 using D3.Achievements; -//Blizzless Project 2022 using D3.Client; -//Blizzless Project 2022 using D3.OnlineService; -//Blizzless Project 2022 using D3.PartyMessage; -//Blizzless Project 2022 using D3.Profile; -//Blizzless Project 2022 using DiIiS_NA.Core.Extensions; -//Blizzless Project 2022 using DiIiS_NA.Core.Storage; -//Blizzless Project 2022 using DiIiS_NA.Core.Storage.AccountDataBase.Entities; -//Blizzless Project 2022 using DiIiS_NA.LoginServer.Base; -//Blizzless Project 2022 using DiIiS_NA.LoginServer.Battle; -//Blizzless Project 2022 using DiIiS_NA.LoginServer.ChannelSystem; -//Blizzless Project 2022 using DiIiS_NA.LoginServer.GuildSystem; -//Blizzless Project 2022 using DiIiS_NA.LoginServer.Helpers; -//Blizzless Project 2022 using DiIiS_NA.LoginServer.Objects; -//Blizzless Project 2022 using DiIiS_NA.LoginServer.Toons; -//Blizzless Project 2022 using Google.ProtocolBuffers; +using NHibernate.Mapping; namespace DiIiS_NA.LoginServer.AccountsSystem; public class GameAccount : PersistentRPCObject { + TSource GetField(Func execute) => DBSessions.GetField(PersistentID, execute); + + void SetField(Action execute, [CallerMemberName] string methodName = "") + { + DBSessions.SetField(PersistentID, execute); + #if DEBUG + if (methodName.StartsWith("set_")) + methodName = methodName.Substring(4); + Logger.MethodTrace($"Updated SQL fields for {PersistentID}", methodName); + #endif + } + private Account _owner; public Account Owner { - get => _owner ?? (_owner = AccountManager.GetAccountByPersistentID(AccountId)); + get => _owner ??= AccountManager.GetAccountByPersistentID(AccountId); set { lock (DBGameAccount) @@ -220,9 +214,7 @@ public class GameAccount : PersistentRPCObject lock (DBGameAccount) { - var dbGAcc = DBGameAccount; - dbGAcc.Banner = res.Build().ToByteArray(); - DBSessions.SessionUpdate(dbGAcc); + SetField(x=>x.Banner = res.Build().ToByteArray()); } } else @@ -238,9 +230,7 @@ public class GameAccount : PersistentRPCObject _bannerConfiguration = value; lock (DBGameAccount) { - var dbGAcc = DBGameAccount; - dbGAcc.Banner = value.ToByteArray(); - DBSessions.SessionUpdate(dbGAcc); + SetField(x=>x.Banner = value.ToByteArray()); } ChangedFields.SetPresenceFieldValue(BannerConfigurationField); @@ -281,9 +271,7 @@ public class GameAccount : PersistentRPCObject _currentToonId = value.PersistentID; lock (DBGameAccount) { - var dbGAcc = DBGameAccount; - dbGAcc.LastPlayedHero = value.DBToon; - DBSessions.SessionUpdate(dbGAcc); + SetField(x=>x.LastPlayedHero = value.DBToon); } ChangedFields.SetPresenceFieldValue(LastPlayedHeroIdField); @@ -302,39 +290,36 @@ public class GameAccount : PersistentRPCObject public ulong Gold { - get - { - if (CurrentToon.IsHardcore) return DBGameAccount.HardcoreGold; - - return DBGameAccount.Gold; - } + get => CurrentToon.IsHardcore ? GetField(s => s.HardcoreGold) : GetField(s => s.Gold); set { lock (DBGameAccount) { - if (CurrentToon.IsHardcore) - DBGameAccount.HardcoreGold = value; - else - DBGameAccount.Gold = value; - - DBSessions.SessionUpdate(DBGameAccount); + SetField(update => + { + if (CurrentToon.IsHardcore) + update.HardcoreGold = value; + else + update.Gold = value; + }); } } } public int BloodShards { - get => CurrentToon.IsHardcore ? DBGameAccount.HardcoreBloodShards : DBGameAccount.BloodShards; + get => CurrentToon.IsHardcore ? GetField(x=>x.HardcoreBloodShards) : GetField(x=>x.BloodShards); set { lock (DBGameAccount) { - if (CurrentToon.IsHardcore) - DBGameAccount.HardcoreBloodShards = value; - else - DBGameAccount.BloodShards = value; - - DBSessions.SessionUpdate(DBGameAccount); + SetField(update => + { + if (CurrentToon.IsHardcore) + update.HardcoreBloodShards = value; + else + update.BloodShards = value; + }); } } } @@ -343,55 +328,57 @@ public class GameAccount : PersistentRPCObject { get { - if (CurrentToon.IsHardcore) return DBGameAccount.HardTotalBloodShards; - - return DBGameAccount.TotalBloodShards; + return CurrentToon.IsHardcore ? GetField(x=>x.HardTotalBloodShards) : GetField(x=>x.TotalBloodShards); } set { lock (DBGameAccount) { - if (CurrentToon.IsHardcore) - DBGameAccount.HardTotalBloodShards = value; - else - DBGameAccount.TotalBloodShards = value; - DBSessions.SessionUpdate(DBGameAccount); + SetField(update => + { + if (CurrentToon.IsHardcore) + update.HardTotalBloodShards = value; + else + update.TotalBloodShards = value; + }); } } } public int StashSize { - get => CurrentToon.IsHardcore ? DBGameAccount.HardcoreStashSize : DBGameAccount.StashSize; + get => CurrentToon.IsHardcore ? GetField(x=>x.HardcoreStashSize) : GetField(x=>x.StashSize); set { lock (DBGameAccount) { - if (CurrentToon.IsHardcore) - DBGameAccount.HardcoreStashSize = value; - else - DBGameAccount.StashSize = value; - DBSessions.SessionUpdate(DBGameAccount); + SetField(update => + { + if (CurrentToon.IsHardcore) + update.HardcoreStashSize = value; + else + update.StashSize = value; + }); } } } - public int SeasonStashSize { - get => CurrentToon.IsHardcore ? DBGameAccount.HardSeasonStashSize : DBGameAccount.SeasonStashSize; + get => CurrentToon.IsHardcore ? GetField(x=>x.HardSeasonStashSize) : GetField(x=>x.SeasonStashSize); set { lock (DBGameAccount) { - if (CurrentToon.IsHardcore) - DBGameAccount.HardSeasonStashSize = value; - else - DBGameAccount.SeasonStashSize = value; - DBSessions.SessionUpdate(DBGameAccount); + SetField(update => + { + if (CurrentToon.IsHardcore) + update.HardSeasonStashSize = value; + else + update.SeasonStashSize = value; + }); } } } - public ulong PvPTotalKilled { get => CurrentToon.IsHardcore ? DBGameAccount.HardPvPTotalKilled : DBGameAccount.PvPTotalKilled; @@ -403,11 +390,9 @@ public class GameAccount : PersistentRPCObject DBGameAccount.HardPvPTotalKilled = value; else DBGameAccount.PvPTotalKilled = value; - DBSessions.SessionUpdate(DBGameAccount); } } } - public ulong PvPTotalWins { get => CurrentToon.IsHardcore ? DBGameAccount.HardPvPTotalWins : DBGameAccount.PvPTotalWins; @@ -419,11 +404,9 @@ public class GameAccount : PersistentRPCObject DBGameAccount.HardPvPTotalWins = value; else DBGameAccount.PvPTotalWins = value; - DBSessions.SessionUpdate(DBGameAccount); } } } - public ulong PvPTotalGold { get @@ -440,335 +423,284 @@ public class GameAccount : PersistentRPCObject DBGameAccount.HardPvPTotalGold = value; else DBGameAccount.PvPTotalGold = value; - DBSessions.SessionUpdate(DBGameAccount); } } } - public int CraftItem1 { - get - { - if (CurrentToon.IsHardcore) return DBGameAccount.HardCraftItem1; - - return DBGameAccount.CraftItem1; - } + get => CurrentToon.IsHardcore ? GetField(x=>x.HardCraftItem1) : GetField(x=>x.CraftItem1); set { lock (DBGameAccount) { - if (CurrentToon.IsHardcore) - DBGameAccount.HardCraftItem1 = value; - else - DBGameAccount.CraftItem1 = value; - DBSessions.SessionUpdate(DBGameAccount); + SetField(update => + { + if (CurrentToon.IsHardcore) + update.HardCraftItem1 = value; + else + update.CraftItem1 = value; + }); } } } public int CraftItem2 { - get - { - if (CurrentToon.IsHardcore) return DBGameAccount.HardCraftItem2; - - return DBGameAccount.CraftItem2; - } + get => CurrentToon.IsHardcore ? GetField(x=>x.HardCraftItem2) : GetField(x=>x.CraftItem2); set { lock (DBGameAccount) { - if (CurrentToon.IsHardcore) - DBGameAccount.HardCraftItem2 = value; - else - DBGameAccount.CraftItem2 = value; - DBSessions.SessionUpdate(DBGameAccount); + SetField(update => + { + if (CurrentToon.IsHardcore) + update.HardCraftItem2 = value; + else + update.CraftItem2 = value; + }); } } } public int CraftItem3 { - get - { - if (CurrentToon.IsHardcore) return DBGameAccount.HardCraftItem3; - - return DBGameAccount.CraftItem3; - } + get => CurrentToon.IsHardcore ? GetField(x=>x.HardCraftItem3) : GetField(x=>x.CraftItem3); set { lock (DBGameAccount) { - if (CurrentToon.IsHardcore) - DBGameAccount.HardCraftItem3 = value; - else - DBGameAccount.CraftItem3 = value; - DBSessions.SessionUpdate(DBGameAccount); + SetField(update => + { + if (CurrentToon.IsHardcore) + update.HardCraftItem3 = value; + else + update.CraftItem3 = value; + }); } } } public int CraftItem4 { - get - { - if (CurrentToon.IsHardcore) return DBGameAccount.HardCraftItem4; - - return DBGameAccount.CraftItem4; - } + get => CurrentToon.IsHardcore ? GetField(x=>x.HardCraftItem4) : GetField(x=>x.CraftItem4); set { lock (DBGameAccount) { - if (CurrentToon.IsHardcore) - DBGameAccount.HardCraftItem4 = value; - else - DBGameAccount.CraftItem4 = value; - DBSessions.SessionUpdate(DBGameAccount); + SetField(update => + { + if (CurrentToon.IsHardcore) + update.HardCraftItem4 = value; + else + update.CraftItem4 = value; + }); } } } - + public int CraftItem5 { - get - { - if (CurrentToon.IsHardcore) return DBGameAccount.HardCraftItem5; - - return DBGameAccount.CraftItem5; - } + get => CurrentToon.IsHardcore ? GetField(x=>x.HardCraftItem5) : GetField(x=>x.CraftItem5); set { lock (DBGameAccount) { - if (CurrentToon.IsHardcore) - DBGameAccount.HardCraftItem5 = value; - else - DBGameAccount.CraftItem5 = value; - DBSessions.SessionUpdate(DBGameAccount); + SetField(update => + { + if (CurrentToon.IsHardcore) + update.HardCraftItem5 = value; + else + update.CraftItem5 = value; + }); } } } public int BigPortalKey { - get - { - if (CurrentToon.IsHardcore) return DBGameAccount.HardBigPortalKey; - - return DBGameAccount.BigPortalKey; - } + get => CurrentToon.IsHardcore ? GetField(x=>x.HardBigPortalKey) : GetField(x=>x.BigPortalKey); set { lock (DBGameAccount) { - if (CurrentToon.IsHardcore) - DBGameAccount.HardBigPortalKey = value; - else - DBGameAccount.BigPortalKey = value; - DBSessions.SessionUpdate(DBGameAccount); + SetField(update => + { + if (CurrentToon.IsHardcore) + update.HardBigPortalKey = value; + else + update.BigPortalKey = value; + }); } } } - + public int LeorikKey { - get - { - if (CurrentToon.IsHardcore) return DBGameAccount.HardLeorikKey; - - return DBGameAccount.LeorikKey; - } + get => CurrentToon.IsHardcore ? GetField(x=>x.HardLeorikKey) : GetField(x=>x.LeorikKey); set { lock (DBGameAccount) { - if (CurrentToon.IsHardcore) - DBGameAccount.HardLeorikKey = value; - else - DBGameAccount.LeorikKey = value; - DBSessions.SessionUpdate(DBGameAccount); + SetField(update => + { + if (CurrentToon.IsHardcore) + update.HardLeorikKey = value; + else + update.LeorikKey = value; + }); } } } - + public int VialofPutridness { - get - { - if (CurrentToon.IsHardcore) return DBGameAccount.HardVialofPutridness; - - return DBGameAccount.VialofPutridness; - } + get => CurrentToon.IsHardcore ? GetField(x=>x.HardVialofPutridness) : GetField(x=>x.VialofPutridness); set { lock (DBGameAccount) { - if (CurrentToon.IsHardcore) - DBGameAccount.HardVialofPutridness = value; - else - DBGameAccount.VialofPutridness = value; - DBSessions.SessionUpdate(DBGameAccount); + SetField(update => + { + if (CurrentToon.IsHardcore) + update.HardVialofPutridness = value; + else + update.VialofPutridness = value; + }); } } } - + public int IdolofTerror { - get - { - if (CurrentToon.IsHardcore) return DBGameAccount.HardIdolofTerror; - - return DBGameAccount.IdolofTerror; - } + get => CurrentToon.IsHardcore ? GetField(x=>x.HardIdolofTerror) : GetField(x=>x.IdolofTerror); set { lock (DBGameAccount) { - if (CurrentToon.IsHardcore) - DBGameAccount.HardIdolofTerror = value; - else - DBGameAccount.IdolofTerror = value; - DBSessions.SessionUpdate(DBGameAccount); + SetField(update => + { + if (CurrentToon.IsHardcore) + update.HardIdolofTerror = value; + else + update.IdolofTerror = value; + }); } } } - + public int HeartofFright { - get - { - if (CurrentToon.IsHardcore) return DBGameAccount.HardHeartofFright; - - return DBGameAccount.HeartofFright; - } + get => CurrentToon.IsHardcore ? GetField(x=>x.HardHeartofFright) : GetField(x=>x.HeartofFright); set { lock (DBGameAccount) { - if (CurrentToon.IsHardcore) - DBGameAccount.HardHeartofFright = value; - else - DBGameAccount.HeartofFright = value; - DBSessions.SessionUpdate(DBGameAccount); + SetField(update => + { + if (CurrentToon.IsHardcore) + update.HardHeartofFright = value; + else + update.HeartofFright = value; + }); } } } - + public int HoradricA1Res { - get - { - if (CurrentToon.IsHardcore) return DBGameAccount.HardHoradricA1; - - return DBGameAccount.HoradricA1; - } + get => CurrentToon.IsHardcore ? GetField(x=>x.HardHoradricA1) : GetField(x=>x.HoradricA1); set { lock (DBGameAccount) { - if (CurrentToon.IsHardcore) - DBGameAccount.HardHoradricA1 = value; - else - DBGameAccount.HoradricA1 = value; - DBSessions.SessionUpdate(DBGameAccount); + SetField(update => + { + if (CurrentToon.IsHardcore) + update.HardHoradricA1 = value; + else + update.HoradricA1 = value; + }); } } } - + public int HoradricA2Res { - get - { - if (CurrentToon.IsHardcore) return DBGameAccount.HardHoradricA2; - - return DBGameAccount.HoradricA2; - } + get => CurrentToon.IsHardcore ? GetField(x=>x.HardHoradricA2) : GetField(x=>x.HoradricA2); set { lock (DBGameAccount) { - if (CurrentToon.IsHardcore) - DBGameAccount.HardHoradricA2 = value; - else - DBGameAccount.HoradricA2 = value; - DBSessions.SessionUpdate(DBGameAccount); + SetField(update => + { + if (CurrentToon.IsHardcore) + update.HardHoradricA2 = value; + else + update.HoradricA2 = value; + }); } } } - + public int HoradricA3Res { - get - { - if (CurrentToon.IsHardcore) return DBGameAccount.HardHoradricA3; - - return DBGameAccount.HoradricA3; - } + get => CurrentToon.IsHardcore ? GetField(x=>x.HardHoradricA3) : GetField(x=>x.HoradricA3); set { lock (DBGameAccount) { - if (CurrentToon.IsHardcore) - DBGameAccount.HardHoradricA3 = value; - else - DBGameAccount.HoradricA3 = value; - DBSessions.SessionUpdate(DBGameAccount); + SetField(update => + { + if (CurrentToon.IsHardcore) + update.HardHoradricA3 = value; + else + update.HoradricA3 = value; + }); } } } - + public int HoradricA4Res { - get - { - if (CurrentToon.IsHardcore) return DBGameAccount.HardHoradricA4; - - return DBGameAccount.HoradricA4; - } + get => CurrentToon.IsHardcore ? GetField(x=>x.HardHoradricA4) : GetField(x=>x.HoradricA4); set { lock (DBGameAccount) { - if (CurrentToon.IsHardcore) - DBGameAccount.HardHoradricA4 = value; - else - DBGameAccount.HoradricA4 = value; - DBSessions.SessionUpdate(DBGameAccount); + SetField(update => + { + if (CurrentToon.IsHardcore) + update.HardHoradricA4 = value; + else + update.HoradricA4 = value; + }); } } } - + public int HoradricA5Res { - get - { - if (CurrentToon.IsHardcore) return DBGameAccount.HardHoradricA5; - - return DBGameAccount.HoradricA5; - } + get => CurrentToon.IsHardcore ? GetField(x=>x.HardHoradricA5) : GetField(x=>x.HoradricA5); set { lock (DBGameAccount) { - if (CurrentToon.IsHardcore) - DBGameAccount.HardHoradricA5 = value; - else - DBGameAccount.HoradricA5 = value; - DBSessions.SessionUpdate(DBGameAccount); + SetField(update => + { + if (CurrentToon.IsHardcore) + update.HardHoradricA5 = value; + else + update.HoradricA5 = value; + }); } } } + + - public Guild Clan - { - get { return GuildManager.GetClans().Where(g => g.HasMember(this)).FirstOrDefault(); } - } + public Guild Clan => GuildManager.GetClans().FirstOrDefault(g => g.HasMember(this)); - public List Communities - { - get { return GuildManager.GetCommunities().Where(g => g.HasMember(this)).ToList(); } - } + public ImmutableArray Communities => GuildManager.GetCommunities().Where(g => g.HasMember(this)).ToImmutableArray(); public List GuildInvites = new(); @@ -788,9 +720,7 @@ public class GameAccount : PersistentRPCObject lock (DBGameAccount) { - var dbGAcc = DBGameAccount; - dbGAcc.UISettings = res.ToByteArray(); - DBSessions.SessionUpdate(dbGAcc); + SetField(x => x.UISettings = res.ToByteArray()); } } else @@ -804,9 +734,7 @@ public class GameAccount : PersistentRPCObject { lock (DBGameAccount) { - var dbGAcc = DBGameAccount; - dbGAcc.UISettings = value.ToByteArray(); - DBSessions.SessionUpdate(dbGAcc); + SetField(x => x.UISettings = value.ToByteArray()); } ChangedFields.SetPresenceFieldValue(BannerConfigurationField); @@ -830,9 +758,7 @@ public class GameAccount : PersistentRPCObject lock (DBGameAccount) { - var dbGAcc = DBGameAccount; - dbGAcc.UIPrefs = res.ToByteArray(); - DBSessions.SessionUpdate(dbGAcc); + SetField(x => x.UIPrefs = res.ToByteArray()); } } else @@ -846,9 +772,7 @@ public class GameAccount : PersistentRPCObject { lock (DBGameAccount) { - var dbGAcc = DBGameAccount; - dbGAcc.UIPrefs = value.ToByteArray(); - DBSessions.SessionUpdate(dbGAcc); + SetField(x => x.UIPrefs = value.ToByteArray()); } ChangedFields.SetPresenceFieldValue(BannerConfigurationField); @@ -1018,26 +942,46 @@ public class GameAccount : PersistentRPCObject EntityId.CreateBuilder().SetIdHigh(0).SetIdLow(0).Build(); //Platinum + // public int Platinum + // { + // get + // { + // if (CurrentToon.IsHardcore) return DBGameAccount.HardPlatinum; + // + // return DBGameAccount.Platinum; + // } + // set + // { + // lock (DBGameAccount) + // { + // if (CurrentToon.IsHardcore) + // DBGameAccount.HardPlatinum = value; + // else + // DBGameAccount.Platinum = value; + // DBSessions.SessionUpdate(DBGameAccount); + // } + // } + // } + // new version with GetField and SetField: public int Platinum { get { - if (CurrentToon.IsHardcore) return DBGameAccount.HardPlatinum; - - return DBGameAccount.Platinum; + if (CurrentToon.IsHardcore) return GetField(x=>x.Platinum); + return GetField(x=>x.Platinum); } set { lock (DBGameAccount) { if (CurrentToon.IsHardcore) - DBGameAccount.HardPlatinum = value; + SetField(x => x.HardPlatinum = value); else - DBGameAccount.Platinum = value; - DBSessions.SessionUpdate(DBGameAccount); + SetField(x => x.HardPlatinum = value); } } } + public List Toons => ToonManager.GetToonsForGameAccount(this); @@ -1161,9 +1105,7 @@ public class GameAccount : PersistentRPCObject { lock (DBGameAccount) { - var dbGAcc = DBGameAccount; - dbGAcc.Flags = (int)value; - DBSessions.SessionUpdate(dbGAcc); + SetField(x => x.Flags = (int)value); } } } diff --git a/src/DiIiS-NA/BGS-Server/AccountsSystem/GameAccountManager.cs b/src/DiIiS-NA/BGS-Server/AccountsSystem/GameAccountManager.cs index 431cc44..4b6915b 100644 --- a/src/DiIiS-NA/BGS-Server/AccountsSystem/GameAccountManager.cs +++ b/src/DiIiS-NA/BGS-Server/AccountsSystem/GameAccountManager.cs @@ -1,6 +1,4 @@ -//Blizzless Project 2022 - -using System; +using System; using DiIiS_NA.Core.Logging; using DiIiS_NA.Core.Storage; using DiIiS_NA.Core.Storage.AccountDataBase.Entities; diff --git a/src/DiIiS-NA/BGS-Server/ServicesSystem/Services/ChannelService.cs b/src/DiIiS-NA/BGS-Server/ServicesSystem/Services/ChannelService.cs index 3705a24..4793b10 100644 --- a/src/DiIiS-NA/BGS-Server/ServicesSystem/Services/ChannelService.cs +++ b/src/DiIiS-NA/BGS-Server/ServicesSystem/Services/ChannelService.cs @@ -78,7 +78,7 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services //*/ Channel channel = ChannelManager.GetChannelByDynamicId((((HandlerController) controller).LastCallHeader).ObjectId); - Logger.MethodTrace(request.ToString()); + Logger.Debug($"Agent ID: {(request.HasAgentId ? request.AgentId.ToString() : "N/A")}, gas state change: {(request.HasStateChange ? request.StateChange.ToString() : "N/A")}"); foreach (bgs.protocol.Attribute attribute in request.StateChange.AttributeList) { @@ -87,7 +87,7 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services if (attribute.HasValue && !attribute.Value.MessageValue.IsEmpty) //Sometimes not present -Egris { var gameCreateParams = D3.OnlineService.GameCreateParams.ParseFrom(attribute.Value.MessageValue); - Logger.Debug("D3.Party.GameCreateParams: {0}", gameCreateParams.ToString()); + Logger.Debug("$[underline]$D3.Party.GameCreateParams:$[/]$ {0}", gameCreateParams.ToString()); //D3.OnlineService.EntityId hero = gameCreateParams.Coop.ResumeFromSaveHeroId; bool clear_quests = (((HandlerController) controller).Client.GameChannel != null && gameCreateParams.CampaignOrAdventureMode.QuestStepId == -1 && (gameCreateParams.CampaignOrAdventureMode.SnoQuest == 87700 || @@ -177,7 +177,7 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services { // TODO: Find a game that fits the clients params and join /raist. var publicGameParams = D3.PartyMessage.SearchForPublicGameParams.ParseFrom(attribute.Value.MessageValue); - Logger.Debug("SearchForPublicGameParams: {0}", publicGameParams.ToString()); + Logger.Debug("$[underline]$SearchForPublicGameParams:$[/]$ {0}", publicGameParams.ToString()); var attr = bgs.protocol.Attribute.CreateBuilder() .SetName("D3.Party.SearchForPublicGame.Params") .SetValue(bgs.protocol.Variant.CreateBuilder().SetMessageValue(publicGameParams.ToByteString()).Build()); @@ -193,7 +193,7 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services .SetValue(bgs.protocol.Variant.CreateBuilder()); channel.AddAttribute(attr.Build()); - Logger.Debug("D3.Party.ScreenStatus = null"); + Logger.Debug("$[underline]$D3.Party.ScreenStatus$[/]$ is null"); } else { @@ -220,7 +220,7 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services .SetValue(joinPermission); channel.AddAttribute(attr.Build()); - Logger.Debug("D3.Party.JoinPermissionPreviousToLock = {0}", joinPermission.IntValue); + Logger.Debug("$[underline]$D3.Party.JoinPermissionPreviousToLock$[/]$ = {0}", joinPermission.IntValue); } else if (attribute.Name == "D3.Party.JoinPermissionPreviousToClose") { @@ -233,7 +233,7 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services .SetValue(joinPermission); channel.AddAttribute(attr.Build()); - Logger.Debug("D3.Party.JoinPermissionPreviousToClose = {0}", joinPermission.IntValue); + Logger.Debug("$[underline]$D3.Party.JoinPermissionPreviousToClose$[/]$ = {0}", joinPermission.IntValue); } else if (attribute.Name == "D3.Party.LockReasons") { @@ -246,7 +246,7 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services .SetValue(lockReason); channel.AddAttribute(attr.Build()); - Logger.Debug("D3.Party.LockReasons = {0}", lockReason.IntValue); + Logger.Debug("$[underline]$D3.Party.LockReasons$[/]$ = {0}", lockReason.IntValue); } else if (attribute.Name == "D3.Party.GameId") { @@ -258,10 +258,10 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services .SetValue(bgs.protocol.Variant.CreateBuilder().SetMessageValue(gameId.ToByteString()).Build()); channel.AddAttribute(attr.Build()); - Logger.Debug("D3.Party.GameId = {0}", gameId.GameInstanceId); + Logger.Debug("$[underline]$D3.Party.GameId$[/]$ = {0}", gameId.GameInstanceId); } else - Logger.Debug("D3.Party.GameId = null"); + Logger.Debug("$[underline]$D3.Party.GameId$[/]$ is null"); } else if (attribute.Name == "D3.Party.EnterGame.Members") @@ -274,10 +274,10 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services .SetValue(bgs.protocol.Variant.CreateBuilder().SetMessageValue(members.ToByteString()).Build()); channel.AddAttribute(attr.Build()); - Logger.Debug("D3.Party.EnterGame.Members = {0}", members.ToString()); + Logger.Debug("$[underline]$D3.Party.EnterGame.Members$[/]$ = {0}", members.ToString()); } else - Logger.Debug("D3.Party.EnterGame.Members = null"); + Logger.Debug("$[underline]$D3.Party.EnterGame.Members$[/]$ is null"); } else if (attribute.Name == "D3.Party.JoinPermission") @@ -290,10 +290,10 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services .SetValue(bgs.protocol.Variant.CreateBuilder().SetMessageValue(permission.ToByteString()).Build()); channel.AddAttribute(attr.Build()); - Logger.Debug("D3.Party.JoinPermission = {0}", permission.ToString()); + Logger.Debug("$[underline]$D3.Party.JoinPermission$[/]$ = {0}", permission.ToString()); } else - Logger.Debug("D3.Party.JoinPermission = null"); + Logger.Debug("$[underline]$D3.Party.JoinPermission$[/]$ is null"); } else if (attribute.Name == "D3.Party.EnterGame.Leader.AtQueueStart") @@ -306,10 +306,10 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services .SetValue(bgs.protocol.Variant.CreateBuilder().SetMessageValue(queueStart.ToByteString()).Build()); channel.AddAttribute(attr.Build()); - Logger.Debug("D3.Party.EnterGame.Leader.AtQueueStart = {0}", queueStart.ToString()); + Logger.Debug("$[underline]$D3.Party.EnterGame.Leader.AtQueueStart$[/]$ = {0}", queueStart.ToString()); } else - Logger.Debug("D3.Party.EnterGame.Leader.AtQueueStart = null"); + Logger.Debug("$[underline]$D3.Party.EnterGame.Leader.AtQueueStart$[/]$ = null"); } else @@ -368,11 +368,11 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services .SetName("D3.PartyMember.GameId") .SetValue(bgs.protocol.Variant.CreateBuilder().SetMessageValue(gameId.ToByteString()).Build()); state.AddAttribute(attr); - Logger.Trace("D3.PartyMember.GameId = {0}", gameId.GameInstanceId); + Logger.Debug("$[underline]$D3.PartyMember.GameId$[/]$ = {0}", gameId.GameInstanceId); } else { - Logger.Trace("D3.PartyMember.GameId = null"); + Logger.Debug("$[underline]$D3.PartyMember.GameId$[/]$ is null"); channel.RemoveMember(((HandlerController) controller).Client, Channel.GetRemoveReasonForRequest((Channel.RemoveRequestReason)2)); } } diff --git a/src/DiIiS-NA/BGS-Server/ServicesSystem/Services/GameUtilitiesService.cs b/src/DiIiS-NA/BGS-Server/ServicesSystem/Services/GameUtilitiesService.cs index 3e16de2..f179b1a 100644 --- a/src/DiIiS-NA/BGS-Server/ServicesSystem/Services/GameUtilitiesService.cs +++ b/src/DiIiS-NA/BGS-Server/ServicesSystem/Services/GameUtilitiesService.cs @@ -102,7 +102,7 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services Init.SetMatchmakingPool("Default"); var guildInfo = D3.Guild.GuildInfoList.CreateBuilder(); - if (Client.Account.GameAccount.Clan != null || Client.Account.GameAccount.Communities.Count > 0) + if (Client.Account.GameAccount.Clan != null || Client.Account.GameAccount.Communities.Length > 0) { //* if (Client.Account.GameAccount.Clan != null) diff --git a/src/DiIiS-NA/Core/Logging/AnsiTarget.cs b/src/DiIiS-NA/Core/Logging/AnsiTarget.cs index 192e7ac..4cf51ac 100644 --- a/src/DiIiS-NA/Core/Logging/AnsiTarget.cs +++ b/src/DiIiS-NA/Core/Logging/AnsiTarget.cs @@ -73,13 +73,29 @@ public class AnsiTarget : LogTarget /// Replaced with color changes public static string Beautify(string text) { + const string blizz = "dodgerblue1"; + const string less = "deepskyblue2"; + const string diablo = "red3_1"; + const string d3 = "red"; + const string mpq = "underline deepskyblue2"; + const string sql = "underline dodgerblue1"; + const string discord = "underline blue"; + const string notNull = "green"; + const string @null = "underline red"; + const string unkNull = "underline yellow"; return text - .Replace("Blizzless", "[dodgerblue1]Blizz[/][deepskyblue2]less[/]", StringComparison.CurrentCultureIgnoreCase) - .Replace("Diablo III", "[red3_1]Diablo[/] [red]III[/]", StringComparison.CurrentCultureIgnoreCase) - .Replace("MPQ", "[underline yellow4]MPQ[/]") - .Replace("Discord", "[underline blue]Discord[/]", StringComparison.CurrentCultureIgnoreCase) - .Replace("not null", "[green]is not null[/]", StringComparison.CurrentCultureIgnoreCase) - .Replace("null", "[underline red]is null[/]", StringComparison.CurrentCultureIgnoreCase); + .Replace("Blizzless", $"[{blizz}]Blizz[/][{less}]less[/]", StringComparison.CurrentCultureIgnoreCase) + .Replace("Diablo III", $"[{diablo}]Diablo[/] [{d3}]III[/]", StringComparison.CurrentCultureIgnoreCase) + .Replace(@"D3\.", $"[{diablo}]D[/][{d3}]3[/]", StringComparison.CurrentCultureIgnoreCase) //D3.* + + .Replace("MPQ", $"[{mpq}]MPQ[/]") + .Replace("SQL", $"[{sql}]SQL[/]") + .Replace("Discord", $"[{discord}]Discord[/]", StringComparison.CurrentCultureIgnoreCase) + .Replace("not null", $"[{notNull}]is not null[/]", StringComparison.CurrentCultureIgnoreCase) + .Replace("!= null", $"[{notNull}]!= null[/]", StringComparison.CurrentCultureIgnoreCase) + .Replace("is null", $"[{@null}]is null[/]", StringComparison.CurrentCultureIgnoreCase) + .Replace("= null", $"[{@null}]= null[/]", StringComparison.CurrentCultureIgnoreCase) + .Replace("null", $"[{unkNull}]null[/]", StringComparison.CurrentCultureIgnoreCase); } diff --git a/src/DiIiS-NA/Core/Logging/Logger.cs b/src/DiIiS-NA/Core/Logging/Logger.cs index c61bf34..242ea79 100644 --- a/src/DiIiS-NA/Core/Logging/Logger.cs +++ b/src/DiIiS-NA/Core/Logging/Logger.cs @@ -1,6 +1,7 @@ //Blizzless Project 2022 using System; using System.Globalization; +using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; @@ -106,7 +107,8 @@ namespace DiIiS_NA.Core.Logging public void MethodTrace(string message, [CallerMemberName] string methodName = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0) { #if DEBUG - Log(Level.MethodTrace, $"$[darkolivegreen3_2]${methodName}()$[/]$ @ {lineNumber}: " + message, null); + var fileName = Path.GetFileName(filePath); + Log(Level.MethodTrace, $"$[underline white]${fileName}:{lineNumber}$[/]$ $[darkolivegreen3_2]${methodName}()$[/]$: $[black on white]$" + message + "$[/]$", null); #else Log(Level.MethodTrace, $"$[darkolivegreen3_2]${methodName}()$[/]$: " + message, null); #endif diff --git a/src/DiIiS-NA/Core/Storage/DBSessions.cs b/src/DiIiS-NA/Core/Storage/DBSessions.cs index bae1f65..44de38d 100644 --- a/src/DiIiS-NA/Core/Storage/DBSessions.cs +++ b/src/DiIiS-NA/Core/Storage/DBSessions.cs @@ -34,26 +34,41 @@ namespace DiIiS_NA.Core.Storage { try { - using (IStatelessSession session = AccountDataBase.SessionProvider.SessionFactory.OpenStatelessSession()) - session.Insert(obj); + using IStatelessSession session = AccountDataBase.SessionProvider.SessionFactory.OpenStatelessSession(); + session.Insert(obj); } catch (Exception e) { - Logger.WarnException(e, "Unhandled DB exception caught:"); + Logger.ErrorException(e, "Unhandled DB exception caught:"); throw; } } + public static TResult GetField(object obj, Func execute) + { + using IStatelessSession session = AccountDataBase.SessionProvider.SessionFactory.OpenStatelessSession(); + var db = session.Get(obj); + return execute(db); + } + + public static void SetField(object obj, Action execute) + { + using IStatelessSession session = AccountDataBase.SessionProvider.SessionFactory.OpenStatelessSession(); + var db = session.Get(obj); + execute(db); + session.Update(db); + } + public static void SessionUpdate(Object obj) { try { - using (IStatelessSession session = AccountDataBase.SessionProvider.SessionFactory.OpenStatelessSession()) - session.Update(obj); + using IStatelessSession session = AccountDataBase.SessionProvider.SessionFactory.OpenStatelessSession(); + session.Update(obj); } catch (Exception e) { - Logger.WarnException(e, "Unhandled DB exception caught:"); + Logger.ErrorException(e, "Unhandled DB exception caught:"); throw; } } @@ -62,12 +77,12 @@ namespace DiIiS_NA.Core.Storage { try { - using (IStatelessSession session = AccountDataBase.SessionProvider.SessionFactory.OpenStatelessSession()) - session.Delete(obj); + using IStatelessSession session = AccountDataBase.SessionProvider.SessionFactory.OpenStatelessSession(); + session.Delete(obj); } catch (Exception e) { - Logger.WarnException(e, "Unhandled DB exception caught:"); + Logger.ErrorException(e, "Unhandled DB exception caught:"); throw; } } @@ -76,12 +91,12 @@ namespace DiIiS_NA.Core.Storage { try { - using (IStatelessSession session = AccountDataBase.SessionProvider.SessionFactory.OpenStatelessSession()) - return session.QueryOver().WhereRestrictionOn(expression).IsIn(list).List().ToList(); + using IStatelessSession session = AccountDataBase.SessionProvider.SessionFactory.OpenStatelessSession(); + return session.QueryOver().WhereRestrictionOn(expression).IsIn(list).List().ToList(); } catch (Exception e) { - Logger.WarnException(e, "Unhandled DB exception caught:"); + Logger.ErrorException(e, "Unhandled DB exception caught:"); throw; } } @@ -90,12 +105,12 @@ namespace DiIiS_NA.Core.Storage { try { - using (IStatelessSession session = AccountDataBase.SessionProvider.SessionFactory.OpenStatelessSession()) - return session.Query().ToList(); + using IStatelessSession session = AccountDataBase.SessionProvider.SessionFactory.OpenStatelessSession(); + return session.Query().ToList(); } catch (Exception e) { - Logger.WarnException(e, "Unhandled DB exception caught:"); + Logger.ErrorException(e, "Unhandled DB exception caught:"); throw; } } @@ -104,12 +119,12 @@ namespace DiIiS_NA.Core.Storage { try { - using (IStatelessSession session = AccountDataBase.SessionProvider.SessionFactory.OpenStatelessSession()) - return session.QueryOver().Where(predicate).List().ToList(); + using IStatelessSession session = AccountDataBase.SessionProvider.SessionFactory.OpenStatelessSession(); + return session.QueryOver().Where(predicate).List().ToList(); } catch (Exception e) { - Logger.WarnException(e, "Unhandled DB exception caught:"); + Logger.ErrorException(e, "Unhandled DB exception caught:"); throw; } } @@ -118,12 +133,12 @@ namespace DiIiS_NA.Core.Storage { try { - using (IStatelessSession session = AccountDataBase.SessionProvider.SessionFactory.OpenStatelessSession()) - return session.Query().Single(predicate); + using IStatelessSession session = AccountDataBase.SessionProvider.SessionFactory.OpenStatelessSession(); + return session.Query().Single(predicate); } catch (Exception e) { - Logger.WarnException(e, "Unhandled DB exception caught:"); + Logger.ErrorException(e, "Unhandled DB exception caught:"); throw; } } @@ -132,12 +147,12 @@ namespace DiIiS_NA.Core.Storage { try { - using (IStatelessSession session = AccountDataBase.SessionProvider.SessionFactory.OpenStatelessSession()) - return (T)session.Get(obj); + using IStatelessSession session = AccountDataBase.SessionProvider.SessionFactory.OpenStatelessSession(); + return (T)session.Get(obj); } catch (Exception e) { - Logger.WarnException(e, "Unhandled DB exception caught:"); + Logger.ErrorException(e, "Unhandled DB exception caught:"); throw; } } diff --git a/src/DiIiS-NA/Core/Storage/GameDBSession.cs b/src/DiIiS-NA/Core/Storage/GameDBSession.cs index f508fbd..6c8d1ef 100644 --- a/src/DiIiS-NA/Core/Storage/GameDBSession.cs +++ b/src/DiIiS-NA/Core/Storage/GameDBSession.cs @@ -247,14 +247,22 @@ namespace DiIiS_NA.Core.Storage } } + public void Update(object obj, Action execute) + { + using IStatelessSession session = AccountDataBase.SessionProvider.SessionFactory.OpenStatelessSession(); + var db = session.Get(obj); + execute(db); + session.Update(db); + } + public T SessionGet(Object obj) { if (typeof(T) == typeof(DBAchievements)) { try { - using (IStatelessSession session = AccountDataBase.SessionProvider.SessionFactory.OpenStatelessSession()) - return (T)session.Get(obj); + using IStatelessSession session = AccountDataBase.SessionProvider.SessionFactory.OpenStatelessSession(); + return session.Get(obj); } catch (Exception e) { diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/AccountCommands.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/AccountCommands.cs index 44e6301..2b8a346 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/AccountCommands.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/AccountCommands.cs @@ -1,6 +1,7 @@ using System.Linq; using DiIiS_NA.LoginServer.AccountsSystem; using DiIiS_NA.LoginServer.Battle; +using FluentNHibernate.Utils; namespace DiIiS_NA.GameServer.CommandManager; diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/DifficultyCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/DifficultyCommand.cs index 57b28c0..a25b46c 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/DifficultyCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/DifficultyCommand.cs @@ -6,6 +6,28 @@ namespace DiIiS_NA.GameServer.CommandManager; [CommandGroup("difficulty", "Changes difficulty of the game", Account.UserLevels.GM)] public class DifficultyCommand : CommandGroup { + [Command("max", "Sets difficulty to max", Account.UserLevels.GM)] + public string Max(string[] @params, BattleClient invokerClient) + { + if (invokerClient?.InGameClient is null) + return "You must execute this command in-game."; + if (invokerClient.InGameClient.Player.World.Game.Difficulty == 19) + return "You can't increase difficulty any more."; + invokerClient.InGameClient.Player.World.Game.SetDifficulty(19); + return $"Difficulty set to max - {invokerClient.InGameClient.Player.World.Game.Difficulty}"; + } + + [Command("min", "Sets difficulty to min", Account.UserLevels.GM)] + public string Min(string[] @params, BattleClient invokerClient) + { + if (invokerClient?.InGameClient is null) + return "You must execute this command in-game."; + if (invokerClient.InGameClient.Player.World.Game.Difficulty == 0) + return "You can't decrease difficulty any more."; + invokerClient.InGameClient.Player.World.Game.SetDifficulty(0); + return $"Difficulty set to min - {invokerClient.InGameClient.Player.World.Game.Difficulty}"; + } + [Command("up", "Increases difficulty of the game", Account.UserLevels.GM)] public string Up(string[] @params, BattleClient invokerClient) { @@ -40,10 +62,16 @@ public class DifficultyCommand : CommandGroup } [DefaultCommand] - public string Get(string[] @params, BattleClient invokerClient) + public string Default(string[] @params, BattleClient invokerClient) { if (invokerClient?.InGameClient is null) return "You must execute this command in-game."; - return $"Current difficulty is {invokerClient.InGameClient.Player.World.Game.Difficulty}"; + return $"Current difficulty is {invokerClient.InGameClient.Player.World.Game.Difficulty}\n" + + $"Difficulties range from 0-19.\n\n" + + $"Use !difficulty set - to set difficulty to a specific value.\n" + + $"Use !difficulty up - to increase difficulty by 1.\n" + + $"Use !difficulty down - to decrease difficulty by 1.\n" + + $"Use !difficulty max - to set difficulty to max (19).\n" + + $"Use !difficulty min - to set difficulty to min (0)."; } } \ No newline at end of file diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/ModifySpeedCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/SpeedCommand.cs similarity index 99% rename from src/DiIiS-NA/D3-GameServer/CommandManager/Commands/ModifySpeedCommand.cs rename to src/DiIiS-NA/D3-GameServer/CommandManager/Commands/SpeedCommand.cs index 8da80f1..cfbda5e 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/ModifySpeedCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/SpeedCommand.cs @@ -13,7 +13,7 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; [CommandGroup("speed", "Modify speed walk of you character.\nUsage: !speed \nReset: !speed")] -public class ModifySpeedCommand : CommandGroup +public class SpeedCommand : CommandGroup { [DefaultCommand] public string ModifySpeed(string[] @params, BattleClient invokerClient) diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/WorldCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/WorldCommand.cs new file mode 100644 index 0000000..64158f6 --- /dev/null +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/WorldCommand.cs @@ -0,0 +1,28 @@ +using System.Linq; +using DiIiS_NA.GameServer.GSSystem.ActorSystem.Implementations; +using DiIiS_NA.LoginServer.AccountsSystem; +using DiIiS_NA.LoginServer.Battle; + +namespace DiIiS_NA.GameServer.CommandManager; + +[CommandGroup("world", "World commands", Account.UserLevels.Tester)] +public class WorldCommand : CommandGroup +{ + [Command("info", "Current World Info")] + public string Info(string[] @params, BattleClient invokerClient) + { + if (invokerClient?.InGameClient?.Player is not {} player) + return "You are not in game"; + + if (player.World == null) + return "You are not in world"; + + var world = player.World; + return $"[{world.SNO.ToString()}] - {world.SNO}\n{world.Players.Count} players\n" + + $"{world.Monsters.Count(s=>!s.Dead)} of {world.Monsters.Count} monsters alive\n" + + $"{world.Portals} portal(s)\n" + + $"{world.Actors.Count(s=>s.Value is Door)} door(s)\n" + + $"{(world.Game.ActiveNephalemPortal ? "Nephalem portal is active" : "Nephalem portal is inactive")}\n" + + $"{world.Game.ActiveNephalemProgress} nephalem progress"; + } +} \ No newline at end of file diff --git a/src/DiIiS-NA/D3-GameServer/Config.cs b/src/DiIiS-NA/D3-GameServer/Config.cs index 5c197dd..a1b404e 100644 --- a/src/DiIiS-NA/D3-GameServer/Config.cs +++ b/src/DiIiS-NA/D3-GameServer/Config.cs @@ -160,6 +160,15 @@ namespace DiIiS_NA.GameServer get => GetBoolean(nameof(AutoSaveQuests), false); set => Set(nameof(AutoSaveQuests), value); } + + /// + /// Progress gained when killing a monster in Nephalem Rifts + /// + public float NephalemRiftProgressMultiplier + { + get => GetFloat(nameof(NephalemRiftProgressMultiplier), 1f); + set => Set(nameof(NephalemRiftProgressMultiplier), value); + } public static Config Instance { get; } = new(); diff --git a/src/DiIiS-NA/D3-GameServer/GSSystem/PlayerSystem/Inventory.cs b/src/DiIiS-NA/D3-GameServer/GSSystem/PlayerSystem/Inventory.cs index cd354f6..7a600d7 100644 --- a/src/DiIiS-NA/D3-GameServer/GSSystem/PlayerSystem/Inventory.cs +++ b/src/DiIiS-NA/D3-GameServer/GSSystem/PlayerSystem/Inventory.cs @@ -2241,7 +2241,6 @@ namespace DiIiS_NA.GameServer.GSSystem.PlayerSystem } else _owner.GoldCollectedTempCount += amount; - UpdateCurrencies(); } @@ -2259,12 +2258,12 @@ namespace DiIiS_NA.GameServer.GSSystem.PlayerSystem if (_inventoryGold != null) { - // Logger.Warn($"InventoryGold is $[bold red]$NOT$[/]$ null: {_inventoryGold.Attributes[GameAttribute.Gold]}"); + //Logger.Warn($"InventoryGold is not null: $[yellow]${_inventoryGold.Attributes[GameAttribute.Gold]} / {_owner.Toon.GameAccount.Gold}$[/]$"); return _inventoryGold.Attributes[GameAttribute.Gold]; } else { - // Logger.Warn($"InventoryGold is $[bold red]$NULL$[/]$"); + //Logger.Warn($"InventoryGold is null"); return -1; } @@ -2296,7 +2295,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PlayerSystem { var moneys = D3.Items.CurrencySavedData.CreateBuilder(); var playerAcc = _owner.InGameClient.BnetClient.Account.GameAccount; - D3.Items.CurrencyData goldData = D3.Items.CurrencyData.CreateBuilder().SetId(0).SetCount((long)this.GetGoldAmount()).Build(); + D3.Items.CurrencyData goldData = D3.Items.CurrencyData.CreateBuilder().SetId(0).SetCount(GetGoldAmount()).Build(); D3.Items.CurrencyData bloodShardData = D3.Items.CurrencyData.CreateBuilder().SetId(1).SetCount(playerAcc.BloodShards).Build(); D3.Items.CurrencyData platinumData = D3.Items.CurrencyData.CreateBuilder().SetId(2).SetCount(playerAcc.Platinum).Build(); diff --git a/src/DiIiS-NA/D3-GameServer/GSSystem/PowerSystem/Payloads/DeathPayload.cs b/src/DiIiS-NA/D3-GameServer/GSSystem/PowerSystem/Payloads/DeathPayload.cs index 02129bc..0bde8f6 100644 --- a/src/DiIiS-NA/D3-GameServer/GSSystem/PowerSystem/Payloads/DeathPayload.cs +++ b/src/DiIiS-NA/D3-GameServer/GSSystem/PowerSystem/Payloads/DeathPayload.cs @@ -125,7 +125,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Payloads public void Apply() { - var PositionOfDeath = Target.Position; + var positionOfDeath = Target.Position; if (!Target.World.Game.Working) return; if (Target.Attributes.Contains(GameAttribute.Quest_Monster)) @@ -145,7 +145,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Payloads //(this.Target as NecromancerSkeleton_A).Master+ masterPlr.InGameClient.SendMessage(new MessageSystem.Message.Definitions.Pet.PetDetachMessage() { - PetId = skeletonA.DynamicID((skeletonA.Master as Player)) + PetId = skeletonA.DynamicID(skeletonA.Master as Player) }); masterPlr.NecroSkeletons.Remove(skeletonA); } @@ -153,7 +153,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Payloads { masterPlr2.InGameClient.SendMessage(new MessageSystem.Message.Definitions.Pet.PetDetachMessage() { - PetId = Target.DynamicID(((Target as Minion).Master as Player)) + PetId = Target.DynamicID((Target as Minion).Master as Player) }); masterPlr2.ActiveGolem = null; } @@ -331,24 +331,24 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Payloads if (Target.World.SNO == WorldSno.a4dun_garden_of_hope_01) { //Check if there are portals - var PortalToHell = Target.World.GetActorsBySNO(ActorSno._a4_heaven_gardens_hellportal); //{[Actor] [Type: Gizmo] SNOId:224890 DynamicId: 280 Position: x:696,681 y:695,4387 z:0,2636871 Name: a4_Heaven_Gardens_HellPortal} - if (PortalToHell.Count == 0) + var portalToHell = Target.World.GetActorsBySNO(ActorSno._a4_heaven_gardens_hellportal); //{[Actor] [Type: Gizmo] SNOId:224890 DynamicId: 280 Position: x:696,681 y:695,4387 z:0,2636871 Name: a4_Heaven_Gardens_HellPortal} + if (portalToHell.Count == 0) { - var Corruptions = Target.World.GetActorsBySNO(ActorSno._a4dun_garden_corruption_monster); - if (Corruptions.Count > 1) + var corruptions = Target.World.GetActorsBySNO(ActorSno._a4dun_garden_corruption_monster); + if (corruptions.Count > 1) { if (RandomHelper.Next(0, 30) > 26) { - Portal HellPortal = new Portal(Target.World, ActorSno._a4_heaven_gardens_hellportal, Target.World.StartingPoints[0].Tags); - HellPortal.EnterWorld(Target.Position); + Portal hellPortal = new Portal(Target.World, ActorSno._a4_heaven_gardens_hellportal, Target.World.StartingPoints[0].Tags); + hellPortal.EnterWorld(Target.Position); Context.User.World.SpawnMonster(ActorSno._diablo_vo, Context.User.Position); StartConversation(Target.World, 217226); } } else { - Portal HellPortal = new Portal(Target.World, ActorSno._a4_heaven_gardens_hellportal, Target.World.StartingPoints[0].Tags); - HellPortal.EnterWorld(Target.Position); + Portal hellPortal = new Portal(Target.World, ActorSno._a4_heaven_gardens_hellportal, Target.World.StartingPoints[0].Tags); + hellPortal.EnterWorld(Target.Position); Context.User.World.SpawnMonster(ActorSno._diablo_vo, Context.User.Position); StartConversation(Target.World, 217226); } @@ -357,16 +357,16 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Payloads //Second floor of the gardens of hope else if (Target.World.SNO == WorldSno.a4dun_garden_of_hope_random) { //Check if there are portals - var PortalToHell = Target.World.GetActorsBySNO(ActorSno._a4_heaven_gardens_hellportal); //{[Actor] [Type: Gizmo] SNOId:224890 DynamicId: 280 Position: x:696,681 y:695,4387 z:0,2636871 Name: a4_Heaven_Gardens_HellPortal} - if (PortalToHell.Count == 0) + var portalToHell = Target.World.GetActorsBySNO(ActorSno._a4_heaven_gardens_hellportal); //{[Actor] [Type: Gizmo] SNOId:224890 DynamicId: 280 Position: x:696,681 y:695,4387 z:0,2636871 Name: a4_Heaven_Gardens_HellPortal} + if (portalToHell.Count == 0) { - var Corruptions = Target.World.GetActorsBySNO(ActorSno._a4dun_garden_corruption_monster); - if (Corruptions.Count > 1) + var corruptions = Target.World.GetActorsBySNO(ActorSno._a4dun_garden_corruption_monster); + if (corruptions.Count > 1) { if (RandomHelper.Next(0, 30) > 26) { - Portal HellPortal = new Portal(Target.World, ActorSno._a4_heaven_gardens_hellportal, Target.World.StartingPoints[0].Tags); - HellPortal.EnterWorld(Target.Position); + Portal hellPortal = new Portal(Target.World, ActorSno._a4_heaven_gardens_hellportal, Target.World.StartingPoints[0].Tags); + hellPortal.EnterWorld(Target.Position); if (Context.User.World.GetActorsBySNO(ActorSno._diablo_vo).Count == 0) Context.User.World.SpawnMonster(ActorSno._diablo_vo, Context.User.Position); StartConversation(Target.World, 217228); @@ -374,8 +374,8 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Payloads } else { - Portal HellPortal = new Portal(Target.World, ActorSno._a4_heaven_gardens_hellportal, Target.World.StartingPoints[0].Tags); - HellPortal.EnterWorld(Target.Position); + Portal hellPortal = new Portal(Target.World, ActorSno._a4_heaven_gardens_hellportal, Target.World.StartingPoints[0].Tags); + hellPortal.EnterWorld(Target.Position); if (Context.User.World.GetActorsBySNO(ActorSno._diablo_vo).Count == 0) Context.User.World.SpawnMonster(ActorSno._diablo_vo, Context.User.Position); StartConversation(Target.World, 217228); @@ -403,9 +403,9 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Payloads { grantedExp = (int)(grantedExp * plr.World.Game.XpModifier); - float tempEXP = grantedExp * Config.Instance.RateExp; + float tempExp = grantedExp * Config.Instance.RateExp; - plr.UpdateExp(Math.Max((int)tempEXP, 1)); + plr.UpdateExp(Math.Max((int)tempExp, 1)); var a = (int)plr.Attributes[GameAttribute.Experience_Bonus]; var a1 = (int)plr.Attributes[GameAttribute.Experience_Bonus_Percent]; @@ -556,7 +556,8 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Payloads if (Context.DogsSummoned >= 3) plr.GrantAchievement(74987243307567); } - Logger.Trace("Killed monster, id: $[red]${0}$[/]$, level $[red]${1}$[/]$", Target.SNO, Target.Attributes[GameAttribute.Level]); + Logger.Trace( + $"$[green3_1]${Context?.User?.GetType().Name}$[/]$ killed monster, id: $[red]${{0}}$[/]$, level $[red]${{1}}$[/]$", Target.SNO, Target.Attributes[GameAttribute.Level]); //handling quest triggers @@ -594,14 +595,14 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Payloads } //Nephalem Rift - if ((Target.CurrentScene.Specification.SNOLevelAreas[0] == 332339 || Target.CurrentScene.Specification.SNOLevelAreas[0] == 288482) && Target.World.Game.ActiveNephalemTimer && Target.World.Game.ActiveNephalemKilledMobs == false) + if ((Target.CurrentScene.Specification.SNOLevelAreas[0] is 332339 or 288482) && Target.World.Game.ActiveNephalemTimer && Target.World.Game.ActiveNephalemKilledMobs == false) { - Target.World.Game.ActiveNephalemProgress += (1f * (Target.Quality + 1)); - Player Master = null; + Target.World.Game.ActiveNephalemProgress += Config.Instance.NephalemRiftProgressMultiplier * (Target.Quality + 1); + Player master = null; foreach (var plr in Target.World.Game.Players.Values) { if (plr.PlayerIndex == 0) - Master = plr; + master = plr; plr.InGameClient.SendMessage(new SimpleMessage(Opcodes.KillCounterRefresh) { @@ -612,8 +613,6 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Payloads Field0 = Target.World.Game.ActiveNephalemProgress }); - - if (Target.World.Game.ActiveNephalemProgress > 650) { Target.World.Game.ActiveNephalemKilledMobs = true; @@ -683,11 +682,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Payloads var position = new Core.Types.Math.Vector3D(Target.Position.X + (float)RandomHelper.NextDouble() * 30f, Target.Position.Y + (float)RandomHelper.NextDouble() * 30f, Target.Position.Z); - Item item = null; - if (Target.World.Game.NephalemGreater) - item = ItemGenerator.Cook(Master, "p1_tiered_rifts_Orb"); - else - item = ItemGenerator.Cook(Master, "p1_normal_rifts_Orb"); + Item item = ItemGenerator.Cook(master, Target.World.Game.NephalemGreater ? "p1_tiered_rifts_Orb" : "p1_normal_rifts_Orb"); if (item != null) item.EnterWorld(position); } @@ -748,12 +743,12 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Payloads Target.World.SpawnRandomUniqueGem(Target, plr); - TagMap NewTagMap = new TagMap(); - NewTagMap.Add(new TagKeySNO(526850), new TagMapEntry(526850, 332336, 0)); //World - NewTagMap.Add(new TagKeySNO(526853), new TagMapEntry(526853, 332339, 0)); //Zone - NewTagMap.Add(new TagKeySNO(526851), new TagMapEntry(526851, 24, 0)); //Entry-Pointа + TagMap newTagMap = new TagMap(); + newTagMap.Add(new TagKeySNO(526850), new TagMapEntry(526850, 332336, 0)); //World + newTagMap.Add(new TagKeySNO(526853), new TagMapEntry(526853, 332339, 0)); //Zone + newTagMap.Add(new TagKeySNO(526851), new TagMapEntry(526851, 24, 0)); //Entry-Pointа - var portal = new Portal(Target.World, ActorSno._x1_openworld_lootrunportal, NewTagMap); + var portal = new Portal(Target.World, ActorSno._x1_openworld_lootrunportal, newTagMap); portal.EnterWorld(new Core.Types.Math.Vector3D(Target.Position.X + 10f, Target.Position.Y + 10f, Target.Position.Z)); } @@ -790,7 +785,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Payloads }); //StartConversation(this.Target.World, 340878); var hubWorld = this.Target.World.Game.GetWorld(WorldSno.x1_tristram_adventure_mode_hub); - var orek = (hubWorld.GetActorBySNO(ActorSno._x1_lr_nephalem) as InteractiveNPC); + var orek = hubWorld.GetActorBySNO(ActorSno._x1_lr_nephalem) as InteractiveNPC; orek.Conversations.Add(new ActorSystem.Interactions.ConversationInteraction(340878)); orek.ForceConversationSNO = 340878; orek.Attributes[GameAttribute.Conversation_Icon, 0] = 2; @@ -881,9 +876,9 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Payloads foreach (float rate in dropRates) { // if seed is less than the drop rate, drop the item - if (seed < (rate * (1f - + plr.Attributes[GameAttribute.Magic_Find]) - * Config.Instance.RateDrop)) + if (seed < rate * (1f + + plr.Attributes[GameAttribute.Magic_Find]) + * Config.Instance.RateDrop) { //Logger.Debug("rate: {0}", rate); var lootQuality = Target.World.Game.IsHardcore @@ -992,15 +987,15 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Payloads if (Context.User is Player & Target is Monster) if (RandomHelper.Next(0, 100) > 40 & (Context.User as Player).Toon.Class == ToonClass.Necromancer) { - var Flesh = Context.User.World.SpawnMonster(ActorSno._p6_necro_corpse_flesh, PositionOfDeath); - Flesh.Attributes[GameAttribute.Necromancer_Corpse_Source_Monster_SNO] = (int)Target.SNO; - Flesh.Attributes.BroadcastChangedIfRevealed(); + var flesh = Context.User.World.SpawnMonster(ActorSno._p6_necro_corpse_flesh, positionOfDeath); + flesh.Attributes[GameAttribute.Necromancer_Corpse_Source_Monster_SNO] = (int)Target.SNO; + flesh.Attributes.BroadcastChangedIfRevealed(); } } if (Target is Monster) (Target as Monster).PlayLore(); - bool isCoop = (Target.World.Game.Players.Count > 1); + bool isCoop = Target.World.Game.Players.Count > 1; bool isHardcore = Target.World.Game.IsHardcore; bool isSeasoned = Target.World.Game.IsSeasoned; //114917