diff options
| author | historia <[not public]> | 2026-06-24 22:55:35 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-24 22:55:35 -0400 |
| commit | 15b7e221b799ef107dec44ecdb294026dfd3d059 (patch) | |
| tree | 3748e464a77f0f082bea1567e9d6990052054961 /internal/game/sys_safespot.go | |
| parent | 9d4b799db4868bcab291b83599ff088763cd4ed6 (diff) | |
| download | thehouseoficarus-15b7e221b799ef107dec44ecdb294026dfd3d059.tar.gz | |
refactor: pulled techs out to yaml files, unified numerous combat functions, broke up game object
Diffstat (limited to 'internal/game/sys_safespot.go')
| -rw-r--r-- | internal/game/sys_safespot.go | 55 |
1 files changed, 15 insertions, 40 deletions
diff --git a/internal/game/sys_safespot.go b/internal/game/sys_safespot.go index 44a8f9f..28f08d9 100644 --- a/internal/game/sys_safespot.go +++ b/internal/game/sys_safespot.go @@ -20,10 +20,7 @@ var sizeRank = map[string]int{ } func (g *Game) isSafespotted(playerName string) bool { - g.safespotMu.Lock() - defer g.safespotMu.Unlock() - ss, ok := g.safespotStates[playerName] - return ok && ss.Active && ss.HideCountdown <= 0 + return g.safespot.IsActive(playerName) } func (g *Game) safespotTier(p *player.Player) int { @@ -54,9 +51,7 @@ func (g *Game) safespotBlocksHazard(p *player.Player) bool { } func (g *Game) safespotBlocksMob(p *player.Player, mob *world.MobInstance) bool { - g.safespotMu.Lock() - ss, ok := g.safespotStates[p.Name] - g.safespotMu.Unlock() + ss, ok := g.safespot.Get(p.Name) if !ok || !ss.Active || ss.HideCountdown > 0 { return false } @@ -89,9 +84,7 @@ func (g *Game) sessionInRoom(name string, roomSessions []*net.Session) *net.Sess func (g *Game) activateSafespot(sess *net.Session, p *player.Player, ss *SafespotState) { objDef, err := g.ObjectStore.Load(ss.ObjectDefID) if err != nil || objDef.Safespot == nil { - g.safespotMu.Lock() - delete(g.safespotStates, p.Name) - g.safespotMu.Unlock() + g.safespot.Delete(p.Name) sess.WriteLine("The safespot no longer exists.") return } @@ -99,9 +92,7 @@ func (g *Game) activateSafespot(sess *net.Session, p *player.Player, ss *Safespo cfg := objDef.Safespot st := g.World.GetObjState(ss.RoomID, ss.ObjectDefID, ss.ObjectIndex) if st == nil { - g.safespotMu.Lock() - delete(g.safespotStates, p.Name) - g.safespotMu.Unlock() + g.safespot.Delete(p.Name) sess.WriteLine("The safespot no longer exists.") return } @@ -110,9 +101,7 @@ func (g *Game) activateSafespot(sess *net.Session, p *player.Player, ss *Safespo st.SafespotLevel = len(cfg.Levels) st.SafespotTicksAtLevel = 0 } else if st.SafespotLevel <= 0 { - g.safespotMu.Lock() - delete(g.safespotStates, p.Name) - g.safespotMu.Unlock() + g.safespot.Delete(p.Name) sess.WriteLine(fmt.Sprintf("The %s has been completely destroyed.", objDef.Name)) return } @@ -199,9 +188,7 @@ func (g *Game) degradeSafespot(st *world.ObjState, objDef *object.ObjectDef, cfg if st.SafespotLevel <= 0 { for _, name := range st.SafespotOccupants { - g.safespotMu.Lock() - delete(g.safespotStates, name) - g.safespotMu.Unlock() + g.safespot.Delete(name) if occSess := g.sessionInRoom(name, roomSessions); occSess != nil { occSess.WriteLine(color.ExpandTags(g.colorMode(occSess), fmt.Sprintf("The %s crumbles away!", objDef.Name))) @@ -258,16 +245,12 @@ func (g *Game) scheduleSafespotRespawn(st *world.ObjState, objDef *object.Object } func (g *Game) leaveSafespot(sess *net.Session, p *player.Player) { - g.safespotMu.Lock() - ss, ok := g.safespotStates[p.Name] + ss, ok := g.safespot.Get(p.Name) if !ok { - g.safespotMu.Unlock() return } - delete(g.safespotStates, p.Name) - g.safespotMu.Unlock() - - g.removeSafespotOccupant(p.Name, ss) + g.safespot.Delete(p.Name) + g.removeSafespotOccupant(p.Name, &ss) objDef, _ := g.ObjectStore.Load(ss.ObjectDefID) objName := "cover" @@ -279,10 +262,7 @@ func (g *Game) leaveSafespot(sess *net.Session, p *player.Player) { } func (g *Game) forceLeaveSafespot(sess *net.Session, p *player.Player, ss *SafespotState, reason string) { - g.safespotMu.Lock() - delete(g.safespotStates, p.Name) - g.safespotMu.Unlock() - + g.safespot.Delete(p.Name) g.removeSafespotOccupant(p.Name, ss) if reason != "" { @@ -318,25 +298,20 @@ func (g *Game) SafespotTick() { continue } - g.safespotMu.Lock() - ss, ok := g.safespotStates[p.Name] + ss, ok := g.safespot.Get(p.Name) if !ok || !ss.Active { - g.safespotMu.Unlock() continue } if ss.HideCountdown > 0 { - ss.HideCountdown-- - if ss.HideCountdown > 0 { - g.safespotMu.Unlock() + newCountdown, _ := g.safespot.DecrementHideCountdown(p.Name) + if newCountdown > 0 { continue } - g.safespotMu.Unlock() - g.activateSafespot(sess, p, ss) + g.activateSafespot(sess, p, &ss) continue } - g.safespotMu.Unlock() - g.safespotMaintenance(sess, p, ss) + g.safespotMaintenance(sess, p, &ss) } } |
