Esempio n. 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);
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
        public static void Test_Returns_False_For_Session_Who_Stole_Others_Token()
        {
            //arrange
            Mock <ISigningService> signingService = new Mock <ISigningService>();

            signingService.Setup(x => x.isSigned(It.IsAny <byte[]>(), It.IsAny <byte[]>()))
            .Returns(true);

            ElevationManager      elevationManager = new ElevationManager(Mock.Of <ILog>(), signingService.Object);
            IElevatableSession    session          = Mock.Of <IElevatableSession>();
            AuthenticationMessage message          = new AuthenticationMessage(new byte[0]);

            session.UniqueAuthToken = elevationManager.RequestSingleUseToken(session);

            //act:Preform a authentication
            elevationManager.TryAuthenticate(session, message);

            //assert
            Assert.True(elevationManager.isElevated(session));

            //Should fail because this session isn't authorized with this token
            IElevatableSession criminalSession = Mock.Of <IElevatableSession>();

            criminalSession.UniqueAuthToken = session.UniqueAuthToken;

            Assert.False(elevationManager.isElevated(criminalSession));
        }
        public static void Test_Returns_False_On_Expected_Unelevated_Session()
        {
            //arrange
            ElevationManager elevationManager = new ElevationManager(Mock.Of <ILog>(), Mock.Of <ISigningService>());

            //assrt
            Assert.False(elevationManager.isElevated(Mock.Of <IElevatableSession>()));
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        static void Prefix(Cell cell, ref Vector3 pos)
        {
            CellMark mark = ElevationManager.GetCellMark(cell);

            if (mark != null)
            {
                pos.y = mark.Elevation;
            }
        }
Esempio n. 8
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;
            }
        }
Esempio n. 9
0
        static bool Prefix(Cell c, ref int stackHeight)
        {
            CellMark mark = ElevationManager.GetCellMark(c);

            if (mark.elevationTier > 0)
            {
                stackHeight -= mark.elevationTier * 2;
            }
            return(true);
        }
Esempio n. 10
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);
            }
        }
        public static void Test_Returns_False_After_Failed_Authentication_Without_Valid_Token()
        {
            //arrange
            ElevationManager   elevationManager = new ElevationManager(Mock.Of <ILog>(), Mock.Of <ISigningService>());
            IElevatableSession session          = Mock.Of <IElevatableSession>();

            //act:Preform a failed authentication
            elevationManager.TryAuthenticate(session, Mock.Of <AuthenticationMessage>());

            //assrt
            Assert.False(elevationManager.isElevated(session));
        }
Esempio n. 12
0
        public static void DoElevationBlock(Cell cell, ref bool result)
        {
            CellMark mark = ElevationManager.GetCellMark(cell);

            if (mark != null)
            {
                if (PathingManager.BlockedCompletely(cell))
                {
                    result = true;
                }
            }
        }
Esempio n. 13
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);
                }
            }
Esempio n. 14
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);
                }
            }
        }
Esempio n. 15
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;
             }
         }
     }
 }
Esempio n. 16
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 });
                        }
                    }
                }
            }
        }
Esempio n. 17
0
 private void ApplySettingsChanges()
 {
     ProgressMonitorProvider.Run(progressMonitor =>
     {
         if (requiresElevation)
         {
             ElevationManager.TryElevate(elevationContext => ApplySettingsChanges(elevationContext, progressMonitor),
                                         "Administrative access required to apply certain settings changes.");
         }
         else
         {
             ApplySettingsChanges(null, progressMonitor);
         }
     });
 }
Esempio n. 18
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);
     }
 }
Esempio n. 19
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;
     }));
 }
Esempio n. 20
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);
                    }
                }
            }
        }
Esempio n. 21
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);
        }
Esempio n. 22
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);
     }
 }
Esempio n. 23
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);
     }
 }
        public static void Test_Returns_True_After_Sucessful_Authentication()
        {
            //arrange
            Mock <ISigningService> signingService = new Mock <ISigningService>();

            signingService.Setup(x => x.isSigned(It.IsAny <byte[]>(), It.IsAny <byte[]>()))
            .Returns(true);

            ElevationManager      elevationManager = new ElevationManager(Mock.Of <ILog>(), signingService.Object);
            IElevatableSession    session          = Mock.Of <IElevatableSession>();
            AuthenticationMessage message          = new AuthenticationMessage(new byte[0]);

            session.UniqueAuthToken = elevationManager.RequestSingleUseToken(session);

            //act:Preform a authentication
            elevationManager.TryAuthenticate(session, message);

            //assrt
            Assert.True(elevationManager.isElevated(session));
        }
Esempio n. 25
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);
            }
        }
Esempio n. 26
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);
            }
        }
Esempio n. 27
0
    public async Task <HttpResponseMessage> Get(string a, string f, int id)
    {
        HttpResponseMessage r    = Request.CreateResponse();
        IElevation          elev = await ElevationManager.GetElevationAsync(id);

        CutSheet.CutSheet cutSheet = await AlumCloudPlans.Manager.GetCutSheetAsync(elev);
Esempio n. 28
0
        public void ElevationManager_ConstructorTest_with_ValidElevatorTimeList()
        {
            ElevationManager elevationManager = new ElevationManager(timeForEachElevators);

            Assert.IsNotNull(elevationManager);
        }
Esempio n. 29
0
 public void ElevationManager_ConstructorTest_with_ElevatorTimeListNull()
 {
     ElevationManager elevationManager = new ElevationManager(null);
 }