Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(command): implement actor hit command
- Loading branch information
Showing
9 changed files
with
57 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
import { mustExist } from '@apextoaster/js-utils'; | ||
import { InvalidArgumentError, mustExist } from '@apextoaster/js-utils'; | ||
|
||
import { ScriptScope, ScriptTarget } from '..'; | ||
import { isActor } from '../../../model/entity/Actor'; | ||
import { decrementKey } from '../../../util/map'; | ||
|
||
export async function ActorHit(this: ScriptTarget, scope: ScriptScope): Promise<void> { | ||
if (!isActor(this)) { | ||
throw new InvalidArgumentError('invalid entity type'); | ||
} | ||
|
||
const attacker = mustExist(scope.actor); | ||
//const item = mustExist(scope.item); | ||
const item = mustExist(scope.item); | ||
|
||
scope.logger.debug(`${this.meta.name} has been hit by ${attacker.meta.name}!`); // with the ${item.meta.name}!`); | ||
const health = decrementKey(this.stats, 'health'); | ||
await scope.render.show(`${attacker.meta.name} has hit ${this.meta.name} with a ${item.meta.name}!`); | ||
await scope.render.show(`${this.meta.name} has ${health} health left`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters