Skip to content

Commit

Permalink
fix(script): prevent actors from hitting themselves (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed May 23, 2021
1 parent adc429c commit c2e59fb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 4 additions & 2 deletions data/base.yml
Expand Up @@ -34,10 +34,12 @@ worlds:
seen: |-
You see a {{item.meta.name}}: {{item.meta.desc}} ({{item.meta.id}}).
hit:
type: |-
{{cmd.target}} is not an actor!
item: |-
You cannot hit {{target.meta.name}}, you are not holding anything!
self: |-
You cannot hit yourself!
type: |-
{{cmd.target}} is not an actor!
drop:
type: |-
{{cmd.target}} is not an item!
Expand Down
5 changes: 5 additions & 0 deletions src/service/script/common/ActorStep.ts
Expand Up @@ -119,6 +119,11 @@ export async function ActorStepHit(this: Actor, context: ScriptContext): Promise
return;
}

if (this === target) {
await context.focus.show('actor.step.hit.self', { cmd });
return;
}

if (this.items.length === 0) {
await context.focus.show('actor.step.hit.item', { target });
return;
Expand Down
4 changes: 2 additions & 2 deletions src/service/state/LocalStateService.ts
@@ -1,4 +1,4 @@
import { constructorName, isNil, mustExist, NotFoundError } from '@apextoaster/js-utils';
import { constructorName, InvalidArgumentError, isNil, mustExist, NotFoundError } from '@apextoaster/js-utils';
import { EventEmitter } from 'events';
import { BaseOptions, Container, Inject, Logger } from 'noicejs';

Expand Down Expand Up @@ -240,7 +240,7 @@ export class LocalStateService extends EventEmitter implements StateService {
type: ACTOR_TYPE,
});
if (!isActor(player)) {
throw new Error('invalid focus actor');
throw new InvalidArgumentError('invalid focus actor');
}

const input = await this.getActorInput(player);
Expand Down

0 comments on commit c2e59fb

Please sign in to comment.