public static int GetPrice(this Shop shop, ShopDefItem item, Shop.PurchaseType purchaseType, Shop.ShopType shopType) { var price = UIControler.GetPrice(item); //Control.LogDebug(DInfo.Price, $"get_price for {item.ID}: {price}"); return(price); }
public string PostPurchaseForFaction(List <string> ids, string Faction) { try { Faction realFaction = (Faction)Enum.Parse(typeof(Faction), Faction); if (Holder.factionShops != null) { FactionShop shop = Holder.factionShops.FirstOrDefault(x => x.shopOwner == realFaction); if (shop != null) { foreach (string ID in ids) { ShopDefItem item = shop.currentSoldItems.FirstOrDefault(x => x.ID.Equals(ID)); if (item != null) { item.Count--; } } shop.currentSoldItems.RemoveAll(x => x.Count <= 0); } } Logger.LogLine(ids.Count + " items removed from shop for " + Faction); return(ids.Count + " items removed from shop for " + Faction); } catch (Exception e) { Logger.LogError(e); return("Error"); } }
static void Postfix() { try { if (Fields.currentShopSold.Key != Faction.INVALID_UNSET) { Web.PostSoldItems(Fields.currentShopSold.Value, Fields.currentShopSold.Key); Fields.currentShopSold = new KeyValuePair <Faction, List <ShopDefItem> >(Faction.INVALID_UNSET, new List <ShopDefItem>()); } if (Fields.currentShopBought.Key != Faction.INVALID_UNSET) { Web.PostBuyItems(Fields.currentShopBought.Value, Fields.currentShopBought.Key); foreach (string id in Fields.currentShopBought.Value) { ShopDefItem match = Fields.currentShops[Fields.currentShopBought.Key].FirstOrDefault(x => x.ID.Equals(id)); if (match != null) { if (match.Count == 0) { Fields.currentShops[Fields.currentShopBought.Key].Remove(match); } } } Fields.currentShopBought = new KeyValuePair <Faction, List <string> >(Faction.INVALID_UNSET, new List <string>()); } } catch (Exception e) { PersistentMapClient.Logger.LogError(e); } }
public static void StartDialog(string replace_title, ShopDefItem selected, string item_name, int max, int price, UnityAction <int> on_confirm, UnityAction on_cancel) { Replace = true; Text = replace_title; var popup = LazySingletonBehavior <UIManager> .Instance.GetOrCreatePopupModule <SG_Stores_MultiPurchasePopup>("", true); popup.SetData(Control.State.Sim, selected, item_name, max, price, on_confirm, on_cancel); }
// Send any salvage the user didn't want to the faction inventory public static bool PostUnusedSalvage(List <SalvageDef> ___finalPotentialSalvage, Faction faction) { List <ShopDefItem> items = new List <ShopDefItem>(); foreach (SalvageDef salvage in ___finalPotentialSalvage) { ShopDefItem item = new ShopDefItem(); item.ID = salvage.Description.Id; switch (salvage.ComponentType) { case ComponentType.AmmunitionBox: { item.Type = ShopItemType.AmmunitionBox; break; } case ComponentType.HeatSink: { item.Type = ShopItemType.HeatSink; break; } case ComponentType.JumpJet: { item.Type = ShopItemType.JumpJet; break; } case ComponentType.MechPart: { item.Type = ShopItemType.MechPart; break; } case ComponentType.Upgrade: { item.Type = ShopItemType.Upgrade; break; } case ComponentType.Weapon: { item.Type = ShopItemType.Weapon; break; } } item.DiscountModifier = 1f; item.Count = 1; items.Add(item); } if (items.Count > 0) { string testjson = JsonConvert.SerializeObject(items); HttpWebRequest request = new RequestBuilder(WarService.PostSalvage).Faction(faction).PostData(testjson).Build(); HttpWebResponse response = request.GetResponse() as HttpWebResponse; using (Stream responseStream = response.GetResponseStream()) { StreamReader reader = new StreamReader(responseStream); string mapstring = reader.ReadToEnd(); } } return(true); }
public static List <ShopDefItem> GenerateNewShop(Faction realFaction) { List <ShopDefItem> newShop = new List <ShopDefItem>(); Random rand = new Random(); if (Holder.factionInventories == null) { Holder.factionInventories = FactionInventoryStateManager.Build(); } if (!Holder.factionInventories.ContainsKey(realFaction)) { Holder.factionInventories.Add(realFaction, new List <ShopDefItem>()); } if (Holder.factionInventories[realFaction].Count <= 0) { return(newShop); } int maxCount = Holder.factionInventories[realFaction].Max(x => x.Count); foreach (ShopDefItem item in Holder.factionInventories[realFaction].OrderByDescending(x => x.Count)) { if (newShop.Count >= Helper.LoadSettings().MaxItemsPerShop) { break; } int rolledNumber = rand.Next(0, maxCount + 1); if (rolledNumber <= item.Count) { while (rolledNumber < item.Count) { if (newShop.FirstOrDefault(x => x.ID.Equals(item.ID)) == null) { ShopDefItem newItem = new ShopDefItem(item); newItem.Count = 1; newShop.Add(newItem); } else { newShop.FirstOrDefault(x => x.ID.Equals(item.ID)).Count++; } item.Count--; item.DiscountModifier = Math.Min(item.DiscountModifier + Helper.LoadSettings().DiscountPerItem, Helper.LoadSettings().DiscountCeiling); } } } foreach (ShopDefItem item in newShop) { logger.Debug($"Added {item.ID} count {item.Count}"); } Holder.factionInventories[realFaction].RemoveAll(x => x.Count <= 0); logger.Info($"New shop generated for faction ({realFaction})"); return(newShop); }
static void Postfix(Shop __instance, ShopDefItem item, Shop.ShopType shopType, ref int __result) { try { if (shopType == Shop.ShopType.Faction) { DescriptionDef itemDescription = __instance.GetItemDescription(item); __result = Mathf.CeilToInt(itemDescription.Cost * item.DiscountModifier); } } catch (Exception e) { PersistentMapClient.Logger.LogError(e); } }
static void Postfix(Shop __instance, ShopDefItem item, bool __result, StarSystem ___system, SimGameState ___Sim) { try { if (__result && __instance.ThisShopType == Shop.ShopType.Faction && ___Sim.IsFactionAlly(___system.Owner, null)) { if (Fields.currentShopSold.Key == Faction.INVALID_UNSET) { Fields.currentShopSold = new KeyValuePair <Faction, List <ShopDefItem> >(___system.Owner, new List <ShopDefItem>()); } Fields.currentShopSold.Value.Add(item); } } catch (Exception e) { PersistentMapClient.Logger.LogError(e); } }
static void Postfix(ShopDefItem item, bool __result, StarSystem ___system) { try { if (__result) { if (Fields.currentShopSold.Key == Faction.INVALID_UNSET) { Fields.currentShopSold = new KeyValuePair <Faction, List <ShopDefItem> >(___system.Owner, new List <ShopDefItem>()); } Fields.currentShopSold.Value.Add(item); } } catch (Exception e) { Logger.LogError(e); } }
public bool OnSellItem(ShopDefItem item, int num) { if (Exists && Web.CanPostSoldItems()) { Fields.currentShopOwner = RelatedFaction; if (!Fields.shopItemsPosted.ContainsKey(item.ID)) { ShopDefItem pItem = new ShopDefItem(item); pItem.Count = num; Fields.shopItemsPosted.Add(item.ID, pItem); } else { Fields.shopItemsPosted[item.ID].Count += num; } return(true); } return(false); }
public string PostPurchaseForFactionDepricated(string Faction, string ID) { Faction realFaction = (Faction)Enum.Parse(typeof(Faction), Faction); if (Holder.factionShops != null) { FactionShop shop = Holder.factionShops.FirstOrDefault(x => x.shopOwner == realFaction); if (shop != null) { ShopDefItem item = shop.currentSoldItems.FirstOrDefault(x => x.ID.Equals(ID)); if (item != null) { item.Count--; } shop.currentSoldItems.RemoveAll(x => x.Count <= 0); } } Logger.LogLine(ID + " 1 removed from shop for " + Faction); return(ID + " 1 removed from shop for " + Faction); }