Пример #1
0
    public void RequestCharacterMove(Point3d roomPosition)
    {
        Debug.Log("GameWorldModel:requestCharacterMove - Requesting move to (" + roomPosition.x + ", " + roomPosition.y + ")");

        if (!IsCharacterMoveRequestPending)
        {
            GameData                  gameData             = SessionData.GetInstance().CurrentGameData;
            CharacterEntity           entity               = GetCharacterEntity(CurrentCharacterID);
            AsyncCharacterMoveRequest characterMoveRequest = null;

            IsCharacterMoveRequestPending = true;

            characterMoveRequest = new AsyncCharacterMoveRequest(m_gameWorldController.gameObject, entity, roomPosition);
            characterMoveRequest.Execute(
                (AsyncCharacterMoveRequest asyncRequest) =>
            {
                IsCharacterMoveRequestPending = false;

                switch (asyncRequest.ResultCode)
                {
                case AsyncCharacterMoveRequest.eResult.success:
                    {
                        Debug.Log("GameWorldModel:requestCharacterMove - Move Succeeded!");

                        // Tell anyone listening on IRC that the game state changed
                        m_gameWorldController.SendCharacterUpdatedGameEvent();
                    }
                    break;

                case AsyncCharacterMoveRequest.eResult.failed_path:
                case AsyncCharacterMoveRequest.eResult.failed_server_denied:
                    {
                        Debug.LogError("GameWorldModel:requestCharacterMove - " + asyncRequest.ResultDetails);
                        m_gameWorldController.OnCharacterActionDisallowed(asyncRequest);
                    }
                    break;

                case AsyncCharacterMoveRequest.eResult.failed_server_connection:
                    {
                        Debug.LogError("GameWorldModel:requestCharacterMove - " + asyncRequest.ResultDetails);
                        m_gameWorldController.OnRequestFailed("Connection Failed!");
                    }
                    break;
                }

                // Parse any incoming game events
                if (asyncRequest.ServerResponse != null)
                {
                    gameData.ParseEventResponse(asyncRequest.ServerResponse);
                }

                // If there were new events, notify the controller so that
                // it can start playing the events back
                if (!gameData.IsEventCursorAtLastEvent)
                {
                    m_gameWorldController.OnGameHasNewEvents();
                }
            });
        }
    }