Esempio n. 1
0
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server)
        {
            int casterID = 0, targetID = 0, spellID = 0, itemID = 0, castLevel = 0;

            stream.Read(out itemID);
            stream.Read(out casterID);
            stream.Read(out targetID);
            stream.Read(out spellID);
            stream.Read(out castLevel);

            Vob  itemVob = null;
            Item item    = null;

            Vob   casterVob = null;
            Spell spell     = null;

            NPCProto caster = null;
            Vob      target = null;

            sWorld.VobDict.TryGetValue(casterID, out casterVob);
            sWorld.VobDict.TryGetValue(itemID, out itemVob);

            if (casterVob == null)
            {
                throw new Exception("Caster was not found!");
            }
            if (!(casterVob is NPCProto))
            {
                throw new Exception("Caster was not a npcproto " + casterVob);
            }
            caster = (NPCProto)casterVob;
            if (targetID != 0)
            {
                sWorld.VobDict.TryGetValue(targetID, out target);
            }

            Spell.SpellDict.TryGetValue(spellID, out spell);
            if (spell == null)
            {
                throw new Exception("Spell can not be null!");
            }


            Scripting.Objects.Vob sT = (target == null) ? null : target.ScriptingVob;


            if (itemVob != null)
            {
                item = (Item)itemVob;
                if (item.ItemInstance.Flags.HasFlag(Flags.ITEM_MULTI))
                {
                    item.Amount -= 1;
                }
            }

            int manaInvested = 0;
            int realLevel    = (spell.processMana.Length > castLevel + 1) ? castLevel : spell.processMana.Length - 1;

            for (int i = 0; i <= realLevel; i++)
            {
                manaInvested += spell.processMana[i];
            }
            caster.ScriptingNPC.MP -= manaInvested;

            Scripting.Objects.Character.NPCProto.isOnCastSpell(
                caster.ScriptingNPC, spell.ScriptingProto, sT);



            Write(caster, item, target, spell, packet.guid);
        }
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server)
        {
            Vec3f locHit = null, flydir = null;
            int   victim = 0, attacker = 0, weaponMode = 0, spellID = 0, weapon = 0;
            float fallDownDistanceY = 0.0f;

            byte sendFlags, damageMode;

            stream.Read(out victim);
            stream.Read(out damageMode);
            stream.Read(out sendFlags);

            if ((sendFlags & 1) == 1)
            {
                stream.Read(out locHit);
            }
            if ((sendFlags & 2) == 2)
            {
                stream.Read(out flydir);
            }
            if ((sendFlags & 4) == 4)
            {
                stream.Read(out attacker);
            }
            if ((sendFlags & 8) == 8)
            {
                stream.Read(out weaponMode);
            }
            if ((sendFlags & 16) == 16)
            {
                stream.Read(out spellID);
            }
            if ((sendFlags & 32) == 32)
            {
                stream.Read(out weapon);
            }
            if ((sendFlags & 64) == 64)
            {
                stream.Read(out fallDownDistanceY);
            }

            NPCProto vicProto = (NPCProto)sWorld.VobDict[victim];
            Vob      attProto = null;

            Scripting.Objects.Vob attackerScriptProto = null;

            if (attacker != 0)
            {
                attProto            = sWorld.VobDict[attacker];
                attackerScriptProto = attProto.ScriptingVob;
            }

            Item weaponIt = null;

            Scripting.Objects.Item weaponScriptItem = null;
            if (weapon != 0)
            {
                weaponIt         = (Item)sWorld.VobDict[weapon];
                weaponScriptItem = weaponIt.ScriptingProto;
            }


            Spell spell = null;

            Scripting.Objects.Spell scriptSpell = null;
            if (spellID > 100)
            {
                Spell.SpellDict.TryGetValue(spellID, out spell);
                if (spell != null)
                {
                    scriptSpell = spell.ScriptingProto;
                }
            }

            Scripting.Objects.Character.NPCProto.isOnDamage(vicProto.ScriptingNPC, (DamageTypes)damageMode, locHit, flydir, attackerScriptProto, weaponMode, scriptSpell, weaponScriptItem, fallDownDistanceY);
            Write(vicProto, (DamageTypes)damageMode, locHit, flydir, attProto, weaponMode, spell, weaponIt, fallDownDistanceY, packet.guid);
        }