std.include("scripts/common.lua")

function init_level()
   -----------------------------------
   -- Dim lights
   set_ambient_light(0.01,0.01,0.01)
   set_direct_light(0.01,0.01,0.01)
   
   -----------------------------------
   -- Create portal
   local spawn_point=get_trigger_point(65280)
   local p=get_trigger_point_world_pos(spawn_point)
   local portal=instance_game_sprite("portal","portal",p)
   set_hostile(portal,false)
   set_shadow(portal,false)
   -----------------------------------
   -- Spawn old man
   local player=get_player()
   set_frame(player,frame_north)
   enable_input(player,false)
   enable_anim(player,false)
   enable_movement(player,false)
   -- Particle system
   local spawn_point=get_trigger_point(1)
   local p=add_vec3(get_trigger_point_world_pos(spawn_point),{ 1.5,0,4.5 })
   instance_particle_system("puff_white_smoke",p)

   local light=instance_light(add_vec3(p,{0,2,-1}),10)

   -- Old man
   wait_time(1000)
   local old_man=instance_game_sprite("old_man","old_man",p)
   set_frame(old_man,frame_south)
   wait_time(2000)
   -----------------------------------
   -- Speech part
   local text_id
   text_id=say(old_man,"Very good!\nHope the rabbits weren't\ntoo hard to deal with...",4000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(old_man,"As you might have noticed,\nthis dungeon is very dark...",4000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(old_man,"...and as such",2000,{ 0.2,1.0,0.1,1 }); wait_text(text_id)
   text_id=say(old_man,"...it's dangerous to go alone...",4000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(player,"So, this time you'll be comming?",4000,{ 0.2,1.0,0.1,1 }); wait_text(text_id)
   text_id=say(old_man,"!",2000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(old_man,"Again with the siliness!",4000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(old_man,"Just take this Orb of the Sun...",4000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(old_man,"When you activate it, it will\nshine a powerfull light for\na short period of time!",4000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(old_man,"This way, you can see your\nway around...",4000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(player,"And the wand? In case there's\nsome unholy hedgehogs or\nsomething?",4000,{ 0.2,1.0,0.1,1 }); wait_text(text_id)
   text_id=say(old_man,"No need, this is a deserted\npart of the dungeon...",4000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(old_man,"The lava makes everything too hot...\n",2000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(player,"Lava?! But, but...",2000,{ 0.2,1.0,0.1,1 }); wait_text(text_id)
   text_id=say(old_man,"Don't worry about the lava,\njust find the portal!",4000,{ 1,1,0,1 }); wait_text(text_id)
   text_id=say(old_man,"Watch out, the orb only has 3 charges,\nbut you can come back to this\nroom to recharge it!",4000,{ 1,1,0,1 }); wait_text(text_id)
   wait_time(1000)
   -----------------------------------
   -- Disappear old man
   -- Particle system
   instance_particle_system("puff_white_smoke",p)
   -- Old man
   wait_time(1000)
   kill_game_sprite(old_man)
   -----------------------------------
   -- Give object to player
   give_object(player,"scripts/orb_of_the_sun.lua")
   -----------------------------------
   -- Renable player
   enable_input(player,true)
   enable_anim(player,true)
   enable_movement(player,true)
end
