public boolean isValid() {
   if (!DataConversions.inArray(Formulae.headSprites, head)
       || !DataConversions.inArray(Formulae.bodySprites, body)) {
     return false;
   }
   if (hairColour < 0 || topColour < 0 || trouserColour < 0 || skinColour < 0) {
     return false;
   }
   if (hairColour > 9 || topColour > 14 || trouserColour > 14 || skinColour > 4) {
     return false;
   }
   return true;
 }
Exemple #2
0
  public void updatePosition() {
    long now = GameEngine.getAccurateTimestamp();
    Player victim = findVictim();

    if (!isBusy() && def.isAggressive() && now - getCombatTimer() > 3000 && victim != null) {
      resetPath();

      victim.resetPath();
      victim.resetAll();
      victim.setStatus(Action.FIGHTING_MOB);
      victim.getActionSender().sendSound("underattack");
      victim.getActionSender().sendMessage("You are under attack!");

      if (victim.isSleeping()) {
        victim.getActionSender().sendWakeUp(false, false);
        victim.getActionSender().sendFatigue(victim.getFatigue());
      }

      this.setLocation(victim.getLocation(), true);

      for (Player p : getViewArea().getPlayersInView()) {
        p.removeWatchedNpc(this);
      }

      victim.setBusy(true);
      victim.setSprite(9);
      victim.setOpponent(this);
      victim.setCombatTimer();

      setBusy(true);
      setSprite(8);
      setOpponent(victim);
      setCombatTimer();
      FightEvent fighting = new FightEvent(victim, this, true);
      fighting.setLastRun(0);
      World.getWorld().getDelayedEventHandler().add(fighting);
    }

    if (now - lastMovement > 2200) {
      lastMovement = now;
      int rand = DataConversions.random(0, 1);
      if (!isBusy() && finishedPath() && rand == 1 && !isRemoved()) {
        int newX = DataConversions.random(loc.minX(), loc.maxX());
        int newY = DataConversions.random(loc.minY(), loc.maxY());
        setPath(new Path(getX(), getY(), newX, newY));
      }
    }

    super.updatePosition();
  }
Exemple #3
0
  /**
   * Distributes the XP from this monster and the loot
   *
   * @param attacker the person that "finished off" the npc
   * @return the player who did the most damage / should get the loot
   */
  public Player handleLootAndXpDistribution(Player attacker) {
    Player toLoot = attacker;
    int mostDamageDone = 0;
    int exp = DataConversions.roundUp(Formulae.combatExperience(this) / 4D);

    for (long playerHash : getCombatDamagers()) {
      int newXP = 0;
      Player p = World.getWorld().getPlayer(playerHash);
      if (p == null) continue;
      int dmgDoneByPlayer = getCombatDamageDoneBy(p);

      if (dmgDoneByPlayer > mostDamageDone) {
        toLoot = p;
        mostDamageDone = dmgDoneByPlayer;
      }

      newXP = (exp * dmgDoneByPlayer) / this.getDef().hits;
      switch (p.getCombatStyle()) {
        case 0:
          for (int x = 0; x < 3; x++) {
            p.incExp(x, newXP, true, true, true);
            p.getActionSender().sendStat(x);
          }
          break;
        case 1:
          p.incExp(2, newXP * 3, true, true, true);
          p.getActionSender().sendStat(2);
          break;
        case 2:
          p.incExp(0, newXP * 3, true, true, true);
          p.getActionSender().sendStat(0);
          break;
        case 3:
          p.incExp(1, newXP * 3, true, true, true);
          p.getActionSender().sendStat(1);
          break;
      }
      p.incExp(3, newXP, true, true, true);
      p.getActionSender().sendStat(3);
    }
    for (long playerHash : getRangeDamagers()) {

      int newXP = 0;
      Player p = World.getWorld().getPlayer(playerHash);
      int dmgDoneByPlayer = getRangeDamageDoneBy(p);
      if (p == null) continue;

      if (dmgDoneByPlayer > mostDamageDone) {
        toLoot = p;
        mostDamageDone = dmgDoneByPlayer;
      }
      newXP = (exp * dmgDoneByPlayer) / this.getDef().hits;
      p.incExp(4, newXP * 4, true, true, true);
      p.getActionSender().sendStat(4);
    }
    for (long playerHash : getMageDamagers()) {

      Player p = World.getWorld().getPlayer(playerHash);

      int dmgDoneByPlayer = getMageDamageDoneBy(p);
      if (p == null) continue;

      if (dmgDoneByPlayer > mostDamageDone) {
        toLoot = p;
        mostDamageDone = dmgDoneByPlayer;
      }
    }
    return toLoot;
  }
Exemple #4
0
  public void killedBy(Mob mob, boolean stake) {
    if (mob instanceof Player) {
      Player player = (Player) mob;
      player.getActionSender().sendSound("victory");
    }

    Mob opponent = super.getOpponent();
    if (opponent != null) {
      opponent.resetCombat(CombatState.WON);
    }

    resetCombat(CombatState.LOST);
    world.unregisterNpc(this);
    this.remove();

    // Player owner = mob instanceof Player ? (Player) mob : null;

    Player owner = null;

    if (mob instanceof Player) {
      owner = handleLootAndXpDistribution((Player) mob);
      if (PluginHandler.getPluginHandler()
          .blockDefaultAction("PlayerKilledNpc", new Object[] {owner, this})) {
        return;
      }
    }
    ItemDropDef[] drops = def.getDrops();

    int total = 0;
    for (ItemDropDef drop : drops) {
      total += drop.getWeight();
    }
    //
    int hit = DataConversions.random(0, total);
    total = 0;
    if (getCombatLevel() >= 90 && Constants.GameServer.MEMBER_WORLD) { // key halves?
      if (Formulae.Rand(0, 3000) == 500) {
        if (Formulae.Rand(0, 1) == 1) {
          world.registerItem(new Item(1276, getX(), getY(), 1, owner));
        } else {
          world.registerItem(new Item(1277, getX(), getY(), 1, owner));
        }
      }
    }
    for (ItemDropDef drop : drops) {
      if (drop == null) {
        continue;
      }
      if (drop.getWeight() == 0) {
        world.registerItem(new Item(drop.getID(), getX(), getY(), drop.getAmount(), owner));
        continue;
      }
      if (hit >= total && hit < (total + drop.getWeight())) {
        if (drop.getID() != -1) {
          if (EntityHandler.getItemDef(drop.getID()).members && Constants.GameServer.MEMBER_WORLD) {
            world.registerItem(new Item(drop.getID(), getX(), getY(), drop.getAmount(), owner));
            break;
          }
          if (!EntityHandler.getItemDef(drop.getID()).members) {
            world.registerItem(new Item(drop.getID(), getX(), getY(), drop.getAmount(), owner));
            break;
          }
        }
      }
      total += drop.getWeight();
    }
    // World.getQuestManager().handleNpcKilled(this, owner);
  }