Merge branch 'fix-static-target-null': no AI freeze when a targeted piece is destroyed
This commit is contained in:
commit
64fbd66987
1 changed files with 11 additions and 2 deletions
|
|
@ -207,14 +207,23 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
if (!FactionsConfig.Hostility) return;
|
if (!FactionsConfig.Hostility) return;
|
||||||
Traverse targetStatic = Traverse.Create(__instance).Field("m_targetStatic");
|
Traverse targetStatic = Traverse.Create(__instance).Field("m_targetStatic");
|
||||||
if (targetStatic.GetValue() == null) return;
|
// GetValue() hands back a plain object, and object == null skips Unity's destroyed
|
||||||
|
// check: a piece smashed or removed while targeted stays non-null here, and touching
|
||||||
|
// its gameObject throws. That throw escapes into MonoUpdaters.FixedUpdate and stops
|
||||||
|
// every AI after this one for the frame, every frame, until the field changes.
|
||||||
|
Component target = targetStatic.GetValue() as Component;
|
||||||
|
if (target == null)
|
||||||
|
{
|
||||||
|
if (targetStatic.GetValue() != null) targetStatic.SetValue(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Character monster = Traverse.Create(__instance).Field<Character>("m_character").Value;
|
Character monster = Traverse.Create(__instance).Field<Character>("m_character").Value;
|
||||||
if (monster == null) return;
|
if (monster == null) return;
|
||||||
|
|
||||||
// A piece an allied race built is never a target, with or without anyone around.
|
// A piece an allied race built is never a target, with or without anyone around.
|
||||||
// See FactionPieceTruce.
|
// See FactionPieceTruce.
|
||||||
if (targetStatic.GetValue() is Component target && FactionPieceTruce.Protects(target.gameObject, monster))
|
if (FactionPieceTruce.Protects(target.gameObject, monster))
|
||||||
{
|
{
|
||||||
targetStatic.SetValue(null);
|
targetStatic.SetValue(null);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue