mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-30 16:52:27 +00:00
Add random shell damage (#1665)
Closes #555 ## Description: Added random damage for warship shells and defence posts. Damage mapping: roll 1-5 → 200, 225, 250, 275, 300 damage respectively. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I have read and accepted the CLA agreement (only required once). ## Please put your Discord username so you can be contacted if a bug or regression is found: kipstzz
This commit is contained in:
@@ -9,6 +9,7 @@ export class ShellExecution implements Execution {
|
||||
private shell: Unit | undefined;
|
||||
private mg: Game;
|
||||
private destroyAtTick: number = -1;
|
||||
private random: PseudoRandom;
|
||||
|
||||
constructor(
|
||||
private spawn: TileRef,
|
||||
@@ -20,6 +21,7 @@ export class ShellExecution implements Execution {
|
||||
init(mg: Game, ticks: number): void {
|
||||
this.pathFinder = new AirPathFinder(mg, new PseudoRandom(mg.ticks()));
|
||||
this.mg = mg;
|
||||
this.random = new PseudoRandom(mg.ticks());
|
||||
}
|
||||
|
||||
tick(ticks: number): void {
|
||||
@@ -61,7 +63,16 @@ export class ShellExecution implements Execution {
|
||||
|
||||
private effectOnTarget(): number {
|
||||
const { damage } = this.mg.config().unitInfo(UnitType.Shell);
|
||||
return damage ?? 0;
|
||||
const baseDamage = damage ?? 250;
|
||||
|
||||
const roll = this.random.nextInt(1, 6);
|
||||
const damageMultiplier = (roll - 1) * 25 + 200;
|
||||
|
||||
return Math.round((baseDamage / 250) * damageMultiplier);
|
||||
}
|
||||
|
||||
public getEffectOnTargetForTesting(): number {
|
||||
return this.effectOnTarget();
|
||||
}
|
||||
|
||||
isActive(): boolean {
|
||||
|
||||
Reference in New Issue
Block a user