From 18de4cd0707e142d112e823f5ff5aaf80740439d Mon Sep 17 00:00:00 2001 From: Kevin Dungs Date: Mon, 11 Aug 2014 16:03:59 +0200 Subject: [PATCH] Improved upgrade system. Needs content! --- index.html | 19 +- js/game.js | 1 + js/gameobjects.js | 73 +++--- json/upgrades.json | 574 +++------------------------------------------ mobile.html | 13 +- 5 files changed, 85 insertions(+), 595 deletions(-) diff --git a/index.html b/index.html index 2f13348..c2538ce 100644 --- a/index.html +++ b/index.html @@ -83,7 +83,7 @@
-

Research

+

Research


  • @@ -91,7 +91,8 @@

    {{ r.level > 0 ? r.name : '?????' }} Level {{ r.level }}

    -

    {{ r.description }} Researching it will give you {{ r.reputation | niceNumber }} reputation.

    +

    {{ r.description }}

    +

    Research yields {{ r.reputation | niceNumber }} reputation.

    @@ -136,13 +137,14 @@
    -

    HR

    +

    HR


    • {{ w.name }} {{ w.hired | niceNumber }}

      -

      {{ w.description }} They produce {{ w.rate | niceNumber }} data per second.

      +

      {{ w.description }}

      +

      Produce {{ w.rate | niceNumber }} data per second.

    • @@ -150,14 +152,15 @@
    -

    Upgrades

    +

    Upgrades


      -
    • +
    • -

      {{ u.name }}

      +

      {{ u.name }}

      {{ u.description }}

      - +

      {{ u.effect }}

      +
    diff --git a/js/game.js b/js/game.js index 78555e2..a42cc86 100644 --- a/js/game.js +++ b/js/game.js @@ -94,6 +94,7 @@ this.upgrade = function(upgrade) { if (upgrade.buy()) { achievements.update('count', 'moneyUpgrades', upgrade.cost); + UI.showUpdateValue("#update-funding", upgrade.cost); } } }); diff --git a/js/gameobjects.js b/js/gameobjects.js index dd774e8..9c97b89 100644 --- a/js/gameobjects.js +++ b/js/gameobjects.js @@ -5,6 +5,14 @@ * found in the localStorage. */ var GameObjects = (function() { + var allObjects = { + push: function(key_property, list) { + for (var i = 0; i < list.length; i++) { + this[list[i][key_property]] = list[i]; + } + } + }; + /** Lab */ var labPrototype = { @@ -47,6 +55,7 @@ var GameObjects = (function() { } }; var lab = $.extend({}, labPrototype, ObjectStorage.load('lab')); + allObjects['lab'] = lab; /** Research */ @@ -83,6 +92,7 @@ var GameObjects = (function() { research = research.map(function(item) { return $.extend({}, researchPrototype, item); }); + allObjects.push('name', research); /** Workers @@ -111,58 +121,46 @@ var GameObjects = (function() { workers = workers.map(function(worker) { return $.extend({}, workersPrototype, worker); }); + allObjects.push('name', workers); /** Upgrades */ var upgradesPrototype = { - getReceiver: function() { - if (this.type === "detector") { - return lab.detector; - } else if (this.type === "reputation"){ - return lab.factor; - } else { - var context; - if (this.type === "research") { context = research; } - else if (this.type === "hr") { context = workers; } - else { return null; } - for (var i = 0; i < context.length; i++) { - if (context[i].name === this.receiver) { - return context[i]; - } + _visible: false, + _used: false, + meetsRequirements: function() { + for (var i = 0; i < this.requirements.length; i++) { + var req = this.requirements[i]; + if (allObjects[req.key][req.property] < req.threshold) { + return false; } - return null; } + return true; }, - hasReceiver: function() { - if (this.type === "detector" || this.type === "reputation") { + isAvailable: function() { + if (!this._used && lab.money >= this.cost && this.meetsRequirements()) { return true; } - var rec = this.getReceiver(); - if (this.type === "research") { - return rec.level > 0; - } else if (this.type === "hr") { - return rec.hired > 0; - } return false; }, - is_visible: function() { - return !this.used && this.hasReceiver() && lab.money >= this.cost * .7; - }, - is_available: function() { - return !this.used && this.hasReceiver() && lab.money >= this.cost; + isVisible: function() { + if (!this._used && (this._visible || lab.money >= this.cost * .7 && this.meetsRequirements())) { + this._visible = true; + return true; + } + return false; }, buy: function() { - if (!this.used && lab.buy(this.cost)) { - this.used = true; - analytics.sendEvent(analytics.events.categoryUpgrades, analytics.events.actionBuy, this.name, 1); - var rec = this.getReceiver(); - if (rec) { - rec[this.property] = rec[this.property] * this.factor + this.constant; + if (!this._used && lab.buy(this.cost)) { + for (var i = 0; i < this.targets.length; i++) { + var t = this.targets[i]; + allObjects[t.key][t.property] *= this.factor || 1; + allObjects[t.key][t.property] += this.constant || 0; } - return true; + this._used = true; + this._visible = false; } - return false; } }; var upgrades = $.extend([], Helpers.loadFile('json/upgrades.json'), @@ -170,6 +168,7 @@ var GameObjects = (function() { upgrades = upgrades.map(function(upgrade) { return $.extend({}, upgradesPrototype, upgrade); }); + allObjects.push('name', upgrades); /** Save all the game objects at once. @@ -187,6 +186,6 @@ var GameObjects = (function() { research: research, workers: workers, upgrades: upgrades, - saveAll: saveAll + saveAll: saveAll, } })(); diff --git a/json/upgrades.json b/json/upgrades.json index 0e918ec..78337ea 100644 --- a/json/upgrades.json +++ b/json/upgrades.json @@ -1,556 +1,40 @@ [ { - "name": "Free beer", - "description": "The work is easier when the worker is happy. Your PhD Students will produce +2 data.", - "cost": 1000, - "used": false, - "type": "hr", - "receiver": "PhD Students", - "property": "rate", - "factor": 1, - "constant": 2 - }, - { - "name": "Extra coffee", - "description": "Sleeping is the coffee of the weak. Your PhD Students will produce 1.3 times more data.", - "cost": 3000, - "used": false, - "type": "hr", - "receiver": "PhD Students", - "property": "rate", - "factor": 1.5, - "constant": 0 - }, - { - "name": "Motivation", - "description": "There are other, you know... more diligent Students... Your PhD Students will produce 2 times more data.", - "cost": 10000, - "used": false, - "type": "hr", - "receiver": "PhD Students", - "property": "rate", + "name": "Thesis supervision", + "description": "Somebody takes care of your PhD Students.", + "effect": "PhD Students produce twice as much data per second.", + "icon": "fa-group", + "cost": 100, + "targets": [{"key": "PhD Students", "property": "rate"}], + "requirements": [{"key": "PhD Students", "property": "hired", "threshold": 1}], "factor": 2, "constant": 0 }, { - "name": "Division of labor", - "description": "Teamwork between PhD Students is a great invention. Your PhD Students will produce much more data.", - "cost": 175000, - "used": false, - "type": "hr", - "receiver": "PhD Students", - "property": "rate", - "factor": 3, - "constant": 3 - }, - - { - "name": "Free beer", - "description": "The work is easier when the worker is happy. Your Postdocs will produce +4 data.", - "cost": 5000, - "used": false, - "type": "hr", - "receiver": "Postdocs", - "property": "rate", - "factor": 1, - "constant": 4 - }, - { - "name": "Extra coffee", - "description": "Sleeping is the coffee of the weak. Your Postdocs will produce 1.5 times more data.", - "cost": 20000, - "used": false, - "type": "hr", - "receiver": "Postdocs", - "property": "rate", - "factor": 1.5, - "constant": 0 - }, - - { - "name": "Motivation", - "description": "There are other, you know... more diligent Postdocs... Your Postdocs will produce 2 times more data.", - "cost": 500000, - "used": false, - "type": "hr", - "receiver": "Postdocs", - "property": "rate", - "factor": 2, - "constant": 0 - }, - - { - "name": "Division of labor", - "description": "Teamwork between Postdocs is a great invention. Your Postdocs will produce much more data.", - "cost": 2000000, - "used": false, - "type": "hr", - "receiver": "Postdocs", - "property": "rate", - "factor": 1.5, - "constant": 18 - }, - - { - "name": "Increased budget", - "description": "Your Research Fellows get a little more money. They will produce +25 more data.", - "cost": 200000, - "used": false, - "type": "hr", - "receiver": "Research Fellows", - "property": "rate", - "factor": 1, - "constant": 25 - }, - - { - "name": "New gadgets", - "description": "Your Research Fellows receive new techs. They will produce 1.2 times more data.", - "cost": 800000, - "used": false, - "type": "hr", - "receiver": "Research Fellows", - "property": "rate", - "factor": 1.2, - "constant": 0 - }, - - { - "name": "More PhD Students", - "description": "Your Mighty Professors get some Students to work. They will produce +75 more data.", - "cost": 20000000, - "used": false, - "type": "hr", - "receiver": "Tenured Professors", - "property": "rate", - "factor": 1, - "constant": 75 - }, - - { - "name": "2. Nobel Prize", - "description": "So your Brightest Minds are now demigods... They will produce 1.7 times more data.", - "cost": 100000000, - "used": false, - "type": "hr", - "receiver": "Nobel Prize Winners", - "property": "rate", - "factor": 1.7, - "constant": 0 - }, - - { - "name": "Accelerator upgrade", - "description": "Increases the luminosity (you get 3 times more data with clicks).", - "cost": 1000, - "used": false, - "type": "detector", - "receiver": "", - "property": "rate", - "factor": 3, - "constant": 0 - }, - - { - "name": "Accelerator upgrade 2", - "description": "Increases the luminosity (you get 3 times more data with clicks).", + "name": "Own desk", + "description": "Not having to share one is a blessing.", + "effect": "PhD Students produce twice as much data per second.", + "icon": "fa-group", "cost": 10000, - "used": false, - "type": "detector", - "receiver": "", - "property": "rate", - "factor": 3, - "constant": 0 - }, - - { - "name": "Accelerator upgrade 3", - "description": "Increases the luminosity (you get 3 times more data with clicks).", - "cost": 100000, - "used": false, - "type": "detector", - "receiver": "", - "property": "rate", - "factor": 3, - "constant": 0 - }, - - { - "name": "Detector upgrade", - "description": "Your amazing detector works with better efficiency (you get +4 data with clicks).", - "cost": 500, - "used": false, - "type": "detector", - "receiver": "detector", - "property": "rate", - "factor": 1, - "constant": 4 - }, - - { - "name": "Detector upgrade 2", - "description": "Your amazing detector works with better efficiency (you get +12 data with clicks).", - "cost": 5000, - "used": false, - "type": "detector", - "receiver": "", - "property": "rate", - "factor": 1, - "constant": 12 - }, - - { - "name": "Detector upgrade 3", - "description": "Your amazing detector works with better efficiency (you get +42 data with clicks).", - "cost": 50000, - "used": false, - "type": "detector", - "receiver": "detector", - "property": "rate", - "factor": 1, - "constant": 42 - }, - - { - "name": "Public Relations, lvl 1", - "description": "Mainstream press writes about your research of the CP violation. Future research yields 1.2 times more reputation.", - "cost": 5000, - "used": false, - "type": "research", - "receiver": "CP violation", - "property": "reputation", - "factor": 1.2, - "constant": 1 - }, - - { - "name": "Science is cool!! lvl 1", - "description": "Because your science is so popular, you get 1.1 times more money for your reputation.", - "cost": 700, - "used": false, - "type": "reputation", - "receiver": "", - "property": "rate", - "factor": 1.2, - "constant": 0 - }, - - { - "name": "Science is cool!! lvl 2", - "description": "Because your science is so popular, you get 1.1 times more money for your reputation.", - "cost": 50000, - "used": false, - "type": "reputation", - "receiver": "", - "property": "rate", - "factor": 1.18, - "constant": 0 - }, - - { - "name": "Science is cool!! lvl 3", - "description": "Because your science is so popular, you get 1.1 times more money for your reputation.", - "cost": 200000, - "used": false, - "type": "reputation", - "receiver": "", - "property": "rate", - "factor": 1.16, - "constant": 0 - }, - - { - "name": "Science is cool!! lvl 4", - "description": "Because your science is so popular, you get 1.1 times more money for your reputation.", - "cost": 800000, - "used": false, - "type": "reputation", - "receiver": "", - "property": "rate", - "factor": 1.14, - "constant": 0 - }, - - { - "name": "Science is cool!! lvl 5", - "description": "Because your science is so popular, you get 1.1 times more money for your reputation.", - "cost": 1200000, - "used": false, - "type": "reputation", - "receiver": "", - "property": "rate", - "factor": 1.12, - "constant": 0 - }, - - { - "name": "Science is cool!! lvl 6", - "description": "Because your science is so popular, you get 1.1 times more money for your reputation.", - "cost": 1800000, - "used": false, - "type": "reputation", - "receiver": "", - "property": "rate", - "factor": 1.12, - "constant": 0 - }, - - { - "name": "Science is cool!! lvl 7", - "description": "Because your science is so popular, you get 1.1 times more money for your reputation.", - "cost": 3000000, - "used": false, - "type": "reputation", - "receiver": "", - "property": "rate", - "factor": 1.12, - "constant": 0 - }, - - { - "name": "Science is cool!! lvl 8", - "description": "Because your science is so popular, you get 1.1 times more money for your reputation.", - "cost": 10000000, - "used": false, - "type": "reputation", - "receiver": "", - "property": "rate", - "factor": 1.12, - "constant": 0 - }, - - { - "name": "Public Relations, lvl 1", - "description": "Mainstream press writes about your research of the CP violation. Future research yields 1.2 times more reputation.", - "cost": 5000, - "used": false, - "type": "research", - "receiver": "CP violation", - "property": "reputation", - "factor": 1.2, - "constant": 1 - }, - - { - "name": "Public Relations, lvl 2", - "description": "Mainstream press writes about your research of the CP violation. Future research yields 1.2 times more reputation.", - "cost": 100000, - "used": false, - "type": "research", - "receiver": "CP violation", - "property": "reputation", - "factor": 1.2, - "constant": 1 - }, - - { - "name": "Public Relations, lvl 1", - "description": "Your research on J/ψ is featured on national television. Future research yields 1.2 times more reputation.", - "cost": 40000, - "used": false, - "type": "research", - "receiver": "J/ψ", - "property": "reputation", - "factor": 1.2, - "constant": 1 - }, - - { - "name": "Public Relations, lvl 2", - "description": "Your research on J/ψ is featured on national television. Future research yields 1.2 times more reputation.", - "cost": 130000, - "used": false, - "type": "research", - "receiver": "J/ψ", - "property": "reputation", - "factor": 1.2, - "constant": 1 - }, - - { - "name": "Public Relations, lvl 1", - "description": "In a scientific documentary you speak about the τ lepton. Future research yields 1.2 times more reputation.", - "cost": 100000, - "used": false, - "type": "research", - "receiver": "τ lepton", - "property": "reputation", - "factor": 1.2, - "constant": 1 - }, - - { - "name": "Public Relations, lvl 2", - "description": "In a scientific documentary you speak about the τ lepton. Future research yields 1.2 times more reputation.", - "cost": 250000, - "used": false, - "type": "research", - "receiver": "τ lepton", - "property": "reputation", - "factor": 1.2, - "constant": 1 - }, - - { - "name": "Public Relations, lvl 1", - "description": "You just discovered the most beautiful quark ever! Future research yields 1.2 times more reputation.", - "cost": 100000, - "used": false, - "type": "research", - "receiver": "Beauty quark", - "property": "reputation", - "factor": 1.2, - "constant": 1 - }, - - { - "name": "Public Relations, lvl 2", - "description": "You discovered the most beautiful quark ever! Future research yields 1.2 times more reputation.", - "cost": 500000, - "used": false, - "type": "research", - "receiver": "Beauty quark", - "property": "reputation", - "factor": 1.2, - "constant": 1 - }, - - { - "name": "Public Relations, lvl 1", - "description": "You give lectures about this very important part of the Standard Model! Future research yields 1.2 times more reputation.", - "cost": 250000, - "used": false, - "type": "research", - "receiver": "W and Z boson", - "property": "reputation", - "factor": 1.2, - "constant": 1 - }, - - { - "name": "Public Relations, lvl 2", - "description": "You give lectures about this very important part of the Standard Model! Future research yields 1.2 times more reputation.", - "cost": 1000000, - "used": false, - "type": "research", - "receiver": "W and Z boson", - "property": "reputation", - "factor": 1.2, - "constant": 1 - }, - - { - "name": "Public Relations, lvl 1", - "description": "This is the top of your career! Future research yields 1.2 times more reputation.", - "cost": 5000000, - "used": false, - "type": "research", - "receiver": "Top quark", - "property": "reputation", - "factor": 1.2, - "constant": 1 + "targets": [{"key": "PhD Students", "property": "rate"}], + "requirements": [{"key": "Thesis supervision", "property": "_used", "threshold": 1}], + "factor": 2 }, { - "name": "Public Relations, lvl 2", - "description": "This is the top of your career! Future research yields 1.2 times more reputation.", - "cost": 7500000, - "used": false, - "type": "research", - "receiver": "Top quark", - "property": "reputation", - "factor": 1.2, - "constant": 1 - }, - - { - "name": "Public Relations, lvl 1", - "description": "Hollywood makes a movie about the antihydrogen. Your future research yields 1.2 times more reputation.", - "cost": 22500000, - "used": false, - "type": "research", - "receiver": "Antihydrogen", - "property": "reputation", - "factor": 1.2, - "constant": 1 - }, - - { - "name": "Public Relations, lvl 2", - "description": "Hollywood makes a movie about the antihydrogen. Your future research yields 1.2 times more reputation.", - "cost": 40000000, - "used": false, - "type": "research", - "receiver": "Antihydrogen", - "property": "reputation", - "factor": 1.2, - "constant": 1 - }, - - { - "name": "Public Relations, lvl 1", - "description": "Your little daughter writes about your research on B oscillations in her homework. Future research yields 1.2 times more reputation.", - "cost": 75000000, - "used": false, - "type": "research", - "receiver": "B oscillations", - "property": "reputation", - "factor": 1.2, - "constant": 1 - }, - - { - "name": "Public Relations, lvl 2", - "description": "Your little daughter writes about your research on B oscillations in her homework. Future research yields 1.2 times more reputation.", - "cost": 90000000, - "used": false, - "type": "research", - "receiver": "B oscillations", - "property": "reputation", - "factor": 1.2, - "constant": 1 - }, - { - "name": "Public Relations, lvl 1", - "description": "You know more about Top quark than everybody else. Future research yields 1.2 times more reputation.", - "cost": 50000000, - "used": false, - "type": "research", - "receiver": "Top quark", - "property": "reputation", - "factor": 1.2, - "constant": 1 - }, - { - "name": "Public Relations, lvl 2", - "description": "You know more about Top quark then everybody else. Future research yields 1.2 times more reputation.", - "cost": 120000000, - "used": false, - "type": "research", - "receiver": "Top quark", - "property": "reputation", - "factor": 1.2, - "constant": 1 - }, - { - "name": "Public Relations, lvl 1", - "description": "You've found the last missing element of the Standard Model! Future research yields 1.2 times more reputation.", - "cost": 90000000, - "used": false, - "type": "research", - "receiver": "Higgs boson", - "property": "reputation", - "factor": 1.2, - "constant": 1 - }, - { - "name": "Public Relations, lvl 2", - "description": "You've found the last missing element of the Standard Model! Future research yields 1.2 times more reputation.", - "cost": 110000000, - "used": false, - "type": "research", - "receiver": "Higgs boson", - "property": "reputation", - "factor": 1.2, - "constant": 1 + "name": "Free coffee", + "description": "Addictively delicious. Also free.", + "effect": "All workers produce twice as much data per second.", + "icon": "fa-group", + "cost": 1e6, + "targets": [ + {"key": "PhD Students", "property": "rate"}, + {"key": "Postdocs", "property": "rate"}, + {"key": "Research Fellows", "property": "rate"}, + {"key": "Tenured Professors", "property": "rate"}, + {"key": "Nobel Prize Winners", "property": "rate"}, + {"key": "Summer Students", "property": "rate"} + ], + "requirements": [], + "factor": 2 } ] diff --git a/mobile.html b/mobile.html index cddfb7e..f1ffb04 100644 --- a/mobile.html +++ b/mobile.html @@ -54,7 +54,8 @@

    {{ r.level > 0 ? r.name : '?????' }} Level {{ r.level }}

    -

    {{ r.description }} Researching it will give you {{ r.reputation | niceNumber }} reputation.

    +

    {{ r.description }}

    +

    Research yields {{ r.reputation | niceNumber }} reputation.

    @@ -69,7 +70,8 @@
  • {{ w.name }} {{ w.hired | niceNumber }}

    -

    {{ w.description }} They produce {{ w.rate | niceNumber }} data per second.

    +

    {{ w.description }}

    +

    Produce {{ w.rate | niceNumber }} data per second.

  • @@ -78,11 +80,12 @@
      -
    • +
    • -

      {{ u.name }}

      +

      {{ u.name }}

      {{ u.description }}

      - +

      {{ u.effect }}

      +