Beispiel #1
0
  @Override
  public void processPacket(Client c, int packetType, int packetSize) {
    c.playerIndex = 0;
    c.npcIndex = 0;
    switch (packetType) {

        /** Attack player */
      case ATTACK_PLAYER:
        c.playerIndex = c.getInStream().readSignedWordBigEndian();
        if (PlayerHandler.players[c.playerIndex] == null) {
          break;
        }

        if (c.respawnTimer > 0) {
          break;
        }

        if (c.autocastId > 0) {
          c.autocasting = true;
        }

        if (!c.autocasting && c.spellId > 0) {
          c.spellId = 0;
        }
        c.mageFollow = false;
        c.spellId = 0;
        c.usingMagic = false;
        boolean usingBow = false;
        boolean usingOtherRangeWeapons = false;
        boolean usingArrows = false;
        boolean usingCross = c.playerEquipment[c.playerWeapon] == 9185;
        for (int bowId : c.BOWS) {
          if (c.playerEquipment[c.playerWeapon] == bowId) {
            usingBow = true;
            for (int arrowId : c.ARROWS) {
              if (c.playerEquipment[c.playerArrows] == arrowId) {
                usingArrows = true;
              }
            }
          }
        }
        for (int otherRangeId : c.OTHER_RANGE_WEAPONS) {
          if (c.playerEquipment[c.playerWeapon] == otherRangeId) {
            usingOtherRangeWeapons = true;
          }
        }
        if (c.duelStatus == 5) {
          if (c.duelCount > 0) {
            c.sendMessage("The duel hasn't started yet!");
            c.playerIndex = 0;
            return;
          }
          if (c.duelRule[9]) {
            boolean canUseWeapon = false;
            for (int funWeapon : Config.FUN_WEAPONS) {
              if (c.playerEquipment[c.playerWeapon] == funWeapon) {
                canUseWeapon = true;
              }
            }
            if (!canUseWeapon) {
              c.sendMessage("You can only use fun weapons in this duel!");
              return;
            }
          }

          if (c.duelRule[2] && (usingBow || usingOtherRangeWeapons)) {
            c.sendMessage("Range has been disabled in this duel!");
            return;
          }
          if (c.duelRule[3] && !usingBow && !usingOtherRangeWeapons) {
            c.sendMessage("Melee has been disabled in this duel!");
            return;
          }
        }

        if ((usingBow || c.autocasting)
            && c.goodDistance(
                c.getX(),
                c.getY(),
                PlayerHandler.players[c.playerIndex].getX(),
                PlayerHandler.players[c.playerIndex].getY(),
                6)) {
          c.usingBow = true;
          c.stopMovement();
        }

        if (usingOtherRangeWeapons
            && c.goodDistance(
                c.getX(),
                c.getY(),
                PlayerHandler.players[c.playerIndex].getX(),
                PlayerHandler.players[c.playerIndex].getY(),
                3)) {
          c.usingRangeWeapon = true;
          c.stopMovement();
        }
        if (!usingBow) {
          c.usingBow = false;
        }
        if (!usingOtherRangeWeapons) {
          c.usingRangeWeapon = false;
        }

        if (!usingCross
            && !usingArrows
            && usingBow
            && c.playerEquipment[c.playerWeapon] < 4212
            && c.playerEquipment[c.playerWeapon] > 4223) {
          c.sendMessage("You have run out of arrows!");
          return;
        }
        if (c.getCombat().correctBowAndArrows() < c.playerEquipment[c.playerArrows]
            && Config.CORRECT_ARROWS
            && usingBow
            && !c.getCombat().usingCrystalBow()
            && c.playerEquipment[c.playerWeapon] != 9185) {
          c.sendMessage(
              "You can't use "
                  + c.getItems().getItemName(c.playerEquipment[c.playerArrows]).toLowerCase()
                  + "s with a "
                  + c.getItems().getItemName(c.playerEquipment[c.playerWeapon]).toLowerCase()
                  + ".");
          c.stopMovement();
          c.getCombat().resetPlayerAttack();
          return;
        }

        if (c.getCombat().checkReqs()) {
          c.followId = c.playerIndex;
          if (!c.usingMagic && !usingBow && !usingOtherRangeWeapons) {
            c.followDistance = 1;
            c.getPA().followPlayer();
          }
          if (c.attackTimer <= 0) {
            // c.sendMessage("Tried to attack...");
            // c.getCombat().attackPlayer(c.playerIndex);
            // c.attackTimer++;
          }
        }
        break;

        /** Attack player with magic */
      case MAGE_PLAYER:
        if (!c.mageAllowed) {
          c.mageAllowed = true;
          break;
        }
        // c.usingSpecial = false;
        // c.getItems().updateSpecialBar();

        c.playerIndex = c.getInStream().readSignedWordA();
        int castingSpellId = c.getInStream().readSignedWordBigEndian();
        c.usingMagic = false;
        if (PlayerHandler.players[c.playerIndex] == null) {
          break;
        }

        if (c.respawnTimer > 0) {
          break;
        }

        for (int i = 0; i < c.MAGIC_SPELLS.length; i++) {
          if (castingSpellId == c.MAGIC_SPELLS[i][0]) {
            c.spellId = i;
            c.usingMagic = true;
            break;
          }
        }

        if (c.autocasting) {
          c.autocasting = false;
        }

        if (!c.getCombat().checkReqs()) {
          break;
        }
        if (c.duelStatus == 5) {
          if (c.duelCount > 0) {
            c.sendMessage("The duel hasn't started yet!");
            c.playerIndex = 0;
            return;
          }
          if (c.duelRule[4]) {
            c.sendMessage("Magic has been disabled in this duel!");
            return;
          }
        }

        for (int r = 0; r < c.REDUCE_SPELLS.length; r++) { // reducing
          // spells,
          // confuse
          // etc
          if (PlayerHandler.players[c.playerIndex].REDUCE_SPELLS[r]
              == c.MAGIC_SPELLS[c.spellId][0]) {
            if (System.currentTimeMillis()
                    - PlayerHandler.players[c.playerIndex].reduceSpellDelay[r]
                < PlayerHandler.players[c.playerIndex].REDUCE_SPELL_TIME[r]) {
              c.sendMessage("That player is currently immune to this spell.");
              c.usingMagic = false;
              c.stopMovement();
              c.getCombat().resetPlayerAttack();
            }
            break;
          }
        }

        if (System.currentTimeMillis() - PlayerHandler.players[c.playerIndex].teleBlockDelay
                < PlayerHandler.players[c.playerIndex].teleBlockLength
            && c.MAGIC_SPELLS[c.spellId][0] == 12445) {
          c.sendMessage("That player is already affected by this spell.");
          c.usingMagic = false;
          c.stopMovement();
          c.getCombat().resetPlayerAttack();
        }

        /*
         * if(!c.getCombat().checkMagicReqs(c.spellId)) {
         * c.stopMovement(); c.getCombat().resetPlayerAttack(); break; }
         */

        if (c.usingMagic) {
          if (c.goodDistance(
              c.getX(),
              c.getY(),
              PlayerHandler.players[c.playerIndex].getX(),
              PlayerHandler.players[c.playerIndex].getY(),
              7)) {
            c.stopMovement();
          }
          if (c.getCombat().checkReqs()) {
            c.followId = c.playerIndex;
            c.mageFollow = true;
            if (c.attackTimer <= 0) {
              // c.getCombat().attackPlayer(c.playerIndex);
              // c.attackTimer++;
            }
          }
        }
        break;
    }
  }
Beispiel #2
0
 public void handlePotion(int itemId, int slot) {
   if (c.duelRule[5]) {
     c.sendMessage("You may not drink potions in this duel.");
     return;
   }
   if (System.currentTimeMillis() - c.potDelay >= 1200) {
     c.potDelay = System.currentTimeMillis();
     c.foodDelay = c.potDelay;
     c.getCombat().resetPlayerAttack();
     c.attackTimer++;
     c.sendMessage(
         "You drink some of your " + server.org.engine.item.Item.getItemName(itemId) + ".");
     String item = server.org.engine.item.Item.getItemName(itemId);
     if (item.endsWith("(4)")) {
       c.sendMessage("You have 3 doses of potion left.");
     } else if (item.endsWith("(3)")) {
       c.sendMessage("You have 2 doses of potion left.");
     } else if (item.endsWith("(2)")) {
       c.sendMessage("You have 1 dose of potion left.");
     } else if (item.endsWith("(1)")) {
       c.sendMessage("You have finished your potion.");
     }
     switch (itemId) {
         // Magic pots
       case 3040:
         drinkMagicPotion(itemId, 3042, slot, 6, false);
         break;
       case 3042:
         drinkMagicPotion(itemId, 3044, slot, 6, false);
         break;
       case 3044:
         drinkMagicPotion(itemId, 3046, slot, 6, false);
         break;
       case 3046:
         drinkMagicPotion(itemId, 229, slot, 6, false);
         break;
       case 6685: // brews
         doTheBrew(itemId, 6687, slot);
         break;
       case 6687:
         doTheBrew(itemId, 6689, slot);
         break;
       case 6689:
         doTheBrew(itemId, 6691, slot);
         break;
       case 6691:
         doTheBrew(itemId, 229, slot);
         break;
       case 2436:
         drinkStatPotion(itemId, 145, slot, 0, true); // sup attack
         break;
       case 145:
         drinkStatPotion(itemId, 147, slot, 0, true);
         break;
       case 147:
         drinkStatPotion(itemId, 149, slot, 0, true);
         break;
       case 149:
         drinkStatPotion(itemId, 229, slot, 0, true);
         break;
       case 2440:
         drinkStatPotion(itemId, 157, slot, 2, true); // sup str
         break;
       case 157:
         drinkStatPotion(itemId, 159, slot, 2, true);
         break;
       case 159:
         drinkStatPotion(itemId, 161, slot, 2, true);
         break;
       case 161:
         drinkStatPotion(itemId, 229, slot, 2, true);
         break;
       case 2444:
         drinkStatPotion(itemId, 169, slot, 4, false); // range pot
         break;
       case 169:
         drinkStatPotion(itemId, 171, slot, 4, false);
         break;
       case 171:
         drinkStatPotion(itemId, 173, slot, 4, false);
         break;
       case 173:
         drinkStatPotion(itemId, 229, slot, 4, false);
         break;
       case 2432:
         drinkStatPotion(itemId, 133, slot, 1, false); // def pot
         break;
       case 133:
         drinkStatPotion(itemId, 135, slot, 1, false);
         break;
       case 135:
         drinkStatPotion(itemId, 137, slot, 1, false);
         break;
       case 137:
         drinkStatPotion(itemId, 229, slot, 1, false);
         break;
       case 113:
         drinkStatPotion(itemId, 115, slot, 2, false); // str pot
         break;
       case 115:
         drinkStatPotion(itemId, 117, slot, 2, false);
         break;
       case 117:
         drinkStatPotion(itemId, 119, slot, 2, false);
         break;
       case 119:
         drinkStatPotion(itemId, 229, slot, 2, false);
         break;
       case 2428:
         drinkStatPotion(itemId, 121, slot, 0, false); // attack
         // pot
         break;
       case 121:
         drinkStatPotion(itemId, 123, slot, 0, false);
         break;
       case 123:
         drinkStatPotion(itemId, 125, slot, 0, false);
         break;
       case 125:
         drinkStatPotion(itemId, 229, slot, 0, false);
         break;
       case 2442:
         drinkStatPotion(itemId, 163, slot, 1, true); // super def
         // pot
         break;
       case 163:
         drinkStatPotion(itemId, 165, slot, 1, true);
         break;
       case 165:
         drinkStatPotion(itemId, 167, slot, 1, true);
         break;
       case 167:
         drinkStatPotion(itemId, 229, slot, 1, true);
         break;
       case 3024:
         drinkPrayerPot(itemId, 3026, slot, true); // sup restore
         break;
       case 3026:
         drinkPrayerPot(itemId, 3028, slot, true);
         break;
       case 3028:
         drinkPrayerPot(itemId, 3030, slot, true);
         break;
       case 3030:
         drinkPrayerPot(itemId, 229, slot, true);
         break;
       case 10925:
         drinkPrayerPot(itemId, 10927, slot, true); // sanfew
         // serums
         curePoison(300000);
         break;
       case 10927:
         drinkPrayerPot(itemId, 10929, slot, true);
         curePoison(300000);
         break;
       case 10929:
         drinkPrayerPot(itemId, 10931, slot, true);
         curePoison(300000);
         break;
       case 10931:
         drinkPrayerPot(itemId, 229, slot, true);
         curePoison(300000);
         break;
       case 2434:
         drinkPrayerPot(itemId, 139, slot, false); // pray pot
         break;
       case 139:
         drinkPrayerPot(itemId, 141, slot, false);
         break;
       case 141:
         drinkPrayerPot(itemId, 143, slot, false);
         break;
       case 143:
         drinkPrayerPot(itemId, 229, slot, false);
         break;
       case 2446:
         drinkAntiPoison(itemId, 175, slot, 30000); // anti poisons
         break;
       case 175:
         drinkAntiPoison(itemId, 177, slot, 30000);
         break;
       case 177:
         drinkAntiPoison(itemId, 179, slot, 30000);
         break;
       case 179:
         drinkAntiPoison(itemId, 229, slot, 30000);
         break;
       case 2448:
         drinkAntiPoison(itemId, 181, slot, 300000); // anti
         // poisons
         break;
       case 181:
         drinkAntiPoison(itemId, 183, slot, 300000);
         break;
       case 183:
         drinkAntiPoison(itemId, 185, slot, 300000);
         break;
       case 185:
         drinkAntiPoison(itemId, 229, slot, 300000);
         break;
     }
   }
 }