2019-06-09 00:55:25 +02:00
local Event = require ' utils.event '
local Token = require ' utils.token '
local Task = require ' utils.task '
2019-06-10 15:15:14 +02:00
local Debug = require ' utils.debug '
2019-06-09 00:55:25 +02:00
local Cutscene = require ' features.cutscene.cutscene_controller '
2019-06-14 23:19:21 +02:00
local CS_Rendering = require ' features.cutscene.rendering '
2019-06-09 00:55:25 +02:00
local RS = require ' map_gen.shared.redmew_surface '
2019-06-09 13:31:44 +02:00
local Color = require ' resources.color_presets '
2019-06-09 23:59:16 +02:00
local PC = require ' features.player_create '
2019-06-14 19:24:11 +02:00
local Experience = require ' map_gen.maps.diggy.feature.experience '
2019-06-10 15:15:14 +02:00
local register_rendering = Cutscene.register_rendering_id
local play_sound = Cutscene.play_sound
2019-06-14 19:24:11 +02:00
local draw_text = CS_Rendering.draw_text
local draw_multi_line = CS_Rendering.draw_multi_line_text
local rad = math.rad
2019-06-14 23:19:21 +02:00
local Rendering = require ' utils.rendering '
2021-03-30 21:09:48 +02:00
local Settings = require ' utils.redmew_settings '
local auto_play_cutscene_setting_name = ' diggy.auto_play_cutscene '
Settings.register ( auto_play_cutscene_setting_name , Settings.types . boolean , true , auto_play_cutscene_setting_name )
Cutscene.set_auto_play_cutscene_setting_name ( auto_play_cutscene_setting_name )
2019-06-09 00:55:25 +02:00
2019-06-10 15:15:14 +02:00
local DiggyCutscene = { }
2019-06-09 23:59:16 +02:00
2019-10-04 20:59:32 +02:00
local function valid ( entity )
return entity and entity.valid
end
2019-06-10 19:10:02 +02:00
local delayed_draw_text =
Token.register (
function ( params )
2019-06-14 23:19:21 +02:00
local player = params.player
2019-10-04 20:59:32 +02:00
if ( not valid ( player ) ) then
return
end
local tick = params.tick
2019-06-10 19:10:02 +02:00
if params.play_sound > 1 then
2019-06-14 23:19:21 +02:00
play_sound ( tick , player , ' utility/list_box_click ' , 1 )
2019-06-10 19:10:02 +02:00
end
2019-06-22 16:53:18 +02:00
register_rendering ( player.index , tick , draw_text ( params.settings , params.offset , params.text , params.player , params.params , params.draw_background , params.fit_to_edge ) )
2019-06-10 19:10:02 +02:00
end
)
2019-06-22 16:53:18 +02:00
local function draw_text_auto_replacing ( tick , settings , offset , texts , player , params , draw_background , fit_to_edge , time , between_time )
2019-06-10 19:10:02 +02:00
time = time or 400
time = time / # texts
between_time = between_time or 30
params.time_to_live = time - between_time
if params.background then
params.background . time_to_live = time - between_time
end
for i = 1 , # texts do
2019-06-10 19:29:14 +02:00
if texts [ i ] ~= ' ' then
2019-06-22 16:53:18 +02:00
Task.set_timeout_in_ticks ( time * ( i - 1 ) , delayed_draw_text , { tick = tick , settings = settings , offset = offset , text = texts [ i ] , player = player , params = params , draw_background = draw_background , fit_to_edge = fit_to_edge , play_sound = i } )
2019-06-10 19:29:14 +02:00
end
2019-06-10 19:10:02 +02:00
end
end
2019-06-14 19:24:11 +02:00
local delayed_draw_arrow =
Token.register (
function ( params )
local player = params.player
2019-10-04 20:59:32 +02:00
if ( not valid ( player ) ) then
return
end
2019-06-14 23:19:21 +02:00
local tick = params.tick
2019-06-14 19:24:11 +02:00
params = params.params
local rendering_parmas = params.params
2019-06-22 16:53:18 +02:00
local id = CS_Rendering.draw_arrow ( params.settings , params.offset , player , rendering_parmas , params.fit_to_edge )
2019-06-14 23:19:21 +02:00
register_rendering ( player.index , tick , id )
2019-06-14 19:24:11 +02:00
Rendering.blink ( id , 20 , rendering_parmas.time_to_live )
end
)
2019-06-14 23:19:21 +02:00
local function delayed_function ( func , player , tick , params , offset_time )
2019-10-04 20:59:32 +02:00
if ( not valid ( player ) ) then
return
end
2019-06-14 23:19:21 +02:00
Task.set_timeout_in_ticks ( offset_time , func , { player = player , tick = tick , params = params } )
2019-06-14 19:24:11 +02:00
end
local delayed_fade_blackout =
Token.register (
function ( params )
2019-10-04 20:59:32 +02:00
local player = params.player
if ( not valid ( player ) ) then
return
end
2019-06-14 23:19:21 +02:00
local render_params = params.params
2019-10-04 20:59:32 +02:00
local id = CS_Rendering.blackout ( player , render_params.zoom , render_params.time_to_live , render_params.color )
register_rendering ( player.index , params.tick , id )
2019-06-14 23:19:21 +02:00
Rendering.fade ( id , render_params.time_to_live - 1 , 10 )
2019-06-14 19:24:11 +02:00
end
)
local original_resolution = { height = 1440 , width = 2560 }
local original_zoom = 1
2019-06-09 00:55:25 +02:00
local function cutscene_function ( player_index , waypoint_index , params )
local cases = { }
2019-06-14 19:24:11 +02:00
2021-04-17 22:21:48 +02:00
local player = game.get_player ( player_index )
2019-06-09 13:31:44 +02:00
local ttw = params.time_to_wait
local zoom = params.zoom
2019-06-14 23:19:21 +02:00
local tick = params.tick
2019-06-14 19:24:11 +02:00
local settings = { original_resolution = original_resolution , original_zoom = original_zoom , player_zoom = zoom }
2019-06-10 01:04:14 +02:00
if waypoint_index ~= - 1 then
2019-06-14 23:19:21 +02:00
play_sound ( tick , player , ' utility/list_box_click ' , 1 )
--play_sound(tick, player, 'utility/inventory_move', 1, 10)
2019-06-09 23:59:16 +02:00
end
2019-06-09 00:55:25 +02:00
cases [ - 1 ] = function ( )
2019-06-14 23:19:21 +02:00
play_sound ( tick , player , ' utility/game_won ' )
play_sound ( tick , player , ' ambient/first-light ' , 1 , 550 )
register_rendering ( player_index , tick , CS_Rendering.blackout ( player , zoom , ttw + 1 ) )
2019-06-22 16:53:18 +02:00
register_rendering ( player_index , tick , draw_text ( settings , { x = 0 , y = - 16 } , ' Diggy ' , player , { scale = 10 , time_to_live = ttw , color = Color.yellow } , false , false ) )
2019-06-10 15:15:14 +02:00
register_rendering (
2019-06-09 23:59:16 +02:00
player_index ,
2019-06-14 23:19:21 +02:00
tick ,
2020-07-18 11:24:41 +02:00
draw_multi_line ( settings , { x = 0 , y = - 5 } , { { ' diggy.cutscene_case_line2 ' , ' Diggy ' } , ' --------------------- ' , { ' diggy.cutscene_case_line4 ' , ' Redmew ' } , { ' diggy.cutscene_case_line5 ' , ' redmew.com/discord ' } } , player , { scale = 5 , time_to_live = ttw } , false )
2019-06-09 23:59:16 +02:00
)
2019-06-22 16:53:18 +02:00
draw_text_auto_replacing ( tick , settings , { x = 0 , y = 10 } , { ' ' , { ' diggy.cutscene_case_line6 ' } } , player , { scale = 3 } , false , false , ttw , 0 )
draw_text_auto_replacing ( tick , settings , { x = 0 , y = 16 } , { ' ' , ' ' , { ' diggy.cutscene_case_line7 ' } } , player , { scale = 1 } , false , false , ttw , 0 )
2019-06-09 00:55:25 +02:00
end
cases [ 0 ] = function ( )
2019-06-14 23:19:21 +02:00
register_rendering ( player_index , tick , CS_Rendering.blackout ( player , zoom , ttw + 1 ) )
2019-06-22 16:53:18 +02:00
register_rendering ( player_index , tick , draw_text ( settings , { x = 0 , y = 0 } , ' Redmew - Diggy ' , player , { scale = 10 , time_to_live = ttw - 60 , color = Color.red } , false , false ) )
register_rendering ( player_index , tick , draw_text ( settings , { x = 0 , y = - 5 } , ' Introduction ' , player , { scale = 5 , time_to_live = ttw - 60 } , false , false ) )
2019-06-14 19:24:11 +02:00
2019-06-22 16:53:18 +02:00
delayed_function ( delayed_draw_arrow , player , tick , { settings = settings , offset = { x = 7 , y = 2.5 } , params = { rotation = rad ( - 45 ) , time_to_live = 275 * 3 - 30 } , fit_to_edge = true } , 0 )
2019-06-14 19:24:11 +02:00
2019-06-22 16:53:18 +02:00
draw_text_auto_replacing ( tick , settings , { x = 8.5 , y = 3 } , { ' This is our toolbar! ' } , player , { scale = 2.5 , alignment = ' left ' } , false , true , 275 )
2019-06-14 19:24:11 +02:00
2019-06-22 16:53:18 +02:00
draw_text_auto_replacing ( tick , settings , { x = 8.5 , y = 3 } , { ' ' , " Here you'll find a wide range of tools and informations about us! " } , player , { scale = 2.5 , alignment = ' left ' } , false , true , 275 * 2 )
2019-06-14 19:24:11 +02:00
2019-06-22 16:53:18 +02:00
draw_text_auto_replacing ( tick , settings , { x = 8.5 , y = 3 } , { ' ' , ' ' , ' Hover your mouse over them for more information ' } , player , { scale = 2.5 , alignment = ' left ' } , false , true , 275 * 3 )
2019-06-14 19:24:11 +02:00
2019-06-22 16:53:18 +02:00
delayed_function ( delayed_draw_arrow , player , tick , { settings = settings , offset = { x = 1 , y = 2.5 } , params = { rotation = rad ( - 45 ) , time_to_live = 275 - 30 } , fit_to_edge = true } , 275 * 3 )
2019-06-14 19:24:11 +02:00
2019-06-22 16:53:18 +02:00
draw_text_auto_replacing ( tick , settings , { x = 2.5 , y = 3 } , { ' ' , ' ' , ' ' , ' You can toggle our toolbar with this button ' } , player , { scale = 2.5 , alignment = ' left ' } , false , true , 275 * 4 )
2019-06-14 19:24:11 +02:00
2019-06-22 16:53:18 +02:00
delayed_function ( delayed_draw_arrow , player , tick , { settings = settings , offset = { x = 3.5 , y = 2.5 } , params = { rotation = rad ( - 45 ) , time_to_live = 275 - 30 } , fit_to_edge = true } , 275 * 4.5 )
2019-06-14 19:24:11 +02:00
2019-06-22 16:53:18 +02:00
draw_text_auto_replacing ( tick , settings , { x = 5 , y = 3 } , { ' ' , ' ' , ' ' , ' ' , ' This is the Diggy experience menu ' } , player , { scale = 2.5 , alignment = ' left ' } , false , true , 275 * 5.5 )
2019-06-14 19:24:11 +02:00
2019-06-22 16:53:18 +02:00
delayed_function ( delayed_draw_arrow , player , tick , { settings = settings , offset = { x = 15 , y = 9 } , params = { rotation = rad ( - 90 ) , time_to_live = 275 - 30 } , fit_to_edge = true } , 275 * 5.5 )
2019-06-14 19:24:11 +02:00
2019-06-14 23:19:21 +02:00
Cutscene.toggle_gui ( tick , player , Experience , 275 * 5.5 , ' left ' )
2019-06-14 19:24:11 +02:00
2019-06-22 16:53:18 +02:00
draw_text_auto_replacing ( tick , settings , { x = 17 , y = 8.7 } , { ' ' , ' ' , ' ' , ' ' , ' ' , ' Here you can see the current progress of the mine ' } , player , { scale = 2.5 , alignment = ' left ' } , false , true , 275 * 6.5 )
2019-06-14 19:24:11 +02:00
2019-06-14 23:19:21 +02:00
Cutscene.toggle_gui ( tick , player , Experience , 275 * 6.5 )
2019-06-14 19:24:11 +02:00
2019-06-14 23:19:21 +02:00
delayed_function ( delayed_fade_blackout , player , tick , { zoom = zoom , time_to_live = 120 + 61 , color = { 0 , 0 , 0 , 1 } } , ttw - 61 )
2019-06-14 19:24:11 +02:00
end
cases [ 1 ] = function ( )
2019-06-22 16:53:18 +02:00
draw_text_auto_replacing ( tick , settings , { x = 0 , y = 18 } , { { ' diggy.cutscene_case0_line1 ' } , { ' diggy.cutscene_case0_line3 ' } } , player , { scale = 2.5 } , true , false , ttw )
2019-06-10 16:32:13 +02:00
local entity = RS.get_surface ( ) . find_entities_filtered { position = { 0 , 0 } , radius = 20 , name = ' stone-wall ' , limit = 1 }
2019-06-09 00:55:25 +02:00
if entity [ 1 ] then
local position = entity [ 1 ] . position
2019-06-09 13:31:44 +02:00
local waypoint = {
2019-06-14 19:24:11 +02:00
-- case 2
2019-06-09 00:55:25 +02:00
position = position ,
transition_time = 120 ,
2019-06-10 19:10:02 +02:00
time_to_wait = 275 ,
2019-06-09 00:55:25 +02:00
zoom = 5
}
2019-06-10 19:29:14 +02:00
Debug.print_position ( position , ' position of wall ' )
2019-06-14 19:24:11 +02:00
Cutscene.inject_waypoint ( player_index , waypoint , waypoint_index + 3 , true )
2019-06-09 00:55:25 +02:00
end
end
cases [ 2 ] = function ( )
2019-06-14 23:19:21 +02:00
--play_sound(tick, player, 'utility/build_small', 1, 25)
2019-06-22 16:53:18 +02:00
draw_text_auto_replacing ( tick , settings , { x = 0 , y = 18 } , { { ' diggy.cutscene_case1_line1 ' } } , player , { scale = 2.5 } , true , false , ttw )
2019-06-09 00:55:25 +02:00
end
cases [ 3 ] = function ( )
2019-06-22 16:53:18 +02:00
draw_text_auto_replacing ( tick , settings , { x = 0 , y = 18 } , { { ' diggy.cutscene_case2_line1 ' } , { ' diggy.cutscene_case2_line3 ' } } , player , { scale = 2.5 } , true , false , ttw )
2019-06-14 19:24:11 +02:00
end
cases [ 4 ] = function ( )
2019-06-22 16:53:18 +02:00
draw_text_auto_replacing ( tick , settings , { x = 0 , y = 18 } , { { ' diggy.cutscene_case3_line1 ' } , { ' diggy.cutscene_case3_line3 ' } } , player , { scale = 2.5 } , true , false , ttw )
2019-06-10 15:15:14 +02:00
local radius = 10
2019-06-09 23:59:16 +02:00
local entity
repeat
2019-06-10 16:32:13 +02:00
entity = RS.get_surface ( ) . find_entities_filtered { position = { 0 , 0 } , radius = radius , name = ' rock-big ' , limit = 1 }
if radius <= 10 then
radius = 0
end
radius = radius + 25
2019-06-09 23:59:16 +02:00
until entity [ 1 ] or radius >= 200
local position = { 0 , 3.5 }
local way_zoom = 0.4
2019-06-14 19:24:11 +02:00
entity = entity [ 1 ]
if entity then
position = entity.position
2019-06-09 23:59:16 +02:00
way_zoom = 5
2019-06-10 15:15:14 +02:00
Debug.print_position ( position , ' position of rock ' )
2019-06-09 23:59:16 +02:00
end
2019-06-09 00:55:25 +02:00
local waypoint = {
2019-06-14 19:24:11 +02:00
-- case 5
2019-06-09 00:55:25 +02:00
position = position ,
transition_time = 120 ,
2019-06-10 19:10:02 +02:00
time_to_wait = 550 ,
2019-06-09 23:59:16 +02:00
zoom = way_zoom
2019-06-09 00:55:25 +02:00
}
2019-06-14 19:24:11 +02:00
Cutscene.inject_waypoint ( player_index , waypoint , waypoint_index + 3 )
2019-06-09 00:55:25 +02:00
end
2019-06-14 19:24:11 +02:00
cases [ 5 ] = function ( )
2019-06-14 23:19:21 +02:00
play_sound ( waypoint_index , player , ' utility/axe_mining_ore ' , 3 , 35 )
2019-06-22 16:53:18 +02:00
draw_text_auto_replacing ( tick , settings , { x = 0 , y = 18 } , { { ' diggy.cutscene_case4_line1 ' } , { ' diggy.cutscene_case4_line3 ' } } , player , { scale = 2.5 } , true , false , ttw )
2019-06-09 00:55:25 +02:00
end
2019-06-14 19:24:11 +02:00
cases [ 6 ] = function ( )
2019-06-14 23:19:21 +02:00
play_sound ( tick , player , ' utility/research_completed ' , 1 , 5 )
2019-06-10 01:04:14 +02:00
local exp = 2500
local text = { ' ' , ' [img=item/automation-science-pack] ' , { ' diggy.float_xp_gained_research ' , exp } }
2019-06-10 16:32:13 +02:00
player.create_local_flying_text { position = params.position , text = text , color = Color.light_sky_blue , time_to_live = ttw / 3 }
2019-06-22 16:53:18 +02:00
draw_text_auto_replacing ( tick , settings , { x = 0 , y = 18 } , { { ' diggy.cutscene_case5_line1 ' } , { ' diggy.cutscene_case5_line3 ' } } , player , { scale = 2.5 } , true , false , ttw )
2019-06-09 00:55:25 +02:00
end
2019-06-14 19:24:11 +02:00
cases [ 7 ] = function ( )
2019-06-14 23:19:21 +02:00
play_sound ( tick , player , ' utility/axe_fighting ' , 5 , 25 , 10 )
play_sound ( tick , player , ' worm-sends-biters ' , 1 , 70 )
2019-06-22 16:53:18 +02:00
draw_text_auto_replacing ( tick , settings , { x = 0 , y = 18 } , { { ' diggy.cutscene_case6_line1 ' } , { ' diggy.cutscene_case6_line3 ' } } , player , { scale = 2.5 } , true , false , ttw )
2019-06-10 01:04:14 +02:00
end
2019-06-14 19:24:11 +02:00
cases [ 8 ] = function ( )
2019-06-22 16:53:18 +02:00
draw_text_auto_replacing ( tick , settings , { x = 0 , y = 18 } , { { ' diggy.cutscene_case7_line1 ' } , { ' diggy.cutscene_case7_line3 ' } } , player , { scale = 2.5 } , true , false , ttw )
2019-06-14 23:19:21 +02:00
--play_sound(tick, player, 'utility/tutorial_notice', 1)
2019-06-09 00:55:25 +02:00
end
local case = cases [ waypoint_index ]
if case then
case ( )
end
end
local waypoints = {
{
-- case -1
position = { x = 0 , y = 0 } ,
transition_time = 60 ,
2019-06-10 19:10:02 +02:00
time_to_wait = 600 ,
2019-06-09 00:55:25 +02:00
zoom = 0.5
} ,
2019-06-14 19:24:11 +02:00
{
-- case -1.1
position = { x = 0 , y = 0 } ,
2019-06-14 23:19:21 +02:00
transition_time = 0 ,
2019-06-14 19:24:11 +02:00
time_to_wait = 275 * 7 ,
zoom = 0.5
} ,
2019-06-09 00:55:25 +02:00
{
-- case 0
position = { x = 0 , y = 0 } ,
transition_time = 120 ,
2019-06-10 19:10:02 +02:00
time_to_wait = 550 ,
2019-06-09 00:55:25 +02:00
zoom = 1
} ,
{
-- case 1
2019-06-09 12:26:51 +02:00
position = { x = 0 , y = 0 } ,
transition_time = 120 ,
2019-06-10 19:10:02 +02:00
time_to_wait = 275 ,
2019-06-09 12:26:51 +02:00
zoom = 1.5
} ,
{
-- case 2
2019-06-09 00:55:25 +02:00
position = { x = 0.5 , y = 3.5 } ,
transition_time = 120 ,
2019-06-10 19:10:02 +02:00
time_to_wait = 550 ,
2019-06-09 00:55:25 +02:00
zoom = 5
} ,
{
2019-06-09 12:26:51 +02:00
-- case 3
2019-06-09 00:55:25 +02:00
position = { x = 0 , y = 0 } ,
transition_time = 120 ,
2019-06-10 19:10:02 +02:00
time_to_wait = 550 ,
2019-06-09 00:55:25 +02:00
zoom = 2
} ,
-- inserting case 4
{
-- case 5
2019-06-10 01:04:14 +02:00
position = { x = 0 , y = - 2 } ,
transition_time = 120 ,
2019-06-10 19:10:02 +02:00
time_to_wait = 550 ,
zoom = 1.8
2019-06-10 01:04:14 +02:00
} ,
{
-- case 6
2019-06-09 00:55:25 +02:00
position = { x = 0 , y = 0 } ,
transition_time = 120 ,
2019-06-10 19:10:02 +02:00
time_to_wait = 550 ,
2019-06-09 00:55:25 +02:00
zoom = 0.3
} ,
{
2019-06-10 01:04:14 +02:00
-- case 7
2019-06-09 00:55:25 +02:00
position = { x = 0 , y = 0 } ,
transition_time = 120 ,
2019-06-10 19:10:02 +02:00
time_to_wait = 430 ,
2019-06-09 00:55:25 +02:00
zoom = 0.8
}
}
2019-06-09 23:59:16 +02:00
local function terminate_function ( player_index )
2019-06-10 19:10:02 +02:00
local player = game.get_player ( player_index )
PC.show_start_up ( player )
player.print ( { ' diggy.replay_cutscene ' , ' /replay ' } , Color.yellow )
2019-06-09 23:59:16 +02:00
end
Cutscene.register_cutscene_function ( ' Diggy_Welcome ' , waypoints , Token.register ( cutscene_function ) , Token.register ( terminate_function ) )
2019-06-10 15:15:14 +02:00
Cutscene.register_replay ( ' Diggy_Welcome ' , 120 )
2019-06-09 00:55:25 +02:00
2019-06-09 13:31:44 +02:00
local start_cutscene =
Token.register (
function ( params )
2021-03-30 21:09:48 +02:00
local player_index = params.event . player_index
if Settings.get ( player_index , auto_play_cutscene_setting_name ) then
Cutscene.register_running_cutscene ( params.event . player_index , ' Diggy_Welcome ' , 120 )
end
2019-06-09 13:31:44 +02:00
end
)
2019-06-09 00:55:25 +02:00
function DiggyCutscene . register ( )
2019-06-09 23:59:16 +02:00
global.config . player_create.cutscene = true
2019-06-09 00:55:25 +02:00
Event.add (
defines.events . on_player_created ,
function ( event )
Task.set_timeout_in_ticks ( 60 , start_cutscene , { event = event } )
end
)
end
return DiggyCutscene