-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
132 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { VillageActivity, VillageCommand } from "@rpg-village/core"; | ||
|
||
import { test } from "../../utils"; | ||
|
||
test("should start a build activity when gold is enough", { | ||
initState: { village: { stash: { resource: { gold: 100 } }, trainingField: 0 } }, | ||
commands: [VillageCommand.BuildTrainingField], | ||
expectedState: (state, t) => t.withRandomId(state.activities, { name: VillageActivity.Build, startArgs: { targetBuilding: 'trainingField' } }), | ||
}); | ||
|
||
test("should block the second command for building", { | ||
initState: { village: { stash: { resource: { gold: 1000 } }, trainingField: 0 } }, | ||
commands: [VillageCommand.BuildTrainingField, VillageCommand.BuildTrainingField], | ||
expectedState: [ | ||
(state, t) => t.withRandomId(state.activities, { name: VillageActivity.Build, startArgs: { targetBuilding: 'trainingField' } }), | ||
(state, t) => t.deepEqual(state.village, { stash: { resource: { gold: 900 } }, trainingField: 0 }) | ||
] | ||
}); |
6 changes: 3 additions & 3 deletions
6
packages/core-test/tests/commands/village/build-blacksmith.test.ts
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
6 changes: 3 additions & 3 deletions
6
packages/core-test/tests/commands/village/build-house.test.ts
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
6 changes: 3 additions & 3 deletions
6
packages/core-test/tests/commands/village/build-portals.test.ts
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
6 changes: 3 additions & 3 deletions
6
packages/core-test/tests/commands/village/build-rune-workshop.test.ts
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { injectable } from "inversify"; | ||
import { dec, evolve, inc } from "ramda"; | ||
|
||
import { Activity, IActivityHandler } from "@modules/activity"; | ||
|
||
import { VillageStore } from "../village-store"; | ||
|
||
interface BuildState { | ||
progress: number; | ||
} | ||
|
||
export type VillageBuildings = "houses" | "blacksmith" | "portals" | "trainingField" | "runeWorkshop"; | ||
|
||
interface BuildStartArgs { | ||
targetBuilding: VillageBuildings; | ||
} | ||
|
||
@injectable() | ||
export class BuildActivity implements IActivityHandler<Activity<BuildState, BuildStartArgs>> { | ||
constructor(private villageStore: VillageStore) {} | ||
|
||
start(): BuildState { | ||
return { | ||
progress: 100 | ||
}; | ||
} | ||
|
||
isRunnable(): boolean { | ||
return true; | ||
} | ||
|
||
execute({ state }: Activity<BuildState, BuildStartArgs>): BuildState { | ||
return evolve({ progress: dec }, state); | ||
} | ||
|
||
isDone({ state: { progress } }: Activity<BuildState, BuildStartArgs>): boolean { | ||
return progress === 0; | ||
} | ||
|
||
resolve({ startArgs: { targetBuilding } }: Activity<BuildState, BuildStartArgs>) { | ||
this.villageStore.update(targetBuilding, inc); | ||
} | ||
} |
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 +1,2 @@ | ||
export * from "./village-heal"; | ||
export * from './build'; |
1 change: 1 addition & 0 deletions
1
packages/core/src/modules/village/interfaces/village-activity.ts
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,3 +1,4 @@ | ||
export enum VillageActivity { | ||
Heal = "village/heal", | ||
Build = "village/build" | ||
} |
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