mirror of
https://git.alee14.me/shiftos-archive/ShiftOS_TheReturn.git
synced 2025-02-02 06:17:34 +00:00
Dramatic shop optimizations.
This commit is contained in:
parent
86f204ee49
commit
c544e4081d
2 changed files with 61 additions and 7 deletions
|
@ -443,12 +443,46 @@ Contents:
|
|||
Contents = res.ToString()
|
||||
}));
|
||||
|
||||
break;
|
||||
case "shop_getitems":
|
||||
var shopName = args["shopname"] as string;
|
||||
Shop tempShop = null;
|
||||
foreach(var item in JsonConvert.DeserializeObject<List<Shop>>(File.ReadAllText("shops.json")))
|
||||
{
|
||||
if(item.Name == shopName)
|
||||
{
|
||||
tempShop = item;
|
||||
}
|
||||
}
|
||||
|
||||
if(tempShop != null)
|
||||
foreach(var item in tempShop.Items)
|
||||
{
|
||||
server.DispatchTo(new Guid(msg.GUID), new NetObject("item", new ServerMessage
|
||||
{
|
||||
Name = "shop_additem",
|
||||
GUID = "server",
|
||||
Contents = JsonConvert.SerializeObject(new
|
||||
{
|
||||
shop = shopName,
|
||||
itemdata = item
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
break;
|
||||
case "shop_getall":
|
||||
List<Shop> shops = new List<Shop>();
|
||||
if (File.Exists("shops.json"))
|
||||
shops = JsonConvert.DeserializeObject<List<Shop>>(File.ReadAllText("shops.json"));
|
||||
|
||||
//Purge all items in all shops temporarily.
|
||||
//This is to save on network bandwidth as it will take a long time to send everyone's shops down if we don't purge the stock.
|
||||
//And with high bandwidth usage, we may end up DOSing our clients when too many people upload too many things.
|
||||
//Furthermore, this'll make the MUD Control Centre seem faster...
|
||||
for (int i = 0; i <= shops.Count; i++)
|
||||
{
|
||||
shops[i].Items = new List<ShopItem>();
|
||||
}
|
||||
server.DispatchTo(new Guid(msg.GUID), new NetObject("ladouceur", new ServerMessage
|
||||
{
|
||||
Name = "shop_all",
|
||||
|
|
|
@ -140,6 +140,15 @@ namespace ShiftOS.WinForms.Applications
|
|||
ShowShop(JsonConvert.DeserializeObject<Shop>(msg.Contents));
|
||||
}));
|
||||
}
|
||||
else if(msg.Name == "shop_additem")
|
||||
{
|
||||
var contents = JsonConvert.DeserializeObject<Dictionary<string, object>>(msg.Contents);
|
||||
if((string)contents["shop"] == CurrentShop.Name)
|
||||
{
|
||||
CurrentShop.Items.Add((ShopItem)contents["itemdata"]);
|
||||
this.Invoke(new Action(PopulateShopView));
|
||||
}
|
||||
}
|
||||
else if(msg.Name == "user_noshop")
|
||||
{
|
||||
this.Invoke(new Action(() =>
|
||||
|
@ -181,7 +190,7 @@ namespace ShiftOS.WinForms.Applications
|
|||
public void PopulateShopEditor()
|
||||
{
|
||||
txtshopdescription.Text = editingShop.Description;
|
||||
txtshopname.Text = editingShop.Description;
|
||||
txtshopname.Text = editingShop.Name;
|
||||
lbeditingshopitems.Items.Clear();
|
||||
foreach(var item in editingShop.Items)
|
||||
{
|
||||
|
@ -247,6 +256,17 @@ namespace ShiftOS.WinForms.Applications
|
|||
|
||||
}
|
||||
|
||||
public void PopulateShopView()
|
||||
{
|
||||
lbupgrades.Items.Clear();
|
||||
shopItems = CurrentShop.Items;
|
||||
foreach (var item in CurrentShop.Items)
|
||||
{
|
||||
lbupgrades.Items.Add(item.Name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void ShowShop(Shop shop)
|
||||
{
|
||||
shop_view.BringToFront();
|
||||
|
@ -257,12 +277,11 @@ namespace ShiftOS.WinForms.Applications
|
|||
lbprice.Text = "Select an item from the list on the left.";
|
||||
btnbuy.Hide();
|
||||
|
||||
lbupgrades.Items.Clear();
|
||||
shopItems = shop.Items;
|
||||
foreach (var item in shop.Items)
|
||||
ServerManager.SendMessage("shop_getitems", JsonConvert.SerializeObject(new
|
||||
{
|
||||
lbupgrades.Items.Add(item.Name);
|
||||
}
|
||||
shopname = CurrentShop.Name
|
||||
}));
|
||||
|
||||
lbupgrades.SelectedIndexChanged += (o, a) =>
|
||||
{
|
||||
item = shopItems[lbupgrades.SelectedIndex];
|
||||
|
@ -715,6 +734,7 @@ Current legions: {legionname}";
|
|||
AppearanceManager.SetupWindow(new ShopItemCreator(new ShopItem(), new Action<ShopItem>((item) =>
|
||||
{
|
||||
editingShop.Items.Add(item);
|
||||
PopulateShopEditor();
|
||||
})));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue