public static float GetAbsoluteStackHeightOfBuildingAtIndex(Cell c, int idx) { CellMark mark = ElevationManager.GetCellMark(c); int count = 0; float i = 0; if (mark != null) { i = mark.Elevation; } while (count < c.OccupyingStructure.Count) { float stackRealHeight = 0f; if (buildingRealStackHeights.ContainsKey(c.OccupyingStructure[count].UniqueName)) { stackRealHeight = buildingRealStackHeights[c.OccupyingStructure[count].UniqueName]; } if (count == idx) { return(i); } i += stackRealHeight; count++; } return(0); }
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 UnevenTerrain(Building b) { Cell firstCell = b.GetCell(); bool flag = false; CellMark firstMark = ElevationManager.GetCellMark(firstCell); if (firstCell != null && firstMark != null) { int elevationTier = firstMark.elevationTier; b.ForEachTileInBounds(delegate(int x, int y, Cell cell) { CellMark mark = ElevationManager.GetCellMark(cell); if (mark != null) { if (mark.elevationTier != elevationTier) { flag = true; } } }); } return(flag); }
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 Prefix(Cell cell, ref Vector3 pos) { CellMark mark = ElevationManager.GetCellMark(cell); if (mark != null) { pos.y = mark.Elevation; } }
static bool Prefix(Cell c, ref int stackHeight) { CellMark mark = ElevationManager.GetCellMark(c); if (mark.elevationTier > 0) { stackHeight -= mark.elevationTier * 2; } return(true); }
static void Prefix(CastleBlock __instance, ref Vector3 position, ref Vector3 faceDirection) { CellMark mark = ElevationManager.GetCellMark(__instance.GetComponent <Building>().GetCell()); if (mark != null) { position.y = __instance.transform.localPosition.y - mark.Elevation; faceDirection.y = 0f; } }
static void Postfix(Building b) { Cell cell = World.inst.GetCellData(b.transform.position); CellMark mark = ElevationManager.GetCellMark(cell); float leveling = GetLevellingForBuilding(b); if (cell != null && mark != null) { b.transform.position = new Vector3(b.transform.position.x, b.transform.position.y + leveling, b.transform.position.z); } }
public static void DoElevationBlock(Cell cell, ref bool result) { CellMark mark = ElevationManager.GetCellMark(cell); if (mark != null) { if (PathingManager.BlockedCompletely(cell)) { result = true; } } }
static void Postfix(Building b, Vector3 newPos) { DebugExt.dLog("patch"); Cell cell = World.inst.GetCellData(b.transform.position); CellMark mark = ElevationManager.GetCellMark(cell); float leveling = mark.Elevation; if (cell != null && mark != null) { DebugExt.dLog(leveling.ToString()); b.transform.position = new Vector3(b.transform.position.x, b.transform.position.y + leveling, b.transform.position.z); } }
static void Postfix(WitchHut __result) { Cell cell = World.inst.GetCellData(__result.transform.position); if (cell != null) { CellMark mark = ElevationManager.GetCellMark(cell); if (mark != null) { __result.transform.position = new Vector3(__result.transform.position.x, mark.Elevation, __result.transform.position.z); } } }
static void Postfix(Cell __instance, ref int __result) { if (__instance != null && __instance.TopStructure != null) { if (__instance.TopStructure.Stackable) { CellMark mark = ElevationManager.GetCellMark(__instance); if (mark != null) { __result += mark.elevationTier * __instance.TopStructure.StackHeight; } } } }
static void Postfix(CastleBlock __instance) { Cell c = __instance.GetComponent <Building>().GetCell(); CellMark mark = ElevationManager.GetCellMark(c); if (mark != null) { Cell[] neighborCells = new Cell[4]; Building b = __instance.GetComponent <Building>(); World.inst.GetNeighborCells(c, ref neighborCells); int idx = -1; for (int n = 0; n < c.OccupyingStructure.Count; n++) { if (c.OccupyingStructure[n] == b) { idx = n; break; } } float selfHeight = BuildingPlacePatch.GetAbsoluteStackHeightOfBuildingAtIndex(c, idx); DebugExt.dLog(" -- " + idx.ToString() + " -- "); DebugExt.dLog(selfHeight.ToString()); typeof(CastleBlock).GetMethod("ClearDoors", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, new object[] { }); for (int m = 0; m < neighborCells.Length; m++) { float otherHeight = BuildingPlacePatch.GetAbsoluteStackHeightTotal(neighborCells[m]); if (otherHeight > 0f) { DebugExt.dLog(otherHeight.ToString()); } Cell cell = neighborCells[m]; if (cell != null) { if (Mathf.Approximately(selfHeight - 0.5f, otherHeight) && otherHeight > 0) { DebugExt.dLog("Connection!"); typeof(CastleBlock).GetMethod("VisibleDoors", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, new object[] { true }); } } } } }
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); } }
static void Postfix(int x, int z) { Cell cell = World.inst.GetCellData(x, z); if (cell != null) { CellMark mark = ElevationManager.GetCellMark(cell); if (mark != null) { foreach (GameObject obj in cell.Models) { obj.transform.position = new Vector3(obj.transform.position.x, obj.transform.position.y + mark.Elevation, obj.transform.position.z); } } } }
static Cell FindClosestGroundTile(Cell cell) { return(World.inst.FindBestSuitedCell(cell, true, 30, (_cell) => { CellMark mark = ElevationManager.GetCellMark(_cell); if (mark != null) { if (mark.elevationTier == 0) { return Vector3.Distance(cell.Center.xz(), _cell.Center.xz()); } } return 0f; })); }
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 float GetLevellingForBuilding(Building b) { float max = 0f; b.ForEachTileInBounds(delegate(int x, int z, Cell cell) { float num = 0f; CellMark mark = ElevationManager.GetCellMark(cell); if (mark != null) { num = mark.Elevation; } if (num > max) { max = num; } }); return(max); }
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); } }
internal void Mark(CellMark mark) { Field.ToList().ForEach(f => { f.DisableMenu(); }); switch (mark) { case CellMark.None: EvaluationStackPanel.Background = new SolidColorBrush(Colors.White); CodeStackPanel.Background = new SolidColorBrush(Colors.White); break; case CellMark.ForInput: GradientStop gs1 = new GradientStop(Colors.White, 0); GradientStop gs2 = new GradientStop(Colors.White, 0.5); GradientStop gs3 = new GradientStop(Colors.Gray, 0.5); GradientStop gs4 = new GradientStop(Colors.Gray, 1); LinearGradientBrush lgb = new LinearGradientBrush(); lgb.MappingMode = BrushMappingMode.Absolute; lgb.StartPoint = new Point(0, 0); lgb.EndPoint = new Point(4, 4); lgb.SpreadMethod = GradientSpreadMethod.Repeat; lgb.GradientStops.Add(gs1); lgb.GradientStops.Add(gs2); lgb.GradientStops.Add(gs3); lgb.GradientStops.Add(gs4); EvaluationStackPanel.Background = lgb; CodeStackPanel.Background = lgb; Field.ToList().ForEach(f => { f.EnableMenu(); }); break; case CellMark.CompareTrue: EvaluationStackPanel.Background = new SolidColorBrush(Colors.LightGreen); CodeStackPanel.Background = new SolidColorBrush(Colors.LightGreen); break; case CellMark.CompareFalse: EvaluationStackPanel.Background = new SolidColorBrush(Colors.IndianRed); CodeStackPanel.Background = new SolidColorBrush(Colors.IndianRed); break; } }
public static float GetAbsoluteStackHeightTotal(Cell c) { CellMark mark = ElevationManager.GetCellMark(c); float i = 0; if (mark != null) { i = mark.Elevation; } bool flag = false; for (int count = 0; count < c.OccupyingStructure.Count; count++) { float stackRealHeight = 0f; if (c.OccupyingStructure[count].Stackable) { if (buildingRealStackHeights.ContainsKey(c.OccupyingStructure[count].UniqueName)) { DebugExt.dLog("stackable " + buildingRealStackHeights[c.OccupyingStructure[count].UniqueName].ToString()); stackRealHeight = buildingRealStackHeights[c.OccupyingStructure[count].UniqueName]; flag = true; } } i += stackRealHeight; } if (flag) { return(i); } else { return(0); } }
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); } }
public void MarkGuessCell(int row, CellMark mark) { GuessCells[row].Mark(mark); }
public PointInfoLog(PointInfo pointInfo, CellMark cellMark) { this.pointInfo = pointInfo; this.cellMark = cellMark; }
private void FillDiamon(Point screenPoint, bool isRefresh, bool isClearGreen,CellMark cellMark) { do { Color color = Color.Green; if (cellMark == CellMark.CanMove) { if (isClearGreen) { break; } color = Color.Green; } else if (cellMark == CellMark.Shelter) { color = Color.Yellow; } else if (cellMark == CellMark.CanNotMove) { color = Color.Red; } backgroundGraphics = Graphics.FromImage(pictureBox1.Image); Point[] points = new Point[] { new Point(screenPoint.X, screenPoint.Y - tileHeight / 2), new Point(screenPoint.X - tileWidth / 2, screenPoint.Y ), new Point(screenPoint.X, screenPoint.Y + tileHeight / 2), new Point(screenPoint.X + tileWidth / 2, screenPoint.Y ) }; backgroundGraphics.FillPolygon(new SolidBrush(Color.FromArgb(70, color)), points); } while (false); if (isRefresh) { pictureBox1.Refresh(); } }
private void DrawDiamonByMark(Point screenPoint, CellMark lastMark, CellMark cellMark) { if (lastMark != cellMark) { FillDiamon(screenPoint, true, false,cellMark); } //else if (lastMark != CellMark.CanNotMove && cellMark != lastMark) { // RefreshMesh(); //} //else { // FillDiamon(screenPoint, true, cellMark); //} }
private void ChangeCellMark(int X, int Y, CellMark cellMark) { Point _45Point = ScreenTo45(X, Y); Point screenPoint = GetDiamondScreenCenterBy45(_45Point); CellMark lastMark; PointInfo pointInfo = _points[_45Point]; if (pointInfo != null) { if (cellMark == pointInfo.mark) { return; } lastMark = pointInfo.mark; pointHistory.Add(new PointInfoLog(pointInfo, pointInfo.mark)); oneUndoTime++; pointInfo.mark = cellMark; this.撤销ToolStripMenuItem.Enabled = true; DrawDiamonByMark(screenPoint, lastMark, cellMark); } else { MessageBox.Show("程序执行发送错误"); System.Environment.Exit(0); } }