Current location - Recipe Complete Network - Complete cookbook of home-style dishes - Introduction to the refreshing mechanism of floating objects on the sea in Don’t Starve Online
Introduction to the refreshing mechanism of floating objects on the sea in Don’t Starve Online

How are floating objects on the sea refreshed in Don’t Starve Together? Novice players may not understand the rules. Let’s take a look at the introduction to the refreshing mechanism of floating objects on the sea in Don’t Starve Together.

Introduction to the refreshing mechanism of floating objects in the sea of ??Don’t Starve Together

1. Types of floating objects

Weight refresh items:

Chinese name, code , weight

Driftwood, driftwood_log, 1

Boat fragment, boatfragment03, 0.3

Boat fragment, boatfragment04, 0.3

Boat fragment , boatfragment05, 0.3,

cutgrass, cutgrass, 1

rope, twigs, 1

oceanfishableflotsam_water, 1

< p>Must-refresh items:

Drift bottle, messagebottle

2. Surface logic

1. The refresh of drift bottles and the refresh of other items are two different things. Interference process, but will use some related functions together.

2. The refresh cycle of the drift bottle is randomly 1-2 days. If the randomly generated refresh point does not meet the conditions, it will be refreshed after one-eighth of a day. The refresh location is a point centered on the player, with a random angle and a radius of 40.

3. The first refresh period of other items is randomly 1-150 seconds, and the subsequent refresh periods are randomly 30-180 seconds. The location is the same as the drift bottle.

4. Each player refreshes independently. In other words, the more players there are together, the faster (more) the sensory refresh will be.

3. Underlying logic

All functions in this part are under the flotsamgerator component by default, and each generation process is bound to a single player.

Drift bottle refresh process: When the system needs to generate a drift bottle, the system will first call the StartGuaranteedSpawn function. Then call the ScheduleGuaranteedSpawn function to set a timer for the drift bottle, with a period of 1-2 game days (TUNING.TOTAL_DAY_TIME) evenly distributed. When the timer expires, the SpawnGuaranteedFlotsam function will be triggered. At this time, the SpawnFlotsamForPlayer function will be called to generate the item. After generation, the ScheduleGuaranteedSpawn function will be called back based on the generated results to time the next update of the drift bottle. If the item is generated successfully, the time will be based on the previous time; if the item generation fails, the period of the above timer will be one-eighth of the game days (GUARANTEED_FLOTSAM_REATTEMPT_DELAY).

Other items refresh process: When the system needs to generate other floating items, the system will first call the ScheduleSpawn function. The system will set a timer with a timing period of 1-150 random seconds (the source of 150 is 180-30 written in the code). The timing cycle calls the SpawnFlotsamForPlayer function to generate other items and re-enters the timing cycle. The subsequent timing period is a random number of seconds from 30 to 180.

SpawnFlotsamForPlayer function: First get the player's position and determine whether the player is on the boat. If not, return directly. Otherwise, get the coordinates of the ship. The position of the item refresh is only related to the player position and the position of the ship. The function for generating the item position is GetSpawnPoint. If the generated coordinates are available, a float will be generated. One thing to note here is that when the system needs to generate drift bottles, it will pass in the two parameters override_prefab and override_notrealflotsam, and when it generates other drift objects, these two parameters will be passed in empty. The two parameters override_prefab and override_notrealflotsam will then be passed to the GetSpawnPoint function. The first parameter is used to specify the generated floating objects. If this parameter is not specified, floating objects will be randomly generated based on the weight. (Therefore, a drift bottle can only be generated when the "drift bottle" parameter is passed here.) The second parameter, override_notrealflotsam, will eventually be passed to the setinsttoflotsam function to determine whether to add the "flotsam" mark to the generated items. In addition, the SpawnFlotsamForPlayer function has an additional parameter reschedule, which is a function name.

When the system calls the SpawnFlotsamForPlayer function from the ScheduleSpawn function, the ScheduleSpawn function itself is used as the parameter of reschedule to prepare for the next timing cycle.

SpawnFlotsam function: This function has 3 parameters: spawnpoint, prefab, notrealflotsam. spawnpoint is the item coordinates passed in from the SpawnFlotsamForPlayer function, and prefab is the specified generated item (can be empty). notrealflotsam will be passed to the setinsttoflotsam function. As mentioned above, the function will first determine whether prefab is empty. If it is empty, it will randomly select an item to generate based on the weight. Then a random number is generated to determine whether to rotate the item 180 degrees. Then transfer the item to the corresponding coordinates, and then pass the item and notrealflotsam parameters into the setinsttoflotsam function.

GetSpawnPoint function: generate coordinates. . The general idea is that based on the player coordinates, the angle is random and a point with a radius of 40 is generated. The availability of coordinates will be judged.

setinsttoflotsam function: This function has three parameters, inst, time, notag. inst is the item to be generated. If time is empty, time will be assigned a value of 3-4 game cycles (uniformly distributed). This time is used to calculate the time from item refresh to sink. notag is used to determine whether to add the "flotsam" tag. At the same time, three monitoring events are designed for the items, namely, sinking time, being picked up, and being removed. There will be other functions to deal with them later. What is more interesting is that when an item sinks, a "splash_sink" will be generated at the original coordinates of the item. (I tested it in the game and it seems to be a bubble.)

Overall logic:

There is a variable _maxflotsam, which is used to control the maximum number of floating objects, which is currently 4 (But there is no judgment on the current number of floating objects in the program. So this variable may not be actually used).

When the world is generated, the _updating variable will be judged. If it is false, it will be set to true, and all players in the _activeplayers list will enter the drift bottle generation process and other floating objects generation process. . If true, delete the current data of all floating objects (including drift bottles) and regenerate it. .

When a new player enters the game, the player will be added to the _activeplayers list. At the same time, enter the process of generating drift bottles. In addition, the _updating variable will be evaluated. If true, additionally enter the process of generating other floating objects.