public static bool ToVehicleSalvageDef(ref SalvageDef salvageDef, ShopDefItem __instance)
        {
            if (__instance.Type != ShopItemType.Mech)
            {
                return(true);
            }

            var     dataManager = SceneSingletonBehavior <UnityGameInstance> .Instance.Game.DataManager;
            string  id          = CustomSalvage.ChassisHandler.GetMDefFromCDef(__instance.GUID);
            MechDef mechDef3    = null;

            if (dataManager.MechDefs.Exists(id))
            {
                mechDef3 = dataManager.MechDefs.Get(id);
            }
            MechDef mechDef4 = new MechDef(mechDef3, null, true);

            mechDef4.Refresh();
            if (mechDef4 != null)
            {
                salvageDef.MechComponentDef = null;
                salvageDef.Description      = mechDef3.Description;
                salvageDef.Type             = SalvageDef.SalvageType.CHASSIS;
                salvageDef.ComponentType    = ComponentType.MechPart;
            }
            return(false);
        }
Ejemplo n.º 2
0
        public static bool FixGetMechdef(ref ShopDefItem itemDef, Shop shop, bool isBulkAdd, bool isSelling, IMechLabDropTarget targetWidget,
                                         MechLabInventoryWidget_ListView ___inventoryWidget, bool ___isInBuyingState, SimGameState ___simState,
                                         SG_Shop_Screen __instance)
        {
            if (itemDef.Type == ShopItemType.Mech && !___isInBuyingState)
            {
                var dataManager = ___simState.DataManager;

                string guid8 = itemDef.GUID;
                if (dataManager.ChassisDefs.Exists(guid8))
                {
                    ChassisDef chassisDef = dataManager.ChassisDefs.Get(guid8);
                    string     newGUID    = ___simState.GenerateSimGameUID();
                    var        id         = ChassisHandler.GetMDefFromCDef(guid8);
                    MechDef    stockMech  = dataManager.MechDefs.Get(id);
                    MechDef    mechDef3   = new MechDef(chassisDef, newGUID, stockMech);
                    mechDef3.Refresh();
                    if (mechDef3 != null)
                    {
                        InventoryDataObject_ShopFullMech inventoryDataObject_ShopFullMech2 = new InventoryDataObject_ShopFullMech();
                        inventoryDataObject_ShopFullMech2.Init(mechDef3, itemDef, shop, ___simState, dataManager,
                                                               targetWidget, itemDef.Count, isSelling, new UnityAction <InventoryItemElement>(__instance.OnItemSelected));
                        ___inventoryWidget.AddItemToInventory(inventoryDataObject_ShopFullMech2, isBulkAdd);
                        inventoryDataObject_ShopFullMech2.SetItemDraggable(false);
                    }
                }
                return(false);
            }

            return(true);
        }
        public static AbstractActor SpawnAmbushMech(Team team, Lance ambushLance, Vector3 ambushOrigin, Vector3 spawnPos, Quaternion spawnRot, List <MechAndPilotDef> spawnPool)
        {
            // Randomly determine one of the spawnpairs from the current ambushdef
            List <MechAndPilotDef> shuffledSpawns = new List <MechAndPilotDef>();

            shuffledSpawns.AddRange(spawnPool);
            shuffledSpawns.Shuffle();

            MechAndPilotDef ambushDef = shuffledSpawns[0];

            PilotDef pilotDef = ModState.Combat.DataManager.PilotDefs.Get(ambushDef.PilotDefId);
            MechDef  mechDef  = ModState.Combat.DataManager.MechDefs.Get(ambushDef.MechDefId);

            mechDef.Refresh();

            // Adjust position so we don't spawn in the ground.
            spawnPos.y = ModState.Combat.MapMetaData.GetLerpedHeightAt(spawnPos, true);

            // Rotate to face the ambush origin
            Vector3    spawnDirection = Vector3.RotateTowards(spawnRot.eulerAngles, ambushOrigin, 1f, 0f);
            Quaternion spawnRotation  = Quaternion.LookRotation(spawnDirection);

            Mech mech = ActorFactory.CreateMech(mechDef, pilotDef, team.EncounterTags, ModState.Combat, team.GetNextSupportUnitGuid(), "", null);

            mech.Init(spawnPos, spawnRotation.eulerAngles.y, true);
            mech.InitGameRep(null);
            Mod.Log.Debug?.Write($"Spawned mech {CombatantUtils.Label(mech)} at position: {spawnPos}");

            if (mech == null)
            {
                Mod.Log.Error?.Write($"Failed to spawn mechDefId: {ambushDef.MechDefId} / pilotDefId: {ambushDef.PilotDefId} !");
            }

            Mod.Log.Debug?.Write($" Spawned ambush mech, adding to team: {team} and lance: {ambushLance}");
            team.AddUnit(mech);
            mech.AddToTeam(team);
            mech.AddToLance(ambushLance);

            mech.BehaviorTree = BehaviorTreeFactory.MakeBehaviorTree(ModState.Combat.BattleTechGame, mech, BehaviorTreeIDEnum.CoreAITree);
            Mod.Log.Debug?.Write("Enabled mech behavior tree");

            UnitSpawnedMessage message = new UnitSpawnedMessage("CJ_MECH", mech.GUID);

            ModState.Combat.MessageCenter.PublishMessage(message);

            return(mech);
        }
Ejemplo n.º 4
0
        private static void AutoFixMechDef(MechDef mechDef, IEnumerable <MechDefAutoFixCategory> fixers)
        {
            if (Control.settings.AutoFixMechDefSkip.Contains(mechDef.Description.Id))
            {
                return;
            }

            mechDef.Refresh();

            float originalTotalTonnage = 0, maxValue = 0;

            MechStatisticsRules.CalculateTonnage(mechDef, ref originalTotalTonnage, ref maxValue);

            foreach (var fixer in fixers)
            {
                if (fixer.ShouldFix)
                {
                    fixer.AutoFixMechDef.AutoFixMechDef(mechDef, originalTotalTonnage);
                }
            }
        }
Ejemplo n.º 5
0
        internal static void AddEngineIfPossible(MechDef mechDef)
        {
            if (!Control.settings.AutoFixMechDefEngine)
            {
                return;
            }

            //Control.mod.Logger.LogDebug("A Id=" + mechDef.Description.Id);

            mechDef.Refresh();

            //Control.mod.Logger.LogDebug("B DataManager=" + mechDef.DataManager);

            if (mechDef.Inventory.Any(x => x.GetEngineRef() != null))
            {
                return;
            }

            float currentValue = 0, maxValue = 0;

            MechStatisticsRules.CalculateTonnage(mechDef, ref currentValue, ref maxValue);

            var tonnage          = mechDef.Chassis.Tonnage;
            var maxEngineTonnage = tonnage - currentValue;
            var maxEngine        = (EngineDef)null;

            //Control.mod.Logger.LogDebug("C maxEngineTonnage=" + maxEngineTonnage);

            foreach (var keyvalue in mechDef.DataManager.HeatSinkDefs)
            {
                var heatSinkDef = keyvalue.Value;

                if (heatSinkDef.Tonnage > maxEngineTonnage)
                {
                    continue;
                }

                var engineDef = heatSinkDef.GetEngineDef();
                if (engineDef == null)
                {
                    continue;
                }

                if (engineDef.Type != EngineDef.EngineType.Std)
                {
                    continue;
                }

                if (maxEngine != null && maxEngine.Rating >= engineDef.Rating)
                {
                    continue;
                }

                maxEngine = engineDef;
            }

            //Control.mod.Logger.LogDebug("D maxEngine=" + maxEngine);

            if (maxEngine == null)
            {
                return;
            }

            var componentRefs = new List <MechComponentRef>(mechDef.Inventory);

            { // remove superfluous jump jets
                var maxJetCount = Control.calc.CalcJumpJetCount(maxEngine, tonnage);
                var jumpJetList = componentRefs.Where(x => x.ComponentDefType == ComponentType.JumpJet).ToList();
                for (var i = 0; i < jumpJetList.Count - maxJetCount; i++)
                {
                    componentRefs.Remove(jumpJetList[i]);
                }
            }

            { // add engine
                var componentRef = new MechComponentRef(maxEngine.Def.Description.Id, null, maxEngine.Def.ComponentType, ChassisLocations.CenterTorso);
                componentRefs.Add(componentRef);
            }

            mechDef.SetInventory(componentRefs.ToArray());
        }