mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-05-28 00:01:54 +08:00
stop creating income without enough resources
Fix issue where there worker created income without enough resources available.
This commit is contained in:
+14
-3
@@ -342,9 +342,20 @@ var StateManager = {
|
||||
|
||||
if(income.timeLeft <= 0) {
|
||||
Engine.log('collection income from ' + source);
|
||||
if(source == 'thieves') $SM.addStolen(income.stores);
|
||||
$SM.addM('stores', income.stores, true);
|
||||
changed = true;
|
||||
if(source == 'thieves') $SM.addStolen(income.stores);
|
||||
|
||||
var cost = income.stores;
|
||||
var ok = true;
|
||||
for(var k in cost) {
|
||||
var have = $SM.get('stores["'+k+'"]', true);
|
||||
if(have + cost[k] < 0) {
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
if(ok){
|
||||
$SM.addM('stores', income.stores, true);
|
||||
}
|
||||
changed = true;
|
||||
if(typeof income.delay == 'number') {
|
||||
income.timeLeft = income.delay;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user