class 'Putemo';

function Putemo:__init()
	self.AA = 0;
	self.LastR = 0;
	self.Ignite = false;
	AddLoadCallback(function()
		PrintChat("<font color=\"#D2527F\">Loaded le teemo de kuzu</font>");
		if myHero:GetSpellData(SUMMONER_1).name:find("SummonerDot") then
			self.Ignite = true;
			self.IgniteSlot = SUMMONER_1;
		end
		if myHero:GetSpellData(SUMMONER_2).name:find("SummonerDot") then
			self.Ignite = true;
			self.IgniteSlot = SUMMONER_2;
		end
	end);
	AddProcessAttackCallback(function(unit, spell)
		if unit and unit.isMe then
			if spell.name:lower():find("attack") then
				if spell.target.type == myHero.type then
					if myHero:CanUseSpell(_R) == READY then
						if GetDistance(spell.target) < 200 then
							if self.LastR + 1.5 > os.clock() then return end
							CastSpell(_R, myHero.x, myHero.z);
						end
					end
					if myHero:CanUseSpell(_Q) == READY then
						CastSpell(_Q, spell.target);
					end
					if self.AA == 1 then
						if myHero:CanUseSpell(_W) == READY then
							self.AA = 0;
							CastSpell(_W);
						end
					else
						self.AA = 1;
					end
				end
				if self.AA == 1 and spell.target.type ~= myHero.type then
					self.AA = 0;
				end

			end
		end
	end);
	AddProcessSpellCallback(function(unit, spell)
		if unit and unit.isMe then
			if spell.name == "TeemoRCast" then
				self.LastR = os.clock();
			end
		end
	end);
	AddDrawCallback(function()
		for _, unit in pairs(GetEnemyHeroes()) do
			self:LetsDraw(unit);
		end
	end);
end

function Putemo:LetsDraw(unit)
	local barPos = GetUnitHPBarPos(unit);
	local off = GetUnitHPBarOffset(unit);
	local y = barPos.y + (off.y * 53) + 2;
	local xOff = ({['AniviaEgg'] = -0.1,['Darius'] = -0.05,['Renekton'] = -0.05,['Sion'] = -0.05,['Thresh'] = -0.03,})[unit.charName];
	local x = barPos.x + ((xOff or 0) * 140) - 66;
	if not unit.dead and unit.visible then
		if barPos.x > -100 and barPos.x < WINDOW_W+100 and barPos.y > -100 and barPos.y < WINDOW_H+100 then
			local dmg = unit.health - self:TDMG(unit);
			DrawLine(x+(((dmg > 0 and dmg or 0) / unit.maxHealth) * 101), y-15, x+(((dmg > 0 and dmg or 0) / unit.maxHealth) * 104), y-15, 50,  ARGB(255, 210, 82, 127));
			DrawLine(x + ((unit.health / unit.maxHealth) * 150), y-40, x+(((dmg > 0 and dmg or 0) / unit.maxHealth) * 104), y-40, 2, ARGB(255, 210, 82, 127))
			if dmg > unit.health then
				DrawText("Killable", 20, x + ((unit.health / unit.maxHealth) * 155), y-48, 0xFFFFFFFF);
			else
				DrawText(""..unit.health - dmg.."", 20, x + ((unit.health / unit.maxHealth) * 155), y-48, 0xFFFFFFFF);
			end
		end
	end
end

function Putemo:TDMG(unit)
	local ret = 0;
	if self.Ignite and myHero:CanUseSpell(self.IgniteSlot) == READY then
		ret = ret + 40 + (20 * myHero.level);
	end
	if myHero:CanUseSpell(_Q) == READY then
		local ret2 = myHero:GetSpellData(_Q).level * 45 + 35 + myHero.ap * .8;
		ret = ret + math.floor(myHero:CalcMagicDamage(unit, ret));
	end
	ret = ret + 4 * math.floor(myHero:CalcMagicDamage(unit, (6 * myHero:GetSpellData(_E).level + myHero.ap * .1));
end

Putemo();