ignore next collision with first enex too

This commit is contained in:
in0finite 2019-11-24 17:00:18 +01:00
parent 8d93a7f2c5
commit 4acc23dacd

View file

@ -98,7 +98,7 @@ namespace SanAndreasUnity.Behaviours
public EntranceExitMapObject CurrentCollidingEnex { get; private set; } public EntranceExitMapObject CurrentCollidingEnex { get; private set; }
public Importing.Items.Placements.EntranceExit FirstEnex { get; private set; } public Importing.Items.Placements.EntranceExit FirstEnex { get; private set; }
public Importing.Items.Placements.EntranceExit SecondEnex { get; private set; } public Importing.Items.Placements.EntranceExit SecondEnex { get; private set; }
bool m_ignoreNextCollisionWithSecondEnex = false; Importing.Items.Placements.EntranceExit m_enexToIgnoreNextCollision;
private Coroutine m_findGroundCoroutine; private Coroutine m_findGroundCoroutine;
@ -652,43 +652,46 @@ namespace SanAndreasUnity.Behaviours
this.CurrentCollidingEnex = enex; this.CurrentCollidingEnex = enex;
// teleport to counterpart
if (NetStatus.IsServer) if (NetStatus.IsServer)
{ {
if (enex.Info == this.SecondEnex) if (enex.Info == m_enexToIgnoreNextCollision)
{ {
// we collided with second enex // we should ignore this collision
// collision will be processed next time
m_enexToIgnoreNextCollision = null;
}
else
{
if (enex.Info == this.SecondEnex)
{
// we collided with second enex
if (m_ignoreNextCollisionWithSecondEnex)
{
// ignore this collision
// collision will be processed next time
m_ignoreNextCollisionWithSecondEnex = false;
}
else
{
// teleport back to first enex ; reset first and second enex // teleport back to first enex ; reset first and second enex
var tmpEnex = this.FirstEnex; var tmpEnex = this.FirstEnex;
this.FirstEnex = null; this.FirstEnex = null;
this.SecondEnex = null; this.SecondEnex = null;
m_enexToIgnoreNextCollision = tmpEnex; // ignore next collision with first enex
this.TeleportToEnex(tmpEnex); this.TeleportToEnex(tmpEnex);
} }
} else
else
{
var matchingEnexes = Importing.Items.Item.Enexes.Where(e => e.Name == enex.Info.Name && e != enex.Info);
Debug.LogFormat("Matching enexes:\n{0}", string.Join("\n", matchingEnexes.Select(e => e.TargetInterior + " - " + e.Flags)));
var counterPart = matchingEnexes.FirstOrDefault(e => e.TargetInterior != enex.Info.TargetInterior);
if (counterPart != null)
{ {
// found a counterpart where we can teleport var matchingEnexes = Importing.Items.Item.Enexes.Where(e => e.Name == enex.Info.Name && e != enex.Info);
Debug.LogFormat("Matching enexes:\n{0}", string.Join("\n", matchingEnexes.Select(e => e.TargetInterior + " - " + e.Flags)));
// remember first and second enex var counterPart = matchingEnexes.FirstOrDefault(e => e.TargetInterior != enex.Info.TargetInterior);
this.FirstEnex = enex.Info; if (counterPart != null)
this.SecondEnex = counterPart; {
// teleport to second enex // found a counterpart where we can teleport
m_ignoreNextCollisionWithSecondEnex = true;
this.TeleportToEnex(counterPart); // remember first and second enex
this.FirstEnex = enex.Info;
this.SecondEnex = counterPart;
// ignore next collision with second enex
m_enexToIgnoreNextCollision = counterPart;
// teleport to second enex
this.TeleportToEnex(counterPart);
}
} }
} }
} }