Skip to content

Commit

Permalink
client side, send actions to server side. need to finish move
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Aug 25, 2023
1 parent 897466d commit c4e032b
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 8 deletions.
5 changes: 3 additions & 2 deletions client/src/app/components/avatar/avatar.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@
transform: scale(1);
}
}

&.active {
--glow-color-start: #033;
--glow-color-end: #0ff;

animation: glow 1s ease-in-out infinite alternate;

filter: drop-shadow(1px 1px 0 var(--glow-color-start))
drop-shadow(-1px 1px 0 var(--glow-color-start))
drop-shadow(1px -1px 0 var(--glow-color-start))
drop-shadow(-1px -1px 0 var(--glow-color-start));

animation: glow 1s ease-in-out infinite alternate;

@keyframes glow {
0% {
filter: drop-shadow(1px 1px 0 var(--glow-color-start))
Expand Down
30 changes: 25 additions & 5 deletions client/src/app/pages/combat/combat.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
</ion-col>

<ion-col class="action-container">
<ion-button class="action-button" [disabled]="!isMyCharacterActive">
<ion-button
class="action-button"
[disabled]="!isMyCharacterActive"
(click)="startMoving()"
>
Move
</ion-button>
</ion-col>
Expand Down Expand Up @@ -51,9 +55,21 @@
<ion-card>
<ion-card-content>
<div class="fight">
<ion-row *ngFor="let row of fight.tiles" class="tile-row">
<ion-col *ngFor="let col of row; let i = index" class="tile-col">
<div class="tile" [class.enemy]="i > 3" [class.friendly]="i <= 3">
<ion-row
*ngFor="let row of fight.tiles; let y = index"
class="tile-row"
>
<ion-col *ngFor="let col of row; let x = index" class="tile-col">
<div
class="tile"
[class.enemy]="x > 3"
[class.friendly]="x <= 3"
[class.glowing]="isTileActive(x, y)"
[ngClass]="['x-' + x, 'y-' + y]"
(mouseenter)="selectTilesOnHover(x, y)"
(contextmenu)="resetAbilityAndSelection(); $event.preventDefault()"
(click)="clickTile(col, x, y)"
>
<div
class="character-container"
[class.active]="isMyCharacterActive"
Expand All @@ -76,7 +92,7 @@
size="small"
[padding]="0"
[noScale]="true"
[active]="isMyCharacterActive"
[active]="isMyCharacterActive && !selectedAbility"
></app-avatar>

<app-monster-icon
Expand All @@ -103,6 +119,10 @@
</div>
</ion-card-content>
</ion-card>

<ion-card *ngIf="selectedAbility">
<ion-card-content>{{ selectedAbility | json }}</ion-card-content>
</ion-card>
</ion-content>

<ion-modal
Expand Down
19 changes: 19 additions & 0 deletions client/src/app/pages/combat/combat.page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@
&.friendly {
background-color: #040;
}

&.glowing {
--glow-color-start: #099;
--glow-color-end: #0cc;

cursor: pointer;

animation: glow 1s ease-in-out infinite alternate;
}

@keyframes glow {
0% {
background-color: var(--glow-color-start);
}

100% {
background-color: var(--glow-color-end);
}
}
}
}

Expand Down
171 changes: 171 additions & 0 deletions client/src/app/pages/combat/combat.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import {
Element,
ICombatAbility,
ICombatAbilityPattern,
ICombatTargetParams,
IFight,
IFightCharacter,
IFightTile,
IMonster,
IPlayer,
IUser,
Expand Down Expand Up @@ -52,6 +55,7 @@ export class CombatPage implements OnInit {
public myCharacterJob = '';
public myCharacterLevel = 0;
public selectedAbility: ICombatAbility | undefined;
public staticSelectedTiles: Record<string, boolean> = {};

public get myCharacter(): IFightCharacter {
return this.fightCharacters[this.myCharacterId];
Expand All @@ -61,6 +65,12 @@ export class CombatPage implements OnInit {
return this.fight.currentTurn === this.myCharacterId;
}

public get defenders(): IFightCharacter[] {
return this.fight.defenders.map((character) => {
return this.fightCharacters[character.characterId];
});
}

constructor(
private store: Store,
private contentService: ContentService,
Expand Down Expand Up @@ -126,8 +136,169 @@ export class CombatPage implements OnInit {

selectAbility(ability: ICombatAbility) {
this.selectedAbility = ability;
this.staticSelectedTiles = {};

this.abilitiesModal.dismiss();

this.chooseSelectedTiles(ability);
}

findTileWithCharacter(characterId: string): [number, number] | undefined {
let foundTile: [number, number] | undefined;

this.fight.tiles.forEach((row, y) => {
row.forEach((tile, x) => {
if (tile.containedCharacters.includes(characterId)) {
foundTile = [x, y];
}
});
});

return foundTile;
}

choosePatternAroundCenter(
x: number,
y: number,
pattern: ICombatAbilityPattern,
): Record<string, boolean> {
const staticSelectedTiles: Record<string, boolean> = {};

switch (pattern) {
case 'Single': {
staticSelectedTiles[`${x}-${y}`] = true;
return staticSelectedTiles;
}

case 'Cross': {
staticSelectedTiles[`${x}-${y}`] = true;
staticSelectedTiles[`${x - 1}-${y}`] = true;
staticSelectedTiles[`${x + 1}-${y}`] = true;
staticSelectedTiles[`${x}-${y - 1}`] = true;
staticSelectedTiles[`${x}-${y + 1}`] = true;
return staticSelectedTiles;
}

case 'CrossNoCenter': {
staticSelectedTiles[`${x - 1}-${y}`] = true;
staticSelectedTiles[`${x + 1}-${y}`] = true;
staticSelectedTiles[`${x}-${y - 1}`] = true;
staticSelectedTiles[`${x}-${y + 1}`] = true;
return staticSelectedTiles;
}

case 'ThreeVertical': {
staticSelectedTiles[`${x}-${y}`] = true;
staticSelectedTiles[`${x}-${y - 1}`] = true;
staticSelectedTiles[`${x}-${y + 1}`] = true;
return staticSelectedTiles;
}

case 'TwoHorizontal': {
staticSelectedTiles[`${x}-${y}`] = true;
staticSelectedTiles[`${x + 1}-${y}`] = true;
return staticSelectedTiles;
}

default:
return pattern satisfies never;
}
}

drawPatternAroundCenter(
x: number,
y: number,
pattern: ICombatAbilityPattern,
) {
const patternTiles = this.choosePatternAroundCenter(x, y, pattern);
this.staticSelectedTiles = { ...this.staticSelectedTiles, ...patternTiles };
}

chooseSelectedTiles(ability: ICombatAbility) {
switch (ability.targetting) {
case 'Self': {
const center = this.findTileWithCharacter(this.myCharacterId);
if (!center) return;

this.drawPatternAroundCenter(center[0], center[1], ability.pattern);
return;
}

case 'Creature': {
this.defenders.forEach((defender) => {
const center = this.findTileWithCharacter(defender.characterId);
if (!center) return;

this.drawPatternAroundCenter(center[0], center[1], ability.pattern);
});
return;
}
}
}

selectTilesOnHover(hoverTileX: number, hoverTileY: number) {
if (!this.selectedAbility || this.selectedAbility.targetting !== 'Ground')
return;

this.resetSelectedTiles();
this.drawPatternAroundCenter(
hoverTileX,
hoverTileY,
this.selectedAbility.pattern,
);
}

resetAbilityAndSelection() {
this.resetAbility();
this.resetSelectedTiles();
}

resetAbility() {
this.selectedAbility = undefined;
}

resetSelectedTiles() {
this.staticSelectedTiles = {};
}

isTileActive(x: number, y: number) {
if (!this.selectedAbility) return false;

const tileKey = `${x}-${y}`;
return this.staticSelectedTiles[tileKey];
}

clickTile(tile: IFightTile, x: number, y: number) {
if (!this.selectedAbility) return;

if (this.isTileActive(x, y)) {
const targetArgs =
this.selectedAbility.targetting === 'Ground'
? { tile: { x, y } }
: { characterId: tile.containedCharacters[0] };

this.fightService
.takeAction(this.selectedAbility.itemId, targetArgs)
.subscribe();
}

this.resetAbilityAndSelection();
}

startMoving() {
const moveAction = this.contentService.getAbilityByName('Move');
if (!moveAction) return;

this.selectAbility(moveAction);
}

finalizeAction(targetParams: ICombatTargetParams) {
const action = this.selectedAbility;
if (!action) return;

this.fightService.takeAction(action.itemId, targetParams).subscribe();
this.resetAbility();
this.resetSelectedTiles();
}

async flee() {
Expand Down
2 changes: 1 addition & 1 deletion server/src/modules/fight/fight.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export class FightService {
}

default: {
console.log('default action', action);
console.log('default action', action, targetParams);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions shared/interfaces/combat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type ICombatAbilityTargetting = 'Creature' | 'Ground' | 'Self';
export type ICombatAbilityPattern =
| 'Single'
| 'Cross'
| 'CrossNoCenter'
| 'ThreeVertical'
| 'TwoHorizontal';

Expand Down

0 comments on commit c4e032b

Please sign in to comment.