Ejemplo n.º 1
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());
    }
Ejemplo n.º 2
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();
                }
            }
        }
    }
Ejemplo n.º 3
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);
    }