private void SavePosition()
        {
            MyPosition pos = new MyPosition();
            XmlSerializer serializer = new XmlSerializer(pos.GetType());

            string path = string.Format("{0}_{1}.xml", Name, Instrument);
            using (TextWriter writer = new StreamWriter(path))
            {
                if (null == Position)
                {
                    pos.EntryDate = Clock.Now;
                    pos.Amount = 0;
                    pos.Price = 0;
                }
                else
                {
                    pos.EntryDate = Position.EntryDate;
                    pos.Amount = Position.Amount;
                    pos.Price = Position.GetPrice();
                }

                serializer.Serialize(writer, pos);
                writer.Close();

                Console.WriteLine(string.Format("保存路径:{0},持仓:{1},价格:{2}", path, pos.Amount, pos.Price));
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="symbol">Symbol of position to adjust.</param>
        /// <param name="leverage">Leverage value. Send a number between 0.01 and 100 to enable isolated margin with a fixed leverage. Send 0 to enable cross margin.</param>
        /// <returns></returns>
        public async ValueTask <MyPosition> ChooseLeverage(string symbol, decimal leverage)
        {
            var _result = new MyPosition();

            var _params = new Dictionary <string, object>();
            {
                _params.Add("symbol", symbol);
                _params.Add("leverage", leverage);
            }

            var _response = await privateClient.CallApiPost2Async("/api/v1/position/leverage", _params);

            if (_response != null)
            {
#if RAWJSON
                _result.rawJson = _response.Content;
#endif
                if (_response.IsSuccessful == true)
                {
                    var _position = privateClient.DeserializeObject <BMyPositionItem>(_response.Content);
                    if (_position != null)
                    {
                        _result.result = _position;
                        _result.SetSuccess();
                    }
                }
                else
                {
                    var _message = privateClient.GetResponseMessage(_response);
                    _result.SetFailure(_message.message);
                }
            }

            return(_result);
        }
Esempio n. 3
0
        private void add_btn_Click(object sender, RoutedEventArgs e)
        {
            AddStaffWindow addStaffWindow = new AddStaffWindow();

            if (addStaffWindow.ShowDialog() == true)
            {
                if (addStaffWindow.titleBox.Text == "" || addStaffWindow.IdBox.Text == "" || addStaffWindow.depBox.Text == "" || addStaffWindow.quanBox.SelectedItem == null ||
                    addStaffWindow.nowBox.SelectedItem == null || addStaffWindow.tariffBox.Text == "")

                {
                    MessageBox.Show("Set all new staff's data...");
                }

                else
                {
                    MyStaffTable sSt = new MyStaffTable
                    {
                        IdPosFor = addStaffWindow.IdBox.Text,
                        DepFor   = addStaffWindow.depBox.SelectedItem.ToString(),
                        Quantity = (int)addStaffWindow.quanBox.SelectedItem,
                        Now      = (int)addStaffWindow.nowBox.SelectedItem,
                    };
                    client?.AddStaff(sSt);
                    MyPosition sPs = new MyPosition

                    {
                        PosId     = addStaffWindow.IdBox.Text,
                        PosTitle  = addStaffWindow.titleBox.Text,
                        PosTariff = Convert.ToDouble(addStaffWindow.tariffBox.Text),
                    };
                    client?.AddPosition(sPs);
                    RefreshTwo();
                }
            }
        }
Esempio n. 4
0
        /**
         * This method is managing the click on the main button of the page
         */
        private async void onMainButtonClicked(object sender, EventArgs e)
        {
            switch (state)
            {
            case 0:    //ready to shot
                showRadar();
                map.lockTarget();
                break;

            case 1:    //ready to localize
                MyPosition newUserPosition = await localize();

                MyPosition start = map.getUserPosition();
                partie.addPositionForCurrentHole(start, new MyPosition(map.TargetPin.Position.Latitude, map.TargetPin.Position.Longitude), newUserPosition);
                updateScore();
                map.setUserPosition(newUserPosition, partie.Shots.Count);
                map.setTargetMovable();
                updateDistance();
                showBall();
                break;

            default:    //the user is ready to shot by default
                showBall();
                break;
            }
        }
Esempio n. 5
0
        /**
         * This method is called when clicking on the little relocalize button
         */
        private async void onRelocalizeAction(object sender, EventArgs e)
        {
            MyPosition newUserPosition = await localize();

            map.setUserPosition(newUserPosition, partie.Shots.Count);
            updateDistance();
        }
Esempio n. 6
0
        /**
         * Adds a shot in the shots list using positions in parameters to create it
         * start : the position where the shot was performed
         * target : the position of the target on the map
         * userPosition : the current position of the user (the position where the ball was shot)
         * return the created Shot object
         */
        public Shot addPositionForCurrentHole(MyPosition start, MyPosition target, MyPosition userPosition)
        {
            Shot s = new Shot(CurrentClub, start, target, userPosition, DateTime.Now);

            Shots.Add(s);
            return(s);
        }
Esempio n. 7
0
        private void SavePosition()
        {
            MyPosition    pos        = new MyPosition();
            XmlSerializer serializer = new XmlSerializer(pos.GetType());

            string path = string.Format("{0}_{1}.xml", Name, Instrument);

            using (TextWriter writer = new StreamWriter(path))
            {
                if (null == Position)
                {
                    pos.EntryDate = Clock.Now;
                    pos.Amount    = 0;
                    pos.Price     = 0;
                }
                else
                {
                    pos.EntryDate = Position.EntryDate;
                    pos.Amount    = Position.Amount;
                    pos.Price     = Position.GetPrice();
                }

                serializer.Serialize(writer, pos);
                writer.Close();

                Console.WriteLine(string.Format("保存路径:{0},持仓:{1},价格:{2}", path, pos.Amount, pos.Price));
            }
        }
Esempio n. 8
0
        public static bool CanShoot(MyPosition startPos, MyPosition endPos, SimGame game, SimUnit unit, double bulletSpeed)
        {
            var hitPos = GetHitPos(startPos, endPos, game, bulletSpeed, unit);
            var spread = AimService.GetSpread(unit);
            var posses = spread.Select(s => GetHitPos(startPos, s, game, bulletSpeed, unit)).ToArray();

            foreach (var p in posses)
            {
                LogService.DrawLine(p, unit.Position, 0, 0, 1);
            }

            if (unit.WeaponType == WeaponType.RocketLauncher)
            {
                if (posses.Any(p => p.Dist(unit.TargetEnemy.Position) > p.Dist(unit.Position) && p.Dist(endPos) > unit.Weapon.Parameters.Explosion.Value.Radius - 1))
                {
                    return(false);
                }

                if (unit.TargetEnemy.Position.Dist(endPos) - unit.Weapon.Parameters.Explosion.Value.Radius > unit.Position.Dist(endPos))
                {
                    return(false);
                }
            }

            return(hitPos.Dist(endPos) < 1);
        }
Esempio n. 9
0
 public SimMine(Mine mine)
 {
     Mine      = mine;
     Timer     = _timer = Mine.Timer ?? 1000.0;
     Position  = new MyPosition(mine.Position.X, mine.Position.Y);
     _position = Position.Clone;
 }
Esempio n. 10
0
        public void MostraRotas()
        {
            viewModel.Rotas = new ObservableCollection <RotaModel>();

            List <RotasBD> lista = RotasBD.GetRotas(App.usrCorrente.Email);

            if (lista == null)
            {
                return;
            }

            RotaModel            nova;
            MyPosition           pos;
            List <MyPosition>    posicoes;
            List <CoordenadasBD> bdCoord;

            foreach (RotasBD rota in lista)
            {
                posicoes = new List <MyPosition>();
                bdCoord  = CoordenadasBD.GetCoordenadas(rota.Id);
                foreach (CoordenadasBD coord in bdCoord)
                {
                    pos = new MyPosition(coord.Latitude, coord.Longitude, coord.DataHora);
                    posicoes.Add(pos);
                }

                nova = new RotaModel(rota.Id, rota.DtHrInicial, rota.DtHrFinal,
                                     rota.Distancia, posicoes);
                viewModel.Rotas.Add(nova);
            }

            viewModel.InformaAlteracao("Rotas");
        }
Esempio n. 11
0
        public SimUnit(Unit unit)
        {
            MaxHealth    = Const.Properties.UnitMaxHealth;
            Unit         = this.unit = unit;
            Id           = unit.Id;
            HasWeapon    = unit.Weapon.HasValue;
            Weapon       = HasWeapon ? unit.Weapon.Value : new Weapon();
            WeaponType   = unit.Weapon.HasValue ? unit.Weapon.Value.Typ : WeaponType.Pistol;
            MaxFireTimer = unit.Weapon.HasValue ? unit.Weapon.Value.Parameters.FireRate : 10000;
            Rounds       = _rounds = HasWeapon ? unit.Weapon.Value.Magazine : 0;
            Magazine     = HasWeapon ? unit.Weapon.Value.Parameters.MagazineSize : 0;
            ReloadTime   = HasWeapon ? unit.Weapon.Value.Parameters.ReloadTime : 1;

            FireTimer    = _fireTimer = unit.Weapon.HasValue ? (unit.Weapon.Value.FireTimer ?? 0) : 10000;
            TeamId       = unit.PlayerId;
            Health       = _health = unit.Health;
            HalfWidth    = unit.Size.X / 2;
            HalffHeight  = unit.Size.Y / 2;
            Position     = new MyPosition(unit.Position.X, unit.Position.Y + HalffHeight);
            _position    = Position.Clone;
            JumpTime     = _jumpTime = unit.JumpState.MaxTime > 0 ? unit.JumpState.MaxTime : (unit.JumpState.CanJump ? MaxJumpTime : 0);
            CanJump      = unit.JumpState.CanJump;
            Speed        = unit.JumpState.Speed;
            CanCancel    = unit.JumpState.CanCancel;
            Spread       = _spread = unit.Weapon.HasValue ? unit.Weapon.Value.Spread : 0;
            MaxSpread    = unit.Weapon.HasValue ? unit.Weapon.Value.Parameters.MaxSpread : 0;
            MinSpread    = unit.Weapon.HasValue ? unit.Weapon.Value.Parameters.MinSpread : 0;
            SpreadChange = unit.Weapon.HasValue ? unit.Weapon.Value.Parameters.AimSpeed : 0;
            Recoil       = unit.Weapon.HasValue ? unit.Weapon.Value.Parameters.Recoil : 0;
            AimAngle     = _aimAngle = unit.Weapon.HasValue ? unit.Weapon.Value.LastAngle ?? 0.0 : 0.0;
        }
Esempio n. 12
0
        // Find all reachable tiles.

        public static void DrawPath(MyPosition p1, MyPosition p2)
        {
            var k = 0;

            LogService.WriteLine("DIST: " + DistService.GetDist(p1, p2));
            while ((int)p1.X != (int)p2.X || (int)p1.Y != (int)p2.Y)
            {
                k++;
                if (k > 30)
                {
                    return;
                }
                var best     = p1;
                var bestDist = 100000000.0;
                for (var i = 0; i < 4; i++)
                {
                    var xx = (int)p1.X + dxes[i];
                    var yy = (int)p1.Y + dyes[i];
                    if (!Game.OnBoard(xx, yy) || Game.GetTile(xx, yy) == AiCup2019.Model.Tile.Wall)
                    {
                        continue;
                    }
                    //LogService.DrawLineBetweenCenter(p1, new MyPosition(xx, yy), 0, 0, 1);
                    var newPos = new MyPosition(xx, yy);
                    var dist   = GetDist(p2, newPos);
                    if (dist < bestDist)
                    {
                        best     = newPos;
                        bestDist = dist;
                    }
                }
                LogService.DrawLineBetweenCenter(p1, best, 0, 0, 1);
                p1 = best;
            }
        }
        private void LoadPosition()
        {
            MyPosition pos = new MyPosition();
            XmlSerializer serializer = new XmlSerializer(pos.GetType());

            string path = string.Format("{0}_{1}.xml", Name, Instrument);

            try
            {
                using (FileStream stream = new FileStream(path, FileMode.Open))
                {
                    pos = (MyPosition)serializer.Deserialize(stream);
                    stream.Close();

                    if (pos.Amount != 0)
                    {
                        Portfolio.Add(pos.EntryDate, pos.Amount > 0 ? TransactionSide.Buy : TransactionSide.Sell,
                            Math.Abs(pos.Amount), Instrument, pos.Price, "从XML中初始化");
                    }

                    Console.WriteLine(string.Format("加载路径:{0},持仓:{1},价格:{2}", path,pos.Amount,pos.Price));
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Esempio n. 14
0
        private void LoadPosition()
        {
            MyPosition    pos        = new MyPosition();
            XmlSerializer serializer = new XmlSerializer(pos.GetType());

            string path = string.Format("{0}_{1}.xml", Name, Instrument);

            try
            {
                using (FileStream stream = new FileStream(path, FileMode.Open))
                {
                    pos = (MyPosition)serializer.Deserialize(stream);
                    stream.Close();

                    if (pos.Amount != 0)
                    {
                        Portfolio.Add(pos.EntryDate, pos.Amount > 0 ? TransactionSide.Buy : TransactionSide.Sell,
                                      Math.Abs(pos.Amount), Instrument, pos.Price, "从XML中初始化");
                    }

                    Console.WriteLine(string.Format("加载路径:{0},持仓:{1},价格:{2}", path, pos.Amount, pos.Price));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Esempio n. 15
0
 public static int GetDist(MyPosition p1, MyPosition p2)
 {
     if (!Game.game.OnBoard(p1.X, p1.Y) || !Game.game.OnBoard(p2.X, p2.Y))
     {
         return((int)p1.Dist(p2));
     }
     return(Dists[Game.GetPos((int)p1.X, (int)p1.Y), Game.GetPos((int)p2.X, (int)p2.Y)]);
 }
Esempio n. 16
0
 public static void DrawLine(MyPosition p1, MyPosition p2, float r, float g, float b)
 {
     if (!m_debug)
     {
         return;
     }
     MyStrategy.Debug.Draw(new Line(p1.CreateFloatVec, p2.CreateFloatVec, 0.1f, new ColorFloat(r, g, b, 1)));
 }
Esempio n. 17
0
        public PaginaInicial()
        {
            InitializeComponent();
            viewModel           = new PaginaInicialViewModel();
            this.BindingContext = viewModel;

            ColetandoDadosGPS = false;
            ultPosicao        = null;
        }
Esempio n. 18
0
        public static MyPosition GetHitPos(MyPosition startPos, MyPosition endPos, SimGame game, double bulletSpeed, SimUnit firering, bool stopOnEnd = true)
        {
            var dist = endPos.Dist(startPos);
            var time = GetShootTime(dist, bulletSpeed) * Const.Properties.TicksPerSecond * 15;
            var dx   = (endPos.X - startPos.X) / time;
            var dy   = (endPos.Y - startPos.Y) / time;
            var x    = startPos.X;
            var y    = startPos.Y;
            var d    = startPos.Dist(endPos);

            for (var i = 0; i < time * 2; i++)
            {
                x += dx;
                y += dy;
                if (!game.game.OnBoard(x, y))
                {
                    return(new MyPosition(x, y));
                }
                var tile = game.GetTileD(x, y);
                if (tile == Tile.Wall)
                {
                    return(new MyPosition(x, y));
                }
                tile = game.GetTileD(x - firering.Weapon.Parameters.Bullet.Size * 0.5, y - firering.Weapon.Parameters.Bullet.Size * 0.5);
                if (tile == Tile.Wall)
                {
                    return(new MyPosition(x, y));
                }
                tile = game.GetTileD(x + firering.Weapon.Parameters.Bullet.Size * 0.5, y - firering.Weapon.Parameters.Bullet.Size * 0.5);
                if (tile == Tile.Wall)
                {
                    return(new MyPosition(x, y));
                }
                var nextD = Math.Sqrt(MyPosition.Pow(x - endPos.X) + MyPosition.Pow(y - endPos.Y));
                if (nextD > d && stopOnEnd || nextD < 0.3)
                {
                    return(endPos);
                }
                d = nextD;
                foreach (var u in game.Units)
                {
                    if (u == firering || u.unit.PlayerId != firering.unit.PlayerId)
                    {
                        continue;
                    }
                    var unit = u.unit;
                    if (!(Math.Abs(x - unit.Position.X) > firering.Weapon.Parameters.Bullet.Size / 2 + unit.Size.X / 2 ||
                          Math.Abs(y - unit.Position.Y) > firering.Weapon.Parameters.Bullet.Size / 2 + unit.Size.Y / 2))
                    {
                        return(new MyPosition(x, y));
                    }
                }
            }

            return(endPos);
        }
Esempio n. 19
0
 public static void DrawLineBetweenCenter(MyPosition p1, MyPosition p2, float r, float g, float b)
 {
     if (!m_debug)
     {
         return;
     }
     p1 = new MyPosition(p1.X + 0.5, p1.Y + 0.5);
     p2 = new MyPosition(p2.X + 0.5, p2.Y + 0.5);
     MyStrategy.Debug.Draw(new Line(p1.CreateFloatVec, p2.CreateFloatVec, 0.1f, new ColorFloat(r, g, b, 1)));
 }
Esempio n. 20
0
        /**
         * Localizes the user with his GPS
         * return a MyPosition class wrapping the longitude and latitude of the user current position
         */
        public async Task <MyPosition> localize()
        {
            backToRadar.IsVisible = false;
            showLoad();
            MyPosition position = await GpsService.getCurrentPosition();

            showBall();
            backToRadar.IsVisible = true;
            return(position);
        }
Esempio n. 21
0
 public Shot(Club currentClub, MyPosition initPlace, MyPosition target, MyPosition realShot, DateTime date)
 {
     this.Club          = currentClub;
     this.InitPlace     = initPlace;
     this.Target        = target;
     this.RealShot      = realShot;
     this.Date          = date;
     this.PenalityCount = 0;
     this.ShotType      = determineShotCategory();
 }
Esempio n. 22
0
        private static void FlyToTarget(SimBullet bullet, double angle, MyPosition start, int unitId)
        {
            bullet.UnitId = unitId;
            bullet.Position.UpdateFrom(start);
            var dx = Math.Cos(angle) * bullet.Speed;
            var dy = Math.Sin(angle) * bullet.Speed;

            bullet.Dx           = dx;
            bullet.Dy           = dy;
            bullet.IsDead       = false;
            bullet.IsSimCreated = true;
        }
Esempio n. 23
0
 public SimBullet(Bullet bullet)
 {
     this.bullet   = bullet;
     UnitId        = bullet.UnitId;
     Speed         = Math.Sqrt(bullet.Velocity.X * bullet.Velocity.X + bullet.Velocity.Y * bullet.Velocity.Y);
     Position      = new MyPosition(bullet.Position.X, bullet.Position.Y);
     _position     = Position.Clone;
     Dx            = bullet.Velocity.X;
     Dy            = bullet.Velocity.Y;
     HalfSize      = bullet.Size / 2 + bullet.Size * 0.1;
     ExplosionSize = bullet.ExplosionParameters.HasValue ? bullet.ExplosionParameters.Value.Radius : 0.0;
 }
Esempio n. 24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="base_name">The type of trading base-currency of which information you want to query for.</param>
        /// <param name="quote_name">The type of trading quote-currency of which information you want to query for.</param>
        /// <param name="leverage"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public async Task <MyPosition> ChooseLeverage(string base_name, string quote_name, decimal leverage, Dictionary <string, object> args = null)
        {
            var _result = new MyPosition(base_name, quote_name);

            var _market = await publicApi.LoadMarket(_result.marketId);

            if (_market.success == true)
            {
                tradeClient.ExchangeInfo.ApiCallWait(TradeType.Trade);

                var _params = new Dictionary <string, object>();
                {
                    _params.Add("symbol", _market.result.symbol);
                    _params.Add("leverage", leverage);

                    if (args != null)
                    {
                        foreach (var _a in args)
                        {
                            if (_params.ContainsKey(_a.Key) == true)
                            {
                                _params.Remove(_a.Key);
                            }

                            _params.Add(_a.Key, _a.Value);
                        }
                    }
                }

                var _json_value = await tradeClient.CallApiPut1Async("/api/v1/position/leverage", _params);

#if DEBUG
                _result.rawJson = _json_value.Content;
#endif
                var _json_result = tradeClient.GetResponseMessage(_json_value.Response);
                if (_json_result.success == true)
                {
                    var _position = tradeClient.DeserializeObject <BMyPositionItem>(_json_value.Content);
                    {
                        _result.result = _position;
                    }
                }

                _result.SetResult(_json_result);
            }
            else
            {
                _result.SetResult(_market);
            }

            return(_result);
        }
Esempio n. 25
0
        public static bool CanShootAt(MyPosition pos, MyPosition target)
        {
            var y  = (int)target.Y;
            var y2 = (int)(target.Y + Const.HalfUnitHeight);

            if (y == y2)
            {
                return(canShootMap[Const.GetPos((int)pos.X, (int)pos.Y), Const.GetPos((int)target.X, y)]);
            }

            return(canShootMap[Const.GetPos((int)pos.X, (int)pos.Y), Const.GetPos((int)target.X, y)] ||
                   canShootMap[Const.GetPos((int)pos.X, (int)pos.Y), Const.GetPos((int)target.X, y2)]);
        }
Esempio n. 26
0
        /**
         * Methode allant chercher des infos sur une API web pour retrouver des infos concernant le vent.
         */
        /*async*/
        public async Task <WindInfo> getCurrentWindInfo(MyPosition position)
        {
            if (!isAvaible())
            {
                throw new NotAvaibleException();
            }
            position = await GpsService.getCurrentPosition();

            string fullUrl = url + appid + "&lat=" + position.X + "&lon=" + position.Y;

            img = ImageSource.FromResource("GreenSa.Ressources.Images.left-arrow.png");

            return(await FetchData(fullUrl));
        }
Esempio n. 27
0
        public static void DrawSquare(MyPosition position, double width, double height, float r, float g, float b)
        {
            if (!m_debug)
            {
                return;
            }
            var x1 = position.X - width / 2;
            var x2 = position.X + width / 2;
            var y1 = position.Y - height / 2;
            var y2 = position.Y + height / 2;

            DrawLine(new MyPosition(x1, y1), new MyPosition(x2, y1), r, g, b);
            DrawLine(new MyPosition(x2, y1), new MyPosition(x2, y2), r, g, b);
            DrawLine(new MyPosition(x2, y2), new MyPosition(x1, y2), r, g, b);
            DrawLine(new MyPosition(x1, y2), new MyPosition(x1, y1), r, g, b);
        }
Esempio n. 28
0
        public void Fire(MyPosition target, SimGame game)
        {
            if (!HasWeapon || FireTimer > 0 || Rounds <= 0)
            {
                return;
            }

            var newAngle = Math.Atan2(target.Y - Position.Y, target.X - Position.X);
            var diff     = Math.Abs(AimAngle - newAngle);

            if (diff > Math.PI)
            {
                var newDiff = Math.Abs(AimAngle - (newAngle - Math.PI * 2));
                if (newDiff < diff)
                {
                    diff = newDiff;
                }
            }
            AimAngle = newAngle;
            if (AimAngle < 0)
            {
                AimAngle += Math.PI * 2;
            }
            else if (AimAngle > Math.PI * 2)
            {
                AimAngle -= Math.PI * 2;
            }
            Spread = Math.Max(MinSpread, Math.Min(MaxSpread, Spread + diff));

            if (debug)
            {
                LogService.DrawLine(Position, new MyPosition(Position.X + Math.Cos(AimAngle) * 10, Position.Y + Math.Sin(AimAngle) * 10), 0, 0, 1);
            }

            //var bullets = BulletFactory.GetBullets(WeaponType, Position, newAngle, Id, Spread);
            //game.Bullets.AddRange(bullets);
            Spread += Recoil;
            Rounds--;
            FireTimer = MaxFireTimer;
            if (Rounds <= 0)
            {
                FireTimer = ReloadTime;
                Rounds    = Magazine;
            }

            Score += 0.5 * (MaxSpread - MinSpread) / Math.Max(0.01, Spread - MinSpread);
        }
Esempio n. 29
0
        void ProcessMessage(ClientConnection client, MyPosition message)
        {
            if (client.Avatar == null)
            {
                _log.Warn("Position message from client " + client.RemoteEndPoint + " who has no avatar.");
                return;
            }
            var ma = (MobileAvatar)client.Avatar;

            if (message.Position != client.Avatar.Position)
            {
                ma.LastMoveUpdate = Global.Now;
            }
            ma.SetMobileState(message.State);

            _world.Relocate(client.Avatar, message.Position, message.Rotation);
        }
Esempio n. 30
0
        public static MyPosition FindWalkTarget(SimGame game, SimUnit unit)
        {
            var target = GetRealTarget(game, unit);

            for (var y = (int)target.Y; y < game.game.Height; y++)
            {
                var p = new MyPosition(target.X, y);
                var d = DistService.GetDist(p, unit.Position);
                if (d < game.game.Width * game.game.Height * 4)
                {
                    target = p;
                    break;
                }
            }

            LogService.DrawLine(target, unit.Position, 1, 0, 0);
            return(target);
        }
Esempio n. 31
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="base_name">The type of trading base-currency of which information you want to query for.</param>
        /// <param name="quote_name">The type of trading quote-currency of which information you want to query for.</param>
        /// <param name="leverage"></param>
        /// <param name="args">Add additional attributes for each exchange</param>
        /// <returns></returns>
        public async Task <MyPosition> ChooseLeverage(string base_name, string quote_name, decimal leverage, Dictionary <string, object> args = null)
        {
            var _result = new MyPosition(base_name, quote_name);

            var _market = await publicApi.LoadMarketAsync(_result.marketId);

            if (_market.success == true)
            {
                tradeClient.ExchangeInfo.ApiCallWait(TradeType.Trade);

                var _params = tradeClient.MergeParamsAndArgs(
                    new Dictionary <string, object>
                {
                    { "symbol", _market.result.symbol },
                    { "leverage", leverage }
                },
                    args
                    );

                var _json_value = await tradeClient.CallApiPost1Async("/api/v1/position/leverage", _params);

#if RAWJSON
                _result.rawJson = _json_value.Content;
#endif
                var _json_result = tradeClient.GetResponseMessage(_json_value.Response);
                if (_json_result.success == true)
                {
                    var _position = tradeClient.DeserializeObject <BMyPositionItem>(_json_value.Content);
                    {
                        _result.result = _position;
                    }
                }

                _result.SetResult(_json_result);
            }
            else
            {
                _result.SetResult(_market);
            }

            return(_result);
        }
Esempio n. 32
0
        //
        // Evento: posição corrente do usuário foi alterada
        //
        private void PositionChanged(object sender, PositionEventArgs e)
        {
            var position = e.Position;

            // verifica se posição realmente mudou
            if (ultPosicao != null)
            {
                if ((ultPosicao.Latitude == position.Latitude) &&
                    (ultPosicao.Longitude == position.Longitude))
                {
                    return;
                }
            }

            MyPosition pos = new MyPosition(position.Latitude, position.Longitude, DateTime.Now);

            // cria uma nova lista a partir da lista já existente e adiciona novo elemento "pos"
            var list = new List <MyPosition>(mapVisualizacao.RouteCoordinates)
            {
                pos
            };

            mapVisualizacao.RouteCoordinates = list;

            mapVisualizacao.MoveToRegion(
                MapSpan.FromCenterAndRadius(
                    new Xamarin.Forms.Maps.Position(pos.Latitude, pos.Longitude),
                    Distance.FromMeters(250.0)
                    )
                );

            // calcula distância entre as coordenadas
            if (list.Count > 1)
            {
                viewModel.DistTotal +=
                    DependencyService.Get <IDeviceSpecific>().CalculaDistancia(pos.Latitude, pos.Longitude,
                                                                               ultPosicao.Latitude, ultPosicao.Longitude);
                viewModel.InformaAlteracao("DistTotal");
            }

            ultPosicao = pos;
        }