Compare commits

...

3 Commits

8 changed files with 46 additions and 13 deletions

View File

@ -8,6 +8,7 @@
let numberOfUnits = 0;
let repeatMission = false;
$: maximumUnits = getRemainingUnitCount($village, 'soldier');
$: if (numberOfUnits > maximumUnits) {
numberOfUnits = maximumUnits || 0;
@ -20,7 +21,12 @@
function pillage() {
moves.pillage(region.state.index, numberOfUnits);
moves.pillage(region.state.index, numberOfUnits, repeatMission);
}
function toggleMissionRepeat() {
moves.toggleMissionRepeat(region.state.index);
}
</script>
@ -34,6 +40,10 @@
<div>
<p>{ region.state.mission.unitCount } soldiers are on a mission here.</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>
{ :else }
<div>
@ -44,15 +54,13 @@
max={ maximumUnits }
bind:value={ numberOfUnits }
/>
<input
type="number"
name="units"
min="0"
max={ maximumUnits }
bind:value={ numberOfUnits }
/>
{ numberOfUnits }
<button on:click={ setMaxUnits }>↑</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>
{ /if }
</div>

View File

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

View File

@ -5,7 +5,7 @@ import type { VillageState } from "../village";
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',
name: 'Palace',
maxLevel: 20,
maxLevel: 10,
unique: true,
requiredTownhallLevel: 10,
cost: (level: number) => {
@ -345,7 +345,7 @@ export default [
},
triggers: {
onLevelUp: (V: VillageState, self: BuildingType) => {
if (self.level === 10 || self.level === 20) {
if (self.level === 5 || self.level === 10) {
// Create a new hero.
V.heroes.push(createHero());
}

View File

@ -18,6 +18,13 @@ export function resolveMission(V: VillageState, region: RegionType) {
default:
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');
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 recruitUnits from './recruitUnits';
import startQuest from './startQuest';
import toggleMissionRepeat from './toggleMissionRepeat';
import upgradeBuilding from './upgradeBuilding';
@ -36,4 +37,5 @@ export default {
pillage: makeMove(pillage),
recruitUnits: makeMove(recruitUnits),
startQuest: makeMove(startQuest),
toggleMissionRepeat: makeMove(toggleMissionRepeat),
};

View File

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