/// <summary> /// Initializes a new instance of the <see cref="SimItem" /> class. /// Creates a new SimItem from previous instance and with updated quantity. /// </summary> /// <param name="oldItem">Old SimItem that is going to be replaced.</param> /// <param name="newQuantity">Updated quantity the new SimItem will have.</param> public SimItem(SimItem oldItem, int newQuantity) { // Check that new quantity is greater than ceiling. if (newQuantity > oldItem.MaxQuantity) newQuantity = oldItem.MaxQuantity; // Check that new quantity is not less than floor. if (newQuantity < oldItem.MinQuantity) newQuantity = oldItem.MinQuantity; // Set updated quantity values, plus ceiling and floor. Quantity = newQuantity; MinQuantity = oldItem.MinQuantity; MaxQuantity = oldItem.MaxQuantity; StartingQuantity = oldItem.StartingQuantity; // Scoring information for points tabulation if player wins the game. PointsPerAmount = oldItem.PointsPerAmount; PointsAwarded = oldItem.PointsAwarded; // Ensure the values for points per amount are not zero. if (PointsPerAmount <= 0) PointsPerAmount = 1; // Display name and SimItem entity type. Name = oldItem.Name; Category = oldItem.Category; Cost = oldItem.Cost; DelineatingUnit = oldItem.DelineatingUnit; PluralForm = oldItem.PluralForm; Weight = oldItem.Weight; }
/// <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); }
/// <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); }
/// <summary> /// Initializes a new instance of the <see cref="SimItem" /> class. /// Creates a new SimItem from previous instance and with updated quantity. /// </summary> /// <param name="oldItem">Old SimItem that is going to be replaced.</param> /// <param name="newQuantity">Updated quantity the new SimItem will have.</param> public SimItem(SimItem oldItem, int newQuantity) { // Check that new quantity is greater than ceiling. if (newQuantity > oldItem.MaxQuantity) { newQuantity = oldItem.MaxQuantity; } // Check that new quantity is not less than floor. if (newQuantity < oldItem.MinQuantity) { newQuantity = oldItem.MinQuantity; } // Set updated quantity values, plus ceiling and floor. Quantity = newQuantity; MinQuantity = oldItem.MinQuantity; MaxQuantity = oldItem.MaxQuantity; StartingQuantity = oldItem.StartingQuantity; // Scoring information for points tabulation if player wins the game. PointsPerAmount = oldItem.PointsPerAmount; PointsAwarded = oldItem.PointsAwarded; // Ensure the values for points per amount are not zero. if (PointsPerAmount <= 0) { PointsPerAmount = 1; } // Display name and SimItem entity type. Name = oldItem.Name; Category = oldItem.Category; Cost = oldItem.Cost; DelineatingUnit = oldItem.DelineatingUnit; PluralForm = oldItem.PluralForm; Weight = oldItem.Weight; }
/// <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); }
/// <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; }
/// <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; }
/// <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; } }
/// <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); }