示例#1
0
        public ZonePlayer(short entityId, Data.Character toon, ushort zoneId, Client client)
            : base(entityId, toon.Name, toon.Surname, toon.X, toon.Y, toon.Z, toon.Heading.Value)
        {
            this.Client = client;
            _acctId = toon.AccountID;
            _charId = toon.CharacterID;
            _acctStatus = toon.Account.Status;
            _connState = ZoneConnectionState.Connecting;

            // TODO: change storage to the cached profile

            _pp.ZoneId = (ushort)zoneId;
            this.Class = toon.Class.Value;
            this.Level = toon.CharLevel;
            _pp.XP = toon.XP;   // Bypass property setter to avoid packet sending
            _pp.Points = toon.PracticePoints.Value;

            _pp.STR = (uint)toon.STR.Value;
            _pp.STA = (uint)toon.STA.Value;
            _pp.DEX = (uint)toon.DEX.Value;
            _pp.AGI = (uint)toon.AGI.Value;
            _pp.INT = (uint)toon.INT.Value;
            _pp.WIS = (uint)toon.WIS.Value;
            _pp.CHA = (uint)toon.CHA.Value;

            this.Race = toon.Race.Value;
            _baseRace = toon.Race.Value;
            this.Gender = toon.Gender.Value;
            _baseGender = toon.Gender.Value;
            this.Deity = (uint)toon.Deity.Value;
            _hairColor = toon.HairColor.Value;
            _hairStyle = toon.HairStyle.Value;
            _beardColor = toon.BeardColor.Value;
            _beard = toon.Beard.Value;
            _eyeColor1 = toon.EyeColor1.Value;
            _eyeColor2 = toon.EyeColor2.Value;
            _luclinFace = toon.Face.Value;
            this.GMStatus = toon.GMStatus;
            this.Platinum = toon.Platinum;
            this.Gold = toon.Gold;
            this.Silver = toon.Silver;
            this.Copper = toon.Copper;

            _pp.Birthday = Utility.TimeTFromDateTime(toon.CreatedDate);
            _pp.LastLogin = _pp.Birthday;
            //_pp.TimePlayedMin = 0;
            _pp.HungerLevel = (uint)toon.HungerLevel.Value;
            _pp.ThirstLevel = (uint)toon.ThirstLevel.Value;
            _pp.Languages = Encoding.ASCII.GetBytes(toon.Languages);

            if (this.X == -1 && this.Y == -1 && this.Z == -1)  // -1 is what these were set to on char creation
            {
                // set to zone safe points
                this.X = toon.Zone.SafeX;
                this.Y = toon.Zone.SafeY;
                this.Z = toon.Zone.SafeZ;

                _log.Debug("Char coords set to safe points");
            }

            // TODO: factions

            // TODO: old emu has code for invalid Z position fix

            _invMgr = new InventoryManager(toon.InventoryItems, this);
            _invMgr.ItemChargeUsed += new EventHandler<ItemChargeUseEventArgs>(InvMgr_ItemChargeUsed);
            _invMgr.ItemMoved += new EventHandler<ItemMoveEventArgs>(InvMgr_ItemMoved);

            // TODO: guild stuff
            _pp.GuildRank = (byte)Guild.GuildRank.None;   // TODO: implement guild tables and fetch this live

            _size = Mob.GetSize((CharRaces)_race);

            // TODO: AAs

            // Spells
            foreach (ScribedSpell ss in toon.ScribedSpells)
                _pp.SpellBook[ss.SlotID] = ss.SpellID;

            foreach (MemorizedSpell ms in toon.MemorizedSpells) {
                _pp.MemSpells[ms.SlotID] = ms.SpellID;
                _memdSpells[ms.SlotID] = ms.Spell;
            }

            // TODO: buffs?
            for (int i = 0; i < Character.MAX_BUFF; i++)    // blank out the buffs spell id
                Buffer.BlockCopy(BitConverter.GetBytes((uint)Spell.BLANK_SPELL), 0, _pp.BuffsBlob, (20 * i) + 4, 4);
                //_pp.BuffsBlob[i] = 0xFF;

            // TODO: binds
            _pp.Binds[0].ZoneId = (uint)zoneId;
            _pp.Binds[0].X = this.X;
            _pp.Binds[0].Y = this.Y;
            _pp.Binds[0].Z = this.Z;
            _pp.Binds[0].Heading = this.Heading;

            _pp.Mana = 0u;  // TODO: Mana
            _pp.HP = (uint)toon.HP.Value;
            _curHP = toon.HP.Value; // Bypass property settors to avoid packet sending

            CalcStatModifiers();    // Calculate stats (ac, attack, hp, bonuses, etc.)

            if (_pp.HP <= 0) {
                _pp.HP = (uint)this.MaxHP;  // If they were dead, let's set things back to full
                _curHP = this.MaxHP;
            }

            _pp.Endurance = _maxEndurance;

            // TODO: group shit

            // TODO: once zone init is coded, do underworld checks

            // Skills
            for (int i = 0; i < toon.Skills.Length; i++)
                _pp.Skills[i] = (uint)toon.Skills[i];   // may want to turn the db representation into an nchar if skill levels get > 255

            // TODO: tribute
            _pp.TributeTimeRemaining = uint.MaxValue;

            InitPlayerProfile();

            // Init timers
            int autoSaveInterval = WorldServer.ServerConfig.AutosaveIntervalSec * 1000;
            _autoSaveTimer = new Timer(new TimerCallback(AutosaveTimerCallback), null, autoSaveInterval, autoSaveInterval);
            _ldTimer = new SimpleTimer(0);
            _deadTimer = new SimpleTimer(0);
            _hpUpdateTimer = new SimpleTimer(0);
            _campTimer = new SimpleTimer(0);

            _msgMgr = new MessagingManager(this);
        }
示例#2
0
 public void Dispose()
 {
     _autoSaveTimer.Dispose();
     _invMgr = null;
 }
示例#3
0
        internal static CharacterSelect GetCharSelectData(int acctId)
        {
            CharacterSelect charSel = new CharacterSelect();

            byte[] noneBuf = Encoding.ASCII.GetBytes("<none>");
            for (int i = 0; i < 10; i++)
                Buffer.BlockCopy(noneBuf, 0, charSel.Name, i * 64, 6);

            using (EmuDataContext dbCtx = new EmuDataContext())
            {
                DataLoadOptions dlo = new DataLoadOptions();
                dlo.LoadWith<Character>(c => c.InventoryItems);
                dlo.LoadWith<InventoryItem>(ii => ii.Item);
                dbCtx.LoadOptions = dlo;

                var characters = from c in dbCtx.Characters
                                 where c.AccountID == acctId
                                 select c;

                int charIdx = 0;
                foreach (Character c in characters) {
                    // character info
                    if (c.Name.Length < 6)
                        Buffer.BlockCopy(Encoding.ASCII.GetBytes(c.Name + "\0\0"), 0, charSel.Name, charIdx * 64, c.Name.Length + 2);
                    else
                        Buffer.BlockCopy(Encoding.ASCII.GetBytes(c.Name), 0, charSel.Name, charIdx * 64, c.Name.Length);
                    charSel.Level[charIdx] = (byte)c.CharLevel;
                    charSel.Class[charIdx] = (byte)c.Class;
                    charSel.Race[charIdx] = (int)c.Race;
                    charSel.Gender[charIdx] = (byte)c.Gender;
                    charSel.Deity[charIdx] = (int)c.Deity;
                    charSel.Zone[charIdx] = (int)c.ZoneID;
                    charSel.HairColor[charIdx] = (byte)c.HairColor;
                    charSel.BeardColor[charIdx] = (byte)c.BeardColor;
                    charSel.EyeColor1[charIdx] = (byte)c.EyeColor1;
                    charSel.EyeColor2[charIdx] = (byte)c.EyeColor2;
                    charSel.Hair[charIdx] = (byte)c.HairStyle;
                    charSel.Beard[charIdx] = (byte)c.Beard;

                    // Get equiped items
                    if (c.InventoryItems.Count > 0) {
                        InventoryManager invMgr = new InventoryManager(c.InventoryItems);

                        for (int equipType = 0; equipType < MAX_EQUIPABLES; equipType++) {
                            InventoryItem ii = invMgr[(int)InventoryManager.GetEquipableSlot((EquipableType)equipType)];
                            if (ii == null)
                                continue;

                            charSel.Equip[charIdx * equipType] = ii.Item.Material;
                            charSel.EquipColors[charIdx * equipType] = ii.Item.Color ?? 0;   // TODO: tints (LoY era)

                            // Held items (set the idfile)
                            if (equipType == (int)EquipableType.Primary || equipType == (int)EquipableType.Secondary) {
                                if (ii.Item.IDFile.Length > 2) {
                                    int idFile = int.Parse(ii.Item.IDFile.Substring(2));
                                    if (equipType == (int)EquipableType.Primary)
                                        charSel.Primary[charIdx] = idFile;
                                    else
                                        charSel.Secondary[charIdx] = idFile;
                                }
                            }
                        }
                    }

                    charIdx++;
                }
            }

            return charSel;
        }