forked from External/mage
Added possibility to check kind of cost to pay for conditional mana use.
This commit is contained in:
parent
d63f6d7d27
commit
c8f82b49ff
208 changed files with 770 additions and 571 deletions
|
|
@ -38,6 +38,7 @@ import mage.ConditionalMana;
|
|||
import mage.MageObject;
|
||||
import mage.Mana;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.ManaType;
|
||||
import mage.constants.TurnPhase;
|
||||
|
|
@ -108,9 +109,10 @@ public class ManaPool implements Serializable {
|
|||
* @param ability
|
||||
* @param filter
|
||||
* @param game
|
||||
* @param costToPay complete costs to pay (needed to check conditional mana)
|
||||
* @return
|
||||
*/
|
||||
public boolean pay(ManaType manaType, Ability ability, Filter filter, Game game) {
|
||||
public boolean pay(ManaType manaType, Ability ability, Filter filter, Game game, Cost costToPay) {
|
||||
if (!autoPayment && !manaType.equals(unlockedManaType)) {
|
||||
// if manual payment and the needed mana type was not unlocked, nothing will be paid
|
||||
return false;
|
||||
|
|
@ -121,8 +123,8 @@ public class ManaPool implements Serializable {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (getConditional(manaType, ability, filter, game) > 0) {
|
||||
removeConditional(manaType, ability, game);
|
||||
if (getConditional(manaType, ability, filter, game, costToPay) > 0) {
|
||||
removeConditional(manaType, ability, game, costToPay);
|
||||
lockManaType(); // pay only one mana if mana payment is set to manually
|
||||
return true;
|
||||
}
|
||||
|
|
@ -160,12 +162,14 @@ public class ManaPool implements Serializable {
|
|||
return getMana().get(manaType);
|
||||
}
|
||||
|
||||
private int getConditional(ManaType manaType, Ability ability, Filter filter, Game game) {
|
||||
private int getConditional(ManaType manaType, Ability ability, Filter filter, Game game, Cost costToPay) {
|
||||
if (ability == null || getConditionalMana().isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
for (ManaPoolItem mana : manaItems) {
|
||||
if (mana.isConditional() && mana.getConditionalMana().get(manaType) > 0 && mana.getConditionalMana().apply(ability, game, mana.getSourceId())) {
|
||||
if (mana.isConditional()
|
||||
&& mana.getConditionalMana().get(manaType) > 0
|
||||
&& mana.getConditionalMana().apply(ability, game, mana.getSourceId(), costToPay)) {
|
||||
if (filter == null || filter.match(game.getObject(mana.getSourceId()), game)) {
|
||||
return mana.getConditionalMana().get(manaType);
|
||||
}
|
||||
|
|
@ -174,13 +178,13 @@ public class ManaPool implements Serializable {
|
|||
return 0;
|
||||
}
|
||||
|
||||
public int getConditionalCount(Ability ability, Game game, FilterMana filter) {
|
||||
public int getConditionalCount(Ability ability, Game game, FilterMana filter, Cost costToPay) {
|
||||
if (ability == null || getConditionalMana().isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
int count = 0;
|
||||
for (ConditionalMana mana : getConditionalMana()) {
|
||||
if (mana.apply(ability, game, mana.getManaProducerId())) {
|
||||
if (mana.apply(ability, game, mana.getManaProducerId(), costToPay)) {
|
||||
count += mana.count(filter);
|
||||
}
|
||||
}
|
||||
|
|
@ -249,7 +253,7 @@ public class ManaPool implements Serializable {
|
|||
ManaPoolItem item = it.next();
|
||||
if (item.isConditional()) {
|
||||
ConditionalMana cm = item.getConditionalMana();
|
||||
if (cm.apply(ability, game, cm.getManaProducerId())) {
|
||||
if (cm.apply(ability, game, cm.getManaProducerId(), null)) {
|
||||
total += item.count();
|
||||
it.remove();
|
||||
}
|
||||
|
|
@ -279,7 +283,7 @@ public class ManaPool implements Serializable {
|
|||
ManaPoolItem item = it.next();
|
||||
if (item.isConditional()) {
|
||||
ConditionalMana c = item.getConditionalMana();
|
||||
if (c.apply(ability, game, c.getManaProducerId())) {
|
||||
if (c.apply(ability, game, c.getManaProducerId(), null)) {
|
||||
int count = c.count(filter);
|
||||
if (count > 0) {
|
||||
total += count;
|
||||
|
|
@ -362,7 +366,7 @@ public class ManaPool implements Serializable {
|
|||
|
||||
public Mana getAllConditionalMana(Ability ability, Game game, FilterMana filter) {
|
||||
Mana m = new Mana();
|
||||
m.setGeneric(getConditionalCount(ability, game, filter));
|
||||
m.setGeneric(getConditionalCount(ability, game, filter, null));
|
||||
return m;
|
||||
}
|
||||
|
||||
|
|
@ -414,9 +418,9 @@ public class ManaPool implements Serializable {
|
|||
return new ManaPool(this);
|
||||
}
|
||||
|
||||
private void removeConditional(ManaType manaType, Ability ability, Game game) {
|
||||
private void removeConditional(ManaType manaType, Ability ability, Game game, Cost costToPay) {
|
||||
for (ConditionalMana mana : getConditionalMana()) {
|
||||
if (mana.get(manaType) > 0 && mana.apply(ability, game, mana.getManaProducerId())) {
|
||||
if (mana.get(manaType) > 0 && mana.apply(ability, game, mana.getManaProducerId(), costToPay)) {
|
||||
mana.set(manaType, mana.get(manaType) - 1);
|
||||
GameEvent event = new GameEvent(GameEvent.EventType.MANA_PAYED, ability.getId(), mana.getManaProducerId(), ability.getControllerId(), 0, mana.getFlag());
|
||||
event.setData(mana.getManaProducerOriginalId().toString());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue