Exemple #1
0
 public static void SaveToDB(GameAccount gameAccount)
 {
     try
     {
         DBSessions.AccountSession.SaveOrUpdate(gameAccount.DBGameAccount);
         DBSessions.AccountSession.Flush();
     }
     catch (Exception e)
     {
         Logger.ErrorException(e, "GameAccount.SaveToDB()");
     }
 }
Exemple #2
0
        public static Toon CreateNewToon(string name, int classId, ToonFlags flags, byte level, GameAccount gameAccount)
        {
            var dbGameAccount = DBSessions.AccountSession.Get<DBGameAccount>(gameAccount.PersistentID);
            var newDBToon = new DBToon
                                {
                                    Class = @Toon.GetClassByID(classId),
                                    Name = name,
                                    /*HashCode = GetUnusedHashCodeForToonName(name),*/
                                    Flags = flags,
                                    Level = level,
                                    DBGameAccount = DBSessions.AccountSession.Get<DBGameAccount>(gameAccount.PersistentID)
                                };

            dbGameAccount.DBToons.Add(newDBToon);
            DBSessions.AccountSession.SaveOrUpdate(dbGameAccount);
            DBSessions.AccountSession.Flush();


            return GetToonByLowID(newDBToon.Id);
        }
Exemple #3
0
 public static Dictionary<ulong, Toon> GetToonsForGameAccount(GameAccount account)
 {
     return Toons.Where(pair => pair.Value.GameAccount != null).Where(pair => pair.Value.GameAccount.PersistentID == account.PersistentID).ToDictionary(pair => pair.Key, pair => pair.Value);
 }
Exemple #4
0
        private void SetFields(string name, int hashCode, int @class, ToonFlags flags, byte level, GameAccount owner, uint timePlayed, int goldAmount)
        {
            this.D3EntityID = D3.OnlineService.EntityId.CreateBuilder().SetIdHigh((ulong)EntityIdHelper.HighIdType.ToonId).SetIdLow(this.PersistentID).Build();


            this.HeroNameField.Value = name;
            this.HeroClassField.Value = @class;
            this.HeroFlagsField.Value = (uint)flags;
            this.HeroLevelField.Value = level;
            this.GameAccount = owner;
            this.HashCode = hashCode;
            this.TimePlayed = timePlayed;
            this.GoldAmount = goldAmount;
            this.Field6.Value = 99999999999999999;
            this.Field7.Value = 99999999999999999;

            var visualItems = new[]
            {                                
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Head
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Chest
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Feet
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Hands
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Weapon (1)
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Weapon (2)
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Shoulders
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Legs
            };

            this.HeroVisualEquipmentField.Value = D3.Hero.VisualEquipment.CreateBuilder().AddRangeVisualItem(visualItems).Build();

        }
Exemple #5
0
 public Toon(string name, int hashCode, int classHash, ToonFlags flags, byte level, GameAccount account) // Toon with **newly generated** persistent ID
     : base(StringHashHelper.HashIdentity(name + "#" + hashCode.ToString("D3")))
 {
     this.HeroClassField.transformDelegate += HeroClassFieldTransform;
     this.SetFields(name, hashCode, Toon.GetClassFromHash(classHash), flags, level, account, 0, 0);
 }
Exemple #6
0
        public Toon(string name, int hashCode, int classId, ToonFlags flags, byte level, GameAccount account) // Toon with **newly generated** persistent ID
            : base(StringHashHelper.HashIdentity(name + "#" + hashCode.ToString("D3")))
        {
            this.D3EntityID = D3.OnlineService.EntityId.CreateBuilder().SetIdHigh((ulong)EntityIdHelper.HighIdType.ToonId).SetIdLow(this.PersistentID).Build();

            this.Name = name;
            this.HashCode = hashCode;
            this.Class = @GetClassByID(classId);
            this.Flags = flags;
            this.Level = level;
            this.ExperienceNext = Player.LevelBorders[level];
            this.GameAccount = account;
            this.TimePlayed = 0;

            var visualItems = new[]
            {                                
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Head
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Chest
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Feet
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Hands
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Weapon (1)
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Weapon (2)
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Shoulders
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Legs
            };

            this.HeroVisualEquipmentField.Value = D3.Hero.VisualEquipment.CreateBuilder().AddRangeVisualItem(visualItems).Build();
        }
Exemple #7
0
 public bool HasMember(GameAccount gameAccount) //check if a given game account is already channels member
 {
     return this.Members.Any(pair => pair.Value.Identity.AccountId.Low == gameAccount.BnetEntityId.Low);
 }
Exemple #8
0
        private void SetFields(string name, int hashCode, ToonClass @class, ToonFlags flags, byte level, GameAccount owner, uint timePlayed)
        {
            //this.BnetEntityID = bnet.protocol.EntityId.CreateBuilder().SetHigh((ulong)EntityIdHelper.HighIdType.ToonId + this.PersistentID).SetLow(this.PersistentID).Build();
            this.D3EntityID = D3.OnlineService.EntityId.CreateBuilder().SetIdHigh((ulong)EntityIdHelper.HighIdType.ToonId).SetIdLow(this.PersistentID).Build();

            this.Name = name;
            this.HashCode = hashCode;
            this.Class = @class;
            this.Flags = flags;
            this.Level = level;
            this.GameAccount = owner;
            this.TimePlayed = timePlayed;

            var visualItems = new[]
            {                                
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Head
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Chest
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Feet
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Hands
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Weapon (1)
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Weapon (2)
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Shoulders
                D3.Hero.VisualItem.CreateBuilder().SetEffectLevel(0).Build(), // Legs
            };

            this.Equipment = D3.Hero.VisualEquipment.CreateBuilder().AddRangeVisualItem(visualItems).Build();

        }
Exemple #9
0
 public Toon(string name, int hashCode, int classId, ToonFlags flags, byte level, GameAccount account) // Toon with **newly generated** persistent ID
     : base(StringHashHelper.HashIdentity(name + "#" + hashCode.ToString("D3")))
 {
     this.SetFields(name, hashCode, GetClassByID(classId), flags, level, account, 0);
 }
Exemple #10
0
 public static GameAccount CreateGameAccount(Account account)
 {
     var gameAccount = new GameAccount(account);
     GameAccounts.Add(gameAccount.PersistentID, gameAccount);
     gameAccount.SaveToDB();
     return gameAccount;
 }
Exemple #11
0
        private static void LoadGameAccounts()
        {
            var query = "SELECT * FROM gameaccounts";
            var cmd = new SQLiteCommand(query, DBManager.Connection);
            var reader = cmd.ExecuteReader();

            if (!reader.HasRows) return;

            while (reader.Read())
            {
                var gameAccountId = Convert.ToUInt64(reader["id"]);
                var accountId = Convert.ToUInt64(reader["accountid"]);
                var gameAccount = new GameAccount(gameAccountId, accountId);

                #region Populate GameAccount Data

                var banner = (byte[])reader.GetValue(2);
                gameAccount.BannerConfiguration = D3.Account.BannerConfiguration.ParseFrom(banner);
                GameAccounts.Add(gameAccountId, gameAccount);

                #endregion
            }
        }
Exemple #12
0
        public static void DeleteGameAccount(GameAccount GameAccount)
        {
            if (!GameAccounts.ContainsKey(GameAccount.PersistentID))
            {
                Logger.Error("Attempting to delete game account that does not exist: {0}", GameAccount.PersistentID);
                return;
            }

            //Delete all toons for game account
            foreach (var toon in ToonManager.GetToonsForGameAccount(GameAccount).Values)
            {
                ToonManager.DeleteToon(toon);
            }

            if (GameAccount.DeleteFromDB()) GameAccounts.Remove(GameAccount.PersistentID);
        }
Exemple #13
0
 public static Toon GetDeletedToon(GameAccount account)
 {
     return (from pair in Toons where pair.Value.Deleted == true && pair.Value.GameAccount.PersistentID == account.PersistentID select pair.Value).FirstOrDefault();
 }
Exemple #14
0
        public static void DeleteGameAccount(GameAccount gameAccount)
        {
            if (gameAccount == null)
                return;
            if (LoadedGameAccounts.Contains(gameAccount))
                LoadedGameAccounts.Remove(gameAccount);

            //Delete all toons for game account
            foreach (var toon in ToonManager.GetToonsForGameAccount(gameAccount))

                ToonManager.DeleteToon(toon);


            var inventoryToDelete = DBSessions.AccountSession.Query<DBInventory>().Where(inv => inv.DBGameAccount.Id == gameAccount.DBGameAccount.Id);
            foreach (var inv in inventoryToDelete)
                DBSessions.AccountSession.Delete(inv);



            gameAccount.DBGameAccount.DBAccount.DBGameAccounts.Remove(gameAccount.DBGameAccount);

            DBSessions.AccountSession.Update(gameAccount.DBGameAccount.DBAccount);
            DBSessions.AccountSession.Delete(gameAccount.DBGameAccount);
            DBSessions.AccountSession.Flush();

        }
Exemple #15
0
 public static List<Toon> GetToonsForGameAccount(GameAccount account)
 {
     var toons = account.DBGameAccount.DBToons.Select(dbt => GetToonByLowID(dbt.Id));
     return toons.ToList();
 }
Exemple #16
0
 public static Toon GetDeletedToon(GameAccount account)
 {
     var query = DBSessions.AccountSession.Query<DBToon>().Where(dbt => dbt.DBGameAccount.Id == account.PersistentID && dbt.Deleted);
     return query.Any() ? GetToonByLowID(query.First().Id) : null;
 }