Search in sources :

Example 1 with AttackStrategy

use of net.citizensnpcs.api.ai.AttackStrategy in project Citizens2 by CitizensDev.

the class MCTargetStrategy method update.

@Override
public boolean update() {
    if (target == null || !target.isValid()) {
        cancelReason = CancelReason.TARGET_DIED;
        return true;
    }
    if (target.getWorld() != handle.getWorld()) {
        cancelReason = CancelReason.TARGET_MOVED_WORLD;
        return true;
    }
    if (cancelReason != null) {
        return true;
    }
    if (!aggro && distanceSquared() <= parameters.distanceMargin()) {
        stop();
        return false;
    } else if (updateCounter == -1 || updateCounter++ > parameters.updatePathRate()) {
        targetNavigator.setPath();
        updateCounter = 0;
    }
    targetNavigator.update();
    NMS.look(handle, target);
    if (aggro && canAttack()) {
        AttackStrategy strategy = parameters.attackStrategy();
        if (strategy != null && strategy.handle((LivingEntity) handle, (LivingEntity) getTarget())) {
        } else if (strategy != parameters.defaultAttackStrategy()) {
            parameters.defaultAttackStrategy().handle((LivingEntity) handle, (LivingEntity) getTarget());
        }
        attackTicks = parameters.attackDelayTicks();
    }
    if (attackTicks > 0) {
        attackTicks--;
    }
    return false;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) AttackStrategy(net.citizensnpcs.api.ai.AttackStrategy)

Aggregations

AttackStrategy (net.citizensnpcs.api.ai.AttackStrategy)1 LivingEntity (org.bukkit.entity.LivingEntity)1