Example #1
0
        public Player(Client client, bool saveInventory = true)
            : base(client.Manager, client.Character.ObjectType)
        {
            var settings = Manager.Resources.Settings;
            var gameData = Manager.Resources.GameData;

            _client = client;

            // found in player.update partial
            Sight           = new Sight(this);
            _clientEntities = new UpdatedSet(this);

            _accountId      = new SV <int>(this, StatsType.AccountId, client.Account.AccountId, true);
            _experience     = new SV <int>(this, StatsType.Experience, client.Character.Experience, true);
            _experienceGoal = new SV <int>(this, StatsType.ExperienceGoal, 0, true);
            _level          = new SV <int>(this, StatsType.Level, client.Character.Level);
            _currentFame    = new SV <int>(this, StatsType.CurrentFame, client.Account.Fame, true);
            _fame           = new SV <int>(this, StatsType.Fame, client.Character.Fame, true);
            _fameGoal       = new SV <int>(this, StatsType.FameGoal, 0, true);
            _stars          = new SV <int>(this, StatsType.Stars, 0);
            _guild          = new SV <string>(this, StatsType.Guild, "");
            _guildRank      = new SV <int>(this, StatsType.GuildRank, -1);
            _credits        = new SV <int>(this, StatsType.Credits, client.Account.Credits, true);
            _nameChosen     = new SV <bool>(this, StatsType.NameChosen, client.Account.NameChosen, false, v => _client.Account?.NameChosen ?? v);
            _texture1       = new SV <int>(this, StatsType.Texture1, client.Character.Tex1);
            _texture2       = new SV <int>(this, StatsType.Texture2, client.Character.Tex2);
            _skin           = new SV <int>(this, StatsType.Skin, 0);
            _glow           = new SV <int>(this, StatsType.Glow, 0);
            _mp             = new SV <int>(this, StatsType.MP, client.Character.MP);
            _hasBackpack    = new SV <bool>(this, StatsType.HasBackpack, client.Character.HasBackpack, true);
            _oxygenBar      = new SV <int>(this, StatsType.OxygenBar, -1, true);
            _rank           = new SV <int>(this, StatsType.Rank, client.Account.Rank);
            _admin          = new SV <int>(this, StatsType.Admin, client.Account.Admin ? 1 : 0);

            Name             = client.Account.Name;
            HP               = client.Character.HP;
            ConditionEffects = 0;

            var s = (ushort)client.Character.Skin;

            if (gameData.Skins.Keys.Contains(s))
            {
                SetDefaultSkin(s);
                SetDefaultSize(gameData.Skins[s].Size);
            }

            var guild = Manager.Database.GetGuild(client.Account.GuildId);

            if (guild?.Name != null)
            {
                Guild     = guild.Name;
                GuildRank = client.Account.GuildRank;
            }

            PetId = client.Character.PetId;

            HealthPots = new ItemStacker(this, 254, 0x0A22,
                                         client.Character.HealthStackCount, settings.MaxStackablePotions);
            MagicPots = new ItemStacker(this, 255, 0x0A23,
                                        client.Character.MagicStackCount, settings.MaxStackablePotions);
            Stacks = new ItemStacker[] { HealthPots, MagicPots };

            // inventory setup
            DbLink    = new DbCharInv(Client.Account, Client.Character.CharId);
            Inventory = new Inventory(this,
                                      Utils.ResizeArray(
                                          (DbLink as DbCharInv).Items
                                          .Select(_ => (_ == 0xffff || !gameData.Items.ContainsKey(_)) ? null : gameData.Items[_])
                                          .ToArray(),
                                          20));
            if (!saveInventory)
            {
                DbLink = null;
            }

            Inventory.InventoryChanged += (sender, e) => Stats.ReCalculateValues(e);
            SlotTypes = Utils.ResizeArray(
                gameData.Classes[ObjectType].SlotTypes,
                20);
            Stats = new StatsManager(this);

            Manager.Database.IsMuted(client.IP)
            .ContinueWith(t =>
            {
                Muted = !Client.Account.Admin && t.IsCompleted && t.Result;
            });

            Manager.Database.IsLegend(AccountId)
            .ContinueWith(t =>
            {
                Glow = t.Result ? 1 : -1;
            });
        }
Example #2
0
        public Player(Client client, bool saveInventory = true)
            : base(client.Manager, client.Character.ObjectType)
        {
            var settings = Manager.Resources.Settings;
            var gameData = Manager.Resources.GameData;

            _client = client;

            // found in player.update partial
            Sight           = new Sight(this);
            _clientEntities = new UpdatedSet(this);

            _accountId      = new SV <int>(this, StatsType.AccountId, client.Account.AccountId, true);
            _experience     = new SV <int>(this, StatsType.Experience, client.Character.Experience, true);
            _experienceGoal = new SV <int>(this, StatsType.ExperienceGoal, 0, true);
            _level          = new SV <int>(this, StatsType.Level, client.Character.Level);
            _statpoint      = new SV <int>(this, StatsType.StatPoint, client.Character.StatPoint);
            _runestone      = new SV <ushort>(this, StatsType.RuneStone, client.Character.RuneStone);

            _currentFame = new SV <int>(this, StatsType.CurrentFame, client.Account.Fame, true);
            _fame        = new SV <int>(this, StatsType.Fame, client.Character.Fame, true);
            _fameGoal    = new SV <int>(this, StatsType.FameGoal, 0, true);
            _stars       = new SV <int>(this, StatsType.Stars, 0);
            _guild       = new SV <string>(this, StatsType.Guild, "");
            _guildRank   = new SV <int>(this, StatsType.GuildRank, -1);
            _credits     = new SV <int>(this, StatsType.Credits, client.Account.Credits, true);
            _nameChosen  = new SV <bool>(this, StatsType.NameChosen, client.Account.NameChosen, false, v => _client.Account?.NameChosen ?? v);
            _texture1    = new SV <int>(this, StatsType.Texture1, client.Character.Tex1);
            _texture2    = new SV <int>(this, StatsType.Texture2, client.Character.Tex2);
            _skin        = new SV <int>(this, StatsType.Skin, 0);
            _glow        = new SV <int>(this, StatsType.Glow, 0);
            _mp          = new SV <int>(this, StatsType.MP, client.Character.MP);
            _hasBackpack = new SV <bool>(this, StatsType.HasBackpack, client.Character.HasBackpack, true);
            _xpBoosted   = new SV <bool>(this, StatsType.XPBoost, client.Character.XPBoostTime != 0, true);
            _oxygenBar   = new SV <int>(this, StatsType.OxygenBar, -1, true);
            _rank        = new SV <int>(this, StatsType.Rank, client.Account.Rank);
            _admin       = new SV <int>(this, StatsType.Admin, client.Account.Admin ? 1 : 0);
            _tokens      = new SV <int>(this, StatsType.Tokens, client.Account.Tokens, true);

            Name             = client.Account.Name;
            HP               = client.Character.HP;
            ConditionEffects = 0;

            XPBoostTime = client.Character.XPBoostTime;
            LDBoostTime = client.Character.LDBoostTime;
            LTBoostTime = client.Character.LTBoostTime;

            var s = (ushort)client.Character.Skin;

            if (gameData.Skins.Keys.Contains(s))
            {
                SetDefaultSkin(s);
                SetDefaultSize(gameData.Skins[s].Size);
            }

            var guild = Manager.Database.GetGuild(client.Account.GuildId);

            if (guild?.Name != null)
            {
                Guild     = guild.Name;
                GuildRank = client.Account.GuildRank;
            }

            HealthPots = new ItemStacker(this, 254, 0x0A22,
                                         client.Character.HealthStackCount, settings.MaxStackablePotions);
            MagicPots = new ItemStacker(this, 255, 0x0A23,
                                        client.Character.MagicStackCount, settings.MaxStackablePotions);
            Stacks = new ItemStacker[] { HealthPots, MagicPots };

            // inventory setup
            DbLink    = new DbCharInv(Client.Account, Client.Character.CharId);
            Inventory = new Inventory(this,
                                      Utils.ResizeArray(
                                          (DbLink as DbCharInv).Items
                                          .Select(_ => (_ == 0xffff || !gameData.Items.ContainsKey(_)) ? null : gameData.Items[_])
                                          .ToArray(),
                                          settings.InventorySize)
                                      );
            if (!saveInventory)
            {
                DbLink = null;
            }

            Inventory.InventoryChanged += (sender, e) => Stats.ReCalculateValues(e);
            SlotTypes = Utils.ResizeArray(
                gameData.Classes[ObjectType].SlotTypes,
                settings.InventorySize);
            Stats = new StatsManager(this);

            // set size of player if using set skin
            var skin = (ushort)Skin;

            if (gameData.SkinTypeToEquipSetType.ContainsKey(skin))
            {
                var setType = gameData.SkinTypeToEquipSetType[skin];
                var ae      = gameData.EquipmentSets[setType].ActivateOnEquipAll
                              .SingleOrDefault(e => e.SkinType == skin);

                if (ae != null)
                {
                    Size = ae.Size;
                }
            }

            // override size
            if (Client.Account.Size > 0)
            {
                Size = Client.Account.Size;
            }

            Manager.Database.IsMuted(client.IP)
            .ContinueWith(t =>
            {
                Muted = !Client.Account.Admin && t.IsCompleted && t.Result;
            });

            Manager.Database.IsLegend(AccountId)
            .ContinueWith(t =>
            {
                Glow = t.Result && client.Account.GlowColor == 0
                        ? 0xFF0000
                        : client.Account.GlowColor;
            });
        }