public void buy_item(Player pl) { int item_gold_value; switch (im_shopping_for) { case Shopping_Mode.Sell: sell_item(pl); break; case Shopping_Mode.Scrolls: item_gold_value = scrolls_in_stock[selected_item_index].get_my_gold_value(); if (pl.get_my_gold() >= item_gold_value) { pl.pay_gold(item_gold_value); pl.acquire_item(scrolls_in_stock[selected_item_index]); scrolls_in_stock.RemoveAt(selected_item_index); } break; default: item_gold_value = current_list[selected_item_index].get_my_gold_value(); int buyback_value = (int)Math.Max(item_gold_value * .93, item_gold_value - 500); if (im_shopping_for == Shopping_Mode.Buyback) { item_gold_value = buyback_value; } if (pl.get_my_gold() >= item_gold_value) { pl.pay_gold(item_gold_value); if (current_list[selected_item_index] is Potion) { Potion p = (Potion)current_list[selected_item_index]; p.adjust_quantity(-1); Potion p2 = new Potion(p.get_my_IDno(), p.get_my_gold_value(), p.get_my_name(), p); p2.set_quantity(1); pl.acquire_potion(p2); if (p.get_my_quantity() == 0) { current_list.RemoveAt(selected_item_index); } } else { pl.acquire_item(current_list[selected_item_index]); current_list.RemoveAt(selected_item_index); } } break; } player_gold = pl.get_my_gold(); scroll_menu(0); }
public void sell_item(Player pl) { int item_gold_value = items_to_sell[selected_item_index].get_my_gold_value(); int sale_value = (int)Math.Max(item_gold_value * .93, item_gold_value - 500); if (items_to_sell[selected_item_index] is Potion) { Potion p = (Potion)items_to_sell[selected_item_index]; Potion p2 = new Potion(p.get_my_IDno(), p.get_my_gold_value(), p.get_my_name(), p); p2.set_quantity(1); p.adjust_quantity(-1); if (p.get_my_quantity() == 0) { items_to_sell.RemoveAt(selected_item_index); } bool stacked = false; for (int i = 0; i < sold_items.Count; i++) { if (sold_items[i] is Potion) { Potion p3 = (Potion)sold_items[i]; if (p3.get_my_IDno() == p2.get_my_IDno()) { stacked = true; p3.adjust_quantity(1); } } } if (!stacked) { sold_items.Add(p2); } } else { sold_items.Add(items_to_sell[selected_item_index]); items_to_sell.RemoveAt(selected_item_index); } pl.add_gold(sale_value); }
public List <Item> retrieve_random_consumables(Player pl, int number) { PotionDC[] raw_potion_data = cManager.Load <PotionDC[]>("XmlData/Items/potions"); List <PotionDC> selected_potion_data = new List <PotionDC>(); List <Item> fetched_list = new List <Item>(); int tiers_available = 0; int playerGold = pl.get_my_gold(); if (playerGold < 1500) { tiers_available = 1; } else { tiers_available = 2; } string pl_chclass = pl.my_class_as_string(); for (int i = 0; i < raw_potion_data.Count(); i++) { string[] available_for = raw_potion_data[i].ValidClasses.Split(' '); bool valid_class = false; for (int cl = 0; cl < available_for.Count(); cl++) { if (String.Compare(pl_chclass, available_for[cl]) == 0) { valid_class = true; } } if (valid_class && (raw_potion_data[i].ItemTier == tiers_available || raw_potion_data[i].ItemTier == tiers_available - 1) && (raw_potion_data[i].Cost <= playerGold || raw_potion_data[i].Cost == 500)) { selected_potion_data.Add(raw_potion_data[i]); } } while ((fetched_list.Count) < number && selected_potion_data.Count > 0) { int selected_p_index = rGen.Next(selected_potion_data.Count); bool duplicate_type = false; //Check to see if it's a duplicate type first. for (int j = 0; j < fetched_list.Count; j++) { if (fetched_list[j] is Potion) { Potion p = (Potion)fetched_list[j]; string rpdType = selected_potion_data[selected_p_index].PotionType; switch (p.get_type()) { case Potion.Potion_Type.Health: duplicate_type = String.Compare(rpdType, "Health") == 0; break; case Potion.Potion_Type.Repair: duplicate_type = String.Compare(rpdType, "Repair") == 0; break; } } } //If it is not a duplicate type, add the potion intialized from the data //to fectched item list. //regardless, the potion is removed from selected raw data. if (!duplicate_type) { fetched_list.Add(process_pDC(selected_potion_data[selected_p_index])); } selected_potion_data.RemoveAt(selected_p_index); } //Raw potion data 0 should be minor Health Potion. it's the first one //in the list. This guarantees that if no other health potion is present you //At least get a minor one. Toss the player a bone. bool health_potion_present = false; for (int i = 0; i < fetched_list.Count; i++) { if (fetched_list[i] is Potion) { Potion p = (Potion)fetched_list[i]; if (p.get_type() == Potion.Potion_Type.Health) { health_potion_present = true; } } } if (!health_potion_present) { int MPID = raw_potion_data[0].IDNumber; int MPC = raw_potion_data[0].Cost; string MPN = raw_potion_data[0].Name; int MPP = raw_potion_data[0].PotionPotency; fetched_list.Add(new Potion(MPID, MPC, MPN, Potion.Potion_Type.Health, MPP)); } bool bonus_quan = false; while (!bonus_quan) { int item_index = rGen.Next(fetched_list.Count); if (fetched_list[item_index] is Potion) { Potion p = (Potion)fetched_list[item_index]; p.adjust_quantity(1); bonus_quan = true; } } return(fetched_list); }