forked from heroiclabs/hiro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_leaderboards.go
90 lines (73 loc) · 6 KB
/
event_leaderboards.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
// Copyright 2023 Heroic Labs & Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package hiro
import (
"context"
"github.com/heroiclabs/nakama-common/runtime"
)
// EventLeaderboardsConfig is the data definition for the EventLeaderboardsSystem type.
type EventLeaderboardsConfig struct {
EventLeaderboards map[string]*EventLeaderboardsConfigLeaderboard `json:"event_leaderboards,omitempty"`
}
type EventLeaderboardsConfigLeaderboard struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Category string `json:"category,omitempty"`
Ascending bool `json:"ascending,omitempty"`
Operator string `json:"operator,omitempty"`
ResetSchedule string `json:"reset_schedule,omitempty"`
CohortSize int `json:"cohort_size,omitempty"`
AdditionalProperties map[string]string `json:"additional_properties,omitempty"`
MaxNumScore int `json:"max_num_score,omitempty"`
RewardTiers map[string][]*EventLeaderboardsConfigLeaderboardRewardTier `json:"reward_tiers,omitempty"`
ChangeZones map[string]*EventLeaderboardsConfigChangeZone `json:"change_zones,omitempty"`
Tiers int `json:"tiers,omitempty"`
MaxIdleTierDrop int `json:"max_idle_tier_drop,omitempty"`
StartTimeSec int64 `json:"start_time_sec,omitempty"`
EndTimeSec int64 `json:"end_time_sec,omitempty"`
Duration int64 `json:"duration,omitempty"`
}
type EventLeaderboardsConfigLeaderboardRewardTier struct {
Name string `json:"name,omitempty"`
RankMax int `json:"rank_max,omitempty"`
RankMin int `json:"rank_min,omitempty"`
Reward *EconomyConfigReward `json:"reward,omitempty"`
TierChange int `json:"tier_change,omitempty"`
}
type EventLeaderboardsConfigChangeZone struct {
Promotion float64 `json:"promotion,omitempty"`
Demotion float64 `json:"demotion,omitempty"`
DemoteIdle bool `json:"demote_idle,omitempty"`
}
// An EventLeaderboardsSystem is a gameplay system which represents cohort-segmented, tier-based event leaderboards.
type EventLeaderboardsSystem interface {
System
// GetEventLeaderboard returns a specified event leaderboard's cohort for the user.
GetEventLeaderboard(ctx context.Context, logger runtime.Logger, nk runtime.NakamaModule, userID, eventLeaderboardID string) (eventLeaderboard *EventLeaderboard, err error)
// RollEventLeaderboard places the user into a new cohort for the specified event leaderboard if possible.
RollEventLeaderboard(ctx context.Context, logger runtime.Logger, nk runtime.NakamaModule, userID, eventLeaderboardID string, tier *int, matchmakerProperties map[string]interface{}) (eventLeaderboard *EventLeaderboard, err error)
// UpdateEventLeaderboard updates the user's score in the specified event leaderboard, and returns the user's updated cohort information.
UpdateEventLeaderboard(ctx context.Context, logger runtime.Logger, nk runtime.NakamaModule, userID, username, eventLeaderboardID string, score, subscore int64, metadata map[string]interface{}) (eventLeaderboard *EventLeaderboard, err error)
// ClaimEventLeaderboard claims the user's reward for the given event leaderboard.
ClaimEventLeaderboard(ctx context.Context, logger runtime.Logger, nk runtime.NakamaModule, userID, eventLeaderboardID string) (eventLeaderboard *EventLeaderboard, err error)
// SetOnEventLeaderboardsReward sets a custom reward function which will run after an event leaderboard's reward is rolled.
SetOnEventLeaderboardsReward(fn OnReward[*EventLeaderboardsConfigLeaderboard])
// SetOnEventLeaderboardCohortSelection sets a custom function that can replace the cohort or opponent selection feature of event leaderboards.
SetOnEventLeaderboardCohortSelection(fn OnEventLeaderboardCohortSelection)
// DebugFill fills the user's current cohort with dummy users for all remaining available slots.
DebugFill(ctx context.Context, logger runtime.Logger, nk runtime.NakamaModule, userID, eventLeaderboardID string, targetCount int) (eventLeaderboard *EventLeaderboard, err error)
// DebugRandomScores assigns random scores to the participants of the user's current cohort, except to the user themselves.
DebugRandomScores(ctx context.Context, logger runtime.Logger, nk runtime.NakamaModule, userID, eventLeaderboardID string, scoreMin, scoreMax, subscoreMin, subscoreMax int64, operator *int) (eventLeaderboard *EventLeaderboard, err error)
}
type OnEventLeaderboardCohortSelection func(ctx context.Context, logger runtime.Logger, nk runtime.NakamaModule, storageIndex string, eventID string, config *EventLeaderboardsConfigLeaderboard, userID string, tier int, matchmakerProperties map[string]interface{}) (cohortID string, cohortUserIDs []string, forceNewCohort bool, err error)