コード例 #1
0
  @Override
  public void attackTarget(Creature target) {
    Npc npc = getOwner();

    /** Check all prerequisites */
    if (npc == null || npc.getLifeStats().isAlreadyDead() || !npc.isSpawned()) return;

    if (!npc.canAttack()) return;

    AI<?> ai = npc.getAi();
    NpcGameStats gameStats = npc.getGameStats();

    if (target == null || target.getLifeStats().isAlreadyDead()) {
      ai.handleEvent(Event.MOST_HATED_CHANGED);
      return;
    }

    /** notify attack observers */
    super.attackTarget(target);

    /** Calculate and apply damage */
    List<AttackResult> attackList = AttackUtil.calculateAttackResult(npc, target);

    int damage = 0;
    for (AttackResult result : attackList) {
      damage += result.getDamage();
    }

    int attackType = 0; // TODO investigate attack types (0 or 1)
    PacketSendUtility.broadcastPacket(
        npc, new SM_ATTACK(npc, target, gameStats.getAttackCounter(), 274, attackType, attackList));

    target.getController().onAttack(npc, damage, true);
    gameStats.increaseAttackCounter();
  }
 @Override
 public void handleEvent(Event event, AI<?> ai) {
   ai.setAiState(AIState.THINKING);
 }