-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg_quick.go
96 lines (88 loc) · 2.34 KB
/
msg_quick.go
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package happy
import (
"github.com/cnlisea/happy/pmgr/player"
"github.com/cnlisea/happy/vote"
"time"
)
func (h *_Happy) MsgQuickHandler(userKey interface{}) {
if h.curRound > 0 {
return
}
if h.quickVote == nil || h.quickVote.End() {
if h.curRound > 0 {
return
}
gamePlayerLen := h.pMgr.Len(func(p *player.Player) bool {
return !p.View()
})
if gamePlayerLen == h.game.PlayerMaxNum() {
return
}
if !h.game.Quick(gamePlayerLen) {
return
}
}
if h.pMgr.Get(userKey) == nil {
return
}
if h.quickVote == nil {
var (
gamePlayerLen = h.pMgr.Len(func(p *player.Player) bool {
return !p.View()
})
minNum = gamePlayerLen
)
if h.plugin != nil && h.plugin.QuickMinAgreeNum != nil {
if minNum = h.plugin.QuickMinAgreeNum(gamePlayerLen); minNum <= 0 {
minNum = gamePlayerLen
}
}
h.quickVote = vote.New(minNum, gamePlayerLen)
var pass bool
if h.plugin != nil && h.plugin.QuickDeadlinePass != nil {
pass = h.plugin.QuickDeadlinePass(h.extend)
}
h.quickVote.Deadline(h.delay, h.game.QuickTs(), pass, true)
h.quickVote.CallbackPass(func(ts int64) {
if h.event != nil && h.event.QuickPass != nil {
var op = make(map[interface{}]bool, h.quickVote.Num())
h.quickVote.Range(func(key interface{}, o bool) bool {
op[key] = o
return true
})
h.event.QuickPass(h, ts, h.pMgr, op, h.extend)
}
h.RoundBegin(false, true)
})
h.quickVote.CallbackFail(func(ts int64) {
if h.event != nil && h.event.QuickFail != nil {
var op = make(map[interface{}]bool, h.quickVote.Num())
h.quickVote.Range(func(key interface{}, o bool) bool {
op[key] = o
return true
})
h.event.QuickFail(h, ts, h.pMgr, op, h.extend)
}
})
h.quickVote.CallbackAdd(func(ts time.Duration, deadlineTs int64, key interface{}, agree bool) {
if h.event == nil || (agree && h.event.QuickAgree == nil) || (!agree && h.event.QuickReject == nil) {
return
}
var op = make(map[interface{}]bool, h.quickVote.Num())
h.quickVote.Range(func(key interface{}, o bool) bool {
op[key] = o
return true
})
switch agree {
case true:
h.event.QuickAgree(h, ts, deadlineTs, userKey, h.pMgr, op, h.extend)
default:
h.event.QuickReject(h, ts, deadlineTs, userKey, h.pMgr, op, h.extend)
}
})
}
if h.quickVote.End() {
h.quickVote.Reset()
}
h.quickVote.Add(userKey, true)
}