Exemplo n.º 1
0
        public bool ExchengeEdit(OrderTrade order)
        {
            Loger.Log("Client ExchengeEdit " + order.ToString());
            var stat = TransObject <ModelStatus>(order, (int)PackageType.Request21, (int)PackageType.Response22);

            if (stat != null && stat.Status != 0)
            {
                ErrorMessage = stat.Message;
                return(false);
            }

            return(stat != null);
        }
        public OrderTrade Convert(Binance.AccountTrade x)
        {
            var si     = GetSymbolInformation(x.symbol);
            var result = new OrderTrade(si)
            {
                Id             = x.id.ToString(),
                OrderId        = x.orderId.ToString(),
                Price          = x.price,
                Quantity       = x.qty,
                Side           = (x.isBuyer) ? TradeSide.Buy : TradeSide.Sell,
                Timestamp      = x.time.FromUnixTimestamp(),
                Comission      = x.commission,
                ComissionAsset = x.commissionAsset
            };

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// область снизу справа - просмотр и редактирование ордера
        /// </summary>
        /// <param name="inRect"></param>
        public void DoWindowEditOrder(Rect inRect)
        {
            if (PlaceCurrent == null)
            {
                PlaceCurrent = new Place();
                WorldObject wo;
                if (PlaceMap != null)
                {
                    wo = PlaceMap.info.parent;
                }
                else
                {
                    wo = PlaceCaravan;
                }
                PlaceCurrent.Name          = wo.LabelCap;
                PlaceCurrent.PlaceServerId = UpdateWorldController.GetServerInfo(wo).ServerId;
                PlaceCurrent.ServerName    = SessionClientController.My.ServerName;
                PlaceCurrent.Tile          = wo.Tile;
                PlaceCurrent.DayPath       = 0;
            }
            if (EditOrder == null)
            {
                //Действие не выбрано: по умолчанию настраиваем панельна создание нового ордера
                EditOrderTitle = "OCity_Dialog_Exchenge_Order_Create".Translate();
                var editOrder = new OrderTrade();
                editOrder.Owner         = SessionClientController.My;
                editOrder.Place         = PlaceCurrent;
                editOrder.CountBeginMax = 1;

                editOrder.SellThings = new List <ThingTrade>();
                editOrder.BuyThings  = new List <ThingTrade>();
                var silverDef = (ThingDef)GenDefDatabase.GetDef(typeof(ThingDef), "Silver");
                var th        = ThingTrade.CreateTrade(silverDef, 0f, QualityCategory.Awful, 1);
                editOrder.BuyThings.Add(th);

                editOrder.PrivatPlayers = new List <Player>();

                SetEditOrder(editOrder);
            }

            bool existInServer = EditOrder.Id != 0;

            //заголовок
            Rect rect = new Rect(0f, 0f, inRect.width, 18);

            inRect.yMin += rect.height;
            Text.Font    = GameFont.Tiny; // высота Tiny 18
            Text.Anchor  = TextAnchor.MiddleCenter;
            Widgets.Label(rect, EditOrderTitle);

            ///todo
            ///полоску проскрутки

            //кнопка в углу
            rect = new Rect(inRect.width - 150f, 20f, 150f, 24);
            if (!EditOrderToTrade)
            {
                GUI.color = Color.red;
            }
            if (Widgets.ButtonText(rect.ContractedBy(1f)
                                   , EditOrderIsMy
                    ? existInServer ? "OCity_Dialog_Exchenge_Save".Translate() : "OCity_Dialog_Exchenge_Create".Translate()
                    : "OCity_Dialog_Exchenge_Trade".Translate()
                                   , true, false, true))
            {
                GUI.color = Color.white;
                SoundDefOf.Tick_High.PlayOneShotOnCamera(null);
                if (!EditOrderToTrade)
                {
                    return;
                }

                if (!EditOrderIsMy)
                {
                    //торговать
                    //todo
                }
                else
                {
                    //создать или отредактировать
                    SessionClientController.Command((connect) =>
                    {
                        SoundDefOf.Tick_High.PlayOneShotOnCamera(null);

                        if (!connect.ExchengeEdit(EditOrder))
                        {
                            Loger.Log("Client ExchengeEdit error: " + connect.ErrorMessage);
                            Find.WindowStack.Add(new Dialog_Input("OCity_Dialog_Exchenge_Action_Not_CarriedOut".Translate(), connect.ErrorMessage, true));
                        }
                        else
                        {
                            SetEditOrder(null);
                        }

                        UpdateOrders();
                    });
                    return;
                }

                EditOrderChange();
                return;
            }
            GUI.color = Color.white;

            //кнопка
            if (!EditOrderIsMy)
            {
                rect = new Rect(160f, 20f, inRect.width - 160f - 160f, 24);
                if (Widgets.ButtonText(rect.ContractedBy(1f)
                                       , "OCity_Dialog_Exchenge_Counterproposal".Translate()
                                       , true, false, true))
                {
                    SoundDefOf.Tick_High.PlayOneShotOnCamera(null);

                    //todo

                    return;
                }
            }
            if (EditOrderIsMy && existInServer && EditOrder.Id != 0)
            {
                rect = new Rect(160f, 20f, 100f, 24);
                if (Widgets.ButtonText(rect.ContractedBy(1f)
                                       , "OCity_Dialog_Exchenge_Delete".Translate()
                                       , true, false, true))
                {
                    SoundDefOf.Tick_High.PlayOneShotOnCamera(null);

                    SessionClientController.Command((connect) =>
                    {
                        SoundDefOf.Tick_High.PlayOneShotOnCamera(null);

                        EditOrder.Id = -EditOrder.Id;
                        if (!connect.ExchengeEdit(EditOrder))
                        {
                            EditOrder.Id = -EditOrder.Id;
                            Loger.Log("Client ExchengeEdit error: " + connect.ErrorMessage);
                            Find.WindowStack.Add(new Dialog_Input("OCity_Dialog_Exchenge_Action_Not_CarriedOut".Translate(), connect.ErrorMessage, true));
                        }
                        else
                        {
                            SetEditOrder(null);
                        }

                        UpdateOrders();
                    });

                    return;
                }
            }

            rect = new Rect(0, 20f, 150f, 24f);
            if (Widgets.ButtonText(rect.ContractedBy(1f)
                                   , "OCity_Dialog_Exchenge_Order_New".Translate()
                                   , true, false, true))
            {
                SoundDefOf.Tick_High.PlayOneShotOnCamera(null);

                SetEditOrder(null);

                return;
            }

            inRect.yMin += rect.height;

            rect        = new Rect(0f, 44f, inRect.width, 24f);
            Text.Anchor = TextAnchor.MiddleLeft;

            if (EditOrderIsMy)
            {
                Widgets.Label(rect, "OCity_Dialog_Exchenge_No_Exchanges".Translate());
                var rect2 = new Rect(rect.x + 250f, rect.y, 70f, rect.height);

                int    countToTransfer = EditOrder.CountBeginMax;
                string editBuffer;
                if (!EditOrderEditBuffer.TryGetValue(EditOrder.GetHashCode(), out editBuffer))
                {
                    EditOrderEditBuffer.Add(EditOrder.GetHashCode(), editBuffer = countToTransfer.ToString());
                }
                Widgets.TextFieldNumeric <int>(rect2.ContractedBy(2f), ref countToTransfer, ref editBuffer, 1f, 999999999f);
                EditOrderEditBuffer[EditOrder.GetHashCode()] = editBuffer;
                if (countToTransfer > 0)
                {
                    EditOrder.CountBeginMax = countToTransfer;
                    EditOrderChange();
                }

                rect.y += 24f;
            }

            Widgets.Label(rect, "OCity_Dialog_Exchenge_No_Available_Exchange".Translate() + EditOrder.CountReady.ToString());
            if (EditOrderIsMy)
            {
                rect.xMin += 250;
                Widgets.Label(rect, "OCity_Dialog_Exchenge_Done_Once".Translate() + EditOrder.CountFnished.ToString());
                rect.xMin = 0;
            }
            rect.y += 24f;

            if (EditOrderIsMy)
            {
                Widgets.Label(rect, "OCity_Dialog_Exchenge_We_Give".Translate());
                rect.y += 24f;
                EditOrderShowSellThings(ref rect);

                Widgets.Label(rect, "OCity_Dialog_Exchenge_We_Get".Translate());
                rect.y += 24f;
                EditOrderShowBuyThings(ref rect);
            }
            else
            {
                Widgets.Label(rect, "OCity_Dialog_Exchenge_We_Get".Translate());
                rect.y += 24f;
                EditOrderShowBuyThings(ref rect);

                Widgets.Label(rect, "OCity_Dialog_Exchenge_We_Give2".Translate(EditOrder.Owner.Login));
                rect.y += 24f;
                EditOrderShowSellThings(ref rect);
            }

            if (EditOrder.PrivatPlayers == null || EditOrder.PrivatPlayers.Count == 0)
            {
                Widgets.Label(rect, "OCity_Dialog_Exchenge_No_User_Restrictions".Translate());
                rect.y += 24f;
            }
            else
            {
                Widgets.Label(rect, "OCity_Dialog_Exchenge_User_Restrictions".Translate());
                rect.y += 24f;
                for (int i = 0; i < EditOrder.PrivatPlayers.Count; i++)
                {
                    var rect3 = new Rect(rect.x, rect.y, 24f, 24f);
                    Widgets.Label(rect3, EditOrder.PrivatPlayers[i].Login);

                    rect3 = new Rect(rect.xMax - 24f, rect.y, 24f, 24f);
                    if (EditOrderIsMy && Widgets.ButtonImage(rect3, IconDelTex))
                    {
                        EditOrder.PrivatPlayers.RemoveAt(i--);
                    }
                    rect.y += 24f;
                }
            }
            var rect4 = new Rect(rect);

            rect4.width = 150f;
            if (Widgets.ButtonText(rect4.ContractedBy(1f)
                                   , "OCity_Dialog_Exchenge_Add_User".Translate()
                                   , true, false, true))
            {
                SoundDefOf.Tick_High.PlayOneShotOnCamera(null);

                var editOrder = EditOrder;
                var list      = SessionClientController.Data.Players.Keys
                                .Where(p => !editOrder.PrivatPlayers.Any(pp => pp.Login == p) && p != "system")
                                .Select(p => new FloatMenuOption(p,
                                                                 () =>
                {
                    if (editOrder.PrivatPlayers.Any(pp => pp.Login == p))
                    {
                        return;
                    }
                    editOrder.PrivatPlayers.Add(SessionClientController.Data.Players[p].Public);
                }))
                                .ToList();
                if (list.Count == 0)
                {
                    return;
                }
                var menu = new FloatMenu(list);
                Find.WindowStack.Add(menu);

                return;
            }
        }
Exemplo n.º 4
0
 private void SetEditOrder(OrderTrade order)
 {
     EditOrder           = order;
     EditOrderEditBuffer = new Dictionary <long, string>();
     EditOrderChange();
 }
Exemplo n.º 5
0
        public ModelStatus ExchengeEdit(OrderTrade order)
        {
            if (Player == null)
            {
                return(null);
            }
            lock (Player)
            {
                var timeNow = DateTime.UtcNow;

                var data = Repository.GetData;

                if (Player.Public.Login != order.Owner.Login)
                {
                    return(new ModelStatus()
                    {
                        Status = 1,
                        Message = "Ошибка. Ордер другого игрока"
                    });
                }

                if (order.Id == 0)
                {
                    //создать новый

                    //актуализируем
                    order.Created = timeNow;

                    order.Owner = Player.Public;

                    if (order.PrivatPlayers == null)
                    {
                        order.PrivatPlayers = new List <Player>();
                    }
                    order.PrivatPlayers = order.PrivatPlayers
                                          .Select(pp => data.PlayersAll.FirstOrDefault(p => p.Public.Login == pp.Login)?.Public)
                                          .ToList();
                    if (order.PrivatPlayers.Any(pp => pp == null))
                    {
                        return(new ModelStatus()
                        {
                            Status = 2,
                            Message = "Ошибка. Указан несуществующий игрок"
                        });
                    }

                    order.Id = Repository.GetData.GetChatId();

                    lock (data)
                    {
                        data.Orders.Add(order);
                    }
                }
                else
                {
                    //проверяем на существование
                    lock (data)
                    {
                        var id        = order.Id > 0 ? order.Id : -order.Id;
                        var dataOrder = data.Orders.FirstOrDefault(o => o.Id == id);
                        if (dataOrder == null ||
                            Player.Public.Login != dataOrder.Owner.Login)
                        {
                            return(new ModelStatus()
                            {
                                Status = 3,
                                Message = "Ошибка. Ордер не найден"
                            });
                        }

                        if (order.Id > 0)
                        {
                            //редактирование

                            //актуализируем
                            order.Created = timeNow;

                            order.Owner = Player.Public;

                            if (order.PrivatPlayers == null)
                            {
                                order.PrivatPlayers = new List <Player>();
                            }
                            order.PrivatPlayers = order.PrivatPlayers
                                                  .Select(pp => data.PlayersAll.FirstOrDefault(p => p.Public.Login == pp.Login)?.Public)
                                                  .ToList();
                            if (order.PrivatPlayers.Any(pp => pp == null))
                            {
                                return(new ModelStatus()
                                {
                                    Status = 4,
                                    Message = "Ошибка. Указан несуществующий игрок"
                                });
                            }

                            Loger.Log("Server ExchengeEdit " + Player.Public.Login + " Edit Id = " + order.Id.ToString());
                            data.Orders[data.Orders.IndexOf(dataOrder)] = order;
                        }
                        else
                        {
                            //Удаление
                            Loger.Log("Server ExchengeEdit " + Player.Public.Login + " Delete Id = " + order.Id.ToString());
                            data.Orders.Remove(dataOrder);
                        }
                    }
                }
                Repository.Get.ChangeData = true;

                return(new ModelStatus()
                {
                    Status = 0,
                    Message = null
                });
            }
        }
Exemplo n.º 6
0
 public void RegisterTrade(OrderTrade trade)
 {
     Trades.AddOrUpdate(trade);
 }