示例#1
0
            /// <summary>
            /// Add a quantity
            /// </summary>
            public void AddQuantity(TrajectoryQuantity q)
            {
                var lastIdx          = Quantities.Count;
                var nOccurancesDelta = q.IsTransition ? 0 : -1;

                TotalTrajectorySize += (Program.Cfg.NSteps + nOccurancesDelta) * q.Length;
                SingleStepSize      += q.Length;

                q.Index = lastIdx;
                if (lastIdx > 0)
                {
                    q.Offset = Quantities.Last().Offset + Quantities.Last().Length;
                }
                else
                {
                    q.Offset = 1;
                }

                if (lastIdx > 0 && Quantities.Last().IsTransition)
                {
                    // Transitions must be added to the end
                    Debug.Assert(q.IsTransition);
                }
                else if (q.IsTransition)
                {
                    // The first transition
                    StateQuantityCount = lastIdx;
                    StateQuantitySize  = q.Offset - 1;
                }
                Quantities.Add(q);
            }
示例#2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="proxy">XML proxy.</param>
        /// <exception cref="XNeut.InvalidMessageException">Thrown if an error is encountered.</exception>
        internal MaterialRequirement(XsdNs.MaterialRequirementType proxy)
            : this() // Call the default constructor
        {
            if (proxy.MaterialDefinitionID != null)
            {
                foreach (var idProxy in proxy.MaterialDefinitionID)
                {
                    MaterialDefinitionIdentifiers.Add(new IdentifierType(idProxy)); // throws InvalidMessageException
                }
            }

            if (proxy.MaterialLotID != null)
            {
                foreach (var idProxy in proxy.MaterialLotID)
                {
                    MaterialLotIdentifiers.Add(new IdentifierType(idProxy)); // throws InvalidMessageException
                }
            }

            if (proxy.MaterialUse != null)
            {
                MaterialUse = new MaterialUse(proxy.MaterialUse); // throws InvalidMessageException
            }

            if (proxy.Quantity != null)
            {
                foreach (var qItem in proxy.Quantity)
                {
                    Quantities.Add(new QuantityValue(qItem)); // throws InvalidMessageException
                }
            }

            if (proxy.AssemblyRequirement != null)
            {
                foreach (var arItem in proxy.AssemblyRequirement)
                {
                    AssemblyRequirements.Add(new MaterialRequirement(arItem)); // throws InvalidMessageException
                }
            }
        }
        /// <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;
                            }
                        }
                    }
                }
            }
        }