-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDailyRaidManager.lua
220 lines (195 loc) · 6.91 KB
/
DailyRaidManager.lua
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
if not DailyRaidManager then
DailyRaidManager = {}
DailyRaidManager._options_path = SavePath .. "daily_raid.txt"
DailyRaidManager._defaults_path = ModPath .. "defaults.json"
DailyRaidManager._options = {}
-- Allowlist of raids.
-- It's an allowlist in case people start modding in custom maps
DailyRaidManager.RAID_ALLOWLIST = {
"flakturm", -- Odin's Fall
"gold_rush", -- Gold Rush
"train_yard", -- Amber Train
"radio_defense", -- Wiretap
"ger_bridge", -- Trainwreck
"settlement", -- Strongpoint
"bunker_test", -- Bunker Busters
"tnd", -- Tiger Trap
"hunters", -- Hunters
"convoy", -- Last Orders
"spies_test", -- Extraction
"silo", -- Countdown
"kelly" -- Kelly
}
-- MUG team keeps adding new unfinished cards,
-- so it's better to have an allowlist instead of blocklist
DailyRaidManager.CARD_ALLOWLIST = {
"ra_on_the_scrounge",
"ra_no_backups",
"ra_this_is_gonna_hurt",
"ra_not_in_the_face",
"ra_loaded_for_bear",
"ra_total_carnage",
"ra_switch_hitter",
"ra_gunslingers",
"ra_fresh_troops",
"ra_dont_you_die_on_me",
"ra_no_second_chances",
"ra_a_perfect_score",
"ra_helmet_shortage",
"ra_hemorrhaging",
"ra_crab_people",
"op_limited_supplies",
"op_take_the_cannoli",
"op_everyones_a_tough_guy",
"op_nichtsplosions",
"op_war_weary",
"op_special_for_a_reason",
"op_dont_blink",
"op_bad_coffee",
"op_playing_for_keeps",
"op_silent_shout",
"op_blow_me",
"op_you_only_live_once",
"op_short_controlled_bursts",
"op_elite_opponents",
"op_and_headaches_for_all",
"ra_slasher_movie",
"ra_pumpkin_pie",
"ra_season_of_resurrection",
"ra_dooms_day",
"mag_roulette"
}
-- Required difficulty
-- 1. Easy
-- 2. Normal
-- 3. Hard
-- 4. Very Hard
DailyRaidManager.required_difficulty = 3
--Gold rewards for each raid and card rarity
DailyRaidManager.rewards = {
["flakturm"] = 20,
["gold_rush"] = 20,
["train_yard"] = 20,
["radio_defense"] = 20,
["ger_bridge"] = 20,
["settlement"] = 20,
["bunker_test"] = 15,
["tnd"] = 10,
["hunters"] = 10,
["convoy"] = 15,
["spies_test"] = 15,
["silo"] = 20,
["kelly"] = 20,
[LootDropTweakData.RARITY_COMMON] = 10,
[LootDropTweakData.RARITY_UNCOMMON] = 15,
[LootDropTweakData.RARITY_RARE] = 20,
["default"] = 15
}
-- Currently selected forced card
---@type string | nil
DailyRaidManager.forced_card = nil
-- Reward for current daily bounty
---@type number | nil
DailyRaidManager.daily_reward = nil
-- Current daily bounty seed
---@type number | nil
DailyRaidManager.daily_seed = nil
-- Reimplementing Beardlib save functions to support sblt
function DailyRaidManager:LoadDefaults()
local default_file = io.open(self._defaults_path, "r")
if default_file then
self._options = json.decode(default_file:read("*all"))
default_file:close()
end
end
function DailyRaidManager:Load()
self:LoadDefaults()
local file = io.open(self._options_path, "r")
if file then
local config = json.decode(file:read("*all"))
file:close()
if config and type(config) == "table" then
for k, v in pairs(config) do
self._options[k] = v
end
end
end
end
function DailyRaidManager:Save()
local file = io.open(self._options_path, "w+")
if file then
file:write(json.encode(self._options))
file:close()
end
end
function DailyRaidManager:GetOption(id)
return self._options[id]
end
function DailyRaidManager:SetOption(id, value, save)
self._options[id] = value
if save then
self:Save()
end
end
--Seed for random raid and card is current date at UTC+0
--converted to number. i.e. 22072022 (dd,mm,yyyy)
--Random numbers at the end are needed because otherwise random numbers don't feel random enough
function DailyRaidManager:seed_today()
return math.floor(tonumber(os.date('!%d%m%Y', os.time())) * 20170926 / 201407)
end
--time until next daily raid, in seconds
function DailyRaidManager:time_until_next()
--Huge thanks to dorentuz!
local utc = os.date("!*t")
local result = (-utc.hour * 3600 - utc.min * 60 - utc.sec) % 86400
return result
end
--Checks if current date is not the same as the one saved
function DailyRaidManager:can_do_new_daily()
return self:GetOption("last_finished") ~= self:seed_today()
end
--Saves finished seed to the save file
---@param seed number
function DailyRaidManager:job_finished(seed)
self:SetOption("last_finished", seed, true)
self:remove_daily()
end
--Remove everything related to current daily
function DailyRaidManager:remove_daily()
DailyRaidManager.forced_card = nil
DailyRaidManager.daily_reward = nil
DailyRaidManager.daily_seed = nil
end
-- Calculates amount of gold that should be granted for given thing
---@param data string
function DailyRaidManager:calculate_gold(data)
local reward = self.rewards[data]
if not reward then
reward = self.rewards["default"]
end
return reward
end
---@return integer, string, string, number
function DailyRaidManager:generate_daily()
--Seeding the RNG
local seed = self:seed_today()
math.randomseed(seed)
-- Generating random mission
local daily_mission_name = self.RAID_ALLOWLIST[math.random(#self.RAID_ALLOWLIST)]
-- Generating random card
local daily_forced_card = self.CARD_ALLOWLIST[math.random(#self.CARD_ALLOWLIST)]
local card_data = tweak_data.challenge_cards:get_card_by_key_name(daily_forced_card)
--Generating gold
local reward = self:calculate_gold(daily_mission_name) + self:calculate_gold(card_data.rarity)
return seed, daily_mission_name, daily_forced_card, reward
end
---@param message_id string
---@param[opt] params {[string]: any}
function DailyRaidManager:send_message(message_id, params)
--Adding a prefix to the message
local message = "[" ..
managers.localization:text("daily_daily_bounty") .. "] " .. managers.localization:text(message_id, params)
managers.chat:send_message(1, managers.network.account:username() or "SYSTEM", message)
end
DailyRaidManager:Load()
end