Package org.moparscape.msc.gs.model

Examples of org.moparscape.msc.gs.model.Mob


    if (player.isBusy()) {
      player.resetPath();
      return;
    }
    player.resetAll();
    Mob affectedMob = null;
    int serverIndex = p.readShort();
    if (pID == 57) {
      affectedMob = world.getPlayer(serverIndex);
    } else if (pID == 73) {
      affectedMob = world.getNpc(serverIndex);
    }
    if (player.isPMod() && !player.isMod())
      return;
    if (affectedMob == null || affectedMob.equals(player)) {
      player.resetPath();
      return;
    }
    if (affectedMob instanceof Player) {
      Player pl = (Player) affectedMob;
      if (pl.inCombat() && player.getRangeEquip() < 0) {
        return;
      }

      if (pl.getLocation().inWilderness()
          && System.currentTimeMillis() - pl.getLastRun() < 3000) {
        return;
      }
    }

    player.setFollowing(affectedMob);
    player.setStatus(Action.ATTACKING_MOB);

    if (player.getRangeEquip() < 0) {
      Instance.getDelayedEventHandler().add(
          new WalkToMobEvent(player, affectedMob,
              affectedMob instanceof Npc ? 1 : 2) {
            public void arrived() {
              owner.resetPath();
              owner.resetFollowing();
              boolean cont = false;
              if (affectedMob instanceof Player) {
                Player opp = (Player) affectedMob;

                if (GameEngine.getTime()
                    - opp.getLastMineTimer() < 2000
                    && opp.isBusy())
                  cont = true;
              }
              if (affectedMob instanceof Player) {
                world.addEntryToSnapshots(new Activity(owner
                    .getUsername(), owner.getUsername()
                    + " attacked a Player ("
                    + ((Player) affectedMob).getUsername()
                    + ")"));
              } else {
                world.addEntryToSnapshots(new Activity(owner
                    .getUsername(), owner.getUsername()
                    + " attacked a NPC ("
                    + ((Npc) affectedMob).getDef().name
                    + ")"));
              }
              if (cont) {
                if (owner.isBusy()
                    || !owner.nextTo(affectedMob)
                    || !owner.checkAttack(affectedMob,
                        false)
                    || owner.getStatus() != Action.ATTACKING_MOB) {
                  return;
                }
              } else {
                if (owner.isBusy()
                    || affectedMob.isBusy()
                    || !owner.nextTo(affectedMob)
                    || !owner.checkAttack(affectedMob,
                        false)
                    || owner.getStatus() != Action.ATTACKING_MOB) {
                  return;
                }
              }
              if (affectedMob.getID() == 35) {
                owner.getActionSender()
                    .sendMessage(
                        "Delrith can not be attacked without the Silverlight sword");
                return;
              }
              if (affectedMob.getID() == 140
                  && affectedMob.getX() > 327
                  && affectedMob.getX() < 335
                  && affectedMob.getY() > 433
                  && affectedMob.getY() < 439) {
                owner.informOfNpcMessage(new ChatMessage(
                    affectedMob, "a curse be upon you",
                    owner));
                for (int i = 0; i < 3; i++) {
                  int stat = owner.getCurStat(i);
                  if (stat < 3)
                    owner.setCurStat(i, 0);
                  else
                    owner.setCurStat(i, stat - 3);
                }
                owner.getActionSender().sendStats();

              }

              owner.resetAll();
              owner.setStatus(Action.FIGHTING_MOB);
              if (affectedMob instanceof Player) {
                Player affectedPlayer = (Player) affectedMob;
                affectedPlayer.resetAll();
                affectedPlayer.setStatus(Action.FIGHTING_MOB);
                affectedPlayer.getActionSender().sendSound(
                    "underattack");
                affectedPlayer.getActionSender().sendMessage(
                    "You are under attack!");
                owner.setSkulledOn(affectedPlayer);
              }
              affectedMob.resetPath();

              owner.setLocation(affectedMob.getLocation(), true);
              for (Player p : owner.getViewArea()
                  .getPlayersInView()) {
                p.removeWatchedPlayer(owner);
              }

              owner.setBusy(true);
              owner.setSprite(9);
              /*
               * if(affectedMob instanceof Npc) { Npc n =
               * (Npc)affectedMob; for(Fighter p : n.fighters) {
               * p.useCombat = true; if(p.player == owner)
               * if(p.useMagic) { p.useMagic = false; break; } } }
               */
              owner.setOpponent(affectedMob);
              owner.setCombatTimer();
              affectedMob.setBusy(true);
              affectedMob.setSprite(8);
              affectedMob.setOpponent(owner);
              affectedMob.setCombatTimer();
              FightEvent fighting = new FightEvent(owner,
                  affectedMob);
              fighting.setLastRun(0);
              Instance.getDelayedEventHandler().add(fighting);
            }
          });
    } else {
      if (!new ProjectilePath(player.getX(), player.getY(),
          affectedMob.getX(), affectedMob.getY()).isValid()) {
        player.getActionSender().sendMessage(
            "I can't get a clear shot from here");
        player.resetPath();
        return;
      }
      if (Config.f2pWildy && player.getLocation().inWilderness()) {

        for (InvItem i : player.getInventory().getItems()) {
          if (i.id == 638 || i.id == 640 || i.id == 642
              || i.id == 644 || i.id == 646) {
            player.getActionSender()
                .sendMessage(
                    "You can not have any P2P arrows in your inventory in a F2P wilderness");
            return;
          }
        }

      }
      int radius = 7;
      if (player.getRangeEquip() == 59 || player.getRangeEquip() == 60)
        radius = 5;
      if (player.getRangeEquip() == 189)
        radius = 4;
      Instance.getDelayedEventHandler().add(
          new WalkToMobEvent(player, affectedMob, radius) {
            public void arrived() {
              owner.resetPath();
              if (owner.isBusy()
                  || !owner.checkAttack(affectedMob, true)
                  || owner.getStatus() != Action.ATTACKING_MOB) {
                return;
              }

              if (!new ProjectilePath(owner.getX(), owner.getY(),
                  affectedMob.getX(), affectedMob.getY())
                  .isValid()) {
                owner.getActionSender().sendMessage(
                    "I can't get a clear shot from here");
                owner.resetPath();
                return;
              }
              if (affectedMob instanceof Player) {
                world.addEntryToSnapshots(new Activity(owner
                    .getUsername(), owner.getUsername()
                    + " ranged a Player ("
                    + ((Player) affectedMob).getUsername()
                    + ")"));
              } else {
                world.addEntryToSnapshots(new Activity(owner
                    .getUsername(), owner.getUsername()
                    + " ranged a NPC ("
                    + ((Npc) affectedMob).getDef().name
                    + ")"));
              }
              if (affectedMob.getID() == 35) {
                owner.getActionSender()
                    .sendMessage(
                        "Delrith can not be attacked without the Silverlight sword");
                return;
              }
View Full Code Here


      affectedMob.resetCombat(CombatState.ERROR);
      this.stop();
      return;
    }

    Mob attacker, opponent;

    if (hits++ % 2 == firstHit) {
      attacker = owner;
      opponent = affectedMob;
    } else {
      attacker = affectedMob;
      opponent = owner;
    }

    if (attacker instanceof Npc) {
      Npc n = (Npc) attacker;
      if (attacker.getHits() <= 0) {
        n.resetCombat(CombatState.ERROR);
        owner.resetCombat(CombatState.ERROR);
        this.stop();
        return;
      }
    }
    if (opponent instanceof Npc) {
      Npc n = (Npc) opponent;
      if (opponent.getHits() <= 0) {
        n.resetCombat(CombatState.ERROR);
        owner.resetCombat(CombatState.ERROR);
        this.stop();
        return;
      }
    }
    if (opponent instanceof Player && attacker instanceof Player) {
      if (((Player) opponent).isSleeping()) {
        ((Player) opponent).getActionSender().sendWakeUp(false);
      }
    }

    /*
     * if(opponent.getHits() <= 0) { attacker.resetCombat(CombatState.WON);
     * opponent.resetCombat(CombatState.LOST); return; }
     */
    attacker.incHitsMade();
    if (attacker instanceof Npc && opponent.isPrayerActivated(12)) {
      return;
    }
    // int damage = (attacker instanceof Player && opponent instanceof
    // Player ? Formulae
    // .calcFightHit(attacker, opponent) : Formulae
    // .calcFightHitWithNPC(attacker, opponent));

    int damage = CombatFormulae.getNextHit(attacker, opponent);
    if (attacker instanceof Player && opponent instanceof Npc) {
      Npc npc = (Npc) opponent;

      int newDmg = damage;
      if (npc.getCurHits() - damage <= 0 && npc.getCurHits() > 0) {
        newDmg = npc.getCurHits();
      }
      npc.getSyndicate().addDamage(owner, newDmg, Damage.COMBAT_DAMAGE);
    }

    if (attacker instanceof Npc && opponent instanceof Player
        && attacker.getHitsMade() >= (attacked ? 4 : 3)) {
      Npc npc = (Npc) attacker;
      Player player = (Player) opponent;
      if (npc.getCurHits() <= npc.getDef().hits * 0.10
          && npc.getCurHits() > 0) {
        if (!npc.getLocation().inWilderness()
            && npc.getDef().attackable && !npc.getDef().aggressive) {
          boolean go = true;
          for (int i : Constants.GameServer.NPCS_THAT_DONT_RETREAT) {
            if (i == npc.getID()) {
              go = false;
              break;
            }
          }

          if (go) {
            player.getActionSender().sendSound("retreat");
            npc.unblock();
            npc.resetCombat(CombatState.RUNNING);
            player.resetCombat(CombatState.WAITING);
            npc.setRan(true);
            npc.setPath(new Path(attacker.getX(), attacker.getY(),
                DataConversions.random(npc.getLoc().minX(), npc
                    .getLoc().maxX()), DataConversions
                    .random(npc.getLoc().minY(), npc
                        .getLoc().maxY())));
            player.resetAll();
            player.getActionSender().sendMessage(
                "Your opponent is retreating");
            this.stop();
            return;
          }
        }
      }
    }

    opponent.setLastDamage(damage);
    int newHp = opponent.getHits() - damage;
    opponent.setHits(newHp);

    String combatSound = null;
    combatSound = damage > 0 ? "combat1b" : "combat1a";
    if (opponent instanceof Player) {
      if (attacker instanceof Npc) {
        Npc n = (Npc) attacker;
        if (n.hasArmor) {
          combatSound = damage > 0 ? "combat2b" : "combat2a";
        } else if (n.undead) {
          combatSound = damage > 0 ? "combat3b" : "combat3a";
        } else {
          combatSound = damage > 0 ? "combat1b" : "combat1a";
        }
      }
      Player opponentPlayer = ((Player) opponent);
      opponentPlayer.getActionSender().sendStat(3);
      opponentPlayer.getActionSender().sendSound(combatSound);
    }
    if (attacker instanceof Player) {
      if (opponent instanceof Npc) {
        Npc n = (Npc) opponent;
        if (n.hasArmor) {
          combatSound = damage > 0 ? "combat2b" : "combat2a";
        } else if (n.undead) {
          combatSound = damage > 0 ? "combat3b" : "combat3a";
        } else {
          combatSound = damage > 0 ? "combat1b" : "combat1a";
        }
      }
      Player attackerPlayer = (Player) attacker;
      attackerPlayer.getActionSender().sendSound(combatSound);
    }

    if (newHp <= 0) {

      Mob toLoot = attacker;

      // Logging.debug(opponent+" killed by "+attacker);

      if (attacker instanceof Player) {
        Player attackerPlayer = (Player) attacker;
View Full Code Here

    int serverIndex = p.readShort();
    final Player player = (Player) session.getAttachment();
    if (player.isBusy()) {
      return;
    }
    final Mob affectedMob = world.getNpc(serverIndex);
    final Npc affectedNpc = (Npc) affectedMob;
    if (affectedNpc == null || affectedMob == null || player == null)
      return;
    if (!World.isMembers()) {
      player.getActionSender().sendMessage(
View Full Code Here

  public void handlePacket(Packet p, IoSession session) throws Exception {
    Player player = (Player) session.getAttachment();
    int pID = ((RSCPacket) p).getID();
    if (player.inCombat()) {
      if (pID == 132) {
        Mob opponent = player.getOpponent();
        if (opponent == null) { // This shouldn't happen
          player.setSuspiciousPlayer(true);
          return;
        }
        if (opponent.getHitsMade() >= 3) {
          if (player.isDueling() && player.getDuelSetting(0)) {
            player.getActionSender().sendMessage(
                "Running has been disabled in this duel.");
            return;
          }
          player.setLastRun(GameEngine.getTime());
          player.resetCombat(CombatState.RUNNING);

          player.isMining(false);
          if (opponent instanceof Npc) {
            Npc n = (Npc) opponent;
            n.unblock();
            opponent.resetCombat(CombatState.WAITING);
            if (n.getDef().aggressive) {
              player.setLastNpcChasingYou(n);
              Instance.getDelayedEventHandler().add(
                  new MiniEvent(player, 2000) {
                    public void action() {

                      final Npc npc = owner
                          .getLastNpcChasingYou();
                      owner.setLastNpcChasingYou(null);
                      if (npc.isBusy()
                          || npc.getChasing() != null)
                        return;

                      npc.resetPath();
                      npc.setChasing(owner);

                      Instance.getDelayedEventHandler()
                          .add(new WalkMobToMobEvent(
                              npc, owner, 0) {
                            public void arrived() {
                              if (affectedMob
                                  .isBusy()
                                  || owner.isBusy()) {
                                npc.setChasing(null);
                                return;
                              }
                              if (affectedMob
                                  .inCombat()
                                  || owner.inCombat()) {
                                npc.setChasing(null);
                                return;
                              }
                              Player player = (Player) affectedMob;
                              player.resetPath();
                              player.setBusy(true);
                              npc.resetPath();
                              player.resetAll();
                              player.setStatus(Action.FIGHTING_MOB);
                              player.getActionSender()
                                  .sendSound(
                                      "underattack");
                              player.getActionSender()
                                  .sendMessage(
                                      "You are under attack!");

                              npc.setLocation(
                                  player.getLocation(),
                                  true);
                              for (Player p : npc
                                  .getViewArea()
                                  .getPlayersInView())
                                p.removeWatchedNpc(npc);
                              player.setBusy(true);
                              player.setSprite(9);
                              player.setOpponent(npc);
                              player.setCombatTimer();

                              npc.setBusy(true);
                              npc.setSprite(8);
                              npc.setOpponent(player);
                              npc.setCombatTimer();
                              npc.setChasing(null);
                              FightEvent fighting = new FightEvent(
                                  player,
                                  npc, true);
                              fighting.setLastRun(0);
                              world.getDelayedEventHandler()
                                  .add(fighting);
                            }

                            public void failed() {
                              npc.setChasing(null);
                            }
                          });
                    }
                  });
            }

          } else {
            opponent.resetCombat(CombatState.WAITING);
          }
        } else {
          player.getActionSender()
              .sendMessage(
                  "You cannot retreat in the first 3 rounds of battle.");
View Full Code Here

TOP

Related Classes of org.moparscape.msc.gs.model.Mob

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.