public static void FixCost(
            SimGameState __instance,
            MechComponentRef mechComponent,
            ChassisLocations newLocation,
            ChassisLocations previousLocation,
            string mechSimGameUID,
            WorkOrderEntry_InstallComponent __result)
        {
            try
            {
                Control.LogDebug(DType.InstallCost, $"SimGameState_CreateComponentInstallWorkOrder: for {mechComponent.ComponentDefID}");
                Control.LogDebug(DType.InstallCost, $"-- from {previousLocation} to {newLocation}");
                Control.LogDebug(DType.InstallCost, $"-- order {__result?.GetType().ToString() ?? "null"}");

                if (__result == null)
                {
                    Control.LogDebug(DType.InstallCost, "-- No order");
                    return;
                }


                if (__result.DesiredLocation == ChassisLocations.None)
                {
                    var tr = Traverse.Create(__result);
                    tr.Field <int>("Cost").Value = 0;
                }
                else
                {
                    var tr = Traverse.Create(__result).Field <int>("Cost");

                    if (tr == null)
                    {
                        Control.LogDebug(DType.InstallCost, "SimGameState_CreateComponentInstallWorkOrder: traverce not created!");
                        return;
                    }
                    MechDef mechByID = __instance.GetMechByID(mechSimGameUID);
#if CCDEBUG
                    if (mechByID == null)
                    {
                        Control.LogDebug(DType.InstallCost, "-- no mech found!");
                    }
#endif
                    if (mechByID != null && mechByID.Chassis.ChassisTags.Contains(Control.Settings.OmniTechFlag))
                    {
                        Control.LogDebug(DType.InstallCost, "-- mech is omni!");
                        tr.Value = (Control.Settings.OmniTechCostBySize ? mechComponent.Def.InventorySize / 2 : 1) * Control.Settings.OmniTechInstallCost;
                    }


                    if (tr.Value == 0)
                    {
                        tr.Value = 1;
                    }
                }
            }
            catch (Exception e)
            {
                Control.LogError(e);
            }
        }
Пример #2
0
        internal static void ChangeInstallationCosts(MechComponentRef mechComponent, WorkOrderEntry_InstallComponent workOrderEntry)
        {
            if (mechComponent == null)
            {
                return;
            }

            // removing is always fast and cheap
            if (workOrderEntry.DesiredLocation == ChassisLocations.None)
            {
                return;
            }

            var engine = mechComponent.GetEngineCoreRef(null);

            if (engine == null)
            {
                return;
            }

            var cbillCost = workOrderEntry.GetCBillCost();
            var techCost  = workOrderEntry.GetCost();

            Control.calc.CalcInstallCosts(engine.CoreDef, ref cbillCost, ref techCost);

            var traverse = Traverse.Create(workOrderEntry);

            traverse.Field("CBillCost").SetValue(cbillCost);
            traverse.Field("Cost").SetValue(techCost);
        }
        public void ApplyToMechlab()
        {
            if (Applied)
            {
                return;
            }
            var mechLab = MechLabHelper.CurrentMechLab;
            var lhelper = mechLab.GetLocationHelper(Location);

            if (lhelper == null)
            {
                return;
            }

            if (slot != null)
            {
                if (mechLab.InSimGame)
                {
                    WorkOrderEntry_InstallComponent subEntry = mechLab.MechLab.Sim.CreateComponentInstallWorkOrder(
                        mechLab.MechLab.baseWorkOrder.MechID,
                        slot.ComponentRef, Location, slot.MountedLocation);
                    mechLab.MechLab.baseWorkOrder.AddSubEntry(subEntry);
                }
            }
            else
            {
                slot = DefaultHelper.CreateSlot(ItemID, Type);
            }

            lhelper.widget.OnAddItem(slot, true);
            slot.MountedLocation = Location;
        }
Пример #4
0
        public override void DoChange(MechLabHelper mechLab, LocationHelper loc)
        {
            Control.LogDebug(DType.ComponentInstall, $"-- AddFromInventoryChange: {item.ComponentRef.ComponentDefID} to {location}");

            var widget = location == loc.widget.loadout.Location ? loc.widget : mechLab.GetLocationWidget(location);

            if (widget == null)
            {
                return;
            }

            widget.OnAddItem(item, false);
            Control.LogDebug(DType.ComponentInstall, "--- added");


            if (mechLab.MechLab.IsSimGame)
            {
                Control.LogDebug(DType.ComponentInstall, "--- not default: create work order");
                WorkOrderEntry_InstallComponent subEntry = mechLab.MechLab.Sim.CreateComponentInstallWorkOrder(
                    mechLab.MechLab.baseWorkOrder.MechID,
                    item.ComponentRef, widget.loadout.Location, item.MountedLocation);
                mechLab.MechLab.baseWorkOrder.AddSubEntry(subEntry);
            }
            item.MountedLocation = location;
        }
Пример #5
0
            public static void Prefix(WorkOrderEntry_InstallComponent __instance, ref int techCost, ref int cbillCost, string mechSimGameUID)
            {
                var mechTags = UnityGameInstance.BattleTechGame.Simulation.GetMechByID(mechSimGameUID).MechTags.ToList();

                if (mechTags.Contains("BR_MQ_GenericDesign"))
                {
                    techCost  = (int)(techCost * Core.Settings.GenericDesignRefitFactor);
                    cbillCost = (int)(cbillCost * Core.Settings.GenericDesignRefitFactor);
                }
                if (mechTags.Contains("BR_MQ_Bushwacker") && __instance.ComponentType == ComponentType.HeatSink)
                {
                    techCost  = (int)(techCost * Core.Settings.BushwackerHSComponentFactor);
                    cbillCost = (int)(cbillCost * Core.Settings.BushwackerHSComponentFactor);
                }
                if (mechTags.Contains("BR_MQ_Omni"))
                {
                    techCost = (int)(Core.Settings.OmniRefitValue);
                }
                if (mechTags.Contains("BR_MQ_NonStandardParts"))
                {
                    techCost  = (int)(techCost * Core.Settings.NonStandardPartsFactor);
                    cbillCost = (int)(cbillCost * Core.Settings.NonStandardPartsFactor);
                }
                if (mechTags.Contains("BR_MQ_Rare"))
                {
                    techCost  = (int)(techCost * Core.Settings.RareRepairFactor);
                    cbillCost = (int)(cbillCost * Core.Settings.RareRepairFactor);
                }
                if (mechTags.Contains("BR_MQ_MuseumItem"))
                {
                    techCost  = (int)(techCost * Core.Settings.MuseumItemRepairFactor);
                    cbillCost = (int)(cbillCost * Core.Settings.MuseumItemRepairFactor);
                }
            }
Пример #6
0
 public void OnInstalled(WorkOrderEntry_InstallComponent order, SimGameState state, MechDef mech)
 {
     Control.LogDebug(DType.ComponentInstall, $"- AutoReplace");
     Control.LogDebug(DType.ComponentInstall, $"-- search replace for {order.MechComponentRef.ComponentDefID}");
     if (order.PreviousLocation != ChassisLocations.None)
     {
         var location = Location == ChassisLocations.None ? order.PreviousLocation : Location;
         Control.LogDebug(DType.ComponentInstall, $"-- found, adding {ComponentDefId} to {location}");
         DefaultHelper.AddInventory(ComponentDefId, mech, location, order.MechComponentRef.ComponentDefType, state);
     }
     else
     {
         Control.LogDebug(DType.ComponentInstall, $"-- new component, not replacement needed");
     }
 }
 public static void Postfix(
     SimGameState __instance,
     MechComponentRef mechComponent,
     ChassisLocations newLocation,
     ChassisLocations previousLocation,
     WorkOrderEntry_InstallComponent __result
     )
 {
     try
     {
         WorkOrderCostsHandler.Shared.ComponentInstallWorkOrder(mechComponent, newLocation, __result);
     }
     catch (Exception e)
     {
         Control.mod.Logger.LogError(e);
     }
 }
            // Copied from OnMechLabDrop() but with inplace replacing of parts removed
            public static bool Prefix(
                MechLabLocationWidget __instance,
                MechLabPanel ___mechLab,
                Localize.Text ____dropErrorMessage,
                PointerEventData eventData,
                MechLabDropTargetType addToType)
            {
                return(_harmonyManager.PrefixLogExceptions(() =>
                {
                    if (!___mechLab.Initialized)
                    {
                        return;
                    }

                    if (___mechLab.DragItem == null)
                    {
                        return;
                    }

                    IMechLabDraggableItem dragItem = ___mechLab.DragItem;
                    bool flag = __instance.ValidateAdd(dragItem.ComponentRef);
                    if (!flag)
                    {
                        ___mechLab.ShowDropErrorMessage(____dropErrorMessage);
                        ___mechLab.OnDrop(eventData);
                        return;
                    }

                    bool clearOriginalItem = __instance.OnAddItem(dragItem, true);
                    if (__instance.Sim != null)
                    {
                        WorkOrderEntry_InstallComponent subEntry =
                            __instance.Sim.CreateComponentInstallWorkOrder(___mechLab.baseWorkOrder.MechID,
                                                                           dragItem.ComponentRef, __instance.loadout.Location, dragItem.MountedLocation);
                        ___mechLab.baseWorkOrder.AddSubEntry(subEntry);
                    }

                    dragItem.MountedLocation = __instance.loadout.Location;
                    ___mechLab.ClearDragItem(clearOriginalItem);
                    __instance.RefreshHardpointData();
                    ___mechLab.ValidateLoadout(false);
                }));
            }
Пример #9
0
 public static void Postfix(
     SimGameState __instance,
     string mechSimGameUID,
     MechComponentRef mechComponent,
     ChassisLocations newLocation,
     ChassisLocations previousLocation,
     WorkOrderEntry_InstallComponent __result
     )
 {
     try
     {
         var mechDef = __instance.GetMechByID(mechSimGameUID);
         WorkOrderCostsHandler.Shared.ComponentInstallWorkOrder(mechDef, mechComponent, newLocation, __result);
     }
     catch (Exception e)
     {
         Control.LogError(e);
     }
 }
        public static void Postfix(WorkOrderEntry_InstallComponent order, SimGameState __instance)
        {
            Control.LogDebug(DType.ComponentInstall, $"ML_InstallComponent {order.MechComponentRef.ComponentDefID} - {order.MechComponentRef.Def == null}");
            if (!order.IsMechLabComplete)
            {
                return;
            }

            var mech = __instance.GetMechByID(order.MechID);

            if (mech == null)
            {
                return;
            }

            foreach (var handler in order.MechComponentRef.GetComponents <IOnInstalled>())
            {
                handler.OnInstalled(order, __instance, mech);
            }
            Control.LogDebug(DType.ComponentInstall, $"ML_InstallComponent complete");
        }
Пример #11
0
        internal static void ChangeInstallationCosts(MechComponentRef mechComponent, WorkOrderEntry_InstallComponent workOrderEntry)
        {
            if (mechComponent == null)
            {
                return;
            }

            if (workOrderEntry.DesiredLocation == ChassisLocations.None)
            {
                return;
            }

            var engine = mechComponent.GetEngineRef();

            if (engine == null)
            {
                return;
            }

            workOrderEntry.SetCost(Control.calc.CalcInstallTechCost(engine.engineDef));
        }
Пример #12
0
        public void OnInstalled(WorkOrderEntry_InstallComponent order, SimGameState state, MechDef mech)
        {
            Control.LogDebug(DType.ComponentInstall, $"- AutoLinked");

            if (order.PreviousLocation != ChassisLocations.None)
            {
                foreach (var link in Links)
                {
                    Control.LogDebug(DType.ComponentInstall, $"-- removing {link.ComponentDefId} from {link.Location}");
                    DefaultHelper.RemoveInventory(link.ComponentDefId, mech, link.Location, link.ComponentDefType ?? Def.ComponentType);
                }
            }

            if (order.DesiredLocation != ChassisLocations.None)
            {
                foreach (var link in Links)
                {
                    Control.LogDebug(DType.ComponentInstall, $"-- adding {link.ComponentDefId} to {link.Location}");
                    DefaultHelper.AddInventory(link.ComponentDefId, mech, link.Location, link.ComponentDefType ?? Def.ComponentType, state);
                }
            }
        }
Пример #13
0
        // @ToDo: Somehow implement that manual Remove/Add of components AFTER this method-call calculates work-orders correctly
        public static void SetEquipment(this MechLabPanel mechLabPanel, List <InventoryItemElement_Simple> equipment, MechLabLocationWidget locationWidget, LocationLoadoutDef loadout)
        {
            locationWidget.loadout = loadout;

            // Nah. This kills fixed equipment!
            //locationWidget.ClearInventory();

            for (int i = 0; i < equipment.Count; i++)
            {
                if (equipment[i].ComponentRef.MountedLocation == loadout.Location)
                {
                    Logger.Debug("[Extensions.SetEquipment] Component: " + equipment[i].ComponentRef.ComponentDefID + " gets installed at: " + loadout.Location.ToString() + " and was fetched from (simulated): " + equipment[i].Origin);

                    // NOTE that creation of items (vs. simulate-grabbing the real ones from inventory) will confuse the work-order-entries
                    // @ToDo: Try setting "copyComponentRef" to true and test somewhen
                    MechLabItemSlotElement mechLabItemSlotElement = mechLabPanel.CreateMechComponentItem(equipment[i].ComponentRef, false, loadout.Location, locationWidget, null);
                    Traverse.Create(mechLabItemSlotElement).Field("originalDropParentType").SetValue(equipment[i].Origin);

                    if (mechLabItemSlotElement != null)
                    {
                        List <MechLabItemSlotElement> ___localInventory = (List <MechLabItemSlotElement>)AccessTools.Field(typeof(MechLabLocationWidget), "localInventory").GetValue(locationWidget);
                        ___localInventory.Add(mechLabItemSlotElement);
                        int ___usedSlots = (int)AccessTools.Field(typeof(MechLabLocationWidget), "usedSlots").GetValue(locationWidget);
                        ___usedSlots += equipment[i].ComponentRef.Def.InventorySize;
                        Transform ___inventoryParent = (Transform)AccessTools.Field(typeof(MechLabLocationWidget), "inventoryParent").GetValue(locationWidget);
                        mechLabItemSlotElement.gameObject.transform.SetParent(___inventoryParent, false);
                        mechLabItemSlotElement.gameObject.transform.localScale = Vector3.one;

                        ReflectionHelper.InvokePrivateMethode(locationWidget, "RefreshMechComponentData", new object[] { mechLabItemSlotElement, false });
                        locationWidget.RefreshHardpointData();

                        // Add WorkOrderEntry
                        WorkOrderEntry_InstallComponent subEntry = locationWidget.Sim.CreateComponentInstallWorkOrder(mechLabPanel.baseWorkOrder.MechID, equipment[i].ComponentRef, loadout.Location, ChassisLocations.None);
                        mechLabPanel.baseWorkOrder.AddSubEntry(subEntry);
                    }
                }
            }
            //mechLabPanel.ValidateLoadout(false);
        }
        public static void Postfix(WorkOrderEntry_InstallComponent order, SimGameState __instance)
        {
            try
            {
                Control.LogDebug(DType.ComponentInstall, $"ML_InstallComponent {order.MechComponentRef.ComponentDefID} - {order.MechComponentRef.Def == null}");
                if (!order.IsMechLabComplete)
                {
                    return;
                }

                var mech = __instance.GetMechByID(order.MechID);
                if (mech == null)
                {
                    return;
                }

                var changes = new Queue <IChange>();
                if (order.PreviousLocation != ChassisLocations.None)
                {
                    changes.Enqueue(new Change_Remove(order.MechComponentRef, order.PreviousLocation, true));
                }
                if (order.DesiredLocation != ChassisLocations.None)
                {
                    changes.Enqueue(new Change_Add(order.MechComponentRef, order.DesiredLocation, true));
                }
                var state = new InventoryOperationState(changes, mech);
                state.DoChanges();
                state.ApplyInventory();

                Control.LogDebug(DType.ComponentInstall, $"ML_InstallComponent complete");
            }
            catch (Exception e)
            {
                Control.LogError(e);
            }
        }
        public static void ChangeCost(string mechSimGameUID,
                                      MechComponentRef mechComponent, ChassisLocations newLocation,
                                      ChassisLocations previousLocation, ref WorkOrderEntry_InstallComponent __result)
        {
            if (newLocation == ChassisLocations.None)
            {
                return;
            }
            if (MechLabPanel_LoadMech.CurrentMech == null || MechLabPanel_LoadMech.CurrentMech.Chassis == null)
            {
                return;
            }
            if (mechComponent.Def == null)
            {
                return;
            }

            if (__result == null)
            {
                return;
            }


            float tpmod = 1;
            float cbmod = 1;

            Logger.LogDebug($"Module Install Cost for {mechComponent.ComponentDefID}: ");
            Logger.LogDebug("***************************************");


            foreach (var tag in ArmorRepair.ModSettings.RepairCostByTag)
            {
                if (MechLabPanel_LoadMech.CurrentMech.Chassis.ChassisTags.Contains(tag.Tag))
                {
                    Logger.LogDebug($" Chassis {tag.Tag} mods tp:{tag.InstallTPCost:0.00} cb:{tag.InstallCBCost:0.00}");

                    tpmod *= tag.InstallTPCost;
                    cbmod *= tag.InstallCBCost;
                }

                if (mechComponent.Def.ComponentTags.Contains(tag.Tag))
                {
                    Logger.LogDebug($" {mechComponent.ComponentDefID} {tag.Tag} mods tp:{tag.InstallTPCost:0.00} cb:{tag.InstallCBCost:0.00}");
                    tpmod *= tag.InstallTPCost;
                    cbmod *= tag.InstallCBCost;
                }
            }

            if (tpmod != 1 || cbmod != 1)
            {
                var trav = new Traverse(__result);
                if (tpmod != 1)
                {
                    var cost     = trav.Field <int>("Cost");
                    int new_cost = Mathf.CeilToInt(cost.Value * tpmod);
                    Logger.LogDebug($" TP cost: {cost.Value} * {tpmod:0.000} = {new_cost}");
                    cost.Value = new_cost;
                }

                if (cbmod != 1)
                {
                    var cost     = trav.Field <int>("CBillCost");
                    int new_cost = Mathf.CeilToInt(cost.Value * cbmod);
                    Logger.LogDebug($" CBIll cost: {cost.Value} * {cbmod:0.000} = {new_cost}");
                    cost.Value = new_cost;
                }
            }
            else
            {
                Logger.LogDebug(" no need to adjust, return");
            }

            Logger.LogDebug("***************************************");
        }
        public void ComponentInstallWorkOrder(MechComponentRef mechComponent, ChassisLocations newLocation, WorkOrderEntry_InstallComponent result)
        {
            var workOrderCosts = mechComponent.Def.GetComponent <WorkOrderCosts>();

            if (workOrderCosts == null)
            {
                return;
            }

            if (newLocation == ChassisLocations.None) // remove
            {
                if (mechComponent.DamageLevel == ComponentDamageLevel.Destroyed)
                {
                    ApplyCosts(result, workOrderCosts.RemoveDestroyed);
                }
                else
                {
                    ApplyCosts(result, workOrderCosts.Remove);
                }
            }
            else // install
            {
                ApplyCosts(result, workOrderCosts.Install);
            }
        }
Пример #17
0
        public void OnInstalled(WorkOrderEntry_InstallComponent order, SimGameState state, MechDef mech)
        {
            Control.LogDebug(DType.ComponentInstall, $"- Category");
            if (order.PreviousLocation != ChassisLocations.None)
            {
                Control.LogDebug(DType.ComponentInstall, "-- removing");
                MechComponentRef def_replace = DefaultFixer.Shared.GetReplaceFor(mech, CategoryID, order.PreviousLocation, state);
                if (def_replace != null)
                {
                    Control.LogDebug(DType.ComponentInstall, $"--- added {def_replace.ComponentDefID}");
                    var inv = mech.Inventory.ToList();
                    inv.Add(def_replace);
                    mech.SetInventory(inv.ToArray());
                }
            }

            if (order.DesiredLocation == ChassisLocations.None)
            {
                return;
            }

            if (!CategoryDescriptor.AutoReplace || CategoryDescriptor.MaxEquiped < 0 && CategoryDescriptor.MaxEquipedPerLocation < 0)
            {
                Control.LogDebug(DType.ComponentInstall, $"-- {CategoryDescriptor.DisplayName} r:{CategoryDescriptor.AutoReplace}  max:{CategoryDescriptor.MaxEquiped} mpr:{CategoryDescriptor.MaxEquipedPerLocation} = not requre replace");

                return;
            }


            int n1 = mech.Inventory.Count(i => i.IsCategory(CategoryID));
            int n2 = mech.Inventory.Count(i => i.MountedLocation == order.DesiredLocation && i.IsCategory(CategoryID));

#if CCDEBUG
            if (Control.Settings.DebugInfo.HasFlag(DType.ComponentInstall))
            {
                Control.LogDebug(DType.ComponentInstall, "--- list:");
                foreach (var def in mech.Inventory
                         .Where(i => i.MountedLocation == order.DesiredLocation && i.IsCategory(CategoryID))
                         .Select(i => i.Def))
                {
                    Control.LogDebug(DType.ComponentInstall,
                                     $"---- list: {def.Description.Id}: Default:{def.IsDefault()}");
                }
            }
#endif

            Control.LogDebug(DType.ComponentInstall, $"-- total {n1}/{CategoryDescriptor.MaxEquiped}  location: {n2}/{CategoryDescriptor.MaxEquipedPerLocation}");

            var replace = mech.Inventory.FirstOrDefault(i => !i.IsModuleFixed(mech) && (i.MountedLocation == order.DesiredLocation || CategoryDescriptor.ReplaceAnyLocation) && i.IsCategory(CategoryID) && i.IsDefault());

            Control.LogDebug(DType.ComponentInstall, $"-- possible replace: {(replace == null ? "not found" : replace.ComponentDefID)}");

            if (replace == null)
            {
                return;
            }

            bool need_replace = (CategoryDescriptor.MaxEquiped > 0 && n1 > CategoryDescriptor.MaxEquiped) ||
                                (CategoryDescriptor.MaxEquipedPerLocation > 0 && n2 > CategoryDescriptor.MaxEquipedPerLocation);

            Control.LogDebug(DType.ComponentInstall, $"-- need_repalce: {need_replace}");

            if (need_replace)
            {
                DefaultHelper.RemoveInventory(replace.ComponentDefID, mech, replace.MountedLocation, replace.ComponentDefType);
            }
        }
Пример #18
0
            public static bool Prefix(MechBayPanel __instance, MechBayMechUnitElement mechElement)
            {
                Logger.LogDebug("We are repairing, yes?");
                Logger.Log("We are repairing, yes?");
                if (!Core.Settings.RepairRearm)
                {
                    return(true);
                }

                var     sim     = UnityGameInstance.BattleTechGame.Simulation;
                MechDef mechDef = mechElement.MechDef;
                WorkOrderEntry_MechLab workOrderEntry_MechLab = __instance.Sim.GetWorkOrderEntryForMech(mechDef);
                bool flag = false;

                for (int i = 0; i < mechDef.Inventory.Length; i++)
                {
                    MechComponentRef mechComponentRef = mechDef.Inventory[i];
                    if (mechComponentRef.DamageLevel != ComponentDamageLevel.Functional && mechComponentRef.DamageLevel
                        != ComponentDamageLevel.Installing && !MechValidationRules.MechComponentUnderMaintenance(mechComponentRef, MechValidationLevel.MechLab, workOrderEntry_MechLab))
                    {
                        flag = true;
                        break;
                    }
                }
                if (!mechDef.IsDamaged && !flag)
                {
                    return(false);
                }
                List <ChassisLocations> list = new List <ChassisLocations>();

                __instance.pendingWorkOrderNew = false;
                __instance.pendingWorkOrderEntriesToAdd.Clear();
                if (workOrderEntry_MechLab == null)
                {
                    workOrderEntry_MechLab = new WorkOrderEntry_MechLab(WorkOrderType.MechLabGeneric, "MechLab-BaseWorkOrder", Strings.T("Modify 'Mech - {0}", new object[]
                    {
                        mechDef.Description.Name
                    }), mechDef.GUID, 0, Strings.T(__instance.Sim.Constants.Story.GeneralMechWorkOrderCompletedText, new object[]
                    {
                        mechDef.Description.Name
                    }));
                    workOrderEntry_MechLab.SetMechDef(mechDef);
                    __instance.pendingWorkOrderNew = true;
                }
                __instance.pendingWorkOrder = workOrderEntry_MechLab;
                if (!MechValidationRules.MechStructureUnderMaintenance(ChassisLocations.Head, MechValidationLevel.MechLab, workOrderEntry_MechLab) && mechDef.Head.CurrentInternalStructure < mechDef.Chassis.Head.InternalStructure)
                {
                    list.Add(ChassisLocations.Head);
                }
                if (!MechValidationRules.MechStructureUnderMaintenance(ChassisLocations.CenterTorso, MechValidationLevel.MechLab, workOrderEntry_MechLab) && mechDef.CenterTorso.CurrentInternalStructure < mechDef.Chassis.CenterTorso.InternalStructure)
                {
                    list.Add(ChassisLocations.CenterTorso);
                }
                if (!MechValidationRules.MechStructureUnderMaintenance(ChassisLocations.LeftTorso, MechValidationLevel.MechLab, workOrderEntry_MechLab) && mechDef.LeftTorso.CurrentInternalStructure < mechDef.Chassis.LeftTorso.InternalStructure)
                {
                    list.Add(ChassisLocations.LeftTorso);
                }
                if (!MechValidationRules.MechStructureUnderMaintenance(ChassisLocations.RightTorso, MechValidationLevel.MechLab, workOrderEntry_MechLab) && mechDef.RightTorso.CurrentInternalStructure < mechDef.Chassis.RightTorso.InternalStructure)
                {
                    list.Add(ChassisLocations.RightTorso);
                }
                if (!MechValidationRules.MechStructureUnderMaintenance(ChassisLocations.LeftLeg, MechValidationLevel.MechLab, workOrderEntry_MechLab) && mechDef.LeftLeg.CurrentInternalStructure < mechDef.Chassis.LeftLeg.InternalStructure)
                {
                    list.Add(ChassisLocations.LeftLeg);
                }
                if (!MechValidationRules.MechStructureUnderMaintenance(ChassisLocations.RightLeg, MechValidationLevel.MechLab, workOrderEntry_MechLab) && mechDef.RightLeg.CurrentInternalStructure < mechDef.Chassis.RightLeg.InternalStructure)
                {
                    list.Add(ChassisLocations.RightLeg);
                }
                if (!MechValidationRules.MechStructureUnderMaintenance(ChassisLocations.LeftArm, MechValidationLevel.MechLab, workOrderEntry_MechLab) && mechDef.LeftArm.CurrentInternalStructure < mechDef.Chassis.LeftArm.InternalStructure)
                {
                    list.Add(ChassisLocations.LeftArm);
                }
                if (!MechValidationRules.MechStructureUnderMaintenance(ChassisLocations.RightArm, MechValidationLevel.MechLab, workOrderEntry_MechLab) && mechDef.RightArm.CurrentInternalStructure < mechDef.Chassis.RightArm.InternalStructure)
                {
                    list.Add(ChassisLocations.RightArm);
                }
                if (list.Count < 1 && !flag)
                {
                    GenericPopupBuilder.Create("Repair Already Ordered", string.Format("A repair order has already been queued for " +
                                                                                       "{0}", mechDef.Name)).AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true).Render();
                    __instance.OnRepairAllCancelled();
                    return(false);
                }
                int num  = 0;
                int num2 = 0;

                for (int j = 0; j < list.Count; j++)
                {
                    LocationDef        chassisLocationDef = mechDef.GetChassisLocationDef(list[j]);
                    LocationLoadoutDef locationLoadoutDef = mechDef.GetLocationLoadoutDef(list[j]);
                    int structureCount = Mathf.RoundToInt(Mathf.Max(0f, chassisLocationDef.InternalStructure - locationLoadoutDef.CurrentInternalStructure));
                    WorkOrderEntry_RepairMechStructure workOrderEntry_RepairMechStructure = __instance.Sim.CreateMechRepairWorkOrder(mechDef.GUID, list[j], structureCount);
                    __instance.pendingWorkOrderEntriesToAdd.Add(workOrderEntry_RepairMechStructure);
                    num  += workOrderEntry_RepairMechStructure.GetCost();
                    num2 += workOrderEntry_RepairMechStructure.GetCBillCost();
                }
                StringBuilder stringBuilder = new StringBuilder();
                int           num3          = 0;

                for (int k = 0; k < mechDef.Inventory.Length; k++)
                {
                    MechComponentRef mechComponentRef2 = mechDef.Inventory[k];
                    if (string.IsNullOrEmpty(mechComponentRef2.SimGameUID))
                    {
                        mechComponentRef2.SetSimGameUID(__instance.Sim.GenerateSimGameUID());
                    }
                    if (mechComponentRef2.DamageLevel == ComponentDamageLevel.Destroyed)
                    {
                        if (num3 < 1)
                        {
                            stringBuilder.Append("\n\nThe following components have been Destroyed. If you continue with the Repair, " +
                                                 "replacement Components will NOT be installed. If you want to replace them with identical or " +
                                                 "different Components, you must Refit the 'Mech.\n\n");
                        }
                        if (num3 < 5)
                        {
                            stringBuilder.Append(mechComponentRef2.MountedLocation.ToString());
                            stringBuilder.Append(": ");
                            stringBuilder.Append(mechComponentRef2.Def.Description.Name);
                            stringBuilder.Append("\n");
                        }
                        num3++;
                        WorkOrderEntry_InstallComponent workOrderEntry_InstallComponent = sim.CreateComponentInstallWorkOrder(__instance.selectedMech.MechDef.GUID,
                                                                                                                              mechComponentRef2, ChassisLocations.None, mechComponentRef2.MountedLocation);
                        __instance.pendingWorkOrderEntriesToAdd.Insert(0, workOrderEntry_InstallComponent);
                        num  += workOrderEntry_InstallComponent.GetCost();
                        num2 += workOrderEntry_InstallComponent.GetCBillCost();
                    }
                    else if (mechComponentRef2.DamageLevel != ComponentDamageLevel.Functional && mechComponentRef2.DamageLevel != ComponentDamageLevel.Installing)
                    {
                        WorkOrderEntry_RepairComponent workOrderEntry_RepairComponent = __instance.Sim.CreateComponentRepairWorkOrder(mechComponentRef2, true);
                        __instance.pendingWorkOrderEntriesToAdd.Add(workOrderEntry_RepairComponent);
                        num  += workOrderEntry_RepairComponent.GetCost();
                        num2 += workOrderEntry_RepairComponent.GetCBillCost();
                    }
                }

                foreach (var foo in __instance.pendingWorkOrderEntriesToAdd)
                {
                    Logger.LogDebug(foo.ID);
                }
                Logger.LogDebug("Armor Repair Section");
                float armorLoss = 1;
                bool  armorTag  = false;

                foreach (var tag in mechDef.MechTags)
                {
                    Logger.LogDebug(tag);
                    if (tag.StartsWith("XLRPArmor"))
                    {
                        armorTag = true;
                        string[] parsedString = tag.Split('_');
                        armorLoss = float.Parse(parsedString[1]);
                    }
                    Logger.LogDebug(armorLoss.ToString());
                }
                if (armorTag)
                {
                    if (!mechDef.MechTags.Contains("XLRP_Armor_Repairing"))
                    {
                        mechDef.MechTags.Add("XLRP_Armor_Repairing");
                    }
                    int brokenArmor = (int)((1 - armorLoss) * mechDef.MechDefAssignedArmor);
                    int frontArmor  = (int)(mechDef.MechDefAssignedArmor - mechDef.CenterTorso.AssignedRearArmor -
                                            mechDef.LeftTorso.AssignedRearArmor - mechDef.RightTorso.AssignedRearArmor);
                    int rearArmor = (int)(mechDef.CenterTorso.AssignedRearArmor +
                                          mechDef.LeftTorso.AssignedRearArmor + mechDef.RightTorso.AssignedRearArmor);
                    Logger.LogDebug($"brokenAmor: {brokenArmor}, frontArmor: {frontArmor}, rearArmor: {rearArmor}");
                    WorkOrderEntry_ModifyMechArmor subEntry = sim.CreateMechArmorModifyWorkOrder(__instance.selectedMech.MechDef.GUID,
                                                                                                 ChassisLocations.All, brokenArmor, frontArmor, rearArmor);

                    __instance.pendingWorkOrderEntriesToAdd.Add(subEntry);
                    num  += subEntry.GetCost();
                    num2 += subEntry.GetCBillCost();
                }

                num = Mathf.Max(1, Mathf.CeilToInt((float)num / (float)__instance.Sim.MechTechSkill));
                if (num3 > 5)
                {
                    stringBuilder.Append(Strings.T("...\nAnd {0} additional destroyed components.\n", new object[]
                    {
                        num3 - 5
                    }));
                }
                string body = Strings.T("Repairing {0} will cost {1:n0} C-Bills and take {2} Days.{3}\n\nProceed?", new object[]
                {
                    mechDef.Name,
                    num2,
                    num,
                    stringBuilder.ToString()
                });

                GenericPopupBuilder.Create("Repair 'Mech?", body).AddButton("Cancel", new Action(__instance.OnRepairAllCancelled), true, null).
                AddButton("Repair", new Action(__instance.OnRepairAllAccepted), true, null).AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true).Render();
                return(false);
            }
Пример #19
0
        public void OnInstalled(WorkOrderEntry_InstallComponent order, SimGameState state, MechDef mech)
        {
            try
            {
                if (order.DesiredLocation != ChassisLocations.None &&
                    ChassisLocations.Arms.HasFlag(order.DesiredLocation))
                {
                    var slots = ArmActuatorCC.ClearDefaultActuators(mech, order.DesiredLocation);
                    CustomComponents.Control.LogDebug(DType.ComponentInstall,
                                                      $"- ArmActuator removing, left {slots}");

                    ArmActuatorCC.AddDefaultToInventory(mech, state, order.DesiredLocation,
                                                        ArmActuatorSlot.PartShoulder, ref slots);
                    ArmActuatorCC.AddDefaultToInventory(mech, state, order.DesiredLocation,
                                                        ArmActuatorSlot.PartUpper, ref slots);
                    CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- done");

                    if (!ArmActuatorCC.IsIgnoreFullActuators(mech))
                    {
                        var limit = mech.Chassis.Is <ArmActuatorSupport>(out var s)
                                ? s.GetLimit(order.DesiredLocation)
                                : ArmActuatorSlot.Hand;
                        if (limit.HasFlag(ArmActuatorSlot.PartLower))
                        {
                            ArmActuatorCC.AddDefaultToInventory(mech, state, order.DesiredLocation,
                                                                ArmActuatorSlot.PartLower, ref slots);
                        }
                        if (limit.HasFlag(ArmActuatorSlot.PartHand))
                        {
                            ArmActuatorCC.AddDefaultToInventory(mech, state, order.DesiredLocation,
                                                                ArmActuatorSlot.PartHand, ref slots);
                        }
                    }
                }

                if (order.PreviousLocation != ChassisLocations.None &&
                    ChassisLocations.Arms.HasFlag(order.PreviousLocation))
                {
                    var slots = ArmActuatorCC.ClearDefaultActuators(mech, order.PreviousLocation);
                    CustomComponents.Control.LogDebug(DType.ComponentInstall,
                                                      $"- ArmActuator adding, left {slots}");

                    ArmActuatorCC.AddDefaultToInventory(mech, state, order.PreviousLocation,
                                                        ArmActuatorSlot.PartShoulder, ref slots);
                    ArmActuatorCC.AddDefaultToInventory(mech, state, order.PreviousLocation,
                                                        ArmActuatorSlot.PartUpper, ref slots);
                    CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- done");

                    if (!ArmActuatorCC.IsIgnoreFullActuators(mech))
                    {
                        var limit = mech.Chassis.Is <ArmActuatorSupport>(out var s)
                                ? s.GetLimit(order.PreviousLocation)
                                : ArmActuatorSlot.Hand;
                        if (limit.HasFlag(ArmActuatorSlot.PartLower))
                        {
                            ArmActuatorCC.AddDefaultToInventory(mech, state, order.PreviousLocation,
                                                                ArmActuatorSlot.PartLower, ref slots);
                        }
                        if (limit.HasFlag(ArmActuatorSlot.PartHand))
                        {
                            ArmActuatorCC.AddDefaultToInventory(mech, state, order.PreviousLocation,
                                                                ArmActuatorSlot.PartHand, ref slots);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                CustomComponents.Control.LogError(e);
            }
        }
Пример #20
0
        public static bool Prefix(MechLabLocationWidget __instance, ref string ___dropErrorMessage,
                                  List <MechLabItemSlotElement> ___localInventory,
                                  int ___usedSlots,
                                  int ___maxSlots,
                                  TextMeshProUGUI ___locationName,
                                  MechLabPanel ___mechLab)
        {
            Control.mod.Logger.Log("Drop on " + ___locationName.text);


            if (!___mechLab.Initialized)
            {
                Control.mod.Logger.Log("not Initialized");

                return(false);
            }
            if (___mechLab.DragItem == null)
            {
                Control.mod.Logger.Log("Dragged item: NULL, exit");
                return(false);
            }

            var drag_item = ___mechLab.DragItem;


            if (drag_item.ComponentRef == null)
            {
                Control.mod.Logger.Log("Dropped item: NULL, exit");

                return(false);
            }

            Control.mod.Logger.Log("Dropped item: " + drag_item.ComponentRef.ComponentDefID);

            UniqueItem new_item_info;

            if (!drag_item.ComponentRef.Def.IsUnique(out new_item_info))
            {
                Control.mod.Logger.Log("Item not Unique, exit");

                return(true);
            }

            bool flag = __instance.ValidateAdd(drag_item.ComponentRef);

            Control.mod.Logger.Log(string.Format("Validation: {0} - {1}", flag, ___dropErrorMessage));

            if (!flag && !___dropErrorMessage.EndsWith("Not enough free slots."))
            {
                return(true);
            }

            var n = ___localInventory.FindUniqueItem(new_item_info);

            Control.mod.Logger.Log("index = " + n.ToString());

            //if no - continue normal flow(add new or show "not enough slots" message
            if (n < 0)
            {
                return(true);
            }

            if (___usedSlots - ___localInventory[n].ComponentRef.Def.InventorySize + drag_item.ComponentRef.Def.InventorySize >
                ___maxSlots)
            {
                return(true);
            }

            var old_item = ___localInventory[n];

            __instance.OnRemoveItem(old_item, true);
            ___mechLab.ForceItemDrop(old_item);
            var clear = __instance.OnAddItem(drag_item, true);

            if (__instance.Sim != null)
            {
                WorkOrderEntry_InstallComponent subEntry = __instance.Sim.CreateComponentInstallWorkOrder(
                    ___mechLab.baseWorkOrder.MechID,
                    drag_item.ComponentRef, __instance.loadout.Location, drag_item.MountedLocation);
                ___mechLab.baseWorkOrder.AddSubEntry(subEntry);
            }

            drag_item.MountedLocation = __instance.loadout.Location;
            ___mechLab.ClearDragItem(clear);
            __instance.RefreshHardpointData();
            ___mechLab.ValidateLoadout(false);
            return(false);
        }
Пример #21
0
 // change engine installation costs
 public static void Postfix(SimGameState __instance, MechComponentRef mechComponent, ref WorkOrderEntry_InstallComponent __result)
 {
     try
     {
         Engine.ChangeInstallationCosts(mechComponent, __result);
     }
     catch (Exception e)
     {
         Control.mod.Logger.LogError(e);
     }
 }