item_energysabre = MeleeWeapon:new()
itemTable = item_energysabre:new{
	extended = false,
}

function item_energysabre:initialize()
	self.item:LoadSoundEffect("swing", "Items/MeleeWeapons/Energysabre/SoundFX/item_energysabre_swing.wav")
	self.item:LoadSoundEffect("hit", "Items/MeleeWeapons/Energysabre/SoundFX/item_energysabre_hit.wav")
	self.item:LoadSoundEffect("extend", "Items/MeleeWeapons/Energysabre/SoundFX/item_energysabre_extend.wav")
	self.item:LoadSoundEffect("retract", "Items/MeleeWeapons/Energysabre/SoundFX/item_energysabre_retract.wav")
	self.item:LoadSoundEffect("hum", "Items/MeleeWeapons/Energysabre/SoundFX/item_energysabre_hum.wav")
	self.item._holdAnimationPlayer:StartAnimation("holdRetracted")
end

function item_energysabre:start()
end

function item_energysabre:equip()
	self.item._holdAnimationPlayer:StartAnimation("holdRetracted")
	self.extended = false
end

function item_energysabre:unequip()
	if self.humSoundInstance ~= nil and self.item:IsSoundPlaying(self.humSoundInstance) == true then
		self.humSoundInstance:Pause()
	end
end

function item_energysabre:updateWhileEquipped()
	if self.extended == true then
		if self.humSoundInstance == nil then
			self.humSoundInstance = self.item:PlayLoopingSoundEffect("hum", .3, 0)
		elseif self.item:IsSoundPlaying(self.humSoundInstance) ~= true then
			self.humSoundInstance:Resume()
		end
	else
		if self.humSoundInstance ~= nil and self.item:IsSoundPlaying(self.humSoundInstance) then
			self.humSoundInstance:Pause()
		end
	end
end

function item_energysabre:keyframeTriggerEvent(triggerString)
	MeleeWeapon.keyframeTriggerEvent(self, triggerString)
	
	if triggerString == "enableCollisions" then
		self.item:PlaySoundEffect("swing", .5, (.2 * math.random() - .1))
	end
end

function item_energysabre:animationCompleted(animationName)
	self.item.Attacking = false
	if animationName == "swing" then
		if self.extended == true then
			self.item:TransitionToAnimation("hold", .25)
		end
	elseif animationName == "extend" then
		self.item:TransitionToAnimation("hold", .25)
	elseif animationName == "retract" then
		self.item:TransitionToAnimation("holdRetracted", .25)
	end
end

function item_energysabre:hitBlock(monster)
	self.item:PlaySoundEffect("hit", .5, (.2 * math.random() - .1))
	self.item.Attacking = false
end

function item_energysabre:hitCreature(monster)
	self.item:PlaySoundEffect("hit", .5, (.2 * math.random() - .1))
	self.item.Attacking = false
end

function item_energysabre:primaryAttackStart()
	if self.item.Attacking == false then
		if self.extended == true then
			self.item:TransitionToAnimation("primaryAttack", .25, 2)
			self.item.Attacking = true;
		else
			self.item:TransitionToAnimation("extend", .25, 2)
			self.item:PlaySoundEffect("extend", .5, (.2 * math.random() - .1))
			self.extended = true
		end
	end
end

function item_energysabre:secondaryAttackStart()
	if self.extended == true then
		self.item:TransitionToAnimation("retract", .25, 2)
		self.item:PlaySoundEffect("retract", .5, (.2 * math.random() - .1))
		self.extended = false
	elseif self.extended == false then
		self.item:TransitionToAnimation("extend", .25, 2)
		self.item:PlaySoundEffect("extend", .5, (.2 * math.random() - .1))
		self.extended = true
	end
end

return itemTable