public static void Prefix(SimGameState __instance, SimGameSave save, ref SerializableReferenceContainer references)
            {
                Contract selectedContract = __instance.SelectedContract;

                // TODO check we're in simGame, not combat!
                if (selectedContract == null || __instance.BattleTechGame.Combat != null)
                {
                    return;
                }

                LanceConfiguration lastLance = Traverse.Create(__instance).Method("GetLastLance").GetValue <LanceConfiguration>();

                selectedContract.SetLanceConfiguration(lastLance);
                selectedContract.SetCarryOverNegotationValues(true);
                selectedContract.Accept(true);
                selectedContract.Override.disableNegotations = true;

                Contract travelContract = createTravelContract(selectedContract);

                Logger.Minimal("created travelcontract with name: " + travelContract.Name);
                __instance.PrepareBreadcrumb(travelContract);
                // __instance.SetSelectedContract(travelContract, true);
                //references.AddItem(ModSettings.MOD_SAVE_REFERENCECONTAINER_KEY, travelContract);
                //references.AddItem("activeBreadcrumb", travelContract);
                Logger.Minimal("saving selected contract: " + travelContract.GUID);
                //references.AddItemList<Contract>("globalContracts", new List<Contract>() { selectedContract });
                //this.globalContracts = globalReferences.GetItemList<Contract>("globalContracts");
            }
        public static void Prefix(SimGameState __instance, SimGameSave save, ref SerializableReferenceContainer references)
        {
            Contract selectedContract = __instance.SelectedContract;

            if (selectedContract == null || __instance.BattleTechGame.Combat != null)
            {
                return;
            }

            references.AddItem(ModSettings.MOD_SAVE_REFERENCECONTAINER_KEY, selectedContract);
        }
Beispiel #3
0
        public static void LoadShops(GameInstanceSave gameInstanceSave, SimGameState __instance)
        {
            Control.State.CurrentSystem = __instance.CurSystem;
            Control.State.Sim           = __instance;

            SerializableReferenceContainer globalReferences = gameInstanceSave.GlobalReferences;

            Control.LogDebug(DInfo.SaveLoad, "Loading Shops");
            foreach (var shop in Control.Shops)
            {
                if (shop is ISaveShop save)
                {
                    var name = "Shop" + shop.Name;
                    Control.LogDebug(DInfo.SaveLoad, "- " + shop.Name);
                    try
                    {
                        var Shop = globalReferences.GetItem <Shop>(name);
                        save.SetLoadedShop(Shop);

                        Control.LogDebug(DInfo.SaveLoad, "-- " + shop.Name + " Loaded");
                        Control.LogDebug(DInfo.SaveLoad, $"-- total {Shop.ActiveInventory.Count} items");
                    }
                    catch (Exception)
                    {
                        Control.LogError($"Error finding {name} Create new");
                        shop.RefreshShop();
                        Control.LogDebug(DInfo.SaveLoad, "-- total " + save.GetShopToSave().ActiveInventory.Count + " items");
                    }
                }
                else
                {
                    shop.RefreshShop();
                }
            }

            //Control.Log($"Hated: {__instance.Constants.Story.HatedRepShopAdjustment}");
            //Control.Log($"Disliked: {__instance.Constants.Story.DislikedRepShopAdjustment}");
            //Control.Log($"Indifferent: {__instance.Constants.Story.IndifferentRepShopAdjustment}");
            //Control.Log($"Liked: {__instance.Constants.Story.LikedRepShopAdjustment}");
            //Control.Log($"Friendly: {__instance.Constants.Story.FriendlyRepShopAdjustment}");
            //Control.Log($"Honored: {__instance.Constants.Story.HonoredRepShopAdjustment}");
        }
 public static void SaveShops(SerializableReferenceContainer references)
 {
     Control.LogDebug(DInfo.SaveLoad, "Saving Shops");
     foreach (var shop in Control.Shops)
     {
         if (shop is ISaveShop save)
         {
             Control.LogDebug(DInfo.SaveLoad, "- " + shop.Name);
             var shop_to_save = save.GetShopToSave();
             if (shop_to_save != null)
             {
                 references.AddItem <Shop>("Shop" + shop.Name, shop_to_save);
                 Control.LogDebug(DInfo.SaveLoad, "-- Saved as Shop" + shop.Name);
             }
             else
             {
                 Control.LogDebug(DInfo.SaveLoad, "-- no shop to save");
             }
         }
     }
 }
        // TODO: Need to cover vanilla serialisation for `CustomBehaviorVariableScope` type before this will work
        // TODO: Patch a call into this for the unit to load the data from the save file, or output as a companion save file
        public void Dehydrate(SerializableReferenceContainer references)
        {
            Dictionary <string, BehaviorVariableValue>    dictionary  = new Dictionary <string, BehaviorVariableValue>(this.behaviorVariables.Count);
            Dictionary <int, CustomBehaviorVariableScope> dictionary2 = new Dictionary <int, CustomBehaviorVariableScope>(this.ScopesByMood.Count);

            foreach (KeyValuePair <string, BehaviorVariableValue> keyValuePair in this.behaviorVariables)
            {
                string key = (string)keyValuePair.Key;
                BehaviorVariableValue value = keyValuePair.Value;
                dictionary.Add(key, value);
            }

            foreach (KeyValuePair <AIMood, CustomBehaviorVariableScope> keyValuePair2 in this.ScopesByMood)
            {
                int key2 = (int)keyValuePair2.Key;
                CustomBehaviorVariableScope value2 = keyValuePair2.Value;
                dictionary2.Add(key2, value2);
            }

            references.AddItemDictionary <string, BehaviorVariableValue>(this, "serializableCustomBehaviorVariables", dictionary);
            references.AddItemDictionary <int, CustomBehaviorVariableScope>(this, "serializableCustomScopesByMood", dictionary2);
        }
        // TODO: Need to cover vanilla deserialisation for `CustomBehaviorVariableScope` type before this will work
        // TODO: Patch a call into this for the unit to save the data into the save file, or output as a companion save file
        public void Hydrate(SerializableReferenceContainer references)
        {
            Dictionary <string, BehaviorVariableValue>    itemDictionary  = references.GetItemDictionary <string, BehaviorVariableValue>(this, "serializableCustomBehaviorVariables");
            Dictionary <int, CustomBehaviorVariableScope> itemDictionary2 = references.GetItemDictionary <int, CustomBehaviorVariableScope>(this, "serializableCustomScopesByMood");

            this.behaviorVariables = new Dictionary <string, BehaviorVariableValue>(itemDictionary.Count);

            foreach (KeyValuePair <string, BehaviorVariableValue> keyValuePair in itemDictionary)
            {
                string key = (string)keyValuePair.Key;
                BehaviorVariableValue value = keyValuePair.Value;
                this.behaviorVariables.Add(key, value);
            }

            this.ScopesByMood = new Dictionary <AIMood, CustomBehaviorVariableScope>(itemDictionary2.Count);
            foreach (KeyValuePair <int, CustomBehaviorVariableScope> keyValuePair2 in itemDictionary2)
            {
                AIMood key2 = (AIMood)keyValuePair2.Key;
                CustomBehaviorVariableScope value2 = keyValuePair2.Value;
                this.ScopesByMood.Add(key2, value2);
            }
        }
        public static bool Prefix(AbstractActor __instance, SerializableReferenceContainer references,
                                  ref bool ___underscoreIsShutDown, bool ____isShutDown,
                                  ref string ___underscoreLanceID, string ____lanceId,
                                  ref string ___underscoreSpawnerID, string ____spawnerId,
                                  ref string ___underscoreTeamID, string ____teamId,
                                  ref bool ___serializableHasHandledDeath,
                                  ref int ___serializableDeathLocation, int ____deathLocation,
                                  ref DeathMethod ___serializableDeathMethod, DeathMethod ____deathMethod,
                                  Team ____team, List <Weapon> ___weapons
                                  )
        {
            //SkillBasedInit.Logger.Log($"AbstractActor:Dehydrate - preventing native call to allow serialization of initiative");

            ___underscoreIsShutDown        = ____isShutDown;
            ___underscoreLanceID           = ____lanceId;
            ___underscoreSpawnerID         = ____spawnerId;
            ___underscoreTeamID            = ____teamId;
            ___serializableHasHandledDeath = __instance.HasHandledDeath;
            ___serializableDeathLocation   = ____deathLocation;
            ___serializableDeathMethod     = ____deathMethod;
            references.AddItem <Team>(__instance, "_team", ____team);
            if (__instance.BehaviorTree != null)
            {
                __instance.BehaviorTree.Dehydrate(references);
            }
            references.AddItemList <Weapon>(__instance, "Weapons", ___weapons);
            references.AddItemList <AmmunitionBox>(__instance, "AmmoBox", __instance.ammoBoxes);
            references.AddItemList <Jumpjet>(__instance, "JumpJets", __instance.jumpjets);
            references.AddItem <Weapon>(__instance, "ImaginaryLaser", __instance.ImaginaryLaserWeapon);
            if (!(__instance.Initiative > 0 && __instance.Initiative < (Mod.MaxPhase + 1)))
            {
                Mod.Log.Info(string.Format("Saving an AbstractActor of type {0} with an invalid initiative of {1}", __instance.ClassName, __instance.Initiative));
            }

            return(false);
        }
        public static bool Prefix(AbstractActor __instance, SerializableReferenceContainer references, CombatGameState loadedState,
                                  ref bool ____isShutDown, bool ___underscoreIsShutDown,
                                  ref string ____lanceId, string ___underscoreLanceID,
                                  ref string ____spawnerId, string ___underscoreSpawnerID,
                                  ref string ____teamId, string ___underscoreTeamID,
                                  ref Team ____team,
                                  ref Lance ____lance,
                                  ref bool ____hasHandledDeath, bool ___serializableHasHandledDeath,
                                  ref int ____deathLocation, int ___serializableDeathLocation,
                                  ref DeathMethod ____deathMethod, DeathMethod ___serializableDeathMethod,
                                  List <Weapon> ___weapons
                                  )
        {
            //SkillBasedInit.Logger.Log($"AbstractActor:Hydrate - preventing native call to allow deserialization of initiative");

            Traverse.Create(__instance).Property("Combat").SetValue(loadedState);

            ____isShutDown      = ___underscoreIsShutDown;
            ____lanceId         = ___underscoreLanceID;
            ____spawnerId       = ___underscoreSpawnerID;
            ____teamId          = ___underscoreTeamID;
            ____team            = references.GetItem <Team>(__instance, "_team");
            ____lance           = ____team.GetLanceByUID(____lanceId);
            ____hasHandledDeath = ___serializableHasHandledDeath;
            ____deathLocation   = ___serializableDeathLocation;
            ____deathMethod     = ___serializableDeathMethod;
            if (__instance.BehaviorTree != null)
            {
                __instance.BehaviorTree.Hydrate(loadedState, references);
            }
            ___weapons = references.GetItemList <Weapon>(__instance, "Weapons");
            foreach (Weapon weapon in __instance.Weapons)
            {
                weapon.Hydrate(references);
                __instance.allComponents.Add(weapon);
            }
            __instance.ammoBoxes = references.GetItemList <AmmunitionBox>(__instance, "AmmoBox");
            foreach (AmmunitionBox ammunitionBox in __instance.ammoBoxes)
            {
                ammunitionBox.Hydrate(references);
                __instance.allComponents.Add(ammunitionBox);
            }
            __instance.jumpjets = references.GetItemList <Jumpjet>(__instance, "JumpJets");
            foreach (Jumpjet jumpjet in __instance.jumpjets)
            {
                jumpjet.Hydrate(references);
                __instance.allComponents.Add(jumpjet);
            }
            __instance.ImaginaryLaserWeapon = references.GetItem <Weapon>(__instance, "ImaginaryLaser");
            if (__instance.ImaginaryLaserWeapon != null)
            {
                __instance.ImaginaryLaserWeapon.Hydrate(references);
            }
            if (__instance.CustomHeraldryDef != null)
            {
                Traverse requestResources = Traverse.Create(__instance).Method("RequestResources", new Type[] { typeof(DataManager), typeof(Action) });
                requestResources.GetValue(new object[] { loadedState.DataManager, true });
            }

            // OriginalLogic: Initiative > 0 && Initiative < 6;
            if (!(__instance.Initiative > 0 && __instance.Initiative <= Mod.MaxPhase))
            {
                Mod.Log.Info(string.Format("Loading an AbstractActor of type {0} with an invalid initiative of {1}, Reverting to BaseInitiative", __instance.ClassName, __instance.Initiative));
                __instance.Initiative = 1;
            }

            return(false);
        }