Package games.stendhal.server.entity.creature.impl.attack

Source Code of games.stendhal.server.entity.creature.impl.attack.HandToHand

/* $Id: HandToHand.java,v 1.3 2011/02/11 17:14:37 kiheru Exp $ */
/***************************************************************************
*                   (C) Copyright 2003-2010 - Stendhal                    *
***************************************************************************
***************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
***************************************************************************/
package games.stendhal.server.entity.creature.impl.attack;

import games.stendhal.server.core.engine.SingletonRepository;
import games.stendhal.server.entity.RPEntity;
import games.stendhal.server.entity.creature.Creature;

class HandToHand implements AttackStrategy {

  private static final int FOLLOW_RADIUS = 12;

  public void attack(final Creature creature) {
    if (creature.isAttackTurn(SingletonRepository.getRuleProcessor().getTurn())) {
      creature.attack();
      creature.tryToPoison();
    }
  }

  public boolean canAttackNow(final Creature creature) {
    if (creature.getAttackTarget() != null) {
      return creature.squaredDistance(creature.getAttackTarget()) < 1;
    } else {
      return false;
    }
  }

  public void findNewTarget(final Creature creature) {
    final RPEntity enemy = creature.getNearestEnemy(creature.getPerceptionRange()+2);
    if (enemy != null) {
      creature.setTarget(enemy);
    }
  }

  public void getBetterAttackPosition(final Creature creature) {
    final games.stendhal.server.entity.Entity target = creature.getAttackTarget();
    if (creature.hasTargetMoved()) {
      creature.setMovement(target, 0, 1, creature.getMovementRange());
    }
    if (!creature.hasPath()) {
      if ((int) creature.squaredDistance(target) >= 1) {
        creature.stopAttack();
        return;
      }
    }
    creature.faceToward(creature.getAttackTarget());
  }

  public boolean hasValidTarget(final Creature creature) {
    if (!creature.isAttacking()) {
      return false;
    }

    final RPEntity victim = creature.getAttackTarget();
    if (victim.isInvisibleToCreatures()) {
      return false;
    }
    if (!victim.getZone().equals(creature.getZone())) {
      return false;
    }

    if (!creature.getZone().has(victim.getID())) {
      return false;
    }
    return creature.squaredDistance(victim) < (FOLLOW_RADIUS * FOLLOW_RADIUS);
  }

  public int getRange() {
    return 0;
  }
}
TOP

Related Classes of games.stendhal.server.entity.creature.impl.attack.HandToHand

TOP
Copyright © 2018 www.massapi.com. 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.