Skip to content

Commit 08e85b1

Browse files
chore: don't select dead entities in combat
- idk if this is quite the right solution. I think you want to set the entity enabled=False to avoid selection. 🤷
1 parent 302417e commit 08e85b1

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

src/app/routes/combat/behaviors/choose-action.machine.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,14 @@ export class ChooseActionType extends State<CombatChooseActionStateNames> {
7979
let sub: Subscription | null = null;
8080

8181
let clickSelect = (click: CombatSceneClick) => {
82+
const targetClick = click.hits[0];
83+
// If the target has no HP, it's not a valid target.
84+
if (!targetClick?.model?.hp) {
85+
return;
86+
}
8287
sub?.unsubscribe();
8388
sub = null;
84-
machine.target = click.hits[0];
89+
machine.target = targetClick;
8590
machine.parent.items[0].select();
8691
};
8792
assertTrue(machine.current, 'Requires Current Player');
@@ -221,6 +226,10 @@ export class ChooseActionTarget extends State<CombatChooseActionStateNames> {
221226
machine.setCurrentState(ChooseActionSubmit.NAME);
222227
return;
223228
}
229+
// If the target has no HP, it's not a valid target.
230+
if (!target?.model?.hp) {
231+
return;
232+
}
224233
machine.target = target;
225234
machine.parent.setPointerTarget(target, 'left');
226235
};

src/app/routes/combat/combat.component.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,32 +74,21 @@ export class CombatComponent
7474
implements IProcessObject, OnDestroy, AfterViewInit
7575
{
7676
@Input() scene: Scene = new Scene();
77-
/**
78-
* A pointing UI element that can be attached to `SceneObject`s to attract attention
79-
* @type {null}
80-
*/
77+
/** A pointing UI element that can be attached to `SceneObject`s to attract attention */
8178
pointer: UIAttachment | null = null;
8279

83-
/**
84-
* Available menu items for selection.
85-
*/
86-
@Input()
87-
items: ICombatMenuItem[] = [];
80+
/** Available menu items for selection. */
81+
@Input() items: ICombatMenuItem[] = [];
8882

8983
/** The combat state machine */
9084
@ViewChild(CombatStateMachineComponent) machine: CombatStateMachineComponent;
9185

92-
/**
93-
* Damages displaying on screen.
94-
* @type {Array}
95-
*/
86+
/** Damages displaying on screen. */
9687
@Input() damages: ICombatDamageSummary[] = [];
9788

9889
@Input() defaultState: CombatStateNames | null = 'start';
9990

100-
/**
101-
* Mouse hook for capturing input with world and screen coordinates.
102-
*/
91+
/** Mouse hook for capturing input with world and screen coordinates. */
10392
mouse: NamedMouseElement | null = null;
10493

10594
@ViewChild('combatCanvas') canvasElementRef: ElementRef;
@@ -318,7 +307,7 @@ export class CombatComponent
318307
}
319308

320309
/**
321-
* Render all of the map feature components
310+
* Render all of the map features and combatants.
322311
*/
323312
renderFrame(elapsed: number) {
324313
this.clearRect();

0 commit comments

Comments
 (0)