share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/death02.lua
changeset 12940 39b7b3ed619e
parent 12936 b9904380ce26
child 12970 dc35a79c6ef9
equal deleted inserted replaced
12939:0112ef349ddc 12940:39b7b3ed619e
    52 -- After hero killed an enemy, his weapons will be reset in the next round
    52 -- After hero killed an enemy, his weapons will be reset in the next round
    53 local heroWeaponResetPending = false
    53 local heroWeaponResetPending = false
    54 local battleStarted = false
    54 local battleStarted = false
    55 local firstTurn = true
    55 local firstTurn = true
    56 
    56 
    57 -- Spawn health particles and print health message
       
    58 local function healthBoostAnim(gear, health, tint)
       
    59 	if health < 1 then
       
    60 		return
       
    61 	end
       
    62 	local h = 0
       
    63 	while (h < health and h < 1000) do
       
    64 		local vg = AddVisualGear(GetX(gear), GetY(gear), vgtStraightShot, sprHealth, false)
       
    65 		if vg ~= nil then
       
    66 			SetVisualGearValues(vg, nil, nil, nil, nil, nil, nil, nil, nil, nil, tint)
       
    67 			SetState(vg, sprHealth)
       
    68 		end
       
    69 		h = h + 5
       
    70 	end
       
    71 	if math.floor(health) >= 1 then
       
    72 		AddCaption(string.format(loc("+%d"), math.floor(health)), GetClanColor(GetHogClan(gear)), capgrpMessage2)
       
    73 	end
       
    74 end
       
    75 
       
    76 -------------- LuaAPI EVENT HANDLERS ------------------
    57 -------------- LuaAPI EVENT HANDLERS ------------------
    77 
    58 
    78 function onGameInit()
    59 function onGameInit()
    79 	Seed = 1
    60 	Seed = 1
    80 	TurnTime = 25000
    61 	TurnTime = 25000
   133 	end
   114 	end
   134 end
   115 end
   135 
   116 
   136 function onGearDelete(gear)
   117 function onGearDelete(gear)
   137 	if isHog(gear) then
   118 	if isHog(gear) then
       
   119 		-- Set health to 100 (with heal effect, if health was smaller)
   138 		local healthDiff = 100 - GetHealth(hero.gear)
   120 		local healthDiff = 100 - GetHealth(hero.gear)
   139 		SetHealth(hero.gear, 100)
   121 		if healthDiff > 1 then
   140 		healthBoostAnim(hero.gear, healthDiff, 0x00FF00FF)
   122 			HealHog(hero.gear, healthDiff, true, 0x00FF00FF)
       
   123 		else
       
   124 			SetHealth(hero.gear, 100)
       
   125 		end
   141 		local deadHog = getHog(gear)
   126 		local deadHog = getHog(gear)
   142 		if deadHog.weapon == amMortar then
   127 		if deadHog.weapon == amMortar then
   143 			hero.mortarAmmo = 0
   128 			hero.mortarAmmo = 0
   144 		elseif deadHog.weapon == amFirePunch then
   129 		elseif deadHog.weapon == amFirePunch then
   145 			hero.firepunchAmmo = 0
   130 			hero.firepunchAmmo = 0
   163 end
   148 end
   164 
   149 
   165 function onGearDamage(gear, damage)
   150 function onGearDamage(gear, damage)
   166 	if isHog(gear) and GetHealth(hero.gear) then
   151 	if isHog(gear) and GetHealth(hero.gear) then
   167 		local bonusHealth = div(damage, 3)
   152 		local bonusHealth = div(damage, 3)
   168 		SetHealth(hero.gear, GetHealth(hero.gear) + bonusHealth)
   153 		HealHog(hero.gear, bonusHealth, true, 0xFF0000FF)
   169 		healthBoostAnim(hero.gear, bonusHealth, 0xFF0000FF)
       
   170 	end
   154 	end
   171 end
   155 end
   172 
   156 
   173 function onGameTick()
   157 function onGameTick()
   174 	AnimUnWait()
   158 	AnimUnWait()