Skip to content

Commit

Permalink
feat: [#157] Implemented Police Shield effect
Browse files Browse the repository at this point in the history
  • Loading branch information
annabranco committed Feb 3, 2021
1 parent 2756bd3 commit 8685d21
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 49 deletions.
16 changes: 8 additions & 8 deletions src/components/Items/ItemsArea/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ const ItemsArea = ({
bonusDices,
callback,
canAttack,
canBeAbsorbed,
canBeDeflected,
canCombine,
canSearch,
causeDamage,
charCanAbsorb,
charCanDeflect,
charName,
charVoice,
combineItemSelected,
Expand Down Expand Up @@ -256,9 +256,9 @@ const ItemsArea = ({
activateKillButtons={activateKillButtons}
callback={callback}
canAttack={canAttack}
canBeAbsorbed={canBeAbsorbed}
canBeDeflected={canBeDeflected}
canCombine={canCombine && canCombine.includes(item)}
charCanAbsorb={charCanAbsorb}
charCanDeflect={charCanDeflect}
combineItemSelected={combineItemSelected}
combinePair={combinePair}
damageMode={damageMode}
Expand Down Expand Up @@ -355,11 +355,11 @@ ItemsArea.propTypes = {
bonusDices: BonusDicesType,
callback: func,
canAttack: bool,
canBeAbsorbed: bool,
canBeDeflected: bool,
canCombine: bool,
canSearch: bool,
causeDamage: func,
charCanAbsorb: bool,
charCanDeflect: bool,
charName: string,
charVoice: string,
combineItemSelected: bool,
Expand Down Expand Up @@ -398,11 +398,11 @@ ItemsArea.defaultProps = {
bonusDices: null,
callback: () => null,
canAttack: false,
canBeAbsorbed: false,
canBeDeflected: false,
canCombine: false,
canSearch: false,
causeDamage: null,
charCanAbsorb: false,
charCanDeflect: false,
charName: null,
charVoice: null,
combineItemSelected: false,
Expand Down
86 changes: 58 additions & 28 deletions src/components/Sections/PlayersSection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ import NewGame from '../../NewGame';

import CharacterFace from '../../CharacterFace';
import {
ABSORBED,
ABSORBED_ONE,
DEFLECTED,
DEFLECTED_ONE,
BLOCKED,
BLOCKED_ONE,
ADD_CHARACTER,
BONUS_ACTION,
BREAK_DOOR,
Expand Down Expand Up @@ -1089,8 +1091,6 @@ const PlayersSection = ({
const setNewChar = updatedCharacters => {
addNewChar(false);
updateCharacters(updatedCharacters);

console.log('$$$ LS new char', updatedCharacters);
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(updatedCharacters));
};

Expand All @@ -1100,12 +1100,19 @@ const PlayersSection = ({
const characterCanResist =
woundedCharacter.abilities.includes(ABILITIES_S1.TOUGH.name) &&
!woundedCharacter.abilitiesUsed.includes(RESISTED);
const characterCanAbsorb =
woundedCharacter.abilities.includes(ABILITIES_S1.ALL_YOUVE_GOT.name) &&
!checkIfCharHasNoItems([
...woundedCharacter.inHand,
...woundedCharacter.inReserve
]);
const characterCanBlock =
woundedCharacter.inHand[selectedSlot - 1] ===
ALL_ITEMS.PoliceRiotShield.name &&
!woundedCharacter.abilitiesUsed.includes(BLOCKED);
const characterCanDeflect =
(woundedCharacter.abilities.includes(ABILITIES_S1.ALL_YOUVE_GOT.name) &&
!checkIfCharHasNoItems([
...woundedCharacter.inHand,
...woundedCharacter.inReserve
])) ||
(woundedCharacter.inHand[selectedSlot - 1] ===
ALL_ITEMS.PoliceRiotShield.name &&
woundedCharacter.abilitiesUsed.includes(BLOCKED));
const characterIsProtected =
[...woundedCharacter.inHand, ...woundedCharacter.inReserve][
selectedSlot - 1
Expand Down Expand Up @@ -1135,13 +1142,22 @@ const PlayersSection = ({
setTimeout(() => {
toggleResistedAttack(false);
}, 2000);
} else if (characterCanAbsorb || characterIsProtected) {
} else if (characterCanDeflect || characterIsProtected) {
if (selectedSlot <= 2) {
woundedCharacter.inHand[selectedSlot - 1] = '';
} else {
woundedCharacter.inReserve[selectedSlot - 3] = '';
}
toggleResistedAttack(ABSORBED_ONE);
toggleResistedAttack(DEFLECTED_ONE);
setTimeout(() => {
toggleResistedAttack(false);
}, 2000);
changeCharacter(woundedCharacter);
toggleDamageMode(attacker);
return null;
} else if (characterCanBlock) {
toggleResistedAttack(BLOCKED_ONE);
woundedCharacter.abilitiesUsed.push(BLOCKED);
setTimeout(() => {
toggleResistedAttack(false);
}, 2000);
Expand All @@ -1155,7 +1171,10 @@ const PlayersSection = ({

woundedCharacter.wounded = KILLED;
damage = KILL;
if (firstPlayer.includes(woundedCharacter.name)) {
if (
remainingCharacters.length > 1 &&
firstPlayer.includes(woundedCharacter.name)
) {
changeFirstPlayer(`next-${characters[charIndex + 1].name}`);
}

Expand All @@ -1169,8 +1188,14 @@ const PlayersSection = ({
setTimeout(() => {
toggleResistedAttack(false);
}, 2000);
} else if (characterCanAbsorb || characterIsProtected) {
toggleResistedAttack(ABSORBED);
} else if (characterCanBlock) {
toggleResistedAttack(BLOCKED);
woundedCharacter.abilitiesUsed.push(BLOCKED);
setTimeout(() => {
toggleResistedAttack(false);
}, 2000);
} else if (characterCanDeflect || characterIsProtected) {
toggleResistedAttack(DEFLECTED);
setTimeout(() => {
toggleResistedAttack(false);
}, 2000);
Expand Down Expand Up @@ -1746,13 +1771,14 @@ const PlayersSection = ({
bonusDices={character.bonusDices}
callback={spendAction}
canAttack={canAttack}
canBeAbsorbed={
character.abilities.includes(
canBeDeflected={
(character.abilities.includes(
ABILITIES_S1.ALL_YOUVE_GOT.name
) &&
item !== '' &&
item !== NONE &&
item !== WOUNDED
item !== '' &&
item !== NONE &&
item !== WOUNDED) ||
item === ALL_ITEMS.PoliceRiotShield.name
}
canCombine={!!generalActions && canCombine}
canSearch={canSearch}
Expand All @@ -1763,14 +1789,18 @@ const PlayersSection = ({
combinePair={
combiningItem && combiningItem.pair === itemName
}
charCanAbsorb={
character.abilities.includes(
charCanDeflect={
(character.abilities.includes(
ABILITIES_S1.ALL_YOUVE_GOT.name
) &&
!checkIfCharHasNoItems([
...character.inHand,
...character.inReserve
])
!checkIfCharHasNoItems([
...character.inHand,
...character.inReserve
])) ||
character.inHand.some(
inHandItem =>
inHandItem === ALL_ITEMS.PoliceRiotShield.name
)
}
charVoice={character.voice}
damageMode={damageMode}
Expand Down Expand Up @@ -1816,7 +1846,7 @@ const PlayersSection = ({
...character.inReserve
])}
callback={spendAction}
canBeAbsorbed={
canBeDeflected={
character.abilities.includes(
ABILITIES_S1.ALL_YOUVE_GOT.name
) &&
Expand All @@ -1827,7 +1857,7 @@ const PlayersSection = ({
canCombine={!!generalActions && canCombine}
canSearch={canSearch}
causeDamage={takeDamage}
charCanAbsorb={
charCanDeflect={
character.abilities.includes(
ABILITIES_S1.ALL_YOUVE_GOT.name
) &&
Expand Down
16 changes: 8 additions & 8 deletions src/components/SoundBlock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ const SoundBlock = ({
activateKillButtons,
callback,
canAttack,
canBeAbsorbed,
canBeDeflected,
canCombine,
charCanAbsorb,
charCanDeflect,
combineItemSelected,
combinePair,
damageMode,
Expand Down Expand Up @@ -169,8 +169,8 @@ const SoundBlock = ({

return (
<Block
canBeAbsorbed={canBeAbsorbed}
charCanAbsorb={charCanAbsorb}
canBeDeflected={canBeDeflected}
charCanDeflect={charCanDeflect}
damageMode={damageMode}
type={type}
wounded={wounded}
Expand Down Expand Up @@ -225,9 +225,9 @@ SoundBlock.propTypes = {
activateKillButtons: func,
callback: func,
canAttack: bool,
canBeAbsorbed: bool,
canBeDeflected: bool,
canCombine: bool,
charCanAbsorb: bool,
charCanDeflect: bool,
combineItemSelected: bool,
combinePair: bool,
damageMode: bool,
Expand Down Expand Up @@ -260,9 +260,9 @@ SoundBlock.defaultProps = {
activateKillButtons: null,
callback: null,
canAttack: false,
canBeAbsorbed: false,
canBeDeflected: false,
canCombine: false,
charCanAbsorb: false,
charCanDeflect: false,
combineItemSelected: false,
combinePair: false,
damageMode: false,
Expand Down
12 changes: 9 additions & 3 deletions src/components/SoundBlock/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ export const Block = styled.div`
border-radius: 5px;
box-shadow: 0 0 5px 0 black;
height: 100%;
display: ${({ canBeAbsorbed, charCanAbsorb, damageMode, type, wounded }) => {
if (damageMode && charCanAbsorb && !canBeAbsorbed) {
display: ${({
canBeDeflected,
charCanDeflect,
damageMode,
type,
wounded
}) => {
if (damageMode && charCanDeflect && type === WOUND) {
return 'none';
}
if (damageMode && canBeAbsorbed) {
if (damageMode && canBeDeflected) {
return 'flex';
}
if (damageMode && wounded && type !== WOUND) {
Expand Down
6 changes: 4 additions & 2 deletions src/constants/mechanics.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export const ABSORBED = 'Absorbed attack';
export const ABSORBED_ONE = 'Absorbed the first attack';
export const BLOCKED = 'Blocked attack';
export const BLOCKED_ONE = 'Blocked the first attack';
export const CHOOSE_PLAYER = 'Who is gonna play?';
export const CHOOSE_PLAYER_DYNAMIC = 'Who is gonna play the new character?';
export const DEFLECTED = 'Deflected attack';
export const DEFLECTED_ONE = 'Deflected the first attack';
export const FINISH_SETUP = 'Finish setup';
export const HAS_BEEN_KILLED = 'has \nbeen killed';
export const KILLED_EM_ALL = 'All characters are dead';
Expand Down

0 comments on commit 8685d21

Please sign in to comment.