local fail = false
for k,v in pairs(GLOBAL.ModManager.mods) do
	if v.modinfo and v.modinfo.id == "defaultmodpack" then
		fail = true
	end
end
if fail then
	print("WARNING! Itempack will be disabled as long as Modpack stays enabled. Ya know, compatibility reasons.")
	return false
end
--Mod doesn't load if Modpack is enabled

PrefabFiles = {
	"ewecushat",
	"hollowhat",
	"woodenmace",
	"summerbandana",
	"growthstaff",
	"birchnuthat",
	"cactusmace",
	"armormosquito",
	"fryingpan",
	"baronsuit",
	"dark_axe",
	"dark_pickaxe",
	"flyswatter",
	"lightnecklace",
	--
	"spartahelmut",
	"spartaswurd",
}

Assets = {
	Asset("SOUNDPACKAGE", "sound/fryingpan.fev"),
	Asset("SOUND", "sound/fryingpan1.fsb"),
	Asset("SOUNDPACKAGE", "sound/flyswatter.fev"),
	Asset("SOUND", "sound/flyswatter1.fsb"),

	Asset("ATLAS", "images/inventoryimages/ewecushat.xml"),
	Asset("ATLAS", "images/inventoryimages/hollowhat.xml"),
	Asset("ATLAS", "images/inventoryimages/woodenmace.xml"),
	Asset("ATLAS", "images/inventoryimages/summerbandana.xml"),
	Asset("ATLAS", "images/inventoryimages/growthstaff.xml"),
	Asset("ATLAS", "images/inventoryimages/birchnuthat.xml"),
	Asset("ATLAS", "images/inventoryimages/cactusmace.xml"),
	Asset("ATLAS", "images/inventoryimages/armormosquito.xml"),
	Asset("ATLAS", "images/inventoryimages/fryingpan.xml"),
	Asset("ATLAS", "images/inventoryimages/baronsuit.xml"),
	Asset("ATLAS", "images/inventoryimages/dark_axe.xml"),
	Asset("ATLAS", "images/inventoryimages/dark_pickaxe.xml"),
	Asset("ATLAS", "images/inventoryimages/lightnecklace1.xml"),
	Asset("ATLAS", "images/inventoryimages/spartahelmut1.xml"),
	Asset("ATLAS", "images/inventoryimages/spartaswurd1.xml"),
}

local TUNING = GLOBAL.TUNING
local SpawnPrefab = GLOBAL.SpawnPrefab
local DST = GLOBAL.TheSim and GLOBAL.TheSim:GetGameID()=="DST"
local ROG = DST or GLOBAL.IsDLCEnabled(GLOBAL.REIGN_OF_GIANTS)

--much cleaner, isn't it? -M
modimport("strings.lua")
modimport("recipes.lua")

--fly swatter
bonus_targets = 
{
	bee = true,
	killerbee = true,
	mosquito = true,
	butterfly = true,
	glommer = true,
	dragonfly = true,
	dummytarget = true, -- for testing
}
 
AddComponentPostInit("combat", function(Combat)
	local OldCalcDamage = Combat.CalcDamage
	Combat.CalcDamage = function(self, target, weapon, ...)
		local old_damage = nil
		if weapon and weapon.prefab == "flyswatter" and target and bonus_targets[target.prefab] then
			old_damage = weapon.components.weapon.damage
			weapon.components.weapon.damage = old_damage + 85
			if self.inst.components.combat and self.inst.components.combat.damagemultiplier ~= nil and (self.inst.components.combat.damagemultiplier*weapon.components.weapon.damage < 100 or self.inst.components.combat.damagemultiplier <= 1 and self.inst:HasTag("spartan")) then
				if not self.inst:HasTag("spartan") then
					weapon.components.weapon.damage = math.ceil(weapon.components.weapon.damage/self.inst.components.combat.damagemultiplier)
				else
					weapon.components.weapon.damage = math.ceil(weapon.components.weapon.damage*1.25/self.inst.components.combat.damagemultiplier)
				end
			end -- buff the weapon damage in case player's damage mult is below 1
		end
		local ret = OldCalcDamage(self, target, weapon, ...)
		if old_damage and weapon then
			weapon.components.weapon.damage = old_damage
		end
		return ret
	end
end)

-- Sparta Helmet
AddComponentPostInit("combat", function(Combat)
	local OldCalcDamage = Combat.CalcDamage
	Combat.CalcDamage = function(self, target, weapon, ...)
		local old_dmg = nil
		if target and self.inst:HasTag("spartan") and self.inst.components.combat.damagemultiplier ~= nil then
			old_dmg = self.inst.components.combat.damagemultiplier
			self.inst.components.combat.damagemultiplier = old_dmg+0.25
		elseif target and self.inst:HasTag("spartan") and self.inst.components.combat.damagemultiplier == nil then
			old_dmg = 1
			self.inst.components.combat.damagemultiplier = old_dmg+0.25
		end
		local ret = OldCalcDamage(self, target, weapon, ...)
		if old_dmg then
			self.inst.components.combat.damagemultiplier = old_dmg
		end
		return ret
	end
end)

--dark axe
--I reverted changes to this function, since it was causing a bug in DST -D
function EvergreenPostInit(inst)
    if GLOBAL.TheWorld.ismastersim then
        local oldonfinish = inst.components.workable.onfinish
        inst.components.workable.onfinish = function(inst, chopper)
            if chopper and chopper:HasTag("shadowchopper") then
                inst.components.lootdropper:AddChanceLoot( "livinglog", 0.08)
            end
            oldonfinish(inst, chopper)
        end
    end
end
  
local trees = {"evergreen", "evergreen_normal", "evergreen_tall", "evergreen_sparse", "evergreen_sparse_normal", "evergreen_sparse_tall", "deciduoustree", "deciduoustree_normal", "deciduoustree_tall"}
for k,v in pairs(trees) do AddPrefabPostInit(v, EvergreenPostInit) end
