Skip to content

Commit

Permalink
move party location reference into mapLocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Greegko committed May 29, 2023
1 parent ade8815 commit 1861dcc
Show file tree
Hide file tree
Showing 29 changed files with 193 additions and 239 deletions.
1 change: 0 additions & 1 deletion packages/core-test/tests/activities/battle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ test("should gain soul", {
battleId: battle({
partyId: party({
id: "party-id",
locationId: "locationId2",
unitIds: [unit({ dmg: 100, hp: 100 })],
stash: { resource: { soul: 5 } },
}),
Expand Down
43 changes: 20 additions & 23 deletions packages/core-test/tests/activities/manager.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
import { MapActivity } from "@rpg-village/core";
import { ActivityType, MapActivity, VillageActivity } from "@rpg-village/core";

import { createState, test } from "../utils";

test("should resolve activity result", {
initState: {
activities: {
"test-activity-id": {
name: MapActivity.Travel,
startArgs: {
partyId: "test-party",
},
state: {
partyId: "test-party",
progress: 1,
targetLocationId: "location-2",
},
},
},
parties: { "test-party": { locationId: "location-1" } },
},
initState: createState(({ activity, village }) => [
village({ houses: 0 }),
activity({
id: "testActivityId",
name: VillageActivity.Build,
type: ActivityType.Global,
startArgs: { targetBuilding: "houses" },
state: { progress: 1 },
}),
]),
turn: true,
expectedState: {
parties: { "test-party": { locationId: "location-2" } },
},
expectedState: { village: { houses: 1 } },
});

test("should decrease progress counter when not finished", {
Expand All @@ -31,6 +23,7 @@ test("should decrease progress counter when not finished", {
"test-activity-id": {
id: "test-activity-id",
name: MapActivity.Travel,
type: ActivityType.Party,
state: { progress: 2 },
},
},
Expand All @@ -39,19 +32,23 @@ test("should decrease progress counter when not finished", {
expectedState: {
activities: {
"test-activity-id": {
id: "test-activity-id",
name: MapActivity.Travel,
type: ActivityType.Party,
state: { progress: 1 },
},
},
},
});

test("should remove old activity on finish", {
initState: createState(({ activity }) => [
initState: createState(({ activity, village }) => [
village({ houses: 0 }),
activity({
id: "testActivityId",
name: MapActivity.Travel,
state: { progress: 1 },
name: VillageActivity.Build,
type: ActivityType.Global,
state: { progress: 1, buildingType: "house" },
}),
]),
turn: true,
Expand Down
54 changes: 14 additions & 40 deletions packages/core-test/tests/activities/world/explore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@ import { createState, test } from "../../utils";

test("should change explore status on tile", {
initState: createState(({ location, party, activity, map }) => [
map({ mapLocationIds: ["tile"] }),
map({ mapLocationIds: [location({ id: "tile", partyIds: ["party"], explored: false })] }),
activity({
name: MapActivity.Explore,
state: {
partyId: party({
id: "party",
locationId: location({ id: "tile", explored: false }),
}),
progress: 1,
},
state: { partyId: party({ id: "party" }), progress: 1 },
}),
]),
turn: true,
Expand All @@ -24,16 +18,10 @@ test("should change explore status on tile", {

test("should add new locations around explored tile", {
initState: createState(({ location, party, activity, map }) => [
map({ mapLocationIds: ["tile"] }),
map({ mapLocationIds: [location({ id: "tile", partyIds: ["party"], explored: false })] }),
activity({
name: MapActivity.Explore,
state: {
partyId: party({
id: "party",
locationId: location({ id: "tile", explored: false }),
}),
progress: 1,
},
state: { partyId: party({ id: "party" }), progress: 1 },
}),
]),
turn: true,
Expand All @@ -42,16 +30,10 @@ test("should add new locations around explored tile", {

test("should add enemy units on new map tile", {
initState: createState(({ location, party, activity, map }) => [
map({ mapLocationIds: ["tile"] }),
map({ mapLocationIds: [location({ id: "tile", partyIds: ["party"], explored: false })] }),
activity({
name: MapActivity.Explore,
state: {
partyId: party({
id: "party",
locationId: location({ id: "tile", explored: false }),
}),
progress: 1,
},
state: { partyId: party({ id: "party" }), progress: 1 },
}),
]),
turn: true,
Expand All @@ -60,16 +42,12 @@ test("should add enemy units on new map tile", {

test("should spawn empty tiles after boss tiles", {
initState: createState(({ location, party, activity, map }) => [
map({ mapLocationIds: ["boss-tile"] }),
map({
mapLocationIds: [location({ id: "boss-tile", partyIds: ["party"], explored: false, type: MapLocationType.Boss })],
}),
activity({
name: MapActivity.Explore,
state: {
partyId: party({
id: "party",
locationId: location({ id: "boss-tile", explored: false, type: MapLocationType.Boss }),
}),
progress: 1,
},
state: { partyId: party({ id: "party" }), progress: 1 },
}),
]),
turn: true,
Expand All @@ -90,16 +68,12 @@ test("should spawn empty tiles after boss tiles", {

test("should not add enemies on empty tiles", {
initState: createState(({ location, party, activity, map }) => [
map({ mapLocationIds: ["boss-tile"] }),
map({
mapLocationIds: [location({ id: "boss-tile", partyIds: ["party"], explored: false, type: MapLocationType.Boss })],
}),
activity({
name: MapActivity.Explore,
state: {
partyId: party({
id: "party",
locationId: location({ id: "boss-tile", explored: false, type: MapLocationType.Boss }),
}),
progress: 1,
},
state: { partyId: party({ id: "party" }), progress: 1 },
}),
]),
turn: true,
Expand Down
11 changes: 7 additions & 4 deletions packages/core-test/tests/activities/world/travel.test.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
import { MapActivity } from "@rpg-village/core";
import { ActivityType, MapActivity } from "@rpg-village/core";

import { createState, stashFactory, test } from "../../utils";

test("should move party to the new location on finish", {
initState: createState(({ party, activity, location }) => [
location({ id: "test", partyIds: ["test-party-id"] }),
activity({
name: MapActivity.Travel,
type: ActivityType.Party,
state: {
partyId: party({ id: "test-party-id", locationId: location() }),
partyId: party({ id: "test-party-id" }),
progress: 1,
targetLocationId: location({ id: "target-location" }),
},
}),
]),
turn: true,
expectedState: {
parties: { "test-party-id": { locationId: "target-location" } },
mapLocations: { "target-location": { partyIds: ["test-party-id"] } },
},
});

test("should store looted resource into village stash", {
initState: createState(({ party, activity, location, village }) => [
location({ id: "test", partyIds: ["test-party-id"] }),
activity({
name: MapActivity.Travel,
type: ActivityType.Party,
state: {
partyId: party({
id: "test-party-id",
locationId: location(),
stash: stashFactory({ resource: { gold: 5, soul: 1 } }),
}),
progress: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { createState, test } from "../../../utils";

test("should give new dmg effect", {
initState: createState(({ unit, village, party }) => [
village({ stash: { resource: { gold: 50 } } }),
party({
locationId: village({ stash: { resource: { gold: 50 } } }),
unitIds: [
unit({
id: "target-unit",
Expand Down Expand Up @@ -35,8 +35,8 @@ test("should give new dmg effect", {

test("should use village gold for upgrade", {
initState: createState(({ unit, village, party }) => [
village({ stash: { resource: { gold: 50 } } }),
party({
locationId: village({ stash: { resource: { gold: 50 } } }),
unitIds: [
unit({
id: "target-unit",
Expand All @@ -56,8 +56,8 @@ test("should use village gold for upgrade", {

test("should upgrade item on hero equipment", {
initState: createState(({ unit, village, party }) => [
village({ stash: { resource: { gold: 50 } } }),
party({
locationId: village({ stash: { resource: { gold: 50 } } }),
unitIds: [
unit({
id: "target-unit",
Expand Down Expand Up @@ -88,9 +88,7 @@ test("should upgrade item on hero equipment", {

test("should upgrade in village stash", {
initState: createState(({ village, party }) => [
party({
locationId: village({ stash: { resource: { gold: 50 }, items: [{ id: "test-item", effects: [] }] } }),
}),
village({ stash: { resource: { gold: 50 }, items: [{ id: "test-item", effects: [] }] } }),
]),
commands: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { createState, test } from "../../../utils";
test("should party jump to location", {
initState: createState(({ village, party, location }) => [
location({ type: MapLocationType.Portal, id: "portal-id" }),
party({
id: "party-id",
locationId: village(),
location({
id: village(),
partyIds: [party({ id: "party-id" })],
}),
]),
commands: [
Expand All @@ -16,5 +16,5 @@ test("should party jump to location", {
args: { partyId: "party-id", portalLocationId: "portal-id" },
},
],
expectedState: { parties: { "party-id": { locationId: "portal-id" } } },
expectedState: { mapLocations: { "portal-id": { partyIds: ["party-id"] } } },
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,30 @@ test("should party jump to village", {
initState: createState(({ village, party, location, map }) => [
map({ id: "map-id", mapLocationIds: ["portal-id"] }),
village({ locationId: "village-location" }),
party({
id: "party-id",
locationId: location({ type: MapLocationType.Portal, id: "portal-id" }),
location({
id: "portal-id",
type: MapLocationType.Portal,
partyIds: [party({ id: "party-id" })],
}),
]),
commands: [
{
command: PortalCommand.LeavePortal,
args: { partyId: "party-id", portalLocationId: "portal-id" },
},
],
expectedState: { parties: { "party-id": { locationId: "village-location" } } },
commands: [{ command: PortalCommand.LeavePortal, args: { partyId: "party-id", portalLocationId: "portal-id" } }],
expectedState: { mapLocations: { "village-location": { partyIds: ["party-id"] } } },
});

test("should remove map when the map is finished and party leaves", {
initState: createState(({ village, party, location, map }) => [
map({
id: "portal-map-id",
mapLocationIds: [location({ type: MapLocationType.Portal, id: "portal-location-id" })],
mapLocationIds: [
location({ id: "boss-location-id", partyIds: [], type: MapLocationType.Boss }),
location({ id: "portal-location-id", partyIds: [party({ id: "party-id" })], type: MapLocationType.Portal }),
],
mapSize: 1,
}),
village({ locationId: "village-location" }),
party({
id: "party-id",
locationId: "portal-location-id",
}),
]),
commands: [
{
command: PortalCommand.LeavePortal,
args: { partyId: "party-id", portalLocationId: "portal-location-id" },
},
{ command: PortalCommand.LeavePortal, args: { partyId: "party-id", portalLocationId: "portal-location-id" } },
],
expectedState: (state, t) => t.is(state.maps["portal-map-id"], undefined),
});
Expand All @@ -46,20 +38,16 @@ test("should start gather portal resource activity when the map is finished and
initState: createState(({ village, party, location, map }) => [
map({
id: "portal-map-id",
mapLocationIds: [location({ type: MapLocationType.Portal, id: "portal-location-id" })],
mapLocationIds: [
location({ type: MapLocationType.Portal, id: "portal-location-id", partyIds: [party({ id: "party-id" })] }),
location({ type: MapLocationType.Boss, id: "boss-location-id", partyIds: [] }),
],
mapSize: 1,
}),
village({ locationId: "village-location" }),
party({
id: "party-id",
locationId: "portal-location-id",
}),
]),
commands: [
{
command: PortalCommand.LeavePortal,
args: { partyId: "party-id", portalLocationId: "portal-location-id" },
},
{ command: PortalCommand.LeavePortal, args: { partyId: "party-id", portalLocationId: "portal-location-id" } },
],
expectedState: (state, t) => t.withRandomId(state.activities, { name: PortalActivity.GatherResourceFromPortal }),
});
23 changes: 4 additions & 19 deletions packages/core-test/tests/commands/map/battle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,11 @@ import { createState, test } from "../../utils";

test("should start Battle activity", {
initState: createState(({ party, unit, location, map }) => [
map({ mapLocationIds: ["battle-location"], modifiers: [] }),
party({
id: "party-x",
locationId: location({ id: "battle-location" }),
unitIds: [unit({ hp: 50 })],
owner: PartyOwner.Player,
}),
party({
id: "party-y",
locationId: location({ id: "battle-location" }),
unitIds: [unit({ hp: 50 })],
owner: PartyOwner.Enemy,
}),
map({ mapLocationIds: [location({ id: "battle-location", partyIds: ["party-x", "party-y"] })], modifiers: [] }),
party({ id: "party-x", unitIds: [unit({ hp: 50 })], owner: PartyOwner.Player }),
party({ id: "party-y", unitIds: [unit({ hp: 50 })], owner: PartyOwner.Enemy }),
]),
commands: [
{
command: MapCommand.Battle,
args: { locationId: "battle-location" },
},
],
commands: [{ command: MapCommand.Battle, args: { locationId: "battle-location" } }],
expectedState: (state, t) => {
t.withRandomId(state.activities, { name: BattleActivityType.Battle });
t.withRandomId(state.battle, {
Expand Down
Loading

0 comments on commit 1861dcc

Please sign in to comment.