public float GetRealAffixCost(ThingWithComps thing = null) { if (thing == null) { return(affixCost); } // This can be called quite a few times, so cache the value string keyThing = thing.ToString(); if (affixCostCache.ContainsKey(keyThing)) { return(affixCostCache[keyThing]); } var affixCostModifier = modifiers.FirstOrFallback(lam => lam.dynamicAffixCost); if (affixCostModifier == null) { return(affixCostCache[keyThing] = affixCost); } return(affixCostCache[keyThing] = affixCostModifier.GetNewAffixCost(thing, affixCost)); }
/// <summary> /// Attempts to equip a weapon from the inventory, puts currently equipped weapon into inventory if it exists /// </summary> /// <param name="useFists">Whether to put the currently equipped weapon away even if no replacement is found</param> public void SwitchToNextViableWeapon(bool useFists = true) { ThingWithComps newEq = null; // Stop current job if (parentPawn.jobs != null) { parentPawn.jobs.StopAll(); } // Cycle through available ranged weapons foreach (ThingWithComps gun in rangedWeaponListCached) { if (parentPawn.equipment != null && parentPawn.equipment.Primary != gun) { CompAmmoUser compAmmo = gun.TryGetComp <CompAmmoUser>(); if (compAmmo == null || compAmmo.HasAndUsesAmmoOrMagazine) { newEq = gun; break; } } } // If no ranged weapon was found, use first available melee weapons if (newEq == null) { newEq = meleeWeaponListCached.FirstOrDefault(); } // Equip the weapon if (newEq != null) { TrySwitchToWeapon(newEq); } else if (useFists) { // Put away current weapon ThingWithComps eq = parentPawn.equipment?.Primary; if (eq != null && !parentPawn.equipment.TryTransferEquipmentToContainer(eq, container)) { // If we can't put it into our inventory, drop it if (parentPawn.Position.InBounds(parentPawn.Map)) { ThingWithComps unused; parentPawn.equipment.TryDropEquipment(eq, out unused, parentPawn.Position); } else { #if DEBUG Log.Warning("CE :: CompInventory :: SwitchToNextViableWeapon :: destroying out of bounds equipment" + eq.ToString()); #endif if (!eq.Destroyed) { eq.Destroy(); } } } } }