Fleshed out stub. Added fortify and stub for attack.

This commit is contained in:
2023-02-13 15:52:17 +00:00
parent d99b5b3373
commit 9ffd43e944
3 changed files with 50 additions and 1 deletions

View File

@ -91,6 +91,55 @@ class Player {
this.turnPhase = PHASE_ATTACK;
}
return false;
} else {
// End turn prematurely.
if (data.action === "END") {
return true;
}
if (this.turnPhase === PHASE_ATTACK && data.action === "ATTACK") {
if (this.attack(data)) {
this.turnPhase = PHASE_FORTIFY;
}
return false;
}
this.turnPhase = PHASE_FORTIFY;
if (data.action === "FORTIFY") {
return this.fortify(data);
}
}
return false;
}
/**
* Process an action which is to attack another region.
*
* @param data Data received via socket
*/
attack(data) {}
/**
* Process an action which is to attack another region.
*
* @param data Data received via socket
*/
fortify(data) {
let sender = Region.getRegion(data.sender);
let receiver = Region.getRegion(data.receiver);
if (
sender.owner === this &&
receiver.owner === this &&
sender.strength > data.strength
) {
receiver.reinforce(data.strength);
sender.strength -= data.strength;
return true;
} else {
return false;
}
}