Fleshed out stub. Added fortify and stub for attack.
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user