1-- Set the namespace 2local ns = {}; 3setmetatable(ns, {__index = _G}); 4all_use_escape_smoke = ns; 5setfenv(1, ns); 6 7-- local references 8local character = nil 9local target = nil 10local target_actor = nil 11local battle_item = nil 12 13local item_step = 0; 14local item_time = 0.0; 15 16local effect_triggered = false; 17 18local Battle = nil 19local Effects = nil 20 21local flash_color = vt_video.Color(1.0, 1.0, 1.0, 1.0); 22 23-- character, the BattleActor using the item 24-- target, the BattleEnemy target 25-- The battle item used on target 26function Initialize(_character, _target, _battle_item) 27 -- Keep the reference in memory 28 character = _character 29 target = _target 30 target_actor = _target:GetActor() 31 battle_item = _battle_item 32 33 Battle = ModeManager:GetTop(); 34 Effects = Battle:GetEffectSupervisor(); 35 36 flash_alpha = 0.0; 37 38 item_step = 0; 39 item_time = 0; 40 41 effect_triggered = false; 42end 43 44function Update() 45 -- Handle the timer 46 item_time = item_time + SystemManager:GetUpdateTime() 47 48 -- triggers the icon display 49 if (item_step == 0) then 50 Battle:GetIndicatorSupervisor():AddItemIndicator(character:GetXLocation() + (character:GetSpriteWidth() / 2.0), 51 character:GetYLocation() - character:GetSpriteHeight(), 52 battle_item:GetGlobalItem()); 53 item_step = 1; 54 return false 55 end 56 57 -- Trigger the throw escape smoke animation 58 if (item_step == 1 and item_time > 600) then 59 character:ChangeSpriteAnimation("escape_smoke") 60 item_step = 2 61 end 62 63 if (item_step == 2 and item_time > 1500) then 64 Battle:TriggerBattleParticleEffect("data/visuals/particle_effects/smoke.lua", 452, 424); 65 Battle:TriggerBattleParticleEffect("data/visuals/particle_effects/smoke.lua", 350, 550); 66 Battle:TriggerBattleParticleEffect("data/visuals/particle_effects/smoke.lua", 555, 560); 67 AudioManager:PlaySound("data/sounds/steam_hisses.ogg"); 68 69 item_step = 3 70 end 71 72 -- Trigger smoke and fade out 73 if (item_step == 3 and item_time > 2000) then 74 75 local display_time = item_time - 2000 76 77 -- The flash alpha 78 if (display_time >= 0 and display_time <= 500) then 79 flash_alpha = display_time / 500; 80 elseif (display_time > 500 and display_time <= 1500) then 81 flash_alpha = 1.0; 82 character:ChangeSpriteAnimation("idle") 83 elseif (display_time > 1500 and display_time <= 4000) then 84 flash_alpha = 1.0 - (display_time - 1500) / (4000 - 1500); 85 elseif (display_time > 4000) then 86 flash_alpha = 0.0; 87 end 88 flash_color:SetAlpha(flash_alpha) 89 Effects:EnableLightingOverlay(flash_color); 90 91 -- Triggers the effect in the middle of the flashbang animation 92 if (effect_triggered == false and item_time > 3000) then 93 battle_item:ExecuteBattleFunction(character, target) 94 effect_triggered = true; 95 end 96 97 -- When it fails ... 98 if (item_time > 5500) then 99 character:RegisterMiss(false); 100 AudioManager:PlaySound("data/sounds/cancel.wav"); 101 Effects:DisableLightingOverlay() 102 return true 103 end 104 105 return false 106 end 107 108 return false; 109end 110