mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 21:12:04 -08:00
Added 3 cards, little refactoring (Unattach cost)
This commit is contained in:
parent
38abee93a6
commit
b0dc7fe276
10 changed files with 308 additions and 202 deletions
|
|
@ -0,0 +1,64 @@
|
|||
package mage.abilities.costs.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.costs.CostImpl;
|
||||
|
||||
/**
|
||||
* @author Galatolol
|
||||
*/
|
||||
public class UnattachCost extends CostImpl {
|
||||
|
||||
protected UUID sourceEquipmentId;
|
||||
|
||||
public UnattachCost(String name, UUID sourceId) {
|
||||
this.text = "Unattach " + name;
|
||||
this.sourceEquipmentId = sourceId;
|
||||
}
|
||||
|
||||
public UnattachCost(final UnattachCost cost) {
|
||||
super(cost);
|
||||
this.sourceEquipmentId = cost.sourceEquipmentId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) {
|
||||
Permanent permanent = game.getPermanent(sourceId);
|
||||
if (permanent != null) {
|
||||
for (UUID attachmentId : permanent.getAttachments()) {
|
||||
Permanent attachment = game.getPermanent(attachmentId);
|
||||
if (attachment != null && attachment.getId().equals(sourceEquipmentId)) {
|
||||
paid = permanent.removeAttachment(attachmentId, game);
|
||||
if (paid) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return paid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPay(Ability ability, UUID sourceId, UUID controllerId, Game game) {
|
||||
Permanent permanent = game.getPermanent(sourceId);
|
||||
if (permanent != null) {
|
||||
for (UUID attachmentId : permanent.getAttachments()) {
|
||||
Permanent attachment = game.getPermanent(attachmentId);
|
||||
if (attachment != null && attachment.getId().equals(sourceEquipmentId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnattachCost copy() {
|
||||
return new UnattachCost(this);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue