static void Postfix(Road __instance, ref bool __result, Cell c) { try { if (__instance != null) { Mod.helper.Log("test"); Cell roadCell = World.inst.GetCellData(__instance.transform.position); if (roadCell != null && c != null) { CellMark markFrom = ElevationManager.GetCellMark(roadCell); CellMark markTo = ElevationManager.GetCellMark(c); if (markFrom != null && markTo != null) { if (ElevationManager.ValidTileForElevation(roadCell) && ElevationManager.ValidTileForElevation(c)) { if (!(markFrom.elevationTier - markTo.elevationTier == 1 || markFrom.elevationTier - markTo.elevationTier == 0)) { __result = false; } } } } } } catch (Exception ex) { DebugExt.HandleException(ex); } }
public static bool BlocksPathDirectional(Cell from, Cell to) { try { CellMark markFrom = ElevationManager.GetCellMark(from); CellMark markTo = ElevationManager.GetCellMark(to); Dictionary <Vector3, Direction> dirs = new Dictionary <Vector3, Direction>() { { new Vector3(1f, 0f, 0f), Direction.East }, { new Vector3(0f, 0f, 1f), Direction.South }, { new Vector3(-1f, 0f, 0f), Direction.West }, { new Vector3(0f, 0f, -1f), Direction.North }, }; Dictionary <Vector3, Diagonal> diagonals = new Dictionary <Vector3, Diagonal>() { { new Vector3(1f, 0f, 1f), Diagonal.SouthEast }, { new Vector3(1f, 0f, -1f), Diagonal.NorthEast }, { new Vector3(-1f, 0f, 1f), Diagonal.SouthWest }, { new Vector3(-1f, 0f, -1f), Diagonal.NorthWest }, }; if (markFrom != null && markTo != null) { if (markFrom.elevationTier > 0 || markTo.elevationTier > 0) { Vector3 diff = from.Center - to.Center; Vector3 diffNormalized = Vector3.ClampMagnitude(new Vector3(diff.x, 0f, diff.z), 1f); bool validCardinal = false; Direction dir = Direction.North; if (dirs.ContainsKey(diffNormalized)) { validCardinal = true; dir = dirs[diffNormalized]; } bool diagonal = diagonals.ContainsKey(diffNormalized); if (validCardinal && !diagonal) { if (markFrom.blockers.Contains(dir) || markTo.blockers.Contains(dir)) { return(true); } } } } } catch (Exception ex) { DebugExt.HandleException(ex); } return(false); }
static void Postfix(Cell __instance, ref Vector3 __result) { try { CellMark mark = ElevationManager.GetCellMark(__instance); if (mark != null) { __result = new Vector3((float)__instance.x + 0.5f, mark.Elevation, (float)__instance.z + 0.5f); } } catch (Exception ex) { DebugExt.HandleException(ex); } }
public static void CheckHomesForCrime() { try { List <IResidence> residences = Player.inst.Residentials; foreach (IResidence residence in residences) { CalcCrimeForHome(residence); } } catch (Exception ex) { DebugExt.HandleException(ex); } }
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(ProjectileDefense __instance, ref int __result) { try { Cell cell = World.inst.GetCellData(__instance.transform.position); if (cell != null) { CellMark mark = ElevationManager.GetCellMark(cell); if (mark != null) { __result += mark.elevationTier; } } } 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); } }
static void Postfix(Building PendingObj) { try { if (UnevenTerrain(PendingObj)) { DebugExt.dLog("Building on uneven terrain"); } else { Vector3 pos = PendingObj.transform.localPosition; Cell cell = PendingObj.GetCell(); CellMark mark = ElevationManager.GetCellMark(cell); float stackHeight = 0; if (PendingObj.Stackable) { stackHeight = GetStackHeightOfBuildingAtIndex(cell, cell.OccupyingStructure.IndexOf(PendingObj)); } if (PendingObj.CategoryName == "projectiletopper") { stackHeight = GetStackHeightTotal(cell); } if (mark != null) { PendingObj.transform.localPosition = new Vector3(pos.x, mark.Elevation + stackHeight, pos.z); PendingObj.UpdateShaderHeight(); } } } catch (Exception ex) { DebugExt.HandleException(ex); } }
static void Finalizer(Exception __exception) { DebugExt.HandleException(__exception); }