Skip to content

Commit

Permalink
Merge pull request #891 from solaris-games/dev
Browse files Browse the repository at this point in the history
Hotfix for bulk upgrades
  • Loading branch information
SpacialCircumstances authored Jun 7, 2024
2 parents 6080414 + d3b9299 commit 9355dd8
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions server/services/scheduleBuy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class ScheduleBuyService extends EventEmitter {
async buyScheduledInfrastructure(game: Game) {
for (let player of game.galaxy.players) {
if (player.scheduledActions.length == 0) continue;
let currentActions = player.scheduledActions
const currentActions = player.scheduledActions
.filter(a => a.tick == game.state.tick - 1) // Tick number that we just finished
.sort((a, b) => {
// Take the defined priorities
Expand All @@ -51,12 +51,27 @@ export default class ScheduleBuyService extends EventEmitter {

// Loop through all actions to execute them.
for (let action of currentActions) {
if (action.buyType === 'percentageOfCredits') break; // As this is sorted, all next ones will also be of this type
if (action.buyType === 'totalCredits' && action.amount > player.credits) {
// When players schedule actions to spend more credits than they have, we spend all their credits
action.amount = player.credits
// TODO: Better error handling
try {
if (action.buyType === 'percentageOfCredits') {
// As this is sorted, all next ones will also be of this type
break;
}
if (action.buyType === 'totalCredits' && action.amount > player.credits) {
// When players schedule actions to spend more credits than they have, we spend all their credits
action.amount = player.credits
}
const report = await this.starUpgradeService.generateUpgradeBulkReport(game, player, action.buyType, action.infrastructureType, action.amount);
if (report.cost > player.credits) {
// If the player does not have enough credits, we do not buy anything.
break;
}
await this.starUpgradeService.upgradeBulk(game, player, action.buyType, action.infrastructureType, action.amount, false)
} catch (e) {
console.error(e)
}
await this.starUpgradeService.upgradeBulk(game, player, action.buyType, action.infrastructureType, action.amount, false)


}

// We want to make sure that all percentage actions are dealt with with the same starting value.
Expand Down

0 comments on commit 9355dd8

Please sign in to comment.