mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
minimize need to player type checks
This commit is contained in:
@@ -121,6 +121,7 @@ public abstract class PlayerController {
|
||||
public abstract List<Card> choosePermanentsToSacrifice(SpellAbility sa, int min, int max, List<Card> validTargets, String message);
|
||||
public abstract List<Card> choosePermanentsToDestroy(SpellAbility sa, int min, int max, List<Card> validTargets, String message);
|
||||
public abstract TargetChoices chooseNewTargetsFor(SpellAbility ability);
|
||||
public abstract boolean chooseTargetsFor(SpellAbility currentAbility); // this is bad a function for it assigns targets to sa inside its body
|
||||
|
||||
// Specify a target of a spell (Spellskite)
|
||||
public abstract Pair<SpellAbilityStackInstance, GameObject> chooseTarget(SpellAbility sa, List<Pair<SpellAbilityStackInstance, GameObject>> allTargets);
|
||||
|
||||
@@ -50,7 +50,6 @@ import forge.game.spellability.Spell;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.SpellAbilityStackInstance;
|
||||
import forge.game.spellability.TargetChoices;
|
||||
import forge.game.spellability.TargetSelection;
|
||||
import forge.game.trigger.Trigger;
|
||||
import forge.game.trigger.WrappedAbility;
|
||||
import forge.game.zone.ZoneType;
|
||||
@@ -73,9 +72,6 @@ public class PlayerControllerAi extends PlayerController {
|
||||
brains = new AiController(p, game);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses GUI to learn which spell the player (human in our case) would like to play
|
||||
*/
|
||||
public SpellAbility getAbilityToPlay(List<SpellAbility> abilities, MouseEvent triggerEvent) {
|
||||
if (abilities.size() == 0) {
|
||||
return null;
|
||||
@@ -636,12 +632,7 @@ public class PlayerControllerAi extends PlayerController {
|
||||
private void prepareSingleSa(final Card host, final SpellAbility sa, boolean isMandatory){
|
||||
if (sa.hasParam("TargetingPlayer")) {
|
||||
Player targetingPlayer = AbilityUtils.getDefinedPlayers(host, sa.getParam("TargetingPlayer"), sa).get(0);
|
||||
if (targetingPlayer.isHuman()) {
|
||||
final TargetSelection select = new TargetSelection(sa);
|
||||
select.chooseTargets(null);
|
||||
} else { //AI
|
||||
sa.doTrigger(true, targetingPlayer);
|
||||
}
|
||||
targetingPlayer.getController().chooseTargetsFor(sa);
|
||||
} else {
|
||||
sa.doTrigger(isMandatory, player);
|
||||
}
|
||||
@@ -676,4 +667,9 @@ public class PlayerControllerAi extends PlayerController {
|
||||
return brains.chooseProliferation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean chooseTargetsFor(SpellAbility currentAbility) {
|
||||
return currentAbility.doTrigger(true, player);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -117,15 +117,9 @@ public class HumanPlaySpellAbility {
|
||||
clearTargets(currentAbility);
|
||||
Player targetingPlayer = ability.hasParam("TargetingPlayer") ?
|
||||
AbilityUtils.getDefinedPlayers(source, ability.getParam("TargetingPlayer"), currentAbility).get(0) : ability.getActivatingPlayer();
|
||||
if (targetingPlayer.isHuman()) {
|
||||
final TargetSelection select = new TargetSelection(currentAbility);
|
||||
if (!select.chooseTargets(null)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else { //AI
|
||||
return currentAbility.doTrigger(true, targetingPlayer);
|
||||
}
|
||||
|
||||
if (!targetingPlayer.getController().chooseTargetsFor(currentAbility))
|
||||
return false;
|
||||
}
|
||||
final SpellAbility subAbility = currentAbility.getSubAbility();
|
||||
if (subAbility != null) {
|
||||
|
||||
@@ -53,7 +53,6 @@ import forge.game.spellability.AbilitySub;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.SpellAbilityStackInstance;
|
||||
import forge.game.spellability.TargetChoices;
|
||||
import forge.game.spellability.TargetSelection;
|
||||
import forge.game.trigger.Trigger;
|
||||
import forge.game.trigger.WrappedAbility;
|
||||
import forge.game.zone.Zone;
|
||||
@@ -1019,4 +1018,11 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
return null;
|
||||
return inp.getProliferationMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean chooseTargetsFor(SpellAbility currentAbility) {
|
||||
final TargetSelection select = new TargetSelection(currentAbility);
|
||||
return select.chooseTargets(null);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.game.spellability;
|
||||
package forge.gui.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -28,6 +28,9 @@ import forge.game.GameObject;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardLists;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.SpellAbilityStackInstance;
|
||||
import forge.game.spellability.TargetRestrictions;
|
||||
import forge.game.zone.Zone;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.gui.GuiChoose;
|
||||
@@ -44,7 +44,6 @@ import forge.game.spellability.Spell;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.SpellAbilityStackInstance;
|
||||
import forge.game.spellability.TargetChoices;
|
||||
import forge.game.spellability.TargetSelection;
|
||||
import forge.game.trigger.Trigger;
|
||||
import forge.game.trigger.WrappedAbility;
|
||||
import forge.game.zone.ZoneType;
|
||||
@@ -496,12 +495,7 @@ public class PlayerControllerForTests extends PlayerController {
|
||||
private void prepareSingleSa(final Card host, final SpellAbility sa, boolean isMandatory){
|
||||
if (sa.hasParam("TargetingPlayer")) {
|
||||
Player targetingPlayer = AbilityUtils.getDefinedPlayers(host, sa.getParam("TargetingPlayer"), sa).get(0);
|
||||
if (targetingPlayer.isHuman()) {
|
||||
final TargetSelection select = new TargetSelection(sa);
|
||||
select.chooseTargets(null);
|
||||
} else { //AI
|
||||
sa.doTrigger(true, targetingPlayer);
|
||||
}
|
||||
targetingPlayer.getController().chooseTargetsFor(sa);
|
||||
} else {
|
||||
sa.doTrigger(isMandatory, player);
|
||||
}
|
||||
@@ -538,4 +532,9 @@ public class PlayerControllerForTests extends PlayerController {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean chooseTargetsFor(SpellAbility currentAbility) {
|
||||
return currentAbility.doTrigger(true, player);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user