public MechComponentRef GetReplace(MechDef mechDef, SimGameState state) { var res = DefaultHelper.CreateRef(DefID, Type, mechDef.DataManager, state); res.SetData(Location, -1, ComponentDamageLevel.Functional, true); return(res); }
public IEnumerable <IChange> ValidateDropOnAdd(MechLabItemSlotElement item, LocationHelper location, MechLabHelper mechlab, List <IChange> changes) { Control.LogDebug(DType.ComponentInstall, "--- AutoLinked Add"); if (Links == null || Links.Length == 0) { yield break; } foreach (var link in Links) { Control.LogDebug(DType.ComponentInstall, $"---- {link.ComponentDefId} to {link.Location}"); var slot = DefaultHelper.CreateSlot(link.ComponentDefId, link.ComponentDefType ?? Def.ComponentType, mechlab.MechLab); if (slot != null) { Control.LogDebug(DType.ComponentInstall, $"----- added"); yield return(new AddDefaultChange(link.Location, slot)); } else { Control.LogDebug(DType.ComponentInstall, $"----- not found"); } } }
public virtual bool AddItems(MechDef mechDef, SimGameState state) { if (AddIfNotPresent) { DefaultHelper.AddInventory(DefID, mechDef, Location, Type, state); return(true); } return(false); }
public void RemoveLinked(IMechLabDraggableItem item, MechLabPanel mechLab) { var helper = new MechLabHelper(mechLab); foreach (var r_link in Links) { Control.LogDebug(DType.ComponentInstall, $"{r_link.ComponentDefId} from {r_link.Location}"); DefaultHelper.RemoveMechLab(r_link.ComponentDefId, r_link.ComponentDefType ?? Def.ComponentType, helper, r_link.Location); } }
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 void OnItemGrabbed(IMechLabDraggableItem item, MechLabPanel mechLab, MechLabLocationWidget widget) { Control.LogDebug(DType.ComponentInstall, $"- AutoReplace"); Control.LogDebug(DType.ComponentInstall, $"-- search replace for {item.ComponentRef.ComponentDefID}"); if (string.IsNullOrEmpty(ComponentDefId)) { Control.LogDebug(DType.ComponentInstall, $"-- no replacement, skipping"); return; } Control.LogDebug(DType.ComponentInstall, $"-- {widget}"); var location = Location == ChassisLocations.None ? widget.loadout.Location : Location; DefaultHelper.AddMechLab(ComponentDefId, Def.ComponentType, new MechLabHelper(mechLab), location); Control.LogDebug(DType.ComponentInstall, $"-- added {ComponentDefId} to {location}"); mechLab.ValidateLoadout(false); }
public void OnItemGrabbed(IMechLabDraggableItem item, MechLabPanel mechLab, MechLabLocationWidget widget) { Control.LogDebug(DType.ComponentInstall, $"- Category {CategoryID}"); Control.LogDebug(DType.ComponentInstall, $"-- search replace for {item.ComponentRef.ComponentDefID}"); var replace = DefaultFixer.Shared.GetReplaceFor(mechLab.activeMechDef, CategoryID, widget.loadout.Location, mechLab.sim); if (replace == null) { Control.LogDebug(DType.ComponentInstall, $"-- no replacement, skipping"); return; } DefaultHelper.AddMechLab(replace, new MechLabHelper(mechLab)); Control.LogDebug(DType.ComponentInstall, $"-- added {replace.ComponentDefID} to {replace.MountedLocation}"); mechLab.ValidateLoadout(false); }
private static List <WeaponDefaultRecord> BuildWeaponDefaults(ChassisDef chassis) { var components = GetWeaponDefaultComponents(chassis).ToList(); if (components.Count == 0) { return(null); } var result = new List <WeaponDefaultRecord>(); foreach (var weaponDefault in components) { var def = DefaultHelper.GetComponentDef(weaponDefault.DefID, weaponDefault.Type); if (def == null) { Control.LogError($"Unknown weapon default {weaponDefault.DefID}/{weaponDefault.Type}"); continue; } if (!def.IsDefault()) { Control.LogError($"Weapon default {weaponDefault.DefID} is not default"); continue; } var wc = def.GetWeaponCategory(); if (wc == null || wc.Is_NotSet) { Control.LogError($"Weapon default {weaponDefault.DefID} not a weapon/UseHardpoint"); continue; } var rec = new WeaponDefaultRecord() { WeaponCategory = wc, Def = def, Categories = weaponDefault.ReplaceCategories?.ToHashSet(), Location = weaponDefault.Location }; result.Add(rec); } return(result.Count > 0 ? result : null); }
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); } } }
public IEnumerable <IChange> ValidateDropOnRemove(MechLabItemSlotElement item, LocationHelper location, MechLabHelper mechlab, List <IChange> changes) { var replace = DefaultFixer.Shared.GetReplaceFor(mechlab.MechLab.activeMechDef, CategoryID, item.MountedLocation, mechlab.MechLab.sim); if (replace == null) { Control.LogDebug(DType.ComponentInstall, $"--- Category {CategoryID} - no replace, return"); yield break; } foreach (var addChange in changes.OfType <AddChange>()) { if (addChange.item.ComponentRef.IsCategory(CategoryID)) { Control.LogDebug(DType.ComponentInstall, $"--- Category {CategoryID} - replace already added"); yield break; } } Control.LogDebug(DType.ComponentInstall, $"--- Category {CategoryID} - add replace {replace.ComponentDefID}"); yield return(new AddDefaultChange(replace.MountedLocation, DefaultHelper.CreateSlot(replace, mechlab.MechLab))); }
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); } }
public bool AddItems(MechDef mechDef, SimGameState state) { DefaultHelper.AddInventory(DefID, mechDef, Location, Type, state); return(true); }