public async Task <ActionResult> Edit(int id, [Bind("CareLevel,Temperment,WaterType,Colours,WaterConditions,MaxSize,ProductCode,Name,Description,Stock,Price,ImageFile,ImageName")] Livestock live) { if (id != live.ProductCode) { return(NotFound()); } if (ModelState.IsValid) { try { var titleIn = "\"" + live.Name + "\" has been updated succesfully!"; db.Update(live); await db.SaveChangesAsync(); Notify("Data saved successfully", title: titleIn, notificationType: NotificationType.success); } catch (DbUpdateConcurrencyException) { if (!LivestockExists(live.ProductCode)) { var titleIn = "\"" + live.Name + "\" could not be updated!"; Notify("Could not update data!", title: titleIn, notificationType: NotificationType.error); return(RedirectToAction(nameof(EditIndex))); } else { throw; } } return(RedirectToAction(nameof(EditIndex))); } return(View(live)); }
public async Task <ActionResult> Create([Bind("CareLevel,Temperment,WaterType,Colours,WaterConditions,MaxSize,ProductCode,Name,Description,Stock,Price,ImageFile")] Livestock newLivestock) { if (ModelState.IsValid) { string wwwRootPath = _hostEnvironment.WebRootPath; string filename = Path.GetFileNameWithoutExtension(newLivestock.ImageFile.FileName); string extension = Path.GetExtension(newLivestock.ImageFile.FileName); newLivestock.ImageName = filename = filename + DateTime.Now.ToString("yymmssfff") + extension; string path = Path.Combine(wwwRootPath + "/images/", filename); using (var filestream = new FileStream(path, FileMode.Create)) { await newLivestock.ImageFile.CopyToAsync(filestream); } db.Livestocks.Add(newLivestock); db.SaveChanges(); Notify("Product creation successful!", title: newLivestock.Name + " has been added to the system!", notificationType: NotificationType.success); return(View("Index", db.Livestocks)); } else { Notify("Please try again or contact your system admin!", title: newLivestock.Name + " could not be added to the system!", notificationType: NotificationType.error); return(View("Index", db.Livestocks)); } }
public async Task <IActionResult> Check(int id, string productType) { if (order1.ContactNo == null) { return(RedirectToAction("Create")); } else { if (productType == "Livestock") { Livestock liveFound = await db.Livestocks.FirstOrDefaultAsync(p => p.ProductCode == id); order1.AddLivestock(liveFound); string msg = liveFound.Name + " added to order!"; Notify(msg, notificationType: NotificationType.success, provider: "toastr", title: "Success"); return(RedirectToAction("Index", "Livestock")); } else if (productType == "Equipment") { Equipment equipFound = await db.Equipments.FirstOrDefaultAsync(p => p.ProductCode == id); order1.AddEquipment(equipFound); string msg = equipFound.Name + " added to order!"; Notify(msg, notificationType: NotificationType.success, provider: "toastr", title: "Success"); return(RedirectToAction("Index", "Equipment")); } else { Notify("Unable to add to order!", notificationType: NotificationType.error, provider: "toastr", title: "Error"); return(RedirectToAction("Index", "Home")); } } }
public static List <Livestock> AnimalLoad() { List <Livestock> animals = new List <Livestock>(); string csv = Encrypt.Decode(_animalfilename); var lines = csv.Split("\n"); bool flg = false; foreach (var line in lines) { //1行目はカラム名なので捨てる if (!flg) { flg = true; } else { var str = line.Split(","); if (str.Length == 4) { Livestock animal = new Livestock() { id = int.Parse(str[0]), name = str[1], cost = int.Parse(str[2]), product = int.Parse(str[3]) }; animals.Add(animal); } } } return(animals); }
public ActionResult AddLivestock(LivestockViewModel model) { if (ModelState.IsValid) { try { // TODO: Add insert logic here var Livestock = new Livestock { Name = model.Name, PhotoPath = "upload.png", Description = model.Description, DateCreated = DateTime.Now, }; Livestock = LivestockService.Create(Livestock); if (Livestock != null) { SaveLivestockImage(Livestock); } return(RedirectToAction("Index", "Farm")); } catch { return(View()); } } return(View()); }
public void SaveLivestockImage(Livestock Livestock) { if (Request.Files.Count > 0) { int fileCount = Request.Files.Count; for (int i = 0; i < fileCount; i++) { var file = Request.Files[i]; if (file.ContentLength == 0) { break; } var fileName = Livestock.Id.ToString() + "_" + i.ToString() + "_" + Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/LivestockProfile"), fileName); try { file.SaveAs(path); Livestock.PhotoPath = fileName; LivestockService.Update(Livestock); } catch (Exception) { } } } }
public ActionResult DeleteConfirmed(int id) { Livestock livestock = db.Livestocks.Find(id); db.Livestocks.Remove(livestock); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "LivestockId,livestockName")] Livestock livestock) { if (ModelState.IsValid) { db.Entry(livestock).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(livestock)); }
public ActionResult Create([Bind(Include = "LivestockId,livestockName")] Livestock livestock) { if (ModelState.IsValid) { db.Livestocks.Add(livestock); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(livestock)); }
// GET: Livestocks/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Livestock livestock = db.Livestocks.Find(id); if (livestock == null) { return(HttpNotFound()); } return(View(livestock)); }
// GET: LivestockController/Edit/5 public async Task <IActionResult> Edit(int id) { if (id == 0) { return(NotFound()); } Livestock live = await db.Livestocks.FindAsync(id); if (live == null) { return(NotFound()); } return(View(live)); }
// GET: LivestockController/Details/5 public ActionResult Details(int id, string json) { Livestock foundLivestock = db.Livestocks.FirstOrDefault(p => p.ProductCode == id); if (foundLivestock != null) { if (json == "yes") { return(Ok(foundLivestock)); } return(View(foundLivestock)); } else { return(NotFound("No livestock found with product code: " + id + "\nIf this is new livestock please add it to the system.")); } }
public async Task <ActionResult> AddStock(int id, int stock) { if (stock < 1) { Notify("Stock addition unsuccessful!", title: "Stock to add must be greater than 0!", notificationType: NotificationType.error); return(View("EditIndex", db.Livestocks)); } Livestock live = db.Livestocks.FirstOrDefault(p => p.ProductCode == id); db.Livestocks.Attach(live); live.Stock += stock; db.Entry(live).Property(x => x.Stock).IsModified = true; await db.SaveChangesAsync(); Notify("Stock addition successful!", title: stock + " " + live.Name + " have been added to the stock!", notificationType: NotificationType.success); return(View("EditIndex", db.Livestocks)); }
public ActionResult Add(Livestock livestock, HttpPostedFileBase file) { livestock.CreatorID = User.Identity.GetUserId <int>(); livestock.CreationDate = DateTime.UtcNow; if (DB.Livestocks.Any(c => c.Name.Contains(livestock.Name))) { ModelState.AddModelError(nameof(livestock.Name), "The livestock already exists"); } if (ModelState.IsValid) { DB.Livestocks.Add(livestock); DB.SaveChanges(); return(RedirectToAction(nameof(Details), new { livestock.ID })); } ViewBag.categories = new SelectList(DB.LivestockCategories.OrderBy(c => c.Name), nameof(LivestockCategory.ID), nameof(LivestockCategory.Name), livestock.CategoryID); ViewBag.parents = new SelectList(DB.Livestocks.OrderBy(c => c.Name), nameof(Livestock.ID), nameof(Livestock.Name), livestock.ParentID); ViewBag.courses = new SelectList(DB.Courses.OrderBy(c => c.Name), nameof(Course.ID), nameof(Course.Name), livestock.CourseID); ViewBag.Title = "Add a livestock"; return(View(livestock)); }
public async Task <ActionResult> PlaceOrder() { if (order1.livestockList.Count > 0) { order1.OrderDetails += "|| Livestock Items " + Environment.NewLine; } foreach (CartLivestock l in order1.livestockList) { Livestock updateStock = await db.Livestocks.FirstOrDefaultAsync(p => p.ProductCode == l.ProductCode); updateStock.Stock -= l.Stock; order1.OrderDetails += " -- Product Code: " + l.ProductCode + ", Name: " + l.Name + ", Qty: " + l.Stock + Environment.NewLine; } if (order1.equipmentList.Count > 0) { order1.OrderDetails += " || Equipment Items " + Environment.NewLine; } foreach (CartEquipment e in order1.equipmentList) { Equipment updateStock = await db.Equipments.FirstOrDefaultAsync(p => p.ProductCode == e.ProductCode); updateStock.Stock -= e.Stock; order1.OrderDetails += " -- Product Code: " + e.ProductCode + ", Name: " + e.Name + ", Qty: " + e.Stock + Environment.NewLine; } order1.Date = DateTime.Now; await db.Orders.AddAsync(order1); await db.SaveChangesAsync(); var titleIn = "Your order is now placed!"; Notify(message: "", title: titleIn, notificationType: NotificationType.success); order1.ContactNo = null; List <Order> findAllOrders = await db.Orders.ToListAsync(); Order lastOrder = findAllOrders.Last(); return(RedirectToAction("Details", lastOrder)); }
//Async Methods public static async Task GetProductDetail(int ProductCode, string ProductType) { HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://bluefininc.azurewebsites.net/"); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); if (ProductType == "Equipment") { HttpResponseMessage response = await client.GetAsync("Equipment/Details/" + ProductCode + "?json=yes"); if (response.IsSuccessStatusCode) { Equipment equipFound = await response.Content.ReadAsAsync <Equipment>(); Console.WriteLine(equipFound.ToString()); } else { Console.WriteLine(response.StatusCode + "\nReasonPhrase: " + response.ReasonPhrase + "\n"); } } else { HttpResponseMessage response = await client.GetAsync("Livestock/Details/" + ProductCode + "?json=yes"); if (response.IsSuccessStatusCode) { Livestock liveFound = await response.Content.ReadAsAsync <Livestock>(); Console.WriteLine(liveFound.ToString()); } else { Console.WriteLine(response.StatusCode + "\nReasonPhrase: " + response.ReasonPhrase + "\n"); } } }
public FarmAnimalType(Livestock livestock) { Type = livestock.ToString(); DeluxeProduceLuck = livestock.DeluxeProduceLuck; }
private void AddWaterOrFood() { int selectedTerrainIndex = map.getTerrainIndex(player.Terrains, true); if (selectedTerrainIndex == -1) { Console.WriteLine("Opción no valida..."); } else { Terrain selectedTerrain = map.Terrains[selectedTerrainIndex]; int playerTerrainIndex = player.Terrains.IndexOf(selectedTerrain); Terrain terrain = player.Terrains[playerTerrainIndex]; if (!terrain.HasBuilding()) { Console.WriteLine("No tienes un edificio en este terreno..."); } else { Building terrainBuilding = terrain.Building; if (terrainBuilding.GetType() == typeof(Plantation)) { Plantation plantationBuilding = terrainBuilding as Plantation; List <Consumable> availableConsumables = new List <Consumable>(); bool hasAvailableConsumables = false; while (!hasAvailableConsumables) { availableConsumables = player.GetAvailableConsumables(new List <string> { "Irrigation", "Fertilizer" }); string option = CheckIfCanAddConsumableToTerrain(availableConsumables); if (option == "out") { return; } else if (option == "continue") { hasAvailableConsumables = true; } } Console.WriteLine("Elige uno de los productos disponibles:"); for (int i = 0; i < availableConsumables.Count; i++) { Console.WriteLine($"({i + 1}) - {availableConsumables[i].Name}"); } int userOption = Int32.Parse(Console.ReadLine()); if (userOption < 1 || userOption > availableConsumables.Count) { Console.WriteLine("Opción no valida..."); return; } Consumable selectedConsumable = availableConsumables[userOption - 1]; if (selectedConsumable.GetType() == typeof(Irrigation)) { Irrigation irrigationConsumable = selectedConsumable as Irrigation; plantationBuilding.Water += irrigationConsumable.QuantityAdded; Console.WriteLine($"Se agrego riego correctamente. Nuevo nivel de agua: {plantationBuilding.Water}"); } else if (selectedConsumable.GetType() == typeof(Fertilizer)) { Fertilizer fertilizerConsumable = selectedConsumable as Fertilizer; plantationBuilding.Nutrients += fertilizerConsumable.QuantityAdded; Console.WriteLine($"Se agrego fertilizante correctamente. Nuevo nivel de nutrientes: {plantationBuilding.Nutrients}"); } else { return; } int indexOfConsumable = player.consumables.IndexOf(selectedConsumable); player.consumables.RemoveAt(indexOfConsumable); } else if (terrainBuilding.GetType() == typeof(Livestock)) { Livestock liveStockBuilding = terrainBuilding as Livestock; List <Consumable> availableConsumables = new List <Consumable>(); bool hasAvailableConsumables = false; while (!hasAvailableConsumables) { availableConsumables = player.GetAvailableConsumables(new List <string> { "AnimalFood", "AnimalWater" }); string option = CheckIfCanAddConsumableToTerrain(availableConsumables); if (option == "out") { return; } else if (option == "continue") { hasAvailableConsumables = true; } } Console.WriteLine("Elige uno de los productos disponibles:"); for (int i = 0; i < availableConsumables.Count; i++) { Console.WriteLine($"({i + 1}) - {availableConsumables[i].Name}"); } int userOption = Int32.Parse(Console.ReadLine()); if (userOption < 1 || userOption > availableConsumables.Count) { Console.WriteLine("Opción no valida..."); return; } Consumable selectedConsumable = availableConsumables[userOption - 1]; if (selectedConsumable.GetType() == typeof(AnimalWater)) { AnimalWater animalWaterConsumable = selectedConsumable as AnimalWater; liveStockBuilding.Water += animalWaterConsumable.QuantityAdded; Console.WriteLine($"Se agrego agua correctamente. Nuevo nivel de agua: {liveStockBuilding.Water}"); } else if (selectedConsumable.GetType() == typeof(AnimalFood)) { AnimalFood animalFoodConsumable = selectedConsumable as AnimalFood; liveStockBuilding.Food += animalFoodConsumable.QuantityAdded; Console.WriteLine($"Se agrego comida correctamente. Nuevo nivel de nutrientes: {liveStockBuilding.Food}"); } else { return; } int indexOfConsumable = player.consumables.IndexOf(selectedConsumable); player.consumables.RemoveAt(indexOfConsumable); } else { return; } } } }
public void ApplyCure() { int selectedTerrainIndex = map.getTerrainIndex(player.Terrains, true); if (selectedTerrainIndex == -1) { Console.WriteLine("Opción no valida..."); } else { Terrain selectedTerrain = map.Terrains[selectedTerrainIndex]; int playerTerrainIndex = player.Terrains.IndexOf(selectedTerrain); Terrain terrain = player.Terrains[playerTerrainIndex]; if (!terrain.HasBuilding()) { Console.WriteLine("No tienes un edificio en este terreno..."); } else { Building terrainBuilding = terrain.Building; if (terrainBuilding.GetType() == typeof(Plantation)) { Plantation plantationBuilding = terrainBuilding as Plantation; List <Consumable> availableConsumables = new List <Consumable>(); bool hasAvailableConsumables = false; while (!hasAvailableConsumables) { availableConsumables = player.GetAvailableConsumables(new List <string> { "Herbicide", "Pesticide", "Fungicide" }); string option = CheckIfCanAddConsumableToTerrain(availableConsumables); if (option == "out") { return; } else if (option == "continue") { hasAvailableConsumables = true; } } Console.WriteLine("Elige uno de los productos disponibles:"); for (int i = 0; i < availableConsumables.Count; i++) { Console.WriteLine($"({i + 1}) - {availableConsumables[i].Name}"); } int userOption = Int32.Parse(Console.ReadLine()); if (userOption < 1 || userOption > availableConsumables.Count) { Console.WriteLine("Opción no valida..."); return; } Consumable selectedConsumable = availableConsumables[userOption - 1]; if (selectedConsumable.GetType() == typeof(Herbicide)) { Herbicide herbicideConsumable = selectedConsumable as Herbicide; if (herbicideConsumable.CheckSuccess()) { plantationBuilding.HasUndergrowth = false; Console.WriteLine($"Herbicida funciono."); } else { Console.WriteLine($"Herbicida no funciono."); } } else if (selectedConsumable.GetType() == typeof(Pesticide)) { Pesticide pesticideConsumable = selectedConsumable as Pesticide; if (pesticideConsumable.CheckSuccess()) { plantationBuilding.HasWorms = false; Console.WriteLine($"Pesticida funciono."); } else { Console.WriteLine($"Pesticida no funciono."); } } else if (selectedConsumable.GetType() == typeof(Fungicide)) { Fungicide fungicideConsumable = selectedConsumable as Fungicide; if (fungicideConsumable.CheckSuccess()) { plantationBuilding.Sick = false; Console.WriteLine($"Fungicida funciono."); } else { Console.WriteLine($"Fungicida no funciono."); } } else { return; } int indexOfConsumable = player.consumables.IndexOf(selectedConsumable); player.consumables.RemoveAt(indexOfConsumable); } else if (terrainBuilding.GetType() == typeof(Livestock)) { Livestock liveStockBuilding = terrainBuilding as Livestock; List <Consumable> availableConsumables = new List <Consumable>(); bool hasAvailableConsumables = false; while (!hasAvailableConsumables) { availableConsumables = player.GetAvailableConsumables(new List <string> { "Vaccine" }); string option = CheckIfCanAddConsumableToTerrain(availableConsumables); if (option == "out") { return; } else if (option == "continue") { hasAvailableConsumables = true; } } Console.WriteLine("Elige uno de los productos disponibles:"); for (int i = 0; i < availableConsumables.Count; i++) { Console.WriteLine($"({i + 1}) - {availableConsumables[i].Name}"); } int userOption = Int32.Parse(Console.ReadLine()); if (userOption < 1 || userOption > availableConsumables.Count) { Console.WriteLine("Opción no valida..."); return; } Consumable selectedConsumable = availableConsumables[userOption - 1]; if (selectedConsumable.GetType() == typeof(Vaccine)) { Vaccine vaccineConsumable = selectedConsumable as Vaccine; if (vaccineConsumable.CheckSuccess()) { liveStockBuilding.Sick = false; Console.WriteLine($"Vacuna funciono."); } else { Console.WriteLine($"Vacuna no funciono."); } } else { return; } int indexOfConsumable = player.consumables.IndexOf(selectedConsumable); player.consumables.RemoveAt(indexOfConsumable); } else { return; } } } }
private void GetFinishedProduct() { List <Building> finishedBuildings = new List <Building>(); List <StorageBuilding> storageBuildings = new List <StorageBuilding>(); foreach (Building building in player.buildings) { if (building.GetType() == typeof(Plantation)) { Plantation plantationBuilding = building as Plantation; if (plantationBuilding.Maturity >= plantationBuilding.Seed.ProductionTime) { finishedBuildings.Add(plantationBuilding); } } else if (building.GetType() == typeof(Livestock)) { Livestock livestockBuilding = building as Livestock; if (livestockBuilding.Maturity >= livestockBuilding.Animal.ProductionTime) { finishedBuildings.Add(livestockBuilding); } } else if (building.GetType() == typeof(StorageBuilding)) { StorageBuilding storageBuilding = building as StorageBuilding; if (!storageBuilding.IsFull()) { storageBuildings.Add(storageBuilding); } } } if (finishedBuildings.Count == 0) { Console.WriteLine("No tienes ningun producto terminado."); } else { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Elige uno de los productos disponibles:"); for (int i = 0; i < finishedBuildings.Count; i++) { Console.WriteLine($"({i + 1}) - {finishedBuildings[i].Name}"); } Console.ResetColor(); int userOption = Int32.Parse(Console.ReadLine()); if (userOption < 1 || userOption > finishedBuildings.Count) { Console.WriteLine("Opción no valida..."); return; } Building finishedBuilding = finishedBuildings[userOption - 1]; if (finishedBuilding.GetType() == typeof(Plantation)) { Plantation plantationBuilding = finishedBuilding as Plantation; double terrainQuality = 0; int fieldBlocks = 0; foreach (Terrain terrain in map.Terrains) { if (terrain.Building == plantationBuilding) { foreach (Block block in terrain.Blocks) { if (block.GetType() == typeof(FieldBlock)) { FieldBlock fieldBlock = block as FieldBlock; fieldBlocks += 1; terrainQuality += fieldBlock.Quality; } } break; } } int seedPrice = market.GetPriceOfSeed(plantationBuilding.Seed); terrainQuality = terrainQuality / fieldBlocks; double terrainProportion = fieldBlocks / 100; double price = plantationBuilding.Health * terrainQuality * terrainProportion; int finalPrice = Convert.ToInt32(price) * seedPrice; if (storageBuildings.Count == 0) { player.Money += finalPrice; Console.WriteLine($"Plantación vendida a {finalPrice}"); } else { Console.WriteLine("Elige uno de las bodegas disponibles:"); for (int i = 0; i < storageBuildings.Count; i++) { Console.WriteLine($"({i + 1}) - {storageBuildings[i].Name}"); } int storageUserOption = Int32.Parse(Console.ReadLine()); if (storageUserOption < 1 || storageUserOption > storageBuildings.Count) { Console.WriteLine("Opción no valida..."); return; } Building storageBuilding = storageBuildings[userOption - 1]; int storageBuildingIndex = player.Buildings.IndexOf(storageBuilding); StorageBuilding userStorageBuilding = player.Buildings[storageBuildingIndex] as StorageBuilding; FinishedProduct finishedProduct = new FinishedProduct(plantationBuilding.Seed.Name, finalPrice, seedPrice, plantationBuilding.Seed.WaterConsume, plantationBuilding.Seed.MinimumWaterLevel, plantationBuilding.Seed.PenaltyForLackOfWater, plantationBuilding.Seed.ProductionTime, plantationBuilding.Seed.ProbabilityOfIllness, plantationBuilding.Seed.PenaltyForIllness, Convert.ToInt32(terrainQuality)); userStorageBuilding.AddFinishedProduct(finishedProduct); Console.WriteLine($"Plantación guardada en bodega {userStorageBuilding.Name}"); } int plantationBuildingIndex = player.Buildings.IndexOf(plantationBuilding); player.Buildings.RemoveAt(plantationBuildingIndex); } else if (finishedBuilding.GetType() == typeof(Livestock)) { Livestock livestockBuilding = finishedBuilding as Livestock; int fieldBlocks = 0; double terrainQuality = 0; foreach (Terrain terrain in map.Terrains) { if (terrain.Building == livestockBuilding) { foreach (Block block in terrain.Blocks) { if (block.GetType() == typeof(FieldBlock)) { FieldBlock fieldBlock = block as FieldBlock; fieldBlocks += 1; terrainQuality += fieldBlock.Quality; } } break; } } terrainQuality = terrainQuality / fieldBlocks; int animalPrice = market.GetPriceOfAnimal(livestockBuilding.Animal); double terrainProportion = fieldBlocks / 100; double originalUnits = 10 * terrainProportion; double price = (livestockBuilding.Health * livestockBuilding.Units) / originalUnits; int finalPrice = Convert.ToInt32(price) * animalPrice; if (storageBuildings.Count == 0) { player.Money += finalPrice; Console.WriteLine($"Ganado vendido a {finalPrice}"); } else { Console.WriteLine("Elige uno de las bodegas disponibles:"); for (int i = 0; i < storageBuildings.Count; i++) { Console.WriteLine($"({i + 1}) - {storageBuildings[i].Name}"); } int storageUserOption = Int32.Parse(Console.ReadLine()); if (storageUserOption < 1 || storageUserOption > storageBuildings.Count) { Console.WriteLine("Opción no valida..."); return; } Building storageBuilding = storageBuildings[userOption - 1]; int storageBuildingIndex = player.Buildings.IndexOf(storageBuilding); StorageBuilding userStorageBuilding = player.Buildings[storageBuildingIndex] as StorageBuilding; FinishedProduct finishedProduct = new FinishedProduct(livestockBuilding.Animal.Name, finalPrice, animalPrice, livestockBuilding.Animal.WaterConsume, livestockBuilding.Animal.MinimumWaterLevel, livestockBuilding.Animal.PenaltyForLackOfWater, livestockBuilding.Animal.ProductionTime, livestockBuilding.Animal.ProbabilityOfIllness, livestockBuilding.Animal.PenaltyForIllness, Convert.ToInt32(terrainQuality)); userStorageBuilding.AddFinishedProduct(finishedProduct); Console.WriteLine($"Ganado guardado en bodega {userStorageBuilding.Name}"); } int liveStockBuildingIndex = player.Buildings.IndexOf(livestockBuilding); player.Buildings.RemoveAt(liveStockBuildingIndex); } else { return; } } }
private void NextTurn() { Console.WriteLine("Pasando de turno..."); Console.ForegroundColor = ConsoleColor.Red; // Se actuliza el precio de las semillas en el mercado foreach (Seed seed in market.Seeds) { seed.AddPriceHistory(); } // Se actulizan los datos de los edificios del usuario foreach (Building building in player.buildings) { if (building.GetType() == typeof(Plantation)) { // Se actulizan datos de las plantaciones Plantation plantationBuilding = building as Plantation; Seed plantationSeed = plantationBuilding.Seed; plantationBuilding.Maturity += 1; if (plantationBuilding.Sick == false) { plantationBuilding.SickPast = false; } if (plantationBuilding.HasUndergrowth == false) { plantationBuilding.HasUndergrowthPast = false; } if (plantationBuilding.HasWorms == false) { plantationBuilding.HasWormsPast = false; } plantationBuilding.GetSick(); plantationBuilding.GetUndergrowth(); plantationBuilding.GetWorms(); // Se revisan las proiedades de la plantacion if (plantationBuilding.Health == 0) { Console.WriteLine($"-La salud de la plantacion {plantationBuilding.Name} llego a 0."); } if (plantationBuilding.Water == 0) { Console.WriteLine($"-El nivel de agua de la plantacion {plantationBuilding.Name} llego a 0."); } if (plantationBuilding.Nutrients == 0) { Console.WriteLine($"-El nivel de nutrientes de la plantacion {plantationBuilding.Name} llego a 0."); } if (plantationBuilding.Nutrients < plantationSeed.MinimumLevelOfNutrients && plantationBuilding.Health != 0) { plantationBuilding.Health -= plantationSeed.PenaltyForLackOfNutrients; Console.WriteLine($"-La salud de la plantacion {plantationBuilding.Name} disminuyo a {plantationBuilding.Health} debido a falta de nutrientes."); } if (plantationBuilding.Water < plantationSeed.MinimumWaterLevel && plantationBuilding.Health != 0) { plantationBuilding.Health -= plantationSeed.PenaltyForLackOfWater; Console.WriteLine($"-La salud de la plantacion {plantationBuilding.Name} disminuyo a {plantationBuilding.Health} debido a falta de Agua."); } if (plantationBuilding.Water != 0) { plantationBuilding.Water -= plantationSeed.WaterConsume; } if (plantationBuilding.Nutrients != 0) { plantationBuilding.Nutrients -= plantationSeed.NutrientConsumption; } if (plantationBuilding.Sick && plantationBuilding.SickPast && plantationBuilding.Health != 0) { plantationBuilding.Health -= plantationSeed.PenaltyForIllness; Console.WriteLine($"-La plantacion {plantationBuilding.Name} se encuentra enferma y disminuyo la Salud a {plantationBuilding.Health}."); } else if (plantationBuilding.Sick) { Console.WriteLine($"-La plantacion {plantationBuilding.Name} se encuentra enferma."); } if (plantationBuilding.HasWorms && plantationBuilding.HasWormsPast && plantationBuilding.Health != 0) { plantationBuilding.Health -= plantationSeed.WormPenalty; Console.WriteLine($"-La plantacion {plantationBuilding.Name} se encuentra con gusanos y disminuyo la Salud a {plantationBuilding.Health}."); } else if (plantationBuilding.HasWorms) { Console.WriteLine($"-La plantacion {plantationBuilding.Name} se encuentra con gusanos."); } if (plantationBuilding.HasUndergrowth && plantationBuilding.HasUndergrowthPast && plantationBuilding.Health != 0) { plantationBuilding.Health -= plantationSeed.WeedPenalty; Console.WriteLine($"-La plantacion {plantationBuilding.Name} se encuentra con maleza y disminuyo la Salud a {plantationBuilding.Health}."); } else if (plantationBuilding.HasUndergrowth) { Console.WriteLine($"-La plantacion {plantationBuilding.Name} se encuentra con maleza."); } plantationBuilding.HasUndergrowthPast = plantationBuilding.HasUndergrowth; plantationBuilding.HasWormsPast = plantationBuilding.HasWorms; plantationBuilding.SickPast = plantationBuilding.Sick; } else if (building.GetType() == typeof(Livestock)) { // Se actulizan datos de los ganados Livestock livestockBuilding = building as Livestock; Animal livestockAnimal = livestockBuilding.Animal; livestockBuilding.Maturity += 1; if (livestockBuilding.Health == 0) { Console.WriteLine($"-La salud del ganado {livestockBuilding.Name} llego a 0."); } //Agua if (livestockBuilding.Water == 0) { Console.WriteLine($"-El nivel de agua del ganado {livestockBuilding.Name} llego a 0."); } else if (livestockBuilding.Water < livestockAnimal.MinimumWaterLevel && livestockBuilding.Health != 0) { livestockBuilding.Health -= livestockAnimal.PenaltyForLackOfWater; Console.WriteLine($"-La salud del ganado {livestockBuilding.Name} disminuyo a {livestockBuilding.Health} debido a falta de Agua."); } //Comida if (livestockBuilding.Food == 0) { Console.WriteLine($"-El nivel de alimentos del ganado {livestockBuilding.Name} llego a 0."); } if (livestockBuilding.Food < livestockAnimal.MinimumFoodLevel && livestockBuilding.Health != 0) { livestockBuilding.Health -= livestockAnimal.PenaltyForLackOfFood; Console.WriteLine($"-La salud del ganado {livestockBuilding.Name} disminuyo a {livestockBuilding.Health} debido a falta de alimentos."); } if (livestockBuilding.Sick == false) { livestockBuilding.SickPast = false; } livestockBuilding.Escape(); livestockBuilding.SuddenDeath(); livestockBuilding.GetSick(); if (livestockBuilding.Sick && livestockBuilding.SickPast && livestockBuilding.Health != 0) { livestockBuilding.Health -= livestockAnimal.PenaltyForIllness; Console.WriteLine($"-El ganado {livestockBuilding.Name} se encuentra enfermo y disminuyo la Salud a {livestockBuilding.Health}."); } else if (livestockBuilding.Sick) { Console.WriteLine($"-El ganado {livestockBuilding.Name} se encuentra enfermo."); } livestockBuilding.SickPast = livestockBuilding.Sick; //consumos if (livestockBuilding.Food != 0) { livestockBuilding.Food -= livestockAnimal.FoodConsumption; } if (livestockBuilding.Water != 0) { livestockBuilding.Water -= livestockAnimal.WaterConsume; } } else if (building.GetType() == typeof(StorageBuilding)) { //Se disminute la calidad de los productos almacenados StorageBuilding storageBuilding = building as StorageBuilding; storageBuilding.ChangeQuality(); } } turn += 1; Console.ResetColor(); Console.WriteLine("Turno pasado..."); Console.WriteLine("Presione cualquier tecla para continuar..."); Console.ReadKey(); }
public bool IsType(Livestock type) { return(Paritee.StardewValley.Core.Characters.FarmAnimal.IsType(GetOriginal(), type)); }