blob: 45996148b71961916d7c7c85162a1c1b4b0bdf5f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
package game
import (
"thehouseoficarus/internal/combat"
"thehouseoficarus/internal/engine"
"thehouseoficarus/internal/net"
)
func (g *Game) executeQuit(sess *net.Session, args []string, rawInput string) {
g.doQuit(sess)
}
func (g *Game) doQuit(sess *net.Session) {
p := sess.Player
if combat.GetCombat(p.Name) != nil {
sess.WriteLine("You can't rest during combat!")
return
}
g.cancelAction(p)
g.cancelRest(p.Name)
g.broadcastAction(sess, "\n%s sits down to rest.", p.Name)
ticksLeft := 10
id := g.Ticks.Subscribe(engine.ToTicks(1), func() bool {
switch ticksLeft {
case 10:
sess.WriteLine("You sit down to rest...")
case 6:
sess.WriteLine("You catch your breath...")
case 3:
sess.WriteLine("You close your eyes...")
case 0:
g.cancelRest(p.Name)
g.AccountStore.SaveCharacter(p)
g.charsMu.Lock()
delete(g.loggedInChars, p.Name)
g.charsMu.Unlock()
if g.Hub != nil {
g.Hub.LeaveRoom(sess)
}
sess.Player = nil
sess.State = net.StateMenu
g.showMenu(sess)
return false
}
ticksLeft--
return true
})
g.restTimers[p.Name] = id
}
func (g *Game) cancelRest(playerName string) {
if id, ok := g.restTimers[playerName]; ok {
g.Ticks.Unsubscribe(id)
delete(g.restTimers, playerName)
}
}
|