logic.go
1.15 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
package roomrank
import (
"apigame/configs/confroomrank"
)
// 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
}
// 查找玩家所在的房间
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
}
// 设置玩家奖励等数据
hasChange = true
player.SettleHas = true
confRoom, hasConfRoom := confActivity.Room[room.ConfigId]
if !hasConfRoom {
return
}
if len(confRoom.Awards) > rankIndex {
player.SettleAward = confRoom.Awards[rankIndex]
}
if len(confRoom.SettleScores) > rankIndex {
player.AddUserScore(confRoom.SettleScores[rankIndex])
}
if len(confRoom.SettleUserType) > rankIndex {
player.UserType = confRoom.SettleUserType[rankIndex]
}
return
}