diff --git a/README.md b/README.md index d915750..caad975 100644 --- a/README.md +++ b/README.md @@ -33,18 +33,17 @@ The player-facing command set is intentionally melee-focused. | Key | Action | | --- | --- | | `h` `j` `k` `l` | move west / south / north / east | -| `.` | wait / rest | +| `.` | wait one turn | | arrows | move (or move the cursor in look/throw mode) | | `f` + `h/j/k/l` | bash an adjacent small obstacle | | `a` | use the Hands item / report the weapon ready | -| `c` `d` `r` | use, swap or consume Belt 1–3 | -| `A` `B` `C` `D` `R` | drop Hands, Body, Belt 1–3 | +| `r` / `t` | use the first / second known Rite | +| `A` `H` `C` `D` `R` | drop Hands, Head, Robe 1–3 | | `g` | get the item from the ground | | `e` | equipment overlay | | `v` | view / look around | | `~` | expand/collapse latest messages | | `@` | character information | -| `x` | skill levels | | `O` | options | | `?` | help / key bindings | | `S` | save and quit | @@ -58,21 +57,22 @@ Walking into a monster attacks it. Bashing is intentional: use `f` and a direction. A bash takes a turn, and some containers such as barrels or crates may drop supplies when smashed. -Screens generally close with `z`, `q`, `Space`, or `Esc`. The player is defenceless -without a melee weapon; there is no unarmed attack. Throwing is deferred for -now. +Screens generally close with `z`, `q`, `Space`, or `Esc`. The player is +defenceless without a melee weapon; there is no unarmed attack. Flask throwing +is deferred for now. -The player has five equipment slots: Hands, Body, Belt 1–3. Body armour is -worn passively and removed/dropped with `B`. Belt 2 and 3 unlock at levels 3 -and 6. +The priest has Hands, Head and a permanently worn Robe with three slots. Robe +slots hold vials, shards or small items. Shards provide all AP and break when +drained. The first slice starts with one random Rite; the planned shrine that +grants a second Rite is not implemented yet. ## Screens -* title, intro story, class selection +* title, generated priest intro and random Rite * compact 80×23 woods map view with unlimited-radius FOV, line-of-sight blockers and remembered terrain * message log and message-buffer screen * inventory, equipment and ground-item screen with item data -* character sheet, skill-level screen, options screen, key-binding screen +* character sheet, equipment/robe screen, options screen, key-binding screen * look mode with tile highlighting * save/load, death and victory screens @@ -104,15 +104,15 @@ and 6. * melee combat with recovered weapon AV/DV and damage values * throwing is deferred; HE grenade and molotov data are retained for a future pass * recovered weapon table (attack/defense value and damage range per subtype) -* five survivor classes with distinct attributes, skills and starting kits -* HP and AP: body armour provides a depletable armour-point pool -* armour vials restore AP from belt slots; acid bypasses AP +* one priest character with a randomly generated name and starting Rite +* HP and AP: equipped robe shards provide a depletable armour-point pool +* shards drain in slot order, break at 0 AP and can be replaced; acid bypasses AP * blood, corpses and limbs -* five player slots: Hands, Body and three belt slots; two belt slots start unlocked -* one-line HUD with HP/AP and the ready weapon; one-line message bar +* Hands, Head and a permanently worn Robe with three starting slots +* one-line HUD with HP/AP, the ready weapon and Rite charges; one-line message bar * `~` expands the latest eight messages; `e` opens a non-scrolling equipment overlay * one item maximum per ground tile; dropping onto an occupied tile is refused -* skills, skill checks, experience, levels and free skill points +* experience is stored for now; player levels and skill points are removed * auto-opening doors, portals, bashing, acid/fire/smoke, rain * options screen wired to the gameplay (AI, doors, god/ghost mode, …) * JSON save/load for the current development format; older saves may break diff --git a/documentation/README.md b/documentation/README.md index 5434891..afe47db 100644 --- a/documentation/README.md +++ b/documentation/README.md @@ -34,7 +34,7 @@ postponed. | Player experience adjustments (classes, intro, HUD, viewport) | Done | [systems/player-experience-adjustments.md](plans/systems/player-experience-adjustments.md) | | Cardinal movement (remove diagonals, unified hjkl controls) | Done | [systems/cardinal-movement.md](plans/systems/cardinal-movement.md) | | Monster AI and cardinal pathfinding | Done | [systems/monster-ai-pathfinding.md](plans/systems/monster-ai-pathfinding.md) | -| Priest player revamp (random rites, robe slots, holy gear; demon end-game deferred) | Proposed | [systems/priest-player-revamp.md](plans/systems/priest-player-revamp.md) | +| Priest player revamp (random rites, robe slots, holy gear; demon end-game deferred) | In progress | [systems/priest-player-revamp.md](plans/systems/priest-player-revamp.md) | | Player and monster states (bleeding, burning, poison, fear, etc.) | Not planned yet | [systems/player-monster-states.md](plans/systems/player-monster-states.md) | | Caves levels 9–17 | Not planned yet | [plans/caves.md](plans/caves.md) | | Temple of the Underminer levels 18–26 | Not planned yet | [plans/temple.md](plans/temple.md) | diff --git a/documentation/plans/README.md b/documentation/plans/README.md index b0a8b34..9abbeb8 100644 --- a/documentation/plans/README.md +++ b/documentation/plans/README.md @@ -40,7 +40,7 @@ revamp plans are written. | Player experience adjustments — classes, intro, one-line HUD, 80×25 layout | Done | [systems/player-experience-adjustments.md](systems/player-experience-adjustments.md) | | Cardinal movement — remove diagonals, unified hjkl controls | Done | [systems/cardinal-movement.md](systems/cardinal-movement.md) | | Monster AI and cardinal pathfinding | Done | [systems/monster-ai-pathfinding.md](systems/monster-ai-pathfinding.md) | -| Priest player revamp — random rites, robe slots, holy gear, zombie variants; demon end-game separate | Proposed | [systems/priest-player-revamp.md](systems/priest-player-revamp.md) | +| Priest player revamp — random rites, robe slots, holy gear, zombie variants; demon end-game separate | In progress | [systems/priest-player-revamp.md](systems/priest-player-revamp.md) | | Player and monster states — bleeding, burning, poison, fear, immobilize | Not planned yet | [systems/player-monster-states.md](systems/player-monster-states.md) | The woods plan intentionally includes the first pass of: diff --git a/documentation/plans/systems/priest-player-revamp.md b/documentation/plans/systems/priest-player-revamp.md index 8ed928e..474746e 100644 --- a/documentation/plans/systems/priest-player-revamp.md +++ b/documentation/plans/systems/priest-player-revamp.md @@ -1,6 +1,6 @@ # Priest Player Revamp — Random Rite, Robe Slots and Holy Gear -Status: **proposed** +Status: **in progress** Parent: [Feature plans](../README.md) Related: [Player redesign](player-redesign.md), [Player experience adjustments](player-experience-adjustments.md), [Woods minimalist snake redesign](../woods/minimalist-snake-redesign.md), [Player and monster states](player-monster-states.md) Scope: player identity, one random starting rite plus one shrine rite, intro, robe/head/slot equipment, priest-themed items and zombie/villager variants. @@ -15,6 +15,13 @@ A separate end-game plan will cover the demon finale and the stone-circle map. Player and monster states such as bleeding will also get a separate plan. Neither is part of this revamp. +Implementation status: the first slice is implemented — no class selection, +priest/rite generation, development reroll, Hands/Head/Robe slots, vials and +shards with sequential breakage, no baseline auto-healing, XP stored without +levels and HUD rite charges. The shrine/second rite, flasks, head-item effects, +robe-slot upgrades, villager variants, states and demon end-game remain for +later slices. + --- ## 1. Goals @@ -406,36 +413,36 @@ These are ideas, not locked decisions: ## 13. Acceptance criteria -- [ ] There is no class-selection screen. -- [ ] The player is always a priest with a randomly generated name. -- [ ] Perks and numeric skill values are removed. -- [ ] The priest starts with exactly one random Rite. +- [x] There is no class-selection screen. +- [x] The player is always a priest with a randomly generated name. +- [x] Perks and numeric skill values are removed. +- [x] The priest starts with exactly one random Rite. - [ ] A single shrine per run grants exactly one additional random Rite. -- [ ] Each Rite has one charge per map, refreshed on entry. -- [ ] The HUD shows the available Rite and its remaining charge. -- [ ] The intro is generated from the assigned Rite and starting kit. -- [ ] Hidden `r` rerolls everything during development. -- [ ] STR/TGH/AGI/INT and player-facing levels are removed. -- [ ] XP is still stored but does not grant levels yet. -- [ ] There is no baseline automatic healing. +- [x] Each Rite has one charge per map, refreshed on entry. +- [x] The HUD shows the available Rite and its remaining charge. +- [x] The intro is generated from the assigned Rite and starting kit. +- [x] Hidden `r` rerolls everything during development. +- [x] STR/TGH/AGI/INT and player-facing levels are removed. +- [x] XP is still stored but does not grant levels yet. +- [x] There is no baseline automatic healing. - [ ] Any later regeneration must be a Rite, relic or separate progression decision, not a perk. -- [ ] Equipment is limited to Hands, Head and the permanently worn Robe. +- [x] Equipment is limited to Hands, Head and the permanently worn Robe. - [ ] The robe starts with three slots and can gain more during the adventure. -- [ ] Each robe slot holds exactly one vial, flask, shard or small item. -- [ ] Vials restore a small flat amount of HP. +- [x] Each robe slot holds exactly one vial, flask, shard or small item. +- [x] Vials restore a small flat amount of HP. - [ ] Flasks are throwable and occupy one slot. -- [ ] Shards provide different maximum AP values. -- [ ] Damage drains shards in order; a shard at 0 AP breaks and frees its slot. -- [ ] Excess shard damage carries to the next shard and then HP. -- [ ] Drained shards are not repaired and can be replaced. -- [ ] Every starting item fits the priest theme. +- [x] Shards provide different maximum AP values. +- [x] Damage drains shards in order; a shard at 0 AP breaks and frees its slot. +- [x] Excess shard damage carries to the next shard and then HP. +- [x] Drained shards are not repaired and can be replaced. +- [x] Every starting item fits the priest theme. - [ ] Living peasants, militia, runners and thugs have matching zombie versions. - [ ] Zombie kills convert the matching villager type. -- [ ] The game remains readable at 80×25. -- [ ] The Meteor Field remains the final woods map until the separate demon +- [x] The game remains readable at 80×25. +- [x] The Meteor Field remains the final woods map until the separate demon end-game plan is implemented. -- [ ] Bleeding and other player/monster states are deferred to their separate plan. +- [x] Bleeding and other player/monster states are deferred to their separate plan. ## 14. Open questions diff --git a/internal/game/actions.go b/internal/game/actions.go index 3d1ff91..7c95985 100644 --- a/internal/game/actions.go +++ b/internal/game/actions.go @@ -23,16 +23,11 @@ func (g *Game) EndPlayerTurn() { } } } - if g.Turn%10 == 0 && g.Player.IsAlive() { - heal := 1 + g.Player.Skill(SkillMetabolism)/25 - g.Player.HP += heal - if g.Player.HP > g.Player.MaxHP { - g.Player.HP = g.Player.MaxHP - } - g.Player.Blood = max(0, g.Player.Blood-1) - } g.updateWeather() g.UpdateMonsters() + if g.PeaceTurns > 0 { + g.PeaceTurns-- + } g.decayTileEffects() g.UpdateFOV() if !g.Player.IsAlive() { diff --git a/internal/game/ai.go b/internal/game/ai.go index 3e1a062..fa818e5 100644 --- a/internal/game/ai.go +++ b/internal/game/ai.go @@ -59,6 +59,26 @@ func (g *Game) MonsterTurn(c *Critter) { c.Path = nil c.Stuck = 0 } + if c.Align == AlignEnemy { + if c.Immobile > 0 { + c.Immobile-- + return + } + if c.Flee > 0 { + c.Flee-- + if g.Player != nil && g.Player.IsAlive() { + g.stepAway(c, g.Player.X, g.Player.Y) + } + return + } + if g.PeaceTurns > 0 { + if g.Roll(100) < 80 { + return + } + g.wander(c) + return + } + } switch c.AI { case AIObserver: p := g.Player diff --git a/internal/game/combat.go b/internal/game/combat.go index f5bc0c2..35c60b8 100644 --- a/internal/game/combat.go +++ b/internal/game/combat.go @@ -216,7 +216,7 @@ func (g *Game) DamageCritter(target *Critter, dmg int, source *Critter, dtype in return } if target.Player { - // AP absorbs a percentage of non-acid damage. Acid bypasses armour. + // Legacy body armour is kept only for old saves. New games use shards. if dtype != 2 { if arm := target.Slots.Body; arm != nil { if stats, ok := ArmorStatsFor(arm.Def()); ok { @@ -233,6 +233,8 @@ func (g *Game) DamageCritter(target *Critter, dmg int, source *Critter, dtype in } } } + } else { + dmg = g.damagePlayerShards(dmg) } } } else if arm := target.Equip[EquipArmor]; arm != nil { @@ -293,7 +295,6 @@ func (g *Game) KillCritter(target, killer *Critter) { xp := target.XP g.Player.XP += xp g.Msg(fmt.Sprintf("you gain %d experience points.", xp), 10) - g.CheckLevelUp() } if target.Align == AlignVillager && killer != nil && killer.Align == AlignEnemy && killer.Class == 1 { g.PendingRises = append(g.PendingRises, PendingRise{X: target.X, Y: target.Y, Turns: 1 + g.Roll(3)}) diff --git a/internal/game/game_test.go b/internal/game/game_test.go index ddc047e..b6d904c 100644 --- a/internal/game/game_test.go +++ b/internal/game/game_test.go @@ -234,35 +234,32 @@ func TestActiveScope(t *testing.T) { } } -func TestPlayerSlotsStartAndBeltUnlock(t *testing.T) { +func TestPriestStartsWithRobeShardVialAndRite(t *testing.T) { g := NewGame(31) g.SetupNewGame(0, "tester") - if g.Player.Slots.Hands == nil || g.Player.Slots.Body == nil { - t.Fatal("starting hands/body missing") + if g.Player.Slots.Hands == nil || g.Player.Slots.Hands.Name() != "sickle" { + t.Fatal("starting weapon missing") } - if g.Player.Slots.BeltUnlocked != 2 { - t.Fatalf("starting belt unlock = %d, want 2", g.Player.Slots.BeltUnlocked) + if g.Player.Slots.RobeSlots != 3 { + t.Fatalf("robe slots = %d, want 3", g.Player.Slots.RobeSlots) } - if g.Player.Slots.Belt[0] == nil { - t.Fatal("starting belt item missing") + if g.Player.Slots.Robe[0] == nil || g.Player.Slots.Robe[0].Def().Kind != KindShard { + t.Fatal("starting shard missing") } - if g.Player.Slots.Belt[1] != nil { - t.Fatal("second belt slot should start empty for loot") + if g.Player.Slots.Robe[1] == nil || g.Player.Slots.Robe[1].Def().Kind != KindMedical { + t.Fatal("starting vial missing") } - if g.Player.Slots.Belt[2] != nil { - t.Fatal("third belt slot should start empty and locked") + if g.Player.Slots.Robe[2] != nil { + t.Fatal("third robe slot should start empty") } - g.Player.Level = 2 - g.Player.XP = 400 - g.CheckLevelUp() - if g.Player.Slots.BeltUnlocked != 2 { - t.Fatalf("belt unlock before level 6 = %d, want 2", g.Player.Slots.BeltUnlocked) + if len(g.KnownRites()) != 1 { + t.Fatalf("known rites = %d, want 1", len(g.KnownRites())) } - g.Player.Level = 5 - g.Player.XP = 1000 - g.CheckLevelUp() - if g.Player.Slots.BeltUnlocked != 3 { - t.Fatalf("belt unlock after level 6 = %d", g.Player.Slots.BeltUnlocked) + if g.RiteCharges[0] != 1 { + t.Fatalf("starting rite charge = %d, want 1", g.RiteCharges[0]) + } + if g.Player.Level != 1 { + t.Fatalf("player level = %d, want 1", g.Player.Level) } } @@ -271,9 +268,7 @@ func TestPickupAutoPlaceAndOneItemPerTile(t *testing.T) { g.SetupNewGame(0, "tester") g.State = StatePlaying g.Player.Slots.Hands = nil - g.Player.Slots.Body = nil - g.Player.Slots.Belt = [3]*Item{} - g.Player.Slots.BeltUnlocked = 1 + g.Player.Slots.Robe = [MaxRobeSlots]*Item{} it := &Item{Proto: 8, X: g.Player.X, Y: g.Player.Y} g.Items = append(g.Items, it) @@ -287,11 +282,11 @@ func TestPickupAutoPlaceAndOneItemPerTile(t *testing.T) { // One item per tile: refusing to drop when occupied. dropped := &Item{Proto: 47, X: -1, Y: -1, Charges: 1} - g.Player.Slots.Belt[0] = dropped + g.Player.Slots.Robe[0] = dropped occupied := &Item{Proto: 48, X: g.Player.X, Y: g.Player.Y, Charges: 5} g.Items = append(g.Items, occupied) - g.DropSlot(SlotBelt1) - if g.Player.Slots.Belt[0] != dropped { + g.DropSlot(SlotRobe1) + if g.Player.Slots.Robe[0] != dropped { t.Fatal("drop should have been refused on an occupied tile") } } @@ -299,11 +294,14 @@ func TestPickupAutoPlaceAndOneItemPerTile(t *testing.T) { func TestPlayerSlotSaveRoundtrip(t *testing.T) { g := NewGame(33) g.SetupNewGame(1, "tester") - g.Player.Slots.BeltUnlocked = 3 - g.Player.Slots.Belt[1] = &Item{Proto: 41, X: -1, Y: -1} - g.Player.Slots.Belt[2] = &Item{Proto: 47, X: -1, Y: -1, Charges: 1} - ensureArmorAP(g.Player.Slots.Body) - g.Player.Slots.Body.AP = 7 + g.Player.Slots.Head = &Item{Proto: itemProtoByName("plain hat"), X: -1, Y: -1} + g.Player.Slots.Robe[0] = &Item{Proto: itemProtoByName("chain shard"), X: -1, Y: -1} + ensureShardAP(g.Player.Slots.Robe[0]) + g.Player.Slots.Robe[1] = &Item{Proto: itemProtoByName("healing vial"), X: -1, Y: -1, Charges: 1} + g.Player.Slots.Robe[2] = &Item{Proto: 47, X: -1, Y: -1, Charges: 1} + g.Player.Slots.RobeSlots = 3 + g.PlayerRites[1] = RiteSmite + g.RiteCharges[1] = 1 path := filepath.Join(t.TempDir(), "slots.json") if err := g.SaveGame(path); err != nil { t.Fatal(err) @@ -312,17 +310,23 @@ func TestPlayerSlotSaveRoundtrip(t *testing.T) { if err := g2.LoadGame(path); err != nil { t.Fatal(err) } - if g2.Player.Slots.Hands == nil || g2.Player.Slots.Body == nil { + if g2.Player.Slots.Hands == nil || g2.Player.Slots.Head == nil { t.Fatal("slots not restored") } - if g2.Player.Slots.BeltUnlocked != 3 { - t.Fatalf("belt unlock lost: %d", g2.Player.Slots.BeltUnlocked) + if g2.Player.Slots.RobeSlots != 3 { + t.Fatalf("robe slots lost: %d", g2.Player.Slots.RobeSlots) + } + if g2.Player.Slots.Robe[0] == nil || g2.Player.Slots.Robe[0].Name() != "chain shard" { + t.Fatal("shard not restored") } - if g2.Player.Slots.Belt[1] == nil || g2.Player.Slots.Belt[1].Proto != 41 { - t.Fatal("belt 2 item lost") + if g2.Player.Slots.Robe[0].AP != 5 { + t.Fatalf("shard AP not restored: %d", g2.Player.Slots.Robe[0].AP) } - if g2.Player.Slots.Body == nil || g2.Player.Slots.Body.AP != 7 { - t.Fatal("armour AP not restored") + if g2.Player.Slots.Head.Name() != "plain hat" { + t.Fatal("head item not restored") + } + if g2.PlayerRites[1] != RiteSmite || g2.RiteCharges[1] != 1 { + t.Fatal("second rite not restored") } } @@ -352,52 +356,46 @@ func TestPlayerSlotMigration(t *testing.T) { } } -func TestArmorAPAbsorption(t *testing.T) { +func TestShardsDrainSequentiallyAndBreak(t *testing.T) { g := NewGame(41) g.SetupNewGame(0, "tester") - arm := g.Player.Slots.Body - if arm == nil { - t.Fatal("starting armour missing") - } - ensureArmorAP(arm) - if arm.AP != 20 { - t.Fatalf("starting AP = %d, want 20", arm.AP) - } + g.Player.Slots.Robe[0] = &Item{Proto: itemProtoByName("leather shard"), X: -1, Y: -1} + g.Player.Slots.Robe[1] = &Item{Proto: itemProtoByName("chain shard"), X: -1, Y: -1} + ensureShardAP(g.Player.Slots.Robe[0]) + ensureShardAP(g.Player.Slots.Robe[1]) hp := g.Player.HP - g.DamageCritter(g.Player, 20, nil, 0) - if arm.AP != 10 { - t.Fatalf("AP after 20 damage = %d, want 10", arm.AP) + + g.DamageCritter(g.Player, 6, nil, 0) + if g.Player.Slots.Robe[0] != nil { + t.Fatal("first shard should have broken") + } + if g.Player.Slots.Robe[1] == nil || g.Player.Slots.Robe[1].AP != 2 { + t.Fatal("second shard did not absorb the remaining damage") } - if g.Player.HP != hp-10 { - t.Fatalf("HP after absorbed damage = %d, want %d", g.Player.HP, hp-10) + if g.Player.HP != hp { + t.Fatalf("HP changed while shards remained: %d -> %d", hp, g.Player.HP) } - // Acid bypasses AP completely. - apBefore := arm.AP - hp = g.Player.HP - g.DamageCritter(g.Player, 10, nil, 2) - if arm.AP != apBefore { - t.Fatalf("acid changed AP: %d -> %d", apBefore, arm.AP) + g.DamageCritter(g.Player, 3, nil, 0) + if g.Player.Slots.Robe[1] != nil { + t.Fatal("second shard should have broken") } - if g.Player.HP != hp-10 { - t.Fatalf("acid HP damage = %d, want 10", hp-g.Player.HP) + if g.Player.HP != hp-1 { + t.Fatalf("excess damage did not reach HP: %d -> %d", hp, g.Player.HP) } } -func TestArmorVialRestoresAP(t *testing.T) { +func TestHealingVialRestoresHP(t *testing.T) { g := NewGame(42) g.SetupNewGame(0, "tester") - g.Player.Slots.BeltUnlocked = 1 - g.Player.Slots.Belt[0] = &Item{Proto: ArmourVialProto, X: -1, Y: -1, Charges: 1} - ensureArmorAP(g.Player.Slots.Body) - g.Player.Slots.Body.AP = 5 - g.UseSlot(SlotBelt1) - cur, _ := armorAP(g.Player.Slots.Body) - if cur != 15 { - t.Fatalf("AP after vial = %d, want 15", cur) - } - if g.Player.Slots.Belt[0] != nil { - t.Fatal("empty vial remained in belt") + g.Player.HP = 10 + vial := g.Player.Slots.Robe[1] + g.UseSlot(SlotRobe2) + if g.Player.HP != 15 { + t.Fatalf("vial healed to %d, want 15", g.Player.HP) + } + if g.Player.Slots.Robe[1] != nil || vial == nil { + t.Fatal("empty vial was not removed from the robe") } } diff --git a/internal/game/map.go b/internal/game/map.go index 633e375..9d3288f 100644 --- a/internal/game/map.go +++ b/internal/game/map.go @@ -451,6 +451,8 @@ func (g *Game) finishLevel(m *Map, level, theme int) { g.Options["optGameLevelID"] = level g.Theme = theme g.Weather = WeatherClear + g.PeaceTurns = 0 + g.RefreshRiteCharges() if theme == 0 { woodsTheme := g.currentWoodsTheme() g.spawnWoodsPopulation(woodsTheme) @@ -787,16 +789,23 @@ func (g *Game) SpawnCritter(proto, x, y int) *Critter { } func (g *Game) SetupNewGame(class int, name string) { - if class < 0 || class >= len(PlayerClasses) { - class = 0 + // The class argument is kept for old callers; the priest is always the + // same character now. + _ = class + if name != "" { + g.PlayerName = name + } + if g.PlayerName == "" { + g.PlayerName = PriestNames[g.Roll(len(PriestNames))] + } + if g.PlayerRites[0] < 0 || g.PlayerRites[0] >= len(RiteDefs) { + g.RollPriestProfile() } - g.PlayerClass = class - g.PlayerName = name g.WoodLoot = newWoodLootAssignment(g.RNG) g.WoodsRun = newWoodsRun(g.RNG) g.Player = &Critter{ Proto: -1, - Name: name, + Name: g.PlayerName, Player: true, Align: AlignPlayer, Class: 4, @@ -804,14 +813,13 @@ func (g *Game) SetupNewGame(class int, name string) { Color: 14, Glyph: '@', Dead: false, + STR: 9, + TGH: 10, + AGI: 9, + INT: 9, + SPD: 2, + Skills: [NumSkills]int{55, 50, 30, 60, 0, 40, 50, 55, 30}, } - c := &PlayerClasses[class] - g.Player.STR = c.STR - g.Player.TGH = c.TGH - g.Player.AGI = c.AGI - g.Player.INT = c.INT - g.Player.SPD = 2 - g.Player.Skills = c.Skills g.Player.MaxHP = g.Player.TGH * 3 g.Player.HP = g.Player.MaxHP g.Player.Level = 1 @@ -819,20 +827,15 @@ func (g *Game) SetupNewGame(class int, name string) { g.Player.Gold = 0 g.Player.Blood = 0 g.Player.Poison = 0 - g.Player.Slots = PlayerSlots{BeltUnlocked: 2} - kit := ClassStartingKit(class) - g.Player.Slots.Hands = startingItem(kit.Hands) + g.Player.Slots = PlayerSlots{RobeSlots: 3} + g.Player.Slots.Hands = g.priestStartingItem("sickle") if g.Player.Slots.Hands != nil { g.Player.Slots.Hands.Active = true } - g.Player.Slots.Body = startingItem(kit.Body) - ensureArmorAP(g.Player.Slots.Body) - for i, proto := range kit.Belt { - if i >= 2 { - break - } - g.Player.Slots.Belt[i] = startingItem(proto) - } + g.Player.Slots.Robe[0] = g.priestStartingItem("leather shard") + g.Player.Slots.Robe[1] = g.priestStartingItem("healing vial") + g.RiteCharges = [MaxRites]int{} + g.RefreshRiteCharges() g.Level = 0 g.Turn = 0 g.Messages = nil diff --git a/internal/game/palette_roles.go b/internal/game/palette_roles.go index ec087c7..6f4493e 100644 --- a/internal/game/palette_roles.go +++ b/internal/game/palette_roles.go @@ -144,6 +144,10 @@ func ItemColorRole(proto int) (ColorRole, bool) { return RoleFireEmber, true case KindMedical, KindFood: return RoleHealthGood, true + case KindShard: + return RoleSteel, true + case KindHead: + return RoleLeather, true case KindBodyPart: return RoleGuts, true } diff --git a/internal/game/player_experience_test.go b/internal/game/player_experience_test.go index 8099c85..911af28 100644 --- a/internal/game/player_experience_test.go +++ b/internal/game/player_experience_test.go @@ -65,35 +65,36 @@ func TestPlayerClassRoster(t *testing.T) { } } -func TestSetupNewGameUsesClassValuesAndKit(t *testing.T) { - for class, def := range PlayerClasses { - g := NewGame(int64(100 + class)) - g.SetupNewGame(class, "tester") - if g.Player.STR != def.STR || g.Player.TGH != def.TGH || - g.Player.AGI != def.AGI || g.Player.INT != def.INT { - t.Fatalf("%s attributes do not match class data", def.Name) +func TestSetupNewGameCreatesPriestProfileAndKit(t *testing.T) { + for seed := int64(100); seed < 108; seed++ { + g := NewGame(seed) + g.SetupNewGame(0, "tester") + if g.Player.Name != "tester" { + t.Fatalf("player name = %q", g.Player.Name) } - if g.Player.Skills != def.Skills { - t.Fatalf("%s skills do not match class data", def.Name) + if len(g.KnownRites()) != 1 { + t.Fatalf("seed %d has %d rites, want 1", seed, len(g.KnownRites())) } - if g.Player.Slots.BeltUnlocked != 2 { - t.Fatalf("%s starts with %d belt slots, want 2", def.Name, g.Player.Slots.BeltUnlocked) + if g.RiteCharges[0] != 1 { + t.Fatalf("seed %d rite charge = %d", seed, g.RiteCharges[0]) } - kit := ClassStartingKit(class) - if g.Player.Slots.Hands == nil || g.Player.Slots.Hands.Proto != kit.Hands { - t.Fatalf("%s starting hands do not match kit", def.Name) + if g.Player.Slots.Hands == nil || g.Player.Slots.Hands.Name() != "sickle" { + t.Fatalf("seed %d starting weapon missing", seed) } - if g.Player.Slots.Body == nil || g.Player.Slots.Body.Proto != kit.Body { - t.Fatalf("%s starting body does not match kit", def.Name) + if g.Player.Slots.RobeSlots != 3 { + t.Fatalf("seed %d robe slots = %d", seed, g.Player.Slots.RobeSlots) } - if g.Player.Slots.Belt[0] == nil || g.Player.Slots.Belt[0].Proto != kit.Belt[0] { - t.Fatalf("%s starting belt 1 does not match kit", def.Name) + if g.Player.Slots.Robe[0] == nil || g.Player.Slots.Robe[0].Name() != "leather shard" { + t.Fatalf("seed %d starting shard missing", seed) } - if g.Player.Slots.Belt[1] != nil { - t.Fatalf("%s should start with belt 2 empty", def.Name) + if g.Player.Slots.Robe[1] == nil || g.Player.Slots.Robe[1].Name() != "healing vial" { + t.Fatalf("seed %d starting vial missing", seed) } - if g.Player.Slots.Belt[2] != nil { - t.Fatalf("%s starts with an item in locked belt 3", def.Name) + if g.Player.Slots.Robe[2] != nil { + t.Fatalf("seed %d third robe slot should start empty", seed) + } + if g.Player.Slots.Body != nil || g.Player.Slots.BeltUnlocked != 0 { + t.Fatalf("seed %d still uses legacy body/belt slots", seed) } } } @@ -170,9 +171,12 @@ func TestHUDIsOneLine(t *testing.T) { if !strings.Contains(hud, "HP ") || !strings.Contains(hud, "AP ") { t.Fatalf("HUD missing HP/AP: %q", hud) } - if !strings.Contains(hud, "hammer") { + if !strings.Contains(hud, "sickle") { t.Fatalf("HUD missing weapon name: %q", hud) } + if !strings.Contains(hud, "Rite:") { + t.Fatalf("HUD missing rite: %q", hud) + } if strings.Contains(hud, "[a]") || strings.Contains(hud, "Lvl") { t.Fatalf("HUD still contains old slot/level text: %q", hud) } @@ -204,21 +208,24 @@ func TestLookOverlayUsesReadablePanelColours(t *testing.T) { } } -func TestCharCreateShowsFiveClassesAndKit(t *testing.T) { +func TestIntroShowsGeneratedPriestAndRite(t *testing.T) { g := NewGame(703) u, s := newTestUI(g, ColorModeTrueColor) defer s.Fini() - u.classSel = len(PlayerClasses) - 1 - u.drawCharCreate() + u.drawIntro() s.Show() text := screenText(s) - for _, class := range PlayerClasses { - if !strings.Contains(text, class.Name) { - t.Fatalf("class selection missing %q", class.Name) - } + if !strings.Contains(text, g.PlayerName) { + t.Fatalf("intro missing priest name %q", g.PlayerName) + } + if !strings.Contains(text, "Rite:") || !strings.Contains(text, RiteDefs[g.PlayerRites[0]].Name) { + t.Fatalf("intro missing generated rite: %q", text) + } + if strings.Contains(text, "select class") { + t.Fatal("intro still shows class selection") } - if !strings.Contains(text, "hands: crowbar") { - t.Fatalf("class selection missing starting kit: %q", text) + if !strings.Contains(text, "press enter to begin") { + t.Fatal("intro missing start prompt") } } @@ -233,8 +240,8 @@ func TestInventoryGetPicksUpItem(t *testing.T) { if g.ItemAt(g.Player.X, g.Player.Y) != nil { t.Fatal("item was not removed from the ground") } - if g.Player.Slots.Belt[1] == nil || g.Player.Slots.Belt[1].Proto != 48 { - t.Fatal("picked-up item was not placed in the free belt slot") + if g.Player.Slots.Robe[2] == nil || g.Player.Slots.Robe[2].Proto != 48 { + t.Fatal("picked-up item was not placed in the free robe slot") } if g.State != StateInventory { t.Fatalf("inventory closed after pickup: state %v", g.State) diff --git a/internal/game/player_slots.go b/internal/game/player_slots.go index aa72ae5..32a73b0 100644 --- a/internal/game/player_slots.go +++ b/internal/game/player_slots.go @@ -28,6 +28,18 @@ func (c *Critter) SlotItem(slot int) *Item { if c.Slots.BeltUnlocked >= 3 { return c.Slots.Belt[2] } + case SlotHead: + return c.Slots.Head + case SlotRobe1: + return c.RobeSlot(0) + case SlotRobe2: + return c.RobeSlot(1) + case SlotRobe3: + return c.RobeSlot(2) + case SlotRobe4: + return c.RobeSlot(3) + case SlotRobe5: + return c.RobeSlot(4) } return nil } @@ -53,6 +65,18 @@ func (c *Critter) SetSlotItem(slot int, it *Item) { if c.Slots.BeltUnlocked >= 3 { c.Slots.Belt[2] = it } + case SlotHead: + c.Slots.Head = it + case SlotRobe1: + c.SetRobeSlot(0, it) + case SlotRobe2: + c.SetRobeSlot(1, it) + case SlotRobe3: + c.SetRobeSlot(2, it) + case SlotRobe4: + c.SetRobeSlot(3, it) + case SlotRobe5: + c.SetRobeSlot(4, it) } } @@ -119,10 +143,9 @@ func (c *Critter) AutoPlaceItem(it *Item) bool { if d == nil { return false } - if d.Kind == KindArmor { - if c.Slots.Body == nil { - ensureArmorAP(it) - c.Slots.Body = it + if d.Kind == KindHead { + if c.Slots.Head == nil { + c.Slots.Head = it return true } return false @@ -131,8 +154,11 @@ func (c *Critter) AutoPlaceItem(it *Item) bool { c.Slots.Hands = it return true } - if i := c.FirstFreeBelt(); i >= 0 { - c.Slots.Belt[i] = it + if i := c.FirstFreeRobeSlot(); i >= 0 { + if d.Kind == KindShard { + ensureShardAP(it) + } + c.Slots.Robe[i] = it return true } return false @@ -366,6 +392,36 @@ func (g *Game) UseSlot(slot int) { default: g.Msg("you cannot use "+d.Name+" from the belt.", 8) } + case SlotHead: + g.Msg("you wear "+d.Name+".", 8) + case SlotRobe1, SlotRobe2, SlotRobe3, SlotRobe4, SlotRobe5: + switch d.Kind { + case KindMedical: + if g.playerConsumeMedical(it) { + if it.Charges <= 0 { + g.Player.SetSlotItem(slot, nil) + } + g.EndPlayerTurn() + } + case KindFood: + if g.playerConsumeFood(it) { + if it.Charges <= 0 { + g.Player.SetSlotItem(slot, nil) + } + g.EndPlayerTurn() + } + case KindShard: + ensureShardAP(it) + g.Msg(fmt.Sprintf("your %s has %d/%d AP.", d.Name, it.AP, shardMaxAP(it)), 8) + case KindRelic: + g.Msg("you turn the "+d.Name+" over. it is a relic of the old world.", 8) + case KindTool: + if g.playerUseTool(it) { + g.EndPlayerTurn() + } + default: + g.Msg("you cannot use "+d.Name+" from the robe.", 8) + } } } diff --git a/internal/game/priest.go b/internal/game/priest.go new file mode 100644 index 0000000..afdb8fa --- /dev/null +++ b/internal/game/priest.go @@ -0,0 +1,125 @@ +package game + +import ( + "fmt" + "strings" +) + +const RiteNone = -1 + +const ( + RiteBlessing = iota + RiteHealingWounds + RiteShout + RiteBanish + RiteImmobilize + RiteSmite + RiteSanctuary +) + +type RiteDef struct { + Name string + Desc string +} + +var RiteDefs = []RiteDef{ + {Name: "Blessing", Desc: "restore 2 AP to the most damaged shard."}, + {Name: "Healing Wounds", Desc: "restore 5 HP."}, + {Name: "Shout", Desc: "drive nearby enemies away for 3 turns."}, + {Name: "Banish", Desc: "repel undead; weak undead are removed."}, + {Name: "Immobilize", Desc: "hold one enemy in place for 3 turns."}, + {Name: "Smite", Desc: "strike one visible enemy with holy damage."}, + {Name: "Sanctuary", Desc: "enemies lose interest for 3 turns."}, +} + +var PriestNames = []string{ + "Father Aleksy", "Father Barnaba", "Father Cyryl", "Father Damian", + "Father Eliasz", "Father Feliks", "Father Grzegorz", "Father Hieronim", + "Father Ignacy", "Father Jakub", "Father Kazimierz", "Father Leon", + "Father Mateusz", "Father Mikołaj", "Father Piotr", "Father Rafał", + "Father Szymon", "Father Tomasz", "Father Urban", "Father Wiktor", +} + +func (g *Game) RollPriestProfile() { + g.PlayerName = PriestNames[g.Roll(len(PriestNames))] + g.PlayerRites = [MaxRites]int{RiteNone, RiteNone} + g.RiteCharges = [MaxRites]int{} + g.PlayerRites[0] = g.Roll(len(RiteDefs)) + g.RiteCharges[0] = 1 +} + +func (g *Game) KnownRites() []int { + var out []int + for _, rite := range g.PlayerRites { + if rite >= 0 && rite < len(RiteDefs) { + out = append(out, rite) + } + } + return out +} + +func (g *Game) RefreshRiteCharges() { + for i, rite := range g.PlayerRites { + if rite >= 0 && rite < len(RiteDefs) { + g.RiteCharges[i] = 1 + } + } +} + +func riteName(rite int) string { + if rite < 0 || rite >= len(RiteDefs) { + return "none" + } + return RiteDefs[rite].Name +} + +func (g *Game) RiteSummary() string { + parts := make([]string, 0, MaxRites) + for i, rite := range g.PlayerRites { + if rite < 0 || rite >= len(RiteDefs) { + continue + } + parts = append(parts, fmt.Sprintf("%s %d", riteName(rite), g.RiteCharges[i])) + } + if len(parts) == 0 { + return "Rite: none" + } + return "Rite: " + strings.Join(parts, " ") +} + +func (g *Game) priestStartingItem(name string) *Item { + proto := itemProtoByName(name) + if proto < 0 { + return nil + } + it := startingItem(proto) + if it != nil && it.Def() != nil && it.Def().Kind == KindShard { + ensureShardAP(it) + } + return it +} + +func init() { + addItem := func(d ItemDef) { + ItemDefs = append(ItemDefs, d) + } + addItem(ItemDef{ + Name: "healing vial", Desc: "a small vial of bitter healing tonic.", + Kind: KindMedical, Weight: 100, Charges: 1, Heal: 5, Glyph: '!', Color: 10, + }) + shard := func(name, desc string, maxAP int, glyph byte, color uint8) { + addItem(ItemDef{ + Name: name, Desc: desc, Kind: KindShard, Weight: 200, + Charges: maxAP, Glyph: glyph, Color: color, + }) + } + shard("leather shard", "a hardened leather plate for the robe.", 3, '=', 6) + shard("chain shard", "a small linked-mail plate for the robe.", 5, '=', 7) + shard("iron shard", "a heavy iron plate for the robe.", 7, '=', 8) + shard("silver shard", "a silver plate that turns aside claws.", 9, '=', 15) + shard("blessed shard", "a blessed plate warm to the touch.", 12, '=', 14) + addItem(ItemDef{ + Name: "plain hat", Desc: "a simple weather-stained hat.", Kind: KindHead, + Weight: 100, Glyph: '^', Color: 6, + }) +} diff --git a/internal/game/priest_test.go b/internal/game/priest_test.go new file mode 100644 index 0000000..7604a1f --- /dev/null +++ b/internal/game/priest_test.go @@ -0,0 +1,141 @@ +package game + +import ( + "testing" + + "github.com/gdamore/tcell/v2" +) + +func TestPriestProfileGeneration(t *testing.T) { + for seed := int64(0); seed < 100; seed++ { + g := NewGame(seed) + if g.PlayerName == "" { + t.Fatalf("seed %d has no priest name", seed) + } + if len(g.KnownRites()) != 1 { + t.Fatalf("seed %d has %d starting rites", seed, len(g.KnownRites())) + } + if g.PlayerRites[1] != RiteNone { + t.Fatalf("seed %d starts with a second rite", seed) + } + if g.RiteCharges[0] != 1 { + t.Fatalf("seed %d starting charge = %d", seed, g.RiteCharges[0]) + } + } +} + +func TestRiteChargesRefreshOnNewMap(t *testing.T) { + g := NewGame(15100) + g.SetupNewGame(0, "tester") + g.State = StatePlaying + g.PlayerRites[0] = RiteHealingWounds + g.RiteCharges[0] = 1 + g.Player.HP = 1 + g.UseRite(0) + if g.RiteCharges[0] != 0 { + t.Fatalf("rite charge = %d after use", g.RiteCharges[0]) + } + g.GenerateLevel(1) + if g.RiteCharges[0] != 1 { + t.Fatalf("rite charge = %d after map change, want 1", g.RiteCharges[0]) + } +} + +func TestNoBaselineAutoHealing(t *testing.T) { + g := NewGame(15200) + g.SetupNewGame(0, "tester") + g.State = StatePlaying + g.Options["optGameUseAI"] = 0 + g.Player.HP = g.Player.MaxHP - 5 + for i := 0; i < 25; i++ { + g.WaitTurn() + } + if g.Player.HP != g.Player.MaxHP-5 { + t.Fatalf("baseline healing changed HP: %d -> %d", g.Player.MaxHP-5, g.Player.HP) + } +} + +func TestHealingWoundsRiteConsumesCharge(t *testing.T) { + g := NewGame(15300) + g.SetupNewGame(0, "tester") + g.State = StatePlaying + g.PlayerRites[0] = RiteHealingWounds + g.RiteCharges[0] = 1 + g.Player.HP = 10 + g.UseRite(0) + if g.Player.HP != 15 { + t.Fatalf("Healing Wounds restored to %d, want 15", g.Player.HP) + } + if g.RiteCharges[0] != 0 { + t.Fatalf("charge after use = %d", g.RiteCharges[0]) + } + g.Player.HP = 10 + g.UseRite(0) + if g.Player.HP != 10 { + t.Fatal("rite healed again with no charges") + } +} + +func TestXPGivesNoLevels(t *testing.T) { + g := NewGame(15350) + g.SetupNewGame(0, "tester") + g.Player.XP = 100000 + oldXP := g.Player.XP + oldLevel := g.Player.Level + target := g.SpawnCritter(0, g.Player.X+1, g.Player.Y) + g.DamageCritter(target, 999, g.Player, 0) + if g.Player.XP <= oldXP { + t.Fatal("XP was not awarded") + } + if g.Player.Level != oldLevel { + t.Fatalf("player level changed from %d to %d", oldLevel, g.Player.Level) + } +} + +func TestIntroStartsGameWithoutClassSelection(t *testing.T) { + g := NewGame(15425) + g.State = StateIntro + u := &UI{g: g} + u.handleIntro(tcell.NewEventKey(tcell.KeyEnter, 0, tcell.ModNone)) + if u.g.State != StatePlaying { + t.Fatalf("intro enter state = %v, want playing", u.g.State) + } + if u.g.Map == nil || u.g.Player == nil { + t.Fatal("intro did not start the game") + } +} + +func TestIntroRerollRegeneratesEverything(t *testing.T) { + g := NewGame(15450) + g.State = StateIntro + u := &UI{g: g} + old := g + u.handleIntro(tcell.NewEventKey(tcell.KeyRune, 'r', tcell.ModNone)) + if u.g == old { + t.Fatal("reroll did not create a new game state") + } + if u.g.State != StateIntro { + t.Fatalf("reroll state = %v, want intro", u.g.State) + } + if len(u.g.KnownRites()) != 1 { + t.Fatal("rerolled priest has no starting rite") + } +} + +func TestBlessingRestoresShardAP(t *testing.T) { + g := NewGame(15400) + g.SetupNewGame(0, "tester") + g.State = StatePlaying + g.PlayerRites[0] = RiteBlessing + g.RiteCharges[0] = 1 + shard := g.Player.Slots.Robe[0] + ensureShardAP(shard) + shard.AP = 1 + g.UseRite(0) + if shard.AP != 3 { + t.Fatalf("Blessing restored shard to %d AP, want 3", shard.AP) + } + if g.RiteCharges[0] != 0 { + t.Fatal("Blessing did not consume its charge") + } +} diff --git a/internal/game/rites.go b/internal/game/rites.go new file mode 100644 index 0000000..802bdfb --- /dev/null +++ b/internal/game/rites.go @@ -0,0 +1,147 @@ +package game + +import ( + "fmt" + "strings" +) + +func (g *Game) UseRite(index int) { + if g.Player == nil || g.State != StatePlaying { + return + } + if index < 0 || index >= MaxRites { + return + } + rite := g.PlayerRites[index] + if rite < 0 || rite >= len(RiteDefs) { + g.Msg("you have no rite to use.", 8) + return + } + if g.RiteCharges[index] <= 0 { + g.Msg(fmt.Sprintf("the rite of %s has no charges left on this map.", riteName(rite)), 8) + return + } + used := false + switch rite { + case RiteBlessing: + used = g.blessShards(2) + if !used { + g.Msg("your shards are already fully restored.", 8) + } + case RiteHealingWounds: + if g.Player.HP >= g.Player.MaxHP { + g.Msg("you are already at full health.", 8) + return + } + g.Player.HP += 5 + if g.Player.HP > g.Player.MaxHP { + g.Player.HP = g.Player.MaxHP + } + g.Msg("your wounds close with a prayer.", 10) + used = true + case RiteShout: + targets := 0 + for _, c := range g.Critters { + if c == nil || !c.IsAlive() || c.Align != AlignEnemy { + continue + } + if _, ok := g.canSeeCritter(g.Player, c, 6); !ok { + continue + } + c.Flee = 3 + c.Path = nil + targets++ + } + if targets > 0 { + g.Msg("your shout drives the dead back.", 14) + used = true + } else { + g.Msg("there is nothing nearby to hear your shout.", 8) + } + case RiteBanish: + target := g.nearestRiteTarget(8) + if target == nil { + g.Msg("there is no enemy in sight to banish.", 8) + return + } + if !isUndeadCritter(target) { + g.Msg("the rite only affects the undead.", 8) + return + } + if target.MaxHP <= 18 { + g.Msg("the "+target.NameOrUnknown()+" is banished from this place.", 14) + target.Dead = true + target.HP = 0 + g.RemoveCritter(target) + } else { + target.Flee = 5 + target.Path = nil + g.Msg("the "+target.NameOrUnknown()+" recoils from your prayer.", 14) + } + used = true + case RiteImmobilize: + target := g.nearestRiteTarget(8) + if target == nil { + g.Msg("there is no enemy in sight to hold.", 8) + return + } + target.Immobile = 3 + target.Path = nil + g.Msg("the "+target.NameOrUnknown()+" is held in place.", 14) + used = true + case RiteSmite: + target := g.nearestRiteTarget(8) + if target == nil { + g.Msg("there is no enemy in sight to smite.", 8) + return + } + dmg := 6 + if isUndeadCritter(target) { + dmg += 2 + } + g.Msg("you call down a smiting light.", 14) + g.DamageCritter(target, dmg, g.Player, 0) + used = true + case RiteSanctuary: + g.PeaceTurns = 3 + for _, c := range g.Critters { + if c != nil && c.Align == AlignEnemy { + c.Alert = 0 + c.Path = nil + } + } + g.Msg("a quiet sanctuary settles over the road.", 10) + used = true + } + if used { + g.RiteCharges[index]-- + g.EndPlayerTurn() + } +} + +func (g *Game) nearestRiteTarget(maxDist int) *Critter { + var best *Critter + bestDist := maxDist + 1 + for _, c := range g.Critters { + if c == nil || !c.IsAlive() || c.Align != AlignEnemy { + continue + } + dist, ok := g.canSeeCritter(g.Player, c, maxDist) + if !ok || dist >= bestDist { + continue + } + best, bestDist = c, dist + } + return best +} + +func isUndeadCritter(c *Critter) bool { + if c == nil { + return false + } + name := strings.ToLower(c.NameOrUnknown()) + return strings.Contains(name, "zombie") || + strings.Contains(name, "ghoul") || + strings.Contains(name, "wraith") || + strings.Contains(name, "undead") +} diff --git a/internal/game/save.go b/internal/game/save.go index 961b863..77f5cb7 100644 --- a/internal/game/save.go +++ b/internal/game/save.go @@ -6,7 +6,7 @@ import ( "os" ) -const saveVersion = 4 +const saveVersion = 5 type saveItem struct { Proto int `json:"p"` @@ -20,9 +20,12 @@ type saveItem struct { type saveSlots struct { Hands saveItem `json:"hands"` - Body saveItem `json:"body"` + Body saveItem `json:"body,omitempty"` Belt []saveItem `json:"belt,omitempty"` - BeltUnlocked int `json:"belt_unlocked"` + BeltUnlocked int `json:"belt_unlocked,omitempty"` + Head saveItem `json:"head,omitempty"` + Robe []saveItem `json:"robe,omitempty"` + RobeSlots int `json:"robe_slots,omitempty"` } type saveCritter struct { @@ -56,6 +59,8 @@ type saveCritter struct { LastSeenX int `json:"lsx"` LastSeenY int `json:"lsy"` Alert int `json:"alert"` + Flee int `json:"flee,omitempty"` + Immobile int `json:"immobile,omitempty"` Dead bool `json:"dead"` } @@ -99,6 +104,9 @@ type saveGame struct { Score int `json:"score"` WoodLoot []int `json:"wood_loot,omitempty"` WoodsRun *WoodsRun `json:"woods_run,omitempty"` + PlayerRites []int `json:"player_rites,omitempty"` + RiteCharges []int `json:"rite_charges,omitempty"` + PeaceTurns int `json:"peace_turns,omitempty"` PendingRises []PendingRise `json:"pending_rises,omitempty"` } @@ -123,17 +131,22 @@ func critterToSave(c *Critter) saveCritter { Align: c.Align, Class: c.Class, AI: c.AI, Color: c.Color, Glyph: c.Glyph, Player: c.Player, Energy: c.Energy, Level: c.Level, XP: c.XP, Gold: c.Gold, Blood: c.Blood, Poison: c.Poison, LastSeenX: c.LastSeenX, LastSeenY: c.LastSeenY, - Alert: c.Alert, Dead: c.Dead, + Alert: c.Alert, Flee: c.Flee, Immobile: c.Immobile, Dead: c.Dead, } if c.Player { ss := &saveSlots{ Hands: itemToSave(c.Slots.Hands), Body: itemToSave(c.Slots.Body), BeltUnlocked: c.Slots.BeltUnlocked, + Head: itemToSave(c.Slots.Head), + RobeSlots: c.Slots.RobeSlots, } for _, it := range c.Slots.Belt { ss.Belt = append(ss.Belt, itemToSave(it)) } + for i := 0; i < c.Slots.RobeSlots && i < MaxRobeSlots; i++ { + ss.Robe = append(ss.Robe, itemToSave(c.Slots.Robe[i])) + } s.Slots = ss } else { for _, it := range c.Inventory { @@ -154,7 +167,7 @@ func critterFromSave(s saveCritter, version int) (*Critter, int) { Align: s.Align, Class: s.Class, AI: s.AI, Color: s.Color, Glyph: s.Glyph, Player: s.Player, Energy: s.Energy, Level: s.Level, XP: s.XP, Gold: s.Gold, Blood: s.Blood, Poison: s.Poison, LastSeenX: s.LastSeenX, LastSeenY: s.LastSeenY, - Alert: s.Alert, Dead: s.Dead, + Alert: s.Alert, Flee: s.Flee, Immobile: s.Immobile, Dead: s.Dead, } if s.Player { c.Slots = PlayerSlots{BeltUnlocked: 2} @@ -185,6 +198,36 @@ func critterFromSave(s saveCritter, version int) (*Critter, int) { c.Slots.Belt[i] = it } c.Slots.BeltUnlocked = s.Slots.BeltUnlocked + if version >= 5 { + if it := itemFromSave(s.Slots.Head); it != nil { + if ItemAvailable(it.Proto) { + c.Slots.Head = it + } else { + removed++ + } + } + c.Slots.RobeSlots = s.Slots.RobeSlots + if c.Slots.RobeSlots < 0 { + c.Slots.RobeSlots = 0 + } + if c.Slots.RobeSlots > MaxRobeSlots { + c.Slots.RobeSlots = MaxRobeSlots + } + for i := 0; i < c.Slots.RobeSlots && i < len(s.Slots.Robe); i++ { + it := itemFromSave(s.Slots.Robe[i]) + if it == nil { + continue + } + if !ItemAvailable(it.Proto) { + removed++ + continue + } + if it.Def() != nil && it.Def().Kind == KindShard { + ensureShardAP(it) + } + c.Slots.Robe[i] = it + } + } } else { // Migrate the old inventory/equipment layout into player slots. oldHand := -1 @@ -308,6 +351,9 @@ func (g *Game) SaveGame(path string) error { Score: g.Score, WoodLoot: append([]int(nil), g.WoodLoot[:]...), WoodsRun: &g.WoodsRun, + PlayerRites: append([]int(nil), g.PlayerRites[:]...), + RiteCharges: append([]int(nil), g.RiteCharges[:]...), + PeaceTurns: g.PeaceTurns, PendingRises: append([]PendingRise(nil), g.PendingRises...), } s.Map = saveMap{ @@ -370,6 +416,18 @@ func (g *Game) LoadGame(path string) error { } else { g.WoodsRun = newWoodsRun(g.RNG) } + g.PlayerRites = [MaxRites]int{RiteNone, RiteNone} + for i := 0; i < MaxRites && i < len(s.PlayerRites); i++ { + g.PlayerRites[i] = s.PlayerRites[i] + } + for i := 0; i < MaxRites && i < len(s.RiteCharges); i++ { + g.RiteCharges[i] = s.RiteCharges[i] + } + if g.PlayerRites[0] < 0 || g.PlayerRites[0] >= len(RiteDefs) { + g.PlayerRites[0] = g.Roll(len(RiteDefs)) + g.RiteCharges[0] = 1 + } + g.PeaceTurns = s.PeaceTurns g.Map = &Map{ W: s.Map.W, H: s.Map.H, Tiles: s.Map.Tiles, Seen: s.Map.Seen, Visible: s.Map.Visible, Blood: s.Map.Blood, Fire: s.Map.Fire, Acid: s.Map.Acid, Smoke: s.Map.Smoke, diff --git a/internal/game/scope.go b/internal/game/scope.go index 93f4359..1bfe15b 100644 --- a/internal/game/scope.go +++ b/internal/game/scope.go @@ -113,23 +113,21 @@ var ActiveKeyBindings = []KeyBind{ {Key: 'j', Name: "move to south", Desc: "move player south"}, {Key: 'k', Name: "move to north", Desc: "move player north"}, {Key: 'l', Name: "move to east", Desc: "move player east"}, - {Key: '.', Name: "wait / rest", Desc: "wait, rest and recover health"}, + {Key: '.', Name: "wait", Desc: "wait one turn"}, {Key: 'f', Name: "bash", Desc: "choose a direction and bash an adjacent small obstacle"}, {Key: 'a', Name: "hands action", Desc: "use the Hands item (tool) or report the weapon ready"}, - {Key: 'c', Name: "belt 1 action", Desc: "use, swap or consume belt slot 1"}, - {Key: 'd', Name: "belt 2 action", Desc: "use, swap or consume belt slot 2"}, - {Key: 'r', Name: "belt 3 action", Desc: "use, swap or consume belt slot 3"}, + {Key: 'r', Name: "use rite", Desc: "use the first known rite"}, + {Key: 't', Name: "use second rite", Desc: "use the second known rite"}, {Key: 'A', Name: "drop hands", Desc: "drop the Hands item"}, - {Key: 'B', Name: "drop body", Desc: "unequip and drop Body armour"}, - {Key: 'C', Name: "drop belt 1", Desc: "drop belt slot 1"}, - {Key: 'D', Name: "drop belt 2", Desc: "drop belt slot 2"}, - {Key: 'R', Name: "drop belt 3", Desc: "drop belt slot 3"}, + {Key: 'H', Name: "drop head", Desc: "drop the Head item"}, + {Key: 'C', Name: "drop robe 1", Desc: "drop robe slot 1"}, + {Key: 'D', Name: "drop robe 2", Desc: "drop robe slot 2"}, + {Key: 'R', Name: "drop robe 3", Desc: "drop robe slot 3"}, {Key: 'g', Name: "get item", Desc: "pick up items from the current tile"}, {Key: 'e', Name: "equipment", Desc: "display the equipment overlay"}, {Key: 'v', Name: "view / look", Desc: "look around and examine the surroundings"}, {Key: '~', Name: "message log", Desc: "expand or collapse the latest eight messages"}, {Key: '@', Name: "player screen", Desc: "display character information"}, - {Key: 'x', Name: "skills", Desc: "display and improve skills"}, {Key: 'O', Name: "options", Desc: "display the options screen"}, {Key: '?', Name: "help", Desc: "display this key binding screen"}, {Key: ' ', Name: "close overlay", Desc: "close a modal screen without taking an action"}, diff --git a/internal/game/screens.go b/internal/game/screens.go index 503be8b..3cfb3a3 100644 --- a/internal/game/screens.go +++ b/internal/game/screens.go @@ -11,6 +11,18 @@ func slotName(slot int) string { switch slot { case SlotHands: return "Hands" + case SlotHead: + return "Head" + case SlotRobe1: + return "Robe 1" + case SlotRobe2: + return "Robe 2" + case SlotRobe3: + return "Robe 3" + case SlotRobe4: + return "Robe 4" + case SlotRobe5: + return "Robe 5" case SlotBody: return "Body" case SlotBelt1: @@ -23,18 +35,30 @@ func slotName(slot int) string { return "?" } -var inventorySlots = []int{SlotHands, SlotBody, SlotBelt1, SlotBelt2, SlotBelt3} +func (g *Game) EquipmentSlots() []int { + slots := []int{SlotHands, SlotHead} + for i := 0; i < g.Player.Slots.RobeSlots && i < MaxRobeSlots; i++ { + slots = append(slots, SlotRobe1+i) + } + return slots +} func slotKey(slot int) string { switch slot { case SlotHands: return "a" - case SlotBelt1: + case SlotHead: + return "h" + case SlotRobe1: return "c" - case SlotBelt2: + case SlotRobe2: return "d" - case SlotBelt3: + case SlotRobe3: return "r" + case SlotRobe4: + return "4" + case SlotRobe5: + return "5" } return "-" } @@ -64,7 +88,9 @@ func itemSummary(it *Item) string { return fmt.Sprintf("%s heal %d charges %d", d.Name, d.Heal, it.Charges) case KindFood: return fmt.Sprintf("%s heal %d charges %d", d.Name, d.Heal, it.Charges) - case KindTool, KindRelic: + case KindShard: + return fmt.Sprintf("%s AP max %d", d.Name, d.Charges) + case KindTool, KindRelic, KindHead: return d.Desc default: return d.Name @@ -77,7 +103,7 @@ func (u *UI) drawInventory() { u.putStr(centerText("[ e ] equipment", screenW), 0, "[ e ] equipment", 2, 0) u.putStr(1, 1, "key slot item stats action", 8, 0) - slots := inventorySlots + slots := g.EquipmentSlots() y := 3 for i, slot := range slots { it := g.Player.SlotItem(slot) @@ -86,22 +112,6 @@ func (u *UI) drawInventory() { key = " " } label := slotName(slot) - locked := false - if slot == SlotBelt2 && g.Player.Slots.BeltUnlocked < 2 { - locked = true - } - if slot == SlotBelt3 && g.Player.Slots.BeltUnlocked < 3 { - locked = true - } - if locked { - fg, bg := uint8(8), uint8(0) - if i == u.slotSel { - fg, bg = 0, 7 - } - u.putStr(1, y, fmt.Sprintf("[%s] %-7s %-16s %-28s %s", key, label, "locked", fmt.Sprintf("level %d", 3+3*(slot-SlotBelt2)), "-"), fg, bg) - y++ - continue - } name := "-" stats := "" if it != nil { @@ -117,20 +127,18 @@ func (u *UI) drawInventory() { y++ } - u.putStr(2, 10, "O", 14, 0) - u.putStr(1, 11, "/|\\", 14, 0) - u.putStr(1, 12, "/ \\", 14, 0) - u.putStr(16, 10, "a/c/d/r act / swap / consume", 8, 0) - u.putStr(16, 11, "A-D/R drop", 8, 0) - u.putStr(16, 12, "B unequip body", 8, 0) + u.putStr(16, 10, "a use hands h head", 8, 0) + u.putStr(16, 11, "c/d/r use robe slot 1-3", 8, 0) + u.putStr(16, 12, "A/H/C/D/R drop slot", 8, 0) u.putStr(16, 13, "j/k select enter use e/z/space close", 8, 0) + u.putStr(16, 14, g.RiteSummary(), 11, 0) ground := g.ItemAt(g.Player.X, g.Player.Y) - u.putStr(1, 16, "[ g ] item here: "+itemSummary(ground), 10, 0) + u.putStr(1, 17, "[ g ] item here: "+itemSummary(ground), 10, 0) u.fill(0, 22, screenW, 2, ' ', 8, 0) - u.putStr(1, 22, "a hands c/d/r belt g get A-D/R drop e/z/space close", 8, 0) - u.putStr(1, 23, "Body armour is worn; B drops it.", 8, 0) + u.putStr(1, 22, "Robe slots hold vials, shards and small items; the robe cannot be removed.", 8, 0) + u.putStr(1, 23, "g get e/z/space close", 8, 0) } func slotStats(it *Item) string { @@ -158,10 +166,15 @@ func slotStats(it *Item) string { return fmt.Sprintf("heal %d charges %d", d.Heal, it.Charges) case KindFood: return fmt.Sprintf("heal %d charges %d", d.Heal, it.Charges) + case KindShard: + ensureShardAP(it) + return fmt.Sprintf("AP %d/%d", it.AP, shardMaxAP(it)) case KindTool: return d.Desc case KindRelic: return "relic" + case KindHead: + return "head item" } return d.Name } @@ -173,19 +186,18 @@ func slotAction(slot int, it *Item) string { if slot == SlotHands { return "act a" } - if slot == SlotBody { - return "unequip B" - } d := it.Def() if d == nil { return "-" } switch d.Kind { case KindMelee, KindGrenade, KindTool: - return "swap " + slotKey(slot) + return "use " + slotKey(slot) case KindMedical, KindFood: return "consume " + slotKey(slot) - case KindRelic: + case KindShard: + return "inspect" + case KindRelic, KindHead: return "inspect" } return "-" @@ -193,37 +205,47 @@ func slotAction(slot int, it *Item) string { func (u *UI) handleInventory(e *tcell.EventKey) { g := u.g + slots := g.EquipmentSlots() + if len(slots) == 0 { + g.State = StatePlaying + return + } + if u.slotSel >= len(slots) { + u.slotSel = len(slots) - 1 + } switch e.Key() { case tcell.KeyEscape: g.State = StatePlaying return case tcell.KeyEnter: - g.UseSlot(inventorySlots[u.slotSel]) + g.UseSlot(slots[u.slotSel]) return } switch e.Rune() { case 'j': - u.slotSel = (u.slotSel + 1) % len(inventorySlots) + u.slotSel = (u.slotSel + 1) % len(slots) case 'k': - u.slotSel = (u.slotSel + len(inventorySlots) - 1) % len(inventorySlots) + u.slotSel = (u.slotSel + len(slots) - 1) % len(slots) case 'a': g.UseSlot(SlotHands) + case 'h': + g.UseSlot(SlotHead) case 'c': - g.UseSlot(SlotBelt1) + g.UseSlot(SlotRobe1) case 'd': - g.UseSlot(SlotBelt2) + g.UseSlot(SlotRobe2) case 'r': - g.UseSlot(SlotBelt3) + g.UseSlot(SlotRobe3) case 'A': g.DropSlot(SlotHands) - case 'B': - g.DropSlot(SlotBody) + case 'H': + g.DropSlot(SlotHead) case 'C': - g.DropSlot(SlotBelt1) + g.DropSlot(SlotRobe1) case 'D': - g.DropSlot(SlotBelt2) + g.DropSlot(SlotRobe2) case 'R': - g.DropSlot(SlotBelt3) + g.DropSlot(SlotRobe3) case 'g': g.PickUp() case 'z', 'q', 'e', ' ': @@ -231,12 +253,8 @@ func (u *UI) handleInventory(e *tcell.EventKey) { } } -func playerArmorLine(p *Critter) string { - arm := p.BodyItem() - if arm == nil { - return "armour AP: 0/0" - } - cur, max := armorAP(arm) +func (g *Game) playerArmorLine() string { + cur, max := g.PlayerAP() return fmt.Sprintf("armour AP: %d/%d", cur, max) } @@ -245,38 +263,40 @@ func (u *UI) drawPlayerScreen() { p := g.Player u.clear(0) u.putStr(centerText("[ @ ] character information", screenW), 0, "[ @ ] character information", 2, 0) - u.putStr(1, 2, "[ ] attributes...", 10, 0) - u.putStr(41, 2, "[ = ] skills...", 10, 0) - u.putStr(1, 3, strings.Repeat("~", 37), 2, 0) - u.putStr(41, 3, strings.Repeat("~", 37), 2, 0) - attrs := []string{ - fmt.Sprintf("class: %s", PlayerClasses[g.PlayerClass].Name), - fmt.Sprintf("name: %s", p.Name), - fmt.Sprintf("strength: %d", p.STR), - fmt.Sprintf("toughness: %d", p.TGH), - fmt.Sprintf("agility: %d", p.AGI), - fmt.Sprintf("intelligence: %d", p.INT), - fmt.Sprintf("health: %d/%d", p.HP, p.MaxHP), - playerArmorLine(p), - fmt.Sprintf("gold: %d", p.Gold), - } - for i, s := range attrs { - u.putStr(3, 5+i, s, 11, 0) - } - u.putStr(41, 5, fmt.Sprintf("level: %d", p.Level), 11, 0) - u.putStr(41, 6, fmt.Sprintf("experience: %d", p.XP), 11, 0) - u.putStr(41, 7, fmt.Sprintf("need to gain: %d", 200*p.Level), 11, 0) - u.putStr(41, 8, fmt.Sprintf("skill points: %d", g.FreePoints), 11, 0) - u.putStr(41, 10, "[ %% ] experience...", 10, 0) - u.putStr(41, 11, strings.Repeat("~", 37), 2, 0) - for i, skill := range ActiveSkills { - y := 13 + i - val := p.Skill(skill) - u.putStr(43, y, fmt.Sprintf("%-16s %3d %s", SkillNames[skill], val, skillLevelName(val)), 11, 0) + u.putStr(1, 2, strings.Repeat("~", 76), 2, 0) + u.putStr(2, 4, "name: "+p.Name, 14, 0) + u.putStr(2, 5, fmt.Sprintf("health: %d/%d", p.HP, p.MaxHP), 11, 0) + u.putStr(2, 6, g.playerArmorLine(), 11, 0) + u.putStr(2, 7, fmt.Sprintf("experience: %d (stored)", p.XP), 11, 0) + u.putStr(2, 8, fmt.Sprintf("gold: %d", p.Gold), 11, 0) + u.putStr(2, 10, "[ rites ]", 10, 0) + row := 11 + for i, rite := range g.PlayerRites { + if rite < 0 || rite >= len(RiteDefs) { + continue + } + u.putStr(3, row, fmt.Sprintf("%-16s %d charge", riteName(rite), g.RiteCharges[i]), 11, 0) + row++ + } + if row == 11 { + u.putStr(3, row, "none", 8, 0) + row++ + } + row++ + u.putStr(2, row, "[ equipment ]", 10, 0) + row++ + for _, slot := range g.EquipmentSlots() { + it := p.SlotItem(slot) + name := "-" + if it != nil { + name = it.Name() + } + u.putStr(3, row, fmt.Sprintf("%-8s %s", slotName(slot), name), 11, 0) + row++ } u.fill(0, 22, screenW, 3, ' ', 8, 0) u.putStr(1, 23, "z/space quit screen", 8, 0) - u.putStr(1, 24, "x skill levels", 8, 0) + u.putStr(1, 24, "e equipment", 8, 0) } func skillLevelName(v int) string { @@ -319,9 +339,6 @@ func (u *UI) handlePlayerScreen(e *tcell.EventKey) { switch e.Rune() { case 'z', 'q', '@', ' ': u.g.State = StatePlaying - case 'x': - u.g.State = StateSkills - u.skillSel = 0 } } } diff --git a/internal/game/shards.go b/internal/game/shards.go new file mode 100644 index 0000000..a89937e --- /dev/null +++ b/internal/game/shards.go @@ -0,0 +1,137 @@ +package game + +import "fmt" + +func shardMaxAP(it *Item) int { + if it == nil { + return 0 + } + d := it.Def() + if d == nil || d.Kind != KindShard { + return 0 + } + if d.Charges < 1 { + return 1 + } + return d.Charges +} + +func ensureShardAP(it *Item) { + maxAP := shardMaxAP(it) + if maxAP == 0 { + return + } + if !it.APInit { + it.AP = maxAP + it.APInit = true + } + if it.AP > maxAP { + it.AP = maxAP + } + if it.AP < 0 { + it.AP = 0 + } +} + +func (c *Critter) RobeSlot(i int) *Item { + if c == nil || i < 0 || i >= c.Slots.RobeSlots || i >= MaxRobeSlots { + return nil + } + return c.Slots.Robe[i] +} + +func (c *Critter) SetRobeSlot(i int, it *Item) { + if c == nil || i < 0 || i >= c.Slots.RobeSlots || i >= MaxRobeSlots { + return + } + c.Slots.Robe[i] = it +} + +func (c *Critter) FirstFreeRobeSlot() int { + if c == nil { + return -1 + } + for i := 0; i < c.Slots.RobeSlots && i < MaxRobeSlots; i++ { + if c.Slots.Robe[i] == nil { + return i + } + } + return -1 +} + +func (g *Game) PlayerAP() (cur, max int) { + if g.Player == nil { + return 0, 0 + } + if g.Player.Slots.Body != nil { + return armorAP(g.Player.Slots.Body) + } + for i := 0; i < g.Player.Slots.RobeSlots && i < MaxRobeSlots; i++ { + shard := g.Player.Slots.Robe[i] + if shard == nil || shard.Def() == nil || shard.Def().Kind != KindShard { + continue + } + ensureShardAP(shard) + cur += shard.AP + max += shardMaxAP(shard) + } + return cur, max +} + +// damagePlayerShards drains equipped shards in slot order and returns the +// damage left for HP. Empty shards break and free their slot immediately. +func (g *Game) damagePlayerShards(dmg int) int { + if g.Player == nil || dmg <= 0 { + return dmg + } + for i := 0; i < g.Player.Slots.RobeSlots && i < MaxRobeSlots && dmg > 0; i++ { + shard := g.Player.Slots.Robe[i] + if shard == nil || shard.Def() == nil || shard.Def().Kind != KindShard { + continue + } + ensureShardAP(shard) + if shard.AP <= 0 { + g.Player.Slots.Robe[i] = nil + continue + } + absorbed := dmg + if absorbed > shard.AP { + absorbed = shard.AP + } + shard.AP -= absorbed + dmg -= absorbed + if shard.AP <= 0 { + g.Msg("your "+shard.Name()+" breaks and falls away.", 12) + g.Player.Slots.Robe[i] = nil + } + } + return dmg +} + +func (g *Game) blessShards(amount int) bool { + if g.Player == nil || amount <= 0 { + return false + } + bestIndex, bestMissing := -1, 0 + for i := 0; i < g.Player.Slots.RobeSlots && i < MaxRobeSlots; i++ { + shard := g.Player.Slots.Robe[i] + if shard == nil || shard.Def() == nil || shard.Def().Kind != KindShard { + continue + } + ensureShardAP(shard) + missing := shardMaxAP(shard) - shard.AP + if missing > bestMissing { + bestIndex, bestMissing = i, missing + } + } + if bestIndex < 0 { + return false + } + shard := g.Player.Slots.Robe[bestIndex] + shard.AP += amount + if shard.AP > shardMaxAP(shard) { + shard.AP = shardMaxAP(shard) + } + g.Msg(fmt.Sprintf("your %s is blessed (%d/%d AP).", shard.Name(), shard.AP, shardMaxAP(shard)), 10) + return true +} diff --git a/internal/game/types.go b/internal/game/types.go index 3bb466a..bd42895 100644 --- a/internal/game/types.go +++ b/internal/game/types.go @@ -17,8 +17,13 @@ const ( KindFood KindTool KindRelic + KindHead + KindShard ) +const MaxRobeSlots = 5 +const MaxRites = 2 + const ( SkillPerception = iota SkillDodging @@ -61,16 +66,25 @@ const ( SlotBelt1 SlotBelt2 SlotBelt3 + SlotHead + SlotRobe1 + SlotRobe2 + SlotRobe3 + SlotRobe4 + SlotRobe5 NumPlayerSlots ) -// PlayerSlots is the complete player inventory. Monsters keep using the -// legacy Inventory/Equip fields. +// PlayerSlots is the complete player inventory. The Body/Belt fields are +// retained only for old save compatibility; new games use Head and Robe slots. type PlayerSlots struct { Hands *Item Body *Item Belt [3]*Item BeltUnlocked int + Head *Item + Robe [MaxRobeSlots]*Item + RobeSlots int } type KeyBind struct { @@ -157,6 +171,8 @@ type Critter struct { LastSeenX int LastSeenY int Alert int + Flee int + Immobile int Dead bool IsAnimal bool @@ -350,6 +366,9 @@ type Game struct { StartTime int64 WoodLoot [9]int WoodsRun WoodsRun + PlayerRites [MaxRites]int + RiteCharges [MaxRites]int + PeaceTurns int PendingRises []PendingRise // temporary screen data ScrollMsg int @@ -375,6 +394,7 @@ func NewGame(seed int64) *Game { } g.WoodLoot = newWoodLootAssignment(g.RNG) g.WoodsRun = newWoodsRun(g.RNG) + g.RollPriestProfile() return g } diff --git a/internal/game/ui.go b/internal/game/ui.go index 59dd9c7..290d12b 100644 --- a/internal/game/ui.go +++ b/internal/game/ui.go @@ -315,8 +315,6 @@ func (u *UI) draw() { u.drawTitle() case StateIntro: u.drawIntro() - case StateCharCreate: - u.drawCharCreate() case StatePlaying: u.drawGame() case StateInventory: @@ -398,32 +396,28 @@ func (u *UI) drawTitle() { func (u *UI) drawIntro() { u.clear(0) - intro := []string{ - "T H E W O O D S A R E D E A D", - "", - "The first body rose seven days ago. By morning the town was gone.", - "By nightfall the trees were full of things that used to be people.", - "", - "You are the last one to leave the road.", - "", - "Somewhere in these woods is the source of the infection.", - "Find it. Destroy it. Do not let it reach the cities.", - "", - "You have a weapon, a handful of supplies, and no way back.", - "", - "press enter to continue", + g := u.g + rite := RiteDefs[0] + if g.PlayerRites[0] >= 0 && g.PlayerRites[0] < len(RiteDefs) { + rite = RiteDefs[g.PlayerRites[0]] } - for i, s := range intro { - fg := uint8(10) - switch { - case i == 0: - fg = 12 - case i == 8: - fg = 14 - case i == len(intro)-1: - fg = 8 - } - u.putStr(centerText(s, screenW), 6+i, s, fg, 0) + lines := []struct { + text string + row int + color uint8 + }{ + {"T H E W O O D S A R E D E A D", 2, 12}, + {g.PlayerName, 5, 14}, + {"The bishop assigned you to a village that no longer answers letters.", 7, 10}, + {"The dead are walking. Find the source and put it to rest.", 9, 14}, + {"Rite: " + rite.Name + " - " + rite.Desc, 12, 11}, + {"Hands: sickle Robe: 3 slots Shard: leather Vial: healing", 14, 10}, + {"The first body rose seven days ago. By morning the town was gone.", 17, 10}, + {"Somewhere in these woods is the source of the infection.", 18, 10}, + {"press enter to begin", 21, 8}, + } + for _, line := range lines { + u.putStr(centerText(line.text, screenW), line.row, line.text, line.color, 0) } } @@ -679,10 +673,7 @@ func slotBrief(it *Item) string { func (u *UI) drawStatus(y int) { g := u.g p := g.Player - ac, am := 0, 0 - if arm := p.BodyItem(); arm != nil { - ac, am = armorAP(arm) - } + ac, am := g.PlayerAP() hpColor := uint8(10) if p.MaxHP > 0 { ratio := float64(p.HP) / float64(p.MaxHP) @@ -705,7 +696,9 @@ func (u *UI) drawStatus(y int) { ap := fmt.Sprintf("AP %d/%d", ac, am) u.putStr(0, y, hp, hpColor, 0) u.putStr(len(hp)+3, y, ap, apColor, 0) - u.putStr(len(hp)+len(ap)+6, y, weapon, 7, 0) + weaponX := len(hp) + len(ap) + 6 + u.putStr(weaponX, y, weapon, 7, 0) + u.putStr(weaponX+len(weapon)+3, y, g.RiteSummary(), 11, 0) } func wrapText(s string, width int) []string { @@ -740,14 +733,7 @@ func (u *UI) handleKey(e *tcell.EventKey) { case StateTitle: u.handleTitle(e) case StateIntro: - if isEnter(e) || e.Key() == tcell.KeyEscape { - g.State = StateCharCreate - if g.PlayerName == "" { - g.PlayerName = RandomNames[g.Roll(len(RandomNames))] - } - } - case StateCharCreate: - u.handleCharCreate(e) + u.handleIntro(e) case StatePlaying: u.handlePlaying(e) case StateInventory: @@ -779,6 +765,26 @@ func isEnter(e *tcell.EventKey) bool { return e.Key() == tcell.KeyEnter || e.Rune() == '\n' || e.Rune() == '\r' } +func (u *UI) handleIntro(e *tcell.EventKey) { + if e.Key() == tcell.KeyEscape || e.Rune() == 'q' { + u.g.State = StateTitle + return + } + if e.Rune() == 'r' { + // Development reroll: regenerate the priest, kit and world. + u.g = NewGame(time.Now().UnixNano()) + u.g.State = StateIntro + return + } + if !isEnter(e) { + return + } + u.g.SetupNewGame(0, u.g.PlayerName) + u.g.State = StatePlaying + u.g.Msg("=== session started ===", 8) + u.g.UpdateFOV() +} + func (u *UI) handleTitle(e *tcell.EventKey) { switch e.Key() { case tcell.KeyUp: @@ -815,9 +821,7 @@ func (u *UI) handleTitle(e *tcell.EventKey) { } switch u.titleSel { case 0: - name := u.g.PlayerName u.g = NewGame(time.Now().UnixNano()) - u.g.PlayerName = name u.g.State = StateIntro case 1: if err := u.g.LoadGame(u.g.SavePath); err != nil { @@ -906,8 +910,7 @@ func (u *UI) handlePlaying(e *tcell.EventKey) { g.Msg("debug: map revealed.", 10) return case tcell.KeyF5: - g.Player.XP += 200 * g.Player.Level - g.CheckLevelUp() + g.Player.XP += 200 g.Msg("debug: experience granted.", 10) return case tcell.KeyF7: @@ -960,22 +963,20 @@ func (u *UI) handlePlaying(e *tcell.EventKey) { g.WaitTurn() case 'a': g.UseSlot(SlotHands) - case 'c': - g.UseSlot(SlotBelt1) - case 'd': - g.UseSlot(SlotBelt2) case 'r': - g.UseSlot(SlotBelt3) + g.UseRite(0) + case 't': + g.UseRite(1) case 'A': g.DropSlot(SlotHands) - case 'B': - g.DropSlot(SlotBody) + case 'H': + g.DropSlot(SlotHead) case 'C': - g.DropSlot(SlotBelt1) + g.DropSlot(SlotRobe1) case 'D': - g.DropSlot(SlotBelt2) + g.DropSlot(SlotRobe2) case 'R': - g.DropSlot(SlotBelt3) + g.DropSlot(SlotRobe3) case 'g': g.PickUp() case 'f': @@ -999,9 +1000,6 @@ func (u *UI) handlePlaying(e *tcell.EventKey) { g.State = StatePlayerScreen case 'S': g.SaveAndQuit() - case 'x': - g.State = StateSkills - u.skillSel = 0 case '>': g.UsePortal() case ']': diff --git a/internal/game/woods_items.go b/internal/game/woods_items.go index d4bbf7f..91869a7 100644 --- a/internal/game/woods_items.go +++ b/internal/game/woods_items.go @@ -9,7 +9,7 @@ import ( var signatureCategoryItems = [][]string{ {"saw", "shovel", "rope", "lantern", "torch", "lockpick", "fishing rod", "whetstone", "hatchet"}, {"apple", "pear", "berries", "honey", "bread", "cheese", "dried meat", "mushroom", "cooked fish", "stew"}, - {"leather jacket", "hide vest", "padded coat", "chain shirt", "ranger cloak", "bone charm"}, + {"leather shard", "chain shard", "iron shard", "silver shard", "blessed shard", "bone charm"}, {"fishing rod", "raw fish", "cooked fish", "rope", "whetstone"}, {"hunting knife", "boar spear", "spear", "snare", "hatchet", "rope"}, {"healing herb", "red potion", "green potion", "blue potion", "antidote", "holy water"}, diff --git a/internal/game/woods_population.go b/internal/game/woods_population.go index a4050ff..f81e306 100644 --- a/internal/game/woods_population.go +++ b/internal/game/woods_population.go @@ -120,15 +120,15 @@ func woodsLootPool(theme int) []int { var names []string switch theme { case WoodsChurch: - names = []string{"holy water", "gold cross", "old tome", "bandage", "bread"} + names = []string{"holy water", "gold cross", "old tome", "bandage", "healing vial", "leather shard"} case WoodsPeasantHouses: - names = []string{"apple", "bread", "cheese", "dried meat", "hatchet", "rope", "leather jacket"} + names = []string{"apple", "bread", "cheese", "dried meat", "hatchet", "rope", "leather shard"} case WoodsMillPond: - names = []string{"raw fish", "cooked fish", "fishing rod", "rope", "whetstone", "apple"} + names = []string{"raw fish", "cooked fish", "fishing rod", "rope", "whetstone", "apple", "leather shard", "chain shard"} case WoodsCemetery: - names = []string{"leather jacket", "chain shirt", "bone charm", "old tome", "shovel", "red potion"} + names = []string{"chain shard", "iron shard", "bone charm", "old tome", "shovel", "red potion"} case WoodsMeteorField: - names = []string{"blue potion", "green potion", "bone charm", "silver chalice", "hatchet", "dried meat"} + names = []string{"blue potion", "green potion", "bone charm", "silver chalice", "hatchet", "dried meat", "iron shard", "silver shard"} } ids := make([]int, 0, len(names)) for _, name := range names {