mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-05-31 09:41: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) {
|
if(income.timeLeft <= 0) {
|
||||||
Engine.log('collection income from ' + source);
|
Engine.log('collection income from ' + source);
|
||||||
if(source == 'thieves') $SM.addStolen(income.stores);
|
if(source == 'thieves') $SM.addStolen(income.stores);
|
||||||
$SM.addM('stores', income.stores, true);
|
|
||||||
changed = true;
|
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') {
|
if(typeof income.delay == 'number') {
|
||||||
income.timeLeft = income.delay;
|
income.timeLeft = income.delay;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user