public void withdraw() { CMarketMessage m = new CMarketMessage(); m.option = "buy"; m.items.Add(World.Instance.mview); m.dbid = World.Instance.selfDbid; Client.Instance.Send(m); }
private void GetMarket() { CMarketMessage msgPull = new CMarketMessage { option = "get" }; Client.Instance.market = null; Client.Instance.Send(msgPull); StartCoroutine(ShowItems()); }
public CMarketMessage GetMarketBuyMessage() { CMarketMessage message = new CMarketMessage { option = "buy" }; foreach (var i in market_items) { message.items.Add(i); } message.dbid = World.Instance.selfDbid; return(message); }
public bool coinType = false; // false - silver, true - gold public void onClickSale() { int price = int.Parse(GetComponentInChildren <InputField>().text); MarketTreasure item = new MarketTreasure { owner_id = World.Instance.selfDbid, id = World.Instance.view.id, name = World.Instance.view.name, type = World.Instance.view.type, effect = World.Instance.view.effect, value = World.Instance.view.value, price = price, status = '3', coinType = coinType }; CMarketMessage msgSell = new CMarketMessage { option = "change", items = new List <MarketTreasure>() }; World.Instance.mview.price = price; msgSell.items.Add(World.Instance.mview); if (World.Instance.view.status != '2') { Client.Instance.Send(msgSell); World.Instance.myinventory.Remove(World.Instance.view); World.Instance.view.status = '3'; MarketTreasure insert = new MarketTreasure(); insert.id = World.Instance.view.id; insert.owner_id = World.Instance.selfId; insert.name = World.Instance.view.name; insert.value = World.Instance.view.value; insert.price = price; insert.type = World.Instance.view.type; insert.effect = World.Instance.view.effect; insert.status = World.Instance.view.status; insert.coinType = coinType; World.Instance.mymarket.Add(insert); } else { MessageBox.Show("Please unload before selling"); } }
private void OnRecvMarket(IChannel channel, Message message) { CMarketMessage request = message as CMarketMessage; SMarketMessage reply = new SMarketMessage(); var conn = db.Instance.Connect(); switch (request.option) { case "get": reply.items = db.Instance.GetMarket(conn); reply.option = "get"; break; case "sell": db.Instance.MarketSell(request.items[0], conn); reply.option = "done"; break; case "buy": int gold = 0, silver = 0; //int silver_coin = db.Instance.GetSilverCoins(request.dbid, conn); //int gold_coin = db.Instance.GetGoldCoins(request.dbid, conn); foreach (var i in request.items) { if (i.coinType) { gold += i.price; } else { silver += i.price; } Treasure temp = new Treasure(); temp.id = i.id; temp.name = i.name; temp.value = i.value; temp.price = i.price; temp.type = i.type; temp.effect = i.effect; temp.status = i.status; reply.invent.Add(temp); } int owner = request.items[0].owner_id; if (/*(gold <= gold_coin && silver <= silver_coin) || request.items[0].owner_id == request.dbid*/ true) { if (gold > 0) { db.Instance.MarketBuy(request.items, request.dbid, owner, true, conn); } else { db.Instance.MarketBuy(request.items, request.dbid, owner, false, conn); } reply.success = true; reply.gold = gold; reply.silver = silver; } else { reply.success = false; } reply.option = "buy"; break; case "change": db.Instance.MarketChange(request.items[0], conn); reply.option = "done"; break; default: break; } channel.Send(reply); }