Beispiel #1
0
        public Character(System.IO.BinaryReader reader, bool sentFromServer)
            : base(reader, sentFromServer)
        {
            myHitPoints = reader.ReadInt16();
            myManaLevel = reader.ReadInt16();

            ushort attribCount = reader.ReadUInt16();

            for (int i = 0; i < attribCount; ++i)
            {
                myBaseAttributes.Add(CharAttribute.GetByID(reader.ReadUInt16()), reader.ReadByte());
            }

            ushort skillCount = reader.ReadUInt16();

            for (int i = 0; i < skillCount; ++i)
            {
                myBaseSkills.Add(CharSkill.GetByID(reader.ReadUInt16()), reader.ReadByte());
            }

            myCurrentWalkDirection = myFacingDirection = (WalkDirection)reader.ReadByte();

            if (!sentFromServer)
            {
                Inventory = new Inventory(this, reader);
            }
        }
Beispiel #2
0
        private void ReceiveCharacterCreate(BinaryReader reader)
        {
            Nickname = reader.ReadString();

            PlayerEntity = new Player();

            ushort attribCount = reader.ReadUInt16();

            for (int i = 0; i < attribCount; ++i)
            {
                CharAttribute attrib = CharAttribute.GetByID(reader.ReadUInt16());
                int           value  = reader.ReadByte();

                PlayerEntity.SetBaseAttributeLevel(attrib, value);
            }

            ushort skillCount = reader.ReadUInt16();

            for (int i = 0; i < skillCount; ++i)
            {
                CharSkill skill = CharSkill.GetByID(reader.ReadUInt16());
                int       value = reader.ReadByte();

                PlayerEntity.SetBaseSkillLevel(skill, value);
            }

            SendCharacterCreate();
        }
Beispiel #3
0
        protected override void OnRegisterNetworkedUpdateHandlers()
        {
            base.OnRegisterNetworkedUpdateHandlers();

            RegisterNetworkedUpdateHandler("StartWalking", delegate(byte[] payload)
            {
                StartWalking(
                    (WalkDirection)payload[0],
                    BitConverter.ToUInt64(payload, 1),
                    new Vector2d(
                        BitConverter.ToDouble(payload, 1 + sizeof(UInt64)),
                        BitConverter.ToDouble(payload, 1 + sizeof(UInt64) + sizeof(Double))
                        )
                    );
            });

            RegisterNetworkedUpdateHandler("StopWalking", delegate(byte[] payload)
            {
                StopWalking(
                    new Vector2d(BitConverter.ToDouble(payload, 0),
                                 BitConverter.ToDouble(payload, sizeof(Double))
                                 )
                    );
            });

            RegisterNetworkedUpdateHandler("SpellCast", delegate(byte[] payload)
            {
                Cast();
            });

            RegisterNetworkedUpdateHandler("SetHitPoints", delegate(byte[] payload)
            {
                HitPoints = BitConverter.ToInt32(payload, 0);
            });

            RegisterNetworkedUpdateHandler("Die", delegate(byte[] payload)
            {
                uint attackerID       = BitConverter.ToUInt32(payload, 0);
                uint weaponID         = BitConverter.ToUInt32(payload, 4);
                DamageType damageType = (DamageType)BitConverter.ToUInt16(payload, 6);

                Entity attacker = null;
                Entity weapon   = null;

                if (attackerID != 0xFFFFFFFF)
                {
                    attacker = Map.GetEntity(attackerID);
                }

                if (weaponID != 0xFFFFFFFF)
                {
                    weapon = Map.GetEntity(weaponID);
                }

                OnDie(attacker, weapon, damageType);

                if (Killed != null)
                {
                    Killed(this, new KilledEventArgs(attacker, weapon, damageType));
                }
            });

            RegisterNetworkedUpdateHandler("Resurrect", delegate(byte[] payload) {
                Resurrect();
            });

            RegisterNetworkedUpdateHandler("SetManaLevel", delegate(byte[] payload)
            {
                ManaLevel = BitConverter.ToInt32(payload, 0);
            });

            RegisterNetworkedUpdateHandler("SetBaseAttribute", delegate(byte[] payload)
            {
                UInt16 id   = BitConverter.ToUInt16(payload, 0);
                byte amount = payload[2];

                SetBaseAttributeLevel(CharAttribute.GetByID(id), amount);
            });

            RegisterNetworkedUpdateHandler("SetBaseSkill", delegate(byte[] payload)
            {
                UInt16 id   = BitConverter.ToUInt16(payload, 0);
                byte amount = payload[2];

                SetBaseSkillLevel(CharSkill.GetByID(id), amount);
            });

            RegisterNetworkedUpdateHandler("EquipSpell", delegate(byte[] payload)
            {
                MemoryStream stream = new MemoryStream(payload);
                BinaryReader reader = new BinaryReader(stream);
                myEquippedSpell     = Spell.Create(SpellInfo.Get(reader.ReadUInt16()), reader.ReadDouble());
                myOrbEquipped       = reader.ReadBoolean();
                reader.Close();
            });

            RegisterNetworkedUpdateHandler("UnEquipSpell", delegate(byte[] payload)
            {
                myEquippedSpell = null;
                myOrbEquipped   = false;
            });
        }