Exemplo n.º 1
0
        protected KickOffResponseDTO ProcessKickOff(KickOffRequestDTO request)
        {
            if (request.eventType == null)
            {
                return(null);
            }

            InitializeGameVariables(request);
            var k = SetPlayerPositionAccordingToAbilities(request);

            k.requestType = "KICKOFF";
            return(k);
        }
Exemplo n.º 2
0
        private KickOffResponseDTO SetPlayerPositionAccordingToAbilities(KickOffRequestDTO request)
        {
            var    k = new KickOffResponseDTO();
            double initialPosition = 90;

            k.players = new KickOffPlayer[teamInfo.players.Length];
            var dirAngle = 270;

            if (goalPostDirection == DirectionType.RIGHT)
            {
                dirAngle        = 90;
                initialPosition = 10;
            }

            var gkPos = new Position {
                x = goalPostBottom.x, y = fieldInfo.pitch.height / 2
            };

            k.players[0] = new KickOffPlayer()
            {
                direction    = dirAngle,
                playerNumber = goalKeeper.playerNumber,
                position     = gkPos
            };

            var pos = GetHotlistedGridCells(new Position {
                x = initialPosition, y = fieldInfo.pitch.height / 2
            }, goalPostDirection);
            var remainingNumbers = playerAbilities
                                   .OrderByDescending(p => p.runningAbility)
                                   .ThenByDescending(p => p.ballControlAbility)
                                   .ThenByDescending(p => p.kickingAbility)
                                   .ThenByDescending(p => p.tacklingAbility)
                                   .Where(p => p.playerNumber != goalKeeper.playerNumber)
                                   .Select(p => p.playerNumber).ToArray();

            if (goalPostDirection == DirectionType.LEFT)
            {
                pos = pos.OrderByDescending(p => p.x).ToList();
            }
            else
            {
                pos = pos.OrderBy(p => p.x).ToList();
            }

            for (int i = 1; i < k.players.Count(); i++)
            {
                Position position;
                if (teamInfo.teamNumber == request.teamKickingOff && i == 1)
                {
                    position = new Position {
                        x = fieldInfo.pitch.width / 2, y = fieldInfo.pitch.height / 2
                    };
                }
                {
                    position = pos[i - 1];
                }

                if (targetPlayer != null && remainingNumbers[i - 1] == targetPlayer.staticState.playerNumber)
                {
                    k.players[i] = new KickOffPlayer()
                    {
                        direction    = dirAngle,
                        playerNumber = remainingNumbers[i - 1],
                        position     = targetPlayer.dynamicState.position
                    };
                }
                else
                {
                    k.players[i] = new KickOffPlayer()
                    {
                        direction    = dirAngle,
                        playerNumber = remainingNumbers[i - 1],
                        position     = position
                    };
                }
            }
            targetPlayer = null;
            return(k);
        }
Exemplo n.º 3
0
        private void InitializeGameVariables(KickOffRequestDTO request)
        {
            Position circleCenter, circleCenterOpposition;
            var      xcor = fieldInfo.pitch.width;

            if (teamInfo.teamNumber == 1)
            {
                direction = request.team1.direction;
            }
            else
            {
                direction = request.team2.direction;
            }

            if (direction == "RIGHT")
            {
                goalPostDirection   = DirectionType.RIGHT;
                goalPostTopOpponent = new Position {
                    x = xcor, y = fieldInfo.pitch.goalY1
                };
                goalPostBottomOpponent = new Position {
                    x = xcor, y = fieldInfo.pitch.goalY2
                };
                goalPostTop = new Position {
                    x = 100 - xcor, y = fieldInfo.pitch.goalY1
                };
                goalPostBottom = new Position {
                    x = 100 - xcor, y = fieldInfo.pitch.goalY2
                };
                circleCenter = new Position {
                    x = 0, y = fieldInfo.pitch.height / 2
                };
                circleCenterOpposition = new Position {
                    x = fieldInfo.pitch.width, y = circleCenter.y
                };
            }
            else
            {
                goalPostDirection = DirectionType.LEFT;
                goalPostTop       = new Position {
                    x = xcor, y = fieldInfo.pitch.goalY1
                };
                goalPostBottom = new Position {
                    x = xcor, y = fieldInfo.pitch.goalY2
                };
                goalPostTopOpponent = new Position {
                    x = 100 - xcor, y = fieldInfo.pitch.goalY1
                };
                goalPostBottomOpponent = new Position {
                    x = 100 - xcor, y = fieldInfo.pitch.goalY2
                };
                circleCenter = new Position {
                    x = fieldInfo.pitch.width, y = fieldInfo.pitch.height / 2
                };
                circleCenterOpposition = new Position {
                    x = 0, y = circleCenter.y
                };
            }

            goalPostMid           = circleCenter;
            goalPostOppositionMid = circleCenterOpposition;
        }