예제 #1
0
        public static CastDef CreateCast(AbstractActor actor)
        {
            string castDefId = $"castDef_{actor.GUID}";

            if (actor.Combat.DataManager.CastDefs.Exists(castDefId))
            {
                return(actor.Combat.DataManager.CastDefs.Get(castDefId));
            }

            FactionValue actorFaction  = actor?.team?.FactionValue;
            bool         factionExists = actorFaction.Name != "INVALID_UNSET" && actorFaction.Name != "NoFaction" &&
                                         actorFaction.FactionDefID != null && actorFaction.FactionDefID.Length != 0 ? true : false;

            string employerFactionName = "Military Support";

            if (factionExists)
            {
                Mod.Log.Debug($"Found factionDef for id:{actorFaction}");
                string     factionId          = actorFaction?.FactionDefID;
                FactionDef employerFactionDef = UnityGameInstance.Instance.Game.DataManager.Factions.Get(factionId);
                if (employerFactionDef == null)
                {
                    Mod.Log.Error($"Error finding FactionDef for faction with id '{factionId}'");
                }
                else
                {
                    employerFactionName = employerFactionDef.Name.ToUpper();
                }
            }
            else
            {
                Mod.Log.Debug($"FactionDefID does not exist for faction: {actorFaction}");
            }

            CastDef newCastDef = new CastDef {
                // Temp test data
                FactionValue  = actorFaction,
                firstName     = $"{employerFactionName} -",
                showRank      = false,
                showCallsign  = true,
                showFirstName = true,
                showLastName  = false
            };

            // DisplayName order is first, callsign, lastname

            newCastDef.id = castDefId;
            string portraitPath = GetRandomPortraitPath();

            newCastDef.defaultEmotePortrait.portraitAssetPath = portraitPath;
            if (actor.GetPilot() != null)
            {
                Mod.Log.Debug("Actor has a pilot, using pilot values.");
                Pilot pilot = actor.GetPilot();
                newCastDef.callsign = pilot.Callsign;

                // Hide the faction name if it's the player's mech
                if (actor.team.IsLocalPlayer)
                {
                    newCastDef.showFirstName = false;
                }
            }
            else
            {
                Mod.Log.Debug("Actor is not piloted, generating castDef.");
                newCastDef.callsign = GetRandomCallsign();
            }
            Mod.Log.Debug($" Generated cast with callsign: {newCastDef.callsign} and DisplayName: {newCastDef.DisplayName()} using portrait: '{portraitPath}'");

            ((DictionaryStore <CastDef>)UnityGameInstance.BattleTechGame.DataManager.CastDefs).Add(newCastDef.id, newCastDef);

            return(newCastDef);
        }
예제 #2
0
        public static CastDef CreateCast(CombatGameState combat, string sourceGUID, Team team, string employerFactionName = "Support")
        {
            string castDefId = $"castDef_{sourceGUID}";

            if (combat.DataManager.CastDefs.Exists(castDefId))
            {
                return(combat.DataManager.CastDefs.Get(castDefId));
            }

            FactionValue actorFaction  = team?.FactionValue;
            bool         factionExists = actorFaction.Name != "INVALID_UNSET" && actorFaction.Name != "NoFaction" &&
                                         actorFaction.FactionDefID != null && actorFaction.FactionDefID.Length != 0 ? true : false;

            if (factionExists)
            {
                Mod.Log.Debug?.Write($"Found factionDef for id:{actorFaction}");
                string     factionId          = actorFaction?.FactionDefID;
                FactionDef employerFactionDef = UnityGameInstance.Instance.Game.DataManager.Factions.Get(factionId);
                if (employerFactionDef == null)
                {
                    Mod.Log.Error?.Write($"Error finding FactionDef for faction with id '{factionId}'");
                }
                else
                {
                    employerFactionName = employerFactionDef.Name.ToUpper();
                }
            }
            else
            {
                Mod.Log.Debug?.Write($"FactionDefID does not exist for faction: {actorFaction}");
            }

            CastDef newCastDef = new CastDef
            {
                // Temp test data
                FactionValue  = actorFaction,
                firstName     = $"{employerFactionName} -",
                showRank      = false,
                showCallsign  = true,
                showFirstName = true,
                showLastName  = false
            };

            // DisplayName order is first, callsign, lastname

            newCastDef.id = castDefId;
            string portraitPath = GetRandomPortraitPath();

            newCastDef.callsign = GetRandomCallsign();
            Mod.Log.Debug?.Write($" Generated cast with callsign: {newCastDef.callsign} and DisplayName: {newCastDef.DisplayName()} using portrait: '{portraitPath}'");

            // Load the associated portrait
            newCastDef.defaultEmotePortrait.portraitAssetPath = portraitPath;
            Mod.Log.Debug?.Write($"Generated random portrait: {portraitPath}.");

            ((DictionaryStore <CastDef>)UnityGameInstance.BattleTechGame.DataManager.CastDefs).Add(newCastDef.id, newCastDef);

            return(newCastDef);
        }