logic.go
1.65 KB
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
package roomrank
import (
"apigame/configs/confroomrank"
"apigame/util/utstring"
"apigame/util/zjson"
"fmt"
)
// TrySettle 尝试判断结算
func TrySettle(gameId string, player *Player, config *confroomrank.ActivityConfig) (hasChange bool) {
hasChange = false
if player.SettleHas {
return
}
if player.ActivityId == 0 {
return
}
if player.ActivityId == config.Id {
return
}
fmt.Println(zjson.Str(player))
// 查找玩家所在的房间
room, hasRoom := LoadRoom(gameId, player.ActivityId, player.RoomUid)
if !hasRoom {
return
}
// 找到玩家在房间里的名次
rankIndex := room.FindPlayer(player.Uid)
if rankIndex < 0 {
return
}
confActivity, hasConfActivity := confroomrank.GetConfig(gameId, room.ActivityId)
if !hasConfActivity {
return
}
TrySettleRoom(gameId, room, confActivity)
// 设置玩家奖励等数据
hasChange = true
player.SettleHas = true
confRoom, hasConfRoom := confActivity.Room[room.ConfigId]
if !hasConfRoom {
return
}
if confAward, hasConfAward := confRoom.Awards[utstring.IntToString(rankIndex)]; hasConfAward {
player.SettleAward = confAward
}
if len(confRoom.SettleScores) > rankIndex {
player.AddUserScore(confRoom.SettleScores[rankIndex])
}
if len(confRoom.SettleUserType) > rankIndex {
player.UserType = confRoom.SettleUserType[rankIndex]
}
return
}
// ChangePlayerScore 房间排行增加积分
func ChangePlayerScore(room *Room, player *Player, addScore int64) (oldScore, newScore int64) {
for i := 0; i < len(room.Details.Players); i++ {
p := room.Details.Players[i]
if player.Uid == p.Uid {
oldScore = p.Score
p.Score += addScore
newScore = p.Score
return
}
}
return
}