forked from dcatanzaro/aoweb
-
Notifications
You must be signed in to change notification settings - Fork 32
feat(siege): guild siege war machines, ammunition modifiers, and gate armor penetration #196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
angelTomo9
wants to merge
2
commits into
Bitcoindefi:main
Choose a base branch
from
angelTomo9:feat-siege-machines-1787850077952
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| /** | ||
| * Guild Siege War Machine & Fortification Assault Engine for OpenAO MMORPG. | ||
| * Simulates deployment of Catapults, Ballistas, and Battering Rams, ammunition damage modifiers, | ||
| * fortification gate armor penetration, reload timers enforcement, and operator crew attachment mechanics. | ||
| */ | ||
|
|
||
| export type SiegeMachineType = "CATAPULT" | "BALLISTA" | "BATTERING_RAM"; | ||
| export type SiegeAmmoType = "HEAVY_BOULDER" | "FIRE_POT" | "IRON_BOLT"; | ||
| export type StructureMaterial = "STONE_WALL" | "WOODEN_GATE" | "REINFORCED_IRON_GATE"; | ||
|
|
||
| export interface SiegeMachineDefinition { | ||
| machineType: SiegeMachineType; | ||
| baseDamage: number; | ||
| reloadTimeSeconds: number; | ||
| maxHp: number; | ||
| supportedAmmo: SiegeAmmoType[]; | ||
| } | ||
|
|
||
| export interface ActiveSiegeMachine { | ||
| instanceId: string; | ||
| machineType: SiegeMachineType; | ||
| guildId: string; | ||
| operatorPlayerId?: string; | ||
| currentHp: number; | ||
| maxHp: number; | ||
| loadedAmmo?: SiegeAmmoType; | ||
| lastFiredEpochMs: number; | ||
| } | ||
|
|
||
| export interface SiegeAttackResult { | ||
| damageDealt: number; | ||
| isTargetDestroyed: boolean; | ||
| remainingStructureHp: number; | ||
| wasEffectiveMaterialBonus: boolean; | ||
| isOnCooldown?: boolean; | ||
| reason?: string; | ||
| } | ||
|
|
||
| export const SIEGE_MACHINE_SPECS: Record<SiegeMachineType, SiegeMachineDefinition> = { | ||
| CATAPULT: { | ||
| machineType: "CATAPULT", | ||
| baseDamage: 800, | ||
| reloadTimeSeconds: 6, | ||
| maxHp: 2000, | ||
| supportedAmmo: ["HEAVY_BOULDER", "FIRE_POT"], | ||
| }, | ||
| BALLISTA: { | ||
| machineType: "BALLISTA", | ||
| baseDamage: 450, | ||
| reloadTimeSeconds: 3, | ||
| maxHp: 1200, | ||
| supportedAmmo: ["IRON_BOLT", "FIRE_POT"], | ||
| }, | ||
| BATTERING_RAM: { | ||
| machineType: "BATTERING_RAM", | ||
| baseDamage: 1200, | ||
| reloadTimeSeconds: 8, | ||
| maxHp: 3000, | ||
| supportedAmmo: ["HEAVY_BOULDER"], | ||
| }, | ||
| }; | ||
|
|
||
| export class SiegeWarMachineEngine { | ||
| /** | ||
| * Deploys a new siege engine for a guild. | ||
| */ | ||
| public static deployMachine( | ||
| instanceId: string, | ||
| machineType: SiegeMachineType, | ||
| guildId: string, | ||
| operatorPlayerId?: string | ||
| ): ActiveSiegeMachine { | ||
| const spec = SIEGE_MACHINE_SPECS[machineType]; | ||
| return { | ||
| instanceId, | ||
| machineType, | ||
| guildId, | ||
| operatorPlayerId, | ||
| currentHp: spec.maxHp, | ||
| maxHp: spec.maxHp, | ||
| loadedAmmo: spec.supportedAmmo[0], | ||
| lastFiredEpochMs: 0, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Calculates the damage multiplier based on ammunition and target structure material. | ||
| */ | ||
| public static getMaterialDamageMultiplier(ammo: SiegeAmmoType, material: StructureMaterial): { multiplier: number; isBonus: boolean } { | ||
| if (ammo === "HEAVY_BOULDER" && material === "STONE_WALL") { | ||
| return { multiplier: 1.5, isBonus: true }; | ||
| } | ||
| if (ammo === "FIRE_POT" && material === "WOODEN_GATE") { | ||
| return { multiplier: 2.0, isBonus: true }; | ||
| } | ||
| if (ammo === "IRON_BOLT" && material === "REINFORCED_IRON_GATE") { | ||
| return { multiplier: 0.5, isBonus: false }; // Ineffective | ||
| } | ||
| return { multiplier: 1.0, isBonus: false }; | ||
| } | ||
|
|
||
| /** | ||
| * Executes a siege engine strike against a fortification structure, enforcing reload cooldowns. | ||
| */ | ||
| public static fireAtStructure( | ||
| machine: ActiveSiegeMachine, | ||
| targetStructureHp: number, | ||
| targetStructureArmor: number, | ||
| targetMaterial: StructureMaterial, | ||
| currentEpochMs: number | ||
| ): SiegeAttackResult { | ||
| const spec = SIEGE_MACHINE_SPECS[machine.machineType]; | ||
|
|
||
| // Enforce reload cooldown | ||
| const reloadMs = spec.reloadTimeSeconds * 1000; | ||
| if (machine.lastFiredEpochMs > 0 && currentEpochMs - machine.lastFiredEpochMs < reloadMs) { | ||
| const remainingCooldown = reloadMs - (currentEpochMs - machine.lastFiredEpochMs); | ||
| return { | ||
| damageDealt: 0, | ||
| isTargetDestroyed: false, | ||
| remainingStructureHp: targetStructureHp, | ||
| wasEffectiveMaterialBonus: false, | ||
| isOnCooldown: true, | ||
| reason: `Machine is currently reloading. Cooldown remaining: ${Math.ceil(remainingCooldown / 1000)}s.`, | ||
| }; | ||
| } | ||
|
|
||
| const ammo = machine.loadedAmmo ?? spec.supportedAmmo[0]; | ||
| const { multiplier, isBonus } = this.getMaterialDamageMultiplier(ammo, targetMaterial); | ||
|
|
||
| // Armor mitigation formula: RawDamage * (100 / (100 + armor)) | ||
| const armorFactor = 100 / (100 + Math.max(0, targetStructureArmor)); | ||
| const rawDamage = spec.baseDamage * multiplier; | ||
| const finalDamage = Math.max(50, Math.floor(rawDamage * armorFactor)); | ||
|
|
||
| const remainingHp = Math.max(0, targetStructureHp - finalDamage); | ||
| machine.lastFiredEpochMs = currentEpochMs; | ||
|
|
||
| return { | ||
| damageDealt: finalDamage, | ||
| isTargetDestroyed: remainingHp === 0, | ||
| remainingStructureHp: remainingHp, | ||
| wasEffectiveMaterialBonus: isBonus, | ||
| isOnCooldown: false, | ||
| }; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { describe, it, expect } from "vitest"; | ||
| import { SiegeWarMachineEngine } from "../lib/siegeWarMachine.js"; | ||
|
|
||
| describe("SiegeWarMachineEngine Fortification Assault & Reload Cooldowns", () => { | ||
| it("deploys siege machine and fires with effective material multiplier", () => { | ||
| const machine = SiegeWarMachineEngine.deployMachine("catapult_01", "CATAPULT", "guild_order"); | ||
| machine.loadedAmmo = "FIRE_POT"; | ||
|
|
||
| // Wooden gate with 0 armor and 2000 HP: base 800 * 2.0 = 1600 damage | ||
| const result = SiegeWarMachineEngine.fireAtStructure(machine, 2000, 0, "WOODEN_GATE", 100000); | ||
| expect(result.damageDealt).toBe(1600); | ||
| expect(result.wasEffectiveMaterialBonus).toBe(true); | ||
| expect(result.remainingStructureHp).toBe(400); | ||
| expect(machine.lastFiredEpochMs).toBe(100000); | ||
| }); | ||
|
|
||
| it("blocks firing while reload cooldown is active", () => { | ||
| const machine = SiegeWarMachineEngine.deployMachine("catapult_01", "CATAPULT", "guild_order"); | ||
|
|
||
| // Fire 1 at 100000 (Catapult reload is 6 seconds = 6000ms) | ||
| SiegeWarMachineEngine.fireAtStructure(machine, 2000, 0, "WOODEN_GATE", 100000); | ||
|
|
||
| // Attempt fire at 103000 (only 3 seconds elapsed) | ||
| const earlyResult = SiegeWarMachineEngine.fireAtStructure(machine, 2000, 0, "WOODEN_GATE", 103000); | ||
| expect(earlyResult.isOnCooldown).toBe(true); | ||
| expect(earlyResult.damageDealt).toBe(0); | ||
| expect(earlyResult.reason).toContain("Machine is currently reloading"); | ||
|
|
||
| // Attempt fire after 6000ms at 106001 -> Success | ||
| const validResult = SiegeWarMachineEngine.fireAtStructure(machine, 400, 0, "WOODEN_GATE", 106001); | ||
| expect(validResult.isOnCooldown).toBe(false); | ||
| expect(validResult.damageDealt).toBeGreaterThan(0); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.