Skip to content

Commit

Permalink
feat: Heal systems and start with full health
Browse files Browse the repository at this point in the history
  • Loading branch information
Clashsoft committed Jul 30, 2024
1 parent 350e694 commit a500e74
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/game-logic/game-logic.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class GameLogicService {
homeSystem.population = empire.resources.population;
homeSystem.upgrade = 'upgraded';
homeSystem.capacity *= SYSTEM_UPGRADES.upgraded.capacity_multiplier;
homeSystem.health = SYSTEM_UPGRADES.upgraded.health;
if (member?.empire?.homeSystem) {
homeSystem.type = member.empire.homeSystem;
}
Expand Down Expand Up @@ -176,6 +177,8 @@ export class GameLogicService {
this.processDistricts(system, systemUpkeepPaid, popCoverage, empire, systemVariables, aggregates);
this.processBuildings(system, systemUpkeepPaid, popCoverage, empire, systemVariables, aggregates);

this.healSystem(system, empire, systemVariables);

this.deductJoblessUpkeep(system, empire, systemVariables, aggregates);

if (popUpkeepPaid) {
Expand Down Expand Up @@ -293,6 +296,14 @@ export class GameLogicService {
}
}

private healSystem(system: SystemDocument, empire: EmpireDocument, variables: Record<Variable, number>) {
const maxHealth = this.systemLogicService.maxHealthOrDefense(system, empire, 'health', variables);
if (system.health < maxHealth) {
const healingRate = 0.1;
system.health = Math.min(maxHealth, system.health + healingRate * maxHealth);
}
}

private deductJoblessUpkeep(system: SystemDocument, empire: EmpireDocument, variables: Record<Variable, number>, aggregates?: Partial<Record<ResourceName, AggregateResult>>) {
const totalJobs = this.getJobs(system);
const joblessPops = system.population - totalJobs;
Expand Down
2 changes: 1 addition & 1 deletion src/system/system-logic.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class SystemLogicService {
}

const baseValue = relevantVariables[upgradeVariable];
const fortressCount = system.buildings.filter(b => b === 'fortress').length;
const fortressCount = system.buildings.countIf(b => b === 'fortress');
const fortressBonus = fortressCount * relevantVariables[fortressVariable];
const total = baseValue + fortressBonus;
if (aggregate) {
Expand Down

0 comments on commit a500e74

Please sign in to comment.