Skip to content

Commit

Permalink
Update ServerKnockbackStabilizer.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zheneq committed Jan 5, 2024
1 parent 2abfa46 commit 6fa0890
Showing 1 changed file with 100 additions and 91 deletions.
191 changes: 100 additions & 91 deletions Assembly-CSharp/ServerKnockbackStabilizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,21 @@
#if SERVER
public class ServerKnockbackStabilizer
{
public void StabilizeKnockbacks(Dictionary<ActorData, ServerKnockbackManager.KnockbackHits> incomingKnockbacks, List<BoardSquare> additionalInvalidSquares)
public void StabilizeKnockbacks(
Dictionary<ActorData, ServerKnockbackManager.KnockbackHits> incomingKnockbacks,
List<BoardSquare> additionalInvalidSquares)
{
bool flag = true;
while (flag)
while (StabilizeKnockbacksForValidDestination(incomingKnockbacks, additionalInvalidSquares)
|| StabilizeKnockbacksVsObstacles(incomingKnockbacks)
|| StabilizeKnockbacksVsStationaries(incomingKnockbacks)
|| StabilizeKnockbacksVsKnockbackees(incomingKnockbacks))
{
bool flag2 = StabilizeKnockbacksForValidDestination(incomingKnockbacks, additionalInvalidSquares);
if (!flag2)
{
flag2 = StabilizeKnockbacksVsObstacles(incomingKnockbacks);
}
if (!flag2)
{
flag2 = StabilizeKnockbacksVsStationaries(incomingKnockbacks);
}
if (!flag2)
{
flag2 = StabilizeKnockbacksVsKnockbackees(incomingKnockbacks);
}
flag = flag2;
}
}

private bool StabilizeKnockbacksForValidDestination(Dictionary<ActorData, ServerKnockbackManager.KnockbackHits> incomingKnockbacks, List<BoardSquare> additionalInvalidSquares)
private bool StabilizeKnockbacksForValidDestination(
Dictionary<ActorData, ServerKnockbackManager.KnockbackHits> incomingKnockbacks,
List<BoardSquare> additionalInvalidSquares)
{
bool flag = false;
foreach (KeyValuePair<ActorData, ServerKnockbackManager.KnockbackHits> knockbackEntry in incomingKnockbacks)
Expand All @@ -39,35 +31,42 @@ private bool StabilizeKnockbacksForValidDestination(Dictionary<ActorData, Server
return flag;
}

private bool StabilizeKnockbackEntryForValidDestination(KeyValuePair<ActorData, ServerKnockbackManager.KnockbackHits> knockbackEntry, List<BoardSquare> additionalInvalidSquares)
private bool StabilizeKnockbackEntryForValidDestination(
KeyValuePair<ActorData, ServerKnockbackManager.KnockbackHits> knockbackEntry,
List<BoardSquare> additionalInvalidSquares)
{
bool result = false;
BoardSquarePathInfo boardSquarePathInfo = knockbackEntry.Value.GetKnockbackPath().GetPathEndpoint();
BoardSquarePathInfo boardSquarePathInfo2 = boardSquarePathInfo;
bool flag = boardSquarePathInfo.square != null && boardSquarePathInfo.square.IsValidForGameplay() && !additionalInvalidSquares.Contains(boardSquarePathInfo.square);
while (!flag)
BoardSquarePathInfo endpoint = knockbackEntry.Value.GetKnockbackPath().GetPathEndpoint();
BoardSquarePathInfo initialEndpoint = endpoint;
bool isValidEndpoint = endpoint.square != null
&& endpoint.square.IsValidForGameplay()
&& !additionalInvalidSquares.Contains(endpoint.square);
while (!isValidEndpoint)
{
if (boardSquarePathInfo.prev == null)
if (endpoint.prev == null)
{
flag = true;
isValidEndpoint = true;
}
else
{
boardSquarePathInfo.square = null;
boardSquarePathInfo.prev.next = null;
boardSquarePathInfo = boardSquarePathInfo.prev;
flag = (boardSquarePathInfo.square != null && boardSquarePathInfo.square.IsValidForGameplay());
endpoint.square = null;
endpoint.prev.next = null;
endpoint = endpoint.prev;
isValidEndpoint = endpoint.square != null && endpoint.square.IsValidForGameplay();
}
}
if (boardSquarePathInfo2 != boardSquarePathInfo)
if (initialEndpoint != endpoint)
{
knockbackEntry.Value.OnKnockbackPathStabilized(boardSquarePathInfo.square);
result = true;
knockbackEntry.Value.OnKnockbackPathStabilized(endpoint.square);
return true;
}
else
{
return false;
}
return result;
}

private bool StabilizeKnockbacksVsObstacles(Dictionary<ActorData, ServerKnockbackManager.KnockbackHits> incomingKnockbacks)
private bool StabilizeKnockbacksVsObstacles(
Dictionary<ActorData, ServerKnockbackManager.KnockbackHits> incomingKnockbacks)
{
bool flag = false;
foreach (KeyValuePair<ActorData, ServerKnockbackManager.KnockbackHits> knockbackEntry in incomingKnockbacks)
Expand All @@ -77,112 +76,122 @@ private bool StabilizeKnockbacksVsObstacles(Dictionary<ActorData, ServerKnockbac
return flag;
}

private bool StabilizeKnockbackEntryVsObstacles(KeyValuePair<ActorData, ServerKnockbackManager.KnockbackHits> knockbackEntry)
private bool StabilizeKnockbackEntryVsObstacles(
KeyValuePair<ActorData, ServerKnockbackManager.KnockbackHits> knockbackEntry)
{
bool result = false;
ActorData key = knockbackEntry.Key;
BoardSquarePathInfo boardSquarePathInfo = knockbackEntry.Value.GetKnockbackPath();
BoardSquarePathInfo boardSquarePathInfo2 = boardSquarePathInfo.next;
BoardSquarePathInfo prev = boardSquarePathInfo.prev;
while (boardSquarePathInfo2 != null)
BoardSquarePathInfo step = knockbackEntry.Value.GetKnockbackPath();
BoardSquarePathInfo next = step.next;
BoardSquarePathInfo prev = step.prev;
while (next != null)
{
bool flag = (prev != null && BarrierManager.Get() != null && BarrierManager.Get().IsMovementBlockedOnCrossover(key, prev.square, boardSquarePathInfo.square)) || (BarrierManager.Get() != null && BarrierManager.Get().IsMovementBlocked(key, boardSquarePathInfo.square, boardSquarePathInfo2.square));
if (flag)
if ((prev != null
&& BarrierManager.Get() != null
&& BarrierManager.Get().IsMovementBlockedOnCrossover(key, prev.square, step.square))
|| (BarrierManager.Get() != null
&& BarrierManager.Get().IsMovementBlocked(key, step.square, next.square)))
{
boardSquarePathInfo.next = null;
boardSquarePathInfo2.prev = null;
boardSquarePathInfo2 = null;
knockbackEntry.Value.OnKnockbackPathStabilized(boardSquarePathInfo.square);
step.next = null;
next.prev = null;
next = null;
knockbackEntry.Value.OnKnockbackPathStabilized(step.square);
result = true;
}
else
{
boardSquarePathInfo = boardSquarePathInfo2;
prev = boardSquarePathInfo2.prev;
boardSquarePathInfo2 = boardSquarePathInfo2.next;
step = next;
prev = next.prev;
next = next.next;
}
}
return result;
}

private bool StabilizeKnockbacksVsStationaries(Dictionary<ActorData, ServerKnockbackManager.KnockbackHits> incomingKnockbacks)
private bool StabilizeKnockbacksVsStationaries(
Dictionary<ActorData, ServerKnockbackManager.KnockbackHits> incomingKnockbacks)
{
bool result = false;
foreach (ActorData actorData in GetStationaryActorsWrtKnockback(incomingKnockbacks))
{
if (!actorData.IsDead())
if (actorData.IsDead())
{
BoardSquare currentBoardSquare = actorData.GetCurrentBoardSquare();
foreach (KeyValuePair<ActorData, ServerKnockbackManager.KnockbackHits> keyValuePair in incomingKnockbacks)
continue;
}
BoardSquare currentBoardSquare = actorData.GetCurrentBoardSquare();
foreach (KeyValuePair<ActorData, ServerKnockbackManager.KnockbackHits> keyValuePair in incomingKnockbacks)
{
ServerKnockbackManager.KnockbackHits value = keyValuePair.Value;
if (value.GetKnockbackEndSquare() == currentBoardSquare)
{
ServerKnockbackManager.KnockbackHits value = keyValuePair.Value;
if (value.GetKnockbackEndSquare() == currentBoardSquare)
BoardSquarePathInfo boardSquarePathInfo = value.GetKnockbackPath().BackUpOnceFromEnd();
if (value.GetKnockbackEndSquare() != boardSquarePathInfo.square)
{
value.OnKnockbackPathStabilized(boardSquarePathInfo.square);
result = true;
}
else
{
BoardSquarePathInfo boardSquarePathInfo = value.GetKnockbackPath().BackUpOnceFromEnd();
if (value.GetKnockbackEndSquare() != boardSquarePathInfo.square)
{
value.OnKnockbackPathStabilized(boardSquarePathInfo.square);
result = true;
}
else
{
Log.Error($"Failed to back up {keyValuePair.Key} in StabilizeKnockbacksVsStationaries.");
}
Log.Error($"Failed to back up {keyValuePair.Key} in StabilizeKnockbacksVsStationaries.");
}
}
}
}
return result;
}

private bool StabilizeKnockbacksVsKnockbackees(Dictionary<ActorData, ServerKnockbackManager.KnockbackHits> incomingKnockbacks)
private bool StabilizeKnockbacksVsKnockbackees(
Dictionary<ActorData, ServerKnockbackManager.KnockbackHits> incomingKnockbacks)
{
bool flag = false;
List<KeyValuePair<ActorData, ServerKnockbackManager.KnockbackHits>> list = incomingKnockbacks.ToList<KeyValuePair<ActorData, ServerKnockbackManager.KnockbackHits>>();
list.Sort(delegate(KeyValuePair<ActorData, ServerKnockbackManager.KnockbackHits> x, KeyValuePair<ActorData, ServerKnockbackManager.KnockbackHits> y)
List<KeyValuePair<ActorData, ServerKnockbackManager.KnockbackHits>> incomingKnockbacksSorted = incomingKnockbacks.ToList();
incomingKnockbacksSorted.Sort((x, y) =>
{
float num2 = x.Value.GetKnockbackEndSquare().HorizontalDistanceOnBoardTo(x.Key.GetCurrentBoardSquare());
float value3 = y.Value.GetKnockbackEndSquare().HorizontalDistanceOnBoardTo(y.Key.GetCurrentBoardSquare());
return num2.CompareTo(value3);
float xDist = x.Value.GetKnockbackEndSquare().HorizontalDistanceOnBoardTo(x.Key.GetCurrentBoardSquare());
float yDist = y.Value.GetKnockbackEndSquare().HorizontalDistanceOnBoardTo(y.Key.GetCurrentBoardSquare());
return xDist.CompareTo(yDist);
});
int num = 0;
while (num < list.Count && !flag)

bool stabilized = false;
for (int i = 0; i < incomingKnockbacksSorted.Count; i++)
{
ServerKnockbackManager.KnockbackHits value = list[num].Value;
for (int i = num + 1; i < list.Count; i++)
ServerKnockbackManager.KnockbackHits knockback1 = incomingKnockbacksSorted[i].Value;
for (int j = i + 1; j < incomingKnockbacksSorted.Count; j++)
{
KeyValuePair<ActorData, ServerKnockbackManager.KnockbackHits> keyValuePair = list[i];
ServerKnockbackManager.KnockbackHits value2 = keyValuePair.Value;
if (value.GetKnockbackEndSquare() == value2.GetKnockbackEndSquare())
ServerKnockbackManager.KnockbackHits knockback2 = incomingKnockbacksSorted[j].Value;
if (knockback1.GetKnockbackEndSquare() == knockback2.GetKnockbackEndSquare())
{
BoardSquarePathInfo boardSquarePathInfo = value2.GetKnockbackPath().BackUpOnceFromEnd();
if (boardSquarePathInfo.square != value2.GetKnockbackEndSquare())
BoardSquarePathInfo stepBack = knockback2.GetKnockbackPath().BackUpOnceFromEnd();
if (stepBack.square != knockback2.GetKnockbackEndSquare())
{
value2.OnKnockbackPathStabilized(boardSquarePathInfo.square);
flag = true;
knockback2.OnKnockbackPathStabilized(stepBack.square);
stabilized = true;
}
else
{
Log.Error($"Failed to back up {keyValuePair.Key} in StabilizeKnockbacksVsKnockbackees.");
Log.Error($"Failed to back up {incomingKnockbacksSorted[j].Key} in StabilizeKnockbacksVsKnockbackees.");
}
}
}
num++;
if (stabilized)
{
return true;
}
}
return flag;
return false;
}

private List<ActorData> GetStationaryActorsWrtKnockback(Dictionary<ActorData, ServerKnockbackManager.KnockbackHits> incomingKnockbacks)
private List<ActorData> GetStationaryActorsWrtKnockback(
Dictionary<ActorData, ServerKnockbackManager.KnockbackHits> incomingKnockbacks)
{
List<ActorData> list = new List<ActorData>(GameFlowData.Get().GetActors());
List<ActorData> actors = new List<ActorData>(GameFlowData.Get().GetActors());
foreach (ActorData item in incomingKnockbacks.Keys)
{
if (list.Contains(item))
if (actors.Contains(item))
{
list.Remove(item);
actors.Remove(item);
}
}
return list;
return actors;
}
}
#endif

0 comments on commit 6fa0890

Please sign in to comment.