Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions packages/client/src/components/ActionsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const ActionsPanel = (): JSX.Element => {
const { character, equippedWeapons } = useCharacter();
const { isSpawned, monstersOnTile, position } = useMap();
const {
actionOutcomes,
attackOutcomes,
attackingItemId,
currentBattle,
lastestBattleOutcome,
Expand All @@ -34,11 +34,11 @@ export const ActionsPanel = (): JSX.Element => {
const { isRefreshing } = useMovement();

const [turnTimeLeft, setTurnTimeLeft] = useState<number>(32);
const [actionButtonFocus, setActionButtonFocus] = useState<number>(0);
const [attackButtonFocus, setAttackButtonFocus] = useState<number>(0);

const parentDivRef = useRef<HTMLDivElement>(null);
const actionButton1Ref = useRef<HTMLButtonElement>(null);
const actionButton2Ref = useRef<HTMLButtonElement>(null);
const attackButton1Ref = useRef<HTMLButtonElement>(null);
const attackButton2Ref = useRef<HTMLButtonElement>(null);

useEffect(() => {
if (parentDivRef.current) {
Expand All @@ -48,25 +48,25 @@ export const ActionsPanel = (): JSX.Element => {
});
}

if (actionButton1Ref.current) {
actionButton1Ref.current.focus();
setActionButtonFocus(0);
if (attackButton1Ref.current) {
attackButton1Ref.current.focus();
setAttackButtonFocus(0);
}
}, [actionOutcomes]);
}, [attackOutcomes]);

useEffect(() => {
const listener = (event: KeyboardEvent) => {
switch (event.key) {
case 'ArrowLeft':
if (actionButtonFocus === 1 && actionButton2Ref.current) {
actionButton1Ref.current?.focus();
setActionButtonFocus(0);
if (attackButtonFocus === 1 && attackButton2Ref.current) {
attackButton1Ref.current?.focus();
setAttackButtonFocus(0);
}
break;
case 'ArrowRight':
if (actionButtonFocus === 0 && actionButton1Ref.current) {
actionButton2Ref.current?.focus();
setActionButtonFocus(1);
if (attackButtonFocus === 0 && attackButton1Ref.current) {
attackButton2Ref.current?.focus();
setAttackButtonFocus(1);
}
break;
default:
Expand All @@ -77,7 +77,7 @@ export const ActionsPanel = (): JSX.Element => {
window.addEventListener('keydown', listener);
// eslint-disable-next-line consistent-return
return () => window.removeEventListener('keydown', listener);
}, [actionButtonFocus]);
}, [attackButtonFocus]);

const battleOver = useMemo(
() => currentBattle?.encounterId === lastestBattleOutcome?.encounterId,
Expand Down Expand Up @@ -238,7 +238,7 @@ export const ActionsPanel = (): JSX.Element => {
).toString(),
)
}
ref={index === 0 ? actionButton1Ref : actionButton2Ref}
ref={index === 0 ? attackButton1Ref : attackButton2Ref}
variant="outline"
w="100%"
>
Expand Down Expand Up @@ -320,19 +320,19 @@ export const ActionsPanel = (): JSX.Element => {
</Typist>
)}

{opponent &&
actionOutcomes.map((action, i) => {
if (action.miss) {
{opponent?.name &&
attackOutcomes.map((attack, i) => {
if (attack.miss[0]) {
return (
<Typist
avgTypingDelay={10}
cursor={{ show: false }}
key={`battle-action-${i}`}
key={`battle-attack-${i}`}
stdTypingDelay={10}
>
{action.attackerId === character?.id ? (
{attack.attackerId === character?.id ? (
<Text
key={`battle-action-${i}`}
key={`battle-attack-${i}`}
size={{ base: 'xs', sm: 'sm', lg: 'md' }}
>
You missed{' '}
Expand All @@ -343,7 +343,7 @@ export const ActionsPanel = (): JSX.Element => {
</Text>
) : (
<Text
key={`battle-action-${i}`}
key={`battle-attack-${i}`}
size={{ base: 'xs', sm: 'sm', lg: 'md' }}
>
<Text as="span" color="green">
Expand All @@ -356,24 +356,24 @@ export const ActionsPanel = (): JSX.Element => {
);
}

const critText = action.crit ? 'Critical hit! ' : '';
const critText = attack.crit[0] ? 'Critical hit! ' : '';

return (
<Typist
avgTypingDelay={10}
cursor={{ show: false }}
key={`battle-action-${i}`}
key={`battle-attack-${i}`}
stdTypingDelay={10}
>
{action.attackerId === character?.id ? (
{attack.attackerId === character?.id ? (
<Text size={{ base: 'xs', sm: 'sm', lg: 'md' }}>
{critText}You attacked{' '}
<Text as="span" color="green">
{opponent?.name}
</Text>{' '}
for{' '}
<Text as="span" color="red">
{action.attackerDamageDelt}
{attack.attackerDamageDelt}
</Text>{' '}
damage.
</Text>
Expand All @@ -385,7 +385,7 @@ export const ActionsPanel = (): JSX.Element => {
</Text>{' '}
attacked you for{' '}
<Text as="span" color="red">
{action.attackerDamageDelt}
{attack.attackerDamageDelt}
</Text>{' '}
damage.
</Text>
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/components/AuctionRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { type ArmorTemplate, type WeaponTemplate } from '../utils/types';
export const AuctionRow = ({
name,
agiModifier,
hitPointModifier,
hpModifier,
intModifier,
minLevel,
strModifier,
Expand Down Expand Up @@ -64,7 +64,7 @@ export const AuctionRow = ({
<Text size={{ base: '2xs', lg: 'sm' }}>{removeEmoji(name)}</Text>
</HStack>
<Text size={{ base: '3xs', sm: '2xs', lg: 'sm' }}>
HP {hitPointModifier} • STR {strModifier} • AGI {agiModifier} • INT{' '}
HP {hpModifier} • STR {strModifier} • AGI {agiModifier} • INT{' '}
{intModifier}
</Text>
</VStack>
Expand Down
38 changes: 19 additions & 19 deletions packages/client/src/components/TileDetailsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const TileDetailsPanel = (): JSX.Element => {
const { inSafetyZone, isSpawned, monstersOnTile, otherCharactersOnTile } =
useMap();
const {
actionOutcomes,
attackOutcomes,
currentBattle,
opponent,
userCharacterForBattleRendering,
Expand All @@ -62,27 +62,27 @@ export const TileDetailsPanel = (): JSX.Element => {
const [isMonsterHit, setIsMonsterHit] = useState(false);

useEffect(() => {
if (!(actionOutcomes[0] && currentBattle && opponent)) return;
if (!(attackOutcomes[0] && currentBattle && opponent)) return;

const actionIndex = actionOutcomes.findLastIndex(
action => action.attackerId === opponent.id,
const attackIndex = attackOutcomes.findLastIndex(
attack => attack.attackerId === opponent.id,
);

if (actionIndex === -1) return;
if (attackIndex === -1) return;

const currentBattleOpponentTurn = localStorage.getItem(
CURRENT_BATTLE_OPPONENT_TURN_KEY,
);

if (currentBattleOpponentTurn) {
if (currentBattleOpponentTurn === actionIndex.toString()) {
if (currentBattleOpponentTurn === attackIndex.toString()) {
return;
}
}

if (
actionOutcomes[actionIndex]?.attackerDamageDelt !== '0' &&
actionIndex - Number(currentBattle.currentTurn) <= 2
attackOutcomes[attackIndex]?.attackerDamageDelt !== '0' &&
attackIndex - Number(currentBattle.currentTurn) <= 2
) {
setIsUserHit(true);
setTimeout(() => {
Expand All @@ -91,33 +91,33 @@ export const TileDetailsPanel = (): JSX.Element => {

localStorage.setItem(
CURRENT_BATTLE_OPPONENT_TURN_KEY,
actionIndex.toString(),
attackIndex.toString(),
);
}
}, [actionOutcomes, currentBattle, opponent]);
}, [attackOutcomes, currentBattle, opponent]);

useEffect(() => {
if (!(actionOutcomes[0] && character && currentBattle)) return;
if (!(attackOutcomes[0] && character && currentBattle)) return;

const actionIndex = actionOutcomes.findLastIndex(
action => action.attackerId === character.id,
const attackIndex = attackOutcomes.findLastIndex(
attack => attack.attackerId === character.id,
);

if (actionIndex === -1) return;
if (attackIndex === -1) return;

const currentBattleDefenderTurn = localStorage.getItem(
CURRENT_BATTLE_USER_TURN_KEY,
);

if (currentBattleDefenderTurn) {
if (currentBattleDefenderTurn === actionIndex.toString()) {
if (currentBattleDefenderTurn === attackIndex.toString()) {
return;
}
}

if (
actionOutcomes[actionIndex]?.attackerDamageDelt !== '0' &&
actionIndex - Number(currentBattle.currentTurn) <= 2
attackOutcomes[attackIndex]?.attackerDamageDelt !== '0' &&
attackIndex - Number(currentBattle.currentTurn) <= 2
) {
setIsMonsterHit(true);
setTimeout(() => {
Expand All @@ -126,10 +126,10 @@ export const TileDetailsPanel = (): JSX.Element => {

localStorage.setItem(
CURRENT_BATTLE_USER_TURN_KEY,
actionIndex.toString(),
attackIndex.toString(),
);
}
}, [actionOutcomes, character, currentBattle]);
}, [attackOutcomes, character, currentBattle]);

const onInitiateCombat = useCallback(
async (opponent: Character | Monster, encounterType: EncounterType) => {
Expand Down
Loading