private void Crafting_Profit_Calculate_Click(object sender, EventArgs e) { Crafting_Profit_Resources.Items.Clear(); RecipeSummaryItem totalressources = new RecipeSummaryItem(); foreach (RecipeSummaryItem item in Crafting_Profit_List.Items) { totalressources.CombineSummaryItem(item); } int amount = 1; if (!Int32.TryParse(Crafting_Profit_Craft_Amount.Text, out amount)) { MessageBox.Show("Craft amount must be at least 1"); return; } foreach (RecipeCraftingItems items in totalressources.CraftingItems) { string add = ""; switch (items.aquirementtype) { case 1: add += "Buy: "; break; case 2: add += "Take out of Inventory: "; break; case 3: add += "Craft: "; break; } add += amount * items.amount + " " + items.name; Crafting_Profit_Resources.Items.Add(add); } totalressources = null; }
private void Crafting_Profit_Check_Click(object sender, EventArgs e) { int laborcost = 0; if (!Int32.TryParse(Crafting_Recipes_Profit_LaborInMoney.Text, out laborcost)) { MessageBox.Show("WorkersPotion must be a number and at least 0"); return; } foreach (RecipeItem item in RecipeItemsTop) { Dictionary <string, int> Materials = new Dictionary <string, int>(); int totalprice = 0; try { RecipeSummaryItem tempitem = item.CheapestWayObtaining(AuctionItemsTop, InventoryItemsTop, laborcost / 1000); var sellpriceitems = AuctionItemsTop.Where(x => x.itemName == item.Name).Where(x => x.TimeStamp > Timestamp(60 * 60 * 24 * 14)); double lowestprice = 999999999; foreach (AuctionItem test in sellpriceitems) { if (test.BuyoutPrice < lowestprice) { lowestprice = test.BuyoutPrice; } } double profitmargin = 0; if (!double.TryParse(Crafting_Profit_Profit.Text, out profitmargin)) { MessageBox.Show("Profit % must be at least 0"); } if (tempitem.totalprice * (1 + profitmargin / 100) < (lowestprice * 0.94)) { tempitem.name = item.Name; tempitem.profitmargin = (1 - (tempitem.totalprice / (lowestprice * 0.94))) * 100; Crafting_Profit_List.Items.Add(tempitem); } } catch (ArgumentException ex) { MessageBox.Show(ex.Message); } } }
public void CombineSummaryItem(RecipeSummaryItem item) { totallabor += item.totallabor; totalprice += item.totalprice; foreach (RecipeCraftingItems subcraftingitem in item.CraftingItems) { bool contained = false; foreach (RecipeCraftingItems craftingitem in CraftingItems) { if (craftingitem.name == subcraftingitem.name) { contained = true; craftingitem.amount += subcraftingitem.amount; } } if (!contained) { CraftingItems.Add(subcraftingitem); } } }
public void CombineSummaryItem(RecipeSummaryItem item) { totallabor += item.totallabor; totalprice += item.totalprice; foreach(RecipeCraftingItems subcraftingitem in item.CraftingItems) { bool contained = false; foreach(RecipeCraftingItems craftingitem in CraftingItems) { if(craftingitem.name == subcraftingitem.name) { contained = true; craftingitem.amount += subcraftingitem.amount; } } if(!contained) { CraftingItems.Add(subcraftingitem); } } }
public RecipeSummaryItem CheapestWayObtaining(List<AuctionItem> DB, List<InventoryItem> InventoryDB,int _laborcost) { RecipeSummaryItem upwarditem = new RecipeSummaryItem(); upwarditem.totallabor += LaborCost * Amount; if(this.isBaseItem()) { int aquirement = 0; var auctionresult = DB.Where(x => x.itemName == Name).Where(x => x.TimeStamp > Timestamp(60 * 60 * 24 * 14)); int auctionprice = 999999999; bool auctionfound = false; foreach(AuctionItem _auctionitem in auctionresult) { auctionfound = true; if(_auctionitem.BuyoutPrice < auctionprice) { auctionprice = _auctionitem.BuyoutPrice; } } var inventoryresult = InventoryDB.Where(x => x.itemname == Name); int inventoryprice = 999999999; bool inventoryfound = false; foreach(InventoryItem _inventory in inventoryresult) { if(_inventory.amount > Amount) { inventoryfound = true; if (_inventory.priceincopper() < inventoryprice) { inventoryprice = _inventory.priceincopper(); } } } if(!inventoryfound && !auctionfound) { throw new System.ArgumentException(Name+" not found in AuctionData or InventoryData","original"); } if (inventoryfound && auctionfound) { if(auctionprice > inventoryprice) { upwarditem.totalprice += auctionprice; aquirement = 1; } else { upwarditem.totalprice += inventoryprice; aquirement = 2; } } else { if (inventoryfound) { upwarditem.totalprice += inventoryprice; aquirement = 2; } if (auctionfound) { upwarditem.totalprice += auctionprice; aquirement = 1; } } RecipeCraftingItems _craftingitem = new RecipeCraftingItems(); _craftingitem.amount += Amount; _craftingitem.name = Name; _craftingitem.aquirementtype = aquirement; upwarditem.CraftingItems.Add(_craftingitem); } else { foreach(RecipeItem recipeitem in SubItems) { RecipeSummaryItem subsummaryitem = recipeitem.CheapestWayObtaining(DB, InventoryDB, _laborcost); int aquirement = 0; var auctionresult = DB.Where(x => x.itemName == recipeitem.Name).Where(x => x.TimeStamp > Timestamp(60 * 60 * 24 * 14)); int auctionprice = 999999999; bool auctionfound = false; foreach (AuctionItem _auctionitem in auctionresult) { auctionfound = true; if (_auctionitem.BuyoutPrice < auctionprice) { auctionprice = _auctionitem.BuyoutPrice; } } var inventoryresult = InventoryDB.Where(x => x.itemname == recipeitem.Name); int inventoryprice = 999999999; bool inventoryfound = false; foreach (InventoryItem _inventory in inventoryresult) { if (_inventory.amount > Amount) { inventoryfound = true; if (_inventory.priceincopper() < auctionprice) { inventoryprice = _inventory.priceincopper(); } } } bool auctionwon = false; if(auctionfound) { if(auctionprice > (subsummaryitem.totalprice+subsummaryitem.totallabor*_laborcost)) { } else { auctionwon = true; } } bool inventorywon = false; if (inventoryfound) { if(inventoryprice > (subsummaryitem.totalprice + subsummaryitem.totallabor * _laborcost)) { } else { inventorywon = true; } } if(inventoryfound && auctionfound && inventorywon && auctionwon) { if(inventoryprice > auctionprice) { inventorywon = false; } else { auctionwon = false; } } if(auctionwon) { upwarditem.totalprice += auctionprice * recipeitem.Amount; upwarditem.CombineSummaryItem(subsummaryitem); } if(inventorywon) { upwarditem.totalprice += inventoryprice * recipeitem.Amount; upwarditem.CombineSummaryItem(subsummaryitem); } if(!auctionwon && !inventorywon) { upwarditem.totalprice += subsummaryitem.totalprice; upwarditem.CombineSummaryItem(subsummaryitem); } } // do the rest (only ever use 1 RecipeSummaryItem)(return it but then take it appart and add to the "parent" recipesummaryitem) } return upwarditem; }
public RecipeSummaryItem CheapestWayObtaining(List <AuctionItem> DB, List <InventoryItem> InventoryDB, int _laborcost) { RecipeSummaryItem upwarditem = new RecipeSummaryItem(); upwarditem.totallabor += LaborCost * Amount; if (this.isBaseItem()) { int aquirement = 0; var auctionresult = DB.Where(x => x.itemName == Name).Where(x => x.TimeStamp > Timestamp(60 * 60 * 24 * 14)); int auctionprice = 999999999; bool auctionfound = false; foreach (AuctionItem _auctionitem in auctionresult) { auctionfound = true; if (_auctionitem.BuyoutPrice < auctionprice) { auctionprice = _auctionitem.BuyoutPrice; } } var inventoryresult = InventoryDB.Where(x => x.itemname == Name); int inventoryprice = 999999999; bool inventoryfound = false; foreach (InventoryItem _inventory in inventoryresult) { if (_inventory.amount > Amount) { inventoryfound = true; if (_inventory.priceincopper() < inventoryprice) { inventoryprice = _inventory.priceincopper(); } } } if (!inventoryfound && !auctionfound) { throw new System.ArgumentException(Name + " not found in AuctionData or InventoryData", "original"); } if (inventoryfound && auctionfound) { if (auctionprice > inventoryprice) { upwarditem.totalprice += auctionprice; aquirement = 1; } else { upwarditem.totalprice += inventoryprice; aquirement = 2; } } else { if (inventoryfound) { upwarditem.totalprice += inventoryprice; aquirement = 2; } if (auctionfound) { upwarditem.totalprice += auctionprice; aquirement = 1; } } RecipeCraftingItems _craftingitem = new RecipeCraftingItems(); _craftingitem.amount += Amount; _craftingitem.name = Name; _craftingitem.aquirementtype = aquirement; upwarditem.CraftingItems.Add(_craftingitem); } else { foreach (RecipeItem recipeitem in SubItems) { RecipeSummaryItem subsummaryitem = recipeitem.CheapestWayObtaining(DB, InventoryDB, _laborcost); int aquirement = 0; var auctionresult = DB.Where(x => x.itemName == recipeitem.Name).Where(x => x.TimeStamp > Timestamp(60 * 60 * 24 * 14)); int auctionprice = 999999999; bool auctionfound = false; foreach (AuctionItem _auctionitem in auctionresult) { auctionfound = true; if (_auctionitem.BuyoutPrice < auctionprice) { auctionprice = _auctionitem.BuyoutPrice; } } var inventoryresult = InventoryDB.Where(x => x.itemname == recipeitem.Name); int inventoryprice = 999999999; bool inventoryfound = false; foreach (InventoryItem _inventory in inventoryresult) { if (_inventory.amount > Amount) { inventoryfound = true; if (_inventory.priceincopper() < auctionprice) { inventoryprice = _inventory.priceincopper(); } } } bool auctionwon = false; if (auctionfound) { if (auctionprice > (subsummaryitem.totalprice + subsummaryitem.totallabor * _laborcost)) { } else { auctionwon = true; } } bool inventorywon = false; if (inventoryfound) { if (inventoryprice > (subsummaryitem.totalprice + subsummaryitem.totallabor * _laborcost)) { } else { inventorywon = true; } } if (inventoryfound && auctionfound && inventorywon && auctionwon) { if (inventoryprice > auctionprice) { inventorywon = false; } else { auctionwon = false; } } if (auctionwon) { upwarditem.totalprice += auctionprice * recipeitem.Amount; upwarditem.CombineSummaryItem(subsummaryitem); } if (inventorywon) { upwarditem.totalprice += inventoryprice * recipeitem.Amount; upwarditem.CombineSummaryItem(subsummaryitem); } if (!auctionwon && !inventorywon) { upwarditem.totalprice += subsummaryitem.totalprice; upwarditem.CombineSummaryItem(subsummaryitem); } } // do the rest (only ever use 1 RecipeSummaryItem)(return it but then take it appart and add to the "parent" recipesummaryitem) } return(upwarditem); }
private void Crafting_Profit_Calculate_Click(object sender, EventArgs e) { Crafting_Profit_Resources.Items.Clear(); RecipeSummaryItem totalressources = new RecipeSummaryItem(); foreach(RecipeSummaryItem item in Crafting_Profit_List.Items) { totalressources.CombineSummaryItem(item); } int amount = 1; if(!Int32.TryParse(Crafting_Profit_Craft_Amount.Text,out amount)) { MessageBox.Show("Craft amount must be at least 1"); return; } foreach(RecipeCraftingItems items in totalressources.CraftingItems) { string add = ""; switch(items.aquirementtype) { case 1: add +="Buy: "; break; case 2: add +="Take out of Inventory: "; break; case 3: add +="Craft: "; break; } add += amount * items.amount + " " + items.name; Crafting_Profit_Resources.Items.Add(add); } totalressources = null; }