[KHM] Implemented Giant Ox (#7447)

* [KHM] Implemented Giant Ox

* [KHM] Giant Ox rework after review
This commit is contained in:
Jozsef Kerekes 2021-01-26 22:31:52 +02:00 committed by GitHub
parent a3b012bdf8
commit c5cc99144d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 3 deletions

View file

@ -0,0 +1,34 @@
package mage.abilities.common;
import mage.abilities.MageSingleton;
import mage.abilities.StaticAbility;
import mage.abilities.effects.common.InfoEffect;
import mage.constants.Zone;
import java.io.ObjectStreamException;
/**
*
* @author varaghar
*/
public class CrewWithToughnessAbility extends StaticAbility implements MageSingleton {
private static final CrewWithToughnessAbility instance = new CrewWithToughnessAbility();
private Object readResolve() throws ObjectStreamException {
return instance;
}
public static CrewWithToughnessAbility getInstance() {
return instance;
}
private CrewWithToughnessAbility() {
super(Zone.BATTLEFIELD, new InfoEffect("{this} crews Vehicles using its toughness rather than its power."));
}
@Override
public CrewWithToughnessAbility copy() {
return instance;
}
}

View file

@ -1,7 +1,9 @@
package mage.abilities.keyword;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.CrewWithToughnessAbility;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.CostImpl;
@ -81,7 +83,7 @@ class CrewCost extends CostImpl {
int selectedPower = this.targets.entrySet().stream()
.map(entry -> (game.getPermanent(entry.getKey())))
.filter(Objects::nonNull)
.mapToInt(p -> (p.getPower().getValue()))
.mapToInt(p -> (getCrewPower(p, game)))
.sum();
String extraInfo = "(selected power " + selectedPower + " of " + value + ")";
if (selectedPower >= value) {
@ -99,7 +101,7 @@ class CrewCost extends CostImpl {
if (!game.replaceEvent(event)) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null && permanent.tap(source, game)) {
sumPower += permanent.getPower().getValue();
sumPower += getCrewPower(permanent, game);
}
}
}
@ -120,7 +122,8 @@ class CrewCost extends CostImpl {
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
int sumPower = 0;
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, controllerId, game)) {
int powerToAdd = permanent.getPower().getValue();
int powerToAdd = getCrewPower(permanent, game);
if (powerToAdd > 0) {
sumPower += powerToAdd;
}
@ -135,4 +138,16 @@ class CrewCost extends CostImpl {
public CrewCost copy() {
return new CrewCost(this);
}
private int getCrewPower(Permanent permanent, Game game) {
MageInt crewPowerSource = null;
if (permanent.hasAbility(CrewWithToughnessAbility.getInstance(), game)) {
crewPowerSource = permanent.getToughness();
} else {
crewPowerSource = permanent.getPower();
}
return crewPowerSource.getValue();
}
}