aboutsummaryrefslogtreecommitdiff
path: root/internal/game/sys_safespot.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/sys_safespot.go')
-rw-r--r--internal/game/sys_safespot.go55
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)
}
}