示例#1
0
 private static bool canCastSpell(Player p, Entity target, int i, bool fakeNPC)
 {
     // fakeNPC is used to keep location when autocasting.
     if (fakeNPC)
     {
         return !p.isDead();
     }
     if (target.isDead() || p.isDead() || target.isDestroyed() || p.isDestroyed())
     {
         return false;
     }
     if (target is Npc)
     {
         if (((Npc)target).getHp() <= 0)
         {
             return false;
         }
         if (i == 47)
         {
             p.getPackets().sendMessage("You cannot cast Teleblock upon an NPC.");
             return false;
         }
     }
     if ((target is Player) && (p is Player))
     {
         if (Location.inFightPits(target.getLocation()) && Location.inFightPits(target.getLocation()))
         {
             if (!Server.getMinigames().getFightPits().hasGameStarted())
             {
                 return false;
             }
             return true;
         }
         if (p.getDuel() != null)
         {
             if (((Player)target).getDuel() != null)
             {
                 if (p.getDuel().getPlayer2().Equals(((Player)target)) && ((Player)target).getDuel().getPlayer2().Equals(p))
                 {
                     if (p.getDuel().ruleEnabled(DuelSession.RULE.NO_MAGIC))
                     {
                         p.getPackets().sendMessage("Magical combat has been disabled in this duel!");
                         return false;
                     }
                     if (p.getDuel().getStatus() == 6 && ((Player)target).getDuel().getStatus() == 6)
                     {
                         return true;
                     }
                 }
             }
             p.getPackets().sendMessage("That isn't your opponent.");
             return false;
         }
         if (i == 47)
         {
             if (((Player)target).getTemporaryAttribute("teleblocked") != null)
             {
                 p.getPackets().sendMessage("That player already has a teleportation block upon them.");
                 return false;
             }
         }
         if (!Location.inWilderness(target.getLocation()))
         {
             p.getPackets().sendMessage("That player isn't in the wilderness.");
             return false;
         }
         if (!Location.inWilderness(p.getLocation()))
         {
             p.getPackets().sendMessage("You aren't in the wilderness.");
             return false;
         }
         int killerWildLevel = p.getLocation().wildernessLevel();
         int targetWildLevel = ((Player)target).getLocation().wildernessLevel();
         int killerCombatLevel = p.getSkills().getCombatLevel();
         int targetCombatLevel = ((Player)target).getSkills().getCombatLevel();
         int highest = killerCombatLevel > targetCombatLevel ? killerCombatLevel : targetCombatLevel;
         int lowest = highest == killerCombatLevel ? targetCombatLevel : killerCombatLevel;
         int difference = (highest - lowest);
         if (difference > killerWildLevel || difference > targetWildLevel)
         {
             ((Player)p).getPackets().sendMessage("You must move deeper into the wilderness to attack that player.");
             return false;
         }
     }
     if (!Location.inMultiCombat(target.getLocation()))
     {
         if (p.getAttacker() != null && !p.getAttacker().Equals(target))
         {
             p.getPackets().sendMessage("You are already in combat!");
             return false;
         }
         if (target.getAttacker() != null && !target.getAttacker().Equals(p))
         {
             string type = target is Player ? "player" : "npc";
             p.getPackets().sendMessage("That " + type + " is already in combat.");
             return false;
         }
     }
     if (p.getSkills().getCurLevel(Skills.SKILL.MAGIC) < SPELL_LEVEL[i])
     {
         p.getPackets().sendMessage("You need a Magic level of " + SPELL_LEVEL[i] + " to cast that spell.");
         return false;
     }
     if (!hasRunes(p, RUNES[i], RUNE_AMOUNTS[i]))
     {
         p.getPackets().sendMessage("You do not have enough runes to cast that spell.");
         return false;
     }
     if (NEEDS_STAFF[i])
     {
         if ((i != 38 && p.getEquipment().getItemInSlot(ItemData.EQUIP.WEAPON) != STAFF[i]) || (i == 38 && p.getEquipment().getItemInSlot(ItemData.EQUIP.WEAPON) != 8841 && p.getEquipment().getItemInSlot(ItemData.EQUIP.WEAPON) != STAFF[i]))
         {
             p.getPackets().sendMessage("You need to wield " + STAFF_NAME[i] + " to cast this spell.");
             return false;
         }
     }
     if (i == 37)
     {
         if (p.getEquipment().getItemInSlot(ItemData.EQUIP.CAPE) != 2412)
         {
             p.getPackets().sendMessage("You need to wear the Cape of Saradomin to be able to cast Saradomin Strike.");
             return false;
         }
     }
     if (i == 38)
     {
         if (p.getEquipment().getItemInSlot(ItemData.EQUIP.CAPE) != 2413)
         {
             p.getPackets().sendMessage("You need to wear the Cape of Guthix to be able to cast Claws of Guthix.");
             return false;
         }
     }
     if (i == 39)
     {
         if (p.getEquipment().getItemInSlot(ItemData.EQUIP.CAPE) != 2414)
         {
             p.getPackets().sendMessage("You need to wear the Cape of Zamorak to be able to cast Flames of Zamorak.");
             return false;
         }
     }
     return true;
 }
示例#2
0
        private static bool canCastSpell2(Player p, Entity target, int i, bool fakeNPC)
        {
            // fakeNPC is used to keep location when autocasting.
            if (fakeNPC)
            {
                return !p.isDead();
            }
            if (target.isDead() || p.isDead() || target.isDestroyed() || p.isDestroyed())
            {
                return false;
            }
            if (target is Npc)
            {
                if (((Npc)target).getHp() <= 0)
                {
                    return false;
                }
            }
            if ((target is Player) && (p is Player))
            {
                if (Location.inFightPits(target.getLocation()) && Location.inFightPits(target.getLocation()))
                {
                    if (!Server.getMinigames().getFightPits().hasGameStarted())
                    {
                        return false;
                    }
                    return true;
                }
                if (p.getDuel() != null)
                {
                    if (((Player)target).getDuel() != null)
                    {
                        if (p.getDuel().getPlayer2().Equals(((Player)target)) && ((Player)target).getDuel().getPlayer2().Equals(p))
                        {
                            if (p.getDuel().ruleEnabled(DuelSession.RULE.NO_MAGIC))
                            {
                                return false;
                            }
                            if (p.getDuel().getStatus() == 6 && ((Player)target).getDuel().getStatus() == 6)
                            {
                                return true;
                            }
                        }
                    }
                    return false;
                }
                if (!Location.inWilderness(target.getLocation()) && !Location.inWilderness(p.getLocation()))
                    return false;

                int killerWildLevel = p.getLocation().wildernessLevel();
                int targetWildLevel = ((Player)target).getLocation().wildernessLevel();
                int killerCombatLevel = p.getSkills().getCombatLevel();
                int targetCombatLevel = ((Player)target).getSkills().getCombatLevel();
                int highest = killerCombatLevel > targetCombatLevel ? killerCombatLevel : targetCombatLevel;
                int lowest = highest == killerCombatLevel ? targetCombatLevel : killerCombatLevel;
                int difference = (highest - lowest);
                if (difference > killerWildLevel || difference > targetWildLevel)
                {
                    return false;
                }
            }
            return true;
        }
示例#3
0
        public static void fightCaveAttacks(Npc npc, Player p)
        {
            if (npc.isDead() || npc.isDestroyed() || p.isDead() || p.isDestroyed() || p.isDead() || !Location.inFightCave(p.getLocation()) || p.getTeleportTo() != null)
            {
                return;
            }
            int damage = Misc.random(npc.getMaxHit());
            int prayer = p.getPrayers().getHeadIcon();
            int hitDelay = npc.getHitDelay();
            int animation = npc.getAttackAnimation();
            switch (npc.getId())
            {
                case 2734: // Tz-Kih (lvl 22)
                case 2735:
                    if (prayer == PrayerData.MELEE)
                    {
                        damage = 0;
                    }
                    break;

                case 2739: // Tz-Xil (lvl 90)
                case 2740:
                    if (prayer == PrayerData.RANGE)
                    {
                        damage = 0;
                    }
                    p.getPackets().sendProjectile(npc.getLocation(), p.getLocation(), 32, 1616, 50, 40, 34, 50, p);
                    break;

                case 2741: // Yt-MejKot (lvl 180)
                case 2742:
                    if (prayer == PrayerData.MELEE)
                    {
                        damage = 0;
                    }
                    // TODO healing
                    break;

                case 2743: // Ket-Zek (lvl 360)
                case 2744:
                    if (!p.getLocation().withinDistance(npc.getLocation(), 2))
                    {
                        hitDelay = 1600;
                        animation = 9266;
                        npc.setLastGraphics(new Graphics(1622));
                        damage = Misc.random(49);
                        if (prayer == PrayerData.MAGIC)
                        {
                            damage = 0;
                        }
                        Event sendProjectileToNpc = new Event(300);
                        sendProjectileToNpc.setAction(() =>
                        {
                            sendProjectileToNpc.stop();
                            p.getPackets().sendProjectile(npc.getLocation(), p.getLocation(), 32, 1623, 50, 40, 34, 80, p);
                        });
                        Server.registerEvent(sendProjectileToNpc);
                    }
                    else
                    {
                        damage = Misc.random(64);
                        if (prayer == PrayerData.MELEE)
                        {
                            damage = 0;
                        }
                    }
                    break;

                case 2745: // TzTok Jad (lvl 702)
                    doJadAttacks(p, npc);
                    break;
            }
            if (npc.getId() == 2745)
            {
                return;
            }
            if (animation != 65535)
            {
                npc.setLastAnimation(new Animation(animation));
            }
            p.setLastAttacked(Environment.TickCount);
            npc.setLastAttack(Environment.TickCount);
            p.setAttacker(npc);
            npc.resetCombatTurns();
            if (damage > p.getHp())
            {
                damage = p.getHp();
            }
            int npcId = npc.getId();

            Event losePrayerFightingEvent = new Event(hitDelay);
            losePrayerFightingEvent.setAction(() =>
            {
                losePrayerFightingEvent.stop();
                if (!Location.inFightCave(p.getLocation()) || p.getTeleportTo() != null)
                {
                    return;
                }
                if (npcId == 2734 || npcId == 2735)
                {
                    int prayerLevel = p.getSkills().getCurLevel(Skills.SKILL.PRAYER);
                    int newPrayerLevel = prayerLevel -= (damage + 1);
                    if (newPrayerLevel <= 0)
                    {
                        newPrayerLevel = 0;
                    }
                    p.getSkills().setCurLevel(Skills.SKILL.PRAYER, newPrayerLevel);
                    p.getPackets().sendSkillLevel(Skills.SKILL.PRAYER);
                }
                else if (npcId == 2743 || npcId == 2744)
                {
                    if (Misc.random(1) == 0)
                    {
                        p.setLastGraphics(new Graphics(1624, 0));
                    }
                }
                if ((p.getCombatTurns() > 2 || p.getCombatTurns() < 0))
                {
                    p.setLastAnimation(new Animation(p.getDefenceAnimation()));
                }
                p.hit(damage);
            });
            Server.registerEvent(losePrayerFightingEvent);
        }