示例#1
0
  public Npc(NPCLoc loc) {
    for (int i : Constants.GameServer.UNDEAD_NPCS) {
      if (loc.getId() == i) {
        this.undead = true;
      }
    }
    for (int i : Constants.GameServer.ARMOR_NPCS) {
      if (loc.getId() == i) {
        this.hasArmor = true;
      }
    }

    def = EntityHandler.getNpcDef(loc.getId());
    curHits = def.getHits();

    this.loc = loc;
    super.setID(loc.getId());
    this.setLocation(Point.location(loc.startX(), loc.startY()), true);
    super.setCombatLevel(
        Formulae.getCombatLevel(def.getAtt(), def.getDef(), def.getStr(), def.getHits(), 0, 0, 0));

    if (this.loc.getId() == 189
        || this.loc.getId() == 53
        || this.loc.getId() == 19) { // this should not be here
      this.def.aggressive = true;
    }
  }
示例#2
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;
  }
示例#3
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);
  }
示例#4
0
 public void weakenStrength(int offset) {
   super.setCombatLevel(
       Formulae.getCombatLevel(
           def.getAtt(), def.getDef(), (def.getStr() - offset), def.getHits(), 0, 0, 0));
 }