Exemplo n.º 1
0
        public int GetTotalQuantity(OperationGroups operation)
        {
            if (!Quantities.ContainsKey(operation))
            {
                return(0);
            }

            return(Quantities[operation].Values.Sum());
        }
Exemplo n.º 2
0
        public double GetSpeedQuantityPerHour(OperationGroups operation)
        {
            if (!Quantities.ContainsKey(operation))
            {
                return(0.0);
            }

            return(Quantities[operation].Values.Sum() / OperationTimes[operation].TotalHours);
        }
        /// <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;
                            }
                        }
                    }
                }
            }
        }