Esempio n. 1
0
        internal void MoveBall(RoomItem item, GameClient client, Point user)
        {
            try
            {
                item.ComeDirection = ComeDirection.GetComeDirection(user, item.Coordinate);

                if (item.ComeDirection != IComeDirection.Null)
                {
                    // item.ballMover = client;
                    new TaskFactory().StartNew(() => MoveBallProcess(item, client));
                }
            }
            catch
            {
            }
        }
Esempio n. 2
0
        internal async void MoveBallProcess(RoomItem item, GameClient client)
        {
            int tryes = 0;
            int newX  = item.Coordinate.X;
            int newY  = item.Coordinate.Y;

            //while (tryes < 3)
            {
                if (_room == null || _room.GetGameMap() == null)
                {
                    return;
                }

                int total = item.ExtraData == "55" ? 6 : 1;
                for (int i = 0; i != total; i++)
                {
                    if (item.ComeDirection == IComeDirection.Null)
                    {
                        item.BallIsMoving = false;
                        break;
                    }

                    int resetX = newX;
                    int resetY = newY;

                    ComeDirection.GetNewCoords(item.ComeDirection, ref newX, ref newY);

                    bool ignoreUsers = false;

                    if (_room.GetGameMap().SquareHasUsers(newX, newY))
                    {
                        if (item.ExtraData != "55" && item.ExtraData != "44")
                        {
                            item.BallIsMoving = false;
                            break;
                        }
                        ignoreUsers = true;
                    }

                    if (ignoreUsers == false)
                    {
                        if (!_room.GetGameMap().ItemCanBePlacedHere(newX, newY))
                        {
                            item.ComeDirection = ComeDirection.InverseDirections(_room, item.ComeDirection, newX, newY);
                            newX = resetX;
                            newY = resetY;
                            tryes++;
                            if (tryes > 2)
                            {
                                item.BallIsMoving = false;
                            }
                            continue;
                        }
                    }

                    if (MoveBall(item, client, newX, newY))
                    {
                        item.BallIsMoving = false;
                        break;
                    }

                    int number;
                    int.TryParse(item.ExtraData, out number);
                    if (number > 11)
                    {
                        item.ExtraData = (int.Parse(item.ExtraData) - 11).ToString();
                    }

                    await Task.Delay(90);
                }

                item.BallValue++;

                if (item.BallValue <= 6)
                {
                    return;
                }
                item.BallIsMoving = false;
                item.BallValue    = 1;
                //break;
            }
        }
Esempio n. 3
0
        internal void OnUserWalk(RoomUser user)
        {
            if (user == null)
            {
                return;
            }

            foreach (RoomItem ball in _balls.Values)
            {
                if (user.SetX == ball.X && user.SetY == ball.Y && user.GoalX == ball.X && user.GoalY == ball.Y &&
                    user.HandelingBallStatus == 0) // super chute.
                {
                    Point userPoint = new Point(user.X, user.Y);
                    ball.ExtraData    = "55";
                    ball.BallIsMoving = true;
                    ball.BallValue    = 1;
                    MoveBall(ball, user.GetClient(), userPoint);
                }
                else if (user.X == ball.X && user.Y == ball.Y && user.HandelingBallStatus == 0)
                {
                    Point userPoint = new Point(user.SetX, user.SetY);
                    ball.ExtraData    = "55";
                    ball.BallIsMoving = true;
                    ball.BallValue    = 1;
                    MoveBall(ball, user.GetClient(), userPoint);
                }
                else
                {
                    if (user.HandelingBallStatus == 0 && user.GoalX == ball.X && user.GoalY == ball.Y)
                    {
                        return;
                    }

                    if (user.SetX != ball.X || user.SetY != ball.Y || !user.IsWalking ||
                        (user.X == user.GoalX && user.Y == user.GoalY))
                    {
                        return;
                    }
                    user.HandelingBallStatus = 1;
                    IComeDirection comeDirection = ComeDirection.GetComeDirection(new Point(user.X, user.Y), ball.Coordinate);
                    if (comeDirection == IComeDirection.Null)
                    {
                        return;
                    }

                    int newX = user.SetX;
                    int newY = user.SetY;

                    if (!ball.GetRoom().GetGameMap().ValidTile2(user.SetX, user.SetY) ||
                        !ball.GetRoom().GetGameMap().ItemCanBePlacedHere(user.SetX, user.SetY))
                    {
                        comeDirection = ComeDirection.InverseDirections(_room, comeDirection, user.X, user.Y);
                        newX          = ball.X;
                        newY          = ball.Y;
                    }

                    ComeDirection.GetNewCoords(comeDirection, ref newX, ref newY);
                    ball.ExtraData = "11";
                    MoveBall(ball, user.GetClient(), newX, newY);
                }
            }
        }