コード例 #1
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);
                }
            }
コード例 #2
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 });
                        }
                    }
                }
            }
        }
コード例 #3
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);
            }
        }
コード例 #4
0
 static void Postfix(PlacementMode __instance)
 {
     Mod.helper.Log("test");
     if (__instance.IsPlacing())
     {
         Mod.dLog("placing");
         bool dragging = (bool)typeof(PlacementMode)
                         .GetField("attemptedDrag", BindingFlags.NonPublic | BindingFlags.Instance)
                         .GetValue(__instance);
         if (!dragging)
         {
             Building b    = __instance.GetHoverBuilding();
             Cell     cell = World.inst.GetCellData(b.transform.position);
             if (cell != null)
             {
                 Cell other = FindClosestGroundTile(cell);
                 if (other != null)
                 {
                     DebugExt.dLog("found close ground-level tile", false, other.Center);
                 }
             }
         }
     }
 }
コード例 #5
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);
            }
        }