mirror of
https://github.com/magefree/mage.git
synced 2025-12-28 22:42:03 -08:00
Added new option for mana payment handling of mana already in the mana pool. Reworked the battlefield context menu a bit.
This commit is contained in:
parent
8066fe911c
commit
907ec7abb0
11 changed files with 263 additions and 139 deletions
|
|
@ -44,6 +44,8 @@ public enum PlayerAction {
|
|||
CONCEDE,
|
||||
MANA_AUTO_PAYMENT_ON,
|
||||
MANA_AUTO_PAYMENT_OFF,
|
||||
MANA_AUTO_PAYMENT_RESTRICTED_ON,
|
||||
MANA_AUTO_PAYMENT_RESTRICTED_OFF,
|
||||
RESET_AUTO_SELECT_REPLACEMENT_EFFECTS,
|
||||
REVOKE_PERMISSIONS_TO_SEE_HAND_CARDS,
|
||||
REQUEST_PERMISSION_TO_SEE_HAND_CARDS,
|
||||
|
|
|
|||
|
|
@ -224,7 +224,8 @@ public interface Game extends MageItem, Serializable {
|
|||
void timerTimeout(UUID playerId);
|
||||
void idleTimeout(UUID playerId);
|
||||
void concede(UUID playerId);
|
||||
void setManaPoolMode(UUID playerId, boolean autoPayment);
|
||||
void setManaPaymentMode(UUID playerId, boolean autoPayment);
|
||||
void setManaPaymentModeRestricted(UUID playerId, boolean autoPaymentRestricted);
|
||||
void undo(UUID playerId);
|
||||
void emptyManaPools();
|
||||
void addEffect(ContinuousEffect continuousEffect, Ability source);
|
||||
|
|
|
|||
|
|
@ -1124,12 +1124,20 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
|
||||
|
||||
@Override
|
||||
public synchronized void setManaPoolMode(UUID playerId, boolean autoPayment) {
|
||||
public synchronized void setManaPaymentMode(UUID playerId, boolean autoPayment) {
|
||||
Player player = state.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
player.getManaPool().setAutoPayment(autoPayment);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void setManaPaymentModeRestricted(UUID playerId, boolean autoPaymentRestricted) {
|
||||
Player player = state.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
player.getManaPool().setAutoPaymentRestricted(autoPaymentRestricted);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playPriority(UUID activePlayerId, boolean resuming) {
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ public class ManaPool implements Serializable {
|
|||
private final List<ManaPoolItem> manaItems = new ArrayList<>();
|
||||
|
||||
private boolean autoPayment; // auto payment from mana pool: true - mode is active
|
||||
private boolean autoPaymentRestricted; // auto payment from mana pool: true - if auto Payment is on, it will only pay if one kind of mana is in the pool
|
||||
private ManaType unlockedManaType; // type of mana that was selected to pay manually
|
||||
|
||||
private final Set<ManaType> doNotEmptyManaTypes = new HashSet<>();
|
||||
|
|
@ -68,6 +69,7 @@ public class ManaPool implements Serializable {
|
|||
public ManaPool(UUID playerId) {
|
||||
this.playerId = playerId;
|
||||
autoPayment = true;
|
||||
autoPaymentRestricted = true;
|
||||
unlockedManaType = null;
|
||||
}
|
||||
|
||||
|
|
@ -77,6 +79,7 @@ public class ManaPool implements Serializable {
|
|||
manaItems.add(item.copy());
|
||||
}
|
||||
this.autoPayment = pool.autoPayment;
|
||||
this.autoPaymentRestricted = pool.autoPaymentRestricted;
|
||||
this.unlockedManaType = pool.unlockedManaType;
|
||||
this.doNotEmptyManaTypes.addAll(pool.doNotEmptyManaTypes);
|
||||
}
|
||||
|
|
@ -101,11 +104,25 @@ public class ManaPool implements Serializable {
|
|||
return get(ManaType.BLACK);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param manaType the mana type that should be paid
|
||||
* @param ability
|
||||
* @param filter
|
||||
* @param game
|
||||
* @return
|
||||
*/
|
||||
public boolean pay(ManaType manaType, Ability ability, Filter filter, Game game) {
|
||||
if (!autoPayment && !manaType.equals(unlockedManaType)) {
|
||||
// if manual payment and the needed mana type was not unlocked, nothing will be paid
|
||||
return false;
|
||||
}
|
||||
if (autoPayment && autoPaymentRestricted && !wasManaAddedBeyondStock() && !manaType.equals(unlockedManaType)) {
|
||||
// if automatic restricted payment and there is laready mana in the pool
|
||||
// and the needed mana type was not unlocked, nothing will be paid
|
||||
return false;
|
||||
}
|
||||
|
||||
if (getConditional(manaType, ability, filter, game) > 0) {
|
||||
removeConditional(manaType, ability, game);
|
||||
lockManaType(); // pay only one mana if mana payment is set to manually
|
||||
|
|
@ -118,6 +135,10 @@ public class ManaPool implements Serializable {
|
|||
continue;
|
||||
}
|
||||
}
|
||||
if (!manaType.equals(unlockedManaType) && autoPayment && autoPaymentRestricted && mana.count() == mana.getStock()) {
|
||||
// no mana added beyond the stock so don't auto pay this
|
||||
continue;
|
||||
}
|
||||
boolean spendAnyMana = spendAnyMana(ability, game);
|
||||
if (mana.get(manaType) > 0 || (spendAnyMana && mana.count() > 0)) {
|
||||
GameEvent event = new GameEvent(GameEvent.EventType.MANA_PAYED, ability.getId(), mana.getSourceId(), ability.getControllerId(), 0, mana.getFlag());
|
||||
|
|
@ -128,6 +149,9 @@ public class ManaPool implements Serializable {
|
|||
} else {
|
||||
mana.remove(manaType);
|
||||
}
|
||||
if (mana.count() == 0) { // so no items with count 0 stay in list
|
||||
manaItems.remove(mana);
|
||||
}
|
||||
lockManaType(); // pay only one mana if mana payment is set to manually
|
||||
return true;
|
||||
}
|
||||
|
|
@ -416,6 +440,14 @@ public class ManaPool implements Serializable {
|
|||
this.autoPayment = autoPayment;
|
||||
}
|
||||
|
||||
public void setAutoPaymentRestricted(boolean autoPaymentRestricted) {
|
||||
this.autoPaymentRestricted = autoPaymentRestricted;
|
||||
}
|
||||
|
||||
public boolean isAutoPaymentRestricted() {
|
||||
return autoPaymentRestricted;
|
||||
}
|
||||
|
||||
public ManaType getUnlockedManaType() {
|
||||
return unlockedManaType;
|
||||
}
|
||||
|
|
@ -428,4 +460,18 @@ public class ManaPool implements Serializable {
|
|||
this.unlockedManaType = null;
|
||||
}
|
||||
|
||||
public void setStock() {
|
||||
for (ManaPoolItem mana : manaItems) {
|
||||
mana.setStock(mana.count());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean wasManaAddedBeyondStock() {
|
||||
for (ManaPoolItem mana : manaItems) {
|
||||
if (mana.getStock() < mana.count()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ public class ManaPoolItem implements Serializable {
|
|||
private UUID originalId; // originalId of the mana producing ability
|
||||
private boolean flag = false;
|
||||
private Duration duration;
|
||||
private int stock; // amount the item had at the start of casting something
|
||||
|
||||
public ManaPoolItem() {}
|
||||
|
||||
|
|
@ -91,6 +92,7 @@ public class ManaPoolItem implements Serializable {
|
|||
this.originalId = item.originalId;
|
||||
this.flag = item.flag;
|
||||
this.duration = item.duration;
|
||||
this.stock = item.stock;
|
||||
}
|
||||
|
||||
public ManaPoolItem copy() {
|
||||
|
|
@ -207,8 +209,9 @@ public class ManaPoolItem implements Serializable {
|
|||
}
|
||||
|
||||
public void removeAny() {
|
||||
int oldCount = count();
|
||||
if (black > 0) {
|
||||
black--;
|
||||
black--;
|
||||
} else if (blue > 0) {
|
||||
blue--;
|
||||
} else if (green > 0) {
|
||||
|
|
@ -219,10 +222,14 @@ public class ManaPoolItem implements Serializable {
|
|||
white--;
|
||||
} else if (colorless > 0) {
|
||||
colorless--;
|
||||
}
|
||||
}
|
||||
if (stock == oldCount && oldCount > count()) {
|
||||
stock--;
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(ManaType manaType) {
|
||||
int oldCount = count();
|
||||
switch(manaType) {
|
||||
case BLACK:
|
||||
if (black > 0) {
|
||||
|
|
@ -255,6 +262,9 @@ public class ManaPoolItem implements Serializable {
|
|||
}
|
||||
break;
|
||||
}
|
||||
if (stock == oldCount && oldCount > count()) {
|
||||
stock--;
|
||||
}
|
||||
}
|
||||
|
||||
public void clear(ManaType manaType) {
|
||||
|
|
@ -310,5 +320,13 @@ public class ManaPoolItem implements Serializable {
|
|||
public void setDuration(Duration duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public int getStock() {
|
||||
return stock;
|
||||
}
|
||||
|
||||
public void setStock(int stock) {
|
||||
this.stock = stock;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1085,6 +1085,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
|
||||
@Override
|
||||
public boolean activateAbility(ActivatedAbility ability, Game game) {
|
||||
getManaPool().setStock(); // needed for the "mana already in the pool has to be used manually" option
|
||||
boolean result;
|
||||
if (ability instanceof PassAbility) {
|
||||
pass(game);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue