Add a max level to all buildings.
This commit is contained in:
parent
92dd8716a4
commit
1f312c072b
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
$: isUpgrading = building.state.upgrade.isUpgrading;
|
$: isUpgrading = building.state.upgrade.isUpgrading;
|
||||||
$: canUpgrade = !isUpgrading && canPayBuildingCost($village, building);
|
$: canUpgrade = !isUpgrading && canPayBuildingCost($village, building);
|
||||||
|
$: maxLevelReached = building.level === building.maxLevel;
|
||||||
|
|
||||||
|
|
||||||
function upgradeBuilding() {
|
function upgradeBuilding() {
|
||||||
@ -24,6 +25,7 @@
|
|||||||
class="level"
|
class="level"
|
||||||
class:can-upgrade={ canUpgrade }
|
class:can-upgrade={ canUpgrade }
|
||||||
class:is-upgrading={ isUpgrading }
|
class:is-upgrading={ isUpgrading }
|
||||||
|
class:max-level={ maxLevelReached }
|
||||||
on:click|stopPropagation={ upgradeBuilding }
|
on:click|stopPropagation={ upgradeBuilding }
|
||||||
>
|
>
|
||||||
{ building.level }
|
{ building.level }
|
||||||
@ -59,4 +61,8 @@
|
|||||||
.level.is-upgrading {
|
.level.is-upgrading {
|
||||||
border-color: hsl(56, 99%, 43%);
|
border-color: hsl(56, 99%, 43%);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.level.max-level {
|
||||||
|
border-color: hsl(209, 70%, 52%);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -8,6 +8,7 @@ export default [
|
|||||||
type: 'townhall',
|
type: 'townhall',
|
||||||
name: 'Town Hall',
|
name: 'Town Hall',
|
||||||
autoBuilt: true,
|
autoBuilt: true,
|
||||||
|
maxLevel: 20,
|
||||||
cost: (level: number) => {
|
cost: (level: number) => {
|
||||||
return {
|
return {
|
||||||
wood: level * 10,
|
wood: level * 10,
|
||||||
@ -31,6 +32,7 @@ export default [
|
|||||||
type: 'woodcutter',
|
type: 'woodcutter',
|
||||||
name: 'Woodcutter',
|
name: 'Woodcutter',
|
||||||
autoBuilt: true,
|
autoBuilt: true,
|
||||||
|
maxLevel: 20,
|
||||||
cost: (level: number) => {
|
cost: (level: number) => {
|
||||||
return {
|
return {
|
||||||
wood: level * 10,
|
wood: level * 10,
|
||||||
@ -56,6 +58,7 @@ export default [
|
|||||||
type: 'mine',
|
type: 'mine',
|
||||||
name: 'Mine',
|
name: 'Mine',
|
||||||
autoBuilt: true,
|
autoBuilt: true,
|
||||||
|
maxLevel: 20,
|
||||||
cost: (level: number) => {
|
cost: (level: number) => {
|
||||||
return {
|
return {
|
||||||
wood: level * 10,
|
wood: level * 10,
|
||||||
@ -81,6 +84,7 @@ export default [
|
|||||||
type: 'pit',
|
type: 'pit',
|
||||||
name: 'Pit',
|
name: 'Pit',
|
||||||
autoBuilt: true,
|
autoBuilt: true,
|
||||||
|
maxLevel: 20,
|
||||||
cost: (level: number) => {
|
cost: (level: number) => {
|
||||||
return {
|
return {
|
||||||
wood: level * 10,
|
wood: level * 10,
|
||||||
@ -106,6 +110,7 @@ export default [
|
|||||||
type: 'field',
|
type: 'field',
|
||||||
name: 'Field',
|
name: 'Field',
|
||||||
autoBuilt: true,
|
autoBuilt: true,
|
||||||
|
maxLevel: 20,
|
||||||
cost: (level: number) => {
|
cost: (level: number) => {
|
||||||
return {
|
return {
|
||||||
wood: level * 10,
|
wood: level * 10,
|
||||||
@ -126,6 +131,7 @@ export default [
|
|||||||
{
|
{
|
||||||
type: 'warehouse',
|
type: 'warehouse',
|
||||||
name: 'Warehouse',
|
name: 'Warehouse',
|
||||||
|
maxLevel: 20,
|
||||||
cost: (level: number) => {
|
cost: (level: number) => {
|
||||||
return {
|
return {
|
||||||
wood: level * 10,
|
wood: level * 10,
|
||||||
@ -150,6 +156,7 @@ export default [
|
|||||||
{
|
{
|
||||||
type: 'granary',
|
type: 'granary',
|
||||||
name: 'Granary',
|
name: 'Granary',
|
||||||
|
maxLevel: 20,
|
||||||
cost: (level: number) => {
|
cost: (level: number) => {
|
||||||
return {
|
return {
|
||||||
wood: level * 10,
|
wood: level * 10,
|
||||||
@ -174,6 +181,7 @@ export default [
|
|||||||
{
|
{
|
||||||
type: 'university',
|
type: 'university',
|
||||||
name: 'University',
|
name: 'University',
|
||||||
|
maxLevel: 20,
|
||||||
cost: (level: number) => {
|
cost: (level: number) => {
|
||||||
return {
|
return {
|
||||||
wood: level * 100,
|
wood: level * 100,
|
||||||
@ -198,6 +206,7 @@ export default [
|
|||||||
{
|
{
|
||||||
type: 'barracks',
|
type: 'barracks',
|
||||||
name: 'Barracks',
|
name: 'Barracks',
|
||||||
|
maxLevel: 20,
|
||||||
cost: (level: number) => {
|
cost: (level: number) => {
|
||||||
return {
|
return {
|
||||||
wood: level * 100,
|
wood: level * 100,
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import moves from "../moves";
|
import moves from "../moves";
|
||||||
import showBuildingPanel from "../stores/showBuildingPanel";
|
import showBuildingPanel from "../stores/showBuildingPanel";
|
||||||
import { getBuilding } from "../utils";
|
import { getBuilding, getBuildingUpgradeCost } from "../utils";
|
||||||
import village from "../village";
|
import village from "../village";
|
||||||
import BuildingRecruitment from "./BuildingRecruitment.svelte";
|
import BuildingRecruitment from "./BuildingRecruitment.svelte";
|
||||||
|
import Cost from "./Cost.svelte";
|
||||||
|
|
||||||
function close() {
|
function close() {
|
||||||
showBuildingPanel.set(null);
|
showBuildingPanel.set(null);
|
||||||
@ -40,9 +41,19 @@
|
|||||||
{ /if }
|
{ /if }
|
||||||
</div>
|
</div>
|
||||||
<div class="upgrade">
|
<div class="upgrade">
|
||||||
|
{ #if building.state.upgrade.isUpgrading }
|
||||||
|
<p>
|
||||||
|
Upgrading to level { building.level + 1 }
|
||||||
|
({ Math.ceil(building.state.upgrade.remainingTime / 1000) }’)
|
||||||
|
</p>
|
||||||
|
{ :else if building.level === building.maxLevel }
|
||||||
|
<p>Max level reached!</p>
|
||||||
|
{ :else }
|
||||||
<div>
|
<div>
|
||||||
|
<Cost cost={ getBuildingUpgradeCost($village, building) } />
|
||||||
<button on:click={ () => upgrade() }>Upgrade</button>
|
<button on:click={ () => upgrade() }>Upgrade</button>
|
||||||
</div>
|
</div>
|
||||||
|
{ /if }
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
@ -12,6 +12,10 @@ export default function upgradeBuilding(V: VillageState, buildingId: number) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (building.level >= building.maxLevel) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!canPayBuildingCost(V, building)) {
|
if (!canPayBuildingCost(V, building)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ export interface BuildingSource {
|
|||||||
name: string;
|
name: string;
|
||||||
type: string;
|
type: string;
|
||||||
autoBuilt?: boolean;
|
autoBuilt?: boolean;
|
||||||
|
maxLevel: number;
|
||||||
cost: (level: number) => CostType;
|
cost: (level: number) => CostType;
|
||||||
behavior: {
|
behavior: {
|
||||||
production?: Function;
|
production?: Function;
|
||||||
|
Loading…
Reference in New Issue
Block a user