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());
        }
Exemplo n.º 2
0
        public void CheckForAndPerformUpgrade(MechComponentRef r, SimGameState s, UpgradeList l, ref float canFreeTonns, MechDef mech, List <string[]> changedAmmoTypes)
        {
            string baseid = r.Def.Description.Id;

            if (s.NetworkRandom.Float(0f, 1f) > l.UpgradePerComponentChance)
            {
                return;
            }

            string log = baseid;

            UpgradeList.UpgradeEntry ue = l.RollEntryFromMatchingSubList(baseid, s.NetworkRandom, s.CurrentDate, ref log, l.UpgradePerComponentChance);
            if (ue != null)
            {
                MechComponentDef d = s.GetComponentDefFromID(ue.ID);
                if (r.CanUpgrade(d, canFreeTonns, mech, r.MountedLocation, mech.Inventory))
                {
                    CheckChangedAmmo(r.Def, d, changedAmmoTypes);
                    r.DoUpgrade(d, ref canFreeTonns);
                    BTRandomMechComponentUpgrader_Init.Log.Log("changing " + log);
                }
                else
                {
                    BTRandomMechComponentUpgrader_Init.Log.Log("cannot upgrade " + log);
                }
            }
            else
            {
                BTRandomMechComponentUpgrader_Init.Log.Log("upgrade unavailable " + log);
            }
        }