From 4b4951230c9f5c33fa7b39ca280985fb00d967d9 Mon Sep 17 00:00:00 2001 From: Lucas de Lima Monteiro Date: Thu, 17 Oct 2024 18:58:13 -0300 Subject: [PATCH] improved trap cards rullings; --- src/components/card/card.jsx | 10 +++++++++- src/components/card/components/context-menu.jsx | 7 ++++++- src/components/card/use-card.js | 10 ++++++++++ .../modals/attack-card/use-attack-card.js | 16 +++++++++++++--- src/shared/hooks/field.jsx | 9 +++++++++ 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/components/card/card.jsx b/src/components/card/card.jsx index 11b3997..2c68e0b 100644 --- a/src/components/card/card.jsx +++ b/src/components/card/card.jsx @@ -33,6 +33,7 @@ const Card = ({ card, type, position }) => { handleTribute, anchorEl, handleClose, + negateCard, } = useCard(position); return ( @@ -69,10 +70,16 @@ const Card = ({ card, type, position }) => { anchorEl, openContextMenu, handleClose, + negateCard, }} /> {card && ( - + { openAttack={openAttackModal} handleCloseAttack={() => setOpenAttackModal(false)} handleDestroyCard={handleDestroy} + handleFlipCard={handleFlip} target={target} /> { return ( Flip + + Negate + - Destroy + Destroy ); diff --git a/src/components/card/use-card.js b/src/components/card/use-card.js index 0400add..8751c60 100644 --- a/src/components/card/use-card.js +++ b/src/components/card/use-card.js @@ -12,6 +12,7 @@ export const useCard = (position) => { destroyCard, selectCard, field, + updateCardZone, } = useField(); const { sendToGraveyard } = useGraveyard(); @@ -86,6 +87,14 @@ export const useCard = (position) => { setOpenChangeStatsModal(false); }; + const negateCard = () => { + const negatedCard = { + ...card, + isNegated: !card.isNegated, + }; + updateCardZone(negatedCard, position); + }; + return { handleTribute, handleChangePosition, @@ -109,5 +118,6 @@ export const useCard = (position) => { openContextMenu, anchorEl, handleClose, + negateCard, }; }; diff --git a/src/components/modals/attack-card/use-attack-card.js b/src/components/modals/attack-card/use-attack-card.js index 477cb9b..d16cbdd 100644 --- a/src/components/modals/attack-card/use-attack-card.js +++ b/src/components/modals/attack-card/use-attack-card.js @@ -50,13 +50,13 @@ export const useAttackCard = (props) => { if (props.card?.def_mode) { if (defDif === 0) return; - defDif > 0 ? props.handleDestroyCard() : setPlayerLp(playerLp + defDif); + defDif > 0 ? handleDestroyCard() : setPlayerLp(playerLp + defDif); return; } if (atkDif >= 0) { - props.handleDestroyCard(); + handleDestroyCard(); if (atkDif > 0) setOpponentLp(opponentLp - atkDif); } @@ -65,10 +65,20 @@ export const useAttackCard = (props) => { } }; + const handleDestroyCard = () => { + if (props.card?.face_down) { + console.log("aueba? estoy aqui..."); + props.handleFlipCard(); + return; + } + + props.handleDestroyCard(); + }; + const searchForTrapCards = () => { let trapCards = field?.filter((card, index) => { if (card) card.fieldPosition = index; - return card?.type === "Trap Card"; + return card?.type === "Trap Card" && !card?.isNegated; }); return trapCards; }; diff --git a/src/shared/hooks/field.jsx b/src/shared/hooks/field.jsx index e80a32c..43d9ef7 100644 --- a/src/shared/hooks/field.jsx +++ b/src/shared/hooks/field.jsx @@ -191,8 +191,17 @@ const useField = () => { generateMagicTrap(position); }; + const updateCardZone = (card, position) => { + setField((prev) => { + const newField = [...prev]; + newField[position] = card; + return newField; + }); + }; + return { field, + updateCardZone, rotateBoard, setRotateBoard, generateCard,