Fix attack and supply distribution rules
This commit is contained in:
@@ -416,10 +416,11 @@ class GameUI {
|
|||||||
this.log(`Victory! Captured cell with strength ${remainingStrength}`, 'victory');
|
this.log(`Victory! Captured cell with strength ${remainingStrength}`, 'victory');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Defender wins
|
// Defender wins - attacker loses all but 1 die
|
||||||
const remainingDefense = defenseRoll - attackRoll;
|
const remainingDefense = defenseRoll - attackRoll;
|
||||||
defender.setStrength(Math.max(1, remainingDefense));
|
defender.setStrength(Math.max(1, remainingDefense));
|
||||||
this.log(`Attack repelled! Defender has ${Math.max(1, remainingDefense)} strength`, 'defeat');
|
attacker.setStrength(1); // Attacker reduced to 1
|
||||||
|
this.log(`Attack repelled! Attacker reduced to 1, Defender has ${Math.max(1, remainingDefense)} strength`, 'defeat');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Move to empty cell - transfer attackStrength (original - 1)
|
// Move to empty cell - transfer attackStrength (original - 1)
|
||||||
@@ -471,19 +472,20 @@ class GameUI {
|
|||||||
|
|
||||||
if (eligibleCells.length === 0 || supply === 0) return;
|
if (eligibleCells.length === 0 || supply === 0) return;
|
||||||
|
|
||||||
// Distribute supply randomly among eligible cells
|
// Distribute supply one by one to random eligible cells
|
||||||
let remainingSupply = supply;
|
let remainingSupply = supply;
|
||||||
while (remainingSupply > 0 && eligibleCells.length > 0) {
|
while (remainingSupply > 0 && eligibleCells.length > 0) {
|
||||||
|
// Pick random cell
|
||||||
const randomCell = eligibleCells[Math.floor(Math.random() * eligibleCells.length)];
|
const randomCell = eligibleCells[Math.floor(Math.random() * eligibleCells.length)];
|
||||||
const currentStrength = randomCell.getStrength();
|
const currentStrength = randomCell.getStrength();
|
||||||
|
|
||||||
if (currentStrength < 48) {
|
if (currentStrength < 48) {
|
||||||
const addStrength = Math.min(remainingSupply, 48 - currentStrength);
|
// Add 1 strength to this cell
|
||||||
const newStrength = currentStrength + addStrength;
|
randomCell.setStrength(currentStrength + 1);
|
||||||
randomCell.setStrength(newStrength);
|
remainingSupply--;
|
||||||
remainingSupply -= addStrength;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove cell from eligible if it's now at max strength
|
||||||
if (randomCell.isMaxStrength()) {
|
if (randomCell.isMaxStrength()) {
|
||||||
eligibleCells.splice(eligibleCells.indexOf(randomCell), 1);
|
eligibleCells.splice(eligibleCells.indexOf(randomCell), 1);
|
||||||
}
|
}
|
||||||
@@ -530,7 +532,8 @@ class GameUI {
|
|||||||
const endTurnBtn = document.getElementById('end-turn-btn');
|
const endTurnBtn = document.getElementById('end-turn-btn');
|
||||||
|
|
||||||
cancelBtn.disabled = !this.selectedCell;
|
cancelBtn.disabled = !this.selectedCell;
|
||||||
endTurnBtn.disabled = !this.hasMoved;
|
// End turn is always enabled
|
||||||
|
endTurnBtn.disabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
log(message, type = '') {
|
log(message, type = '') {
|
||||||
|
|||||||
Reference in New Issue
Block a user