public void ModifyMech(MechDef mDef, SimGameState s, UpgradeList ulist, ref float canFreeTonns, List <string[]> changedAmmoTypes, MechDef fromData) { BTRandomMechComponentUpgrader_Init.Log.Log("checking addition sublists"); List <MechComponentRef> inv = mDef.Inventory.ToList(); foreach (UpgradeList.UpgradeEntry[] l in ulist.Additions) { if (s.NetworkRandom.Float(0f, 1f) < ulist.UpgradePerComponentChance) { string log = ""; UpgradeList.UpgradeEntry ue = ulist.RollEntryFromSubList(l, s.NetworkRandom, -1, s.CurrentDate, ref log, ulist.UpgradePerComponentChance); if (ue != null && !ue.ID.Equals("")) { MechComponentDef d = s.GetComponentDefFromID(ue.ID); ChassisLocations loc = mDef.SearchLocationToAddComponent(d, canFreeTonns, inv, null, ChassisLocations.None); if (loc == ChassisLocations.None) { BTRandomMechComponentUpgrader_Init.Log.Log("cannot add " + log); continue; } BTRandomMechComponentUpgrader_Init.Log.Log($"adding {log} into {loc}"); MechComponentRef r = new MechComponentRef(ue.ID, null, d.ComponentType, loc, -1, ComponentDamageLevel.Functional, false); r.SetComponentDef(d); inv.Add(r); canFreeTonns -= d.Tonnage; } else { BTRandomMechComponentUpgrader_Init.Log.Log("cannot add, nothing rolled " + log); } } } mDef.SetInventory(inv.ToArray()); }
private static void TryAddAmmoBox(MechDef mDef, ref float canFreeTonns, List <MechComponentRef> inv, string[] ca, AmmunitionBoxDef box) { BTRandomMechComponentUpgrader_Init.Log.Log($"changing ammo {ca[0]} -> {ca[1]} (basebox null, try adding one)"); ChassisLocations loc = mDef.SearchLocationToAddComponent(box, canFreeTonns, inv, null, ChassisLocations.None); if (loc != ChassisLocations.None) { BTRandomMechComponentUpgrader_Init.Log.Log($"adding into {loc}"); MechComponentRef r = new MechComponentRef(box.Description.Id, null, box.ComponentType, loc, -1, ComponentDamageLevel.Functional, false); r.SetComponentDef(box); inv.Add(r); canFreeTonns -= box.Tonnage; } }