private static void AddToList(List <HPUsage> list, HPUsage hp)
        {
            var item = list.FirstOrDefault(i => i.WeaponCategoryID == hp.WeaponCategoryID);

            if (item != null)
            {
                item.Total += hp.Total;
            }
            else
            {
                list.Add(new HPUsage(hp));
            }
        }
        public static List <HPUsage> GetHardpointUsage(this MechDef mech, ChassisLocations location, IEnumerable <InvItem> inventory = null)
        {
            if (inventory == null)
            {
                inventory = mech.Inventory.ToInvItems();
            }
            var inv = inventory.ToList();

            var result = mech.GetAllHardpoints(location, inv);

            foreach (var item in inv.Where(i => i.Location == location)
                     .Select(i => i.Item.GetComponent <UseHardpointCustom>())
                     .Where(i => i != null && !i.WeaponCategory.Is_NotSet))
            {
                HPUsage first = null;
                bool    found = false;

                for (int i = 0; i < result.Count; i++)
                {
                    var hp = result[i];

                    if (!hp.hpInfo.CompatibleID.Contains(item.WeaponCategory.ID))
                    {
                        continue;
                    }
                    if (hp.Used < hp.Total)
                    {
                        found    = true;
                        hp.Used += 1;
                    }

                    first ??= hp;
                }

                if (!found)
                {
                    if (first == null)
                    {
                        result.Add(new HPUsage(item.hpInfo, 0, -1));
                    }
                    else
                    {
                        first.Used += 1;
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
 public HPUsage(HPUsage other, bool reset = false)
 {
     this.hpInfo = other.hpInfo;
     this.Total  = other.Total;
     this.Used   = reset ? 0 : other.Used;
 }