local function GetBerriesAnim(inst, num) local max_cycles = inst.components.pickable.max_cycles local cycles_left = inst.components.pickable.cycles_left + num local percent = cycles_left / max_cycles return percent >= 0.9 and "berriesmost" or percent >= 0.33 and "berriesmore" or "berries"endlocal function GetEmptyAnim(inst) return inst.components.pickable:IsBarren() and "idle_dead" or "empty"endlocal function Shake(inst) if inst.components.pickable:CanBePicked() then inst.AnimState:PlayAnimation("shake") inst.AnimState:PushAnimation(GetBerriesAnim(inst, 0)) else inst.AnimState:PlayAnimation("shake_empty") inst.AnimState:PushAnimation(GetEmptyAnim(inst)) endendlocal function GetPerdSpawnChance() return IsSpecialEventActive(SPECIAL_EVENTS.YOTG) and TUNING.YOTG_PERD_SPAWNCHANCE or TUNING.PERD_SPAWNCHANCEendlocal function SpawnPerd(inst) if inst:IsValid() and not inst.components.pickable:IsBarren() then local perd = SpawnPrefab("perd") local x, y, z = inst.Transform:GetWorldPosition() local angle = math.random() * 2 * PI perd.Transform:SetPosition(x + math.cos(angle), 0, z + math.sin(angle)) perd.sg:GoToState("appear") perd.components.homeseeker:SetHome(inst) Shake(inst) endendlocal function OnPicked(inst, picker) inst.AnimState:PlayAnimation(GetBerriesAnim(inst, 1).."_picked") if TheWorld.state.issnowcovered or inst:GetIsWet() then inst.components.pickable:MakeBarren() else inst.AnimState:PushAnimation(GetEmptyAnim(inst)) if not picker:HasTag("berrythief") and math.random() < GetPerdSpawnChance() then inst:DoTaskInTime(3 + math.random() * 3, SpawnPerd) end endendlocal function MakeEmpty(inst) if inst.AnimState:IsCurrentAnimation("idle_dead") then inst.AnimState:PlayAnimation("dead_to_empty") inst.AnimState:PushAnimation("empty") else inst.AnimState:PlayAnimation("empty") endendlocal function MakeBarren(inst, wasempty) inst.AnimState:PushAnimation("idle_dead")endlocal function MakeFull(inst) inst.AnimState:PlayAnimation("idle_picked") inst.AnimState:PushAnimation(GetBerriesAnim(inst, 0))endlocal function OnTransplant(inst) inst.AnimState:PlayAnimation("idle_dead") inst.components.pickable:MakeBarren()endlocal function GetRegenTime(inst) --V2C: nil cycles_left means unlimited picks, so use max value for math local max_cycles = inst.components.pickable.max_cycles local cycles_left = inst.components.pickable.cycles_left or max_cycles local num_cycles_passed = math.max(0, max_cycles - cycles_left) return TUNING.BERRY_REGROW_TIME + TUNING.BERRY_REGROW_INCREASE * num_cycles_passed + TUNING.BERRY_REGROW_VARIANCE * math.random()endlocal function OnWorked(inst, worker) if inst.components.pickable:IsBarren() then inst.components.lootdropper:SpawnLootPrefab("twigs") inst.components.lootdropper:SpawnLootPrefab("twigs") else if inst.components.pickable:CanBePicked() then inst.components.lootdropper:SpawnLootPrefab("coffeebeans") end inst.components.lootdropper:SpawnLootPrefab("dug_"..inst.prefab) end inst:Remove()endlocal function OnHaunt(inst) --TUNING.HAUNT_CHANCE_ALWAYS Shake(inst) inst.components.hauntable.hauntvalue = TUNING.HAUNT_COOLDOWN_TINY return trueend