Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2ed2909

Browse files
committed
add rewards and fix room.IsSingle
1 parent 64494a7 commit 2ed2909

File tree

1 file changed

+51
-4
lines changed

1 file changed

+51
-4
lines changed

‎models/room/room.go

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,21 @@ const (
2323
// Limits etc
2424
PlayerLimit = 100
2525
MinPlayerStartup = 2
26-
WaitingTime = 120000
26+
WaitingTime = 12000
2727

2828
// States
2929
WaitingState = 0
3030
CountdownState = 1
3131
IngameState = 2
3232

33-
// Rewards
33+
// Reward types
34+
// Used for GetRewardForPlacement+
35+
CoinRewardType = 0
36+
BRRewardType = 1
3437

38+
// Rewards
39+
DefaultXPGain = 100
40+
WinXPGain = 250
3541
)
3642

3743
type Room struct {
@@ -48,7 +54,25 @@ type Room struct {
4854
CountdownStarted int64 `json:"countdownStarted,omitempty"`
4955
}
5056

51-
var Rooms map[string]*Room
57+
var (
58+
Rooms map[string]*Room
59+
60+
// Rewards for elimination rooms
61+
// index represents placement
62+
// e.g. first place would get CoinRewards[0] coins
63+
CoinRewards = []int{
64+
75,
65+
50,
66+
25,
67+
}
68+
BRRewards = []int{
69+
150,
70+
100,
71+
50,
72+
25,
73+
10,
74+
}
75+
)
5276

5377
func New(mode uint8) *Room {
5478
r := Room{
@@ -150,7 +174,7 @@ func (r *Room) StartsAt() int64 {
150174
}
151175

152176
func (r *Room) IsSingle() bool {
153-
return len(r.Players) == 0
177+
return len(r.Players) == 1
154178
}
155179

156180
func FindLobbyByWebsocketID(id string) *Room {
@@ -163,4 +187,27 @@ func FindLobbyByWebsocketID(id string) *Room {
163187
return Rooms[i]
164188
}
165189
return nil
190+
}
191+
192+
func GetRewardForPlacement(rewardType uint8, placement int) int {
193+
if placement < 0 {
194+
return 0
195+
}
196+
197+
switch rewardType {
198+
case CoinRewardType:
199+
if placement >= len(CoinRewards) {
200+
return 0
201+
}
202+
203+
return CoinRewards[placement]
204+
case BRRewardType:
205+
if placement >= len(BRRewards) {
206+
return 0
207+
}
208+
209+
return BRRewards[placement]
210+
default:
211+
return 0
212+
}
166213
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /