Skip to content

Commit ed81d58

Browse files
author
MadeByIToncek
committed
Cast a card with two other cards
Progress on #17
1 parent 90b79b1 commit ed81d58

1 file changed

Lines changed: 69 additions & 5 deletions

File tree

server/src/main/java/space/itoncek/trailcompass/modules/DeckManager.java

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,10 @@ public void CastWithOtherCard(UUID cardId, UUID otherCardId) throws BackendExcep
249249
return;
250250
}
251251

252-
boolean shadowCard = false;
253-
CardType cardType;
252+
CardType cardType;
254253
if (card instanceof ShadowCard sc) {
255254
cardType = sc.getMirroredCard().getType();
256-
shadowCard = true;
257-
} else if (card instanceof DeckCard dc) {
255+
} else if (card instanceof DeckCard dc) {
258256
cardType = dc.getType();
259257
} else {
260258
cardType = null;
@@ -264,7 +262,7 @@ public void CastWithOtherCard(UUID cardId, UUID otherCardId) throws BackendExcep
264262
exception.set("Unknown card type!");
265263
return;
266264
} else if (cardType.requirement != CardCastRequirement.OtherCard) {
267-
exception.set("Card does not have a void cast requirement!");
265+
exception.set("Card does not have a \"OtherCard\" cast requirement!");
268266
return;
269267
}
270268

@@ -295,6 +293,72 @@ public void CastWithOtherCard(UUID cardId, UUID otherCardId) throws BackendExcep
295293
throw new BackendException(exception.get());
296294
}
297295
}
296+
public void CastWithTwoOtherCards(UUID cardId, UUID other1, UUID other2) throws BackendException {
297+
AtomicReference<String> exception = new AtomicReference<>(null);
298+
server.ef.runInTransaction(em -> {
299+
try {
300+
Card card = em.find(Card.class, cardId);
301+
Card oCard1 = em.find(Card.class, other1);
302+
Card oCard2 = em.find(Card.class, other1);
303+
if (card == null || oCard1 == null || oCard2 == null) {
304+
exception.set("Unable to find that card in the database!");
305+
return;
306+
}
307+
308+
if(oCard1.getId() == oCard2.getId()) {
309+
exception.set("You need to select two different cards");
310+
return;
311+
}
312+
313+
if (card.getOwner() == null || oCard1.getOwner() == null || oCard2.getOwner() == null) {
314+
exception.set("Nobody owns that card!");
315+
return;
316+
}
317+
318+
CardType cardType;
319+
if (card instanceof ShadowCard sc) {
320+
cardType = sc.getMirroredCard().getType();
321+
} else if (card instanceof DeckCard dc) {
322+
cardType = dc.getType();
323+
} else {
324+
cardType = null;
325+
}
326+
327+
if (cardType == null) {
328+
exception.set("Unknown card type!");
329+
return;
330+
} else if (cardType.requirement != CardCastRequirement.TwoOtherCards) {
331+
exception.set("Card does not have a \"TwoOtherCards\" cast requirement!");
332+
return;
333+
}
334+
335+
switch (cardType) {
336+
case Discard2 -> {
337+
removeCard(em, card);
338+
removeCard(em, oCard1);
339+
removeCard(em, oCard2);
340+
341+
drawCardForPlayer(card.getOwner().getId());
342+
drawCardForPlayer(card.getOwner().getId());
343+
drawCardForPlayer(card.getOwner().getId());
344+
}
345+
346+
case Curse_HiddenHangman, Curse_JammmedDoor, Curse_Urbex, Curse_EggPartner -> {
347+
castCurse(em, cardType);
348+
removeCard(em, card);
349+
removeCard(em, oCard1);
350+
removeCard(em, oCard2);
351+
}
352+
}
353+
} catch (IOException e) {
354+
exception.set(e.toString());
355+
}
356+
});
357+
358+
if (exception.get() != null) {
359+
throw new BackendException(exception.get());
360+
}
361+
}
298362

299363
private static void removeCard(EntityManager em, Card card) {
300364
if (card instanceof ShadowCard sc) {

0 commit comments

Comments
 (0)