Ejemplo n.º 1
0
        private void AutofillWithTaggedOrFirstUnitOverrideSlots(TeamOverride teamOverride, LanceOverride lanceOverride, int numberOfUnitsInLanceOverride, int intendedLanceSize)
        {
            for (int i = numberOfUnitsInLanceOverride; i < intendedLanceSize; i++)
            {
                UnitSpawnPointOverride originalUnitSpawnPointOverride = lanceOverride.GetAnyTaggedLanceMember();

                if (originalUnitSpawnPointOverride == null)
                {
                    originalUnitSpawnPointOverride = lanceOverride.GetUnitToCopy();
                    Main.LogDebug($"[AddExtraLanceMembers] [{teamOverride.faction}] Autofill mode. Adding unit {i + 1} by duplicating an existing unit.");
                }
                else
                {
                    Main.LogDebug($"[AddExtraLanceMembers] [{teamOverride.faction}] Autofill mode. Adding unit {i + 1} by duplicating a 'Tagged' or 'Use Lance' lance member.");
                }

                UnitSpawnPointOverride unitSpawnPointOverride = originalUnitSpawnPointOverride.DeepCopy();
                unitSpawnPointOverride.customUnitName = "";
                Main.LogDebug($"[AddExtraLanceMembers] [{teamOverride.faction}] Using unit with old GUID '{originalUnitSpawnPointOverride.GUID}' and new GUID '{unitSpawnPointOverride.GUID}' unitDefId '{unitSpawnPointOverride.unitDefId}' as a base");

                lanceOverride.unitSpawnPointOverrideList.Add(unitSpawnPointOverride);
            }
        }
        private void ReplaceUnresolvedUnitOverride(List <string> unitSpawnPointGameLogicGUIDs, TeamOverride teamOverride, LanceOverride lanceOverride, LanceDef loadedLanceDef, List <int> unresolvedIndexes)
        {
            // Get all UnitSpawnPointGameLogic GUIDs
            List <string>  availableUnitSpawnPointGameLogicGUIDsList = new List <string>(unitSpawnPointGameLogicGUIDs);
            Stack <string> availableUnitSpawnPointGameLogicGUIDsStack;

            // Ensure no duplicates exist. If so, modder error in their set up.
            if (unitSpawnPointGameLogicGUIDs.Distinct().ToList().Count != unitSpawnPointGameLogicGUIDs.Count())
            {
                Main.Logger.LogError($"[AddExtraLanceSpawnPoints.ReplaceUnresolvedUnitOverride] [Faction:{teamOverride.faction}] The lance '{lanceOverride.GUID}' has duplicate UnitSpawnPointOverride GUIDs. This is incorrect and will cause some units not to spawn! This is not a problem with MC. Please fix this in the contract override data!");
            }

            // Remove any available UnitSpawnPointGameLogicGUIDs that are correctly set in the UnitSpawnPointOverrides
            // The remaining GUIDs are from unassigned UnitSpawnPointGameLogics and they can be assigned below
            foreach (UnitSpawnPointOverride unitSpawnPointOverride in lanceOverride.unitSpawnPointOverrideList)
            {
                if (availableUnitSpawnPointGameLogicGUIDsList.Contains(unitSpawnPointOverride.GUID))
                {
                    availableUnitSpawnPointGameLogicGUIDsList.Remove(unitSpawnPointOverride.GUID);
                }
            }

            Main.Logger.LogDebug($"[AddExtraLanceSpawnPoints.ReplaceUnresolvedUnitOverride] [Faction:{teamOverride.faction}] AvailableUnitSpawnPointGameLogicGUIDs will contain Game Logic GUID: '{string.Join(", ", unitSpawnPointGameLogicGUIDs)}'");
            availableUnitSpawnPointGameLogicGUIDsStack = new Stack <string>(availableUnitSpawnPointGameLogicGUIDsList);

            foreach (int index in unresolvedIndexes)
            {
                UnitSpawnPointOverride originalUnitSpawnPointOverride = lanceOverride.GetUnitToCopy();
                UnitSpawnPointOverride unitSpawnPointOverride         = originalUnitSpawnPointOverride.DeepCopy();

                if (unitSpawnPointGameLogicGUIDs.Count < index)
                {
                    Main.Logger.LogError($"[AddExtraLanceSpawnPoints.ReplaceUnresolvedUnitOverride] [Faction:{teamOverride.faction}] There are more unit overrides in lance '{lanceOverride.name} - {lanceOverride.GUID}' than unit spawn points in LanceSpawner. This should never happen.");
                }

                string indexUnitSpawnPointOverrideGUID = lanceOverride.unitSpawnPointOverrideList[index].GUID;
                Main.Logger.LogDebug($"[AddExtraLanceSpawnPoints.ReplaceUnresolvedUnitOverride] [Faction:{teamOverride.faction}] [Unit{index + 1}] Unit GUID is '{indexUnitSpawnPointOverrideGUID}'");
                if (unitSpawnPointGameLogicGUIDs.Contains(indexUnitSpawnPointOverrideGUID))
                {
                    unitSpawnPointOverride.unitSpawnPoint.EncounterObjectGuid = indexUnitSpawnPointOverrideGUID; // If force resolving - then ensure GUIDs for spawner unit spawns are maintained
                }
                else
                {
                    if (availableUnitSpawnPointGameLogicGUIDsStack.Count > 0)
                    {
                        string guid = availableUnitSpawnPointGameLogicGUIDsStack.Pop();
                        Main.Logger.LogDebug($"[AddExtraLanceSpawnPoints.ReplaceUnresolvedUnitOverride] [Faction:{teamOverride.faction}] [Unit{index + 1}] GUID '{unitSpawnPointOverride.unitSpawnPoint.EncounterObjectGuid}' does not exist for a UnitSpawnerGameLogic object. Reassigning with GUID '{guid}'");
                        unitSpawnPointOverride.unitSpawnPoint.EncounterObjectGuid = guid; // If force resolving - then ensure GUIDs for spawner unit spawns are maintained
                    }
                    else
                    {
                        Main.Logger.LogError($"[AddExtraLanceSpawnPoints.ReplaceUnresolvedUnitOverride] [Faction:{teamOverride.faction}] [Unit{index + 1}] No avaiable spare unit spawner guids to assign to unit override. This should never happen!");
                    }
                }

                unitSpawnPointOverride.customUnitName = "";
                TagSet companyTags = new TagSet(UnityGameInstance.BattleTechGame.Simulation.CompanyTags);

                Main.LogDebug($"[AddExtraLanceSpawnPoints.ReplaceUnresolvedUnitOverride] Generating unresolved unit '{index + 1}'");
                unitSpawnPointOverride.GenerateUnit(MetadataDatabase.Instance, UnityGameInstance.Instance.Game.DataManager, lanceOverride.selectedLanceDifficulty, lanceOverride.name, loadedLanceDef == null ? null : loadedLanceDef.Description.Id, index, DataManager.Instance.GetSimGameCurrentDate(), companyTags);
                lanceOverride.unitSpawnPointOverrideList[index] = unitSpawnPointOverride;
            }
        }