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 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>())); }
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 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 bool Prefix(Cell c, ref int stackHeight) { CellMark mark = ElevationManager.GetCellMark(c); if (mark.elevationTier > 0) { stackHeight -= mark.elevationTier * 2; } return(true); }
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)); }
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 }); } } } } }
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); } }); }
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 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(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 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); } }
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)); }
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 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);
public void ElevationManager_ConstructorTest_with_ValidElevatorTimeList() { ElevationManager elevationManager = new ElevationManager(timeForEachElevators); Assert.IsNotNull(elevationManager); }
public void ElevationManager_ConstructorTest_with_ElevatorTimeListNull() { ElevationManager elevationManager = new ElevationManager(null); }