public Dictionary <AugmentorType, int> GetAugmentorQuantities() { Dictionary <AugmentorType, int> Result = new Dictionary <AugmentorType, int>(); foreach (AugmentorType Type in Enum.GetValues(typeof(AugmentorType)).Cast <AugmentorType>()) { int Qty = 0; if (Quantities != null) { Quantities.TryGetValue(Type, out Qty); } Result.Add(Type, Qty); } return(Result); }
/// <param name="RemoveFromInventory">True if the given <paramref name="Qty"/> should be removed from the player's inventory.</param> /// <param name="Instance">If <paramref name="RemoveFromInventory"/>=true, this Instance's Stack will be reduced. If not specified, the first instance found in the player's inventory will be reduced.</param> internal void OnAugmentorPlaced(AugmentorType Type, int Qty, bool RemoveFromInventory, Augmentor Instance = null) { int MaxQuantity = MachineAugmentorsMod.UserConfig.GetConfig(Type).MaxAttachmentsPerMachine; int CurrentQty = 0; Quantities.TryGetValue(Type, out CurrentQty); int ActualQtyPlaced = Math.Max(0, Math.Min(MaxQuantity - CurrentQty, Qty)); if (ActualQtyPlaced <= 0) { return; } if (Quantities.ContainsKey(Type)) { Quantities[Type] += ActualQtyPlaced; } else { Quantities.Add(Type, ActualQtyPlaced); } if (RemoveFromInventory) { int PendingRemoval = ActualQtyPlaced; if (Instance != null && Game1.player.Items.Contains(Instance)) { int Amt = Math.Min(Instance.Stack, PendingRemoval); if (Amt == Instance.Stack) { Game1.player.Items[Game1.player.Items.IndexOf(Instance)] = null; } else { Instance.Stack -= Amt; } } else { for (int i = 0; i < Game1.player.Items.Count; i++) { Item Item = Game1.player.Items[i]; if (Item != null && Item is Augmentor Augmentor && Augmentor.AugmentorType == Type) { int Amt = Math.Min(Augmentor.Stack, PendingRemoval); if (Amt == Augmentor.Stack) { Game1.player.Items[i] = null; } else { Item.Stack -= Amt; } PendingRemoval -= Amt; if (PendingRemoval <= 0) { break; } } } } } }