Skip to content

Commit

Permalink
improved trap cards rullings;
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasLimaAZ committed Oct 17, 2024
1 parent 526ed19 commit 4b49512
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/components/card/card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const Card = ({ card, type, position }) => {
handleTribute,
anchorEl,
handleClose,
negateCard,
} = useCard(position);

return (
Expand Down Expand Up @@ -69,10 +70,16 @@ const Card = ({ card, type, position }) => {
anchorEl,
openContextMenu,
handleClose,
negateCard,
}}
/>
{card && (
<Box sx={{ transform: card?.def_mode && "rotate(90deg)" }}>
<Box
sx={{
transform: card?.def_mode && "rotate(90deg)",
filter: card?.isNegated && "grayscale(100%)",
}}
>
<Grow in>
<Box
component="img"
Expand All @@ -93,6 +100,7 @@ const Card = ({ card, type, position }) => {
openAttack={openAttackModal}
handleCloseAttack={() => setOpenAttackModal(false)}
handleDestroyCard={handleDestroy}
handleFlipCard={handleFlip}
target={target}
/>
<ChangeStatsModal
Expand Down
7 changes: 6 additions & 1 deletion src/components/card/components/context-menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
AddCircleOutline,
Search,
ChangeCircle,
Delete,
DoDisturb,
} from "@mui/icons-material";

Expand All @@ -24,6 +25,7 @@ const CardContextMenu = ({
anchorEl,
openContextMenu,
handleClose,
negateCard,
}) => {
return (
<Menu
Expand Down Expand Up @@ -63,8 +65,11 @@ const CardContextMenu = ({
<MenuItem onClick={handleFlip}>
<ChangeCircle /> Flip
</MenuItem>
<MenuItem onClick={negateCard}>
<DoDisturb /> Negate
</MenuItem>
<MenuItem onClick={handleDestroy}>
<DoDisturb /> Destroy
<Delete /> Destroy
</MenuItem>
</Menu>
);
Expand Down
10 changes: 10 additions & 0 deletions src/components/card/use-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const useCard = (position) => {
destroyCard,
selectCard,
field,
updateCardZone,
} = useField();

const { sendToGraveyard } = useGraveyard();
Expand Down Expand Up @@ -86,6 +87,14 @@ export const useCard = (position) => {
setOpenChangeStatsModal(false);
};

const negateCard = () => {
const negatedCard = {
...card,
isNegated: !card.isNegated,
};
updateCardZone(negatedCard, position);
};

return {
handleTribute,
handleChangePosition,
Expand All @@ -109,5 +118,6 @@ export const useCard = (position) => {
openContextMenu,
anchorEl,
handleClose,
negateCard,
};
};
16 changes: 13 additions & 3 deletions src/components/modals/attack-card/use-attack-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
};
Expand Down
9 changes: 9 additions & 0 deletions src/shared/hooks/field.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4b49512

Please sign in to comment.