public static void Prefix(UnitSpawnPointGameLogic __instance, ref MechDef mDef, Team team) { try { SimGameState s = __instance.Combat.BattleTechGame.Simulation; if (s == null) { BTRandomMechComponentUpgrader_Init.Log.Log("no simgame, aborting"); return; } if (mDef.Chassis.ChassisTags.Contains("deploy_director")) { BTRandomMechComponentUpgrader_Init.Log.Log($"DeployDirector, not upgrading"); return; } if (!s.DataManager.MechDefs.TryGet(mDef.Description.Id, out MechDef m)) { BTRandomMechComponentUpgrader_Init.Log.Log($"no mechdef found in datamanager for {mDef.Description.Id}"); return; } if (mDef != m) // if its a player mech, it is a different mechdef than in the datamanager) { BTRandomMechComponentUpgrader_Init.Log.Log("player modified mech, no upgrading"); return; } string teamName = team.IsLocalPlayer ? __instance.Combat.ActiveContract.Override.employerTeam.FactionValue.ToString() : team.FactionValue.ToString(); UpgradeList ulist = MechProcesser.GetUpgradeList(teamName); // check if we got a upgradelist for that faction if (ulist == null) { BTRandomMechComponentUpgrader_Init.Log.Log($"no UpgradeList found for {teamName}"); return; } MechDef n = MechProcesser.ProcessMech(mDef, s, ulist); if (MechProcesser.ValidateMech(n, s)) { mDef = n; BTRandomMechComponentUpgrader_Init.Log.Log("validated"); } else { BTRandomMechComponentUpgrader_Init.Log.Log("validation failed, using datamanager mechdef, inventory dump of invalid mechdef:"); foreach (MechComponentRef r in n.Inventory) { BTRandomMechComponentUpgrader_Init.Log.Log($"inventory {r.ComponentDefID} at {r.MountedLocation} {r.HardpointSlot}"); } } } catch (Exception e) { BTRandomMechComponentUpgrader_Init.Log.LogException(e); } }
private void AddSpawnPoints(LanceSpawnerGameLogic lanceSpawner, TeamOverride teamOverride, LanceOverride lanceOverride, int numberOfUnitsInLance) { List <GameObject> unitSpawnPoints = lanceSpawner.gameObject.FindAllContains("UnitSpawnPoint"); numberOfUnitsInLance = lanceOverride.unitSpawnPointOverrideList.Count; if (unitSpawnPoints.Count <= 0) { Main.Logger.Log($"[AddSpawnPoints] Spawner '{lanceSpawner.name}' has '0' unit spawns containing the word 'UnitSpawnPoint'. A lance must have at least one valid spawn point. Skipping last '{lanceOverride.name}'"); return; } if (numberOfUnitsInLance > unitSpawnPoints.Count) { Main.Logger.Log($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Detected lance '{lanceOverride.name}' has more units than lance spawn points. Creating new lance spawns to accommodate."); string spawnerName = lanceSpawner.gameObject.name; GameObject orientationUnit = unitSpawnPoints[0].gameObject; string orientationKey = $"{spawnerName}.{orientationUnit.name}"; encounterRules.ObjectLookup[orientationKey] = orientationUnit; for (int j = unitSpawnPoints.Count; j < numberOfUnitsInLance; j++) { Vector3 randomLanceSpawn = unitSpawnPoints.GetRandom().transform.localPosition; Vector3 spawnPositon = SceneUtils.GetRandomPositionFromTarget(randomLanceSpawn, 24, 100); spawnPositon = spawnPositon.GetClosestHexLerpedPointOnGrid(); // Ensure spawn position isn't on another unit spawn. Give up if one isn't possible. int failSafe = 0; while (spawnPositon.IsTooCloseToAnotherSpawn()) { spawnPositon = SceneUtils.GetRandomPositionFromTarget(randomLanceSpawn, 24, 100); spawnPositon = spawnPositon.GetClosestHexLerpedPointOnGrid(); if (failSafe > 20) { break; } failSafe++; } Main.Logger.Log($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Creating lance '{lanceOverride.name}' spawn point 'UnitSpawnPoint{j + 1}'"); UnitSpawnPointGameLogic unitSpawnGameLogic = LanceSpawnerFactory.CreateUnitSpawnPoint(lanceSpawner.gameObject, $"UnitSpawnPoint{j + 1}", spawnPositon, lanceOverride.unitSpawnPointOverrideList[j].unitSpawnPoint.EncounterObjectGuid); unitSpawnPoints.Add(unitSpawnGameLogic.gameObject); string spawnKey = $"{spawnerName}.{unitSpawnGameLogic.gameObject.name}"; encounterRules.ObjectLookup[spawnKey] = unitSpawnGameLogic.gameObject; spawnKeys.Add(new string[] { spawnKey, orientationKey }); } } }
public static UnitSpawnPointGameLogic CreateUnitSpawnPoint(GameObject parent, string name, Vector3 localPosition, string encounterObjectGuid) { GameObject unitSpawnPointGo = new GameObject(name); unitSpawnPointGo.transform.parent = parent.transform; unitSpawnPointGo.transform.localPosition = localPosition; UnitSpawnPointGameLogic unitSpawnPoint = unitSpawnPointGo.AddComponent <UnitSpawnPointGameLogic>(); unitSpawnPoint.defaultDetectionRange = 200f; unitSpawnPoint.encounterObjectGuid = encounterObjectGuid; unitSpawnPointGo.AddComponent <SnapToTerrain>(); return(unitSpawnPoint); }
public static void Prefix(UnitSpawnPointGameLogic __instance, MechDef ___mechDefOverride) { try { Logger.Debug("[UnitSpawnPointGameLogic_SpawnUnit_PREFIX] UnitDefId: " + __instance.UnitDefId); if (___mechDefOverride != null) { Logger.Debug("[UnitSpawnPointGameLogic_SpawnUnit_PREFIX] Overridden with: " + ___mechDefOverride.Description.Id); } Logger.Debug("[UnitSpawnPointGameLogic_SpawnUnit_PREFIX] pilotDefId: " + __instance.pilotDefId); } catch (Exception e) { Logger.Error(e); } }
public static void Prefix(UnitSpawnPointGameLogic __instance, string ___teamDefinitionGuid) { Mod.Log.Trace?.Write("USPGL:S - entered."); if (Mod.Config.Skirmish.Tag != null && !Mod.Config.Skirmish.Tag.Equals("")) { if (__instance.Combat.ActiveContract.ContractTypeValue.IsSkirmish) { Mod.Log.Debug?.Write($"Contract is skirmish. Existing tags are: {__instance.spawnEffectTags}"); if (!__instance.Combat.HostilityMatrix.IsLocalPlayerFriendly(___teamDefinitionGuid)) { Mod.Log.Debug?.Write($"Unit belongs to enemy or neutral team, adding flag: {Mod.Config.Skirmish.Tag}"); __instance.spawnEffectTags.Add(Mod.Config.Skirmish.Tag); } } } }
public override List <EncounterObjectValidationEntry> Validate(Dictionary <string, EncounterObjectGameLogic> encounterObjectDict) { List <EncounterObjectValidationEntry> list = base.Validate(encounterObjectDict); if (base.unitSpawnPointGameLogicList == null || base.unitSpawnPointGameLogicList.Length < 4) { list.Add(new EncounterObjectValidationEntry { encounterObject = this, validationError = "Player lances need at least 4 spawn points" }); } int num = 0; UnitSpawnPointGameLogic[] unitSpawnPointGameLogicList = base.unitSpawnPointGameLogicList; for (int i = 0; i < unitSpawnPointGameLogicList.Length; i++) { UnitSpawnPointGameLogic unitSpawnPointGameLogic = unitSpawnPointGameLogicList[i]; if (unitSpawnPointGameLogic.HasUnitToSpawn) { if (num != i) { EncounterObjectValidationEntry item = EncounterObjectValidationEntry.GenericGameLogicError(unitSpawnPointGameLogic, base.DisplayName, "Forced player units must be sequential and start at PlayerLanceSpawner1."); list.Add(item); } else { num++; } if (unitSpawnPointGameLogic.HasDefaultPilot) { EncounterObjectValidationEntry item = EncounterObjectValidationEntry.GenericGameLogicError(unitSpawnPointGameLogic, base.DisplayName, "Forced player units must have a non default pilot."); list.Add(item); } } } return(list); }
public static bool Prefix(UnitSpawnPointGameLogic __instance, SpawnableUnit spawnableUnit, MechDef ___mechDefOverride, ref PilotDef ___pilotDefOverride, VehicleDef ___vehicleDefOverride, TurretDef ___turretDefOverride) { if (ModState.PlayerGetsAIMechs && __instance.team == TeamDefinition.Player1TeamDefinitionGuid && spawnableUnit.unitType == UnitType.Mech) { ModInit.modLog.LogMessage( $"PLAYER UNIT: First mech in AIMechVariants was {ModState.AIMechs.First().mechDef.Name} with count {ModState.AIMechs.First().count}"); var AIMechVariants = ModState.AIMechs.OrderBy(x => x.count).ToList(); ModInit.modLog.LogMessage( $"PLAYER UNIT: Filtered to match mechdef IDs and reordered! First mech in AIMechVariants is now {AIMechVariants.First().mechDef.Name} with count {AIMechVariants.First().count}"); ModState.AIMechs.First().count += 1; var newMechDef = AIMechVariants.FirstOrDefault()?.mechDef; newMechDef.DependenciesLoaded(1000U); ___mechDefOverride = newMechDef; ModInit.modLog.LogMessage( $"PLAYER UNIT: mechDefOverride set to {___mechDefOverride.Description.Id}"); ___pilotDefOverride = spawnableUnit.Pilot; ModInit.modLog.LogMessage( $"PLAYER UNIT: pilotDefOverride set to {___pilotDefOverride.Description.Id}"); __instance.pilotDefId = spawnableUnit.PilotId; ModInit.modLog.LogMessage( $"PLAYER UNIT: __instance.pilotDefId is {__instance.pilotDefId}, should be {___pilotDefOverride.Description.Id}"); __instance.mechDefId = newMechDef.Description.Id; ModInit.modLog.LogMessage( $"PLAYER UNIT: __instance.mechDefId is {__instance.mechDefId}, should be {___mechDefOverride.Description.Id}"); __instance.unitType = spawnableUnit.unitType; ___vehicleDefOverride = spawnableUnit.VUnit; ___turretDefOverride = spawnableUnit.TUnit; __instance.vehicleDefId = spawnableUnit.UnitId; __instance.turretDefId = spawnableUnit.UnitId; return(false); } return(true); }
static void Postfix(UnitSpawnPointGameLogic __instance, AbstractActor actor, Team team, Lance lance) { if (actor == null || actor.GetPilot() == null) { Mod.Log.Info?.Write("Actor or pilot is null, cannot check for multi-targeting, skipping."); return; } Statistic multiTargetStat = actor.StatCollection.GetStatistic(ModStats.EnableMultiTarget); if (multiTargetStat != null && multiTargetStat.Value <bool>()) { bool hasMultiTargetAbility = false; foreach (Ability ability in actor.GetPilot().Abilities) { if (ability.Def.Targeting == AbilityDef.TargetingType.MultiFire) { Mod.Log.Debug?.Write(" -- unit already has MultiFire ability, skipping."); hasMultiTargetAbility = true; break; } } if (!hasMultiTargetAbility) { Mod.Log.Debug?.Write(" -- adding multi-target ability to pilot."); AbilityDef abilityDef = SharedState.Combat.DataManager.AbilityDefs.Get(Mod.Config.Abilities.MultiTargetId); Ability ability = new Ability(abilityDef); ability.Init(SharedState.Combat); Pilot pilot = actor.GetPilot(); pilot.Abilities.Add(ability); pilot.ActiveAbilities.Add(ability); pilot.StatCollection.ModifyStat("", -1, ModStats.HBS_MaxTargets, StatCollection.StatOperation.Set, 3); Mod.Log.Debug?.Write(" -- done."); } } }
static bool Prefix(UnitSpawnPointGameLogic __instance, ParticleSystem dropPodVfxPrefab, GameObject dropPodLandedPrefab) { Main.LogDebug("[UnitSpawnPointGameLogicLoadDropPodPrefabsPatch] Patching"); ParticleSystem newdropPodVfxPrefab = null; if (dropPodVfxPrefab != null) { Main.LogDebug("[UnitSpawnPointGameLogicLoadDropPodPrefabsPatch] Building new dropPodVfxPrefab"); newdropPodVfxPrefab = UnityEngine.Object.Instantiate <ParticleSystem>(dropPodVfxPrefab, __instance.transform); newdropPodVfxPrefab.transform.position = __instance.transform.position; newdropPodVfxPrefab.Pause(); newdropPodVfxPrefab.Clear(); AccessTools.Field(typeof(UnitSpawnPointGameLogic), "dropPodVfxPrefab").SetValue(__instance, newdropPodVfxPrefab); } if (dropPodLandedPrefab != null) { GameObject newDropPodLandedPrefab = UnityEngine.Object.Instantiate <GameObject>(dropPodLandedPrefab, offscreenDropPodPosition, Quaternion.identity); AccessTools.Field(typeof(UnitSpawnPointGameLogic), "dropPodLandedPrefab").SetValue(__instance, newDropPodLandedPrefab); } return(false); }
public static void Prefix(UnitSpawnPointGameLogic __instance, ref MechDef mDef, PilotDef pilot, Team team, Mech __result) { if (__instance.team == TeamDefinition.TargetsTeamDefinitionGuid) { if (ModState.AIGetsPlayerMechs) { var oldmDef = mDef; ModInit.modLog.LogMessage( $"AI UNIT: First mech in playerMechs was {ModState.playerMechs.First().mechDef.Name} with count {ModState.playerMechs.First().count}"); var playerMechVariants = ModState.playerMechs .Where(x => x.mechDef.Description.Id == oldmDef.Description.Id).OrderBy(x => x.count) .ToList(); ModInit.modLog.LogMessage( $"AI UNIT: Filtered to match mechdef IDs and reordered! First mech in playerMechVariants is now {playerMechVariants.First().mechDef.Name} with count {playerMechVariants.First().count}"); ModState.playerMechs.First().count += 1; var newMechDef = playerMechVariants.FirstOrDefault()?.mechDef; if (newMechDef != null) { newMechDef.DependenciesLoaded(1000U); mDef = newMechDef; } } } }
public static void Prefix(UnitSpawnPointGameLogic __instance, AbstractActor actor, Team team, Lance lance) { CustomActivatableEquipment.Log.Debug?.Write("UnitSpawnPointGameLogic.initializeActor " + new Text(actor.DisplayName).ToString() + ":" + new Text(__instance.DisplayName).ToString() + "\n"); actor.AddToActiveDefaultQueue(); }
private void IncreaseLanceSpawnPoints(ContractOverride contractOverride, TeamOverride teamOverride) { List <LanceOverride> lanceOverrides = teamOverride.lanceOverrideList; int factionLanceSize = Main.Settings.ExtendedLances.GetFactionLanceSize(teamOverride.faction.ToString()); foreach (LanceOverride lanceOverride in lanceOverrides) { bool isManualLance = lanceOverride.lanceDefId == "Manual"; int numberOfUnitsInLance = lanceOverride.unitSpawnPointOverrideList.Count; if (lanceOverride.IsATurretLance()) { Main.LogDebug($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Detected a turret lance Ignoring for Extended Lances."); continue; } if (isManualLance && numberOfUnitsInLance <= 0) { Main.LogDebug($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Detected a lance that is set to manual but no units were manually specified. This is a bad contract json setup. Fix it! Ignoring for Extended Lances"); continue; } ApplyDifficultyMod(teamOverride, lanceOverride); if ((numberOfUnitsInLance < factionLanceSize) && numberOfUnitsInLance > 0) { // This is usually from a 'tagged' lance being selected which has less lance members than the faction lance size if (Main.Settings.ExtendedLances.Autofill) { Main.LogDebug($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Populated lance '{lanceOverride.name}' has fewer units than the faction requires. Autofilling the missing units"); // GUARD: If an AdditionalLance lance config has been set to 'supportAutoFill' false, then don't autofill if (lanceOverride is MLanceOverride) { MLanceOverride mLanceOverride = (MLanceOverride)lanceOverride; if (!mLanceOverride.SupportAutofill) { Main.LogDebug($"[AddExtraLanceSpawnPoints] Lance Override '{mLanceOverride.GUID}' has 'autofill' explicitly turned off in MC lance '{mLanceOverride.LanceKey}'"); continue; } } AddNewLanceMembers(contractOverride, teamOverride, lanceOverride, numberOfUnitsInLance, factionLanceSize); } else { Main.LogDebug($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Populated lance '{lanceOverride.name}' has fewer units than the faction requires. Allowing as a valid setup as 'Autofill' is false"); } } LanceSpawnerGameLogic lanceSpawner = lanceSpawners.Find(spawner => spawner.GUID == lanceOverride.lanceSpawner.EncounterObjectGuid); if (lanceSpawner != null) { List <GameObject> unitSpawnPoints = lanceSpawner.gameObject.FindAllContains("UnitSpawnPoint"); numberOfUnitsInLance = lanceOverride.unitSpawnPointOverrideList.Count; if (numberOfUnitsInLance > unitSpawnPoints.Count) { Main.Logger.Log($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Detected lance '{lanceOverride.name}' has more units than lance spawn points. Creating new lance spawns to accommodate."); string spawnerName = lanceSpawner.gameObject.name; GameObject orientationUnit = unitSpawnPoints[0].gameObject; string orientationKey = $"{spawnerName}.{orientationUnit.name}"; encounterRules.ObjectLookup[orientationKey] = orientationUnit; for (int i = unitSpawnPoints.Count; i < numberOfUnitsInLance; i++) { Vector3 randomLanceSpawn = unitSpawnPoints.GetRandom().transform.localPosition; Vector3 spawnPositon = SceneUtils.GetRandomPositionFromTarget(randomLanceSpawn, 24, 100); spawnPositon = spawnPositon.GetClosestHexLerpedPointOnGrid(); // Ensure spawn position isn't on another unit spawn. Give up if one isn't possible. int failSafe = 0; while (spawnPositon.IsTooCloseToAnotherSpawn()) { spawnPositon = SceneUtils.GetRandomPositionFromTarget(randomLanceSpawn, 24, 100); spawnPositon = spawnPositon.GetClosestHexLerpedPointOnGrid(); if (failSafe > 20) { break; } failSafe++; } Main.Logger.Log($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Creating lance '{lanceOverride.name}' spawn point 'UnitSpawnPoint{i + 1}'"); UnitSpawnPointGameLogic unitSpawnGameLogic = LanceSpawnerFactory.CreateUnitSpawnPoint(lanceSpawner.gameObject, $"UnitSpawnPoint{i + 1}", spawnPositon, lanceOverride.unitSpawnPointOverrideList[i].unitSpawnPoint.EncounterObjectGuid); string spawnKey = $"{spawnerName}.{unitSpawnGameLogic.gameObject.name}"; encounterRules.ObjectLookup[spawnKey] = unitSpawnGameLogic.gameObject; spawnKeys.Add(new string[] { spawnKey, orientationKey }); } } } else { Main.Logger.LogWarning($"[AddExtraLanceSpawnPoints] [Faction:{teamOverride.faction}] Spawner is null for {lanceOverride.lanceSpawner.EncounterObjectGuid}. This is probably data from a restarted contract that hasn't been cleared up. It can be safely ignored."); } } }