Inheritance: Mooege.Core.MooNet.Objects.PersistentRPCObject
Ejemplo n.º 1
0
        public SkillSet(ToonClass @class, Toon toon)
        {
            this.@Class = @class;

            var query = string.Format("SELECT * FROM active_skills WHERE id_toon={0}", toon.PersistentID);
            var cmd = new SQLiteCommand(query, DBManager.Connection);
            var reader = cmd.ExecuteReader();
            if (!reader.HasRows)
            {
                int[] ActiveSkillsList = Skills.GetAllActiveSkillsByClass(this.@Class).Take(1).ToArray();

                this.ActiveSkills = new ActiveSkillSavedData[6] {
                    new ActiveSkillSavedData { snoSkill = ActiveSkillsList[0], snoRune = -1 },
                    new ActiveSkillSavedData { snoSkill = Skills.None, snoRune = -1 },
                    new ActiveSkillSavedData { snoSkill = Skills.None, snoRune = -1 },
                    new ActiveSkillSavedData { snoSkill = Skills.None, snoRune = -1 },
                    new ActiveSkillSavedData { snoSkill = Skills.None, snoRune = -1 },
                    new ActiveSkillSavedData { snoSkill = Skills.None, snoRune = -1 }
                };
                this.PassiveSkills = new int[3] { -1, -1, -1 };

                var insQuery = string.Format("INSERT INTO active_skills (id_toon,"+
                    "skill_0,skill_1,skill_2,skill_3,skill_4,skill_5,"+
                    "rune_0,rune_1,rune_2,rune_3,rune_4,rune_5,"+
                    "passive_0,passive_1,passive_2) VALUES ({0},{1},-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 )",
                                 toon.PersistentID, ActiveSkillsList[0]);
                var insCmd = new SQLiteCommand(insQuery, DBManager.Connection);
                insCmd.ExecuteNonQuery();
            }
            else
            {
                this.ActiveSkills = new ActiveSkillSavedData[6] {
                    new ActiveSkillSavedData {  snoSkill = Convert.ToInt32(reader["skill_0"]), 
                                                snoRune  = Convert.ToInt32(reader["rune_0"]) },
                    new ActiveSkillSavedData {  snoSkill = Convert.ToInt32(reader["skill_1"]), 
                                                snoRune  = Convert.ToInt32(reader["rune_1"]) },
                    new ActiveSkillSavedData {  snoSkill = Convert.ToInt32(reader["skill_2"]), 
                                                snoRune  = Convert.ToInt32(reader["rune_2"]) },
                    new ActiveSkillSavedData {  snoSkill = Convert.ToInt32(reader["skill_3"]), 
                                                snoRune  = Convert.ToInt32(reader["rune_3"]) },
                    new ActiveSkillSavedData {  snoSkill = Convert.ToInt32(reader["skill_4"]), 
                                                snoRune  = Convert.ToInt32(reader["rune_4"]) },
                    new ActiveSkillSavedData {  snoSkill = Convert.ToInt32(reader["skill_5"]), 
                                                snoRune  = Convert.ToInt32(reader["rune_5"]) }
                };
                this.PassiveSkills = new int[3] {
                    Convert.ToInt32(reader["passive_0"]),
                    Convert.ToInt32(reader["passive_1"]),
                    Convert.ToInt32(reader["passive_2"])
                };
            }
            this.HotBarSkills = new HotbarButtonData[6] {
                new HotbarButtonData { SNOSkill = ActiveSkills[0].snoSkill, Field1 = -1, ItemGBId = -1 }, // left-click
                new HotbarButtonData { SNOSkill = ActiveSkills[1].snoSkill, Field1 = -1, ItemGBId = -1 }, // right-click
                new HotbarButtonData { SNOSkill = ActiveSkills[2].snoSkill, Field1 = -1, ItemGBId = -1 }, // bar-1
                new HotbarButtonData { SNOSkill = ActiveSkills[3].snoSkill, Field1 = -1, ItemGBId = -1 }, // bar-2
                new HotbarButtonData { SNOSkill = ActiveSkills[4].snoSkill, Field1 = -1, ItemGBId = -1 }, // bar-3
                new HotbarButtonData { SNOSkill = ActiveSkills[5].snoSkill, Field1 = -1, ItemGBId = -1 }, // bar-4
            };
        }
Ejemplo n.º 2
0
        public static void DeleteToon(Toon toon)
        {
            if (!Toons.ContainsKey(toon.PersistentID))
            {
                Logger.Error("Attempting to delete toon that does not exist: {0}", toon.PersistentID);
                return;
            }

            if (toon.DeleteFromDB()) Toons.Remove(toon.PersistentID);
        }
Ejemplo n.º 3
0
        public override void CreateToon(Google.ProtocolBuffers.IRpcController controller, CreateToonRequest request, Action<CreateToonResponse> done)
        {            
            var heroCreateParams = D3.OnlineService.HeroCreateParams.ParseFrom(request.AttributeList[0].Value.MessageValue);
            var builder = CreateToonResponse.CreateBuilder();

            int hashCode = ToonManager.GetUnusedHashCodeForToonName(request.Name);
            var toon = new Toon(request.Name, hashCode, heroCreateParams.GbidClass, heroCreateParams.IsFemale ? ToonFlags.Female : ToonFlags.Male, 1, Client.Account);
            if (ToonManager.SaveToon(toon)) builder.SetToon(toon.BnetEntityID);
            done(builder.Build());

            Logger.Trace("CreateToon() {0}", toon);
        }
Ejemplo n.º 4
0
        public static void DeleteToon(Toon toon)
        {
            if (toon == null)
            {
                return;
            }

            //remove toonActiveSkills
            if (toon.DBToon.DBActiveSkills != null)
            {
                DBSessions.AccountSession.Delete(toon.DBToon.DBActiveSkills);
                toon.DBToon.DBActiveSkills = null;
            }

            //remove toon inventory
            var inventoryToDelete = DBSessions.AccountSession.Query <DBInventory>().Where(inv => inv.DBToon.Id == toon.DBToon.Id);

            foreach (var inv in inventoryToDelete)
            {
                //toon.DBToon.DBGameAccount.DBInventories.Remove(inv);
                DBSessions.AccountSession.Delete(inv);
            }



            //remove lastplayed hero if it was toon
            if (toon.DBToon.DBGameAccount.LastPlayedHero != null && toon.DBToon.DBGameAccount.LastPlayedHero.Id == toon.DBToon.Id)
            {
                toon.DBToon.DBGameAccount.LastPlayedHero = null;
            }


            //remove toon from dbgameaccount
            while (toon.DBToon.DBGameAccount.DBToons.Contains(toon.DBToon))
            {
                toon.DBToon.DBGameAccount.DBToons.Remove(toon.DBToon);
            }

            //save all this thinks
            DBSessions.AccountSession.SaveOrUpdate(toon.DBToon.DBGameAccount);
            DBSessions.AccountSession.Delete(toon.DBToon);
            DBSessions.AccountSession.Flush();


            //remove toon from loadedToon list
            if (LoadedToons.Contains(toon))
            {
                LoadedToons.Remove(toon);
            }

            Logger.Debug("Deleting toon {0}", toon.PersistentID);
        }
Ejemplo n.º 5
0
        public static void DeleteToon(Toon toon)
        {
            if (!Toons.ContainsKey(toon.PersistentID))
            {
                Logger.Error("Attempting to delete toon that does not exist: {0}", toon.PersistentID);
                return;
            }

            if (toon.DeleteFromDB())
            {
                Toons.Remove(toon.PersistentID);
            }
        }
Ejemplo n.º 6
0
        //Method only used when creating a Toon for the first time, ambiguous method name - Tharuler
        public static bool SaveToon(Toon toon)
        {
            if (Toons.ContainsKey(toon.PersistentID)) //this should never happen again thanks to hashcode, but lets leave it in for now - Tharuler
            {
                Logger.Error("Duplicate persistent toon id: {0}", toon.PersistentID);
                return(false);
            }

            Toons.Add(toon.PersistentID, toon);
            toon.SaveToDB(); //possible concurrency problem? 2 toon created with same name at same time could introduce a race condition for the same hashcode(chance of 1 in (1000-amount of toons with that name))

            Logger.Trace("Character {0} with HashCode #{1} added to database", toon.Name, toon.HashCodeString);

            return(true);
        }
Ejemplo n.º 7
0
        //Method only used when creating a Toon for the first time, ambiguous method name - Tharuler
        public static bool SaveToon(Toon toon)
        {
            if (Toons.ContainsKey(toon.PersistentID)) //this should never happen again thanks to hashcode, but lets leave it in for now - Tharuler
            {
                Logger.Error("Duplicate persistent toon id: {0}", toon.PersistentID);
                return(false);
            }

            Toons.Add(toon.PersistentID, toon);
            toon.SaveToDB();

            Logger.Trace("Character {0} added to database", toon.HeroNameField.Value);

            return(true);
        }
Ejemplo n.º 8
0
        //Method only used when creating a Toon for the first time, ambiguous method name - Tharuler
        public static bool SaveToon(Toon toon)
        {

            if (Toons.ContainsKey(toon.PersistentID)) //this should never happen again thanks to hashcode, but lets leave it in for now - Tharuler
            {
                Logger.Error("Duplicate persistent toon id: {0}", toon.PersistentID);
                return false;
            }

            Toons.Add(toon.PersistentID, toon);
            toon.SaveToDB(); //possible concurrency problem? 2 toon created with same name at same time could introduce a race condition for the same hashcode(chance of 1 in (1000-amount of toons with that name))

            Logger.Trace("Character {0} with HashCode #{1} added to database", toon.Name, toon.HashCodeString);

            return true;
        }
Ejemplo n.º 9
0
        //Method only used when creating a Toon for the first time, ambiguous method name - Tharuler
        public static bool SaveToon(Toon toon)
        {

            if (Toons.ContainsKey(toon.PersistentID)) //this should never happen again thanks to hashcode, but lets leave it in for now - Tharuler
            {
                Logger.Error("Duplicate persistent toon id: {0}", toon.PersistentID);
                return false;
            }

            Toons.Add(toon.PersistentID, toon);
            toon.SaveToDB();

            Logger.Trace("Character {0} added to database", toon.HeroNameField.Value);

            return true;
        }
Ejemplo n.º 10
0
        private static void LoadToons()
        {
            var query  = "SELECT * from toons";
            var cmd    = new SQLiteCommand(query, DBManager.Connection);
            var reader = cmd.ExecuteReader();

            if (!reader.HasRows)
            {
                return;
            }

            while (reader.Read())
            {
                var databaseId = (ulong)reader.GetInt64(0);
                var toon       = new Toon(databaseId, reader.GetString(1), reader.GetInt32(6), reader.GetByte(2), reader.GetByte(3), reader.GetByte(4), reader.GetInt64(5), (uint)reader.GetInt32(7));
                Toons.Add(databaseId, toon);
            }
        }
Ejemplo n.º 11
0
        public override void CreateToon(Google.ProtocolBuffers.IRpcController controller, bnet.protocol.toon.external.CreateToonRequest request, Action<bnet.protocol.toon.external.CreateToonResponse> done)
        {            
            var heroCreateParams = D3.OnlineService.HeroCreateParams.ParseFrom(request.AttributeList[0].Value.MessageValue);
            var builder = bnet.protocol.toon.external.CreateToonResponse.CreateBuilder();

            int hashCode = ToonManager.GetUnusedHashCodeForToonName(request.Name);
            var toon = new Toon(request.Name, hashCode, heroCreateParams.GbidClass, heroCreateParams.IsFemale ? ToonFlags.Female : ToonFlags.Male, 1, Client.Account);
            if (ToonManager.SaveToon(toon))
                builder.SetToken((uint)toon.BnetEntityID.Low);
            done(builder.Build());

            var notification = bnet.protocol.toon.external.ToonCreatedNotification.CreateBuilder()
                .SetToon(toon.BnetEntityID)
                .SetToken((uint) toon.BnetEntityID.Low)
                .SetErrorCode(0).Build();

            this.Client.MakeRPC(() => bnet.protocol.toon.external.ToonNotifyExternal.CreateStub(this.Client).NotifyToonCreated(null, notification, callback => { }));

            Logger.Trace("CreateToon() {0}", toon);
        }
Ejemplo n.º 12
0
        public static void SaveToDB(Toon toon)
        {
            try
            {
                // save character base data
                var dbToon = DBSessions.AccountSession.Get <DBToon>(toon.PersistentID);
                dbToon.Name = toon.Name;
                /*dbToon.HashCode = toon.HashCode;*/
                dbToon.Class         = toon.Class;
                dbToon.Flags         = toon.Flags;
                dbToon.Level         = toon.Level;
                dbToon.Experience    = toon.ExperienceNext;
                dbToon.DBGameAccount = DBSessions.AccountSession.Get <DBGameAccount>(toon.GameAccount.PersistentID);
                dbToon.TimePlayed    = toon.TimePlayed;
                dbToon.Deleted       = toon.Deleted;

                DBSessions.AccountSession.SaveOrUpdate(dbToon);
                DBSessions.AccountSession.Flush();
            }
            catch (Exception e)
            {
                Logger.ErrorException(e, "Toon.SaveToDB()");
            }
        }
Ejemplo n.º 13
0
        public void UpdateHotbarSkills(int hotBarIndex,int SNOSkill,Toon toon)
        {
            
            /* SKILL MAP Index
             * 0 -> skill_0
             * 1 -> skill_1
             * 7 -> skill_2
             * 6 -> skill_3
             * 5 -> skill_4
             * 4 -> skill_5
             */

            switch (hotBarIndex)
            {
                case 0:
                    Logger.Debug("Update index 0 {0}", SNOSkill);
                    var query_0 = string.Format("UPDATE active_skills SET skill_0={1} WHERE id_toon={0} ", toon.D3EntityID.IdLow, SNOSkill);
                    var cmd_0 = new SQLiteCommand(query_0, DBManager.Connection);
                    cmd_0.ExecuteReader();
                    break;
                case 1:
                    Logger.Debug("Update index 1 {0}", SNOSkill);
                    var query_1 = string.Format("UPDATE active_skills SET skill_1={1} WHERE id_toon={0} ", toon.D3EntityID.IdLow, SNOSkill);
                    var cmd_1 = new SQLiteCommand(query_1, DBManager.Connection);
                    cmd_1.ExecuteReader();
                    break;
                case 4:
                    Logger.Debug("Update index 4 {0}", SNOSkill);
                    var query_4 = string.Format("UPDATE active_skills SET skill_5={1} WHERE id_toon={0} ", toon.D3EntityID.IdLow, SNOSkill);
                    var cmd_4 = new SQLiteCommand(query_4, DBManager.Connection);
                    cmd_4.ExecuteReader();
                    break;
                case 5:
                    Logger.Debug("Update index 5 {0}", SNOSkill);
                    var query_5 = string.Format("UPDATE active_skills SET skill_4={1} WHERE id_toon={0} ", toon.D3EntityID.IdLow, SNOSkill);
                    var cmd_5 = new SQLiteCommand(query_5, DBManager.Connection);
                    cmd_5.ExecuteReader();
                    break;
                case 6:
                    Logger.Debug("Update index 6 {0}", SNOSkill);
                    var query_6 = string.Format("UPDATE active_skills SET skill_3={1} WHERE id_toon={0} ", toon.D3EntityID.IdLow, SNOSkill);
                    var cmd_6 = new SQLiteCommand(query_6, DBManager.Connection);
                    cmd_6.ExecuteReader();
                    break;
                case 7:
                    Logger.Debug("Update index 7 {0}", SNOSkill);
                    var query_7 = string.Format("UPDATE active_skills SET skill_2={1} WHERE id_toon={0} ", toon.D3EntityID.IdLow, SNOSkill);
                    var cmd_7 = new SQLiteCommand(query_7, DBManager.Connection);
                    cmd_7.ExecuteReader();
                    break;
            }

        }
Ejemplo n.º 14
0
 public void UpdatePassiveSkills(Toon toon)
 {
     Logger.Debug("Update passive to {0} {1} {2}", PassiveSkills[0], PassiveSkills[1], PassiveSkills[2]);
     var query = string.Format("UPDATE active_skills SET passive_0={1}, passive_1={2}, passive_2={3} WHERE id_toon={0} ", toon.PersistentID, PassiveSkills[0], PassiveSkills[1], PassiveSkills[2]);
     var cmd = new SQLiteCommand(query, DBManager.Connection);
     cmd.ExecuteNonQuery();
 }
Ejemplo n.º 15
0
        public void SwitchUpdateSkills(int oldSNOSkill, int SNOSkill, int SNORune, Toon toon)
		{
			for (int i = 0; i < this.HotBarSkills.Length; i++)
			{
				if(this.HotBarSkills[i].SNOSkill == oldSNOSkill)
				{
					Logger.Debug("SkillSet: SwitchUpdateSkill Oldskill {0} Newskill {1}", oldSNOSkill, SNOSkill);
					this.HotBarSkills[i].SNOSkill = SNOSkill;
                    this.UpdateSkills(i, SNOSkill, SNORune, toon);
                    return;
				}
			}
		}
Ejemplo n.º 16
0
 public void UpdateSkills(int hotBarIndex, int SNOSkill, int SNORune, Toon toon)
 {
     Logger.Debug("Update index {0} skill {1} rune {2}", hotBarIndex, SNOSkill, SNORune);
     var query = string.Format("UPDATE active_skills SET skill_{1}={2}, rune_{1}={3} WHERE id_toon={0} ", toon.PersistentID, hotBarIndex, SNOSkill, SNORune);
     var cmd = new SQLiteCommand(query, DBManager.Connection);
     cmd.ExecuteNonQuery();
 }
Ejemplo n.º 17
0
        private static void LoadToons()
        {
            var query = "SELECT * from toons";
            var cmd = new SQLiteCommand(query, DBManager.Connection);
            var reader = cmd.ExecuteReader();

            if (!reader.HasRows) return;

            while (reader.Read())
            {
                var databaseId = (ulong)reader.GetInt64(0);
                var toon = new Toon(databaseId, reader.GetString(1), reader.GetInt32(6), reader.GetByte(2), reader.GetByte(3), reader.GetByte(4), reader.GetInt64(5),(uint)reader.GetInt32(7));
                Toons.Add(databaseId, toon);
            }
        }
Ejemplo n.º 18
0
        public void UpdatePassiveSkills(Toon toon)
        {
            Logger.Debug("Update passive to {0} {1} {2}", PassiveSkills[0], PassiveSkills[1], PassiveSkills[2]);
            var dbToon = DBSessions.AccountSession.Get<DBToon>(toon.PersistentID);
            dbToon.DBActiveSkills.Passive0 = PassiveSkills[0];
            dbToon.DBActiveSkills.Passive1 = PassiveSkills[1];
            dbToon.DBActiveSkills.Passive2 = PassiveSkills[2];

            DBSessions.AccountSession.SaveOrUpdate(dbToon.DBActiveSkills);
            DBSessions.AccountSession.Flush();

        }
Ejemplo n.º 19
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, new Dictionary <uint, Item>());
 }
Ejemplo n.º 20
0
        public static void DeleteToon(Toon toon)
        {
            if (toon == null)
                return;

            //remove toonActiveSkills
            if (toon.DBToon.DBActiveSkills != null)
            {
                DBSessions.AccountSession.Delete(toon.DBToon.DBActiveSkills);
                toon.DBToon.DBActiveSkills = null;
            }

            //remove toon inventory
            var inventoryToDelete = DBSessions.AccountSession.Query<DBInventory>().Where(inv => inv.DBToon.Id == toon.DBToon.Id);
            foreach (var inv in inventoryToDelete)
            {
                //toon.DBToon.DBGameAccount.DBInventories.Remove(inv);
                DBSessions.AccountSession.Delete(inv);
            }

            
            

            //remove lastplayed hero if it was toon
            if (toon.DBToon.DBGameAccount.LastPlayedHero != null && toon.DBToon.DBGameAccount.LastPlayedHero.Id == toon.DBToon.Id)
                toon.DBToon.DBGameAccount.LastPlayedHero = null;

            
            //remove toon from dbgameaccount
            while (toon.DBToon.DBGameAccount.DBToons.Contains(toon.DBToon))
                toon.DBToon.DBGameAccount.DBToons.Remove(toon.DBToon);

            //save all this thinks
            DBSessions.AccountSession.SaveOrUpdate(toon.DBToon.DBGameAccount);
            DBSessions.AccountSession.Delete(toon.DBToon);
            DBSessions.AccountSession.Flush();

            
            //remove toon from loadedToon list
            if (LoadedToons.Contains(toon))
                LoadedToons.Remove(toon);

            Logger.Debug("Deleting toon {0}", toon.PersistentID);
        }
Ejemplo n.º 21
0
        public static void SaveToDB(Toon toon)
        {
            try
            {
                // save character base data
                var dbToon = DBSessions.AccountSession.Get<DBToon>(toon.PersistentID);
                dbToon.Name = toon.Name;
                /*dbToon.HashCode = toon.HashCode;*/
                dbToon.Class = toon.Class;
                dbToon.Flags = toon.Flags;
                dbToon.Level = toon.Level;
                dbToon.Experience = toon.ExperienceNext;
                dbToon.DBGameAccount = DBSessions.AccountSession.Get<DBGameAccount>(toon.GameAccount.PersistentID);
                dbToon.TimePlayed = toon.TimePlayed;
                dbToon.Deleted = toon.Deleted;

                DBSessions.AccountSession.SaveOrUpdate(dbToon);
                DBSessions.AccountSession.Flush();
            }
            catch (Exception e)
            {
                Logger.ErrorException(e, "Toon.SaveToDB()");
            }
        }
Ejemplo n.º 22
0
 public bool HasToon(Toon toon) // checks if given toon is already channels member
 {
     return this.Members.Any(pair => pair.Value.Identity.ToonId.Low == toon.BnetEntityID.Low);
 }
Ejemplo n.º 23
0
        private static void LoadToons()
        {
            var query = "SELECT * FROM toons";
            var cmd = new SQLiteCommand(query, DBManager.Connection);
            var reader = cmd.ExecuteReader();

            if (!reader.HasRows) return;

            while (reader.Read())
            {
                var databaseId = Convert.ToUInt64(reader["id"]);
                var toon = new Toon(databaseId);
                Toons.Add(databaseId, toon);
            }
        }
Ejemplo n.º 24
0
        private static void LoadToons()
        {
            var query  = "SELECT * from toons";
            var cmd    = new SQLiteCommand(query, DBManager.Connection);
            var reader = cmd.ExecuteReader();

            if (!reader.HasRows)
            {
                return;
            }

            while (reader.Read())
            {
                var itemCreate = new Dictionary <uint, Item>();
                var databaseId = (ulong)reader.GetInt64(0);
                //TODO: Move this to toon class only create a toon with id and call load from DB
                var toon = new Toon(databaseId, reader.GetString(1), (int)reader.GetInt32(6), reader.GetByte(2), reader.GetByte(3), reader.GetByte(4), reader.GetInt64(5), (uint)reader.GetInt32(7), (int)reader.GetInt32(8), null);
                //add visual equipment
                //TODO: Load all visualEquipment at once
                D3.Hero.VisualItem[] visualItems = new D3.Hero.VisualItem[8];
                var vItemQuery =
                    string.Format("SELECT * from inventory WHERE toon_id = {0} and inventory_slot <> -1", databaseId);
                var itemCmd    = new SQLiteCommand(vItemQuery, DBManager.Connection);
                var itemReader = itemCmd.ExecuteReader();
                if (itemReader.HasRows)
                {
                    while (itemReader.Read())
                    {
                        var slot = (int)itemReader.GetInt64(3);
                        var gbid = (int)itemReader.GetInt64(4);
                        visualItems[slot] = D3.Hero.VisualItem.CreateBuilder()
                                            .SetGbid(gbid)
                                            .SetEffectLevel(0)
                                            .Build();
                    }

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

                //add inventory items
                var itemQuery =
                    string.Format("SELECT * from inventory WHERE toon_id = {0} and inventory_slot = -1", databaseId);
                itemCmd    = new SQLiteCommand(itemQuery, DBManager.Connection);
                itemReader = itemCmd.ExecuteReader();
                if (itemReader.HasRows)
                {
                    uint count = 0;
                    toon.ItemsTable = new Dictionary <uint, KeyValuePair <ItemTable, Vector2D> >();
                    while (itemReader.Read())
                    {
                        var       x    = (int)itemReader.GetInt64(1);
                        var       y    = (int)itemReader.GetInt64(2);
                        var       slot = (int)itemReader.GetInt64(3);
                        var       gbid = (int)itemReader.GetInt64(4);
                        ItemTable it   = ItemGenerator.GetItemDefinition(gbid);
                        Vector2D  v2d  = new Vector2D(x, y);
                        toon.ItemsTable.Add((uint)gbid, new KeyValuePair <ItemTable, Vector2D>(it, v2d));
                        count++;
                    }

                    toon.Items = itemCreate;
                }


                Toons.Add(databaseId, toon);
            }
        }
Ejemplo n.º 25
0
        public SkillSet(ToonClass @class, Toon toon)
        {
            this.@Class = @class;
            var dbToon = DBSessions.AccountSession.Get<DBToon>(toon.PersistentID);

            if (dbToon.DBActiveSkills == null)
            {
                int[] ActiveSkillsList = Skills.GetAllActiveSkillsByClass(this.@Class).Take(1).ToArray();

                this.ActiveSkills = new ActiveSkillSavedData[6] {
                    new ActiveSkillSavedData { snoSkill = ActiveSkillsList[0], snoRune = -1 },
                    new ActiveSkillSavedData { snoSkill = Skills.None, snoRune = -1 },
                    new ActiveSkillSavedData { snoSkill = Skills.None, snoRune = -1 },
                    new ActiveSkillSavedData { snoSkill = Skills.None, snoRune = -1 },
                    new ActiveSkillSavedData { snoSkill = Skills.None, snoRune = -1 },
                    new ActiveSkillSavedData { snoSkill = Skills.None, snoRune = -1 }
                };

                this.PassiveSkills = new int[3] {
                    -1,-1,-1,
                };


                dbToon.DBActiveSkills = new DBActiveSkills
                                            {
                                                Skill0 = ActiveSkillsList[0],
                                                Skill1 = -1,
                                                Skill2 = -1,
                                                Skill3 = -1,
                                                Skill4 = -1,
                                                Skill5 = -1,
                                                Rune0 = -1,
                                                Rune1 = -1,
                                                Rune2 = -1,
                                                Rune3 = -1,
                                                Rune4 = -1,
                                                Rune5 = -1,
                                                Passive0 = -1,
                                                Passive1 = -1,
                                                Passive2 = -1
                                            };
                DBSessions.AccountSession.SaveOrUpdate(dbToon.DBActiveSkills);
                DBSessions.AccountSession.Flush();

            }
            else
            {
                this.ActiveSkills = new ActiveSkillSavedData[6] {
                    new ActiveSkillSavedData {  snoSkill = dbToon.DBActiveSkills.Skill0, 
                                                snoRune  = dbToon.DBActiveSkills.Rune0 },
                    new ActiveSkillSavedData {  snoSkill = dbToon.DBActiveSkills.Skill1, 
                                                snoRune  = dbToon.DBActiveSkills.Rune1 },
                    new ActiveSkillSavedData {  snoSkill = dbToon.DBActiveSkills.Skill2, 
                                                snoRune  = dbToon.DBActiveSkills.Rune2 },
                    new ActiveSkillSavedData {  snoSkill = dbToon.DBActiveSkills.Skill3, 
                                                snoRune  = dbToon.DBActiveSkills.Rune3 },
                    new ActiveSkillSavedData {  snoSkill = dbToon.DBActiveSkills.Skill4, 
                                                snoRune  = dbToon.DBActiveSkills.Rune4 },
                    new ActiveSkillSavedData {  snoSkill = dbToon.DBActiveSkills.Skill5, 
                                                snoRune  = dbToon.DBActiveSkills.Rune5 },
                };
                this.PassiveSkills = new int[3] {
                    dbToon.DBActiveSkills.Passive0,
                    dbToon.DBActiveSkills.Passive1,
                    dbToon.DBActiveSkills.Passive2,
                };
            }

            this.HotBarSkills = new HotbarButtonData[6] {
                new HotbarButtonData { SNOSkill = ActiveSkills[0].snoSkill, Field1 = -1, ItemGBId = -1 }, // left-click
                new HotbarButtonData { SNOSkill = ActiveSkills[1].snoSkill, Field1 = -1, ItemGBId = -1 }, // right-click
                new HotbarButtonData { SNOSkill = ActiveSkills[2].snoSkill, Field1 = -1, ItemGBId = -1 }, // bar-1
                new HotbarButtonData { SNOSkill = ActiveSkills[3].snoSkill, Field1 = -1, ItemGBId = -1 }, // bar-2
                new HotbarButtonData { SNOSkill = ActiveSkills[4].snoSkill, Field1 = -1, ItemGBId = -1 }, // bar-3
                new HotbarButtonData { SNOSkill = ActiveSkills[5].snoSkill, Field1 = -1, ItemGBId = -1 }, // bar-4
            };
        }
Ejemplo n.º 26
0
 private ByteString CreateHero(D3.OnlineService.HeroCreateParams createPrams)
 {
     int hashCode = ToonManager.GetUnusedHashCodeForToonName(createPrams.Name);
     var newToon = new Toon(createPrams.Name, hashCode, createPrams.GbidClass, createPrams.IsFemale ? ToonFlags.Female : ToonFlags.Male, 1, Client.Account.CurrentGameAccount);
     if (ToonManager.SaveToon(newToon))
     {
         Logger.Trace("CreateHero() {0}", newToon);
         return newToon.D3EntityID.ToByteString();
     }
     return ByteString.Empty;
 }
Ejemplo n.º 27
0
        public SkillSet(ToonClass @class,Toon toon)
        {
            this.@Class = @class;

            
            this.CurrentActiveSkills = Skills.GetAllActiveSkillsByClass(this.@Class).Take(6).ToArray();
            
            var query = string.Format("SELECT * from active_skills WHERE id_toon={0}", toon.D3EntityID.IdLow);
            var cmd = new SQLiteCommand(query, DBManager.Connection);
            var reader = cmd.ExecuteReader();

			//30592 base attack

            if (!reader.HasRows)  //this is just in case something goes wrong on  public void SaveToDB() -> we need to change this name ...
            {
                var query_first_insert = string.Format("INSERT INTO  active_skills (id_toon,skill_0,skill_1,skill_2,skill_3,skill_4,skill_5) VALUES ({0},{1},{2},{3},{4},{5},{6} )", toon.D3EntityID.IdLow, this.CurrentActiveSkills[0], 30592, Skills.None, Skills.None, Skills.None, Skills.None, Skills.None);
                var cmd_first_insert = new SQLiteCommand(query_first_insert, DBManager.Connection);
                cmd_first_insert.ExecuteReader();
                Logger.Debug("SkillSet: No Entry for {0}", toon.D3EntityID.IdLow);
				this.HotBarSkills = new HotbarButtonData[9] {     
                new HotbarButtonData { SNOSkill = this.CurrentActiveSkills[0], ItemGBId = -1 }, // left-click
                new HotbarButtonData { SNOSkill = 30592, ItemGBId = -1 }, // right-click
                new HotbarButtonData { SNOSkill = Skills.None, ItemGBId = -1 }, // hidden-bar - left-click switch - which key??
                new HotbarButtonData { SNOSkill = Skills.None, ItemGBId = -1 }, // hidden-bar - right-click switch (press x ingame)
                new HotbarButtonData { SNOSkill = Skills.None, ItemGBId = -1 }, // bar-1
                new HotbarButtonData { SNOSkill = Skills.None, ItemGBId = -1 }, // bar-2
                new HotbarButtonData { SNOSkill = Skills.None, ItemGBId = -1 }, // bar-3
                new HotbarButtonData { SNOSkill = Skills.None, ItemGBId = -1 }, // bar-4 
                new HotbarButtonData { SNOSkill = Skills.None, ItemGBId = 0x622256D4 } // bar-5 - potion
                };
            }
            else
            {
                this.HotBarSkills = new HotbarButtonData[9] {     
                new HotbarButtonData { SNOSkill = (int)reader["skill_0"], ItemGBId = -1 }, // left-click
                new HotbarButtonData { SNOSkill = (int)reader["skill_1"], ItemGBId = -1 }, // right-click
                new HotbarButtonData { SNOSkill = Skills.None, ItemGBId = -1 }, // hidden-bar - left-click switch - which key??
                new HotbarButtonData { SNOSkill = Skills.None, ItemGBId = -1 }, // hidden-bar - right-click switch (press x ingame)
                new HotbarButtonData { SNOSkill = (int)reader["skill_5"], ItemGBId = -1 }, // bar-1
                new HotbarButtonData { SNOSkill = (int)reader["skill_4"], ItemGBId = -1 }, // bar-2
                new HotbarButtonData { SNOSkill = (int)reader["skill_3"], ItemGBId = -1 }, // bar-3
                new HotbarButtonData { SNOSkill = (int)reader["skill_2"], ItemGBId = -1 }, // bar-4 
                new HotbarButtonData { SNOSkill = Skills.None, ItemGBId = 0x622256D4 } // bar-5 - potion
                };
            }    
			
			
			//Current Active Skills part
			
			var query_as = string.Format("SELECT * from current_active_skills WHERE id_toon={0}", toon.D3EntityID.IdLow);
            var cmd_as = new SQLiteCommand(query_as, DBManager.Connection);
            var reader_as = cmd_as.ExecuteReader();

            if (!reader_as.HasRows)
            {
				var query_first_insert = string.Format("INSERT INTO  current_active_skills (id_toon,a_skill0,a_skill1,a_skill2,a_skill3,a_skill4,a_skill5) VALUES ({0},{1},{2},{3},{4},{5},{6} )", toon.D3EntityID.IdLow, this.CurrentActiveSkills[0], Skills.None, Skills.None, Skills.None, Skills.None, Skills.None, Skills.None);
                var cmd_first_insert = new SQLiteCommand(query_first_insert, DBManager.Connection);
                cmd_first_insert.ExecuteReader();
				Logger.Debug("SkillSet: Current Active Skill Seen for the First Time  Entry for {0}", toon.D3EntityID.IdLow);
				//Logger.Debug("CurrentActiveSkill {0}",reader_as["id_toon"]);
				this.ActiveSkills = new int[6]{this.CurrentActiveSkills[0],Skills.None,Skills.None,Skills.None,Skills.None,Skills.None};	
				
			}else 
			{
				this.ActiveSkills = new int[6]{(int)reader_as["a_skill0"],(int)reader_as["a_skill1"],(int)reader_as["a_skill2"],(int)reader_as["a_skill3"],(int)reader_as["a_skill4"],(int)reader_as["a_skill5"]};
				Logger.Debug("ActiveSkill {0}",reader_as["a_skill0"]);
			}
			

            this.PassiveSkills = new int[3] { -1, -1, -1 }; // setting passive skills here crashes the client, need to figure out the reason. /raist       
        }
Ejemplo n.º 28
0
        private static void LoadToons()
        {
            var query = "SELECT * from toons";
            var cmd = new SQLiteCommand(query, DBManager.Connection);
            var reader = cmd.ExecuteReader();

            if (!reader.HasRows) return;

            while (reader.Read())
            {
                var itemCreate = new Dictionary<uint, Item>();
                var databaseId = (ulong)reader.GetInt64(0);
                //TODO: Move this to toon class only create a toon with id and call load from DB
                var toon = new Toon(databaseId, reader.GetString(1), (int)reader.GetInt32(6), reader.GetByte(2), reader.GetByte(3), reader.GetByte(4), reader.GetInt64(5), (uint)reader.GetInt32(7), (int)reader.GetInt32(8),null);
                //add visual equipment
                //TODO: Load all visualEquipment at once
                D3.Hero.VisualItem[] visualItems = new D3.Hero.VisualItem[8];
                var vItemQuery =
                    string.Format("SELECT * from inventory WHERE toon_id = {0} and inventory_slot <> -1", databaseId);
                var itemCmd = new SQLiteCommand(vItemQuery, DBManager.Connection);
                var itemReader = itemCmd.ExecuteReader();
                if (itemReader.HasRows)
                {
                    while (itemReader.Read())
                    {
                        var slot = (int)itemReader.GetInt64(3);
                        var gbid = (int)itemReader.GetInt64(4);
                        visualItems[slot] = D3.Hero.VisualItem.CreateBuilder()
                            .SetGbid(gbid)
                            .SetEffectLevel(0)
                            .Build();
                    }

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

                //add inventory items
                var itemQuery =
                    string.Format("SELECT * from inventory WHERE toon_id = {0} and inventory_slot = -1", databaseId);
                itemCmd = new SQLiteCommand(itemQuery, DBManager.Connection);
                itemReader = itemCmd.ExecuteReader();
                if (itemReader.HasRows)
                {
                    uint count = 0;
                    toon.ItemsTable = new Dictionary<uint, KeyValuePair<ItemTable, Vector2D>>();
                    while (itemReader.Read())
                    {
                        var x = (int)itemReader.GetInt64(1);
                        var y = (int)itemReader.GetInt64(2);
                        var slot = (int)itemReader.GetInt64(3);
                        var gbid = (int)itemReader.GetInt64(4);
                        ItemTable it = ItemGenerator.GetItemDefinition(gbid);
                        Vector2D v2d = new Vector2D(x,y);
                        toon.ItemsTable.Add((uint)gbid,new KeyValuePair<ItemTable, Vector2D>(it,v2d));
                        count++;
                    }

                    toon.Items = itemCreate;
                }


                Toons.Add(databaseId, toon);
            }
        }
Ejemplo n.º 29
0
		public void UpdateAssignedSkill(int skillIndex, int SNOSkill,Toon toon)
		{
			//Fill DB with some entry if is the first time this toon try to put data on DB.
			switch(skillIndex)
			{
				case 0:
					Logger.Debug("UpdateAssignedSkill: index 0 {0}", SNOSkill);
				    var query_0 = string.Format("UPDATE current_active_skills SET a_skill0={1} WHERE id_toon={0} ", toon.D3EntityID.IdLow, SNOSkill);
                    var cmd_0 = new SQLiteCommand(query_0, DBManager.Connection);
                    cmd_0.ExecuteReader();	
					break;
				case 1:
                    Logger.Debug("UpdateAssignedSkill: index 1 {0}", SNOSkill);
                    var query_1 = string.Format("UPDATE current_active_skills SET a_skill1={1} WHERE id_toon={0} ", toon.D3EntityID.IdLow, SNOSkill);
                    var cmd_1 = new SQLiteCommand(query_1, DBManager.Connection);
                    cmd_1.ExecuteReader();
                    break;
                case 2:
                    Logger.Debug("UpdateAssignedSkill: index 2 {0}", SNOSkill);
                    var query_2 = string.Format("UPDATE current_active_skills SET a_skill2={1} WHERE id_toon={0} ", toon.D3EntityID.IdLow, SNOSkill);
                    var cmd_2 = new SQLiteCommand(query_2, DBManager.Connection);
                    cmd_2.ExecuteReader();
                    break;
                case 3:
                    Logger.Debug("UpdateAssignedSkill: index 3 {0}", SNOSkill);
                    var query_3 = string.Format("UPDATE current_active_skills SET a_skill3={1} WHERE id_toon={0} ", toon.D3EntityID.IdLow, SNOSkill);
                    var cmd_3 = new SQLiteCommand(query_3, DBManager.Connection);
                    cmd_3.ExecuteReader();
                    break;
                case 4:
                    Logger.Debug("UpdateAssignedSkill: index 4 {0}", SNOSkill);
                    var query_4 = string.Format("UPDATE current_active_skills SET a_skill4={1} WHERE id_toon={0} ", toon.D3EntityID.IdLow, SNOSkill);
                    var cmd_4 = new SQLiteCommand(query_4, DBManager.Connection);
                    cmd_4.ExecuteReader();
                    break;
                case 5:
                    Logger.Debug("UpdateAssignedSkill: index 5 {0}", SNOSkill);
                    var query_5 = string.Format("UPDATE current_active_skills SET a_skill5={1} WHERE id_toon={0} ", toon.D3EntityID.IdLow, SNOSkill);
                    var cmd_5 = new SQLiteCommand(query_5, DBManager.Connection);
                    cmd_5.ExecuteReader();
                    break;
			}
			
		}
Ejemplo n.º 30
0
        private static void LoadToons()
        {
            var query = "SELECT * from toons";
            var cmd = new SQLiteCommand(query, DBManager.Connection);
            var reader = cmd.ExecuteReader();

            if (!reader.HasRows) return;

            while (reader.Read())
            {
                var databaseId = (ulong)reader.GetInt64(0);
                //TODO: Move this to toon class only create a toon with id and call load from DB
                var toon = new Toon(databaseId, reader.GetString(1), (int)reader.GetInt32(6), reader.GetByte(2), reader.GetByte(3), reader.GetByte(4), reader.GetInt64(5), (uint)reader.GetInt32(7), (int)reader.GetInt32(8));
                //add visual equipment
                //TODO: Load all visualEquipment at once
                D3.Hero.VisualItem[] visualItems = new D3.Hero.VisualItem[8];
                var itemQuery = string.Format("SELECT * from inventory WHERE toon_id = {0}", databaseId);
                var itemCmd = new SQLiteCommand(itemQuery, DBManager.Connection);
                var itemReader = itemCmd.ExecuteReader();
                if (itemReader.HasRows)
                {
                    while (itemReader.Read())
                    {
                        var slot = (int)itemReader.GetInt64(3);
                        var gbid = (int)itemReader.GetInt64(4);
                        visualItems[slot] = D3.Hero.VisualItem.CreateBuilder()
                            .SetGbid(gbid)
                            .SetEffectLevel(0)
                            .Build();
                    }

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


                Toons.Add(databaseId, toon);
            }
        }
Ejemplo n.º 31
0
        public void UpdateSkills(int hotBarIndex, int SNOSkill, int SNORune, Toon toon)
        {
            Logger.Debug("Update index {0} skill {1} rune {2}", hotBarIndex, SNOSkill, SNORune);
            var dbToon = DBSessions.AccountSession.Get<DBToon>(toon.PersistentID);
            switch (hotBarIndex)
            {
                case 0:
                    dbToon.DBActiveSkills.Skill0 = SNOSkill;
                    dbToon.DBActiveSkills.Rune0 = SNORune;
                    break;
                case 1:
                    dbToon.DBActiveSkills.Skill1 = SNOSkill;
                    dbToon.DBActiveSkills.Rune1 = SNORune;
                    break;
                case 2:
                    dbToon.DBActiveSkills.Skill2 = SNOSkill;
                    dbToon.DBActiveSkills.Rune2 = SNORune;
                    break;
                case 3:
                    dbToon.DBActiveSkills.Skill3 = SNOSkill;
                    dbToon.DBActiveSkills.Rune3 = SNORune;
                    break;
                case 4:
                    dbToon.DBActiveSkills.Skill4 = SNOSkill;
                    dbToon.DBActiveSkills.Rune4 = SNORune;
                    break;
                case 5:
                    dbToon.DBActiveSkills.Skill5 = SNOSkill;
                    dbToon.DBActiveSkills.Rune5 = SNORune;
                    break;
            }
            DBSessions.AccountSession.SaveOrUpdate(dbToon.DBActiveSkills);
            DBSessions.AccountSession.Flush();

        }