Example #1
0
        /// <summary>
        ///     Selects a random item from the default inventory layout a vehicle would have. It will also generate a random
        ///     quantity it desires for the item within the bounds of the minimum and maximum quantities.
        /// </summary>
        /// <returns>Returns a randomly created item with random quantity. Returns NULL if anything bad happens.</returns>
        public static SimItem CreateRandomItem()
        {
            // Loop through the inventory and decide which items to give free copies of.
            foreach (var itemPair in DefaultInventory)
            {
                // Determine if we will be making more of this item, if it's the last one then we have to.
                if (GameSimulationApp.Instance.Random.NextBool())
                {
                    continue;
                }

                // Skip certain items that cannot be traded.
                switch (itemPair.Value.Category)
                {
                case Entities.Food:
                case Entities.Clothes:
                case Entities.Ammo:
                case Entities.Wheel:
                case Entities.Axle:
                case Entities.Tongue:
                case Entities.Vehicle:
                case Entities.Animal:
                case Entities.Person:
                {
                    // Create a random number within the range we need to create an item.
                    var amountToMake = itemPair.Value.MaxQuantity / 4;

                    // Check if created amount goes above ceiling.
                    if (amountToMake > itemPair.Value.MaxQuantity)
                    {
                        amountToMake = itemPair.Value.MaxQuantity;
                    }

                    // Check if created amount goes below floor.
                    if (amountToMake <= 0)
                    {
                        amountToMake = 1;
                    }

                    // Add some random amount of the item from one to total amount.
                    var createdAmount = GameSimulationApp.Instance.Random.Next(1, amountToMake);

                    // Create a new item with generated quantity.
                    var createdItem = new SimItem(itemPair.Value, createdAmount);
                    return(createdItem);
                }

                case Entities.Cash:
                case Entities.Location:
                    continue;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            // Default response is to return a NULL item if something terrible happens.
            return(null);
        }
Example #2
0
        /// <summary>
        ///     Creates a prey item from another one as reference.
        /// </summary>
        /// <param name="preyItem">Prey item that should be copied.</param>
        public PreyItem(PreyItem preyItem)
        {
            // Prey specific settings for how long they live on the field.
            Lifetime    = preyItem.Lifetime;
            LifetimeMax = preyItem.LifetimeMax;

            // Prey specific for total length of time they may be targeted.
            TargetTime    = preyItem.TargetTime;
            TargetTimeMax = preyItem.TargetTimeMax;

            // Copy of the animal from the prey item.
            Animal = new SimItem(preyItem.Animal, 1);
        }
Example #3
0
        /// <summary>Initializes a new instance of the <see cref="T:OregonTrailDotNet.Module.Scoring.Points" /> class.</summary>
        /// <param name="resource">The resource.</param>
        /// <param name="optionalDisplayName">The optional Display Name.</param>
        public Points(SimItem resource, string optionalDisplayName = DEFAULT_DISPLAY_NAME)
        {
            // Complain if the per amount is zero, the developer is doing it wrong.
            if (resource.PointsPerAmount <= 0)
            {
                throw new ArgumentException("Per amount is less than zero, default value is one for a reason!");
            }

            // Setup point tabulator basics.
            Resource             = resource;
            PointsAwarded        = resource.PointsAwarded;
            _optionalDisplayName = optionalDisplayName;
            _perAmount           = resource.PointsPerAmount;
        }
Example #4
0
        /// <summary>
        ///     Determines if the vehicles inventory contains the inputted item in the specified quantity.
        /// </summary>
        /// <param name="wantedItem">Item wanted configured with desired quantity.</param>
        /// <returns>TRUE if the vehicle has this item, FALSE if it does not have it or does but not enough quantity for trade.</returns>
        public bool ContainsItem(SimItem wantedItem)
        {
            // Loop through vehicle inventory.
            foreach (var simItem in Inventory)
            {
                if ((simItem.Value.Name == wantedItem.Name) && (simItem.Value.Category == wantedItem.Category) &&
                    (simItem.Value.Quantity >= wantedItem.MinQuantity))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #5
0
        /// <summary>Adds the item to the inventory of the vehicle and subtracts it's cost multiplied by quantity from balance.</summary>
        /// <param name="transaction">The transaction.</param>
        public void Purchase(SimItem transaction)
        {
            // Check of the player can afford this item.
            if (Balance < transaction.TotalValue)
            {
                return;
            }

            // Create new item based on old one, with new quantity value from store, trader, random event, etc.
            Balance -= transaction.TotalValue;

            // Make sure we add the quantity and not just replace it.
            _inventory[transaction.Category].AddQuantity(transaction.Quantity);
        }
Example #6
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:OregonTrailDotNet.Window.Travel.Hunt.PreyItem" /> class.
        /// </summary>
        public PreyItem()
        {
            // Randomly generate a shooting time up to total hunting time.
            Lifetime    = 0;
            LifetimeMax = GameSimulationApp.Instance.Random.Next(HuntManager.HUNTINGTIME);

            // Randomly generate maximum amount of time this animal will be a valid target.
            TargetTime    = 0;
            TargetTimeMax = GameSimulationApp.Instance.Random.Next(HuntManager.MINTARGETINGTIME,
                                                                   HuntManager.MAXTARGETINGTIME);

            // Randomly select a animal for this prey to be from default animals.
            var preyIndex = GameSimulationApp.Instance.Random.Next(HuntManager.DefaultAnimals.Count);

            // Select a random animal that we can be from default animals.
            Animal = new SimItem(HuntManager.DefaultAnimals[preyIndex], 1);
        }
Example #7
0
        /// <summary>Removes an SimItem from the list of pending transactions. If it does not exist then nothing will happen.</summary>
        /// <param name="item">The item.</param>
        public void RemoveItem(SimItem item)
        {
            // Loop through every single transaction.
            var copyList = new Dictionary <Entities, SimItem>(_totalTransactions);

            foreach (var transaction in copyList)
            {
                // Check if SimItem name matches incoming one.
                if (!transaction.Key.Equals(item.Category))
                {
                    continue;
                }

                // Reset the simulation SimItem to default values, meaning the player has none of them.
                _totalTransactions[item.Category].Reset();
                break;
            }
        }
Example #8
0
        /// <summary>
        ///     Fired after the state has been completely attached to the simulation letting the state know it can browse the user
        ///     data and other properties below it.
        /// </summary>
        public override void OnFormPostCreate()
        {
            base.OnFormPostCreate();

            // Figure out what we owe already from other store items, then how many of the SimItem we can afford.
            var currentBalance =
                (int)(GameSimulationApp.Instance.Vehicle.Balance - UserData.Store.TotalTransactionCost);

            _purchaseLimit = (int)(currentBalance / UserData.Store.SelectedItem.Cost);

            // Prevent negative numbers and set credit limit to zero if it drops below that.
            if (_purchaseLimit < 0)
            {
                _purchaseLimit = 0;
            }

            // Set the credit limit to be the carry limit if they player has lots of monies and can buy many, we must limit them!
            if (_purchaseLimit > UserData.Store.SelectedItem.MaxQuantity)
            {
                _purchaseLimit = UserData.Store.SelectedItem.MaxQuantity;
            }

            // Add some information about how many you can buy and total amount you can carry.
            _itemBuyText = new StringBuilder();

            // Change up question asked if plural window matches the name of the SimItem.
            var pluralMatchesName = UserData.Store.SelectedItem.PluralForm.Equals(UserData.Store.SelectedItem.Name,
                                                                                  StringComparison.OrdinalIgnoreCase);

            // Print text about purchasing the selected item.
            _itemBuyText.AppendLine(pluralMatchesName
                ? $"{Environment.NewLine}You can afford {_purchaseLimit} {UserData.Store.SelectedItem.Name.ToLowerInvariant()}."
                : $"{Environment.NewLine}You can afford {_purchaseLimit} {UserData.Store.SelectedItem.PluralForm.ToLowerInvariant()} of {UserData.Store.SelectedItem.Name.ToLowerInvariant()}.");

            // Wait for user input...
            _itemBuyText.Append($"How many {UserData.Store.SelectedItem.PluralForm.ToLowerInvariant()} to buy?");

            // Set the SimItem to buy text.
            _itemToBuy = UserData.Store.SelectedItem;
        }
Example #9
0
 /// <summary>Adds an SimItem to the list of pending transactions. If it already exists it will be replaced.</summary>
 /// <param name="item">The item.</param>
 /// <param name="amount">The amount.</param>
 public void AddItem(SimItem item, int amount)
 {
     _totalTransactions[item.Category] = new SimItem(item, amount);
 }
Example #10
0
 public static ArrayList FindSimilairty()
 {
     ArrayList ar = new ArrayList();
     for (int i = 0; i < models.Length; i++)
     {
         for (int j = i + 1; j < models.Length; j++) // can be easily improved ( by starting from i+1)
         {
             Model mi = models[i];
             Model mj = models[j];
             if (mi.len == -1) continue;
             if (mj.len == -1) continue;
             if (Model.comaprable(models[i], models[j]) == true)
                 if (mi.len > 192)
                 {
                     SimItem sm = new SimItem();
                     sm.id1 = i;
                     sm.id2 = j;
                     sm.sim = sim(models[i], models[j]);
                     sm.len = mi.len;
                     ar.Add(sm);
                     Console.WriteLine("{0}\t{1}\t{2}\t{3}", i, j, sm.sim, sm.len);
                 }
         }
     }
     ar.Sort();
     return ar;
 }