예제 #1
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);
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        static void Prefix(Cell cell, ref Vector3 pos)
        {
            CellMark mark = ElevationManager.GetCellMark(cell);

            if (mark != null)
            {
                pos.y = mark.Elevation;
            }
        }
예제 #6
0
        static bool Prefix(Cell c, ref int stackHeight)
        {
            CellMark mark = ElevationManager.GetCellMark(c);

            if (mark.elevationTier > 0)
            {
                stackHeight -= mark.elevationTier * 2;
            }
            return(true);
        }
예제 #7
0
        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;
            }
        }
예제 #8
0
        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);
            }
        }
예제 #9
0
        public static void DoElevationBlock(Cell cell, ref bool result)
        {
            CellMark mark = ElevationManager.GetCellMark(cell);

            if (mark != null)
            {
                if (PathingManager.BlockedCompletely(cell))
                {
                    result = true;
                }
            }
        }
예제 #10
0
            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);
                }
            }
예제 #11
0
        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);
                }
            }
        }
예제 #12
0
 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;
             }
         }
     }
 }
예제 #13
0
        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 });
                        }
                    }
                }
            }
        }
예제 #14
0
 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);
     }
 }
예제 #15
0
 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;
     }));
 }
예제 #16
0
        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);
                    }
                }
            }
        }
예제 #17
0
        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);
        }
예제 #18
0
 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);
     }
 }
예제 #19
0
 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);
     }
 }
예제 #20
0
        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);
            }
        }
예제 #21
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);
            }
        }