コード例 #1
0
        public void ModifyMech(MechDef mDef, SimGameState s, UpgradeList ulist, ref float canFreeTonns, List <string[]> changedAmmoTypes, MechDef fromData)
        {
            BTRandomMechComponentUpgrader_Init.Log.Log("checking changed ammo types");
            List <MechComponentRef> inv = mDef.Inventory.ToList();

            foreach (string[] ca in changedAmmoTypes)
            {
                AmmunitionBoxDef basebox = GetMainAmmoBox(ca[0], s);
                AmmunitionBoxDef box     = GetMainAmmoBox(ca[1], s);
                if (box == null && basebox == null)
                {
                    BTRandomMechComponentUpgrader_Init.Log.Log($"changing ammo {ca[0]} -> {ca[1]} (both null ???)");
                    continue;
                }
                if (box == null) // removed ammo dependency, remove all ammoboxes as well, tonnagefixer will take care of missing tonnage
                {
                    BTRandomMechComponentUpgrader_Init.Log.Log($"changing ammo {ca[0]} -> {ca[1]} (box null, removing all)");
                    inv.RemoveAll((a) => ca[0].Equals((a.Def as AmmunitionBoxDef)?.AmmoID));
                    continue;
                }
                if (basebox == null) // added ammo dependency, try to add an ammobox
                {
                    TryAddAmmoBox(mDef, ref canFreeTonns, inv, ca, box);
                    continue;
                }
                int   numOldBox = CountAmmoBoxes(inv, ca[0]);
                float or        = (float)GetAmmoTypeUsagePerTurn(inv, ca[0]) / basebox.Capacity;
                float ne        = (float)GetAmmoTypeUsagePerTurn(inv, ca[1]) / box.Capacity;
                if (numOldBox <= 0 || (numOldBox == 1 && or > 0)) // should not happen, but just in case
                {
                    TryAddAmmoBox(mDef, ref canFreeTonns, inv, ca, box);
                    continue;
                }
                float ratio = ne / (or + ne);
                int   swap  = Mathf.RoundToInt(numOldBox * ratio);
                BTRandomMechComponentUpgrader_Init.Log.Log($"changing ammo {ca[0]} -> {ca[1]} (usage {or}/{ne}, changing {swap} boxes)");
                foreach (MechComponentRef r in inv.Where((a) => ca[0].Equals((a.Def as AmmunitionBoxDef)?.AmmoID)))
                {
                    if (swap <= 0)
                    {
                        break;
                    }
                    if (r.CanUpgrade(box, canFreeTonns, mDef, r.MountedLocation, inv))
                    {
                        BTRandomMechComponentUpgrader_Init.Log.Log($"changing ammo {r.Def.Description.Id} -> {box.Description.Id}");
                        r.DoUpgrade(box, ref canFreeTonns);
                        swap--;
                    }
                    else
                    {
                        BTRandomMechComponentUpgrader_Init.Log.Log($"cannot change ammo {r.Def.Description.Id} -> {box.Description.Id}");
                    }
                }
                if (swap > 0)
                {
                    BTRandomMechComponentUpgrader_Init.Log.Log($"missed {swap} changes");
                }
            }
            mDef.SetInventory(inv.ToArray());
        }
コード例 #2
0
ファイル: BTMechDumper.cs プロジェクト: mcb5637/BTMechDumper
        private static DumperDataEntry FillAmmo(AmmunitionBoxDef d)
        {
            DumperDataEntry r = FillComp(d, 1);

            r.DataTxt[4] = d.AmmoID + "/" + d.Capacity;
            r.DataCsv   += ";" + d.AmmoID + ";" + d.Capacity;
            return(r);
        }
コード例 #3
0
 Postfix(AmmunitionBoxDef __instance)
 {
     if (Local.state.getItem("cheat_ammoboxcapacity_infinite") != "")
     {
         Traverse.Create(__instance).Property(
             "Capacity"
             ).SetValue(5000);
     }
 }
コード例 #4
0
 private ListElementControllerCompare(ListElementController_BASE_NotListView item)
 {
     salvageDef   = item.salvageDef;
     componentDef = item.componentDef;
     ammoBoxDef   = item.ammoBoxDef;
     weaponDef    = item.weaponDef;
     mechDef      = item.mechDef;
     chassisDef   = item.chassisDef;
     shopDefItem  = item.shopDefItem;
 }
コード例 #5
0
 public static bool Prefix(AmmunitionBox __instance, ComponentDamageLevel damageLevel, bool applyEffects, WeaponHitInfo hitInfo)
 {
     if (damageLevel == ComponentDamageLevel.Destroyed && applyEffects && __instance.componentDef.CanExplode && __instance.componentDef.ComponentTags.Contains("component_infernoExplosion"))
     {
         if (__instance.parent is Mech m)
         {
             AmmunitionBoxDef b = __instance.componentDef as AmmunitionBoxDef;
             int dmg            = (int)b.Ammo.extDef().HeatDamagePerShot;
             int ammoleft       = __instance.StatCollection.GetValue <int>("CurrentAmmo");
             m.AddExternalHeat("inferno explosion", dmg * ammoleft / 2);
             foreach (EffectData e in b.Ammo.extDef().statusEffects.Where((e) => e.effectType == EffectType.StatisticEffect))
             {
                 m.Combat.EffectManager.CreateEffect(e, e.Description.Id, hitInfo.attackSequenceId, m, m, default, -1, false);
コード例 #6
0
        public TypedShopDefItem(ShopDefItem item)
        {
            try
            {
                Control.LogDebug(DInfo.TypedItemDef, "TypedShopDefItem.ctor");
                this.Count            = item.Count;
                this.ID               = item.ID;
                this.Type             = item.Type;
                this.DiscountModifier = item.DiscountModifier;
                this.Count            = item.Count;
                this.IsInfinite       = item.IsInfinite;
                this.IsDamaged        = item.IsDamaged;
                this.SellCost         = item.SellCost;
                this.SetGuid(item.GUID);
                Control.LogDebug(DInfo.TypedItemDef, "data copied");

                var dm = Control.State.Sim.DataManager;

                switch (item.Type)
                {
                case ShopItemType.Weapon:
                    Control.LogDebug(DInfo.TypedItemDef, "Weapon");
                    WeaponDef weaponDef = null;
                    if (dm.WeaponDefs.Exists(GUID))
                    {
                        weaponDef = dm.WeaponDefs.Get(GUID);
                    }
                    Component   = weaponDef;
                    Description = weaponDef.Description;
                    break;

                case ShopItemType.AmmunitionBox:
                    Control.LogDebug(DInfo.TypedItemDef, "AmmunitionBox");
                    AmmunitionBoxDef ammoboxDef = null;
                    if (dm.AmmoBoxDefs.Exists(GUID))
                    {
                        ammoboxDef = dm.AmmoBoxDefs.Get(GUID);
                    }
                    Component   = ammoboxDef;
                    Description = ammoboxDef.Description;
                    break;

                case ShopItemType.HeatSink:
                    Control.LogDebug(DInfo.TypedItemDef, "HeatSink");
                    HeatSinkDef hsDef = null;
                    if (dm.HeatSinkDefs.Exists(GUID))
                    {
                        hsDef = dm.HeatSinkDefs.Get(GUID);
                    }
                    Component   = hsDef;
                    Description = hsDef.Description;
                    break;

                case ShopItemType.JumpJet:
                    Control.LogDebug(DInfo.TypedItemDef, "JumpJet");
                    JumpJetDef jjDef = null;
                    if (dm.JumpJetDefs.Exists(GUID))
                    {
                        jjDef = dm.JumpJetDefs.Get(GUID);
                    }
                    Component   = jjDef;
                    Description = jjDef.Description;
                    break;

                case ShopItemType.Upgrade:
                    Control.LogDebug(DInfo.TypedItemDef, "Upgrade");
                    UpgradeDef upgradeDef = null;
                    if (dm.UpgradeDefs.Exists(GUID))
                    {
                        upgradeDef = dm.UpgradeDefs.Get(GUID);
                    }
                    Component   = upgradeDef;
                    Description = upgradeDef.Description;
                    break;

                case ShopItemType.MechPart:
                case ShopItemType.Mech:
                    Control.LogDebug(DInfo.TypedItemDef, item.Type.ToString());

                    var id = Control.GetMDefFromCDef(GUID);


                    Control.LogDebug(DInfo.TypedItemDef, $"MechPart/Mech {GUID} {ID} {id}");

                    if (dm.MechDefs.Exists(id))
                    {
                        Mech = dm.MechDefs.Get(id);
                    }
                    else
                    {
                        Control.LogError($"Cannot find Mech for {id}");
                    }

                    Description = Type == ShopItemType.MechPart ? Mech.Description : Mech.Chassis.Description;
                    break;
                }
                Control.LogDebug(DInfo.TypedItemDef, "done");
            }
            catch (Exception e)
            {
                Control.LogError(e);
            }
        }
コード例 #7
0
        // Helper
        internal static bool HasOverrideColor(MechComponentDef mechComponentDef, out Color overrideColor)
        {
            bool result = false;

            overrideColor = Color.red;

            if (mechComponentDef.ComponentType == ComponentType.Weapon)
            {
                WeaponDef weaponDef = mechComponentDef as WeaponDef;

                if (weaponDef.ComponentTags.Contains("component_type_lostech"))
                {
                    if (weaponDef.WeaponCategoryValue.IsBallistic)
                    {
                        overrideColor = ballisticColorLosTech;
                        result        = true;
                    }
                    else if (weaponDef.WeaponCategoryValue.IsMissile)
                    {
                        overrideColor = missileColorLosTech;
                        result        = true;
                    }
                    else if (weaponDef.WeaponCategoryValue.IsEnergy)
                    {
                        overrideColor = energyColorLosTech;
                        result        = true;
                    }
                    else if (weaponDef.WeaponCategoryValue.IsSupport)
                    {
                        overrideColor = supportColorLosTech;
                        result        = true;
                    }
                }
            }
            else if (mechComponentDef.ComponentType == ComponentType.AmmunitionBox)
            {
                AmmunitionBoxDef ammunitionBoxDef = mechComponentDef as AmmunitionBoxDef;

                if (ammunitionBoxDef.ComponentTags.Contains("component_type_lostech"))
                {
                    if (ammunitionBoxDef.AmmoID == "Ammunition_GAUSS" || ammunitionBoxDef.AmmoID == "Ammunition_LB2X" || ammunitionBoxDef.AmmoID == "Ammunition_LB5X" || ammunitionBoxDef.AmmoID == "Ammunition_LB10X" || ammunitionBoxDef.AmmoID == "Ammunition_LB20X")
                    {
                        overrideColor = ballisticColorLosTech;
                        result        = true;
                    }
                    else if (ammunitionBoxDef.AmmoID == "Ammunition_SRMStreak" || ammunitionBoxDef.AmmoID == "Ammunition_Narc")
                    {
                        overrideColor = missileColorLosTech;
                        result        = true;
                    }
                }
            }
            else if (mechComponentDef.ComponentType == ComponentType.HeatSink)
            {
                HeatSinkDef heatSinkDef = mechComponentDef as HeatSinkDef;

                if (heatSinkDef.ComponentTags.Contains("component_type_lostech"))
                {
                    overrideColor = equipmentColorLosTech;
                    result        = true;
                }
            }
            else if (mechComponentDef.ComponentType == ComponentType.Upgrade)
            {
                UpgradeDef upgradeDef = mechComponentDef as UpgradeDef;

                if (upgradeDef.ComponentTags.Contains("component_type_lostech") || upgradeDef.ComponentTags.Contains("component_type_prototype"))
                {
                    overrideColor = equipmentColorLosTech;
                    result        = true;
                }
            }

            if (result)
            {
                Logger.Debug($"[CustomColors.HasOverrideColor] Overriding color for {mechComponentDef.Description.UIName}");
            }

            return(result);
        }
コード例 #8
0
        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;
            }
        }