2020-12-21 07:39:29 -08:00
function tasks . check_xp ( map_id , needed_xp )
if needed_xp <= 0 then
lobby.team_win ( map_id )
end
end
2022-06-11 16:12:07 -07:00
function tasks . add_xp ( pos , node , puncher , swap_to ) -- This function adds xp and swaps the task node.
2021-03-15 08:45:36 -07:00
local player_attributes = puncher : get_meta ( )
2022-02-08 19:48:16 -08:00
local mode = player_attributes : get_string ( ' mode ' )
2021-03-15 08:45:36 -07:00
local meta = minetest.get_meta ( pos )
2022-02-06 19:08:37 -08:00
local earned_xp = meta : get_int ( ' xp ' ) or 1
2021-03-15 08:45:36 -07:00
local wield = puncher : get_wielded_item ( )
local wield_name = wield : get_name ( )
if wield_name ~= ' creative:tool_breaking ' then
local name = puncher : get_player_name ( )
local timer = minetest.get_node_timer ( pos )
2022-02-14 06:37:53 -08:00
local min = math.max ( meta : get_int ( ' time_min ' ) , 5 )
local max = math.max ( meta : get_int ( ' time_max ' ) , 20 )
2022-02-06 19:08:37 -08:00
local random_number = math.random ( min , max )
timer : start ( random_number )
2020-12-21 07:39:29 -08:00
local map_id = lobby.game [ name ]
local traitor = lobby.traitors [ map_id ]
2021-03-15 08:45:36 -07:00
minetest.swap_node ( pos , { name = swap_to , param2 = node.param2 } )
2022-02-11 20:04:05 -08:00
meta : set_string ( ' formspec ' , ' ' )
2020-12-27 09:19:36 -08:00
if map_id ~= ' lobby ' then
if name ~= traitor then
2022-02-08 19:48:16 -08:00
if mode == ' ghost ' then
2021-03-15 08:45:36 -07:00
earned_xp = math.floor ( earned_xp / 2 )
map_id = string.sub ( map_id , 0 , - 7 )
end
2020-12-27 09:19:36 -08:00
local game_data = lobby.savedata . data [ map_id ]
2022-02-08 19:48:16 -08:00
if lobby.xp [ map_id ] and mode ~= ' solo ' then
2021-12-20 17:30:20 -08:00
lobby.xp [ map_id ] = lobby.xp [ map_id ] + earned_xp
local needed_xp = game_data [ ' xp ' ] - lobby.xp [ map_id ]
minetest.chat_send_player ( name , ' You just earned ' .. earned_xp .. ' XP for your team. \n You need ' .. needed_xp .. ' more XP to defeat the imposter. ' )
2022-06-13 06:32:52 -07:00
minetest.log ( ' action ' , map_id .. ' : Gained ' .. earned_xp .. ' xp, still ' .. needed_xp .. ' xp required to complete level. ' )
2021-12-20 17:30:20 -08:00
tasks.check_xp ( map_id , needed_xp )
else
2021-12-31 20:22:49 -08:00
lobby.give_xp ( puncher , 1 )
2021-12-20 17:30:20 -08:00
end
2020-12-27 09:19:36 -08:00
else
minetest.chat_send_player ( name , ' You \' re the traitor, you can do tasks, but you won \' t earn XP. Try killing the other players. ' )
end
2021-10-22 18:30:22 -07:00
elseif map_id == ' lobby ' and not minetest.check_player_privs ( puncher : get_player_name ( ) , { creative = true } ) then
2021-03-15 08:45:36 -07:00
lobby.give_xp ( puncher , 1 )
end
end
end
function tasks . only_add_xp ( xp , name ) -- This function only adds XP, you are responsible for modifying the task node yourself.
local player = minetest.get_player_by_name ( name )
local player_attributes = player : get_meta ( )
2022-02-08 19:48:16 -08:00
local mode = player_attributes : get_string ( ' mode ' )
2021-12-17 19:06:59 -08:00
local map_id = lobby.game [ name ] or ' lobby '
2021-03-15 08:45:36 -07:00
local traitor = lobby.traitors [ map_id ]
if map_id ~= ' lobby ' then
if name ~= traitor then
2022-02-08 19:48:16 -08:00
if mode == ' ghost ' then
2021-03-15 08:45:36 -07:00
xp = math.floor ( xp / 2 )
map_id = string.sub ( map_id , 0 , - 7 )
end
local game_data = lobby.savedata . data [ map_id ]
2022-02-08 19:48:16 -08:00
if lobby.xp [ map_id ] and mode ~= ' solo ' then
2021-12-17 19:06:59 -08:00
lobby.xp [ map_id ] = lobby.xp [ map_id ] + xp
local needed_xp = game_data [ ' xp ' ] - lobby.xp [ map_id ]
minetest.chat_send_player ( name , ' You just earned ' .. xp .. ' XP for your team. \n You need ' .. needed_xp .. ' more XP to defeat the imposter. ' )
2022-06-13 06:32:52 -07:00
minetest.log ( ' action ' , map_id .. ' : Gained ' .. xp .. ' xp, still ' .. needed_xp .. ' xp required to complete level. ' )
2021-12-17 19:06:59 -08:00
tasks.check_xp ( map_id , needed_xp )
else
lobby.give_xp ( player , 1 )
end
2021-03-15 08:45:36 -07:00
else
minetest.chat_send_player ( name , ' You \' re the traitor, you can do tasks, but you won \' t earn XP. Try killing the other players. ' )
2020-12-21 07:39:29 -08:00
end
2021-10-22 18:30:22 -07:00
elseif map_id == ' lobby ' and not minetest.check_player_privs ( name , { creative = true } ) then
2021-03-15 08:45:36 -07:00
lobby.give_xp ( player , 1 )
2020-12-21 07:39:29 -08:00
end
end
2022-06-05 19:29:05 -07:00
function tasks . right_click_on ( pos , node , clicker , formspec )
2022-06-13 06:32:52 -07:00
local name = clicker : get_player_name ( )
2021-09-21 05:49:04 -07:00
local timer = minetest.get_node_timer ( pos )
local meta = minetest.get_meta ( pos )
local min = meta : get_int ( ' time_min ' ) or 30
local max = meta : get_int ( ' time_max ' ) or 60
local random_number = math.random ( min , max )
timer : start ( random_number )
2022-06-13 06:32:52 -07:00
local map_id = lobby.game [ name ]
local sabotage_level = lobby.sabotage_level [ map_id ] or 5
local level = meta : get_int ( ' level ' ) or 0
2022-06-13 19:21:56 -07:00
if level < sabotage_level then
2022-06-13 06:32:52 -07:00
minetest.show_formspec ( name , ' tasks:good ' , formspec )
meta : set_string ( ' formspec ' , ' ' ) --Can be removed at a future point, this just clears formspecs from individual nodes as they are now handled differently.
else
minetest.chat_send_player ( name , ' level is currently sabotaged, and you can \' t do this now. ' )
end
2021-09-21 05:49:04 -07:00
end
2022-06-05 19:29:05 -07:00
function tasks . right_click_off ( pos , node , clicker , formspec )
local name = clicker : get_player_name ( )
local map_id = lobby.game [ name ]
2022-06-13 06:32:52 -07:00
local sabotage_level = lobby.sabotage_level [ map_id ] or 5
2022-06-05 19:29:05 -07:00
local meta = minetest.get_meta ( pos )
local level = meta : get_int ( ' level ' ) or 0
2022-06-13 19:21:56 -07:00
if level < sabotage_level then
2022-06-05 19:29:05 -07:00
tasks.player_config [ name ] = pos
minetest.show_formspec ( name , ' tasks:part_req_form ' , formspec )
else
minetest.chat_send_player ( name , ' level is currently sabotaged, and you can \' t do this now. ' )
end
end
2022-08-29 19:05:26 -07:00
function tasks . on_construct ( pos , info_working , info_repair )
2021-09-21 05:49:04 -07:00
local meta = minetest.get_meta ( pos )
local inv = meta : get_inventory ( )
inv : set_size ( ' part ' , 1 )
2022-08-29 19:05:26 -07:00
meta : set_string ( ' infotext ' , info_working )
meta : set_string ( ' info_working ' , info_working )
meta : set_string ( ' info_repair ' , info_repair )
2021-09-21 05:49:04 -07:00
meta : set_int ( ' time_min ' , 30 )
meta : set_int ( ' time_max ' , 90 )
meta : set_int ( ' xp ' , 5 )
2022-06-05 19:29:05 -07:00
meta : set_int ( ' level ' , 0 )
2021-09-21 05:49:04 -07:00
end
2021-02-17 06:14:23 -08:00
function tasks . is_integer ( input )
local number = tonumber ( input )
if number then
if math.floor ( number ) == number then
return true
end
end
end
function tasks . valid_input ( string )
local variables = string : split ( ' , ' )
local xp = variables [ 1 ]
local timer = variables [ 2 ]
if tasks.is_integer ( xp ) and tasks.is_integer ( timer ) then
return true
end
end
2022-06-05 19:29:05 -07:00
minetest.register_on_player_receive_fields ( function ( player , formname , fields )
local name = player : get_player_name ( )
if formname == ' tasks:part_req_form ' then
if fields.gimme then
local pos = tasks.player_config [ name ]
local node = minetest.get_node ( pos ) . name
local def = minetest.registered_nodes [ node ]
local item = def.req_form
local max = def.req_count
local player_inv = player : get_inventory ( )
if not player_inv : contains_item ( ' main ' , { name = item , count = max } ) then
player_inv : add_item ( ' main ' , item )
else
minetest.chat_send_player ( name , ' You have too many of these already. ' )
end
end
end
end )
2022-08-29 19:05:26 -07:00
minetest.register_lbm ( { --This can be removed in a few months. 08/27/22
label = ' Tasks infotext update ' ,
name = ' tasks:info_update ' ,
run_at_every_load = false ,
nodenames = { ' group:tasks ' } ,
action = function ( pos , node )
local meta = minetest.get_meta ( pos )
local info = meta : get_string ( ' infotext ' )
local info_repair
local info_working
local i , j = string.find ( info , " %( " )
if i then
info_repair = info
info_working = string.sub ( info , 1 , ( i - 2 ) )
else
info_working = info
info_repair = info .. ' (Needs Repair) '
end
meta : set_string ( ' info_repair ' , info_repair )
meta : set_string ( ' info_working ' , info_working )
end
} )