示例#1
0
    protected SpawnedPuzzleItem spawnItem(PuzzleItem item)
    {
        _itemNames.Add(item.Name);
        GameObject        puzzleItemObj = GameObject.Instantiate(PlayState.instance.puzzleItemPrefab) as GameObject;
        SpawnedPuzzleItem spawnedItem   = puzzleItemObj.GetComponent <SpawnedPuzzleItem>();

        // Give the spawned item all the appropriate properties.
        foreach (string propertyName in item.getPropertyNames())
        {
            spawnedItem.setProperty(propertyName, item.getProperty(propertyName));
        }
        if (getRequest(spawnedItem.itemName) != null)
        {
            spawnedItem.initRequest(getRequest(spawnedItem.itemName));
        }

        // Figure out where to spawn the item
        if (item.propertyExists("spawnArea"))
        {
            string spawnAreaName = item.getProperty("spawnArea") as string;
            addArea(spawnAreaName);
            _areaRooms[spawnAreaName].addPiece(spawnedItem);
        }
        return(spawnedItem);
    }
示例#2
0
 public void removeFromOtherItem()
 {
     _pathSpeed            = 0;
     _parentItem.childItem = null;
     _parentItem.alpha     = 1.0f;
     _parentItem           = null;
 }
示例#3
0
    public void addToOtherItem(SpawnedPuzzleItem otherItem)
    {
        if (otherItem.containsItem || insideItem)
        {
            throw new UnityException("Item insertion conflict!");
        }

        if (_text != null && _text.gameObject.activeInHierarchy)
        {
            _text.gameObject.SetActive(false);
        }

        _parentItem           = otherItem;
        _parentItem.childItem = this;
        _parentItem.alpha     = 0.5f;

        transform.parent        = otherItem.transform;
        transform.localPosition = new Vector3(0, 0, 0.5f);
        transform.localScale    = new Vector3(0.5f, 0.5f, 1);

        if (inInventory)
        {
            _currentSlot.removeItem();
        }
        PlayState.instance.removeFromGrid(this);


        // Disable this item so it doesn't receive updates while in a container
        this.enabled = false;
    }
示例#4
0
 public RelationshipExecutor(SpawnedPuzzleItem item1, SpawnedPuzzleItem item2, Room room, ProcGame game)
 {
     _item1 = item1;
     _item2 = item2;
     _currentRoom = room;
     _game = game;
 }
示例#5
0
 public RelationshipExecutor(SpawnedPuzzleItem item1, SpawnedPuzzleItem item2, Room room, ProcGame game)
 {
     _item1       = item1;
     _item2       = item2;
     _currentRoom = room;
     _game        = game;
 }
示例#6
0
 public void addItem(SpawnedPuzzleItem item)
 {
     if (!isEmpty)
         throw new UnityException("Inventory Conflict");
     _item = item;
     _item.transform.parent = transform;
     _item.transform.localPosition = new Vector3(0, 0, -1);
     _item.enabled = false;
 }
示例#7
0
    public void accept(ItemRequestRelationship rel)
    {
        // Give one item to another.

        SpawnedPuzzleItem requested, requester;

        if (rel.requestedName == _item1.itemName)
        {
            requested = _item1;
            requester = _item2;
        }
        else
        {
            requested = _item2;
            requester = _item1;
        }
        // If the requester is inside something, have to remove it first
        if (requester.insideItem)
        {
            PlayState.instance.addPlayerText(string.Format("Have to remove the {0} first.", requester.itemName));
            return;
        }
        // Check to see if the item has the requested property
        if (rel.requestedPropertyName != null && (!requested.propertyExists(rel.requestedPropertyName) || requested.getProperty(rel.requestedPropertyName) != rel.requestedPropertyValue))
        {
            requester.activateText(requester.npcWrongPropertyText());
            return;
        }
        requester.requestFulfilled = true;
        PlayState.instance.playAudio(PlayState.instance.pickupClip);
        // On success, destroy the old item and spawn the new one.
        if (requested.inInventory)
        {
            requested.currentSlot.removeItem();
        }
        if (requested.insideItem)
        {
            requested.removeFromOtherItem();
        }
        requested.die();

        SpawnedPuzzleItem itemToSpawn = spawnItem(rel.rewardItem);

        if (itemToSpawn.carryable)
        {
            itemToSpawn.init();
            itemToSpawn.addToInventory();
        }
        else
        {
            _currentRoom.addPiece(itemToSpawn);
        }

        // Display the fulfilled text.
        requester.activateText(requester.npcFulfilledText());
    }
示例#8
0
 public void addItem(SpawnedPuzzleItem item)
 {
     if (!isEmpty)
     {
         throw new UnityException("Inventory Conflict");
     }
     _item = item;
     _item.transform.parent        = transform;
     _item.transform.localPosition = new Vector3(0, 0, -1);
     _item.enabled = false;
 }
示例#9
0
    protected SpawnedPuzzleItem spawnItem(PuzzleItem item)
    {
        GameObject        newObj      = GameObject.Instantiate(PlayState.instance.puzzleItemPrefab) as GameObject;
        SpawnedPuzzleItem spawnedItem = newObj.GetComponent <SpawnedPuzzleItem>();

        // Give the spawned item all the appropriate properties.
        foreach (string propertyName in item.getPropertyNames())
        {
            spawnedItem.setProperty(propertyName, item.getProperty(propertyName));
        }

        if (_game.getRequest(spawnedItem.itemName) != null)
        {
            spawnedItem.initRequest(_game.getRequest(spawnedItem.itemName));
        }

        return(spawnedItem);
    }
示例#10
0
    public void useItemsTogether(SpawnedPuzzleItem item1, SpawnedPuzzleItem item2)
    {
        Debug.Log(string.Format("Using {0} with {1}", item1.itemName, item2.itemName));
        IRelationship maybeRel = _currentGame.getRelationship(item1.itemName, item2.itemName);

        if (maybeRel != null)
        {
            // Create an executor for using these two items
            RelationshipExecutor executor = new RelationshipExecutor(item1, item2, _currentRoom, _currentGame);
            maybeRel.addRelationshipToGame(executor);
        }
        else
        {
            _player.activateText("\"I don't think I can use those together.\"", 2);
        }

        _inventory.selectedSlot = null;
    }
示例#11
0
    // Update is called once per frame
    void Update()
    {
        // Check if we've won yet
        if (_hasSandwich && !_player.textActive)
        {
            MainMenuState.winState = true;
            Application.LoadLevel("TitleScene");
        }
        else if (Input.GetKeyDown(KeyCode.Escape))
        {
            MainMenuState.winState = false;
            Application.LoadLevel("TitleScene");
        }

        // If we want to reset the level
        if (Input.GetKeyDown(KeyCode.R))
        {
            seedGenerate = true;
            Application.LoadLevel("PlayScene");
        }

        // remove or destroy any pieces that need to be removed before we begin
        foreach (GridPiece piece in _piecesToRemove)
        {
            if (piece != null)
            {
                _gridPieces.Remove(piece);
            }
        }
        _piecesToRemove.Clear();
        foreach (GridPiece piece in _piecesToDestroy)
        {
            if (piece != null)
            {
                Destroy(piece.gameObject);
            }
        }
        _piecesToDestroy.Clear();

        if (_shouldHidePopupText)
        {
            _popupText.gameObject.SetActive(false);
        }
        _shouldHidePopupText = true;

        Vector3 mouseActualPos = tk2dCamera.inst.mainCamera.ScreenToWorldPoint(Input.mousePosition);
        Vector2 mousePos       = new Vector2(mouseActualPos.x, mouseActualPos.y);
        Vector2 mouseGridPos   = PlayState.instance.toGridCoordinates(mouseActualPos.x - PlayState.instance.gridX, mouseActualPos.y - PlayState.instance.gridY);

        // Check to see if we have a selected item
        if (_inventory.selectedSlot != null)
        {
            string useText = string.Format("Use {0} with", _inventory.selectedSlot.item.itemName);
            if (_inventory.selectedSlot.item.insideItem && _highlightedItem == null && _inventory.hoveredSlot == null)
            {
                if (inGrid(mouseGridPos) && currentGridInhabitants(mouseGridPos).Count == 0)
                {
                    useText = string.Format("Remove {0} from {1}", _inventory.selectedSlot.item.itemName, _inventory.selectedSlot.item.parentItem.itemName);
                }
            }
            else if (_inventory.selectedSlot != null && _highlightedItem == null && _inventory.selectedSlot.item.insideItem &&
                     _inventory.selectedSlot.item.carryable && _inventory.hoveredSlot.isEmpty)
            {
                useText = string.Format("Remove {0} from {1}", _inventory.selectedSlot.item.itemName, _inventory.selectedSlot.item.parentItem.itemName);
            }

            if (_highlightedItem != null)
            {
                useText = string.Format("Use {0} with {1}", _inventory.selectedSlot.item.itemName, _highlightedItem.itemName);
            }

            setMousePopupText(useText, mousePos);
        }
        else if (_highlightedItem != null && !_highlightedItem.textActive)
        {
            setPopupText(_highlightedItem.description(), _highlightedItem.gridPos);
        }


        if (_inventory.selectedSlot != null && _highlightedItem != null && Input.GetMouseButtonDown(0))
        {
            useItemsTogether(_inventory.selectedSlot.item, _highlightedItem);
        }
        else if (_inventory.selectedSlot != null && _highlightedItem == null && _inventory.selectedSlot.item.insideItem &&
                 _inventory.hoveredSlot == null && Input.GetMouseButtonDown(0))
        {
            // Check to see if we're over a grid position
            if (inGrid(mouseGridPos) && currentGridInhabitants(mouseGridPos).Count == 0)
            {
                SpawnedPuzzleItem itemInContainer = _inventory.selectedSlot.item;
                itemInContainer.removeFromOtherItem();
                itemInContainer.transform.parent = transform;
                Vector2 actualPos = toActualCoordinates(mouseGridPos);
                itemInContainer.transform.localScale = new Vector3(4, 4, 1);
                itemInContainer.x         = actualPos.x;
                itemInContainer.y         = actualPos.y;
                itemInContainer.gridPos   = mouseGridPos;
                itemInContainer.nextPoint = itemInContainer.gridPos;
                itemInContainer.enabled   = true;
                _gridPieces.Add(itemInContainer);
                _inventory.selectedSlot = null;
            }
        }
        // Finally, removing into the inventory
        else if (_inventory.selectedSlot != null && _highlightedItem == null && _inventory.selectedSlot.item.insideItem &&
                 _inventory.selectedSlot.item.carryable && _inventory.hoveredSlot != null && _inventory.hoveredSlot.isEmpty && Input.GetMouseButtonDown(0))
        {
            SpawnedPuzzleItem itemInContainer = _inventory.selectedSlot.item;
            itemInContainer.removeFromOtherItem();
            itemInContainer.transform.parent     = transform;
            itemInContainer.transform.localScale = new Vector3(4, 4, 1);
            itemInContainer.addToInventory();
            _inventory.selectedSlot = null;
        }

        _highlightedItem = null;

        if (_currentState == GameState.RUN_STATE)
        {
            // Before anything, check to see if we're at an exit
            if (!_player.moving)
            {
                Vector2 playerGridPos = toGridCoordinates(_player.x, _player.y);
                if (_currentRoom.checkForPlayerExit(playerGridPos))
                {
                    return;
                }
            }

            constructCurrentGrid();
            constructClaimedGrid();

            bool turnReady = true;
            _npcTextShowing = false;
            foreach (GridPiece piece in _gridPieces)
            {
                if (!piece.isTurnReady())
                {
                    turnReady = false;
                }
                if (!piece.hasType(GridPiece.PLAYER_TYPE) && piece.textActive)
                {
                    _npcTextShowing = true;
                }
            }
            // Perform the turn if we're ready for it
            if (turnReady)
            {
                // First, a pre-turn
                foreach (GridPiece piece in _gridPieces)
                {
                    piece.turnPerformed = false;
                    piece.preTurn();
                }

                // Now the actual turn. Since pieces might be added to
                // The piece list, using a normal for loop (rather than foreach)
                for (int i = 0; i < _gridPieces.Count; i++)
                {
                    GridPiece piece = _gridPieces[i];
                    performPieceTurn(piece);
                }

                // Update movement
                foreach (GridPiece piece in _gridPieces)
                {
                    performTurnMovement(piece);
                }

                // Finally, the post turn
                foreach (GridPiece piece in _gridPieces)
                {
                    piece.postTurn();
                }
            }
        }
    }
示例#12
0
文件: Room.cs 项目: nixlim/Puzzledice
    public int makeLockedConnection(uint dir, Room otherRoom, SpawnedPuzzleItem lockedDoor, int doorIndex)
    {
        if (dir == GridPiece.UP)
        {
            if (_upExit != null)
            {
                throw new UnityException("Tried to add two up exits to room!");
            }
            _upExit = otherRoom;

            // Carve only a tiny piece out of our room
            if (doorIndex == -1)
            {
                doorIndex = Random.Range(6, 10);
            }
            GridPiece wallToRemove = null;
            foreach (GridPiece piece in _gridPieces)
            {
                if (piece.gridPos.y == Globals.ROOM_HEIGHT - 1 && piece.gridPos.x == doorIndex)
                {
                    wallToRemove = piece;
                }
            }
            _gridPieces.Remove(wallToRemove);
            GameObject.Destroy(wallToRemove.gameObject);
            if (lockedDoor != null)
            {
                addPiece(lockedDoor, new Vector2(doorIndex, Globals.ROOM_HEIGHT - 1));
            }
            return(doorIndex);
        }
        else if (dir == GridPiece.RIGHT)
        {
            if (_rightExit != null)
            {
                throw new UnityException("Tried to add two right exits to room!");
            }
            _rightExit = otherRoom;

            if (doorIndex == -1)
            {
                doorIndex = Random.Range(3, 7);
            }
            GridPiece wallToRemove = null;
            foreach (GridPiece piece in _gridPieces)
            {
                if (piece.gridPos.x == Globals.ROOM_WIDTH - 1 && piece.gridPos.y == doorIndex)
                {
                    wallToRemove = piece;
                }
            }
            _gridPieces.Remove(wallToRemove);
            GameObject.Destroy(wallToRemove.gameObject);
            if (lockedDoor != null)
            {
                addPiece(lockedDoor, new Vector2(Globals.ROOM_WIDTH - 1, doorIndex));
            }
            return(doorIndex);
        }
        else if (dir == GridPiece.DOWN)
        {
            if (_downExit != null)
            {
                throw new UnityException("Tried to add two down exits to room!");
            }
            _downExit = otherRoom;

            // Carve only a tiny piece out of our room
            if (doorIndex == -1)
            {
                doorIndex = Random.Range(6, 10);
            }
            GridPiece wallToRemove = null;
            foreach (GridPiece piece in _gridPieces)
            {
                if (piece.gridPos.y == 0 && piece.gridPos.x == doorIndex)
                {
                    wallToRemove = piece;
                }
            }
            _gridPieces.Remove(wallToRemove);
            GameObject.Destroy(wallToRemove.gameObject);
            if (lockedDoor != null)
            {
                addPiece(lockedDoor, new Vector2(doorIndex, 0));
            }
            return(doorIndex);
        }
        else if (dir == GridPiece.LEFT)
        {
            if (_leftExit != null)
            {
                throw new UnityException("Tried to add two left exits to room!");
            }
            _leftExit = otherRoom;
            if (doorIndex == -1)
            {
                doorIndex = Random.Range(3, 7);
            }
            GridPiece wallToRemove = null;
            foreach (GridPiece piece in _gridPieces)
            {
                if (piece.gridPos.x == 0 && piece.gridPos.y == doorIndex)
                {
                    wallToRemove = piece;
                }
            }
            _gridPieces.Remove(wallToRemove);
            GameObject.Destroy(wallToRemove.gameObject);
            if (lockedDoor != null)
            {
                addPiece(lockedDoor, new Vector2(0, doorIndex));
            }
            return(doorIndex);
        }
        return(-1);
    }
示例#13
0
    // Update is called once per frame
    void Update()
    {
        // Check if we've won yet
        if (_hasSandwich && !_player.textActive) {
            MainMenuState.winState = true;
            Application.LoadLevel("TitleScene");
        }
        else if (Input.GetKeyDown(KeyCode.Escape)) {
            MainMenuState.winState = false;
            Application.LoadLevel("TitleScene");
        }

        // If we want to reset the level
        if (Input.GetKeyDown(KeyCode.R)) {
            seedGenerate = true;
            Application.LoadLevel("PlayScene");
        }

        // remove or destroy any pieces that need to be removed before we begin
        foreach (GridPiece piece in _piecesToRemove) {
            if (piece != null) {
                _gridPieces.Remove(piece);
            }
        }
        _piecesToRemove.Clear();
        foreach (GridPiece piece in _piecesToDestroy) {
            if (piece != null)
                Destroy(piece.gameObject);
        }
        _piecesToDestroy.Clear();

        if (_shouldHidePopupText)
            _popupText.gameObject.SetActive(false);
        _shouldHidePopupText = true;

        Vector3 mouseActualPos = tk2dCamera.inst.mainCamera.ScreenToWorldPoint(Input.mousePosition);
        Vector2 mousePos = new Vector2(mouseActualPos.x, mouseActualPos.y);
        Vector2 mouseGridPos = PlayState.instance.toGridCoordinates(mouseActualPos.x-PlayState.instance.gridX, mouseActualPos.y-PlayState.instance.gridY);
        // Check to see if we have a selected item
        if (_inventory.selectedSlot != null) {

            string useText = string.Format("Use {0} with", _inventory.selectedSlot.item.itemName);
            if (_inventory.selectedSlot.item.insideItem && _highlightedItem == null && _inventory.hoveredSlot == null) {
                if (inGrid(mouseGridPos) && currentGridInhabitants(mouseGridPos).Count == 0) {
                    useText = string.Format("Remove {0} from {1}", _inventory.selectedSlot.item.itemName, _inventory.selectedSlot.item.parentItem.itemName);
                }
            }
            else if (_inventory.selectedSlot != null && _highlightedItem == null && _inventory.selectedSlot.item.insideItem &&
            _inventory.selectedSlot.item.carryable && _inventory.hoveredSlot.isEmpty) {
                useText = string.Format("Remove {0} from {1}", _inventory.selectedSlot.item.itemName, _inventory.selectedSlot.item.parentItem.itemName);
            }

            if (_highlightedItem != null)
                useText = string.Format("Use {0} with {1}", _inventory.selectedSlot.item.itemName, _highlightedItem.itemName);

            setMousePopupText(useText, mousePos);
        }
        else if (_highlightedItem != null && !_highlightedItem.textActive) {
            setPopupText(_highlightedItem.description(), _highlightedItem.gridPos);
        }

        if (_inventory.selectedSlot != null && _highlightedItem != null && Input.GetMouseButtonDown(0)) {
            useItemsTogether(_inventory.selectedSlot.item, _highlightedItem);
        }
        else if (_inventory.selectedSlot != null && _highlightedItem == null && _inventory.selectedSlot.item.insideItem &&
            _inventory.hoveredSlot == null && Input.GetMouseButtonDown(0)) {
            // Check to see if we're over a grid position
            if (inGrid(mouseGridPos) && currentGridInhabitants(mouseGridPos).Count == 0) {
                SpawnedPuzzleItem itemInContainer = _inventory.selectedSlot.item;
                itemInContainer.removeFromOtherItem();
                itemInContainer.transform.parent = transform;
                Vector2 actualPos = toActualCoordinates(mouseGridPos);
                itemInContainer.transform.localScale = new Vector3(4, 4, 1);
                itemInContainer.x = actualPos.x;
                itemInContainer.y = actualPos.y;
                itemInContainer.gridPos = mouseGridPos;
                itemInContainer.nextPoint = itemInContainer.gridPos;
                itemInContainer.enabled = true;
                _gridPieces.Add(itemInContainer);
                _inventory.selectedSlot = null;
            }
        }
        // Finally, removing into the inventory
        else if (_inventory.selectedSlot != null && _highlightedItem == null && _inventory.selectedSlot.item.insideItem &&
            _inventory.selectedSlot.item.carryable && _inventory.hoveredSlot != null && _inventory.hoveredSlot.isEmpty && Input.GetMouseButtonDown(0)) {
            SpawnedPuzzleItem itemInContainer = _inventory.selectedSlot.item;
            itemInContainer.removeFromOtherItem();
            itemInContainer.transform.parent = transform;
            itemInContainer.transform.localScale = new Vector3(4, 4, 1);
            itemInContainer.addToInventory();
            _inventory.selectedSlot = null;
        }

        _highlightedItem = null;

        if (_currentState == GameState.RUN_STATE) {

            // Before anything, check to see if we're at an exit
            if (!_player.moving) {
                Vector2 playerGridPos = toGridCoordinates(_player.x, _player.y);
                if (_currentRoom.checkForPlayerExit(playerGridPos))
                    return;
            }

            constructCurrentGrid();
            constructClaimedGrid();

            bool turnReady = true;
            _npcTextShowing = false;
            foreach (GridPiece piece in _gridPieces) {
                if (!piece.isTurnReady())
                    turnReady = false;
                if (!piece.hasType(GridPiece.PLAYER_TYPE) && piece.textActive)
                    _npcTextShowing = true;
            }
            // Perform the turn if we're ready for it
            if (turnReady) {
                // First, a pre-turn
                foreach (GridPiece piece in _gridPieces) {
                    piece.turnPerformed = false;
                    piece.preTurn();
                }

                // Now the actual turn. Since pieces might be added to
                // The piece list, using a normal for loop (rather than foreach)
                for (int i = 0; i < _gridPieces.Count; i++) {
                    GridPiece piece = _gridPieces[i];
                    performPieceTurn(piece);
                }

                // Update movement
                foreach (GridPiece piece in _gridPieces) {
                    performTurnMovement(piece);
                }

                // Finally, the post turn
                foreach (GridPiece piece in _gridPieces) {
                    piece.postTurn();
                }
            }
        }
    }
示例#14
0
 public void setHighlightedItem(SpawnedPuzzleItem item)
 {
     _highlightedItem = item;
 }
示例#15
0
    public void useItemsTogether(SpawnedPuzzleItem item1, SpawnedPuzzleItem item2)
    {
        Debug.Log(string.Format("Using {0} with {1}", item1.itemName, item2.itemName));
        IRelationship maybeRel = _currentGame.getRelationship(item1.itemName, item2.itemName);
        if (maybeRel != null) {
            // Create an executor for using these two items
            RelationshipExecutor executor = new RelationshipExecutor(item1, item2, _currentRoom, _currentGame);
            maybeRel.addRelationshipToGame(executor);
        }
        else {
            _player.activateText("\"I don't think I can use those together.\"", 2);
        }

        _inventory.selectedSlot = null;
    }
示例#16
0
 public void setHighlightedItem(SpawnedPuzzleItem item)
 {
     _highlightedItem = item;
 }
示例#17
0
文件: Room.cs 项目: alect/Puzzledice
    public int makeLockedConnection(uint dir, Room otherRoom, SpawnedPuzzleItem lockedDoor, int doorIndex)
    {
        if (dir == GridPiece.UP) {
            if (_upExit != null)
                throw new UnityException("Tried to add two up exits to room!");
            _upExit = otherRoom;

            // Carve only a tiny piece out of our room
            if (doorIndex == -1)
                doorIndex = Random.Range(6, 10);
            GridPiece wallToRemove = null;
            foreach (GridPiece piece in _gridPieces) {
                if (piece.gridPos.y == Globals.ROOM_HEIGHT-1 && piece.gridPos.x == doorIndex)
                    wallToRemove = piece;
            }
            _gridPieces.Remove(wallToRemove);
            GameObject.Destroy(wallToRemove.gameObject);
            if (lockedDoor != null)
                addPiece(lockedDoor, new Vector2(doorIndex, Globals.ROOM_HEIGHT-1));
            return doorIndex;
        }
        else if (dir == GridPiece.RIGHT) {
            if (_rightExit != null)
                throw new UnityException("Tried to add two right exits to room!");
            _rightExit = otherRoom;

            if (doorIndex == -1)
                doorIndex = Random.Range(3, 7);
            GridPiece wallToRemove = null;
            foreach (GridPiece piece in _gridPieces) {
                if (piece.gridPos.x == Globals.ROOM_WIDTH-1 && piece.gridPos.y == doorIndex)
                    wallToRemove = piece;
            }
            _gridPieces.Remove(wallToRemove);
            GameObject.Destroy(wallToRemove.gameObject);
            if (lockedDoor != null)
                addPiece(lockedDoor, new Vector2(Globals.ROOM_WIDTH-1, doorIndex));
            return doorIndex;
        }
        else if (dir == GridPiece.DOWN) {
            if (_downExit != null)
                throw new UnityException("Tried to add two down exits to room!");
            _downExit = otherRoom;

            // Carve only a tiny piece out of our room
            if (doorIndex == -1)
                doorIndex = Random.Range(6, 10);
            GridPiece wallToRemove = null;
            foreach (GridPiece piece in _gridPieces) {
                if (piece.gridPos.y == 0 && piece.gridPos.x == doorIndex)
                    wallToRemove = piece;
            }
            _gridPieces.Remove(wallToRemove);
            GameObject.Destroy(wallToRemove.gameObject);
            if (lockedDoor != null)
                addPiece(lockedDoor, new Vector2(doorIndex, 0));
            return doorIndex;
        }
        else if (dir == GridPiece.LEFT) {
            if (_leftExit != null)
                throw new UnityException("Tried to add two left exits to room!");
            _leftExit = otherRoom;
            if (doorIndex == -1)
                doorIndex = Random.Range(3, 7);
            GridPiece wallToRemove = null;
            foreach (GridPiece piece in _gridPieces) {
                if (piece.gridPos.x == 0 && piece.gridPos.y == doorIndex)
                    wallToRemove = piece;
            }
            _gridPieces.Remove(wallToRemove);
            GameObject.Destroy(wallToRemove.gameObject);
            if (lockedDoor != null)
                addPiece(lockedDoor, new Vector2(0, doorIndex));
            return doorIndex;
        }
        return -1;
    }
示例#18
0
    public void accept(CombineRelationship rel)
    {
        // Create a new spawn item for the new item
        SpawnedPuzzleItem itemToSpawn = spawnItem(rel.resultItem);
        // Now, need to figure out where to spawn the new item.
        bool              spawnInInventory = false, spawnAtLocation = false, spawnInItem1Container = false, spawnInItem2Container = false;
        Vector2           locationToSpawn = Vector2.zero;
        SpawnedPuzzleItem item1Container  = _item1.parentItem;
        SpawnedPuzzleItem item2Container  = _item2.parentItem;

        bool destroyItem1 = !_item1.propertyExists("destroyoncombine") || (bool)_item1.getProperty("destroyoncombine");
        bool destroyItem2 = !_item2.propertyExists("destroyoncombine") || (bool)_item2.getProperty("destroyoncombine");

        // If neither ingredient is destoyed, just spawn in the room
        if (!destroyItem1 && !destroyItem2)
        {
            spawnAtLocation       = false;
            spawnInInventory      = false;
            spawnInItem1Container = false;
            spawnInItem2Container = false;
        }
        else if (itemToSpawn.carryable && ((destroyItem1 && _item1.inInventory) || (destroyItem2 && _item2.inInventory)))
        {
            spawnInInventory = true;
        }
        // If the item is not carryable, have to spawn in room
        else
        {
            spawnInInventory = false;
            // Check if we can spawn in item1's container
            if (destroyItem1 && _item1.insideItem && itemToSpawn.propertyExists("fills") && (itemToSpawn.getProperty("fills") as List <string>).Contains(item1Container.itemName))
            {
                spawnInItem1Container = true;
            }
            else if (destroyItem2 && _item2.insideItem && itemToSpawn.propertyExists("fills") && (itemToSpawn.getProperty("fills") as List <string>).Contains(item2Container.itemName))
            {
                spawnInItem2Container = true;
            }
            else if (destroyItem1 && !_item1.inInventory)
            {
                spawnAtLocation = true;
                locationToSpawn = _item1.gridPos;
            }
            else if (destroyItem2 && !_item2.inInventory)
            {
                spawnAtLocation = true;
                locationToSpawn = _item2.gridPos;
            }
        }



        // Destroy items that need to be destroyed.
        if (destroyItem1)
        {
            if (_item1.inInventory)
            {
                _item1.currentSlot.removeItem();
            }
            if (_item1.insideItem)
            {
                _item1.removeFromOtherItem();
            }
            _item1.die();
        }
        if (destroyItem2)
        {
            if (_item2.inInventory)
            {
                _item2.currentSlot.removeItem();
            }
            if (_item2.insideItem)
            {
                _item2.removeFromOtherItem();
            }
            _item2.die();
        }


        // Now finally spawn the item.
        if (spawnInInventory)
        {
            itemToSpawn.init();
            itemToSpawn.addToInventory();
        }
        else if (spawnInItem1Container)
        {
            itemToSpawn.init();
            itemToSpawn.addToOtherItem(item1Container);
        }
        else if (spawnInItem2Container)
        {
            itemToSpawn.addToOtherItem(item2Container);
        }
        else if (spawnAtLocation)
        {
            _currentRoom.addPiece(itemToSpawn, locationToSpawn);
        }
        else
        {
            _currentRoom.addPiece(itemToSpawn);
        }

        // Play a sound
        PlayState.instance.playAudio(PlayState.instance.pickupClip);
    }
示例#19
0
文件: Room.cs 项目: nixlim/Puzzledice
 public int makeLockedConnection(uint dir, Room otherRoom, SpawnedPuzzleItem lockedDoor)
 {
     return(makeLockedConnection(dir, otherRoom, lockedDoor, -1));
 }
示例#20
0
 public void removeItem()
 {
     _item = null;
 }
示例#21
0
 public void removeFromOtherItem()
 {
     _pathSpeed = 0;
     _parentItem.childItem = null;
     _parentItem.alpha = 1.0f;
     _parentItem = null;
 }
示例#22
0
    protected void createAreaConnections()
    {
        if (_startArea == null || !_areaRooms.ContainsKey(_startArea))
        {
            throw new UnityException("No start area!");
        }
        _startRoom = _areaRooms[_startArea];
        // Create a grid of rooms to organize everything
        Room[,] roomGrid = new Room[MAX_MAP_SIZE, MAX_MAP_SIZE];
        // Also keep a record of area positions in the grid
        Dictionary <string, Vector2> areaPositions = new Dictionary <string, Vector2>();

        // Place the start room in the center of the grid
        roomGrid[MAX_MAP_SIZE / 2, MAX_MAP_SIZE / 2] = _startRoom;
        areaPositions[_startArea] = new Vector2((int)(MAX_MAP_SIZE / 2), (int)(MAX_MAP_SIZE) / 2);

        // Branch off from the rooms one by one
        Queue <string> agenda = new Queue <string>();

        agenda.Enqueue(_startArea);

        while (agenda.Count > 0)
        {
            string  areaName     = agenda.Dequeue();
            Vector2 areaPosition = areaPositions[areaName];
            Room    areaRoom     = _areaRooms[areaName];
            if (!_areaConnections.ContainsKey(areaName))
            {
                continue;
            }
            foreach (string neighbor in _areaConnections[areaName])
            {
                // Create a connection to this area

                // Decide how many filler rooms we'll make
                int numFillerRooms = Random.Range(MIN_FILLER_ROOMS, MAX_FILLER_ROOMS + 1);

                Room    currentRoom = areaRoom;
                Vector2 currentPos  = areaPosition;
                uint    dir;
                for (int i = 0; i < numFillerRooms; i++)
                {
                    // Choose a direction to expand
                    dir = expandRoom(currentRoom, currentPos, roomGrid);
                    Vector2 newRoomPos = pointFromDir(dir, currentPos);
                    Room    newRoom    = new Room();
                    newRoom.floorTilesName = currentRoom.floorTilesName;
                    // Connect our rooms
                    currentRoom.makeSpatialConnection(dir, newRoom);
                    newRoom.makeSpatialConnection(oppositeDir(dir), currentRoom);
                    // Add some goblins to the room
                    newRoom.addMonsters();
                    // Update the grid
                    roomGrid[(int)newRoomPos.x, (int)newRoomPos.y] = newRoom;

                    currentRoom = newRoom;
                    currentPos  = newRoomPos;
                }
                // Finally, create the neighboring room at the next location.
                Room neighborRoom = _areaRooms[neighbor];
                dir = expandRoom(currentRoom, currentPos, roomGrid);
                Vector2 neighborPos = pointFromDir(dir, currentPos);
                currentRoom.makeSpatialConnection(dir, neighborRoom);
                neighborRoom.makeSpatialConnection(oppositeDir(dir), currentRoom);
                roomGrid[(int)neighborPos.x, (int)neighborPos.y] = neighborRoom;
                areaPositions[neighbor] = neighborPos;
                agenda.Enqueue(neighbor);
            }
            // Now, the locked doors
            foreach (AreaConnectionRelationship lockedRel in _lockedAreaConnections[areaName])
            {
                string neighbor = lockedRel.secondAreaName;
                // Spawn a lock
                SpawnedPuzzleItem lockedDoor = spawnLockedDoor();
                // Add the locked door relationship to our map
                // Figure out what our actual key name is
                string keyName = lockedRel.keyName;
                DBItem dbKey   = Database.Instance.getItem(keyName);
                if (dbKey.propertyExists("keyname"))
                {
                    keyName = dbKey.getProperty("keyname") as string;
                }
                _itemNames.Add(keyName);

                if (!_relationshipMap.ContainsKey(keyName))
                {
                    _relationshipMap[keyName] = new Dictionary <string, IRelationship>();
                }
                _relationshipMap[keyName][lockedDoor.itemName] = lockedRel;
                if (!_relationshipMap.ContainsKey(lockedDoor.itemName))
                {
                    _relationshipMap[lockedDoor.itemName] = new Dictionary <string, IRelationship>();
                }
                _relationshipMap[lockedDoor.itemName][keyName] = lockedRel;
                // Decide how many filler rooms we'll make
                int numFillerRooms = Random.Range(MIN_FILLER_ROOMS, MAX_FILLER_ROOMS + 1);

                Room    currentRoom = areaRoom;
                Vector2 currentPos  = areaPosition;
                uint    dir;
                for (int i = 0; i < numFillerRooms; i++)
                {
                    // Choose a direction to expand
                    dir = expandRoom(currentRoom, currentPos, roomGrid);
                    Vector2 newRoomPos = pointFromDir(dir, currentPos);
                    Room    newRoom    = new Room();
                    newRoom.floorTilesName = currentRoom.floorTilesName;
                    // Connect our rooms
                    if (i == 0)
                    {
                        int doorIndex = currentRoom.makeLockedConnection(dir, newRoom, lockedDoor);
                        newRoom.makeLockedConnection(oppositeDir(dir), currentRoom, doorIndex);
                    }
                    else
                    {
                        currentRoom.makeSpatialConnection(dir, newRoom);
                        newRoom.makeSpatialConnection(oppositeDir(dir), currentRoom);
                    }
                    // Add some goblins to the room
                    newRoom.addMonsters();
                    // Update the grid
                    roomGrid[(int)newRoomPos.x, (int)newRoomPos.y] = newRoom;

                    currentRoom = newRoom;
                    currentPos  = newRoomPos;
                }
                // Finally, create the neighboring room at the next location.
                Room neighborRoom = _areaRooms[neighbor];
                dir = expandRoom(currentRoom, currentPos, roomGrid);
                Vector2 neighborPos = pointFromDir(dir, currentPos);
                currentRoom.makeSpatialConnection(dir, neighborRoom);
                neighborRoom.makeSpatialConnection(oppositeDir(dir), currentRoom);
                roomGrid[(int)neighborPos.x, (int)neighborPos.y] = neighborRoom;
                areaPositions[neighbor] = neighborPos;
                agenda.Enqueue(neighbor);
            }
        }

        // Finally, go through all the existing rooms and make sure they're not active
        foreach (Room room in roomGrid)
        {
            if (room != null)
            {
                room.deactivateRoom();
            }
        }
    }
示例#23
0
文件: Room.cs 项目: alect/Puzzledice
 public int makeLockedConnection(uint dir, Room otherRoom, SpawnedPuzzleItem lockedDoor)
 {
     return makeLockedConnection(dir, otherRoom, lockedDoor, -1);
 }
示例#24
0
 public void removeItem()
 {
     _item = null;
 }
示例#25
0
    public void addToOtherItem(SpawnedPuzzleItem otherItem)
    {
        if (otherItem.containsItem || insideItem)
            throw new UnityException("Item insertion conflict!");

        if (_text != null && _text.gameObject.activeInHierarchy)
            _text.gameObject.SetActive(false);

        _parentItem = otherItem;
        _parentItem.childItem = this;
        _parentItem.alpha = 0.5f;

        transform.parent = otherItem.transform;
        transform.localPosition = new Vector3(0, 0, 0.5f);
        transform.localScale = new Vector3(0.5f, 0.5f, 1);

        if (inInventory)
            _currentSlot.removeItem();
        PlayState.instance.removeFromGrid(this);

        // Disable this item so it doesn't receive updates while in a container
        this.enabled = false;
    }