@vnejs/plugins.rpg.damage 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { regPlugin } from "@vnejs/shared";
2
+ import { CONSTANTS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.rpg.damage.contract";
3
+ import { Damage } from "./modules/damage.js";
4
+ regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS }, [Damage]);
@@ -0,0 +1,10 @@
1
+ import { Module } from "@vnejs/module";
2
+ import type { DamageEmitPayload, DamageUnitTargetPayload } from "@vnejs/plugins.rpg.damage.contract";
3
+ import type { DamagePluginConstants, DamagePluginEvents, DamagePluginParams, DamagePluginSettings } from "../types.js";
4
+ export declare class Damage extends Module<DamagePluginEvents, DamagePluginConstants, DamagePluginSettings, DamagePluginParams> {
5
+ name: string;
6
+ subscribe: () => void;
7
+ onDamageEmit: ({ unit, target, value, multiplicator, random, accuracy }?: DamageEmitPayload) => Promise<void>;
8
+ onDamageEmitStart: ({ unit, target }?: DamageUnitTargetPayload) => void;
9
+ onDamageEmitFinish: ({ unit, target }?: DamageUnitTargetPayload) => void;
10
+ }
@@ -0,0 +1,38 @@
1
+ import { Module } from "@vnejs/module";
2
+ export class Damage extends Module {
3
+ name = "damage";
4
+ subscribe = () => {
5
+ this.on(this.EVENTS.DAMAGE.EMIT, this.onDamageEmit);
6
+ this.on(this.EVENTS.DAMAGE.EMIT_START, this.onDamageEmitStart);
7
+ this.on(this.EVENTS.DAMAGE.EMIT_FINISH, this.onDamageEmitFinish);
8
+ };
9
+ onDamageEmit = async ({ unit = "", target = "", value = 0, multiplicator = 1, random = 0, accuracy = 1 } = {}) => {
10
+ await this.emit(this.EVENTS.DAMAGE.EMIT_START, { unit, target });
11
+ const accuracyValue = accuracy;
12
+ const hitRandomChance = Math.random();
13
+ if (hitRandomChance >= accuracyValue) {
14
+ await this.emit(this.EVENTS.DAMAGE.MISSED, { unit, target });
15
+ }
16
+ else {
17
+ const baseValue = value * Math.floor(Math.random() * random);
18
+ const multiplicatorValue = multiplicator;
19
+ const damage = baseValue * multiplicatorValue;
20
+ if (damage === 0) {
21
+ await this.emit(this.EVENTS.DAMAGE.BLOCKED, { unit, target });
22
+ }
23
+ else if (damage > 0) {
24
+ await this.emit(this.EVENTS.DAMAGE.DEALT, { unit, target, value: damage });
25
+ }
26
+ else {
27
+ await this.emit(this.EVENTS.DAMAGE.REFLECTED, { unit, target, value: damage });
28
+ }
29
+ }
30
+ await this.emit(this.EVENTS.DAMAGE.EMIT_FINISH, { unit, target });
31
+ };
32
+ onDamageEmitStart = ({ unit = "", target = "" } = {}) => {
33
+ console.log("Damage Start", unit, target);
34
+ };
35
+ onDamageEmitFinish = ({ unit = "", target = "" } = {}) => {
36
+ console.log("Damage Finish", unit, target);
37
+ };
38
+ }
@@ -0,0 +1,6 @@
1
+ import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry, VnePluginParamsMapRegistry, VnePluginSettingsMapRegistry } from "@vnejs/shared";
2
+ import type { Constants, PluginName, SubscribeEvents } from "@vnejs/plugins.rpg.damage.contract";
3
+ export type DamagePluginEvents = VnePluginEventsMapRegistry & Record<PluginName, SubscribeEvents>;
4
+ export type DamagePluginConstants = VnePluginConstantsMapRegistry & Record<PluginName, Constants>;
5
+ export type DamagePluginSettings = VnePluginSettingsMapRegistry;
6
+ export type DamagePluginParams = VnePluginParamsMapRegistry;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@vnejs/plugins.rpg.damage",
3
+ "version": "0.1.1",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "src",
18
+ "tsconfig.json"
19
+ ],
20
+ "scripts": {
21
+ "test": "echo \"Error: no test specified\" && exit 1",
22
+ "build": "npx @vnejs/monorepo package",
23
+ "publish:major:plugin": "npm run publish:major",
24
+ "publish:minor:plugin": "npm run publish:minor",
25
+ "publish:patch:plugin": "npm run publish:patch",
26
+ "publish:major": "npx @vnejs/monorepo publish major --access public",
27
+ "publish:minor": "npx @vnejs/monorepo publish minor --access public",
28
+ "publish:patch": "npx @vnejs/monorepo publish patch --access public"
29
+ },
30
+ "author": "",
31
+ "license": "ISC",
32
+ "dependencies": {
33
+ "@vnejs/plugins.rpg.damage.contract": "~0.0.1"
34
+ },
35
+ "peerDependencies": {
36
+ "@vnejs/module": "~0.0.1",
37
+ "@vnejs/shared": "~0.0.9"
38
+ },
39
+ "devDependencies": {
40
+ "@vnejs/configs.ts-common": "~0.0.1"
41
+ }
42
+ }
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { regPlugin } from "@vnejs/shared";
2
+ import { CONSTANTS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.rpg.damage.contract";
3
+
4
+ import { Damage } from "./modules/damage.js";
5
+
6
+ regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS }, [Damage]);
@@ -0,0 +1,49 @@
1
+ import { Module } from "@vnejs/module";
2
+ import type { DamageEmitPayload, DamageUnitTargetPayload } from "@vnejs/plugins.rpg.damage.contract";
3
+
4
+ import type { DamagePluginConstants, DamagePluginEvents, DamagePluginParams, DamagePluginSettings } from "../types.js";
5
+
6
+ export class Damage extends Module<DamagePluginEvents, DamagePluginConstants, DamagePluginSettings, DamagePluginParams> {
7
+ name = "damage";
8
+
9
+ subscribe = () => {
10
+ this.on(this.EVENTS.DAMAGE.EMIT, this.onDamageEmit);
11
+ this.on(this.EVENTS.DAMAGE.EMIT_START, this.onDamageEmitStart);
12
+ this.on(this.EVENTS.DAMAGE.EMIT_FINISH, this.onDamageEmitFinish);
13
+ };
14
+
15
+ onDamageEmit = async ({ unit = "", target = "", value = 0, multiplicator = 1, random = 0, accuracy = 1 }: DamageEmitPayload = {}) => {
16
+ await this.emit(this.EVENTS.DAMAGE.EMIT_START, { unit, target });
17
+
18
+ const accuracyValue = accuracy;
19
+
20
+ const hitRandomChance = Math.random();
21
+
22
+ if (hitRandomChance >= accuracyValue) {
23
+ await this.emit(this.EVENTS.DAMAGE.MISSED, { unit, target });
24
+ } else {
25
+ const baseValue = value * Math.floor(Math.random() * random);
26
+ const multiplicatorValue = multiplicator;
27
+
28
+ const damage = baseValue * multiplicatorValue;
29
+
30
+ if (damage === 0) {
31
+ await this.emit(this.EVENTS.DAMAGE.BLOCKED, { unit, target });
32
+ } else if (damage > 0) {
33
+ await this.emit(this.EVENTS.DAMAGE.DEALT, { unit, target, value: damage });
34
+ } else {
35
+ await this.emit(this.EVENTS.DAMAGE.REFLECTED, { unit, target, value: damage });
36
+ }
37
+ }
38
+
39
+ await this.emit(this.EVENTS.DAMAGE.EMIT_FINISH, { unit, target });
40
+ };
41
+
42
+ onDamageEmitStart = ({ unit = "", target = "" }: DamageUnitTargetPayload = {}) => {
43
+ console.log("Damage Start", unit, target);
44
+ };
45
+
46
+ onDamageEmitFinish = ({ unit = "", target = "" }: DamageUnitTargetPayload = {}) => {
47
+ console.log("Damage Finish", unit, target);
48
+ };
49
+ }
package/src/types.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry, VnePluginParamsMapRegistry, VnePluginSettingsMapRegistry } from "@vnejs/shared";
2
+ import type { Constants, PluginName, SubscribeEvents } from "@vnejs/plugins.rpg.damage.contract";
3
+
4
+ export type DamagePluginEvents = VnePluginEventsMapRegistry & Record<PluginName, SubscribeEvents>;
5
+
6
+ export type DamagePluginConstants = VnePluginConstantsMapRegistry & Record<PluginName, Constants>;
7
+
8
+ export type DamagePluginSettings = VnePluginSettingsMapRegistry;
9
+
10
+ export type DamagePluginParams = VnePluginParamsMapRegistry;
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@vnejs/configs.ts-common/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist"
6
+ },
7
+ "include": ["src/**/*.ts"],
8
+ "exclude": ["dist", "node_modules"]
9
+ }