aboutsummaryrefslogtreecommitdiff
path: root/internal/combat/state.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-09 05:59:20 -0400
committerhistoria <[not public]>2026-06-09 05:59:20 -0400
commit9eb5ab1818b6b19501fd7209db1987c9e06cc919 (patch)
tree76e046b0bf611dfe939a8c8f6507467de2e9e20f /internal/combat/state.go
downloadthehouseoficarus-9eb5ab1818b6b19501fd7209db1987c9e06cc919.tar.gz
first commit
Diffstat (limited to 'internal/combat/state.go')
-rw-r--r--internal/combat/state.go89
1 files changed, 89 insertions, 0 deletions
diff --git a/internal/combat/state.go b/internal/combat/state.go
new file mode 100644
index 0000000..b0e7dfe
--- /dev/null
+++ b/internal/combat/state.go
@@ -0,0 +1,89 @@
+package combat
+
+import "sync"
+
+type State struct {
+ PlayerName string
+ MobID string
+ MobAttacks int // attacks mob has made (3-hit flee rule)
+ PlayerDamage int // total damage player dealt this combat
+ Active bool
+}
+
+var (
+ mu sync.Mutex
+ combatants = make(map[string]*State) // player name -> state
+ mobTargets = make(map[string]string) // mob ID -> player name
+)
+
+func EnterCombat(playerName, mobID string) {
+ mu.Lock()
+ defer mu.Unlock()
+ combatants[playerName] = &State{
+ PlayerName: playerName,
+ MobID: mobID,
+ Active: true,
+ }
+ mobTargets[mobID] = playerName
+}
+
+func LeaveCombat(playerName string) {
+ mu.Lock()
+ defer mu.Unlock()
+ state, ok := combatants[playerName]
+ if !ok {
+ return
+ }
+ delete(mobTargets, state.MobID)
+ delete(combatants, playerName)
+}
+
+func GetCombat(playerName string) *State {
+ mu.Lock()
+ defer mu.Unlock()
+ return combatants[playerName]
+}
+
+func IsMobInCombat(mobID string) bool {
+ mu.Lock()
+ defer mu.Unlock()
+ _, ok := mobTargets[mobID]
+ return ok
+}
+
+func RecordMobAttack(playerName string) {
+ mu.Lock()
+ defer mu.Unlock()
+ if state, ok := combatants[playerName]; ok {
+ state.MobAttacks++
+ }
+}
+
+func CanFlee(playerName string) bool {
+ mu.Lock()
+ defer mu.Unlock()
+ state, ok := combatants[playerName]
+ if !ok {
+ return true
+ }
+ return state.MobAttacks >= 3
+}
+
+func RecordPlayerDamage(playerName string, dmg int) {
+ mu.Lock()
+ defer mu.Unlock()
+ if state, ok := combatants[playerName]; ok {
+ state.PlayerDamage += dmg
+ }
+}
+
+func GetTotalDamage(playerName string) int {
+ mu.Lock()
+ defer mu.Unlock()
+ if state, ok := combatants[playerName]; ok {
+ d := state.PlayerDamage
+ state.PlayerDamage = 0
+ return d
+ }
+ return 0
+}