/******************************************************************************* * Copyright (c) 2015 * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. *******************************************************************************/ package jsettlers.logic.movable.strategies.soldiers; import jsettlers.common.movable.EMovableAction; import jsettlers.common.movable.EMovableType; import jsettlers.common.movable.ESoldierClass; import jsettlers.logic.constants.Constants; import jsettlers.logic.movable.Movable; import jsettlers.logic.movable.interfaces.IAttackable; /** * Strategy for swordsman and pikeman {@link Movable}s. * * @author Andreas Eberle * */ public final class InfantryStrategy extends SoldierStrategy { private static final long serialVersionUID = -2367165698305111060L; private static final float INFANTRY_ATTACK_DURATION = 1; public InfantryStrategy(Movable movable, EMovableType movableType) { super(movable, movableType); } @Override public final ESoldierClass getSoldierClass() { return ESoldierClass.INFANTRY; } @Override protected boolean isEnemyAttackable(IAttackable enemy, boolean isInTower) { int maxDistance = movable.getPos().getOnGridDistTo(enemy.getPos()); return (maxDistance == 1 || (!enemy.isTower() && super.getMovableType().isPikeman() && maxDistance <= 2)); } @Override protected void startAttackAnimation(IAttackable enemy) { super.playAction(EMovableAction.ACTION1, INFANTRY_ATTACK_DURATION); } @Override protected void hitEnemy(IAttackable enemy) { enemy.receiveHit(super.getMovableType().getStrength() * getCombatStrength(), movable.getPos(), movable.getPlayer().playerId); // decrease the enemy's health } @Override protected short getMaxSearchDistance(boolean isInTower) { return Constants.SOLDIER_SEARCH_RADIUS; } @Override protected short getMinSearchDistance() { return 0; } }