internal static void AddDefaultToInventory(MechDef mechdef, SimGameState simgame, ChassisLocations location, ArmActuatorSlot slot, ref ArmActuatorSlot totalSlots) { bool add_item(string id, ref ArmActuatorSlot total_slot) { if (string.IsNullOrEmpty(id)) { return(false); } var r = DefaultHelper.CreateRef(id, ComponentType.Upgrade, UnityGameInstance.BattleTechGame.DataManager, simgame); if (r.Is <ArmActuator>(out var actuator) && (actuator.Type & total_slot) == 0) { DefaultHelper.AddInventory(id, mechdef, location, ComponentType.Upgrade, simgame); total_slot = total_slot | actuator.Type; return(true); } return(false); } CustomComponents.Control.LogDebug(DType.ComponentInstall, $"---- adding {slot} to {totalSlots}"); if (totalSlots.HasFlag(slot)) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"---- already present"); return; } if (add_item(GetDefaultActuator(mechdef, location, slot), ref totalSlots)) { return; } add_item(GetDefaultActuator(null, location, slot), ref totalSlots); }
public void ApplyToInventory(MechDef mech, List <MechComponentRef> inventory) { if (Applied) { return; } var r = DefaultHelper.CreateRef(ItemID, Type, Location); if (r.IsDefault()) { inventory.Add(r); } }
public void PreviewApply(InventoryOperationState state) { InvItem i = null; if (!Applied) { i = new InvItem(DefaultHelper.CreateRef(ItemID, Type, Location), Location); item = i.Item; } if (i != null) { state.Inventory.Add(i); } }
internal static void ClearInventory(MechDef mech, List <MechComponentRef> result, SimGameState state) { if (SkipArmActuatorValidationAndFixingForMechDef(mech)) { return; } var total_slot = ArmActuatorSlot.None; void add_default(ChassisLocations location, ArmActuatorSlot slot) { bool add_item(string id) { CustomComponents.Control.LogDebug(DType.ClearInventory, $"--- adding {id} to {location}"); if (string.IsNullOrEmpty(id)) { CustomComponents.Control.LogDebug(DType.ClearInventory, $"---- is null - skipping"); return(false); } var r = DefaultHelper.CreateRef(id, ComponentType.Upgrade, state.DataManager, state); if (r.Is <ArmActuator>(out var actuator) && (actuator.Type & total_slot) == 0) { r.SetData(location, -1, ComponentDamageLevel.Functional, true); result.Add(r); total_slot = total_slot | actuator.Type; return(true); } return(false); } if (total_slot.HasFlag(slot)) { CustomComponents.Control.LogDebug(DType.ClearInventory, $"--- already have {slot} skip"); return; } if (!add_item(GetDefaultActuator(mech, location, slot))) { add_item(GetDefaultActuator(null, location, slot)); } } void clear_side(ChassisLocations location) { result.RemoveAll(i => i.MountedLocation == location & i.Is <ArmActuator>() && !i.IsModuleFixed(mech)); total_slot = ArmActuatorSlot.None; foreach (var item in result.Where(i => i.MountedLocation == location)) { if (item.Is <ArmActuator>(out var a)) { total_slot = total_slot | a.Type; } } CustomComponents.Control.LogDebug(DType.ClearInventory, $"-- {location} current {total_slot}"); add_default(location, ArmActuatorSlot.PartShoulder); add_default(location, ArmActuatorSlot.PartUpper); if (ArmActuatorFeature.settings.ForceFullDefaultActuators && !IsIgnoreFullActuators(mech)) { var limit = mech.Chassis.Is <ArmActuatorSupport>(out var s) ? s.GetLimit(location) : ArmActuatorSlot.Hand; if (limit.HasFlag(ArmActuatorSlot.Lower)) { add_default(location, ArmActuatorSlot.PartLower); } if (limit.HasFlag(ArmActuatorSlot.Hand)) { add_default(location, ArmActuatorSlot.PartHand); } } } clear_side(ChassisLocations.LeftArm); clear_side(ChassisLocations.RightArm); }
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); }
public void OnItemGrabbed(IMechLabDraggableItem item, MechLabPanel mechLab, MechLabLocationWidget widget) { if (widget.loadout.Location != ChassisLocations.LeftArm && widget.loadout.Location != ChassisLocations.RightArm) { return; } var loc_helper = new LocationHelper(widget); var total_slot = ArmActuatorSlot.None; var mount_loc = widget.loadout.Location; var ml_helper = new MechLabHelper(mechLab); CustomComponents.Control.LogDebug(DType.ComponentInstall, $"- ArmActuator: {Def.Description.Id} {Type}"); void add_default(ArmActuatorSlot slot) { bool add_item(string 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) { DefaultHelper.AddMechLab(id, ComponentType.Upgrade, ml_helper, mount_loc); total_slot = total_slot | actuator.Type; return(true); } return(false); } CustomComponents.Control.LogDebug(DType.ComponentInstall, $"--- adding {slot} to {total_slot}"); if (total_slot.HasFlag(slot)) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"---- already present"); return; } if (add_item(ArmActuatorCC.GetDefaultActuator(mechLab.activeMechDef, mount_loc, slot))) { return; } add_item(ArmActuatorCC.GetDefaultActuator(null, mount_loc, slot)); } for (int i = loc_helper.LocalInventory.Count - 1; i >= 0; i--) { var slotitem = loc_helper.LocalInventory[i]; if (!slotitem.ComponentRef.Is <ArmActuator>()) { continue; } var actuator = slotitem.ComponentRef.GetComponent <ArmActuator>(); if (slotitem.ComponentRef.IsDefault() && !slotitem.ComponentRef.IsModuleFixed(ml_helper.MechLab.activeMechDef)) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- removing {slotitem.ComponentRef.ComponentDefID} {actuator.Type}"); DefaultHelper.RemoveMechLab(slotitem.ComponentRef.ComponentDefID, slotitem.ComponentRef.ComponentDefType, ml_helper, mount_loc); } else { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- checking {slotitem.ComponentRef.ComponentDefID} {actuator.Type}"); total_slot = total_slot | actuator.Type; } } CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- actuators {total_slot}"); add_default(ArmActuatorSlot.PartShoulder); add_default(ArmActuatorSlot.PartUpper); if (ArmActuatorCC.IsIgnoreFullActuators(mechLab.activeMechDef)) { if (total_slot.HasFlag(ArmActuatorSlot.PartHand) && !total_slot.HasFlag(ArmActuatorSlot.PartLower)) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- Removing hand from {total_slot}"); var hand = loc_helper.LocalInventory.FirstOrDefault(i => i.ComponentRef.Is <ArmActuator>(out var actuator) && actuator.Type.HasFlag(ArmActuatorSlot.PartHand)); if (hand == null || hand.ComponentRef.IsFixed) { return; } var dragitem = mechLab.DragItem; widget.OnRemoveItem(hand, false); mechLab.ForceItemDrop(hand); ml_helper.SetDragItem(dragitem as MechLabItemSlotElement); } else { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- hand already removed from {total_slot}"); } } else { var limit = mechLab.activeMechDef.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); } } }