Fixes to token image handling.

This commit is contained in:
LevelX2 2015-07-19 10:09:50 +02:00
parent 6ef50c42bf
commit 4324a6a683
14 changed files with 356 additions and 71 deletions

View file

@ -27,7 +27,9 @@
*/
package mage.game.permanent.token;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import mage.MageInt;
import mage.constants.CardType;
@ -38,9 +40,15 @@ import mage.constants.CardType;
*/
public class BeastToken extends Token {
final static private List<String> tokenImageSets = new ArrayList<>();
static {
tokenImageSets.addAll(Arrays.asList("C14", "LRW", "M15", "M14", "DDL", "M13", "M12"));
}
public BeastToken() {
super("Beast", "3/3 green Beast creature token");
availableImageSetCodes.addAll(Arrays.asList("C14", "LRW", "M15", "M14", "DDL", "M13", "M12"));
availableImageSetCodes = tokenImageSets;
cardType.add(CardType.CREATURE);
color.setGreen(true);
subtype.add("Beast");
@ -59,4 +67,13 @@ public class BeastToken extends Token {
this.setTokenType(2);
}
}
public BeastToken(final BeastToken token) {
super(token);
}
@Override
public BeastToken copy() {
return new BeastToken(this); //To change body of generated methods, choose Tools | Templates.
}
}

View file

@ -27,7 +27,9 @@
*/
package mage.game.permanent.token;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import mage.MageInt;
import mage.constants.CardType;
@ -37,9 +39,15 @@ import mage.constants.CardType;
*/
public class ElfToken extends Token {
final static private List<String> tokenImageSets = new ArrayList<>();
static {
tokenImageSets.addAll(Arrays.asList("C14", "SHM", "EVG", "LRW", "ORI"));
}
public ElfToken() {
super("Elf Warrior", "1/1 green Elf Warrior creature token");
availableImageSetCodes.addAll(Arrays.asList("C14", "SHM", "EVG", "LRW", "ORI"));
availableImageSetCodes = tokenImageSets;
cardType.add(CardType.CREATURE);
color.setGreen(true);
subtype.add("Elf");
@ -55,4 +63,13 @@ public class ElfToken extends Token {
this.setTokenType(1);
}
}
public ElfToken(final ElfToken token) {
super(token);
}
@Override
public ElfToken copy() {
return new ElfToken(this); //To change body of generated methods, choose Tools | Templates.
}
}

View file

@ -39,7 +39,7 @@ public class GoblinToken extends Token {
public GoblinToken() {
super("Goblin", "1/1 red Goblin creature token");
availableImageSetCodes.addAll(Arrays.asList("SOM", "M10", "C14", "KTK", "EVG", "DTK", "ORI"));
availableImageSetCodes.addAll(Arrays.asList("SOM", "M10", "C14", "KTK", "EVG", "DTK", "ORI", "DDG"));
cardType.add(CardType.CREATURE);
subtype.add("Goblin");

View file

@ -1,33 +1,36 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.game.permanent.token;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import mage.MageInt;
import mage.constants.CardType;
@ -37,18 +40,38 @@ import mage.constants.CardType;
*/
public class SoldierToken extends Token {
public SoldierToken() {
this("10E");
final static private List<String> tokenImageSets = new ArrayList<>();
static {
tokenImageSets.addAll(Arrays.asList("10E", "M15", "C14", "ORI", "ALA", "DDF", "THS", "M12", "M13", "MM2", "MMA", "RTR", "SOM"));
}
public SoldierToken(String setCode) {
public SoldierToken() {
super("Soldier", "1/1 white Soldier creature token");
this.setOriginalExpansionSetCode(setCode);
availableImageSetCodes = tokenImageSets;
cardType.add(CardType.CREATURE);
color.setWhite(true);
subtype.add("Soldier");
power = new MageInt(1);
toughness = new MageInt(1);
}
@Override
public void setExpansionSetCodeForImage(String code) {
super.setExpansionSetCodeForImage(code);
if (getOriginalExpansionSetCode().equals("THS")) {
this.setTokenType(new Random().nextInt(2) + 1);
}
}
public SoldierToken(final SoldierToken token) {
super(token);
}
@Override
public SoldierToken copy() {
return new SoldierToken(this); //To change body of generated methods, choose Tools | Templates.
}
}

View file

@ -27,6 +27,9 @@
*/
package mage.game.permanent.token;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import mage.MageInt;
import mage.constants.CardType;
@ -36,12 +39,15 @@ import mage.constants.CardType;
*/
public class SquirrelToken extends Token {
public SquirrelToken() {
this("CNS");
final static private List<String> tokenImageSets = new ArrayList<>();
static {
tokenImageSets.addAll(Arrays.asList("CNS"));
}
public SquirrelToken(String setCode) {
public SquirrelToken() {
super("Squirrel", "1/1 green Squirrel creature token");
setOriginalExpansionSetCode(setCode);
availableImageSetCodes = tokenImageSets;
cardType.add(CardType.CREATURE);
subtype.add("Squirrel");

View file

@ -27,7 +27,9 @@
*/
package mage.game.permanent.token;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import mage.MageInt;
import mage.abilities.keyword.FlyingAbility;
@ -39,9 +41,15 @@ import mage.constants.CardType;
*/
public class ThopterColorlessToken extends Token {
final static private List<String> tokenImageSets = new ArrayList<>();
static {
tokenImageSets.addAll(Arrays.asList("EXO", "ORI"));
}
public ThopterColorlessToken() {
super("Thopter", "1/1 colorless Thopter artifact creature token with flying");
availableImageSetCodes.addAll(Arrays.asList("EXO", "ORI"));
availableImageSetCodes = tokenImageSets;
cardType.add(CardType.ARTIFACT);
cardType.add(CardType.CREATURE);
subtype.add("Thopter");
@ -58,4 +66,14 @@ public class ThopterColorlessToken extends Token {
this.setTokenType(new Random().nextInt(2) + 1);
}
}
public ThopterColorlessToken(final ThopterColorlessToken token) {
super(token);
}
@Override
public ThopterColorlessToken copy() {
return new ThopterColorlessToken(this); //To change body of generated methods, choose Tools | Templates.
}
}

View file

@ -100,6 +100,7 @@ public class Token extends MageObjectImpl {
this.originalCardNumber = token.originalCardNumber;
this.originalExpansionSetCode = token.originalExpansionSetCode;
this.copySourceCard = token.copySourceCard; // will never be changed
this.availableImageSetCodes = token.availableImageSetCodes;
}
public String getDescription() {
@ -216,6 +217,10 @@ public class Token extends MageObjectImpl {
} else {
setOriginalExpansionSetCode(availableImageSetCodes.get(new Random().nextInt(availableImageSetCodes.size())));
}
} else {
if (getOriginalExpansionSetCode() == null || getOriginalExpansionSetCode().isEmpty()) {
setOriginalExpansionSetCode(code);
}
}
}
}

View file

@ -27,7 +27,9 @@
*/
package mage.game.permanent.token;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import mage.MageInt;
import mage.constants.CardType;
@ -38,9 +40,15 @@ import mage.constants.CardType;
*/
public class ZombieToken extends Token {
final static private List<String> tokenImageSets = new ArrayList<>();
static {
tokenImageSets.addAll(Arrays.asList("10E", "M10", "M11", "M12", "M13", "M14", "M15", "MBS", "ALA", "ISD", "C14", "CNS", "MMA", "BNG", "KTK", "DTK", "ORI"));
}
public ZombieToken() {
super("Zombie", "2/2 black Zombie creature token");
availableImageSetCodes.addAll(Arrays.asList("10E", "M10", "M11", "M12", "M13", "M14", "M15", "MBS", "ALA", "ISD", "C14", "CNS", "MMA", "BNG", "KTK", "DTK", "ORI"));
availableImageSetCodes = tokenImageSets;
cardType.add(CardType.CREATURE);
color.setBlack(true);
subtype.add("Zombie");
@ -56,4 +64,12 @@ public class ZombieToken extends Token {
}
}
public ZombieToken(final ZombieToken token) {
super(token);
}
@Override
public ZombieToken copy() {
return new ZombieToken(this); //To change body of generated methods, choose Tools | Templates.
}
}

View file

@ -376,26 +376,94 @@ public abstract class TargetImpl implements Target {
return targets.size() > 0;
}
/**
* Returns all possible different target combinations
*
* @param source
* @param game
* @return
*/
@Override
public List<? extends TargetImpl> getTargetOptions(Ability source, Game game) {
List<TargetImpl> options = new ArrayList<>();
Set<UUID> possibleTargets = possibleTargets(source.getSourceId(), source.getControllerId(), game);
List<UUID> possibleTargets = new ArrayList<>();
possibleTargets.addAll(possibleTargets(source.getSourceId(), source.getControllerId(), game));
possibleTargets.removeAll(getTargets());
Iterator<UUID> it = possibleTargets.iterator();
while (it.hasNext()) {
UUID targetId = it.next();
// get the length of the array
// e.g. for {'A','B','C','D'} => N = 4
int N = possibleTargets.size();
// not enough targets, return no option
if (N < getNumberOfTargets()) {
return options;
}
// not target but that's allowed, return one empty option
if (N == 0) {
TargetImpl target = this.copy();
target.clearChosen();
target.addTarget(targetId, source, game, true);
if (!target.isChosen()) {
Iterator<UUID> it2 = possibleTargets.iterator();
while (it2.hasNext() && !target.isChosen()) {
UUID nextTargetId = it2.next();
target.addTarget(nextTargetId, source, game, true);
}
options.add(target);
return options;
}
int maxK = getMaxNumberOfTargets() - getTargets().size();
if (maxK > 5) { // Prevent endless iteration with targets set to INTEGER.maxvalue
maxK = 5;
if (N > 10) { // not more than 252 combinations
maxK = 4;
}
if (target.isChosen()) {
options.add(target);
if (N > 20) { // not more than 4845 combinations
maxK = 3;
}
}
if (N < maxK) { // less possible targets than the maximum allowed so reduce the max
maxK = N;
}
int minK = getNumberOfTargets();
if (getNumberOfTargets() == 0) { // add option without targets if possible
TargetImpl target = this.copy();
options.add(target);
minK = 1;
}
for (int K = minK; K <= maxK; K++) {
// get the combination by index
// e.g. 01 --> AB , 23 --> CD
int combination[] = new int[K];
// position of current index
// if (r = 1) r*
// index ==> 0 | 1 | 2
// element ==> A | B | C
int r = 0;
int index = 0;
while (r >= 0) {
// possible indexes for 1st position "r=0" are "0,1,2" --> "A,B,C"
// possible indexes for 2nd position "r=1" are "1,2,3" --> "B,C,D"
// for r = 0 ==> index < (4+ (0 - 2)) = 2
if (index <= (N + (r - K))) {
combination[r] = index;
// if we are at the last position print and increase the index
if (r == K - 1) {
//add the new target option
TargetImpl target = this.copy();
for (int i = 0; i < combination.length; i++) {
target.addTarget(possibleTargets.get(combination[i]), source, game, true);
}
options.add(target);
index++;
} else {
// select index for next position
index = combination[r] + 1;
r++;
}
} else {
r--;
if (r > 0) {
index = combination[r] + 1;
} else {
index = combination[0] + 1;
}
}
}
}
return options;