Exemplo n.º 1
0
        public void execute()
        {
            const string METHODNAME = "execute";

            try
            {
                using (var session = NHibernateHelper.OpenSession())
                {
                    using (var transaction = session.BeginTransaction())
                    {
                        var user      = session.QueryOver <User>().Where(u => u.Id == player.UserID).SingleOrDefault();
                        var character = session.QueryOver <ComplexCharacter>().Where(cc => cc.UserId == user && cc.Name == player.Name).SingleOrDefault();
                        //player.UserID = user.Id;
                        //player.CharacterID = character.Id;

                        character.Level = (int)player.Stats.GetStat <Level>();
                        //Log.Debugformat(CLASSNAME+"post char l")
                        string position = player.Position.Serialize();
                        character.Position = position;
                        // Store stats
                        character.GenStats = player.GetCharData <GeneralStats>().SerializeStats();
                        character.Stats    = player.Stats.SerializeStats();
                        character.Elo      = Convert.ToInt32(player.GetCharData <EloKeeper>().GetElo());

                        //Store items
                        character.Items = player.Items.SerializeItems();

                        session.Save(character);
                        transaction.Commit();
                    }
                }
            }
            catch (Exception e)
            {
                DebugUtils.Logp(DebugUtils.Level.ERROR, CLASSNAME, METHODNAME, "Failed to Store player = " + e.Message);
            }
        }
Exemplo n.º 2
0
        public void AddCharInfo(CPlayerInstance player)
        {
            CharInfo info = new CharInfo()
            {
                Position = player.Position,
                Name     = player.Name,

                //stats
                GenStats  = player.GetCharData <GeneralStats>(),
                Stats     = player.Stats.GetMainStatsForEnemy(),
                Equipment = player.Items.Equipment.ToDictionary(item => (int)item.Key, item => (ItemData)(Item)item.Value),

                //race, sex, class, title, guild
                //effects - pvp flag, debuffs, buffs
                //movement speed for smoothing/calculation
                //action/emote walk, run, sit
            };

            info.GenStats.Gold           = -1;
            info.GenStats.Skulls         = -1;
            info.GenStats.InventorySlots = -1;
            AddSerializedParameter(info, ClientParameterCode.Object, false);
        }
Exemplo n.º 3
0
        public void execute()
        {
            using (var session = NHibernateHelper.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var character = session.QueryOver <ComplexCharacter>().Where(cc => cc.Id == player.ObjectId).List().FirstOrDefault();
                    if (character != null)
                    {
                        transaction.Commit();                         //close connection
                        player.Name = character.Name;

                        //Appearance

                        //Level
                        //player.Stats.SetStat<Level>(character.Level); is set in Stats

                        //Position
                        if (!string.IsNullOrEmpty(character.Position))
                        {
                            player.Position = Position.Deserialize(character.Position);
                        }
                        else
                        {
                            player.Position = new Position();
                        }

                        //Guild
                        //Titles
                        //Timers

                        var GenStats = player.GetCharData <GeneralStats>();
                        if (!string.IsNullOrEmpty(character.GenStats))
                        {
                            GenStats.DeserializeStats(character.GenStats);
                            ((ItemHolder)player.Items).SetInventorySlots(GenStats.InventorySlots);
                        }
                        else
                        {
                            GenStats.Experience          = RegionConstants.GetConstants(ConstantType.EXPERIENCE_FOR_LEVEL)[0];
                            GenStats.NextLevelExperience = RegionConstants.GetConstants(ConstantType.EXPERIENCE_FOR_LEVEL)[1];
                            GenStats.Battles             = 0;
                            GenStats.Win            = 0;
                            GenStats.Loss           = 0;
                            GenStats.Tie            = 0;
                            GenStats.Gold           = 0;
                            GenStats.Skulls         = 0;
                            GenStats.InventorySlots = 20;
                            ((ItemHolder)player.Items).SetInventorySlots(GenStats.InventorySlots);
                        }

                        player.GetCharData <EloKeeper>().UpdateElo(character.Elo);

                        if (!string.IsNullOrEmpty(character.Stats))
                        {
                            player.Stats.DeserializeStats(character.Stats);
                        }

                        //equipment
                        if (!string.IsNullOrEmpty(character.Items))
                        {
                            player.Items.DeserializeItems(character.Items);
                        }
                        else
                        {
                            player.Client.Log.DebugFormat("{0}", player.Items.AddItem(1));
                            player.Client.Log.DebugFormat("{0}", player.Items.AddItem(4));
                            player.Client.Log.DebugFormat("{0}", player.Items.AddItem(5));
                            player.Client.Log.DebugFormat("{0}", player.Items.AddItem(6));
                            player.Items.EquipItem(1);
                            player.Items.EquipItem(2);
                            player.Items.EquipItem(2);
                            player.Client.Log.DebugFormat("{0}", player.Items.AddItem(2));
                            player.Client.Log.DebugFormat("{0}", player.Items.AddItem(3));
                            player.Client.Log.DebugFormat("{0}", player.Items.AddItem(7));
                            player.Client.Log.DebugFormat("{0}", player.Items.AddItem(2));
                        }
                        player.Stats.SetStat <CurrHealth>(player.Stats.GetStat <MaxHealth>());
                    }
                    else
                    {
                        transaction.Commit();
                        player.Client.Log.FatalFormat("{0} - Should not reach - Character not found in database", CLASSNAME);
                    }
                }
            }
        }