-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes.lua
579 lines (490 loc) · 15.9 KB
/
classes.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
ctf_gui.init()
local cooldowns = ctf_core.init_cooldowns()
local CLASS_SWITCH_COOLDOWN = 30
local classes = {}
local class_list = {"knight", "ranged", "support"}
local class_props = {
knight = {
name = "Knight",
color = "grey",
description = "High HP class with a sword capable of short damage bursts",
hp_max = 30,
visual_size = vector.new(1.1, 1.05, 1.1),
items = {
"tournament_mode:knight_sword",
},
disallowed_items = {
"ctf_ranged:rifle",
"ctf_ranged:smg",
"ctf_ranged:sniper_magnum",
},
},
support = {
name = "Support",
color = "cyan",
description = "Helper class with healing bandages, an immunity ability, and building gear",
physics = {speed = 1.1},
items = {
"tournament_mode:support_bandage",
"tournament_mode:support_paxel",
"default:cobble 99",
},
disallowed_items = {
"ctf_ranged:rifle",
"ctf_ranged:smg",
"ctf_ranged:shotgun",
"ctf_melee:",
"ctf_ranged:sniper_magnum",
},
disallowed_items_markup = {
["ctf_melee:"] = "default_tool_steelsword.png^ctf_modebase_group.png",
},
},
ranged = {
name = "Scout",
color = "orange",
description = "Ranged class with a scoped rifle/grenade launcher and a scaling ladder for reaching high places",
visual_size = vector.new(0.9, 1, 0.9),
items = {
"tournament_mode:ranged_rifle_loaded",
"tournament_mode:scaling_ladder"
},
disallowed_items = {
"ctf_melee:",
},
disallowed_items_markup = {
["ctf_melee:"] = "default_tool_steelsword.png^ctf_modebase_group.png",
},
}
}
minetest.register_on_mods_loaded(function()
for k, class_prop in pairs(class_props) do
local items_markup = ""
local disallowed_items_markup = ""
for _, iname in ipairs(class_prop.items or {}) do
local item = ItemStack(iname)
items_markup = string.format("%s <item name=%s width=48>",
items_markup,
item:get_name()
)
end
for _, iname in ipairs(class_prop.disallowed_items or {}) do
if minetest.registered_items[iname] then
disallowed_items_markup = string.format("%s <item name=%s width=48>",
disallowed_items_markup,
iname
)
else
disallowed_items_markup = string.format("%s <img name=%s width=48>",
disallowed_items_markup,
class_prop.disallowed_items_markup[iname]
)
end
end
class_props[k].items_markup = items_markup.."\n"
class_props[k].disallowed_items_markup = disallowed_items_markup
end
end)
local function dist_from_flag(player)
local tname = ctf_teams.get(player)
if not tname then return 0 end
return vector.distance(ctf_map.current_map.teams[tname].flag_pos, player:get_pos())
end
--
--- Knight Sword
--
-- ctf_melee.register_sword("tournament_mode:knight_sword", {
-- description = "Knight Sword",
-- inventory_image = "default_tool_bronzesword.png",
-- damage_groups = {fleshy = 5},
-- })
local KNIGHT_COOLDOWN_TIME = 26
local KNIGHT_USAGE_TIME = 8
ctf_melee.simple_register_sword("tournament_mode:knight_sword", {
description = "Knight Sword\n" .. minetest.colorize("gold",
"(Sneak/Run) + Rightclick to use Rage ability (Lasts "..
KNIGHT_USAGE_TIME.."s, "..KNIGHT_COOLDOWN_TIME.."s cooldown)"),
inventory_image = "default_tool_bronzesword.png",
inventory_overlay = "ctf_modebase_special_item.png",
wield_image = "default_tool_bronzesword.png",
damage_groups = {fleshy = 7},
full_punch_interval = 0.7,
rightclick_func = function(itemstack, user, pointed)
if ctf_settings.get(user, "ctf_classes:simple_knight_activate") ~= "true" then
local ctl = user:get_player_control()
if not ctl.sneak and not ctl.aux1 then return end
end
local pname = user:get_player_name()
if itemstack:get_wear() == 0 then
local step = math.floor(65534 / KNIGHT_USAGE_TIME)
ctf_modebase.update_wear.start_update(pname, "ctf_melee:sword_diamond", step, false, function()
local player = minetest.get_player_by_name(pname)
if player then
local pinv = player:get_inventory()
local pos = ctf_modebase.update_wear.find_item(pinv, "ctf_melee:sword_diamond")
if pos then
local newstack = ItemStack("tournament_mode:knight_sword")
newstack:set_wear(65534)
player:get_inventory():set_stack("main", pos, newstack)
local dstep = math.floor(65534 / KNIGHT_COOLDOWN_TIME)
ctf_modebase.update_wear.start_update(pname, "tournament_mode:knight_sword", dstep, true)
end
end
end,
function()
local player = minetest.get_player_by_name(pname)
if player then
player:get_inventory():remove_item("main", "ctf_melee:sword_diamond")
end
end)
return "ctf_melee:sword_diamond"
end
end,
})
--
--- Ranged Gun
--
local RANGED_COOLDOWN_TIME = 31
local RANGED_ZOOM_MULT = 3
local scoped = ctf_ranged.scoped
ctf_ranged.simple_register_gun("tournament_mode:ranged_rifle", {
type = "classes_rifle",
description = "Scout Rifle\n" .. minetest.colorize("gold",
"(Sneak/Run) + Rightclick to launch grenade ("..RANGED_COOLDOWN_TIME.."s cooldown), otherwise will toggle scope"),
texture = "tournament_mode_ranged_rifle.png",
texture_overlay = "ctf_modebase_special_item.png^[transformFX",
wield_texture = "tournament_mode_ranged_rifle.png",
fire_sound = "ctf_ranged_rifle",
rounds = 0,
range = 150,
damage = 5,
fire_interval = 0.8,
liquid_travel_dist = 4,
rightclick_func = function(itemstack, user, pointed)
local ctl = user:get_player_control()
if not ctl.sneak and not ctl.aux1 then
local uname = user:get_player_name()
if not ctl.zoom then
if scoped[uname] then
ctf_ranged.hide_scope(uname)
else
ctf_ranged.show_scope(uname, itemstack:get_name(), RANGED_ZOOM_MULT)
end
end
return
end
if itemstack:get_wear() == 0 then
grenades.throw_grenade("grenades:frag", 24, user)
local step = math.floor(65534 / RANGED_COOLDOWN_TIME)
ctf_modebase.update_wear.start_update(user:get_player_name(), "tournament_mode:ranged_rifle_loaded", step, true)
itemstack:set_wear(65534)
return itemstack
end
end
})
--
--- Scaling Ladder
--
local SCALING_TIMEOUT = 4
-- Code borrowed from minetest_game default/nodes.lua -> default:ladder_steel
local scaling_def = {
description = "Scaling Ladder\n"..
minetest.colorize("gold", "(Infinite usage, self-removes after "..SCALING_TIMEOUT.."s)"),
tiles = {"default_ladder_steel.png"},
drawtype = "signlike",
inventory_image = "default_ladder_steel.png",
inventory_overlay = "ctf_modebase_special_item.png",
wield_image = "default_ladder_steel.png",
paramtype = "light",
paramtype2 = "wallmounted",
sunlight_propagates = true,
walkable = false,
climbable = true,
is_ground_content = false,
groups = {},
selection_box = {
type = "wallmounted",
},
sounds = default.node_sound_metal_defaults(),
on_place = function(itemstack, placer, pointed_thing, ...)
if pointed_thing.type == "node" then
itemstack:set_count(2)
minetest.item_place(itemstack, placer, pointed_thing, ...)
end
end,
on_construct = function(pos)
minetest.get_node_timer(pos):start(SCALING_TIMEOUT)
end,
on_timer = function(pos)
minetest.remove_node(pos)
end,
}
minetest.register_node("tournament_mode:scaling_ladder", scaling_def)
--
--- Medic Bandage
--
local IMMUNITY_TIME = 6
local IMMUNITY_COOLDOWN = 46
local HEAL_PERCENT = 0.8
ctf_healing.register_bandage("tournament_mode:support_bandage", {
description = string.format(
"Bandage\nHeals teammates for 4-5 HP until target's HP is equal to %d%% of their maximum HP\n" ..
minetest.colorize("gold", "(Sneak/Run) + Rightclick to become immune to damage for %ds (%ds cooldown)"),
HEAL_PERCENT * 100,
IMMUNITY_TIME, IMMUNITY_COOLDOWN
),
inventory_image = "ctf_healing_bandage.png",
inventory_overlay = "ctf_modebase_special_item.png",
wield_image = "ctf_healing_bandage.png",
heal_percent = HEAL_PERCENT,
heal_min = 4,
heal_max = 5,
rightclick_func = function(itemstack, user, pointed)
if ctf_settings.get(user, "ctf_classes:simple_support_activate") ~= "true" then
local ctl = user:get_player_control()
if not ctl.sneak and not ctl.aux1 then return end
end
local pname = user:get_player_name()
if itemstack:get_wear() == 0 then
if ctf_modebase.taken_flags[pname] then
hud_events.new(user, {
quick = true,
text = "You can't become immune while holding the flag",
color = "warning",
})
return
end
ctf_modebase.give_immunity(user)
local step = math.floor(65534 / IMMUNITY_TIME)
ctf_modebase.update_wear.start_update(pname, "tournament_mode:support_bandage", step, false,
function()
ctf_modebase.remove_immunity(user)
local dstep = math.floor(65534 / IMMUNITY_COOLDOWN)
ctf_modebase.update_wear.start_update(pname, "tournament_mode:support_bandage", dstep, true)
end,
function()
ctf_modebase.remove_immunity(user)
end)
itemstack:set_wear(1)
return itemstack
end
end
})
function classes.get_name(player)
local meta = player:get_meta()
local cname = meta:get_string("class")
if not cname or not class_props[cname] then
cname = "knight"
meta:set_string("class", cname)
end
return cname
end
function classes.get(player)
return class_props[classes.get_name(player)]
end
function classes.get_skin_overlay(player_or_class, class)
return "^tournament_mode_" .. (class and player_or_class or classes.get_name(player_or_class)) .. "_overlay.png"
end
function classes.update(player)
local class = classes.get(player)
player:set_properties({
hp_max = class.hp_max or minetest.PLAYER_MAX_HP_DEFAULT,
visual_size = class.visual_size or vector.new(1, 1, 1)
})
if class.physics then
physics.set(player:get_player_name(), "tournament_mode:class_physics", {
speed = class.physics.speed or 1,
jump = class.physics.jump or 1,
gravity = class.physics.gravity or 1,
})
else
physics.remove(player:get_player_name(), "tournament_mode:class_physics")
end
end
function classes.set(player, classname)
if classname == classes.get_name(player) then
return
end
player:get_meta():set_string("class", classname)
ctf_modebase.update_wear.cancel_player_updates(player)
ctf_modebase.player.remove_bound_items(player)
ctf_modebase.player.give_initial_stuff(player)
player_api.set_texture(player, 1, ctf_cosmetics.get_skin(player))
classes.update(player)
player:set_hp(player:get_properties().hp_max)
end
local function select_class(player, classname)
player = PlayerObj(player)
if not player then return end
if ctf_modebase.current_mode == "tournament" and dist_from_flag(player) <= 5 then
cooldowns:set(player, CLASS_SWITCH_COOLDOWN)
classes.set(player, classname)
end
end
local function wrap_class(idx)
if idx > #class_list then
idx = 1
elseif idx < 1 then
idx = #class_list
end
return idx
end
function classes.show_class_formspec(player)
player = PlayerObj(player)
if not player then return end
if not cooldowns:get(player) then
if ctf_modebase.current_mode ~= "tournament" then return end
if dist_from_flag(player) > 5 then
hud_events.new(player, {
quick = true,
text = "You can only change class at your flag!",
color = "warning",
})
return
end
local pteam = ctf_teams.get(player)
ctf_gui.show_formspec(player, "tournament_mode:class_form", function(context)
local form_x, form_y = 12, 10
local pad = 0.3
local bw = 3
local class = context.class
local class_prop = context.class_props[class]
local out = {
"formspec_version[4]",
{"size[%f,%f]", form_x, form_y+1.1},
"real_coordinates[true]",
{"hypertext[0,0.2;%f,1.6;title;<big><center><b>Class Info: %s</b></center></big>]", form_x, class_prop.name},
{"box[%s,1.2;%f,%f;#00000077]", pad, ((form_x/2)-0.7) - pad, form_y-2.4},
{"model[%s,1.4;%f,%f;classpreview;character.b3d;%s,blank.png;{0,160};;;]",
pad,
((form_x/2)-0.7) - pad,
form_y-2.6,
ctf_cosmetics.get_colored_skin(context.player, context.pteam and ctf_teams.team[context.pteam].color) ..
context.classes.get_skin_overlay(class, true) or ""
},
{[[hypertext[%f,1.2;%f,%f;info;<global margin=20 font=mono background=#00000044>
</b>
<center>%s</center>
<img name=heart.png width=20 float=left> %d HP
%s
Special items
%s
Disallowed Items
%s
] ]],
(form_x/2)-0.6,
(form_x/2)+0.6 - pad,
form_y-2.4,
class_prop.description,
class_prop.hp_max or minetest.PLAYER_MAX_HP_DEFAULT,
class_prop.physics and class_prop.physics.speed and
"<img name=sprint_stamina_icon.png width=20 float=left> "..class_prop.physics.speed.."x Speed\n" or "",
class_prop.items_markup,
class_prop.disallowed_items_markup
},
}
local tb = #context.class_list -- total buttons
for i, c in pairs(context.class_list) do
local sect = (i-1)/(tb-1)
table.insert(out, {
"style[select_%s;font_size=*1.4;content_offset=-%f,0;bgcolor="..context.class_props[c].color.."]" ..
"style[show_%s;padding=8,8;bgcolor="..context.class_props[c].color.."]",
c,
20 + 8,
c,
})
table.insert(out, {
"button_exit[%f,%f;%f,1;select_%s;%s]",
pad + (((form_x-(pad*2 + bw))) * sect),
form_y-0.5,
bw,
c,
context.class_props[c].name,
})
table.insert(out, {
"image_button[%f,%f;1,1;settings_info.png;show_%s;]",
pad + (((form_x-(pad*2 + bw))) * sect) + bw - 1,
form_y-0.5,
c,
})
table.insert(out,
{"tooltip[show_%s;Click to show class info]", c}
)
end
return ctf_gui.list_to_formspec_str(out)
end, {
classes = classes,
player = player,
pteam = pteam,
wrap_class = wrap_class,
class_list = class_list,
class_props = class_props,
class = classes.get_name(player) or "knight",
_on_formspec_input = function(pname, context, fields)
if ctf_modebase.current_mode ~= "tournament" then return end
for _, class in pairs(context.class_list) do
if fields["show_"..class] then
context.class = class
return "refresh"
end
if fields["select_"..class] then
if dist_from_flag(player) > 5 then
hud_events.new(player, {
quick = true,
text = "You can only change class at your flag!",
color = "warning",
})
return
end
select_class(pname, class)
end
end
end,
})
else
hud_events.new(player, {
quick = true,
text = "You can only change your class every "..CLASS_SWITCH_COOLDOWN.." seconds",
color = "warning",
})
end
end
function classes.is_restricted_item(player, name)
-- Don't check restricted items for players not in a team
if not ctf_teams.get(player) then
return
end
for _, disallowed in pairs(classes.get(player).disallowed_items) do
if name:match(disallowed) then
hud_events.new(player, {
quick = true,
text = "Your class can't use that item!",
color = "warning",
})
return true
end
end
end
function classes.reset_class_cooldowns(player)
if not player then
minetest.log("action", "Resetting class cooldowns for all players")
for _, p in pairs(minetest.get_connected_players()) do
if cooldowns:get(p) then
cooldowns:set(p)
end
end
else
minetest.log("action", "Resetting class cooldowns for player "..dump(PlayerName(player)))
if cooldowns:get(player) then
cooldowns:set(player)
end
end
end
function classes.finish()
for _, player in pairs(minetest.get_connected_players()) do
classes.reset_class_cooldowns()
player:set_properties({hp_max = minetest.PLAYER_MAX_HP_DEFAULT, visual_size = vector.new(1, 1, 1)})
physics.remove(player:get_player_name(), "tournament_mode:class_physics")
end
end
return classes