-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathAddDescriptionSpell.java
More file actions
47 lines (43 loc) · 2.03 KB
/
AddDescriptionSpell.java
File metadata and controls
47 lines (43 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package net.demilich.metastone.game.spells;
import net.demilich.metastone.game.GameContext;
import net.demilich.metastone.game.Player;
import net.demilich.metastone.game.cards.Attribute;
import net.demilich.metastone.game.cards.dynamicdescription.DynamicDescriptionDesc;
import net.demilich.metastone.game.entities.Entity;
import net.demilich.metastone.game.spells.desc.SpellArg;
import net.demilich.metastone.game.spells.desc.SpellDesc;
import java.util.Arrays;
import java.util.stream.Stream;
/**
* Adds the {@link net.demilich.metastone.game.spells.desc.SpellArg#SECONDARY_TARGET} card's text to the {@code
* target}'s description, concatenating with a space.
* <p>
* Since the target may contain dynamic description entries, we have to copy those too.
*/
public class AddDescriptionSpell extends SetDescriptionSpell {
@Override
protected void onCast(GameContext context, Player player, SpellDesc desc, Entity source, Entity target) {
String description = "";
if (target == null) {
return;
}
if (desc.containsKey(SpellArg.SECONDARY_TARGET)) {
Entity secondaryTarget = context.resolveSingleTarget(player, source, desc.getSecondaryTarget());
description = secondaryTarget.getDescription();
DynamicDescriptionDesc[] dynamicDescription = secondaryTarget.getSourceCard().getDynamicDescription();
if (dynamicDescription != null && dynamicDescription.length > 0) {
target.setAttribute(Attribute.DYNAMIC_DESCRIPTION,
Stream.concat(
Arrays.stream((DynamicDescriptionDesc[]) target.getAttributes().getOrDefault(Attribute.DYNAMIC_DESCRIPTION,
new DynamicDescriptionDesc[0])), Arrays.stream(dynamicDescription)).toArray(DynamicDescriptionDesc[]::new));
}
} else if (desc.containsKey(SpellArg.DESCRIPTION)) {
description = desc.getString(SpellArg.DESCRIPTION);
}
if (target.getDescription() != null && target.getDescription().equals("")) {
target.setAttribute(Attribute.DESCRIPTION, description);
} else {
target.setAttribute(Attribute.DESCRIPTION, target.getDescription() + " " + description);
}
}
}