Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.apollo.game.model.combat;
- import org.apollo.game.action.Action;
- import org.apollo.game.model.Animation;
- import org.apollo.game.model.Character;
- import org.apollo.game.model.Position;
- /**
- * Represents a character attacking another character.
- * @author Michael Bull (Scu11)
- *
- */
- public class CombatAction extends Action<Character> {
- /**
- * Combat action constant.
- */
- public static final CombatAction COMBAT_ACTION = new CombatAction(null, null, false);
- /**
- * The opponent this character is attacking.
- */
- private final Character opponent;
- /**
- * Default constructor.
- * @param character The character who is attacking.
- * @param opponent The character being attacked.
- * @param retaliating The auto retaliate flag.
- */
- public CombatAction(Character character, Character opponent, boolean retaliating) {
- super(retaliating ? 4 : 0, true, true, character);
- this.opponent = opponent;
- }
- /**
- * Gets the opponent this character is attacking.
- * @return The opponent this character is attacking.
- */
- public Character getOpponent() {
- return opponent;
- }
- @Override
- public void execute() {
- if (getCharacter() == null || getOpponent() == null) {
- stop();
- }
- setDelay(getCharacter().getCombatState().getCombatDelay() - 1); // we take 1 pusle off as all actions require at least one pulse
- getCharacter().setInteractingCharacter(getOpponent());
- getCharacter().playAnimation(new Animation(getCharacter().getCombatState().getAttackAnimation()));
- getOpponent().playAnimation(new Animation(getOpponent().getCombatState().getDefendAnimation()));
- if(getOpponent().getCombatState().isAutoRetaliating()) {
- if (getOpponent().getAction() == null ||
- (getOpponent().getAction().isCancellable() &&
- (!getOpponent().actionEquals(COMBAT_ACTION) ||
- ((CombatAction) getOpponent().getAction()).getOpponent() != getCharacter()))) {
- getOpponent().startAction(new CombatAction(getOpponent(), getCharacter(), true));
- getOpponent().setInteractingCharacter(getCharacter());
- }
- }
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- CombatAction other = (CombatAction) obj;
- if (other.getOpponent() != this.opponent) {
- return false;
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement