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; }
public string ReplaceValidateDrop(MechLabItemSlotElement drop_item, LocationHelper location, List <IChange> changes) { if (location.widget.loadout.Location != ChassisLocations.LeftArm && location.widget.loadout.Location != ChassisLocations.RightArm) { return(string.Empty); } var total_slot = Type; var mount_loc = location.widget.loadout.Location; var mechlab = location.mechLab; var mech = mechlab.activeMechDef; CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- ArmActuator: {Def.Description.Id} {Type}"); void add_default(ArmActuatorSlot slot) { bool add_item(string id) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"---- id:[{id}]"); if (string.IsNullOrEmpty(id)) { return(false); } var r = DefaultHelper.CreateRef(id, ComponentType.Upgrade, mechlab.dataManager, mechlab.Sim); if (r.Is <ArmActuator>(out var actuator) && (actuator.Type & total_slot) == 0) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"----- actuator fit: install"); changes.Add(new AddDefaultChange(mount_loc, DefaultHelper.CreateSlot(r, mechlab))); total_slot = total_slot | actuator.Type; return(true); } CustomComponents.Control.LogDebug(DType.ComponentInstall, $"----- actuator not fit, ski[["); return(false); } CustomComponents.Control.LogDebug(DType.ComponentInstall, $"--- adding {slot} to {total_slot}"); if (total_slot.HasFlag(slot)) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"---- already exist, return"); return; } if (add_item(ArmActuatorCC.GetDefaultActuator(mech, mount_loc, slot))) { return; } add_item(ArmActuatorCC.GetDefaultActuator(null, mount_loc, slot)); } foreach (var item in location.LocalInventory.Where(i => i.ComponentRef.Is <ArmActuator>())) { var actuator = item.ComponentRef.GetComponent <ArmActuator>(); if ((actuator.Type & Type) != 0) { if (item.ComponentRef.IsModuleFixed(location.mechLab.activeMechDef)) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"--- cannot remove {item.ComponentRef.ComponentDefID}"); return ($"Cannot install {drop_item.ComponentRef.Def.Description.Name} - {Type} occuped by {item.ComponentRef.Def.Description.Name}"); } CustomComponents.Control.LogDebug(DType.ComponentInstall, $"--- removing {item.ComponentRef.ComponentDefID}"); changes.Add(new RemoveChange(location.widget.loadout.Location, item)); } else { total_slot = total_slot | actuator.Type; } } add_default(ArmActuatorSlot.PartShoulder); add_default(ArmActuatorSlot.PartUpper); if (ArmActuatorCC.IsIgnoreFullActuators(mech)) { if (!total_slot.HasFlag(ArmActuatorSlot.PartLower) && total_slot.HasFlag(ArmActuatorSlot.PartHand)) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"--- adding Lower to {total_slot}"); var change = AddFromInventoryChange.FoundInInventory(mount_loc, new MechLabHelper(mechlab), item => item.Is <ArmActuator>(out var actuator) && actuator.Type == ArmActuatorSlot.PartLower, item => item.Description.Id == ArmActuatorFeature.settings.DefaultCBTLower ); if (change != null) { changes.Add(change); } else if (ArmActuatorFeature.settings.InterruptHandDropIfNoLower) { return($"Cannot found LowerArm"); } } else { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"--- Lower exist in {total_slot}, done"); } } else { var limit = mech.Chassis.Is <ArmActuatorSupport>(out var s) ? s.GetLimit(mount_loc) : ArmActuatorSlot.Hand; if (limit.HasFlag(ArmActuatorSlot.PartLower)) { add_default(ArmActuatorSlot.PartLower); } if (limit.HasFlag(ArmActuatorSlot.PartHand)) { add_default(ArmActuatorSlot.PartHand); } } return(string.Empty); }