浏览代码

Standard upgrades (prod/prod-all) are now automatically generated.

tags/v0.0.1
Fen Dweller 7 年前
父节点
当前提交
6d27837766
找不到此签名对应的密钥 GPG 密钥 ID: E80B35A6F11C3656
共有 2 个文件被更改,包括 191 次插入235 次删除
  1. +138
    -211
      constants.js
  2. +53
    -24
      gorge.js

+ 138
- 211
constants.js 查看文件

@@ -24,91 +24,91 @@ const buildings = {
"name": "Car", "name": "Car",
"plural": "Cars", "plural": "Cars",
"desc": "Crunchy shell, tasty center.", "desc": "Crunchy shell, tasty center.",
"cost": 1e3,
"cost": 1.2e3,
"prod": 1e1/1.2 "prod": 1e1/1.2
}, },
"bus": { "bus": {
"name": "Bus", "name": "Bus",
"plural": "Buses", "plural": "Buses",
"desc": "Probably the worst place to be when a macro is aroud.", "desc": "Probably the worst place to be when a macro is aroud.",
"cost": 1e4,
"cost": 1.4e4,
"prod": 1e2/1.3 "prod": 1e2/1.3
}, },
"house": { "house": {
"name": "House", "name": "House",
"plural": "Houses", "plural": "Houses",
"desc": "Home sweet home - but it doesn't taste sweet?", "desc": "Home sweet home - but it doesn't taste sweet?",
"cost": 1e5,
"cost": 1.6e5,
"prod": 1e3/1.4 "prod": 1e3/1.4
}, },
"apartment": { "apartment": {
"name": "Apartment", "name": "Apartment",
"plural": "Apartments", "plural": "Apartments",
"desc": "More snacks, less packaging.", "desc": "More snacks, less packaging.",
"cost": 1e6,
"cost": 1.8e6,
"prod": 1e4/1.5 "prod": 1e4/1.5
}, },
"block": { "block": {
"name": "Block", "name": "Block",
"plural": "Blocks", "plural": "Blocks",
"desc": "A whole pile of buildings.", "desc": "A whole pile of buildings.",
"cost": 1e7,
"cost": 2e7,
"prod": 1e5/1.6 "prod": 1e5/1.6
}, },
"town": { "town": {
"name": "Town", "name": "Town",
"plural": "Towns", "plural": "Towns",
"desc": "'Tourist trap' has never been this literal.", "desc": "'Tourist trap' has never been this literal.",
"cost": 1e8,
"cost": 2.2e8,
"prod": 1e6/1.7 "prod": 1e6/1.7
}, },
"city": { "city": {
"name": "City", "name": "City",
"plural": "Cities", "plural": "Cities",
"desc": "Please no sitty on our city.", "desc": "Please no sitty on our city.",
"cost": 1e9,
"cost": 2.4e9,
"prod": 1e7/1.8 "prod": 1e7/1.8
}, },
"metro": { "metro": {
"name": "Metropolis", "name": "Metropolis",
"plural": "Metropolises", "plural": "Metropolises",
"desc": "A big ol' city. Tasty, too.", "desc": "A big ol' city. Tasty, too.",
"cost": 1e10,
"cost": 2.6e10,
"prod": 1e8/1.9 "prod": 1e8/1.9
}, },
"county": { "county": {
"name": "County", "name": "County",
"plural": "Counties", "plural": "Counties",
"desc": "Why salt the land when you can slurp it?", "desc": "Why salt the land when you can slurp it?",
"cost": 1e11,
"cost": 2.8e11,
"prod": 1e9/2 "prod": 1e9/2
}, },
"state": { "state": {
"name": "State", "name": "State",
"plural": "States", "plural": "States",
"desc": "The United States is made up of...43 states - no, 42...", "desc": "The United States is made up of...43 states - no, 42...",
"cost": 1e12,
"cost": 3e12,
"prod": 1e10/2.1 "prod": 1e10/2.1
}, },
"country": { "country": {
"name": "Country", "name": "Country",
"plural": "Countries", "plural": "Countries",
"desc": "One nation, under paw.", "desc": "One nation, under paw.",
"cost": 1e13,
"cost": 3.2e13,
"prod": 1e11/2.2 "prod": 1e11/2.2
}, },
"continent": { "continent": {
"name": "Continent", "name": "Continent",
"plural": "Continents", "plural": "Continents",
"desc": "Earth-shattering appetite!", "desc": "Earth-shattering appetite!",
"cost": 1e14,
"cost": 3.4e14,
"prod": 1e12/2.3 "prod": 1e12/2.3
}, },
"planet": { "planet": {
"name": "Planet", "name": "Planet",
"plural": "Planets", "plural": "Planets",
"desc": "Earth appetite!", "desc": "Earth appetite!",
"cost": 1e15,
"cost": 3.6e15,
"prod": 1e13/2.4 "prod": 1e13/2.4
} }
} }
@@ -140,83 +140,23 @@ const effect_types = {
} }
} }


const upgrades = {
"micro-prod-1": {
"name": "Bigger Micros",
"desc": "A macro micro? Certainly more filling.",
let upgrades = {
"car-prod-1": {
"name": "High Occupancy Vehicles",
"desc": "Think of the environment! Think of the gigantic monster's hunger!",
"cost": { "cost": {
"food": buildings.micro.cost * 10
"food": buildings.car.cost * 5
}, },
"effects": [ "effects": [
{ {
"type": "prod", "type": "prod",
"target": "micro",
"target": "car",
"amount": 2, "amount": 2,
} }
], ],
"prereqs": { "prereqs": {
"buildings": { "buildings": {
"micro": 1
}
}
},
"micro-prod-2": {
"name": "Beefy Micros",
"desc": "25% more protein, 10% fewer carbs.",
"cost": {
"food": buildings.micro.cost * 50
},
"effects": [
{
"type": "prod",
"target": "micro",
"amount": 2.25,
}
],
"prereqs": {
"buildings": {
"micro": 5
},
"upgrades": [
"micro-prod-1"
]
}
},
"anthro-prod-1": {
"name": "Willing Prey",
"desc": "Why bother chasing it down?",
"cost": {
"food": buildings.anthro.cost * 5
},
"effects": [
{
"type": "prod",
"target": "anthro",
"amount": 2,
}
],
"prereqs": {
"buildings": {
"anthro": 1
}
}
},
"anthro-prod-2": {
"name": "Mesmerized Prey",
"desc": "Why bother walking over to it?",
"cost": {
"food": buildings.anthro.cost * 50
},
"effects": [
{
"type": "prod",
"target": "anthro",
"amount": 2.25,
}
],
"prereqs": {
"buildings": {
"anthro": 10
"car": 10
}, },
"upgrades": [ "upgrades": [
"anthro-prod-1" "anthro-prod-1"
@@ -245,149 +185,136 @@ const upgrades = {
"anthro-prod-1" "anthro-prod-1"
] ]
} }
},
"prod-1": {
"name": "Sloth Metabolism",
"desc": "Burn those calories. Eventually.",
"cost": {
"food": 5e2
},
"effects": [
{
"type": "prod-all",
"amount": 1.05
}

}

function createTemplateUpgrades() {
console.log("qwewq");
createProdUpgrades();
createProdAllUpgrades();
}

function createProdUpgrades() {
for (const [key, value] of Object.entries(prodUpgradeText)) {
let counter = 1;
let prefix = key + "-prod-";
for (let contents of value) {
upgrades[prefix + counter] = {
"name": contents.name,
"desc": contents.desc,
"cost": {
"food": buildings[key].cost * 5 * Math.pow(10,counter)
},
"effects": [
{
"type": "prod",
"amount": 2 + (counter - 1) * 0.25,
"target": key
}
]
};

if (counter > 1) {
upgrades[prefix + counter]["prereqs"] = {
"upgrades": [
prefix + (counter - 1)
]
};
} }
],
"prereqs": {
"productivity": {
"food": 1e1

counter += 1;
}
}
}

function createProdAllUpgrades() {
let prefix = "prod-all-"

let counter = 1;

for (let contents of prodAllUpgradeText) {
upgrades[prefix + counter] = {
"name": contents.name,
"desc": contents.desc,
"cost": {
"food": 5 * Math.pow(10, counter+1)
},
"effects": [
{
"type": "prod-all",
"amount": 1.05
}
],
"prereqs": {
"productivity": {
"food": Math.pow(10, counter)
}
} }
};

if (counter > 1) {
upgrades[prefix + counter]["prereqs"].upgrades = [
prefix + (counter - 1)
];
}
}
}

let prodUpgradeText = {
"micro": [
{
"name": "Bigger Micros",
"desc": "A macro micro? It's more filling, for sure.",
}, },
},
"prod-2": {
"name": "Decent Metabolism",
"desc": "Picking up the pace.",
"cost": {
"food": 5e3
{
"name": "Beefy Micros",
"desc": "25% more protein, 10% fewer carbs."
}, },
"effects": [
{
"type": "prod-all",
"amount": 1.05
}
],
"prereqs": {
"productivity": {
"food": 1e2
},
"upgrades": [
"prod-1"
]
{
"name": "Delicious Micros",
"desc": "Betcha' can't eat just one."
}
],
"anthro": [
{
"name": "Willing Prey",
"desc": "Why bother chasing down your meal?"
}, },
{
"name": "Mesmerized Prey",
"desc": "Why bother walking to your meal?"
}
],
}

let prodAllUpgradeText = [
{
"name": "Sloth Metabolism",
"desc": "Burn those calories. Eventually."
},
{
"name": "Decent Metabolism",
"desc": "Picking up the pace."
}, },
"prod-3": {
{
"name": "Perky Metabolism", "name": "Perky Metabolism",
"desc": "Sweat a little.",
"cost": {
"food": 5e4
},
"effects": [
{
"type": "prod-all",
"amount": 1.05
}
],
"prereqs": {
"productivity": {
"food": 1e3
},
"upgrades": [
"prod-2"
]
},
"desc": "Sweat a little."
}, },
"prod-4": {
{
"name": "Quick Metabolism", "name": "Quick Metabolism",
"desc": "Burn those calories.",
"cost": {
"food": 5e5
},
"effects": [
{
"type": "prod-all",
"amount": 1.05
}
],
"prereqs": {
"productivity": {
"food": 1e4
},
"upgrades": [
"prod-3"
]
},
"desc": "Burn those calories."
}, },
"prod-5": {
{
"name": "Speedy Metabolism", "name": "Speedy Metabolism",
"desc": "More prey, more power.",
"cost": {
"food": 5e6
},
"effects": [
{
"type": "prod-all",
"amount": 1.05
}
],
"prereqs": {
"productivity": {
"food": 1e5
},
"upgrades": [
"prod-4"
]
},
"desc": "More prey, more power."
}, },
"prod-6": {
{
"name": "Fast Metabolism", "name": "Fast Metabolism",
"desc": "You're a furnace.",
"cost": {
"food": 5e7
},
"effects": [
{
"type": "prod-all",
"amount": 1.05
}
],
"prereqs": {
"productivity": {
"food": 1e6
},
"upgrades": [
"prod-5"
]
},
"desc": "You're a furnace. Fueled by people."
}, },
"prod-7": {
{
"name": "Powerful Metabolism", "name": "Powerful Metabolism",
"desc": "Digest them all.",
"cost": {
"food": 5e8
},
"effects": [
{
"type": "prod-all",
"amount": 1.05
}
],
"prereqs": {
"productivity": {
"food": 1e7
},
"upgrades": [
"prod-6"
]
},
},
}
"desc": "Digest them all."
}
]

+ 53
- 24
gorge.js 查看文件

@@ -227,6 +227,13 @@ function eatMicro() {
// we'll initialize the dict of buildings we can own // we'll initialize the dict of buildings we can own


function setup() { function setup() {

// create static data

createTemplateUpgrades();

// prepare dynamic stuff

initializeData(); initializeData();
createButtons(); createButtons();
createDisplays(); createDisplays();
@@ -339,23 +346,26 @@ function upgradeReachable(id) {
return false; return false;
} }


for (const [type, reqs] of Object.entries(upgrades[id].prereqs)) {
if (type == "buildings") {
for (const [building, amount] of Object.entries(reqs)) {
if (belongings[building].count == 0) {
return false;
if (upgrades[id].prereqs !== undefined ){
for (const [type, reqs] of Object.entries(upgrades[id].prereqs)) {
if (type == "buildings") {
for (const [building, amount] of Object.entries(reqs)) {
if (belongings[building].count == 0) {
return false;
}
} }
} }
}
else if (type == "upgrades") {
for (let upgrade of reqs) {
if (!ownedUpgrades[upgrade]) {
return false;
else if (type == "upgrades") {
for (let upgrade of reqs) {
if (!ownedUpgrades[upgrade]) {
return false;
}
} }
} }
} }
} }



return true; return true;
} }
function upgradeAvailable(id) { function upgradeAvailable(id) {
@@ -367,22 +377,25 @@ function upgradeAvailable(id) {
return false; return false;
} }


for (const [type, reqs] of Object.entries(upgrades[id].prereqs)) {
if (type == "buildings") {
for (const [building, amount] of Object.entries(upgrades[id].prereqs[type])) {
if (belongings[building].count < amount) {
return false;
if (upgrades[id].prereqs !== undefined) {
for (const [type, reqs] of Object.entries(upgrades[id].prereqs)) {
if (type == "buildings") {
for (const [building, amount] of Object.entries(upgrades[id].prereqs[type])) {
if (belongings[building].count < amount) {
return false;
}
} }
}
} else if (type == "productivity") {
for (const [key, value] of Object.entries(reqs)) {
if (currentProductivity[key] < value) {
return false;
} else if (type == "productivity") {
for (const [key, value] of Object.entries(reqs)) {
if (currentProductivity[key] < value) {
return false;
}
} }
} }
} }
} }



return true; return true;
} }


@@ -465,6 +478,10 @@ function renderCost(cost) {
function renderPrereqs(prereqs) { function renderPrereqs(prereqs) {
let list = []; let list = [];


if (prereqs === undefined) {
return renderLines(list);
}
list.push({ list.push({
"text": "Own:" "text": "Own:"
}); });
@@ -562,7 +579,7 @@ function buildingTooltip(id, event) {


fillTooltip("building", "name", buildings[id].name); fillTooltip("building", "name", buildings[id].name);
fillTooltip("building", "desc", buildings[id].desc); fillTooltip("building", "desc", buildings[id].desc);
fillTooltip("building", "cost", costOfBuilding(id) + " food");
fillTooltip("building", "cost", render(costOfBuilding(id)) + " food");
fillTooltip("building", "prod", prodSummary(id)); fillTooltip("building", "prod", prodSummary(id));


let yOffset = tooltip.parentElement.getBoundingClientRect().y; let yOffset = tooltip.parentElement.getBoundingClientRect().y;
@@ -606,11 +623,23 @@ function load() {
return; return;
} }


ownedUpgrades = JSON.parse(storage.getItem("ownedUpgrades"));
let newOwnedUpgrades = JSON.parse(storage.getItem("ownedUpgrades"));

for (const [key, value] of Object.entries(newOwnedUpgrades)) {
ownedUpgrades[key] = value;
}


resources = JSON.parse(storage.getItem("resources"));
let newResources = JSON.parse(storage.getItem("resources"));


belongings = JSON.parse(storage.getItem("belongings"));
for (const [key, value] of Object.entries(newResources)) {
resources[key] = value;
}

let newBelongings = JSON.parse(storage.getItem("belongings"));

for (const [key, value] of Object.entries(newBelongings)) {
belongings[key] = value;
}
} }


function reset() { function reset() {


正在加载...
取消
保存