
local MakePlayerCharacter = require "prefabs/player_common"


local assets = {

        Asset( "ANIM", "anim/player_basic.zip" ),
        Asset( "ANIM", "anim/player_idles_shiver.zip" ),
        Asset( "ANIM", "anim/player_actions.zip" ),
        Asset( "ANIM", "anim/player_actions_axe.zip" ),
        Asset( "ANIM", "anim/player_actions_pickaxe.zip" ),
        Asset( "ANIM", "anim/player_actions_shovel.zip" ),
        Asset( "ANIM", "anim/player_actions_blowdart.zip" ),
        Asset( "ANIM", "anim/player_actions_eat.zip" ),
        Asset( "ANIM", "anim/player_actions_item.zip" ),
        Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ),
        Asset( "ANIM", "anim/player_actions_bugnet.zip" ),
        Asset( "ANIM", "anim/player_actions_fishing.zip" ),
        Asset( "ANIM", "anim/player_actions_boomerang.zip" ),
        Asset( "ANIM", "anim/player_bush_hat.zip" ),
        Asset( "ANIM", "anim/player_attacks.zip" ),
        Asset( "ANIM", "anim/player_idles.zip" ),
        Asset( "ANIM", "anim/player_rebirth.zip" ),
        Asset( "ANIM", "anim/player_jump.zip" ),
        Asset( "ANIM", "anim/player_amulet_resurrect.zip" ),
        Asset( "ANIM", "anim/player_teleport.zip" ),
        Asset( "ANIM", "anim/wilson_fx.zip" ),
        Asset( "ANIM", "anim/player_one_man_band.zip" ),
        Asset( "ANIM", "anim/shadow_hands.zip" ),
        Asset( "SOUND", "sound/sfx.fsb" ),
        Asset( "SOUND", "sound/wilson.fsb" ),
        Asset( "ANIM", "anim/beard.zip" ),

        Asset( "ANIM", "anim/venus.zip" ),
        Asset( "ANIM", "anim/venusrog.zip" ),
}
local prefabs = {
	"venus_flowerhat",
	"flower",
}


local start_inv = {
	"venus_flowerhat",
}


local function  flowerday(inst)
	if IsDLCEnabled(CAPY_DLC) then
	local clock = GetWorld().components.clock
		if not inst:GetIsOnWater() then		
		if clock:IsDay() and inst.components.health.currenthealth >0 then 
        local x,y,z = inst.Transform:GetWorldPosition()
		local fly = SpawnPrefab("flower") 
			if fly then
            fly.Transform:SetPosition(x,y,z)
			end
		end
		end
	elseif IsDLCEnabled(REIGN_OF_GIANTS) then 
	local clock = GetWorld().components.clock
		if clock:IsDay() and inst.components.health.currenthealth >0 then 
        local x,y,z = inst.Transform:GetWorldPosition()
		local fly = SpawnPrefab("flower") 
			if fly then
            fly.Transform:SetPosition(x,y,z)
			end
		end
	end
end

local fn = function(inst)
	
	inst.soundsname = "wilson"
	if IsDLCEnabled(REIGN_OF_GIANTS) then 
		inst.AnimState:SetBuild("venusrog")
	inst:AddComponent("farseer")
	end
	-- Minimap icon
	inst.MiniMapEntity:SetIcon( "venus.tex" )
	-- Stats	
	inst.components.health:SetMaxHealth(100)
	inst.components.hunger:SetMax(150)
	inst.components.sanity:SetMax(250)
	
	--Eat
	inst.components.eater.Venuseat = inst.components.eater.Eat	
	function inst.components.eater:Eat( food )
	if self:CanEat(food) then
		if food.components.edible.foodtype == "MEAT" then
		if self.inst.components.health then
		if (food.components.edible.healthvalue < 0 and self:DoFoodEffects(food) or food.components.edible.healthvalue > 0) and self.inst.components.health then
		        local delta = food.components.edible:GetHealth(self.inst) * -0.5
                 if delta ~= 0 then
                    self.inst.components.health:DoDelta(delta , nil, food.prefab)
                 end
			end
        end
        if self.inst.components.hunger then
			 local delta = food.components.edible:GetHunger(self.inst) * -0.5
                if delta ~= 0 then
                    self.inst.components.hunger:DoDelta(delta)
                end
        end
        if (food.components.edible.sanityvalue < 0 and self:DoFoodEffects(food) or food.components.edible.sanityvalue > 0) and self.inst.components.sanity then
		        local delta = food.components.edible:GetSanity(self.inst) * -0.5
                if delta ~= 0 then
                    self.inst.components.sanity:DoDelta(delta)
                end
		end
		elseif food.components.edible.foodtype == "VEGGIE" then
				if self.inst.components.health then
		if (food.components.edible.healthvalue < 0 and self:DoFoodEffects(food) or food.components.edible.healthvalue > 0) and self.inst.components.health then
		        local delta = food.components.edible:GetHealth(self.inst) * 0.5
                 if delta ~= 0 then
                    self.inst.components.health:DoDelta(delta , nil, food.prefab)
                 end
			end
        end
        if self.inst.components.hunger then

			 local delta = food.components.edible:GetHunger(self.inst) * 0.5
                if delta ~= 0 then
                    self.inst.components.hunger:DoDelta(delta)
                end
        end
        if (food.components.edible.sanityvalue < 0 and self:DoFoodEffects(food) or food.components.edible.sanityvalue > 0) and self.inst.components.sanity then
		        local delta = food.components.edible:GetSanity(self.inst) * 0.5
                if delta ~= 0 then
                    self.inst.components.sanity:DoDelta(delta)
                end
		end
		end
	end
	return inst.components.eater:Venuseat(food)
	end
	inst:AddTag("venus")
	inst:RemoveTag("scarytoprey")
	-- Damage 
    if IsDLCEnabled(CAPY_DLC) then
	inst.components.combat:AddDamageModifier("venus", -0.1)
	else
	inst.components.combat.damagemultiplier = 0.9
	end
	inst.components.builder.science_bonus = 1
	
	-- Hunger rate 
	inst.components.hunger.hungerrate = 1.25 * TUNING.WILSON_HUNGER_RATE
	
	inst.components.sanity.night_drain_mult = 1.25
    inst.components.sanity.neg_aura_mult = 1.25
	
	-- Movement speed
	inst.components.locomotor.walkspeed = 4
	inst.components.locomotor.runspeed = 6
	
	RECIPETABS['VENUS'] = {str = "VENUS", sort= 520, icon = "lvyetab.tex", icon_atlas = "images/hud/lvyetab.xml"}
	inst:ListenForEvent( "daytime",  function() flowerday(inst) end, GetWorld())
end

return MakePlayerCharacter("venus", prefabs, assets, fn, start_inv)
