Exemplo n.º 1
0
        public static void newMagicAttack(Player p, Entity target, int id, bool ancients)
        {
            int index = getSpellIndex(p, id, ancients);
            bool autoCasting = p.getTemporaryAttribute("autoCasting") != null;
            bool fakeNPC = target != null && target is Npc && ((Npc)target).getId() == 0;
            Entity lastAutocastEntity = null;
            bool frozen = false;
            if (index == -1) {
                return;
            }
            if (p.getTarget() == null) {
                if (autoCasting) {
                    if (Location.inMultiCombat(p.getLocation())) {
                        lastAutocastEntity = (Entity) p.getTemporaryAttribute("autocastEntity") == null ? null : (Entity) p.getTemporaryAttribute("autocastEntity");
                        if (lastAutocastEntity == null || lastAutocastEntity is Player) {
                            p.removeTemporaryAttribute("autoCasting");
                            Combat.resetCombat(p, 1);
                            return;
                        }
                        if (hitsMulti(p, index)) {
                            Location location = (Location)p.getTemporaryAttribute("autocastLocation");
                            Entity newTarget = new Npc(0);
                            newTarget.setLocation(location);
                            p.setTarget(newTarget);
                            newMagicAttack(p, newTarget, id, ancients);
                            return;
                        }
                    } else {
                        p.removeTemporaryAttribute("autoCasting");
                        Combat.resetCombat(p, 1);
                        return;
                    }
                } else {
                    p.removeTemporaryAttribute("autoCasting");
                    Combat.resetCombat(p, 1);
                    return;
                }
            } else {
                if (!canCastSpell(p, target, index, fakeNPC)) {
                    p.removeTemporaryAttribute("autoCasting");
                    Combat.resetCombat(p, 1);
                    return;
                }
            }
            int distance = 8;
            if (target is Player) {
                if (((Player)target).getSprites().getPrimarySprite() != -1) {
                    distance = 8;
                }
            }
            if (!fakeNPC) { // we're actually attacking a real npc/player
                if (!p.getLocation().withinDistance(target.getLocation(), distance)) {
                    p.getFollow().setFollowing(target);

                    Event attemptMagicAttackEvent = new Event(500);
                    int attemptMagicAttackCounter = 0;
                    attemptMagicAttackEvent.setAction(() => {
                        if (p.getLocation().withinDistance(target.getLocation(), distance) && p.getTarget() != null) {
                            attemptMagicAttackEvent.stop();
                            newMagicAttack(p, target, id, ancients);
                            return;
                        }
                        attemptMagicAttackCounter++;
                        if (attemptMagicAttackCounter >= 12)
                        {
                            attemptMagicAttackEvent.stop();
                        }
                    });
                    Server.registerEvent(attemptMagicAttackEvent);
                    return;
                }
            }
            int timeSinceLastCast = autoCasting ? 3500 : 2000;
            if (Environment.TickCount - p.getLastMagicAttack() < timeSinceLastCast) {
                p.getWalkingQueue().resetWalkingQueue();
                //return;
            }
            int time = p.getLastCombatType().Equals(Combat.CombatType.MAGE) ? 1550 : 600;
            if (Environment.TickCount - p.getLastAttack() <  time) {
                int delay = p.getLastCombatType().Equals(Combat.CombatType.MAGE) ? 1350 : 800;
                Event attemptMagicAttackEvent = new Event(500);
                attemptMagicAttackEvent.setAction(() => {
                    if (Environment.TickCount - p.getLastAttack() > delay) {
                        attemptMagicAttackEvent.stop();
                        newMagicAttack(p, target, id, ancients);
                    }
                });
                Server.registerEvent(attemptMagicAttackEvent);

                p.getWalkingQueue().resetWalkingQueue();
                p.getPackets().clearMapFlag();
                p.setLastCombatType(Combat.CombatType.MAGE);
                return;
            }
            if (fakeNPC && !monsterInArea(p, target)) {
                p.removeTemporaryAttribute("autoCasting");
                Combat.resetCombat(p, 1);
                return;
            }
            int endGfx = END_GFX[index];
            double damage = misc.random(CombatFormula.getMagicHit(p, target, getSpellMaxHit(p, index)));
            bool mp = false;
            bool magicProtect = mp;
            if (target is Player) {
                mp = ((Player) target).getPrayers().getHeadIcon() == PrayerData.MAGIC;
            }
            if (magicProtect) {
                damage *= 0.60;
            }
            if (p.getEquipment().getItemInSlot(ItemData.EQUIP.WEAPON) == 8841) {
                damage *= 1.10; // void mace 10% hit increase.
            }
            if (damage == 0 && index != 41 && index != 42 && index != 43 && index != 44 && index != 45 && index != 46 && index != 47) {
                endGfx = 85;
            }
            if (!deleteRunes(p, RUNES[index], RUNE_AMOUNTS[index])) {
                p.setTarget(null);
                return;
            }
            p.getFollow().setFollowing(null);
            p.getWalkingQueue().resetWalkingQueue();
            p.getPackets().clearMapFlag();
            p.setFaceLocation(target.getLocation());
            if (HANDS_GFX[index] != -1) {
                p.setLastGraphics(new Graphics(HANDS_GFX[index], 0 , getStartingGraphicHeight(index)));
            }
            p.setLastAnimation(new Animation(SPELL_ANIM[index]));
            p.getPackets().closeInterfaces();
            if (target is Player) {
                ((Player) target).getPackets().closeInterfaces();
            }
            target.setAttacker(p);
            p.setTarget(target);
            target.setLastAttacked(Environment.TickCount);
            p.setLastAttack(Environment.TickCount);
            p.setLastMagicAttack(Environment.TickCount);
            p.setCombatTurns(p.getAttackSpeed());
            Combat.setSkull(p, target);
            if (damage > 0) {
                frozen = freezeTarget(index, target);
                if (!frozen && index == 31) {
                    endGfx = 1677;
                }
            }
            if (AIR_GFX[index] != -1 || ((index == 31 || index == 27) && target is Player && ((Player)target).getWalkingQueue().isRunning())) {
                sendProjectile(index, target, p);
            }
            if (damage > target.getHp()) {
                damage = target.getHp();
            }
            if (index == 47 && misc.random(2) == 0) {
                endGfx = 85;
            }
            Combat.checkIfWillDie(target, damage);
            Event doMagicAttackEvent = new Event(getSpellHitDelay(index));
            doMagicAttackEvent.setAction(() => {
                doMagicAttackEvent.stop();
                if (p == null || p.isDead() || !fakeNPC && (target.isDead() || target.isHidden() || target.isDestroyed())) {
                    return;
                }
                if (target.isAutoRetaliating() && target.getTarget() == null && damage > 0) {
                    if (target is Npc) {
                    } else {
                        if (((Player) target).getTemporaryAttribute("autoCastSpell") != null) {
                            int autoCastSpell = (int)((Player) target).getTemporaryAttribute("autoCastSpell");
                            ((Player) target).setTemporaryAttribute("autoCasting", true);
                            target.setTarget(p);
                            MagicCombat.newMagicAttack((Player) target, p, autoCastSpell, ((Player) target).getTemporaryAttribute("autoCastAncients") != null);
                        }
                    }
                    target.getFollow().setFollowing(p);
                    target.setEntityFocus(p.getClientIndex());
                    if ((target.getCombatTurns() <= (target.getAttackSpeed() / 2) || target.getCombatTurns() >= (target.getAttackSpeed()))) {
                        target.setCombatTurns(target.getAttackSpeed() / 2);
                    }
                    target.setTarget(p);
                    if (target is Player) {
                        ((Player) target).getWalkingQueue().resetWalkingQueue();
                        ((Player) target).getPackets().clearMapFlag();
                    }
                }
                addMagicXp(p, target, damage, index, true);
                target.setLastGraphics(new Graphics(endGfx, 0, getGroundHeight(index, endGfx)));
                if (index == 47 && endGfx != 85) { // teleblock
                    if (target is Player) {
                        teleblockPlayer(p, (Player)target);
                    }
                }
                if (damage != 0) {
                    Combat.checkRecoil(p, target, damage);
                    Combat.checkSmite(p, target, damage);
                    Combat.checkVengeance(p, target, damage);
                    hitInMulti(p, target, index);
                    applyMiasmicEffects(p, target, index);
                    if ((target.getCombatTurns() > 2 || target.getCombatTurns() < 0) && !target.isDead()) {
                        target.setLastAnimation(new Animation(target.getDefenceAnimation()));
                    }
                    if (index != 27) {
                        target.hit((int)damage);
                        if (index == 18 || index == 22 || index == 26 || index == 30) {
                            p.heal(Convert.ToInt32(damage / 4));
                        }
                    } else if (index == 27){
                        Event doHitEvent = new Event(1000);
                        doHitEvent.setAction(() => {
                                doHitEvent.stop();
                                target.hit((int)damage);
                        });
                        Server.registerEvent(doHitEvent);
                    }
                }
            });
            Server.registerEvent(doMagicAttackEvent);
            if (p.getTemporaryAttribute("autoCasting") != null) {
                if (p.getTemporaryAttribute("autoCastSpell") != null) {
                    if (id != (int)p.getTemporaryAttribute("autoCastSpell")) {
                        p.setTarget(null);
                        return;
                    }
                }
                if (!fakeNPC) {
                    p.setTemporaryAttribute("autocastLocation", target.getLocation());
                    p.setTemporaryAttribute("autocastEntity", target);
                }
                Event autoCastSpellEvent = new Event(3500);
                autoCastSpellEvent.setAction(() => {
                    autoCastSpellEvent.stop();
                    if (p.getTemporaryAttribute("autoCasting") != null && p.getTemporaryAttribute("autoCastSpell") != null) {
                        int autoCastSpell = (int)p.getTemporaryAttribute("autoCastSpell");
                        MagicCombat.newMagicAttack(p, p.getTarget(), autoCastSpell, p.getTemporaryAttribute("autoCastAncients") != null);
                    }
                });
                Server.registerEvent(autoCastSpellEvent);
            } else {
                p.setTarget(null);
            }
        }
Exemplo n.º 2
0
 private void handleMagicOnNPC(Player player, Packet packet)
 {
     int childId = packet.readLEShort();
     int interfaceId = packet.readLEShort();
     int junk = packet.readShortA();
     int npcIndex = packet.readLEShortA();
     if (npcIndex < 0 || npcIndex > Constants.MAX_NPCS || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null) {
         return;
     }
     Npc npc = Server.getNpcList()[npcIndex];
     if (npc == null || npc.isDestroyed()) {
         return;
     }
     SkillHandler.resetAllSkills(player);
     player.setTarget(npc);
     MagicCombat.newMagicAttack(player, npc, childId, interfaceId == 193);
     Console.WriteLine(childId);
 }
Exemplo n.º 3
0
        public void setWeapon()
        {
            if (slots[3].getItemId() == -1)
            {
                player.getPackets().sendTab(player.isHd() ? 93 : 83, 92);
                player.getPackets().modifyText("Unarmed", 92, 0);
                AttackInterface.setButtonForAttackStyle(player, 92);
                return;
            }
            string weapon = slots[3].getDefinition().getName();

            player.getSpecialAttack().setUsingSpecial(false);
            player.setTarget(null);
            int interfaceId = -1;

            if (weapon.Equals("Abyssal whip"))
            {
                player.getPackets().sendTab(player.isHd() ? 93 : 83, 93);
                player.getPackets().modifyText(weapon, 93, 0);
                interfaceId = 93;
            }
            else if (weapon.Equals("Granite maul") || weapon.Equals("Tzhaar-ket-om") || weapon.Equals("Torags hammers"))
            {
                player.getPackets().sendTab(player.isHd() ? 93 : 83, 76);
                player.getPackets().modifyText(weapon, 76, 0);
                interfaceId = 76;
            }
            else if (weapon.Equals("Veracs flail") || (weapon.EndsWith("mace") && !weapon.Equals("Void knight mace")))
            {
                player.getPackets().sendTab(player.isHd() ? 93 : 83, 88);
                player.getPackets().modifyText(weapon, 88, 0);
                interfaceId = 88;
            }
            else if (weapon.EndsWith("crossbow") || weapon.EndsWith(" c'bow"))
            {
                player.getPackets().sendTab(player.isHd() ? 93 : 83, 79);
                player.getPackets().modifyText(weapon, 79, 0);
                interfaceId = 79;
            }
            else if (weapon.EndsWith("bow") || weapon.EndsWith("bow full") || weapon.Equals("Seercull"))
            {
                player.getPackets().sendTab(player.isHd() ? 93 : 83, 77);
                player.getPackets().modifyText(weapon, 77, 0);
                interfaceId = 77;
            }
            else if (weapon.StartsWith("Staff") || weapon.EndsWith("staff") || weapon.Equals("Toktz-mej-tal") || weapon.Equals("Void knight mace"))
            {
                player.getPackets().sendTab(player.isHd() ? 93 : 83, 90);
                player.getPackets().modifyText(weapon, 90, 0);
                interfaceId = 90;
            }
            else if (weapon.EndsWith("dart") || weapon.EndsWith("knife") || weapon.EndsWith("javelin") || weapon.EndsWith("thrownaxe") || weapon.Equals("Toktz-xil-ul"))
            {
                player.getPackets().sendTab(player.isHd() ? 93 : 83, 91);
                player.getPackets().modifyText(weapon, 91, 0);
                interfaceId = 91;
            }
            else if (weapon.EndsWith("dagger") || weapon.EndsWith("dagger(s)") || weapon.EndsWith("dagger(+)") || weapon.EndsWith("dagger(p)") || weapon.EndsWith("dagger(p++)"))
            {
                player.getPackets().sendTab(player.isHd() ? 93 : 83, 89);
                player.getPackets().modifyText(weapon, 89, 0);
                interfaceId = 89;
            }
            else if (weapon.EndsWith("pickaxe"))
            {
                player.getPackets().sendTab(player.isHd() ? 93 : 83, 83);
                player.getPackets().modifyText(weapon, 83, 0);
                interfaceId = 83;
            }
            else if (weapon.EndsWith("axe") || weapon.EndsWith("battleaxe") || weapon.EndsWith("adze"))
            {
                player.getPackets().sendTab(player.isHd() ? 93 : 83, 75);
                player.getPackets().modifyText(weapon, 75, 0);
                interfaceId = 75;
            }
            else if (weapon.EndsWith("halberd"))
            {
                player.getPackets().sendTab(player.isHd() ? 93 : 83, 84);
                player.getPackets().modifyText(weapon, 84, 0);
                interfaceId = 84;
            }
            else if (weapon.EndsWith("spear") || weapon.Equals("Guthans warspear"))
            {
                player.getPackets().sendTab(player.isHd() ? 93 : 83, 85);
                player.getPackets().modifyText(weapon, 85, 0);
                interfaceId = 85;
            }
            else if (weapon.EndsWith("claws"))
            {
                player.getPackets().sendTab(player.isHd() ? 93 : 83, 78);
                player.getPackets().modifyText(weapon, 78, 0);
                interfaceId = 78;
            }
            else if (weapon.EndsWith("2h sword") || weapon.EndsWith("godsword") || weapon.Equals("Saradomin sword"))
            {
                player.getPackets().sendTab(player.isHd() ? 93 : 83, 82);
                player.getPackets().modifyText(weapon, 81, 0);
                interfaceId = 81;
            }
            else
            {
                player.getPackets().sendTab(player.isHd() ? 93 : 83, 82);
                player.getPackets().modifyText(weapon, 82, 0);
                interfaceId = 82;
            }
            AttackInterface.setButtonForAttackStyle(player, interfaceId);
            setSpecials();
        }