Quick Changes.

This commit is contained in:
Lucca Faria Ferri 2023-02-23 16:07:32 -08:00
parent aee7eb4af8
commit 1fff1a96c7
7 changed files with 44 additions and 63 deletions

View File

@ -264,7 +264,7 @@ public class GameAccount : PersistentRPCObject
public Toon CurrentToon public Toon CurrentToon
{ {
get => _currentToonId == 0 ? null : ToonManager.GetToonByLowID(_currentToonId); get => _currentToonId == 0 ? null : ToonManager.GetToonByLowId(_currentToonId);
set set
{ {
if (value.GameAccount.PersistentID != PersistentID) return; //just in case... if (value.GameAccount.PersistentID != PersistentID) return; //just in case...

View File

@ -282,7 +282,7 @@ namespace DiIiS_NA.LoginServer.Battle
System.Threading.Tasks.Task.Delay(1).ContinueWith((a) => { System.Threading.Tasks.Task.Delay(1).ContinueWith((a) => {
try try
{ {
Toons.ToonManager.GetToonByLowID((ulong)tscToonId).StateChanged(); Toons.ToonManager.GetToonByLowId((ulong)tscToonId).StateChanged();
} }
catch { } catch { }
}); });

View File

@ -33,7 +33,7 @@ namespace DiIiS_NA.LoginServer.ServicesSystem
static Service() static Service()
{ {
foreach (var type in Assembly.GetExecutingAssembly().GetTypes().Where(type => type.GetInterface("IServerService") != null)) foreach (var type in Assembly.GetExecutingAssembly().GetTypes().Where(type => type.GetInterface(nameof(IServerService)) != null))
{ {
var attributes = type.GetCustomAttributes(typeof(ServiceAttribute), true); var attributes = type.GetCustomAttributes(typeof(ServiceAttribute), true);
if (attributes.Length == 0) return; if (attributes.Length == 0) return;

View File

@ -1075,7 +1075,7 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services
HeroDigestListResponse.Builder builder = HeroDigestListResponse.CreateBuilder(); HeroDigestListResponse.Builder builder = HeroDigestListResponse.CreateBuilder();
foreach (var toon in request.ToonIdList) foreach (var toon in request.ToonIdList)
{ {
builder.AddDigestList(ToonManager.GetToonByLowID(toon).Digest); builder.AddDigestList(ToonManager.GetToonByLowId(toon).Digest);
} }
return builder.Build().ToByteString(); return builder.Build().ToByteString();
@ -1103,7 +1103,7 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services
private ByteString OnHeroDeleteParams(BattleClient client, ByteString data) private ByteString OnHeroDeleteParams(BattleClient client, ByteString data)
{ {
var deleteParams = DeleteHero.ParseFrom(data); var deleteParams = DeleteHero.ParseFrom(data);
var toon = ToonManager.GetToonByLowID(deleteParams.HeroId); var toon = ToonManager.GetToonByLowId(deleteParams.HeroId);
ToonManager.DeleteToon(toon); ToonManager.DeleteToon(toon);
return ByteString.Empty; return ByteString.Empty;
} }
@ -1113,7 +1113,7 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services
var request = GetToonSettings.ParseFrom(data); var request = GetToonSettings.ParseFrom(data);
var oldToon = client.Account.GameAccount.CurrentToon; var oldToon = client.Account.GameAccount.CurrentToon;
var newToon = ToonManager.GetToonByLowID(request.HeroId); var newToon = ToonManager.GetToonByLowId(request.HeroId);
if (oldToon != newToon) if (oldToon != newToon)
{ {
@ -3022,7 +3022,7 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services
{ {
foreach (var hero in testRequest.HeroIdsList) foreach (var hero in testRequest.HeroIdsList)
{ {
var toon = ToonManager.GetToonByLowID(hero); var toon = ToonManager.GetToonByLowId(hero);
if (toon.Dead == false) if (toon.Dead == false)
profileList.AddHeros(toon.Profile); profileList.AddHeros(toon.Profile);
} }
@ -3091,7 +3091,7 @@ namespace DiIiS_NA.LoginServer.ServicesSystem.Services
var request = HeroDigestListRequest.ParseFrom(data); var request = HeroDigestListRequest.ParseFrom(data);
var builder = HeroDigestListResponse.CreateBuilder(); var builder = HeroDigestListResponse.CreateBuilder();
foreach (var toon in request.ToonIdList) foreach (var toon in request.ToonIdList)
builder.AddDigestList(ToonManager.GetToonByLowID(toon).Digest); builder.AddDigestList(ToonManager.GetToonByLowId(toon).Digest);
return builder.Build().ToByteString(); return builder.Build().ToByteString();
} }

View File

@ -1242,28 +1242,18 @@ namespace DiIiS_NA.LoginServer.Toons
#endregion #endregion
public static ToonClass GetClassByID(int classId) public static ToonClass GetClassByID(int classId) =>
{ classId switch
switch (classId)
{ {
case 0x4FB91EE2: 0x4FB91EE2 => ToonClass.Barbarian,
return ToonClass.Barbarian; unchecked((int)0xBE27DC19) => ToonClass.Crusader,
case unchecked((int)0xBE27DC19): unchecked((int)0xC88B9649) => ToonClass.DemonHunter,
return ToonClass.Crusader; 0x003DAC15 => ToonClass.Monk,
case unchecked((int)0xC88B9649): 0x0343C22A => ToonClass.WitchDoctor,
return ToonClass.DemonHunter; 0x1D4681B1 => ToonClass.Wizard,
case 0x003DAC15: unchecked((int)0x8D4D94ED) => ToonClass.Necromancer,
return ToonClass.Monk; _ => ToonClass.Barbarian
case 0x0343C22A: };
return ToonClass.WitchDoctor;
case 0x1D4681B1:
return ToonClass.Wizard;
case unchecked((int)0x8D4D94ED):
return ToonClass.Necromancer;
}
return ToonClass.Barbarian;
}
public override string ToString() public override string ToString()
{ {

View File

@ -15,7 +15,7 @@ namespace DiIiS_NA.LoginServer.Toons
{ {
public static class ToonManager public static class ToonManager
{ {
private static readonly ConcurrentDictionary<ulong, Toon> LoadedToons = new ConcurrentDictionary<ulong, Toon>(); private static readonly ConcurrentDictionary<ulong, Toon> LoadedToons = new();
private static readonly Logger Logger = LogManager.CreateLogger("DataBaseSystem"); private static readonly Logger Logger = LogManager.CreateLogger("DataBaseSystem");
private static readonly DBInventory NewbiePants = new DBInventory private static readonly DBInventory NewbiePants = new DBInventory
@ -146,7 +146,7 @@ namespace DiIiS_NA.LoginServer.Toons
Attributes = "383,:1|1E-45;103,:0|0;406,:0|0;409,:1|1E-45;401,:1|1E-45;405,:1941814752|3.0065772E+31;194,:1067030938|1.2;196,:1067030938|1.2;198,:1067030938|1.2;538,:1067030938|1.2;540,:1067030938|1.2;546,:1067030938|1.2;201,:1067030938|1.2;446,:0|0;447,:0|0;448,:0|0;449,:0|0;539,:0|0;541,:0|0;195,:0|0;197,:0|0;231,0:1073741824|2;224,0:1077936128|3;232,0:1073741824|2;225,0:1077936128|3;226,:1077936128|3;233,:1073741824|2;236,:1075838976|2.5;235,0:1075838976|2.5;542,0:1073741824|2;547,0:1073741824|2;220,0:1073741824|2;216,0:1073741824|2;543,0:0|0;234,0:1075838976|2.5;222,0:1065353216|1;223,0:1065353216|1;227,0:1065353216|1;228,:1065353216|1;544,0:1065353216|1;548,0:1065353216|1;213,0:1065353216|1;545,0:0|0;381,:1000|1.401E-42;380,:1000|1.401E-42;100,30592:1|1E-45;102,30592:1|1E-45;388,57:0|0" Attributes = "383,:1|1E-45;103,:0|0;406,:0|0;409,:1|1E-45;401,:1|1E-45;405,:1941814752|3.0065772E+31;194,:1067030938|1.2;196,:1067030938|1.2;198,:1067030938|1.2;538,:1067030938|1.2;540,:1067030938|1.2;546,:1067030938|1.2;201,:1067030938|1.2;446,:0|0;447,:0|0;448,:0|0;449,:0|0;539,:0|0;541,:0|0;195,:0|0;197,:0|0;231,0:1073741824|2;224,0:1077936128|3;232,0:1073741824|2;225,0:1077936128|3;226,:1077936128|3;233,:1073741824|2;236,:1075838976|2.5;235,0:1075838976|2.5;542,0:1073741824|2;547,0:1073741824|2;220,0:1073741824|2;216,0:1073741824|2;543,0:0|0;234,0:1075838976|2.5;222,0:1065353216|1;223,0:1065353216|1;227,0:1065353216|1;228,:1065353216|1;544,0:1065353216|1;548,0:1065353216|1;213,0:1065353216|1;545,0:0|0;381,:1000|1.401E-42;380,:1000|1.401E-42;100,30592:1|1E-45;102,30592:1|1E-45;388,57:0|0"
}; };
private static readonly DBInventory NewbieNecr = new DBInventory private static readonly DBInventory NewbieNecromancer = new DBInventory
{ {
EquipmentSlot = 4, EquipmentSlot = 4,
LocationX = 0, LocationX = 0,
@ -181,11 +181,8 @@ namespace DiIiS_NA.LoginServer.Toons
public static void PreLoadToons() public static void PreLoadToons()
{ {
Logger.Info("Loading Diablo III - Toons..."); Logger.Info("Loading Diablo III - Toons...");
List<DBToon> all_toons = DBSessions.SessionQuery<DBToon>(); foreach (var toon in DBSessions.SessionQuery<DBToon>())
foreach (var toon in all_toons)
{
LoadedToons.TryAdd(toon.Id, new Toon(toon, null)); LoadedToons.TryAdd(toon.Id, new Toon(toon, null));
}
} }
public static Toon GetToonByDBToon(DBToon dbToon, GameDBSession session = null) public static Toon GetToonByDBToon(DBToon dbToon, GameDBSession session = null)
@ -203,15 +200,15 @@ namespace DiIiS_NA.LoginServer.Toons
public static Account GetOwnerAccountByToonLowId(ulong id) public static Account GetOwnerAccountByToonLowId(ulong id)
{ {
return GetToonByLowID(id).GameAccount.Owner; return GetToonByLowId(id).GameAccount.Owner;
} }
public static GameAccount GetOwnerGameAccountByToonLowId(ulong id) public static GameAccount GetOwnerGameAccountByToonLowId(ulong id)
{ {
return GetToonByLowID(id).GameAccount; return GetToonByLowId(id).GameAccount;
} }
public static Toon GetToonByLowID(ulong id, GameDBSession session = null) public static Toon GetToonByLowId(ulong id, GameDBSession session = null)
{ {
if (LoadedToons.ContainsKey(id)) if (LoadedToons.ContainsKey(id))
return LoadedToons[id]; return LoadedToons[id];
@ -225,20 +222,14 @@ namespace DiIiS_NA.LoginServer.Toons
public static Toon GetDeletedToon(GameAccount account) public static Toon GetDeletedToon(GameAccount account)
{ {
var query = DBSessions.SessionQueryWhere<DBToon>(dbt => dbt.DBGameAccount.Id == account.PersistentID && dbt.Deleted); var query = DBSessions.SessionQueryWhere<DBToon>(dbt => dbt.DBGameAccount.Id == account.PersistentID && dbt.Deleted);
return query.Any() ? GetToonByLowID(query.Last().Id) : null; return query.Any() ? GetToonByLowId(query.Last().Id) : null;
} }
public static List<Toon> GetToonsForGameAccount(GameAccount account) public static List<Toon> GetToonsForGameAccount(GameAccount account) =>
{ DBSessions.SessionQueryWhere<DBToon>(t => t.DBGameAccount.Id == account.PersistentID)
var toons = DBSessions.SessionQueryWhere<DBToon>(t => t.DBGameAccount.Id == account.PersistentID).Select(dbt => GetToonByLowID(dbt.Id)); .Select(dbt => GetToonByLowId(dbt.Id)).ToList();
return toons.ToList();
}
public static int TotalToons => DBSessions.SessionQuery<DBToon>().Count;
public static int TotalToons
{
get { return DBSessions.SessionQuery<DBToon>().Count; }
}
public static Toon CreateNewToon(string name, int classId, ToonFlags flags, byte level, bool IsHardcore, GameAccount gameAccount, int Season) public static Toon CreateNewToon(string name, int classId, ToonFlags flags, byte level, bool IsHardcore, GameAccount gameAccount, int Season)
@ -274,7 +265,7 @@ namespace DiIiS_NA.LoginServer.Toons
DBSessions.SessionSave(newDBToon); DBSessions.SessionSave(newDBToon);
Toon createdToon = GetToonByLowID(newDBToon.Id); Toon createdToon = GetToonByLowId(newDBToon.Id);
CreateSkillSet(newDBToon); CreateSkillSet(newDBToon);
@ -329,7 +320,7 @@ namespace DiIiS_NA.LoginServer.Toons
armor.isHardcore = isHardcore; armor.isHardcore = isHardcore;
DBSessions.SessionSave(armor); DBSessions.SessionSave(armor);
DBInventory weapon = new DBInventory(); DBInventory weapon;
switch (toon.DBToon.Class) switch (toon.DBToon.Class)
{ {
case ToonClass.Barbarian: case ToonClass.Barbarian:
@ -351,7 +342,7 @@ namespace DiIiS_NA.LoginServer.Toons
weapon = NewbieWand; weapon = NewbieWand;
break; break;
case ToonClass.Necromancer: case ToonClass.Necromancer:
weapon = NewbieNecr; weapon = NewbieNecromancer;
break; break;
default: default:
weapon = NewbieKnife; weapon = NewbieKnife;
@ -363,7 +354,6 @@ namespace DiIiS_NA.LoginServer.Toons
DBSessions.SessionSave(weapon); DBSessions.SessionSave(weapon);
if (toon.DBToon.Class == ToonClass.Crusader) //add shield if (toon.DBToon.Class == ToonClass.Crusader) //add shield
{ {
DBInventory shield = new DBInventory();
weapon = NewbieShield; weapon = NewbieShield;
weapon.DBToon = toon.DBToon; weapon.DBToon = toon.DBToon;
weapon.DBGameAccount = toon.GameAccount.DBGameAccount; weapon.DBGameAccount = toon.GameAccount.DBGameAccount;
@ -374,14 +364,15 @@ namespace DiIiS_NA.LoginServer.Toons
public static void CreateHirelingProfile(Toon toon, int type) public static void CreateHirelingProfile(Toon toon, int type)
{ {
var hireling = new DBHireling(); DBSessions.SessionSave(new DBHireling
hireling.Class = type; {
hireling.DBToon = toon.DBToon; Class = type,
hireling.Skill1SNOId = -1; DBToon = toon.DBToon,
hireling.Skill2SNOId = -1; Skill1SNOId = -1,
hireling.Skill3SNOId = -1; Skill2SNOId = -1,
hireling.Skill4SNOId = -1; Skill3SNOId = -1,
DBSessions.SessionSave(hireling); Skill4SNOId = -1
});
} }
public static void DeleteToon(Toon toon) public static void DeleteToon(Toon toon)

View File

@ -43,7 +43,7 @@ namespace DiIiS_NA.GameServer.ClientSystem
var game = GameManager.GetGameById(message.SGameId); var game = GameManager.GetGameById(message.SGameId);
Toon toon = null; Toon toon = null;
if (game != null) if (game != null)
toon = ToonManager.GetToonByLowID((ulong)message.HeroID, game.GameDbSession); toon = ToonManager.GetToonByLowId((ulong)message.HeroID, game.GameDbSession);
bool PVP = false; bool PVP = false;
if (PVP) if (PVP)
toon = new Toon(ToonManager.CreateFakeDBToon(toon.GameAccount.Owner.BattleTag, toon.GameAccount.DBGameAccount), game.GameDbSession); toon = new Toon(ToonManager.CreateFakeDBToon(toon.GameAccount.Owner.BattleTag, toon.GameAccount.DBGameAccount), game.GameDbSession);
@ -53,7 +53,7 @@ namespace DiIiS_NA.GameServer.ClientSystem
if (PVP) if (PVP)
{ {
game = GameManager.CreateGame(message.SGameId, 1); game = GameManager.CreateGame(message.SGameId, 1);
toon = ToonManager.GetToonByLowID((ulong)message.HeroID, game.GameDbSession); toon = ToonManager.GetToonByLowId((ulong)message.HeroID, game.GameDbSession);
game.SetAct(0); game.SetAct(0);
} }
else else