public override void ApplyEvent(GameWorldController gameWorldController, GameEvent.OnEventCompleteDelegate onComplete)
    {
        GameData currentGame = gameWorldController.Model.CurrentGame;

        if (currentGame.CharacterID != _characterState.character_id)
        {
            base.ApplyEvent(gameWorldController, onComplete);

            // Add the character state to the current game state
            currentGame.SetCharacterById(_characterState.character_id, _characterState);

            // Create a new character entity using the character data just set in the game state
            {
                CharacterEntity characterEntity = new CharacterEntity(_characterState.character_id);

                characterEntity.AddToGameWorld(gameWorldController);
            }
        }
        else
        {
            Debug.Log("Ignoring apply CharacterJoinedGame event for primary character_id=" + _characterState.character_id);
        }

        // Completes immediately
        if (onComplete != null)
        {
            onComplete();
        }
    }
Exemplo n.º 2
0
    public override void ApplyEvent(GameWorldController gameWorldController, GameEvent.OnEventCompleteDelegate onComplete)
    {
        GameData currentGame = gameWorldController.Model.CurrentGame;

        if (currentGame.CharacterID != _characterState.character_id)
        {
            base.ApplyEvent(gameWorldController, onComplete);

            // Add the character state to the current game state
            currentGame.SetCharacterById(_characterState.character_id, _characterState);

            // Create a new character entity using the character data just set in the game state
            {
                CharacterEntity characterEntity = new CharacterEntity(_characterState.character_id);

                characterEntity.AddToGameWorld(gameWorldController);
            }
        }
        else
        {
            Debug.Log("Ignoring apply CharacterJoinedGame event for primary character_id=" + _characterState.character_id);
        }

        // Completes immediately
        if (onComplete != null)
        {
            onComplete();
        }
    }
    public override void ApplyEvent(GameWorldController gameWorldController, OnEventCompleteDelegate onComplete)
    {
        base.ApplyEvent(gameWorldController, onComplete);

        CharacterData character = gameWorldController.Model.GetCharacterData(CharacterID);

        // Update the room key and position on the character that changed rooms
        character.room_x = ToRoomKey.x;
        character.room_y = ToRoomKey.y;
        character.room_z = ToRoomKey.z;
        character.x      = ToPosition.x;
        character.y      = ToPosition.y;
        character.z      = ToPosition.z;

        // Character is the current game character
        if (CharacterID == gameWorldController.Model.CurrentCharacterID)
        {
            // Request the static room data for the room the character is portal-ing to
            // event application won't advance while waiting on room data to load from the server.
            // Once we get the new room data we rebuild everything.
            gameWorldController.Model.RequestRoomData(ToRoomKey, onComplete);
        }
        // Character is some other game character
        else
        {
            // Get the character entity for the character id, if any exists
            CharacterEntity entity = gameWorldController.Model.GetCharacterEntity(CharacterID);

            // Character portal-ed to the current room.
            // Make sure the character exists and is at the correct location.
            if (gameWorldController.Model.CurrentGame.CurrentRoomKey.Equals(ToRoomKey))
            {
                if (entity == null)
                {
                    entity = new CharacterEntity(CharacterID);
                    entity.AddToGameWorld(gameWorldController);
                }

                entity.SnapTo(ToPosition, ToAngle);
            }
            // Character left the current room.
            // Make sure the character entity is cleaned up.
            else
            {
                if (entity != null)
                {
                    entity.RemoveFromGameWorld(gameWorldController);
                }
            }

            if (onComplete != null)
            {
                onComplete();
            }
        }
    }
    public override void UndoEvent(GameWorldController gameWorldController)
    {
        CharacterData character = gameWorldController.Model.GetCharacterData(CharacterID);

        // Update the room key and position on the character that changed rooms
        character.room_x = FromRoomKey.x;
        character.room_y = FromRoomKey.y;
        character.room_z = FromRoomKey.z;
        character.x      = FromPosition.x;
        character.y      = FromPosition.y;
        character.z      = FromPosition.z;

        // Character is the current game character
        if (CharacterID == gameWorldController.Model.CurrentCharacterID)
        {
            // Request the static room data for the room the character portal-ed from
            // event application won't advance while waiting on room data to load from the server.
            // Once we get the new room data we rebuild everything.
            gameWorldController.Model.RequestRoomData(FromRoomKey, null);
        }
        // Character is some other game character
        else
        {
            // Get the character entity for the character id, if any exists
            CharacterEntity entity = gameWorldController.Model.GetCharacterEntity(CharacterID);

            // Character portal-ed from the current room.
            // Make sure the character exists and is at the correct location.
            if (gameWorldController.Model.CurrentGame.CurrentRoomKey.Equals(FromRoomKey))
            {
                if (entity == null)
                {
                    entity = new CharacterEntity(CharacterID);
                    entity.AddToGameWorld(gameWorldController);
                }

                entity.SnapTo(FromPosition, FromAngle);
            }
            // Character from some other room than the current one.
            // Make sure the character entity is cleaned up.
            else
            {
                if (entity != null)
                {
                    entity.RemoveFromGameWorld(gameWorldController);
                }
            }
        }

        base.UndoEvent(gameWorldController);
    }
    public override void UndoEvent(GameWorldController gameWorldController)
    {
        GameData currentGame = gameWorldController.Model.CurrentGame;

        if (currentGame.CharacterID != _characterState.character_id)
        {
            // Add the character state back into to the current game state
            gameWorldController.Model.CurrentGame.SetCharacterById(_characterState.character_id, _characterState);

            // Create a new character entity using the character data just set in the game state
            {
                CharacterEntity characterEntity = new CharacterEntity(_characterState.character_id);

                characterEntity.AddToGameWorld(gameWorldController);
            }

            base.UndoEvent(gameWorldController);
        }
        else
        {
            Debug.Log("Ignoring undo CharacterLeftGame event for primary character_id=" + _characterState.character_id);
        }
    }
    public void OnRoomLoaded(RoomKey roomKey)
    {
        RoomData currentRoom = m_gameWorldModel.GetRoomData(roomKey);

        // Get a list of all the characters that are in the same room as my character
        List <int> characterIDList = m_gameWorldModel.GetCharacterIDListInRoom(roomKey);

        // Remove any existing character
        List <int> allCharacterIds = new List <int>(m_gameWorldModel.GetCharacterEntityMap().Keys);

        foreach (int characterEntityId in allCharacterIds)
        {
            CharacterEntity characterEntity = m_gameWorldModel.GetCharacterEntity(characterEntityId);

            characterEntity.RemoveFromGameWorld(this);
        }

        // (Re)Create character entities for each character in the room
        foreach (int characterID in characterIDList)
        {
            CharacterEntity newCharacterEntity = new CharacterEntity(characterID);

            newCharacterEntity.AddToGameWorld(this);
        }

        // Remove any existing mobs
        List <int> allMobIds = new List <int>(m_gameWorldModel.GetMobEntityMap().Keys);

        foreach (int mobEntityId in allMobIds)
        {
            MobEntity mobEntity = m_gameWorldModel.GetMobEntity(mobEntityId);

            mobEntity.RemoveFromGameWorld(this);
        }

        // (Re)Create mob entities for each mob in the room
        foreach (MobData mobData in currentRoom.MobMap.Values)
        {
            MobEntity newMobEntity = new MobEntity(mobData.mob_id);

            newMobEntity.AddToGameWorld(this);
        }

        // Remove any existing energy tanks
        List <int> allEnergyTankIds = new List <int>(m_gameWorldModel.GetEnergyTankEntityMap().Keys);

        foreach (int energyTankId in allEnergyTankIds)
        {
            EnergyTankEntity energyTankEntity = m_gameWorldModel.GetEnergyTankEntity(energyTankId);

            energyTankEntity.RemoveFromGameWorld(this);
        }

        // (Re)Create energy tank entities for each energy tank in the room
        foreach (EnergyTankData energyTankData in currentRoom.EnergyTankMap.Values)
        {
            EnergyTankEntity newEnergyTankEntity = new EnergyTankEntity(energyTankData.energy_tank_id);

            newEnergyTankEntity.AddToGameWorld(this);
        }

        // generate all of the terrain tiles and static objects in the room
        gameWorldView.RebuildRoom(currentRoom);

        // Notify the overlay of a room reload
        m_contextOverlayController.OnRoomLoaded(currentRoom);
    }
Exemplo n.º 7
0
    public void OnRoomLoaded(RoomKey roomKey)
    {
        RoomData currentRoom = m_gameWorldModel.GetRoomData(roomKey);

        // Get a list of all the characters that are in the same room as my character
        List<int> characterIDList = m_gameWorldModel.GetCharacterIDListInRoom(roomKey);

        // Remove any existing character
        List<int> allCharacterIds = new List<int>(m_gameWorldModel.GetCharacterEntityMap().Keys);
        foreach (int characterEntityId in allCharacterIds)
        {
            CharacterEntity characterEntity= m_gameWorldModel.GetCharacterEntity(characterEntityId);

            characterEntity.RemoveFromGameWorld(this);
        }

        // (Re)Create character entities for each character in the room
        foreach (int characterID in characterIDList)
        {
            CharacterEntity newCharacterEntity = new CharacterEntity(characterID);

            newCharacterEntity.AddToGameWorld(this);
        }

        // Remove any existing mobs
        List<int> allMobIds = new List<int>(m_gameWorldModel.GetMobEntityMap().Keys);
        foreach (int mobEntityId in allMobIds)
        {
            MobEntity mobEntity = m_gameWorldModel.GetMobEntity(mobEntityId);

            mobEntity.RemoveFromGameWorld(this);
        }

        // (Re)Create mob entities for each mob in the room
        foreach (MobData mobData in currentRoom.MobMap.Values)
        {
            MobEntity newMobEntity = new MobEntity(mobData.mob_id);

            newMobEntity.AddToGameWorld(this);
        }

        // Remove any existing energy tanks
        List<int> allEnergyTankIds = new List<int>(m_gameWorldModel.GetEnergyTankEntityMap().Keys);
        foreach (int energyTankId in allEnergyTankIds)
        {
            EnergyTankEntity energyTankEntity = m_gameWorldModel.GetEnergyTankEntity(energyTankId);

            energyTankEntity.RemoveFromGameWorld(this);
        }

        // (Re)Create energy tank entities for each energy tank in the room
        foreach (EnergyTankData energyTankData in currentRoom.EnergyTankMap.Values)
        {
            EnergyTankEntity newEnergyTankEntity = new EnergyTankEntity(energyTankData.energy_tank_id);

            newEnergyTankEntity.AddToGameWorld(this);
        }

        // generate all of the terrain tiles and static objects in the room
        gameWorldView.RebuildRoom(currentRoom);

        // Notify the overlay of a room reload
        m_contextOverlayController.OnRoomLoaded(currentRoom);
    }
    public override void UndoEvent(GameWorldController gameWorldController)
    {
        GameData currentGame = gameWorldController.Model.CurrentGame;

        if (currentGame.CharacterID != _characterState.character_id)
        {
            // Add the character state back into to the current game state
            gameWorldController.Model.CurrentGame.SetCharacterById(_characterState.character_id, _characterState);

            // Create a new character entity using the character data just set in the game state
            {
                CharacterEntity characterEntity = new CharacterEntity(_characterState.character_id);

                characterEntity.AddToGameWorld(gameWorldController);
            }

            base.UndoEvent(gameWorldController);
        }
        else
        {
            Debug.Log("Ignoring undo CharacterLeftGame event for primary character_id=" + _characterState.character_id);
        }
    }
    public override void ApplyEvent(GameWorldController gameWorldController, OnEventCompleteDelegate onComplete)
    {
        base.ApplyEvent(gameWorldController, onComplete);

        CharacterData character = gameWorldController.Model.GetCharacterData(CharacterID);

        // Update the room key and position on the character that changed rooms
        character.room_x = ToRoomKey.x;
        character.room_y = ToRoomKey.y;
        character.room_z = ToRoomKey.z;
        character.x = ToPosition.x;
        character.y = ToPosition.y;
        character.z = ToPosition.z;

        // Character is the current game character
        if (CharacterID == gameWorldController.Model.CurrentCharacterID)
        {
            // Request the static room data for the room the character is portal-ing to
            // event application won't advance while waiting on room data to load from the server.
            // Once we get the new room data we rebuild everything.
            gameWorldController.Model.RequestRoomData(ToRoomKey, onComplete);
        }
        // Character is some other game character
        else
        {
            // Get the character entity for the character id, if any exists
            CharacterEntity entity = gameWorldController.Model.GetCharacterEntity(CharacterID);

            // Character portal-ed to the current room.
            // Make sure the character exists and is at the correct location.
            if (gameWorldController.Model.CurrentGame.CurrentRoomKey.Equals(ToRoomKey))
            {
                if (entity == null)
                {
                    entity = new CharacterEntity(CharacterID);
                    entity.AddToGameWorld(gameWorldController);
                }

                entity.SnapTo(ToPosition, ToAngle);
            }
            // Character left the current room.
            // Make sure the character entity is cleaned up.
            else
            {
                if (entity != null)
                {
                    entity.RemoveFromGameWorld(gameWorldController);
                }
            }

            if (onComplete != null)
            {
                onComplete();
            }
        }
    }
    public override void UndoEvent(GameWorldController gameWorldController)
    {
        CharacterData character = gameWorldController.Model.GetCharacterData(CharacterID);

        // Update the room key and position on the character that changed rooms
        character.room_x = FromRoomKey.x;
        character.room_y = FromRoomKey.y;
        character.room_z = FromRoomKey.z;
        character.x = FromPosition.x;
        character.y = FromPosition.y;
        character.z = FromPosition.z;

        // Character is the current game character
        if (CharacterID == gameWorldController.Model.CurrentCharacterID)
        {
            // Request the static room data for the room the character portal-ed from
            // event application won't advance while waiting on room data to load from the server.
            // Once we get the new room data we rebuild everything.
            gameWorldController.Model.RequestRoomData(FromRoomKey, null);
        }
        // Character is some other game character
        else
        {
            // Get the character entity for the character id, if any exists
            CharacterEntity entity = gameWorldController.Model.GetCharacterEntity(CharacterID);

            // Character portal-ed from the current room.
            // Make sure the character exists and is at the correct location.
            if (gameWorldController.Model.CurrentGame.CurrentRoomKey.Equals(FromRoomKey))
            {
                if (entity == null)
                {
                    entity = new CharacterEntity(CharacterID);
                    entity.AddToGameWorld(gameWorldController);
                }

                entity.SnapTo(FromPosition, FromAngle);
            }
            // Character from some other room than the current one.
            // Make sure the character entity is cleaned up.
            else
            {
                if (entity != null)
                {
                    entity.RemoveFromGameWorld(gameWorldController);
                }
            }
        }

        base.UndoEvent(gameWorldController);
    }