Ticket #1839: tribute-insufficient-resources.2.patch
File tribute-insufficient-resources.2.patch, 2.2 KB (added by , 11 years ago) |
---|
-
simulation/components/Player.js
174 174 return amountsNeeded; 175 175 }; 176 176 177 Player.prototype. TrySubtractResources= function(amounts)177 Player.prototype.HasResourcesOrNotify = function(amounts) 178 178 { 179 179 var amountsNeeded = this.GetNeededResources(amounts); 180 180 … … 189 189 cmpGUIInterface.PushNotification(notification); 190 190 return false; 191 191 } 192 else 192 193 // Subtract the resources 194 for (var type in amounts) 193 195 { 196 this.resourceCount[type] -= amounts[type]; 197 } 198 199 return true; 200 }; 201 202 Player.prototype.TrySubtractResources = function(amounts) 203 { 204 var hasResources = this.HasResourcesOrNotify(amounts); 205 206 // If we don't have enough resources, send a notification to the player 207 if (hasResources) 208 { 194 209 // Subtract the resources 195 210 var cmpStatisticsTracker = QueryPlayerIDInterface(this.playerID, IID_StatisticsTracker); 196 for (var type in amounts) 197 { 198 this.resourceCount[type] -= amounts[type]; 199 if (cmpStatisticsTracker) 200 cmpStatisticsTracker.IncreaseResourceUsedCounter(type, amounts[type]); 201 } 211 if (cmpStatisticsTracker) 212 cmpStatisticsTracker.IncreaseResourceUsedCounter(type, amounts[type]); 202 213 } 203 214 204 return true;215 return hasResources; 205 216 }; 206 217 207 218 Player.prototype.GetState = function() … … 533 544 if (this.state != "active" || cmpPlayer.state != "active") 534 545 return; 535 546 536 if ( !this.GetNeededResources(amounts))547 if (this.HasResourcesOrNotify(amounts)) 537 548 { 538 for (var type in amounts)539 this.resourceCount[type] -= amounts[type];540 541 549 cmpPlayer.AddResources(amounts); 542 550 543 551 var total = Object.keys(amounts).reduce(function (sum, type){ return sum + amounts[type]; }, 0); 544 552 var cmpOurStatisticsTracker = QueryPlayerIDInterface(this.playerID, IID_StatisticsTracker); 545 553 if (cmpOurStatisticsTracker) … … 552 560 var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); 553 561 cmpGUIInterface.PushNotification(notification); 554 562 } 555 // else not enough resources... TODO: send gui notification556 563 }; 557 564 558 565 Engine.RegisterComponentType(IID_Player, "Player", Player);