mirror of
https://github.com/wassname/cardsforscience.git
synced 2026-08-02 12:30:06 +08:00
Basic achievements
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
var achievements =
|
||||
{
|
||||
list: [],
|
||||
|
||||
count:
|
||||
{
|
||||
clicks: 0,
|
||||
data: 0,
|
||||
money: 0
|
||||
},
|
||||
|
||||
workers: {},
|
||||
research: {},
|
||||
|
||||
setList: function(list)
|
||||
{
|
||||
achievements.list = list;
|
||||
achievements.list.map(function (item) { // define additional stuff on the objects
|
||||
item.completed = false;
|
||||
item.is_visible = function() {
|
||||
return this.completed;
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
addWorkers: function(list)
|
||||
{
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
achievements.workers[list[i].name] = 0;
|
||||
}
|
||||
},
|
||||
|
||||
addResearch: function(list)
|
||||
{
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
achievements.research[list[i].name] = 0;
|
||||
}
|
||||
},
|
||||
|
||||
update: function(type, subtype, val)
|
||||
{
|
||||
achievements[type][subtype] += val;
|
||||
|
||||
for (var i = 0; i < achievements.list.length; i++) {
|
||||
if (achievements.list[i].type == type &&
|
||||
achievements.list[i].target == subtype &&
|
||||
achievements.list[i].threshold >= achievements[type][subtype]
|
||||
)
|
||||
{
|
||||
achievements.list[i].completed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+15
-1
@@ -31,10 +31,13 @@
|
||||
reputation: 0,
|
||||
money: 0,
|
||||
getGrant: function () {
|
||||
this.money += this.reputation * this.factor.rate; // TODO: adjust factor, 5
|
||||
var addition = this.reputation * this.factor.rate; // TODO: adjust factor
|
||||
this.money += addition;
|
||||
achievements.count.money += addition;
|
||||
},
|
||||
acquire: function(amount) {
|
||||
this.data += amount;
|
||||
achievements.count.data += amount;
|
||||
},
|
||||
research: function(cost, reputation) {
|
||||
if (this.data >= cost) {
|
||||
@@ -55,8 +58,11 @@
|
||||
this.money += cost;
|
||||
}
|
||||
};
|
||||
|
||||
achievements.setList(loadFile('json/achievements.json'));
|
||||
|
||||
var research = loadFile('json/research.json');
|
||||
achievements.addResearch(research);
|
||||
research.map(function(item) {
|
||||
item.level = 0;
|
||||
item.is_visible = function() {
|
||||
@@ -69,6 +75,7 @@
|
||||
if (lab.research(this.cost, this.reputation)) {
|
||||
this.level++;
|
||||
this.cost = Math.round(this.cost * this.cost_increase);
|
||||
achievements.research[this.name]++;
|
||||
}
|
||||
};
|
||||
item.getInfo = function() {
|
||||
@@ -83,6 +90,7 @@
|
||||
});
|
||||
|
||||
var workers = loadFile('json/workers.json');
|
||||
achievements.addWorkers(workers);
|
||||
workers.map(function(worker) {
|
||||
worker.hired = 0;
|
||||
worker.is_visible = function() {
|
||||
@@ -95,6 +103,7 @@
|
||||
if (lab.buy(this.cost)) {
|
||||
this.hired++;
|
||||
this.cost = Math.round(this.cost * this.cost_increase);
|
||||
achievements.update('workers', this.name, 1);
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -183,6 +192,7 @@
|
||||
this.click = function() {
|
||||
lab.acquire(lab.detector.rate);
|
||||
detector.addEvent();
|
||||
achievements.count.clicks += 1;
|
||||
return false;
|
||||
};
|
||||
});
|
||||
@@ -216,4 +226,8 @@
|
||||
app.controller('UpgradesController', function() {
|
||||
this.upgrades = upgrades;
|
||||
});
|
||||
|
||||
app.controller('AchievementsController', function () {
|
||||
this.achievements = achievements.list;
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user