static bool Prefix(Shop __instance, StarSystem ___system, SimGameState ___Sim) { try { if (__instance.ThisShopType == Shop.ShopType.Faction && ___Sim.IsFactionAlly(___system.Owner, null)) { __instance.Clear(); if (!Fields.LastUpdate.ContainsKey(___system.Owner)) { Fields.LastUpdate.Add(___system.Owner, DateTime.MinValue); } if (!Fields.currentShops.ContainsKey(___system.Owner)) { Fields.currentShops.Add(___system.Owner, new List <ShopDefItem>()); } if (Fields.LastUpdate[___system.Owner].AddMinutes(Fields.UpdateTimer) < DateTime.UtcNow) { Fields.currentShops[___system.Owner] = Web.GetShopForFaction(___system.Owner); } foreach (ShopDefItem item in Fields.currentShops[___system.Owner]) { DataManager dataManager = ___Sim.DataManager; if (item.Count > 0) { switch (item.Type) { case ShopItemType.Weapon: { if (dataManager.WeaponDefs.Exists(item.ID)) { __instance.ActiveInventory.Add(item); } break; } case ShopItemType.AmmunitionBox: { if (dataManager.AmmoBoxDefs.Exists(item.ID)) { __instance.ActiveInventory.Add(item); } break; } case ShopItemType.HeatSink: { if (dataManager.HeatSinkDefs.Exists(item.ID)) { __instance.ActiveInventory.Add(item); } break; } case ShopItemType.JumpJet: { if (dataManager.JumpJetDefs.Exists(item.ID)) { __instance.ActiveInventory.Add(item); } break; } case ShopItemType.MechPart: { if (dataManager.MechDefs.Exists(item.ID)) { __instance.ActiveInventory.Add(item); } break; } case ShopItemType.Upgrade: { if (dataManager.UpgradeDefs.Exists(item.ID)) { __instance.ActiveInventory.Add(item); } break; } case ShopItemType.Mech: { if (dataManager.MechDefs.Exists(item.ID)) { __instance.ActiveInventory.Add(item); } break; } } } } Fields.LastUpdate[___system.Owner] = DateTime.UtcNow; return(false); } return(true); } catch (Exception e) { PersistentMapClient.Logger.LogError(e); return(true); } }
static void Postfix(Shop __instance, StarSystem ___system, SimGameState ___Sim) { try { if (!Fields.LastUpdate.ContainsKey(___system.Owner)) { Fields.LastUpdate.Add(___system.Owner, DateTime.MinValue); } if (!Fields.currentShops.ContainsKey(___system.Owner)) { Fields.currentShops.Add(___system.Owner, new List <ShopDefItem>()); } if (Fields.LastUpdate[___system.Owner].AddMinutes(Fields.UpdateTimer) < DateTime.UtcNow) { Fields.currentShops[___system.Owner] = Web.GetShopForFaction(___system.Owner); } foreach (ShopDefItem item in Fields.currentShops[___system.Owner]) { DataManager dataManager = ___Sim.DataManager; switch (item.Type) { case ShopItemType.Weapon: { if (dataManager.WeaponDefs.Exists(item.ID)) { __instance.ActiveSpecials.Add(item); } break; } case ShopItemType.AmmunitionBox: { if (dataManager.AmmoBoxDefs.Exists(item.ID)) { __instance.ActiveSpecials.Add(item); } break; } case ShopItemType.HeatSink: { if (dataManager.HeatSinkDefs.Exists(item.ID)) { __instance.ActiveSpecials.Add(item); } break; } case ShopItemType.JumpJet: { if (dataManager.JumpJetDefs.Exists(item.ID)) { __instance.ActiveSpecials.Add(item); } break; } case ShopItemType.MechPart: { if (dataManager.MechDefs.Exists(item.ID)) { __instance.ActiveSpecials.Add(item); } break; } case ShopItemType.Upgrade: { if (dataManager.UpgradeDefs.Exists(item.ID)) { __instance.ActiveSpecials.Add(item); } break; } case ShopItemType.Mech: { if (dataManager.MechDefs.Exists(item.ID)) { __instance.ActiveSpecials.Add(item); } break; } } } Fields.LastUpdate[___system.Owner] = DateTime.UtcNow; } catch (Exception e) { Logger.LogError(e); } }