static void Postfix(ArcherTower __instance, ref int __result, int maxHeight) { try { Cell cell = World.inst.GetCellData(__instance.transform.position); if (cell != null) { CellMark mark = ElevationManager.GetCellMark(cell); if (mark != null) { __result = Mathff.Clamp(__result + mark.elevationTier, 0, maxHeight); } } } catch (Exception ex) { DebugExt.HandleException(ex); } }
static void Postfix(Pathfinder __instance, ref Pathfinder.Node __result, int sx, int sz, Vector3 start, Vector3 end, int teamId) { try { Cell cell = null; float num = float.MaxValue; int num2 = 1; int num3 = Mathf.Clamp(sx - num2, 0, World.inst.GridWidth - 1); int num4 = Mathf.Clamp(sx + num2, 0, World.inst.GridWidth - 1); int num5 = Mathf.Clamp(sz - num2, 0, World.inst.GridHeight - 1); int num6 = Mathf.Clamp(sz + num2, 0, World.inst.GridHeight - 1); for (int i = num3; i <= num4; i++) { for (int j = num5; j <= num6; j++) { Cell cellDataUnsafe = World.inst.GetCellDataUnsafe(i, j); if (cellDataUnsafe != null) { if (!__instance.blocksPath(cellDataUnsafe, teamId) && !PathingManager.BlockedCompletely(cellDataUnsafe)) { float num7 = Mathff.DistSqrdXZ(cellDataUnsafe.Center, start); if (num7 < num) { num = num7; cell = cellDataUnsafe; } } } } } if (cell != null) { __result = __instance.GetFieldValue <Pathfinder.Node[, ]>("pathGrid")[cell.x, cell.z]; return; } __result = null; } catch (Exception ex) { DebugExt.HandleException(ex); } }
private static IMoveTarget GetNextViking(Vector3 pos, float range) { // Refer to SiegeMonster::ClosestMonster and UnitSystem::GetClosestDamageable. float rangeSquared = range * range; float currentClosestDistance = float.MaxValue; int currentLowestAssigned = int.MaxValue; IMoveTarget nextViking = null; foreach (IMoveTarget viking in enemyAssignments.Keys) { UnitSystem.Army army = viking as UnitSystem.Army; SiegeMonster ogre = viking as SiegeMonster; if ((army == null && ogre == null) || (army != null && (army.IsInvalid() || !OnSameLandmass(pos, army.GetPos()))) || (ogre != null && (ogre.IsInvalid() || !OnSameLandmass(pos, ogre.GetPos()))) || !TargetTypeEnabled(viking)) { continue; } // Select the closest viking squad or ogre with the least points to obey the assignment and distribution // rules. int assigned = enemyAssignments[viking]; float distanceSquared = Mathff.DistSqrdXZ(pos, viking.GetPos()); if (distanceSquared > rangeSquared || assigned > currentLowestAssigned) { continue; } if (nextViking == null || assigned < currentLowestAssigned || (distanceSquared < currentClosestDistance && assigned == currentLowestAssigned)) { nextViking = viking; currentClosestDistance = distanceSquared; currentLowestAssigned = assigned; } } return(nextViking); }