MCPcopy Create free account
hub / github.com/Card-Forge/forge / parseCostPart

Method parseCostPart

forge-game/src/main/java/forge/game/cost/Cost.java:279–609  ·  view source on GitHub ↗
(String parse, boolean tapCost, boolean untapCost)

Source from the content-addressed store, hash-verified

277 }
278
279 private static CostPart parseCostPart(String parse, boolean tapCost, boolean untapCost) {
280 if (parse.startsWith("Mana<")) {
281 final String[] splitStr = TextUtil.split(abCostParse(parse, 1)[0], '\\');
282 final String restriction = splitStr.length > 1 ? splitStr[1] : null;
283 return new CostPartMana(new ManaCost(splitStr[0]), restriction);
284 }
285
286 if (parse.startsWith("tapXType<")) {
287 final String[] splitStr = abCostParse(parse, 3);
288 final String description = splitStr.length > 2 ? splitStr[2] : null;
289 return new CostTapType(splitStr[0], splitStr[1], description, tapCost);
290 }
291
292 if (parse.startsWith("untapYType<")) {
293 final String[] splitStr = abCostParse(parse, 3);
294 final String description = splitStr.length > 2 ? splitStr[2] : null;
295 return new CostUntapType(splitStr[0], splitStr[1], description, untapCost);
296 }
297
298 if (parse.startsWith("SubCounter<")) {
299 // SubCounter<NumCounters/CounterType/{Type/Description/Zone}>
300 final String[] splitStr = abCostParse(parse, 5);
301 final String type = splitStr.length > 2 ? splitStr[2] : "CARDNAME";
302 final String description = splitStr.length > 3 ? splitStr[3] : null;
303 final List<ZoneType> zone = splitStr.length > 4 ? ZoneType.listValueOf(splitStr[4]) : Lists.newArrayList(ZoneType.Battlefield);
304 boolean oneOrMore = false;
305 if (splitStr[0].equals("X1+")) {
306 oneOrMore = true;
307 splitStr[0] = "X";
308 }
309
310 return new CostRemoveCounter(splitStr[0], CounterType.getType(splitStr[1]), type, description, zone, oneOrMore);
311 }
312
313 if (parse.startsWith("AddCounter<")) {
314 // AddCounter<NumCounters/CounterType>
315 final String[] splitStr = abCostParse(parse, 4);
316 final String target = splitStr.length > 2 ? splitStr[2] : "CARDNAME";
317 final String description = splitStr.length > 3 ? splitStr[3] : null;
318 return new CostPutCounter(splitStr[0], CounterType.getType(splitStr[1]), target, description);
319 }
320
321 // While no card has "PayLife<2> PayLife<3> there might be a card that
322 // Changes Cost by adding a Life Payment
323 if (parse.startsWith("PayLife<")) {
324 // PayLife<LifeCost>
325 final String[] splitStr = abCostParse(parse, 2);
326 final String description = splitStr.length > 1 ? splitStr[1] : null;
327 return new CostPayLife(splitStr[0], description);
328 }
329
330 if (parse.startsWith("PayEnergy<")) {
331 // Payenergy<EnergyCost>
332 final String[] splitStr = abCostParse(parse, 1);
333 return new CostPayEnergy(splitStr[0]);
334 }
335 if (parse.startsWith("PayShards<")) { //Adventure specific energy-esque tokens
336 // Payshards<ShardCost>

Callers 1

CostMethod · 0.95

Calls 6

splitMethod · 0.95
abCostParseMethod · 0.95
listValueOfMethod · 0.95
getTypeMethod · 0.95
startsWithMethod · 0.80
equalsMethod · 0.45

Tested by

no test coverage detected