Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AroriaNetwork
GitHub Repository: AroriaNetwork/3kho-backup
Path: blob/main/projects/particle-clicker/js/gameobjects.js
1834 views
1
var GameObjects=function(){"use strict";var t=function(t){if(this.state={},$.extend(this,t),!this.key)throw"Error: GameObject has to have a key!"};t.prototype.loadState=function(t){$.extend(this.state,t)};var e=function(){t.apply(this,[{key:"lab",state:{name:"Give your lab an awesome name!",detector:1,factor:5,data:0,money:0,reputation:0,clicks:0,moneyCollected:0,moneySpent:0,dataCollected:0,dataSpent:0,time:0}}])};(e.prototype=Object.create(t.prototype)).constructor=e,e.prototype.getGrant=function(){var t=this.state.reputation*this.state.factor;return this.state.money+=t,this.state.moneyCollected+=t,t},e.prototype.acquireData=function(t){this.state.data+=t,this.state.dataCollected+=t},e.prototype.clickDetector=function(){this.state.clicks+=1,this.acquireData(this.state.detector)},e.prototype.research=function(t,e){return this.state.data>=t&&(this.state.data-=t,this.state.dataSpent+=t,this.state.reputation+=e,!0)},e.prototype.buy=function(t){return this.state.money>=t&&(this.state.money-=t,this.state.moneySpent+=t,!0)};var s=function(e){t.apply(this,[e]),this.state.level=0,this.state.interesting=!1};(s.prototype=Object.create(t.prototype)).constructor=s,s.prototype.isVisible=function(t){return!!t&&(this.state.level>0||t.state.data>=.5*this.state.cost)},s.prototype.isAvailable=function(t){return!!t&&t.state.data>=this.state.cost},s.prototype.research=function(t){if(t&&t.research(this.state.cost,this.state.reputation)){this.state.level++,this.state.info_levels.length>0&&this.state.level===this.state.info_levels[0]&&(this.state.interesting=!0,this.state.info_levels.splice(0,1));var e=this.state.cost;return this.state.cost=Math.floor(this.state.cost*this.cost_increase),e}return-1},s.prototype.getInfo=function(){return this._info||(this._info=Helpers.loadFile(this.info)),this.state.interesting=!1,this._info};var i=function(e){t.apply(this,[e]),this.state.hired=0};(i.prototype=Object.create(t.prototype)).constructor=i,i.prototype.isVisible=function(t){return!!t&&(this.state.hired>0||t.state.money>=.5*this.state.cost)},i.prototype.isAvailable=function(t){return!!t&&t.state.money>=this.state.cost},i.prototype.hire=function(t){if(t&&t.buy(this.state.cost)){this.state.hired++;var e=this.state.cost;return this.state.cost=Math.floor(e*this.cost_increase),e}return-1},i.prototype.getTotal=function(){return this.state.hired*this.state.rate};var r=function(e){t.apply(this,[e]),this.state.visible=!1,this.state.used=!1};(r.prototype=Object.create(t.prototype)).constructor=r,r.prototype.meetsRequirements=function(t){if(!t)return!1;for(var e=0;e<this.requirements.length;e++){var s=this.requirements[e];if(t[s.key].state[s.property]<s.threshold)return!1}return!0},r.prototype.isAvailable=function(t,e){return!(!t||!e)&&(!this.state.used&&t.state.money>=this.cost&&this.meetsRequirements(e))},r.prototype.isVisible=function(t,e){return!(!t||!e)&&(!(this.state.used||!(this.state.visible||t.state.money>=.5*this.cost&&this.meetsRequirements(e)))&&(this._visible=!0,!0))},r.prototype.buy=function(t,e){if(t&&e&&!this.state.used&&t.buy(this.cost)){for(var s=0;s<this.targets.length;s++){var i=this.targets[s];e[i.key].state[i.property]*=this.factor||1,e[i.key].state[i.property]+=this.constant||0}return this.state.used=!0,this.state.visible=!1,this.cost}return-1};var a=function(e){t.apply(this,[e]),this.state.timeAchieved=null};return(a.prototype=Object.create(t.prototype)).validate=function(t,e,s){return!!this.state.timeAchieved||!!(e.hasOwnProperty(this.targetKey)&&e[this.targetKey].state.hasOwnProperty(this.targetProperty)&&e[this.targetKey].state[this.targetProperty]>=this.threshold)&&(this.state.timeAchieved=t.state.time+(new Date).getTime()-s,UI.showAchievement(this),!0)},a.prototype.isAchieved=function(){return!!this.state.timeAchieved},{Lab:e,Research:s,Worker:i,Upgrade:r,Achievement:a}}();
2
3