1local ns = {} 2setmetatable(ns, {__index = _G}) 3mt_elbrus_scent_anim = ns; 4setfenv(1, ns); 5 6-- Animated image members 7local scent = nil 8 9-- Other fog related members 10local scent_x_position = 300.0; 11local scent_y_position = 500.0; 12local scent_alpha = 0.0; 13local scent_timer; 14local scent_time_length = 8000; 15 16local poison_appliance_cooldown = 0; 17 18-- c++ objects instances 19local Map = nil 20local Script = nil 21local Effects = nil 22 23function Initialize(map_instance) 24 Map = map_instance; 25 Script = Map:GetScriptSupervisor(); 26 Effects = Map:GetEffectSupervisor(); 27 28 -- Construct a timer used to display the scent with a custom alpha value and position 29 scent_timer = vt_system.SystemTimer(scent_time_length, 0); 30 -- Load a scent image used to be displayed dynamically on the map. 31 scent = Script:CreateImage("data/visuals/ambient/fog.png"); 32 scent:SetDimensions(320.0, 256.0); 33 34 scent_timer:Run(); 35 36 poison_appliance_cooldown = 0; 37end 38 39function _ApplyPoison() 40 local index = 0; 41 for index = 0, 3 do 42 local char = GlobalManager:GetCharacterHandler():GetCharacter(index); 43 if (char ~= nil and char:IsAlive() == true) then 44 45 -- Only apply up to a moderate poison 46 local intensity = Map:GetActiveStatusEffectIntensity(char, vt_global.GameGlobal.GLOBAL_STATUS_HP); 47 if (intensity > vt_global.GameGlobal.GLOBAL_INTENSITY_NEG_MODERATE) then 48 -- Makes this be applied through the map mode, to make it applied correctly 49 -- and shown to the player in a visual way. 50 Map:ChangeActiveStatusEffect(char, 51 vt_global.GameGlobal.GLOBAL_STATUS_HP, 52 vt_global.GameGlobal.GLOBAL_INTENSITY_NEG_LESSER, 53 18000); -- multiple of 9000 on purpose 54 -- Give the characters a 5 seconds poison relisiance time 55 -- so they're not poisoned multiple times within a few miliseconds. 56 poison_appliance_cooldown = 5000; 57 end 58 end 59 end 60end 61 62 63function Update() 64 -- Start the timer only at normal battle stage 65 if (scent_timer:IsRunning() == false) then 66 scent_timer:Run(); 67 end 68 69 if (scent_timer:IsFinished()) then 70 scent_timer:Initialize(scent_time_length, 0); 71 scent_timer:Run(); 72 -- Make the fog appear at random position 73 scent_x_position = math.random(200.0, 700.0); 74 scent_y_position = math.random(200.0, 650.0); 75 scent_alpha = 0.0; 76 end 77 78 scent_timer:Update(); 79 -- update scent position and alpha 80 -- Apply a small shifting 81 scent_x_position = scent_x_position - (0.5 * scent_timer:PercentComplete()); 82 83 -- Apply parallax (the camera movement) 84 scent_x_position = scent_x_position + Effects:GetCameraXMovement(); 85 -- Inverted y coords 86 scent_y_position = scent_y_position + Effects:GetCameraYMovement(); 87 88 if (scent_timer:PercentComplete() <= 0.5) then 89 -- fade in 90 scent_alpha = scent_timer:PercentComplete() * 0.3 / 0.5; 91 else 92 -- fade out 93 scent_alpha = 0.3 - (0.3 * (scent_timer:PercentComplete() - 0.5) / 0.5); 94 end 95 96 if (poison_appliance_cooldown >= 0) then 97 poison_appliance_cooldown = poison_appliance_cooldown - SystemManager:GetUpdateTime(); 98 --print(poison_appliance_cooldown) 99 return; 100 end 101 102 -- Apply potential collision effects. 103 local camera = Map:GetCamera(); 104 local state = Map:CurrentState(); 105 if (camera ~= nil and state == vt_map.MapMode.STATE_EXPLORE) then 106 local x_pos = Map:GetScreenXCoordinate(camera:GetXPosition()) 107 local y_pos = Map:GetScreenYCoordinate(camera:GetYPosition()) 108 -- check using a simple bounding box, X centered, Y bottom aligned. 109 if (x_pos > scent_x_position - 32.0 and x_pos < scent_x_position + 32.0 and 110 y_pos > scent_y_position - 48.0 and y_pos < scent_y_position) then 111 --print("colliding with "..scent_x_position..", "..scent_y_position) 112 _ApplyPoison(); 113 end 114 end 115end 116 117local scent_color = vt_video.Color(0.4, 1.0, 0.4, 0.8); 118 119function DrawForeground() 120 -- Draw a random fog effect 121 scent_color:SetAlpha(scent_alpha); 122 VideoManager:Move(scent_x_position, scent_y_position); 123 scent:Draw(scent_color); 124end 125