package main; public class Action { private long interval; public long timeLastPerformed; private long timeJustPerformed; public Action(final long interval) { this.interval = interval; this.timeLastPerformed = 0L; this.timeJustPerformed = 0L; } public Action(final Action copy) { this.interval = copy.interval; this.timeLastPerformed = 0L; this.timeJustPerformed = 0L; } public Action copy() { return new Action(this); } public boolean readyToPerform() { if (this.timeJustPerformed == 0L) { this.timeJustPerformed = System.currentTimeMillis(); this.timeLastPerformed = this.timeJustPerformed; return true; } final long timeCurrent = System.currentTimeMillis(); if (timeCurrent - this.timeJustPerformed >= this.interval) { this.timeLastPerformed = this.timeJustPerformed; this.timeJustPerformed = timeCurrent; return true; } return false; } public static class Defend extends Action { public Defend(final long interval) { super(interval); } public Defend(final Defend copy) { super(copy); } @Override public Defend copy() { return new Defend(this); } } public static class Fire extends Action { public Fire(final long interval) { super(interval); } public Fire(final Fire copy) { super(copy); } @Override public Fire copy() { return new Fire(this); } } public static class Move extends Action { public Move(final long interval) { super(interval); } public Move(final Move copy) { super(copy); } @Override public Move copy() { return new Move(this); } } }