Compare commits

...

3 Commits

8 changed files with 46 additions and 13 deletions

View File

@ -8,6 +8,7 @@
let numberOfUnits = 0; let numberOfUnits = 0;
let repeatMission = false;
$: maximumUnits = getRemainingUnitCount($village, 'soldier'); $: maximumUnits = getRemainingUnitCount($village, 'soldier');
$: if (numberOfUnits > maximumUnits) { $: if (numberOfUnits > maximumUnits) {
numberOfUnits = maximumUnits || 0; numberOfUnits = maximumUnits || 0;
@ -20,7 +21,12 @@
function pillage() { function pillage() {
moves.pillage(region.state.index, numberOfUnits); moves.pillage(region.state.index, numberOfUnits, repeatMission);
}
function toggleMissionRepeat() {
moves.toggleMissionRepeat(region.state.index);
} }
</script> </script>
@ -34,6 +40,10 @@
<div> <div>
<p>{ region.state.mission.unitCount } soldiers are on a mission here.</p> <p>{ region.state.mission.unitCount } soldiers are on a mission here.</p>
<p>Remaining: { Math.ceil(region.state.mission.remainingTime / 1000) }</p> <p>Remaining: { Math.ceil(region.state.mission.remainingTime / 1000) }</p>
<label>
<input type="checkbox" checked={ region.state.mission.repeat } on:change={ toggleMissionRepeat }>
<span title="Send the same troops again when they come back">Repeat</span>
</label>
</div> </div>
{ :else } { :else }
<div> <div>
@ -44,15 +54,13 @@
max={ maximumUnits } max={ maximumUnits }
bind:value={ numberOfUnits } bind:value={ numberOfUnits }
/> />
<input { numberOfUnits }
type="number"
name="units"
min="0"
max={ maximumUnits }
bind:value={ numberOfUnits }
/>
<button on:click={ setMaxUnits }>↑</button> <button on:click={ setMaxUnits }>↑</button>
<button on:click={ pillage } disabled={ numberOfUnits === 0 }>Pillage</button> <button on:click={ pillage } disabled={ numberOfUnits === 0 }>Pillage</button>
<label>
<input type="checkbox" bind:value={ repeatMission }>
<span title="Send the same troops again when they come back">Repeat</span>
</label>
</div> </div>
{ /if } { /if }
</div> </div>

View File

@ -25,5 +25,6 @@
.region { .region {
border: 1px solid white; border: 1px solid white;
padding: 1em; padding: 1em;
width: 40%;
} }
</style> </style>

View File

@ -5,7 +5,7 @@ import type { VillageState } from "../village";
function getStandardTimeToBuild(level: number) { function getStandardTimeToBuild(level: number) {
return Math.round(Math.pow(level, 1 / 1.2) + 1); return Math.round(Math.pow(level, 1 / 0.8) + 2);
} }
@ -325,7 +325,7 @@ export default [
{ {
type: 'palace', type: 'palace',
name: 'Palace', name: 'Palace',
maxLevel: 20, maxLevel: 10,
unique: true, unique: true,
requiredTownhallLevel: 10, requiredTownhallLevel: 10,
cost: (level: number) => { cost: (level: number) => {
@ -345,7 +345,7 @@ export default [
}, },
triggers: { triggers: {
onLevelUp: (V: VillageState, self: BuildingType) => { onLevelUp: (V: VillageState, self: BuildingType) => {
if (self.level === 10 || self.level === 20) { if (self.level === 5 || self.level === 10) {
// Create a new hero. // Create a new hero.
V.heroes.push(createHero()); V.heroes.push(createHero());
} }

View File

@ -18,6 +18,13 @@ export function resolveMission(V: VillageState, region: RegionType) {
default: default:
throw new Error(`Unknown mission type: "${ mission.type }"`); throw new Error(`Unknown mission type: "${ mission.type }"`);
} }
if (mission.repeat) {
mission.remainingTime = region.distance * 10 * 1000;
}
else {
delete region.state.mission;
}
} }
@ -30,5 +37,4 @@ function resolvePillageOasis(V: VillageState, region: OasisType) {
const unit = getUnitSource('soldier'); const unit = getUnitSource('soldier');
V.resources[region.resource] += mission.unitCount * unit.behavior.caryingCapacity; V.resources[region.resource] += mission.unitCount * unit.behavior.caryingCapacity;
delete region.state.mission;
} }

View File

@ -5,6 +5,7 @@ import build from './build';
import pillage from './pillage'; import pillage from './pillage';
import recruitUnits from './recruitUnits'; import recruitUnits from './recruitUnits';
import startQuest from './startQuest'; import startQuest from './startQuest';
import toggleMissionRepeat from './toggleMissionRepeat';
import upgradeBuilding from './upgradeBuilding'; import upgradeBuilding from './upgradeBuilding';
@ -36,4 +37,5 @@ export default {
pillage: makeMove(pillage), pillage: makeMove(pillage),
recruitUnits: makeMove(recruitUnits), recruitUnits: makeMove(recruitUnits),
startQuest: makeMove(startQuest), startQuest: makeMove(startQuest),
toggleMissionRepeat: makeMove(toggleMissionRepeat),
}; };

View File

@ -2,7 +2,7 @@ import { getRemainingUnitCount } from "../utils";
import type { VillageState } from "../village"; import type { VillageState } from "../village";
export default function pillage(V: VillageState, regionIndex: number, soldiersCount: number) { export default function pillage(V: VillageState, regionIndex: number, soldiersCount: number, repeat: boolean) {
if (soldiersCount > getRemainingUnitCount(V, 'soldier')) { if (soldiersCount > getRemainingUnitCount(V, 'soldier')) {
return false; return false;
} }
@ -18,6 +18,7 @@ export default function pillage(V: VillageState, regionIndex: number, soldiersCo
unitType: 'soldier', unitType: 'soldier',
unitCount: soldiersCount, unitCount: soldiersCount,
remainingTime: region.distance * 10 * 1000, remainingTime: region.distance * 10 * 1000,
repeat,
}; };
return true; return true;

View File

@ -0,0 +1,14 @@
import type { VillageState } from "../village";
export default function toggleMissionRepeat(V: VillageState, regionIndex: number) {
const region = V.worldmap[regionIndex];
if (!region.state.mission) {
return false;
}
region.state.mission.repeat = !region.state.mission.repeat;
return true;
}

View File

@ -78,6 +78,7 @@ export interface MissionType {
unitType: string; unitType: string;
unitCount: number; unitCount: number;
remainingTime: number; remainingTime: number;
repeat: boolean;
} }
interface BaseRegionType { interface BaseRegionType {