Mana = 100.0
Think = 0
LastCast = 0
CurrentSpell = "explosion"

function onInit( )
end

function Holster()
	_GModText_Hide(Owner, 8988)
end

function onThink()
	if _CurTime() >= Think+0.35 then
		if Mana < 100 then
			Mana = Mana+3.9
		end
		DrawMana()
		Think = _CurTime()
	end
	if _PlayerIsKeyDown(Owner, IN_ATTACK2) then
		DrawSelectSpells()
		if _PlayerIsKeyDown(Owner, IN_FORWARD) and _PlayerIsKeyDown(Owner, IN_MOVERIGHT) then
			SelectSpell("paralyze")
		elseif _PlayerIsKeyDown(Owner, IN_FORWARD) and _PlayerIsKeyDown(Owner, IN_MOVELEFT) then
			SelectSpell("corpse explode")
		elseif _PlayerIsKeyDown(Owner, IN_FORWARD) then
			SelectSpell("explosion")
		elseif _PlayerIsKeyDown(Owner, IN_BACK) and _PlayerIsKeyDown(Owner, IN_MOVERIGHT) then
			SelectSpell("power well")
		elseif _PlayerIsKeyDown(Owner, IN_BACK) and _PlayerIsKeyDown(Owner, IN_MOVELEFT) then
			SelectSpell("blood well")
		elseif _PlayerIsKeyDown(Owner, IN_BACK) then
			SelectSpell("raise undead")
		elseif _PlayerIsKeyDown(Owner, IN_MOVELEFT) then
			SelectSpell("hex")
		elseif _PlayerIsKeyDown(Owner, IN_MOVERIGHT) then
			SelectSpell("swap location")
		end 
	else
		_GModRect_Hide(Owner, 8988)
	end
end

function SelectSpell(str)
	CurrentSpell = str
	_PrintMessage(Owner, 4, "Current Spell: "..string.upper(str))
end

function onPrimaryAttack( )
	if _CurTime() < LastCast+1 or _PlayerIsKeyDown(Owner, IN_ATTACK2) then return end

	local ManaCost = 0
	if CurrentSpell == "blood well" then ManaCost = 55
	elseif CurrentSpell == "raise undead" then ManaCost = 50
	elseif CurrentSpell == "paralyze" then ManaCost = 65
	elseif CurrentSpell == "explosion" then ManaCost = 60
	elseif CurrentSpell == "swap location" then ManaCost = 30
	elseif CurrentSpell == "hex" then ManaCost = 40
	elseif CurrentSpell == "corpse explode" then ManaCost = 15
	elseif CurrentSpell == "power well" then ManaCost = 65 end

	if Mana < ManaCost then
		_PrintMessage(Owner, 4, "Insufficient Mana")
		return
	end
	Mana = Mana - ManaCost
	_RunString("CastSpell4("..Number()..", "..Owner..")")
	LastCast = _CurTime()
end

function Number(str)
	if CurrentSpell == "blood well" then return 33
	elseif CurrentSpell == "power well" then return 34
	elseif CurrentSpell == "corpse explode" then return 35
	elseif CurrentSpell == "raise undead" then return 36
	elseif CurrentSpell == "paralyze" then return 37
	elseif CurrentSpell == "explosion" then return 38
	elseif CurrentSpell == "swap location" then return 39
	elseif CurrentSpell == "hex" then return 40 end
end

function onSecondaryAttack()
end

function DrawSelectSpells()
_GModRect_Start("necromancer/spellselect")
 _GModRect_SetPos(0.4, 0.75, 0.2, 0.21)
 _GModRect_SetColor(0, 0, 0, 255)
 _GModRect_SetTime(10, 0, 0)
_GModRect_Send(Owner, 8988)
end

function DrawMana()
if Owner <= 0 then return end
_GModRect_Start("gmod/white")
 _GModRect_SetPos(0.41, 0.96, Mana*0.0018, 0.05)
 _GModRect_SetColor( 0, 20, 200, 255 )
 _GModRect_SetTime(9999, 0, 0)
_GModRect_Send(Owner, 1801)
end

function onReload( )
	return false
end

function getWeaponSwapHands()
	return false	
end

function getWeaponFOV() return 75 end
function getWeaponSlot() return 5	end
function getWeaponSlotPos() return 6 end
function getFiresUnderwater() return true	end
function getReloadsSingly() return false end
function getDamage() return 10 end
function getPrimaryShotDelay()	return 0.1 end
function getPrimaryIsAutomatic() return false	end
function getBulletSpread() return vector3( 0.00, 0.00, 0.00 ) end
function getViewKick()	return vector3( 0.0, 0.0, 0.0)	end
function getViewKickRandom() return vector3( 0.0, 0.0, 0.0 ) end
function getNumShotsPrimary() return 1 end
function getPrimaryAmmoType() return "none" end
function getDamageSecondary() return 0 end
function getSecondaryShotDelay() return 1 end
function getSecondaryIsAutomatic()	return false end
function getBulletSpreadSecondary() return vector3( 0.001, 0.001, 0.001 ) end
function getViewKickSecondary() return vector3( 0.5, 0.0, 0.0) end
function getViewKickRandomSecondary() return vector3( 0.0, 0.0, 0.0 ) end
function getNumShotsSecondary() return 1 end
function getSecondaryAmmoType() return "none" end
function getViewModel() return "models/weapons/v_stunbaton.mdl" end
function getWorldModel() return "models/weapons/w_stunbaton.mdl" end
function getClassName() return "necromancer_wand" end
function getMaxClipPrimary() return 1 end
function getMaxClipSecondary()	return -1 end
function getDefClipPrimary() return 1	end
function getDefClipSecondary()	return 0 end
function getAnimPrefix() return "melee" end
function getPrintName() return "Necromancer's Wand" end
function getPrimaryScriptOverride() return 3 end
function getSecondaryScriptOverride() return 3 end
function getDeathIcon( ) return "d_necromancergeneric" end
