diff --git a/docs/GDD.md b/docs/GDD.md index a54bd87..6079016 100644 --- a/docs/GDD.md +++ b/docs/GDD.md @@ -193,21 +193,41 @@ the gap at `BREACH_FLOW_METRES_PER_SECOND`. ## Weapons and items -`WEAPONS` holds damage, fire rate, magazine size, reload time, range falloff and rarity. +`WEAPONS` holds damage, fire rate, magazine size, reload time, range falloff, spread, +ammunition and rarity. Every weapon besides the boathook takes an inventory slot. | Name | Role | |---|---| -| Boathook | Melee and harvesting; always carried | -| Fowling Piece | Close-range spread | +| Boathook | Melee and harvesting; always carried, never in a slot | +| Fowling Piece | Close-range spread of shot | +| Rivet Repeater | Fast, short-range automatic | | Dock Carbine | Mid-range automatic | | Signal Revolver | Accurate sidearm | -| Whaler's Longgun | Long-range, single shot | -| Line Thrower | Fires a line to pull yourself to a surface | +| Whaler's Longgun | Long-range single shot; a heavy ball that drops with distance | +| Harpoon Gun | Slow, heavy bolt; tears through built pieces | +| Line Thrower | Fires a line and yanks you towards where it lands | | Powder Keg | Thrown explosive; damages structures heavily | -Items are in `ITEMS`: Sailcloth Bandage restores health, Brine Tonic restores more -health slowly, and Cork Vest adds armor, up to `PLAYER_MAX_ARMOR`. A player has -`PLAYER_MAX_HEALTH` health and `INVENTORY_SLOTS` carried item slots. +Weapons come in four quality tiers, from `WEAPON_TIERS`: Rusted, Seaworthy, +Brass-Fitted and Captain's. Better tiers hit harder and reload faster. + +Ammunition (`AMMO`) is carried apart from the slots: birdshot, cartridges, heavy balls, +harpoons and lines, each up to its own cap. + +Consumables are in `ITEMS`. Fire with one held starts using it, and it takes effect +after its use time. Changing slot, sprinting or swimming interrupts it and nothing is +used up; taking damage doesn't. An item that would do nothing can't be started. + +| Name | Effect | +|---|---| +| Sailcloth Bandage | Restores some health, up to 75 | +| Brine Tonic | Restores a lot of health, slowly | +| Tar Patch | Adds a little armor, quickly | +| Cork Vest | Adds a lot of armor | + +A player has `PLAYER_MAX_HEALTH` health, up to `PLAYER_MAX_ARMOR` armor, which takes +damage first, and `INVENTORY_SLOTS` slots. The top `HEAD_HEIGHT` of the body takes +each weapon's headshot multiplier. ## Controls diff --git a/src/sim/consumables.gd b/src/sim/consumables.gd new file mode 100644 index 0000000..5a319d7 --- /dev/null +++ b/src/sim/consumables.gd @@ -0,0 +1,49 @@ +## Using bandages, tonics, vests and patches. Fire with a consumable held starts using +## it, if it would do something: heal below its cap, or add armor below the maximum. +## It takes effect after the item's use time and uses up one from the stack. +## +## The server checks everything. Changing slot, dropping or swapping the item, +## sprinting, swimming or being eliminated interrupts it, and nothing is used up. +class_name Consumables +extends RefCounted + + +## True if using the item now would change anything. +static func would_help(player: SimEntity, def: ItemDef) -> bool: + if def.heal > 0 and player.health < mini(def.heal_cap, Tuning.PLAYER_MAX_HEALTH): + return true + return def.armor > 0 and player.armor < Tuning.PLAYER_MAX_ARMOR + + +## Starts using the held consumable. Returns true if it started. +static func start(sim: Simulation, player: SimEntity) -> bool: + var def: ItemDef = Inventory.held_def(player) + if def == null or def.kind != ItemDef.CONSUMABLE or player.use_ticks > 0: + return false + if player.action_cooldown > 0 or not would_help(player, def): + return false + player.use_ticks = maxi(def.use_ticks(), 1) + sim.events.append({"type": "use_started", "player": player.id, "item": def.code}) + return true + + +## Advances a use in progress. Called every tick for a player on foot. +static func update(sim: Simulation, player: SimEntity, command: PlayerCommand) -> void: + if player.use_ticks <= 0: + return + var def: ItemDef = Inventory.held_def(player) + var sprinting: bool = command != null and command.is_pressed(PlayerCommand.BUTTON_SPRINT) and command.move_vector().length() > 0.0 + if def == null or def.kind != ItemDef.CONSUMABLE or sprinting or player.swimming or player.health <= 0: + player.use_ticks = 0 + sim.events.append({"type": "use_cancelled", "player": player.id}) + return + player.use_ticks -= 1 + if player.use_ticks > 0: + return + if def.heal > 0: + var cap: int = mini(def.heal_cap, Tuning.PLAYER_MAX_HEALTH) + player.health = maxi(player.health, mini(player.health + def.heal, cap)) + if def.armor > 0: + player.armor = mini(player.armor + def.armor, Tuning.PLAYER_MAX_ARMOR) + Inventory.take_from_slot(player, Inventory.held_slot(player)) + sim.events.append({"type": "item_used", "player": player.id, "item": def.code}) diff --git a/src/sim/consumables.gd.uid b/src/sim/consumables.gd.uid new file mode 100644 index 0000000..1978572 --- /dev/null +++ b/src/sim/consumables.gd.uid @@ -0,0 +1 @@ +uid://bds3m0j8gf5ah diff --git a/src/sim/inventory.gd b/src/sim/inventory.gd index 4c56072..b6bda6b 100644 --- a/src/sim/inventory.gd +++ b/src/sim/inventory.gd @@ -34,6 +34,7 @@ static func reset(player: SimEntity) -> void: player.ammo.fill(0) player.selected = 0 player.reload_ticks = 0 + player.use_ticks = 0 ## Index into SimEntity.ammo for an ammunition item code, or -1. @@ -69,6 +70,7 @@ static func select(player: SimEntity, selection: int) -> void: return player.selected = selection player.reload_ticks = 0 + player.use_ticks = 0 player.action_cooldown = maxi(player.action_cooldown, roundi(Tuning.SWAP_SECONDS * Tuning.TICK_RATE_HZ)) @@ -158,6 +160,7 @@ static func interact(sim: Simulation, player: SimEntity) -> int: var moved: int = mini(def.stack, pickup.item_count) _fill(player, slot, pickup.item, moved, pickup.item_rounds, pickup.item_tier) player.reload_ticks = 0 + player.use_ticks = 0 taken = moved _take_from_pickup(sim, pickup, taken) var dropped: int = spawn_pickup(sim, spot, old[0], old[1], old[2], old[3]) @@ -181,6 +184,7 @@ static func drop_held(sim: Simulation, player: SimEntity) -> int: sim.events.append({"type": "dropped", "player": player.id, "pickup": id, "item": player.slot_items[slot], "count": player.slot_counts[slot]}) _clear(player, slot) player.reload_ticks = 0 + player.use_ticks = 0 return id diff --git a/src/sim/item_catalog.gd b/src/sim/item_catalog.gd index c180f8d..9785f19 100644 --- a/src/sim/item_catalog.gd +++ b/src/sim/item_catalog.gd @@ -59,6 +59,8 @@ static func _build() -> void: def.kind = ItemDef.CONSUMABLE def.stack = int(stats.get("stack", 1)) def.heal = int(stats.get("heal", 0)) + def.heal_cap = int(stats.get("heal_cap", Tuning.PLAYER_MAX_HEALTH)) + def.rarity = int(stats.get("rarity", 0)) def.armor = int(stats.get("armor", 0)) def.use_seconds = float(stats.get("use_seconds", 0.0)) _add(def) @@ -99,6 +101,8 @@ static func _weapon_def(id: String, stats: Dictionary, ammo_code: int) -> ItemDe def.bloom_degrees = float(stats.get("bloom", 0.0)) def.headshot_multiplier = float(stats.get("headshot", Tuning.HEADSHOT_MULTIPLIER)) def.structure_damage = int(stats.get("structure_damage", 0)) + def.structure_factor = float(stats.get("structure_factor", Tuning.WEAPON_STRUCTURE_FACTOR)) + def.pull_speed = float(stats.get("pull_speed", 0.0)) def.projectile_speed = float(stats.get("projectile_speed", 0.0)) def.projectile_gravity = float(stats.get("projectile_gravity", 0.0)) def.ammo_code = ammo_code diff --git a/src/sim/item_def.gd b/src/sim/item_def.gd index c446136..528057c 100644 --- a/src/sim/item_def.gd +++ b/src/sim/item_def.gd @@ -30,6 +30,10 @@ const AMMO: int = 2 @export var bloom_degrees: float = 0.0 @export var headshot_multiplier: float = 1.0 @export var structure_damage: int = 0 +## Multiplies damage to built pieces and props. +@export var structure_factor: float = 1.0 +## Speed the shooter is pulled towards where a shot lands; 0 for none. +@export var pull_speed: float = 0.0 ## 0 means hitscan. @export var projectile_speed: float = 0.0 @export var projectile_gravity: float = 0.0 @@ -40,6 +44,8 @@ const AMMO: int = 2 @export_group("Consumable") @export var heal: int = 0 +## Healing stops at this much health. +@export var heal_cap: int = 0 @export var armor: int = 0 @export var use_seconds: float = 0.0 @@ -61,8 +67,14 @@ func fire_interval_ticks() -> int: return maxi(ceili(Tuning.TICK_RATE_HZ / fire_rate), 1) -func reload_ticks() -> int: - return roundi(reload_seconds * Tuning.TICK_RATE_HZ) +## Reload time in ticks for a weapon of quality `tier`. +func reload_ticks(tier: int = 0) -> int: + return roundi(reload_seconds * Tuning.TICK_RATE_HZ * float(tier_stats(tier)["reload"])) + + +## The Tuning.WEAPON_TIERS entry for `tier`, clamped into range. +static func tier_stats(tier: int) -> Dictionary: + return Tuning.WEAPON_TIERS[clampi(tier, 0, Tuning.WEAPON_TIERS.size() - 1)] func use_ticks() -> int: diff --git a/src/sim/sim_entity.gd b/src/sim/sim_entity.gd index 4c8e84f..c3e24db 100644 --- a/src/sim/sim_entity.gd +++ b/src/sim/sim_entity.gd @@ -44,6 +44,8 @@ var slot_tiers: PackedInt32Array = PackedInt32Array() var ammo: PackedInt32Array = PackedInt32Array() ## Ticks left on a reload of the held weapon; 0 when not reloading. var reload_ticks: int = 0 +## Ticks left using a consumable from the held slot; 0 when not using one. +var use_ticks: int = 0 ## Extra spread from recent shots, in degrees. var bloom: float = 0.0 ## Buttons held last tick, so pick up and drop act once per press. diff --git a/src/sim/simulation.gd b/src/sim/simulation.gd index 9363d90..bbd2f15 100644 --- a/src/sim/simulation.gd +++ b/src/sim/simulation.gd @@ -162,6 +162,7 @@ func _apply_command(player: SimEntity, command: PlayerCommand) -> void: if player.action_cooldown > 0: player.action_cooldown -= 1 Weapons.update(player) + Consumables.update(self, player, command) var held: int = command.buttons if command != null else 0 var pressed: int = held & ~player.prev_buttons player.prev_buttons = held @@ -184,7 +185,11 @@ func _apply_command(player: SimEntity, command: PlayerCommand) -> void: if player.selected == BOATHOOK_SLOT: Harvest.swing(player, ground, props, events, structures) else: - Weapons.fire(self, player, command.is_pressed(PlayerCommand.BUTTON_AIM)) + var def: ItemDef = Inventory.held_def(player) + if def != null and def.kind == ItemDef.CONSUMABLE: + Consumables.start(self, player) + else: + Weapons.fire(self, player, command.is_pressed(PlayerCommand.BUTTON_AIM)) ## Marks players whose health reached 0 as eliminated, and drops what they carried. @@ -249,6 +254,7 @@ func state_hash() -> String: for array: PackedInt32Array in [entity.slot_items, entity.slot_counts, entity.slot_rounds, entity.slot_tiers, entity.ammo]: buffer.put_data(array.to_byte_array()) buffer.put_32(entity.reload_ticks) + buffer.put_32(entity.use_ticks) buffer.put_64(roundi(entity.bloom * 1000.0)) buffer.put_32(entity.prev_buttons) buffer.put_u8(1 if entity.eliminated else 0) diff --git a/src/sim/tuning.gd b/src/sim/tuning.gd index dff8425..dc1d936 100644 --- a/src/sim/tuning.gd +++ b/src/sim/tuning.gd @@ -246,6 +246,7 @@ const AMMO: Dictionary = { "cartridges": {"cap": 300, "pickup": 30}, "heavy_balls": {"cap": 30, "pickup": 6}, "lines": {"cap": 12, "pickup": 3}, + "harpoons": {"cap": 10, "pickup": 3}, } # Weapons. Falloff is linear from full damage at `range_full` to `falloff_min` @@ -254,6 +255,8 @@ const AMMO: Dictionary = { # degrees, which decays at BLOOM_DECAY_DEGREES_PER_SECOND while the weapon is ready. `projectile_speed` 0 means # hitscan; otherwise shots fly at that speed under `projectile_gravity`. `ammo` names # an AMMO type; a weapon with `stack` above 1 is thrown and is its own ammunition. +# `pull_speed` yanks the shooter towards where the shot lands, at that speed. +# `structure_factor` scales damage to built pieces and props (default 1). const WEAPONS: Dictionary = { "boathook": { "damage": 20, "fire_rate": 1.5, "magazine": 0, "reload": 0.0, @@ -275,6 +278,11 @@ const WEAPONS: Dictionary = { "range_full": 30.0, "range_max": 80.0, "falloff_min": 0.5, "rarity": 0, "spread": 0.8, "bloom": 0.6, "ammo": "cartridges", "headshot": 2.0, }, + "rivet_repeater": { + "damage": 17, "fire_rate": 11.0, "magazine": 35, "reload": 2.0, + "range_full": 12.0, "range_max": 45.0, "falloff_min": 0.4, "rarity": 0, + "spread": 2.4, "bloom": 0.25, "ammo": "cartridges", "headshot": 1.5, + }, "whalers_longgun": { "damage": 105, "fire_rate": 0.5, "magazine": 1, "reload": 2.6, "range_full": 120.0, "range_max": 350.0, "falloff_min": 0.7, "rarity": 2, @@ -285,7 +293,13 @@ const WEAPONS: Dictionary = { "damage": 0, "fire_rate": 0.6, "magazine": 3, "reload": 3.0, "range_full": 45.0, "range_max": 45.0, "falloff_min": 1.0, "rarity": 2, "spread": 0.0, "bloom": 0.0, "ammo": "lines", - "projectile_speed": 90.0, "projectile_gravity": 4.0, + "projectile_speed": 90.0, "projectile_gravity": 4.0, "pull_speed": 18.0, + }, + "harpoon_gun": { + "damage": 70, "fire_rate": 0.9, "magazine": 1, "reload": 1.8, + "range_full": 25.0, "range_max": 70.0, "falloff_min": 0.6, "rarity": 1, + "spread": 0.6, "bloom": 0.0, "ammo": "harpoons", "headshot": 1.5, + "projectile_speed": 120.0, "projectile_gravity": 6.0, "structure_factor": 2.5, }, "powder_keg": { "damage": 80, "structure_damage": 400, "blast_radius": 6.0, "fuse": 3.0, @@ -307,10 +321,23 @@ const HEADSHOT_MULTIPLIER: float = 1.5 const HEAD_HEIGHT: float = 0.35 ## Shots against built pieces and props do this fraction of their player damage. const WEAPON_STRUCTURE_FACTOR: float = 1.0 +## Quality tiers, lowest first. Loot rolls a tier for each weapon it spawns. `damage` +## multiplies every hit and `reload` multiplies the reload time. +const WEAPON_TIERS: Array[Dictionary] = [ + {"name": "rusted", "damage": 1.0, "reload": 1.0}, + {"name": "seaworthy", "damage": 1.08, "reload": 0.95}, + {"name": "brass_fitted", "damage": 1.16, "reload": 0.9}, + {"name": "captains", "damage": 1.25, "reload": 0.85}, +] +## A line pull also lifts the puller this fast, so it clears the ground. +const LINE_PULL_LIFT: float = 4.0 -# Consumables +# Consumables. Fire with one held starts using it; it takes effect after `use_seconds` +# unless interrupted. `heal` restores health up to `heal_cap` (default full), `armor` +# adds armor up to PLAYER_MAX_ARMOR. An item that would do nothing can't be started. const ITEMS: Dictionary = { - "sailcloth_bandage": {"heal": 25, "use_seconds": 3.0, "stack": 6}, - "brine_tonic": {"heal": 60, "use_seconds": 8.0, "stack": 3}, - "cork_vest": {"armor": 50, "use_seconds": 5.0, "stack": 2}, + "sailcloth_bandage": {"heal": 25, "heal_cap": 75, "use_seconds": 3.0, "stack": 6, "rarity": 0}, + "brine_tonic": {"heal": 60, "use_seconds": 8.0, "stack": 3, "rarity": 1}, + "cork_vest": {"armor": 50, "use_seconds": 5.0, "stack": 2, "rarity": 1}, + "tar_patch": {"armor": 20, "use_seconds": 2.0, "stack": 5, "rarity": 0}, } diff --git a/src/sim/weapons.gd b/src/sim/weapons.gd index 1cc7b0c..2b0d994 100644 --- a/src/sim/weapons.gd +++ b/src/sim/weapons.gd @@ -64,7 +64,7 @@ static func start_reload(player: SimEntity) -> bool: return false if player.ammo[Inventory.ammo_index(def.ammo_code)] <= 0: return false - player.reload_ticks = maxi(def.reload_ticks(), 1) + player.reload_ticks = maxi(def.reload_ticks(player.slot_tiers[slot]), 1) return true @@ -207,6 +207,8 @@ static func body_box(player: SimEntity) -> AABB: ## Applies a pellet's hit. `distance` is from where the shot started. static func _apply_hit(sim: Simulation, attacker: int, def: ItemDef, tier: int, hit: Hit, distance: float) -> void: sim.events.append({"type": "impact", "player": attacker, "item": def.code, "point": hit.point, "hit": hit.kind, "target": hit.target}) + if def.pull_speed > 0.0 and hit.kind != HIT_NONE: + _pull(sim, sim.entities.find(attacker), hit.point, def.pull_speed) if def.damage <= 0: return var amount: float = def.damage_at(distance) * tier_multiplier(tier) @@ -216,15 +218,27 @@ static func _apply_hit(sim: Simulation, attacker: int, def: ItemDef, tier: int, amount *= def.headshot_multiplier damage_player(sim, sim.entities.find(hit.target), roundi(amount), attacker, hit.headshot) HIT_PIECE: - sim.damage_piece(hit.target, roundi(amount * Tuning.WEAPON_STRUCTURE_FACTOR), "weapon") + sim.damage_piece(hit.target, roundi(amount * def.structure_factor), "weapon") HIT_PROP: - if sim.damage_prop(hit.target, roundi(amount * Tuning.WEAPON_STRUCTURE_FACTOR)): + if sim.damage_prop(hit.target, roundi(amount * def.structure_factor)): sim.events.append({"type": "prop_destroyed", "prop": hit.target}) -## Damage multiplier for a quality tier. Tiers arrive with the weapon roster (B7). -static func tier_multiplier(_tier: int) -> float: - return 1.0 +## Damage multiplier for a quality tier, from Tuning.WEAPON_TIERS. +static func tier_multiplier(tier: int) -> float: + return float(ItemDef.tier_stats(tier)["damage"]) + + +## Yanks a player on foot towards `point`, lifting them off the ground. +static func _pull(sim: Simulation, player: SimEntity, point: Vector3, speed: float) -> void: + if player == null or player.eliminated or player.drop_state != Drop.NONE or player.swimming: + return + var direction: Vector3 = point - Harvest.eye(player) + if direction.length_squared() < 0.0001: + return + player.velocity = direction.normalized() * speed + Vector3(0.0, Tuning.LINE_PULL_LIFT, 0.0) + player.on_ground = false + sim.events.append({"type": "line_pull", "player": player.id, "point": point}) ## Takes `amount` from armor, then health. Returns the damage actually done. diff --git a/test/sim/test_roster.gd b/test/sim/test_roster.gd new file mode 100644 index 0000000..81660d4 --- /dev/null +++ b/test/sim/test_roster.gd @@ -0,0 +1,272 @@ +extends TestCase + +## The weapon roster and consumables from issue B7: a data-validation pass over every +## weapon, tier and consumable, tier effects, the line thrower's pull, and consumable +## use that is timed, validated and interruptible. + +const FEET: Vector3 = Vector3(100.0, 0.0, 100.0) +## Names must read as Tidewall's own: lowercase words joined by underscores. +const NAME_PATTERN: String = "^[a-z]+(_[a-z]+)*$" + + +func _code(id: String) -> int: + return ItemCatalog.code_of(id) + + +func _sim() -> Simulation: + var sim: Simulation = Simulation.new(9, SimGround.flat()) + var player: SimEntity = sim.entities.find(sim.add_player()) + player.position = FEET + player.on_ground = true + return sim + + +func _step(sim: Simulation, buttons: int = 0, selection: int = 1, move: Vector2 = Vector2.ZERO, pitch: float = 0.0) -> void: + sim.submit_command(1, PlayerCommand.from_input(sim.tick, move, 0.0, pitch, buttons, selection)) + sim.step() + + +func _has_event(sim: Simulation, kind: String) -> bool: + for event: Dictionary in sim.events: + if event["type"] == kind: + return true + return false + + +func test_the_roster_has_eight_weapons_and_four_consumables() -> void: + var weapons: int = 0 + var consumables: int = 0 + for def: ItemDef in ItemCatalog.all(): + if def.kind == ItemDef.WEAPON: + weapons += 1 + elif def.kind == ItemDef.CONSUMABLE: + consumables += 1 + assert_eq(weapons, 8, "eight slot weapons, besides the boathook") + assert_eq(consumables, 4) + assert_eq(Tuning.WEAPON_TIERS.size(), 4) + + +func test_every_weapon_is_valid() -> void: + var name_check: RegEx = RegEx.create_from_string(NAME_PATTERN) + for def: ItemDef in ItemCatalog.all(): + if def.kind != ItemDef.WEAPON: + continue + assert_not_null(name_check.search(def.id), "%s: name format" % def.id) + assert_true(def.damage >= 0, "%s: damage" % def.id) + assert_true(def.pellets >= 1, "%s: pellets" % def.id) + assert_true(def.fire_rate > 0.0 and def.fire_rate <= Tuning.TICK_RATE_HZ, "%s: fire rate" % def.id) + assert_true(def.range_max >= def.range_full and def.range_full >= 0.0, "%s: ranges" % def.id) + assert_true(def.falloff_min > 0.0 and def.falloff_min <= 1.0, "%s: falloff" % def.id) + assert_true(def.rarity >= 0 and def.rarity < Tuning.WEAPON_TIERS.size(), "%s: rarity" % def.id) + assert_true(def.spread_degrees >= 0.0 and def.spread_degrees < 15.0, "%s: spread" % def.id) + assert_true(def.headshot_multiplier >= 1.0, "%s: headshot" % def.id) + assert_true(def.structure_factor >= 0.0, "%s: structure factor" % def.id) + if def.thrown: + assert_eq(def.ammo_code, ItemCatalog.NONE, "%s: thrown weapons are their own ammo" % def.id) + else: + assert_true(def.magazine > 0, "%s: magazine" % def.id) + assert_true(def.reload_seconds > 0.0, "%s: reload" % def.id) + var ammo: ItemDef = ItemCatalog.get_def(def.ammo_code) + assert_not_null(ammo, "%s: ammo" % def.id) + if ammo != null: + assert_eq(ammo.kind, ItemDef.AMMO, "%s: ammo kind" % def.id) + assert_true(ammo.cap >= def.magazine, "%s: a full magazine fits in the ammo cap" % def.id) + if def.projectile_speed > 0.0: + assert_true(def.projectile_gravity >= 0.0, "%s: gravity" % def.id) + for key: String in Tuning.WEAPONS[def.id]: + assert_true(key in [ + "damage", "pellets", "fire_rate", "magazine", "reload", "range_full", "range_max", + "falloff_min", "rarity", "spread", "aim_spread", "bloom", "headshot", "ammo", "stack", + "projectile_speed", "projectile_gravity", "structure_damage", "structure_factor", + "blast_radius", "fuse", "pull_speed", + ], "%s: unknown stat %s, probably a typo" % [def.id, key]) + + +func test_every_consumable_and_ammo_type_is_valid() -> void: + var name_check: RegEx = RegEx.create_from_string(NAME_PATTERN) + for def: ItemDef in ItemCatalog.all(): + assert_not_null(name_check.search(def.id), "%s: name format" % def.id) + match def.kind: + ItemDef.CONSUMABLE: + assert_true(def.heal > 0 or def.armor > 0, "%s does something" % def.id) + assert_true(def.use_seconds > 0.0 and def.use_seconds <= 10.0, "%s: use time" % def.id) + assert_true(def.stack >= 1, "%s: stack" % def.id) + assert_true(def.heal_cap > 0 and def.heal_cap <= Tuning.PLAYER_MAX_HEALTH, "%s: heal cap" % def.id) + ItemDef.AMMO: + assert_true(def.cap > 0 and def.pickup_amount > 0 and def.pickup_amount <= def.cap, "%s: amounts" % def.id) + var used_ammo: Dictionary = {} + for def: ItemDef in ItemCatalog.all(): + if def.ammo_code >= 0: + used_ammo[def.ammo_code] = true + for def: ItemDef in ItemCatalog.all(): + if def.kind == ItemDef.AMMO: + assert_true(used_ammo.has(def.code), "%s is used by some weapon" % def.id) + + +func test_tiers_only_improve() -> void: + var name_check: RegEx = RegEx.create_from_string(NAME_PATTERN) + var previous: Dictionary = {"damage": 0.0, "reload": INF} + for tier: Dictionary in Tuning.WEAPON_TIERS: + assert_not_null(name_check.search(tier["name"])) + assert_true(float(tier["damage"]) > float(previous["damage"])) + assert_true(float(tier["reload"]) < float(previous["reload"])) + previous = tier + assert_eq(float(Tuning.WEAPON_TIERS[0]["damage"]), 1.0, "the lowest tier is the table's stats") + + +func test_a_higher_tier_hits_harder_and_reloads_faster() -> void: + var damage: Array[int] = [] + for tier: int in [0, 3]: + var sim: Simulation = _sim() + var shooter: SimEntity = sim.entities.find(1) + Inventory.give(shooter, _code("signal_revolver"), 1, -1, tier) + var target: SimEntity = sim.entities.find(sim.add_player()) + target.position = FEET + Vector3(0.0, 0.0, 10.0) + var eye: Vector3 = Harvest.eye(shooter) + var aim: float = atan2(target.position.y + 0.9 - eye.y, 10.0) + for _i: int in 10: + _step(sim, PlayerCommand.BUTTON_FIRE | PlayerCommand.BUTTON_AIM, 1, Vector2.ZERO, aim) + if target.health < Tuning.PLAYER_MAX_HEALTH: + break + damage.append(Tuning.PLAYER_MAX_HEALTH - target.health) + assert_eq(damage[0], 38) + assert_eq(damage[1], roundi(38 * 1.25)) + var def: ItemDef = ItemCatalog.get_def(_code("signal_revolver")) + assert_true(def.reload_ticks(3) < def.reload_ticks(0)) + assert_eq(def.reload_ticks(99), def.reload_ticks(3), "out-of-range tiers clamp") + + +func test_the_line_thrower_pulls_the_shooter_towards_where_it_lands() -> void: + var sim: Simulation = _sim() + var shooter: SimEntity = sim.entities.find(1) + Inventory.give(shooter, _code("line_thrower"), 1) + sim.ground.add_solid(AABB(Vector3(90.0, 0.0, 130.0), Vector3(20.0, 12.0, 2.0))) + var pulled: bool = false + for _i: int in 30: + _step(sim, PlayerCommand.BUTTON_FIRE, 1, Vector2.ZERO, 0.15) + if _has_event(sim, "line_pull"): + pulled = true + break + assert_true(pulled, "the line reached the wall") + assert_true(shooter.velocity.z > 10.0, "pulled towards the wall, at %s" % shooter.velocity) + assert_false(shooter.on_ground) + var start_z: float = shooter.position.z + for _i: int in 10: + _step(sim, 0) + assert_true(shooter.position.z > start_z + 3.0, "and it moves") + + +func test_the_harpoon_gun_is_hard_on_structures() -> void: + var def: ItemDef = ItemCatalog.get_def(_code("harpoon_gun")) + assert_true(def.structure_factor > 1.0) + assert_true(def.projectile_speed > 0.0) + + +func test_a_bandage_heals_after_its_use_time() -> void: + var sim: Simulation = _sim() + var player: SimEntity = sim.entities.find(1) + var bandage: ItemDef = ItemCatalog.get_def(_code("sailcloth_bandage")) + Inventory.give(player, bandage.code, 2) + player.health = 40 + _step(sim, 0) + for _i: int in 10: + _step(sim, PlayerCommand.BUTTON_FIRE) + if player.use_ticks > 0: + break + assert_true(player.use_ticks > 0, "use started") + var used_at: int = -1 + for i: int in bandage.use_ticks() + 2: + _step(sim, 0) + if _has_event(sim, "item_used"): + used_at = i + assert_eq(used_at, bandage.use_ticks() - 1, "takes effect after the use time") + assert_eq(player.health, 65) + assert_eq(Inventory.count_of(player, bandage.code), 1) + + +func test_healing_stops_at_the_items_cap() -> void: + var sim: Simulation = _sim() + var player: SimEntity = sim.entities.find(1) + Inventory.give(player, _code("sailcloth_bandage"), 1) + player.health = 70 + player.selected = 1 + assert_true(Consumables.start(sim, player)) + for _i: int in 200: + _step(sim, 0) + assert_eq(player.health, 75) + player.health = 80 + Inventory.give(player, _code("sailcloth_bandage"), 1) + assert_false(Consumables.start(sim, player), "above the cap a bandage does nothing, so it can't start") + + +func test_armor_stops_at_the_maximum() -> void: + var sim: Simulation = _sim() + var player: SimEntity = sim.entities.find(1) + Inventory.give(player, _code("cork_vest"), 2) + player.selected = 1 + player.armor = 80 + assert_true(Consumables.start(sim, player)) + for _i: int in 200: + _step(sim, 0) + assert_eq(player.armor, Tuning.PLAYER_MAX_ARMOR) + assert_false(Consumables.start(sim, player), "full armor") + assert_eq(Inventory.count_of(player, _code("cork_vest")), 1) + + +func test_switching_slots_interrupts_and_uses_nothing() -> void: + var sim: Simulation = _sim() + var player: SimEntity = sim.entities.find(1) + var tonic: int = _code("brine_tonic") + Inventory.give(player, tonic, 1) + player.health = 30 + player.selected = 1 + assert_true(Consumables.start(sim, player)) + for _i: int in 30: + _step(sim, 0, 1) + _step(sim, 0, 2) + assert_eq(player.use_ticks, 0) + for _i: int in 300: + _step(sim, 0, 2) + assert_eq(player.health, 30) + assert_eq(Inventory.count_of(player, tonic), 1) + + +func test_sprinting_interrupts() -> void: + var sim: Simulation = _sim() + var player: SimEntity = sim.entities.find(1) + Inventory.give(player, _code("tar_patch"), 1) + player.selected = 1 + assert_true(Consumables.start(sim, player)) + _step(sim, 0) + _step(sim, PlayerCommand.BUTTON_SPRINT, 1, Vector2(0.0, 1.0)) + assert_true(_has_event(sim, "use_cancelled")) + assert_eq(player.armor, 0) + assert_eq(Inventory.count_of(player, _code("tar_patch")), 1) + + +func test_walking_does_not_interrupt() -> void: + var sim: Simulation = _sim() + var player: SimEntity = sim.entities.find(1) + Inventory.give(player, _code("tar_patch"), 1) + player.selected = 1 + assert_true(Consumables.start(sim, player)) + for _i: int in 90: + _step(sim, 0, 1, Vector2(0.0, 1.0)) + assert_eq(player.armor, 20) + + +func test_damage_mid_use_does_not_interrupt_but_elimination_does() -> void: + var sim: Simulation = _sim() + var player: SimEntity = sim.entities.find(1) + Inventory.give(player, _code("brine_tonic"), 1) + player.health = 50 + player.selected = 1 + assert_true(Consumables.start(sim, player)) + _step(sim, 0) + Weapons.damage_player(sim, player, 10, 0) + _step(sim, 0) + assert_true(player.use_ticks > 0) + player.health = 0 + _step(sim, 0) + assert_true(player.eliminated) + assert_eq(player.use_ticks, 0) diff --git a/test/sim/test_roster.gd.uid b/test/sim/test_roster.gd.uid new file mode 100644 index 0000000..7cb9054 --- /dev/null +++ b/test/sim/test_roster.gd.uid @@ -0,0 +1 @@ +uid://dnj4t2frlfmaw