public void ShowContractObjective(ContractObjectiveGameLogic contractObjectiveGameLogic) { contractObjectiveGameLogic.LogObjective("Contract Objective Shown"); contractObjectiveGameLogic.displayToUser = true; AccessTools.Field(typeof(ContractObjectiveGameLogic), "currentObjectiveStatus").SetValue(contractObjectiveGameLogic, ObjectiveStatus.Active); EncounterLayerParent.EnqueueLoadAwareMessage(new ObjectiveUpdated(contractObjectiveGameLogic.encounterObjectGuid)); }
static void Prefix(EncounterLayerParent __instance) { Main.Logger.Log($"[EncounterLayerParentInitializeContractPatch Prefix] Patching InitializeContract"); MissionControl.Instance.InitSceneData(); MissionControl encounterManager = MissionControl.Instance; MissionControl.Instance.RunEncounterRules(LogicBlock.LogicType.ENCOUNTER_MANIPULATION); }
static void Prefix(EncounterLayerParent __instance, MessageCenterMessage message) { Main.Logger.Log($"[EncounterLayerParentInitializeContractPatch Prefix] Patching InitializeContract"); InitializeContractMessage initializeContractMessage = message as InitializeContractMessage; CombatGameState combat = initializeContractMessage.combat; Contract activeContract = combat.ActiveContract; GizmoManager.GetInstance().SetContract(activeContract); }
protected override void SpawnUnits(bool offScreen) { base.SpawnUnits(offScreen); if (this.teamDefinitionGuid == EncounterRules.PLAYER_TEAM_ID) { EncounterLayerParent.EnqueueLoadAwareMessage(new RefreshPortraitsMessage()); } }
static void Prefix(EncounterLayerParent __instance) { Main.Logger.Log($"[EncounterLayerParentFirstTimeInitializationPatch Prefix] Patching FirstTimeInitialization"); MissionControl EncounterManager = MissionControl.Instance; if (EncounterManager.IsContractValid) { EncounterManager.RunEncounterRules(LogicBlock.LogicType.SCENE_MANIPULATION); } }
static void Prefix(EncounterLayerParent __instance) { Main.Logger.Log($"[EncounterLayerParentFirstTimeInitializationPatch Prefix] Patching FirstTimeInitialization"); MissionControl EncounterManager = MissionControl.Instance; if (EncounterManager.IsContractValid) { UnityGameInstance.BattleTechGame.MessageCenter.PublishMessage(new BeforeSceneManipulationMessage()); EncounterManager.RunEncounterRules(LogicBlock.LogicType.SCENE_MANIPULATION); } }
private EncounterLayerData GetActiveEncounter() { if (EncounterLayerData) { return(EncounterLayerData); } Contract activeContract = UnityGameInstance.BattleTechGame.Combat.ActiveContract; string encounterObjectGuid = activeContract.encounterObjectGuid; // Contract Type GUID EncounterLayerData selectedEncounterLayerData = EncounterLayerParent.GetLayerByGuid(encounterObjectGuid); return(selectedEncounterLayerData); }
public static void LoadMapData(this EncounterLayerData layerData, EncounterLayerIdentifier encounterLayerIdentifier, DataManager dataManager) { EncounterLayerParent component = MissionControl.MissionControl.Instance.EncounterLayerParent; MapMetaDataExporter mapMetaExporter = component.GetComponent <MapMetaDataExporter>(); AccessTools.Method(typeof(MapMetaDataExporter), "LoadMapMetaDataOnly").Invoke(mapMetaExporter, new object[] { UnityGameInstance.BattleTechGame.Combat.MapMetaData, dataManager }); MapMetaData mapMetaData = mapMetaExporter.mapMetaData; InclineMeshData inclineMeshData = mapMetaExporter.inclineMeshData; string encounterLayerIdentifierPath = encounterLayerIdentifier.path; string encounterLayerDataName = MapMetaDataExporter.GetEncounterLayerDataName(encounterLayerIdentifier.name); MissionControl.Main.LogDebug("[LoadMapData] Borrowing Map Data form Layer Data " + encounterLayerDataName); encounterLayerIdentifierPath = dataManager.ResourceLocator.EntryByID(encounterLayerDataName, BattleTechResourceType.LayerData, false).FilePath; byte[] data = File.ReadAllBytes(encounterLayerIdentifierPath); EncounterLayerData layerByGuid = layerData; Serializer.Deserialize <EncounterLayerData>(data, SerializationTarget.Exported, TargetMaskOperation.HAS_ANY, layerByGuid); layerByGuid.ReattachReferences(); using (SerializationStream serializationStream = new SerializationStream(File.ReadAllBytes(encounterLayerIdentifierPath.Replace(".bin", "_RaycastInfo.bin")))) { layerByGuid.LoadRaycastInfo(serializationStream); } int length = mapMetaData.mapTerrainDataCells.GetLength(1); int length2 = mapMetaData.mapTerrainDataCells.GetLength(0); for (int i = 0; i < length; i++) { for (int j = 0; j < length2; j++) { mapMetaData.mapTerrainDataCells[i, j].MapEncounterLayerDataCell = layerByGuid.mapEncounterLayerDataCells[i, j]; mapMetaData.mapTerrainDataCells[i, j].UpdateCachedValues(); } } string inclineMeshPathFromEncounterLayerDataPath = encounterLayerIdentifierPath.Replace(".bin", "_InclineMesh.IMS"); inclineMeshData = new InclineMeshData(); if (inclineMeshData.LoadFromPath(inclineMeshPathFromEncounterLayerDataPath)) { inclineMeshData.mapMetaData = mapMetaData; layerByGuid.inclineMeshData = inclineMeshData; } else { layerByGuid.inclineMeshData = null; } mapMetaExporter.mapTags = new TagSet(mapMetaData.mapTags); MissionControl.Main.LogDebug("[LoadMapData] Load Complete"); }
static void Prefix(LanceSpawnerGameLogic __instance) { // Main.LogDebug($"[LanceSpawnerGameLogicOnUnitSpawnCompletePatch] Patching Prefix"); if (HasLanceSpawnCompleted(__instance)) { LanceSpawnedMessage lanceSpawnedMessage = new LanceSpawnedMessage(__instance.encounterObjectGuid, __instance.LanceGuid); EncounterLayerParent.EnqueueLoadAwareMessage(lanceSpawnedMessage); /* * // From the unit spawn message - might need a similar one for lance spawning to interrupt * if (this.triggerInterruptPhaseOnSpawn) { * abstractActor.IsInterruptActor = true; * base.Combat.StackManager.InsertInterruptPhase(team.GUID, unitSpawnedMessage.messageIndex); * } */ } }
private void DestroyBuildingsUnderLanceSpawns(UnitSpawnPointGameLogic[] unitSpawns, BuildingRepresentation[] buildings, float radius) { foreach (UnitSpawnPointGameLogic unitSpawn in unitSpawns) { Vector3 position = unitSpawn.transform.position; foreach (BuildingRepresentation building in buildings) { if (!building.IsDead) { if (position.DistanceFlat(building.transform.position) <= Radius) { EncounterLayerParent.EnqueueLoadAwareMessage(new DestroyActorMessage(EncounterLayerData.MapLogicGuid, building.parentCombatant.GUID)); } } } } }
public void GenerateEncounterLayerBuildingData() { Main.Logger.LogDebug($"[EncounterDataManager.GenerateEncounterLayerBuildingData] Generating building data"); Terrain terrain = Terrain.activeTerrain; float terrainZSize = terrain.terrainData.size.z; float terrainXSize = terrain.terrainData.size.x; Vector3 terrainPosition = terrain.transform.position; float halfMapCellSize = (float)MapMetaDataExporter.cellSize / 2f; int halfMapCellSizeInt = MapMetaDataExporter.cellSize / 2; EncounterLayerParent encounterLayerParent = MissionControl.Instance.EncounterLayerParent; EncounterLayerData encounterLayerData = MissionControl.Instance.EncounterLayerData; MapMetaDataExporter mapMetaExporter = encounterLayerParent.GetComponent <MapMetaDataExporter>(); MapMetaData mapMetaData = UnityGameInstance.BattleTechGame.Combat.MapMetaData; Vector3 raycastOrigin = new Vector3(0f, 1000f, 0f); // Lookups Dictionary <string, int> regionRaycastHits = new Dictionary <string, int>(); List <RegionGameLogic> regionGameObjectList = new List <RegionGameLogic>(); List <ObstructionGameLogic> obstructionGameObjectList = new List <ObstructionGameLogic>(); // Marks only the ObstructionGameLogic objects for ray tracing for performance reasons AccessTools.Method(typeof(MapMetaDataExporter), "MarkCellsForRaycasting").Invoke(mapMetaExporter, new object[] { mapMetaData.mapTerrainDataCells, (int)terrain.transform.position.x, (int)terrain.transform.position.z }); // TODO: Maybe wipe region building lists. Not sure if I really need/want this yet RegionGameLogic[] componentsInChildren = encounterLayerData.GetComponentsInChildren <RegionGameLogic>(); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].InitRegionForRayCasting(); } // Iterate over the Z cell range for (float i = halfMapCellSize; i < terrainZSize; i += (float)MapMetaDataExporter.cellSize) { int zCellIndex = (int)i / MapMetaDataExporter.cellSize; // Iterate over the X cell range for (float j = halfMapCellSize; j < terrainXSize; j += (float)MapMetaDataExporter.cellSize) { int xCellIndex = (int)j / MapMetaDataExporter.cellSize; MapEncounterLayerDataCell mapEncounterLayerDataCell = new MapEncounterLayerDataCell(); if (mapMetaData.mapTerrainDataCells[zCellIndex, xCellIndex].doRayCast) { int hitIndex = 0; regionRaycastHits.Clear(); regionGameObjectList.Clear(); obstructionGameObjectList.Clear(); for (int k = -halfMapCellSizeInt; k < halfMapCellSizeInt; k++) { raycastOrigin.z = i + (float)k + terrainPosition.z; for (int l = -halfMapCellSizeInt; l < halfMapCellSizeInt; l++) { raycastOrigin.x = j + (float)l + terrainPosition.x; RaycastHit[] raycastHits = Physics.RaycastAll(raycastOrigin, Vector3.down); List <ObstructionGameLogic> list3 = new List <ObstructionGameLogic>(); // Go through all the raycasts at Z,X of the terrain by cell size (middle of cell) // Then find any regions hit, record the number of hits/cells the region has for (int m = 0; m < raycastHits.Length; m++) { RegionGameLogic regionGameLogic = raycastHits[m].transform.GetComponent <RegionGameLogic>(); if (regionGameLogic != null) { if (!regionRaycastHits.ContainsKey(regionGameLogic.encounterObjectGuid)) { regionRaycastHits[regionGameLogic.encounterObjectGuid] = 1; } else { string encounterObjectGuid = regionGameLogic.encounterObjectGuid; regionRaycastHits[encounterObjectGuid]++; } // Cache the region in the lookup if (!regionGameObjectList.Contains(regionGameLogic)) { regionGameObjectList.Add(regionGameLogic); } } ObstructionGameLogic obstructionGameLogicInParent = raycastHits[m].transform.GetComponentInParent <ObstructionGameLogic>(); if (obstructionGameLogicInParent != null && raycastHits[m].point.y > mapMetaData.mapTerrainDataCells[zCellIndex, xCellIndex].terrainHeight) { if (obstructionGameLogicInParent.IsBuildingHitAddWorthy) { if (!obstructionGameObjectList.Contains(obstructionGameLogicInParent)) { obstructionGameObjectList.Add(obstructionGameLogicInParent); } } Vector3 normal = raycastHits[m].normal; BuildingRaycastHit buildingRaycastHit = new BuildingRaycastHit { buildingSteepness = 90f - 57.29578f * Mathf.Atan2(normal.y, Mathf.Sqrt(normal.x * normal.x + normal.z * normal.z)), buildingHeight = raycastHits[m].point.y, buildingGuid = obstructionGameLogicInParent.encounterObjectGuid, hitIndex = hitIndex }; mapEncounterLayerDataCell.AddBuildingHit(buildingRaycastHit); } } hitIndex++; } } // For all the regions detected, if it exists in 10 or more cells - add the region to the map encounter layer data (this is vanilla... why?!) // And all all obstruction games logics to the region foreach (RegionGameLogic regionGameLogic in regionGameObjectList) { if (regionRaycastHits[regionGameLogic.encounterObjectGuid] >= 10) { mapEncounterLayerDataCell.AddRegion(regionGameLogic); foreach (ObstructionGameLogic obstructionGameLogic in obstructionGameObjectList) { regionGameLogic.AddBuildingGuidToRegion(obstructionGameLogic.encounterObjectGuid); } } } mapEncounterLayerDataCell.AverageTheBuildingHits(); mapEncounterLayerDataCell.SortBuildingListByHeight(); } encounterLayerData.mapEncounterLayerDataCells[zCellIndex, xCellIndex] = mapEncounterLayerDataCell; encounterLayerData.mapEncounterLayerDataCells[zCellIndex, xCellIndex].relatedTerrainCell = mapMetaData.mapTerrainDataCells[zCellIndex, xCellIndex]; mapMetaData.mapTerrainDataCells[zCellIndex, xCellIndex].MapEncounterLayerDataCell = mapEncounterLayerDataCell; } } }
public static void Postfix(EncounterLayerParent __instance, CombatGameState combat) { Mod.Log.Trace?.Write($"TD:IFSPT entered"); TurnDirector_OnEncounterBegin.IsFromSave = true; }