Skip to main content

Oceantrawler

Overview

The OceanTrawler component handles the gameplay logic for the ocean trawler entity, including lowering the net into the water, simulating fish capture (both while awake and while the player is sleeping), managing overflow catches beyond container capacity, and synchronizing visual state (e.g., net animations and minimap icon) accordingly. It integrates with the entity’s container, physics, state graph, and map systems.

Dependencies & Tags

Added Tags:

  • trawler_lowered (when net is lowered)
  • trawler_fish_escaped (when fish escaped due to overflow)

Removed Tags:

  • trawler_lowered (on raise or reset)
  • trawler_fish_escaped (on fix or reset)

Component Dependencies:

  • container: Required for item storage; used in nearly all logic.
  • timer: Added via inst:AddComponent("timer").
  • health, transform, physics, animstate, minimap, sg, components.schoolspawner (TheWorld): Used conditionally or in simulation logic.

Properties

PropertyTypeDefault ValueDescription
instEntityReference to the owning entity.
loweredbooleanfalseWhether the trawler net is currently lowered.
rangenumber2.5Radius around the trawler used to detect nearby ocean fish while active.
nearbytrawlerrangenumber16Radius to search for other trawlers that affect catch rates while sleeping.
nearbyshoalrangenumber16Radius to search for ocean fish shoal spawners when a fish is caught.
checkperiodnumber0.75Interval (in seconds) between catch simulation checks while active.
catchfishchancenumber0.125Base per-check probability of catching a fish while awake.
sleepcheckperiodnumberTUNING.SEG_TIMETime interval (in seconds) representing a sleep segment used for catch rate calculation.
sleepcatchfishchancenumber0.0625Base per-check probability of catching a fish per sleep segment.
baitcatchfishmodifiernumber2Multiplier applied to catch chance when appropriate bait is present.
taskTasknilPeriodic task for active-state fish checking.
startsleeptimenumber0Timestamp marking when the entity began sleeping.
elapsedsleeptimenumber0Accumulated time spent sleeping, used to calculate catch attempts.
overflowfishtable{}List of overflow fish indices (prefab names + "_inv") queued to spawn when the net is raised.
overflowescapepercentnumber0.2Base probability per overflow fish to trigger a full escape event.
fishescapedbooleanfalseWhether a full escape event has occurred.

Main Functions

Reset()

  • Description: Resets the trawler state to initial values, cancels update tasks, clears overflow/fish escape state, and removes the trawler_fish_escaped tag.
  • Parameters: None.

OnSave()

  • Description: Returns a serializable data table containing critical state (lowered status, sleep time, overflow fish, escape status) for persistence.
  • Parameters: None.

OnLoad(data)

  • Description: Restores trawler state from saved data. Sets minimap icon based on lowered state and re-applies tags if needed.
  • Parameters:
    data: Table containing lowered, elapsedsleeptime, overflowfish, and fishescaped.

HasCaughtItem()

  • Description: Returns whether the container holds at least one fish.
  • Parameters: None.
  • Returns: boolean.

HasFishEscaped()

  • Description: Returns whether the fish escape state is currently active.
  • Parameters: None.
  • Returns: boolean.

IsLowered()

  • Description: Returns whether the trawler net is lowered.
  • Parameters: None.
  • Returns: boolean.

Lower()

  • Description: Lowers the net, updates state graph, minimap icon, container openness, and starts periodic fish-checking tasks.
  • Parameters: None.

GetOceanTrawlerSpawnChanceModifier(spawnpoint)

  • Description: Returns a spawn chance modifier for sea creatures (e.g., Malbatross) near the trawler—specifically, increases spawn chance if trawler is lowered and full.
  • Parameters:
    spawnpoint: Point in world coordinates (not used directly, but used by caller).

GetBait(eater)

  • Description: Searches container for an edible item matching the diet of a given fish prefab and returns it if found.
  • Parameters:
    eater: Prefab name of the fish expecting bait.

ReleaseOverflowFish()

  • Description: Spawns and launches all overflow fish out of the net when raising.
  • Parameters: None.

Raise()

  • Description: Raises the net, restores container openness, clears overflow fish, updates animations, and resets minimap icon.
  • Parameters: None.

Fix()

  • Description: Clears the fish escape state and removes the trawler_fish_escaped tag.
  • Parameters: None.

StopUpdating()

  • Description: Cancels and nullifies the active fish-checking task.
  • Parameters: None.

StartUpdate()

  • Description: Begins a periodic task (using DoPeriodicTask) to check for fish while lowered and not escaped.
  • Parameters: None.

ReleaseOverflowFish() (Private helper referenced in public flow)

  • Description: See public function above.

SimulateCatchFish()

  • Description: Simulates fish capture over accumulated sleep time, accounting for ocean coverage, nearby trawlers, and bait. Triggers shoal events and overflow logic.
  • Parameters: None.

OnEntitySleep()

  • Description: Records the start of sleep time for later catch simulation.
  • Parameters: None.

OnEntityWake()

  • Description: Resets the periodic task, simulates catch attempts for elapsed sleep time, and restarts active checking.
  • Parameters: None.

OnUpdate(dt)

  • Description: Called periodically during active (non-sleep) periods to attempt catching nearby ocean fish based on range and chance modifiers.
  • Parameters:
    dt: Time delta for the check (used for consistency but not directly applied here).

Events & Listeners

  • Listens to:

    • "itemlose" → Triggers UpdateFishNetAnim
    • "itemget" → Triggers UpdateFishNetAnim
  • Triggers/Pushes:

    • "ms_shoalfishhooked" — when a fish from a shoal is caught.
    • "ms_registerfishshoal" / "ms_unregisterfishshoal"commented out in current code (disabled).