Repository navigation
fix(npc): start new custom npcs at the configured relationship delta - #376
Conversation
NPCRelationData.Init starts an NPC at DefaultRelationshipValue * 5. S1API left that at the vanilla 0.4 and applied the configured delta only in the deferred FinalizeNetworkSpawn, so a new custom NPC read 2.0 for the first seconds after load. Write delta / 5 into the NPC data before the constructor Init and before native Awake. Saved relationship data still wins. Fixes ifBars#375
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 28 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
A PR from a fork gets no secrets, so it can only use the A manual run of the IL2CPP Build Check and the docs workflow on |
Linked issue
Fixes #375
Contributor checklist
Summary
A custom NPC that is new to an existing save now starts at the delta set with
NPCRelationshipDataBuilder.WithDelta, not at the vanilla 2.0.NPCRelationData.Initstarts an NPC atNPCData.Relationship.DefaultRelationshipValue * 5. S1API left that value at the vanilla 0.4 and applied the configured delta only inFinalizeNetworkSpawn, whichNPCNetworkBootstrapdefers by a few seconds. TwoInitcalls ran before that and both started the NPC at 2.0:InitializeRelationshipData) on the registered NPC.Awakeof the spawned instance.NPCPrefabIdentity.ApplyDefaultRelationshipValuenow writesclamp(delta, 0, 5) / 5into the NPC data'sDefaultRelationshipValuebefore both calls (constructor, andApplyCriticalIdentityBeforeAwakein theAwakeprefix).FinalizeNetworkSpawnstill applies the full relationship defaults as before.Compatibility
NPCPrefabIdentity.ApplyDefaultRelationshipValue,NPCDataAccess.ApplyDefaultRelationshipValue,NPCRelationshipPersistencePolicy.ToNativeDefaultRelationshipValue).NPCPrefabIdentityand a configured delta change. They start at the configured delta instead of 2.0 before spawn. NPCs without a configured delta keep the vanilla 0.4 / 2.0. The value written is the same deltaFinalizeNetworkSpawnapplies, clamped to 0 to 5 like the builder.DefaultRelationshipValueis on the per-NPC data copy S1API creates, not a shared preset.Validation
Mono
dotnet build S1API.sln -c MonoMelon: 0 errors.dotnet test -c MonoMelon: 825 passed, 0 failed.IL2CPP
dotnet build S1API.sln -c Il2CppMelon: 0 errors.dotnet test -c Il2CppMelon: 788 passed, 0 failed.ConfiguredDeltaMapsToNativeDefaultRelationshipValue,OutOfRangeDeltaIsClampedLikeTheBuilder.Runtime evidence
Game 0.4.7f12, MelonLoader 0.7.3, IL2CPP. A local test pack adds three NPCs to an existing save that has never seen them: customer A (delta 2.5, unlocked), customer B (delta 2.5, locked behind connections), contact C (delta 3.5). Each NPC is read with a console dump right when the save reports ready.
stable(3.2.1)relDelta=2relDelta=2.5relDelta=2.5relDelta=3.5relDelta=2.5relDelta=2.5Save and reload: saved with A at 2.5, then changed A's configured delta to 4.0 and reloaded. A read 2.5 at load and 2.5 again 9 s later, so the saved value still wins. No
[Relationship Data]warnings in the log.Documentation
None. The documented behavior of
WithDeltadoes not change; it now also holds before spawn.