Jump to content

Moonstorms on load don't always set the moon phase style properly if Celestial Champion was defeated


hoxi
  • Fixed

You can consider this a bug/oversight report on the task scheduler as well, as the issue happens due to this:

function self:OnLoad(data)
	if data ~= nil then
		if data._alterguardian_defeated_count then
			_alterguardian_defeated_count = data._alterguardian_defeated_count
			if _alterguardian_defeated_count > 0 then
				self.inst:DoTaskInTime(0,function()
					TheWorld:PushEvent("ms_setmoonphasestyle", {style = "glassed_default"})
                    TheWorld:PushEvent("ms_moonboss_was_defeated", {count = _alterguardian_defeated_count})
				end)
			end
		end

		-- THIS MUST COME AFTER THE _alterguardian_defeated_count IS SET
		if data.moonstyle_altar then
			_moonstyle_altar = data.moonstyle_altar
			self.inst:DoTaskInTime(0,setmoonphasestyle)
		end

When two tasks for an entity are scheduled in the same stack for the same target tick, the order at which they run isn't necessarily the same as the order in which they were scheduled, due to the nature of how the scheduler works and how iteration is done there.

 

Ideally, the bit of code above should be tweaked a bunch regardless as there's no reason to run two tasks for it, but aside from that, either this can be addressed in the scheduler itself, or at least some notes can be added to clarify that this will happen, in scheduler.lua and in entityscript.lua.

 

Here's how that bit of code could be changed to work better and prevent the issue, even if might not look the best:

function self:OnLoad(data)
	if data ~= nil then
		if data._alterguardian_defeated_count then
			_alterguardian_defeated_count = data._alterguardian_defeated_count
		end

		if data.moonstyle_altar then
			_moonstyle_altar = data.moonstyle_altar
		end

		-- NOTE: intentionally checking the data. values instead of _moonstyle_altar and _alterguardian_defeated_count
		-- except for when firing the "ms_moonboss_was_defeated" event, as that's being done after a game tick and the data one could be outdated

		-- moonstorms are active and celestial champion was defeated
		if data.moonstyle_altar and data._alterguardian_defeated_count and data._alterguardian_defeated_count > 0 then
			self.inst:DoTaskInTime(0, function()
				setmoonphasestyle()
				TheWorld:PushEvent("ms_moonboss_was_defeated", {count = _alterguardian_defeated_count})
			end)
		elseif data.moonstyle_altar then -- moonstorms are active and celestial champion wasn't defeated
			self.inst:DoTaskInTime(0, setmoonphasestyle)
		elseif data._alterguardian_defeated_count and data._alterguardian_defeated_count > 0 then -- moonstorms are inactive and celestial champion was defeated
			self.inst:DoTaskInTime(0, function()
				TheWorld:PushEvent("ms_setmoonphasestyle", {style = "glassed_default"})
				TheWorld:PushEvent("ms_moonboss_was_defeated", {count = _alterguardian_defeated_count})
			end)
		end

 

Oh, lastly, on a slightly related note, the game doesn't save if the Moonstorms' effect of starting or ending that applies to the day phase is active (where the entire current day is set to be a full moon night or new moon night, respectively). Not that big of a deal but it is a bit jarring.


Steps to Reproduce
  • Load a world in which Moonstorms are active and Celestial Champion was defeated.
  • Notice how the moon phase style won't always be the correct one, and will be as if there's no moonstorms active.
  • Like 1



User Feedback


A developer has marked this issue as fixed. This means that the issue has been addressed in the current development build and will likely be in the next update.


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
  • Create New...