Ledger v3 · C# · Godot 4.7 Get started

Reload

A magazine and a reload that keeps its gun quiet

✓ 2 plays, 94 steps, all passingFrom Shooter, content\weapons.ledger
target up to 1 enemiesblocks Activate by holder having TAGexpireset

A magazine and a reload, lifted from the shooter slice's content\weapons.ledger (the Rifle, ReloadRifle and ReloadingRifle) and the player's magazine from content\player.ledger. Each round costs one of the magazine's 30 and the gun's rate of 0.1 s, a hit or a miss: the raycast is the engine's, and a round that meets no foe names none. A reload keeps the gun quiet 1.2 s and fills the magazine as it ends; it is refused on a full magazine. The slice's reload blocks only its own gun, by the gun's tag, so its pistol fires on.

content/cookbook/mechanics/reload.ledgerthe content
1# A magazine and a reload, lifted from the shooter slice's content\weapons.ledger (the Rifle, ReloadRifle and
2# ReloadingRifle) and the player's magazine from content\player.ledger. Each round costs one of the magazine's 30 and
3# the gun's rate of 0.1 s, a hit or a miss: the raycast is the engine's, and a round that meets no foe names none. A
4# reload keeps the gun quiet 1.2 s and fills the magazine as it ends; it is refused on a full magazine. The slice's
5# reload blocks only its own gun, by the gun's tag, so its pistol fires on.
6
7rate 60
8stat MaxHealth
9stat RifleMag
10pool Health max MaxHealth
11pool RifleAmmo max RifleMag whole
12damage Health
13link team
14allegiance team
15tags Unit Weapon Rifle Bullet
17ability Rifle
18 tags Weapon Rifle Bullet
19 target up to 1 enemies
20 cost RifleAmmo 1
21 cooldown 0.1s
22 deal 8 Bullet to targets
24ability ReloadRifle
25 requires holder.RifleAmmo < holder.RifleMag else "full"
26 apply ReloadingRifle to holder
28effect ReloadingRifle
29 stack ignore
30 lasts 1.2s
31 blocks Activate by holder having Rifle
32 expire
33 set RifleAmmo holder.RifleMag
35archetype Side
37archetype Player
38 tags Unit
39 base MaxHealth 100
40 base RifleMag 30
41 full Health RifleAmmo
42 grants Rifle ReloadRifle
44archetype Dummy
45 tags Unit
46 base MaxHealth 1000
47 full Health
content/cookbook/mechanics/reload.playwhat it must do
1catalog reload.ledger
2
3# The rifle's numbers, from Rifle (8 a round, one round, 0.1 s) and ReloadingRifle (1.2 s); a magazine of 30. A player
4# at 0 shoots a dummy at 10 on the other side; each round names what the engine's raycast found, or no one.
5
6play "a round in the dummy takes 8 and one round; one at once is refused by the rate; a round meeting nothing still costs its round"
7 make r Side
8 make b Side
9 make h Player with team = r at 0
10 make d Dummy with team = b at 10
11 act h Rifle at d
12 expect done
13 expect d.Health = 992 from content: the Dummy's 1000 less 8
14 expect h.RifleAmmo = 29 from content: 30 less the round's 1
15 act h Rifle
16 expect refused OnCooldown
17 advance 0.1s
18 act h Rifle
19 expect done
20 expect h.RifleAmmo = 28 from content: 29 less a round that met no foe
21 expect d.Health = 992 from content: nothing met
23play "a full magazine refuses a reload; 30 rounds empty it; the reload keeps it quiet 1.2 s and fills it to 30"
24 make r Side
25 make b Side
26 make h Player with team = r at 0
27 make d Dummy with team = b at 10
28 act h ReloadRifle
29 expect refused Requirement "full"
30 repeat 30
31 act h Rifle at d
32 advance 0.1s
33 expect h.RifleAmmo = 0 from content: 30 rounds of 1
34 act h Rifle at d
35 expect refused CannotAfford
36 act h ReloadRifle
37 expect done
38 save
39 advance 1.1s
40 act h Rifle at d
41 expect refused Blocked
42 advance 0.1s
43 expect h.RifleAmmo = 30 from content: RifleMag 30, set as the reload ends at 1.2 s
44 act h Rifle at d
45 expect done

Run it yourself

ledger check content/cookbook/mechanics/reload.ledger content/cookbook/mechanics/reload.play
ledger play content/cookbook/mechanics/reload.play