local assets =
{
	Asset("ANIM", "anim/gears_mace.zip"),
	Asset("ANIM", "anim/swap_gears_mace.zip"),
}

local function onfinished(inst)
	local fin = SpawnPrefab("ruins_battery")
	fin.Transform:SetPosition(inst.Transform:GetWorldPosition())	
    inst:Remove()
end

local function onequip(inst, owner) 
    owner.AnimState:OverrideSymbol("swap_object", "swap_gears_mace", "swap_nightmaresword")
    owner.AnimState:Show("ARM_carry") 
    owner.AnimState:Hide("ARM_normal") 
end

local function onunequip(inst, owner) 
    owner.AnimState:Hide("ARM_carry") 
    owner.AnimState:Show("ARM_normal") 
end

local chance = 0.20
local chance_effect = 0.50

local function onattack(inst, owner, target)
	if math.random() < chance then
		if math.random() < chance_effect then
			if target and target.components.burnable then
				target.components.burnable:Ignite(true)
			end
		else
			if target and target.components.freezable then
			target.components.freezable:AddColdness(1)
			target.components.freezable:SpawnShatterFX()
			end
		end
	end
end

local function fn()
	local inst = CreateEntity()
	
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()

    MakeInventoryPhysics(inst)
	
    inst.AnimState:SetBank("nightmaresword")
    inst.AnimState:SetBuild("gears_mace")
    inst.AnimState:PlayAnimation("idle")

	inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end
		
    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(TUNING.BATBAT_DAMAGE)
	inst.components.weapon:SetOnAttack(onattack)
	
    -------
	 
    inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetMaxUses(TUNING.SPEAR_USES)
    inst.components.finiteuses:SetUses(TUNING.SPEAR_USES)
    inst.components.finiteuses:SetOnFinished(onfinished)

    inst:AddComponent("tradable")
    inst:AddComponent("inspectable")
    
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.atlasname = "images/inventoryimages/gears_mace.xml"
    
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip(onequip)
    inst.components.equippable:SetOnUnequip(onunequip)
    inst.components.equippable.dapperness = TUNING.CRAZINESS_SMALL
	
    MakeHauntableLaunch(inst)
	
    return inst
end

STRINGS.NAMES.GEARS_MACE 								= "Randomatrix"
STRINGS.RECIPE_DESC.GEARS_MACE							= "Random elemental infliction."

STRINGS.CHARACTERS.GENERIC.DESCRIBE.GEARS_MACE 			= "A scientific breakthrough!"
STRINGS.CHARACTERS.WILLOW.DESCRIBE.GEARS_MACE 			= "Is no way to set this to 'fire' alone?"
STRINGS.CHARACTERS.WOLFGANG.DESCRIBE.GEARS_MACE 		= "Weapon is confused."
STRINGS.CHARACTERS.WENDY.DESCRIBE.GEARS_MACE 			= "A broken weapon."
STRINGS.CHARACTERS.WX78.DESCRIBE.GEARS_MACE 			= "RANDOM INTEGERS DETECTED"
STRINGS.CHARACTERS.WICKERBOTTOM.DESCRIBE.GEARS_MACE 	= "It appears it cannot properly process the gems installed."
STRINGS.CHARACTERS.WOODIE.DESCRIBE.GEARS_MACE 			= "Leave it to chance, eh?"
STRINGS.CHARACTERS.WAXWELL.DESCRIBE.GEARS_MACE 			= "This is not its intended purpose."
STRINGS.CHARACTERS.WATHGRITHR.DESCRIBE.GEARS_MACE 		= "I command the elements."
STRINGS.CHARACTERS.WEBBER.DESCRIBE.GEARS_MACE 			= "It's like a game of chance."

return Prefab( "common/inventory/gears_mace", fn, assets) 
