KnownModIndex = GLOBAL.KnownModIndex
STRINGS = GLOBAL.STRINGS
RECIPETABS = GLOBAL.RECIPETABS
Recipe = GLOBAL.Recipe
Ingredient = GLOBAL.Ingredient
TECH = GLOBAL.TECH
local TUNING = GLOBAL.TUNING
local ACTIONS = GLOBAL.ACTIONS
local Action = GLOBAL.Action
local require = GLOBAL.require
local AllRecipes = GLOBAL.AllRecipes
local GetValidRecipe = GLOBAL.GetValidRecipe
local RECIPETABS = GLOBAL.RECIPETABS
local TheInput = GLOBAL.TheInput
local ThePlayer = GLOBAL.ThePlayer
local IsServer = GLOBAL.TheNet:GetIsServer()
all_clients_require_mod = true 

PrefabFiles = {

	"shadowtorch",
	"shadowtorchfire",
	"shadowhelm",
	"shadowspear",
	"shadow_spear_projectile",
	"shadowtrident",
	"shadowcirclet",
	"shadowstaff",
	"shadowstaffprojectile",
	"shadowbatenemy",
"shadowbatcave",
"batdamageability",
"shadowbatminion",

}

Assets = {
Asset("IMAGE", "images/inventoryimages/shadowblueprint.tex"),
		Asset("ATLAS", "images/inventoryimages/shadowblueprint.xml"),
	
}

-- ==================================================================================

local require = GLOBAL.require
local STRINGS = GLOBAL.STRINGS

STRINGS.NAMES.SHADOWTORCH = "Shadow Torch"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.SHADOWTORCH = "A darker version of light."
STRINGS.RECIPE_DESC.SHADOWTORCH = "Burn deep into your mind."

STRINGS.NAMES.SHADOWSPEAR = "Shadow Spear"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.SHADOWSPEAR = "I can stab things with the essence of nothing. Neat."
STRINGS.RECIPE_DESC.SHADOWSPEAR = "Illusionary Weapon."

STRINGS.NAMES.SHADOWTRIDENT = "Devil's Pitchfork"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.SHADOWTRIDENT = "Even the shadows fear this weapon."
STRINGS.RECIPE_DESC.SHADOWTRIDENT = "Trident of the beast."

STRINGS.NAMES.SHADOWHELM = "Bat Hat"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.SHADOWHELM = "It's dangerous putting nightmares so close to your brain."
STRINGS.RECIPE_DESC.SHADOWHELM = "Insane brain container."

STRINGS.NAMES.SHADOWCIRCLET = "Enigmatic Crown"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.SHADOWCIRCLET = "Frightening and fancy"
STRINGS.RECIPE_DESC.SHADOWCIRCLET = "Ruler of nothing."

STRINGS.NAMES.SHADOWSTAFF = "Vampire Staff"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.SHADOWSTAFF = "Very spooky."
STRINGS.RECIPE_DESC.SHADOWSTAFF = "The wings are nessecary."

STRINGS.NAMES.SHADOWSTAFF = "Vampire Staff"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.SHADOWSTAFF = "Very spooky."
STRINGS.RECIPE_DESC.SHADOWSTAFF = "The wings are nessecary."

STRINGS.NAMES.SHADOWBATCAVE = "Spooky Den"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.SHADOWBATCAVE = "I can hear ominous breathing coming from this hole."

STRINGS.NAMES.SHADOWBATENEMY = "Flying Terror"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.SHADOWBATENEMY = "Fast moving nightmare incarnate."

STRINGS.NAMES.SHADWOBATMINION = "Flying Minion"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.SHADWOBATMINION = "Tiny terrors."
-- ==================================================================================

--    =================== AddRecipe stuff  ================== ================== ==================
    AddRecipe("shadowspear", 
	{Ingredient("spear", 1), Ingredient("nightmarefuel", 4)}, 
	RECIPETABS.MAGIC, TECH.MAGIC_TWO, nil, nil, nil, nil, nil, "images/inventoryimages/shadowspear.xml", "shadowspear.tex")
-- ==================================================================================
local EnableShadowTorch = GetModConfigData("EnableShadowTorch") or "true"
if EnableShadowTorch=="false" then	
else
    AddRecipe("shadowtorch", 
	{Ingredient("torch", 1), Ingredient("nightmarefuel", 3)}, 
	RECIPETABS.MAGIC, TECH.MAGIC_THREE, nil, nil, nil, nil, nil, "images/inventoryimages/shadowtorch.xml", "shadowtorch.tex")	
end	
	-- ==================================================================================
	 AddRecipe("shadowhelm", 
	{Ingredient("pigskin", 1), Ingredient("nightmarefuel", 2), Ingredient("batwing", 2)}, 
	RECIPETABS.MAGIC, TECH.MAGIC_THREE, nil, nil, nil, nil, nil, "images/inventoryimages/shadowhelm.xml", "shadowhelm.tex")
	-- ==================================================================================
local EnableBatStaff = GetModConfigData("EnableBatStaff") or "true"
if EnableBatStaff=="false" then	
else
	 AddRecipe("shadowstaff", 
	{Ingredient("purplegem", 1), Ingredient("nightmarefuel", 3), Ingredient("batwing", 2)}, 
	RECIPETABS.MAGIC, TECH.LOST, nil, nil, nil, nil, nil, "images/inventoryimages/shadowstaff.xml", "shadowstaff.tex")	
end	
-- ==================================================================================
local EnableShadowTrident = GetModConfigData("EnableShadowTrident") or "true"
if EnableShadowTrident=="false" then	
else
	 AddRecipe("shadowtrident", 
	{Ingredient("spear", 1), Ingredient("nightmarefuel", 3), Ingredient("livinglog", 2)}, 
	RECIPETABS.MAGIC, TECH.LOST, nil, nil, nil, nil, nil, "images/inventoryimages/shadowtrident.xml", "shadowtrident.tex")	
end
-- ==================================================================================
local EnableShadowCrown = GetModConfigData("EnableShadowCrown") or "true"
if EnableShadowCrown=="false" then		
else	
	 AddRecipe("shadowcirclet", 
	{Ingredient("purplegem", 1), Ingredient("nightmarefuel", 4), Ingredient("moonrocknugget", 4)}, 
	RECIPETABS.MAGIC, TECH.LOST, nil, nil, nil, nil, nil, "images/inventoryimages/shadowcirclet.xml", "shadowcirclet.tex")
end
-- ==================================================================================	
	
--# code by rezecib
if (KnownModIndex:IsModEnabled("workshop-354415247")) then
	local SMALL_MISS_CHANCE = GLOBAL.GetModConfigData("SMALL_MISS_CHANCE", "workshop-354415247")
	local SMALL_USES = GLOBAL.GetModConfigData("SMALL_USES", "workshop-354415247")
	local LARGE_USES = GLOBAL.GetModConfigData("LARGE_USES", "workshop-354415247")


	local smallhits =
	{	
		frog = true,
		penguin = true,
		eyeplant = true,
	}
	
	function ShadowSpearPostInit(inst)

		local spear = inst
		local function onattack(inst, attacker, target, skipsanity)
			local smalltarget = target:HasTag("smallcreature") and not smallhits[target.prefab]
			local missed = false

				if target.components.combat then
					target:PushEvent("attacked", {attacker = attacker, 0, weapon = spear})
				end			
			attacker.components.sanity:DoDelta(-5)
			
			local newspear = GLOBAL.SpawnPrefab('shadowspear')
			newspear.Transform:SetPosition(inst:GetPosition():Get())
	if newspear.components.finiteuses then
	newspear.components.finiteuses:SetUses(spear.components.finiteuses:GetUses())
	newspear.components.finiteuses:Use(3)
			end

			inst:Remove()
		-- spear.parent.AnimState:OverrideSymbol("swap_object", "", "")
			spear:Remove()


		end
		
local function playsound (inst, attacker, target)
attacker.SoundEmitter:PlaySound("dontstarve/wilson/attack_weapon", nil, nil, true)


end
		

		
			inst:AddComponent('spearthrowable')
		inst.components.spearthrowable:SetRange(8, 10)
		inst.components.spearthrowable:SetOnAttack(onattack)
		inst.components.spearthrowable:SetOnProjectileLaunch(playsound)
		inst.components.spearthrowable:SetProjectile("shadow_spear_projectile")
		
		

		end
		AddPrefabPostInit("shadowspear", ShadowSpearPostInit)
end
--# code by rezecib




function BluePrintEffect(inst)


	


	 
function newcolor(inst)
if inst.recipetouse == "shadowtrident" or inst.recipetouse == "shadowcirclet" or inst.recipetouse == "shadowstaff" then
if inst.components.inventoryitem then
    inst.entity:AddSoundEmitter()
	inst.components.inventoryitem.imagename = "shadowblueprint"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/shadowblueprint.xml"
	
	 function onignite(inst)
    inst.SoundEmitter:PlaySound("dontstarve/creatures/leif/livinglog_burn")
end
	
 function FuelTaken(inst, taker)
    if taker ~= nil and taker.SoundEmitter ~= nil then
        taker.SoundEmitter:PlaySound("dontstarve/creatures/leif/livinglog_burn")
    end
end	
	
	end
	
	    inst:ListenForEvent("onignite", onignite)
	    inst.components.fuel:SetOnTakenFn(FuelTaken)
		 inst.components.fuel.fuelvalue = TUNING.MED_FUEL
			   inst.AnimState:SetMultColour(0, 0, 0, 0.5)
	end
end


 inst:DoTaskInTime(0, newcolor)
	end

 	AddPrefabPostInit("blueprint", BluePrintEffect)
	
	

	
if EnableShadowTrident=="false" then


	
else
AddPrefabPostInit("crawlinghorror", CrawlingLoot)
AddPrefabPostInit("crawlingnightmare", CrawlingLoot)

function CrawlingLoot (inst)
	inst.components.lootdropper:AddChanceLoot("shadowtrident_blueprint", 0.05)
end
end


if EnableShadowCrown=="false" then		

else
AddPrefabPostInit("terrorbeak", TerrorLoot)
AddPrefabPostInit("nightmarebeak", TerrorLoot)
function TerrorLoot (inst)
	inst.components.lootdropper:AddChanceLoot("shadowcirclet_blueprint", 0.05)
end
end


if EnableBatStaff=="false" then	

else




function TreeFunction (inst)


function OnWorkedMe(inst)
if inst:HasTag("burnt") or inst:HasTag("stump") then
local x, y, z = inst.Transform:GetWorldPosition()
 local unit = GLOBAL.SpawnPrefab("shadowbatcave")  
 	unit.Transform:SetPosition(x, y, z)
else


	end
end



    inst:ListenForEvent("worked", OnWorkedMe)






	
end
AddPrefabPostInit("livingtree", TreeFunction)
end












	
	
	
	
	