void placeDog(EnvironmentTile tile)
    {
        if (tile != null)
        {
            //Shpw the shop at the mouse position in the centre of the tile
            spawnedDog.transform.position = new Vector3(mRaycastHits[0].transform.position.x + 5, mRaycastHits[0].transform.position.y + 3, mRaycastHits[0].transform.position.z + 5);

            //Only place a dog if within a paddock and a dog isn't currently within that position
            if (Input.GetMouseButtonDown(0))
            {
                if (tile.isPaddock)
                {
                    if (currency.sufficientFunds(dogCost))
                    {
                        if (tile.GetComponentInParent <Paddock>().addDogs())
                        {
                            dogClone = dog.spawnDog();
                            dogClone.transform.position = tile.Position;

                            //Assign the paddock to the dog
                            dogB = dogClone.GetComponentInChildren <DogBehaviour>();
                            dogB.setTile(tile);
                            dogB.setPaddock(tile.GetComponentInParent <Paddock>().getPaddock());
                            dogB.setPaddockTiles(tile.GetComponentInParent <Paddock>().getPaddockTiles());

                            interactingPaddock = mRaycastHits[0].transform.GetComponentInParent <Paddock>().getPaddock();

                            placingDog = false;

                            currency.takeIncome(dogCost);
                            level.addExp(standardExp);
                        }
                    }
                }

                //Destroy stand in

                Destroy(spawnedDog.gameObject);

                placingDog = false;
            }
        }
    }
Beispiel #2
0
    private void Update()
    {
        // Check to see if the player has clicked a tile and if they have, try to find a path to that
        // tile. If we find a path then the character will move along it to the clicked tile.

        if (characterMgr.health < 0 && Input.GetMouseButtonDown(0))
        {
            ShowSettings();
        }

        if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
        { // Don't move and stuff when the UI is being clicked
            Ray           screenClick = MainCamera.ScreenPointToRay(Input.mousePosition);
            InventorySlot current     = inventoryMgr.inventory[inventoryMgr.selected];
            int           hits        = Physics.RaycastNonAlloc(screenClick, mRaycastHits);
            if (hits > 0)
            {
                EnvironmentTile tile = mRaycastHits[0].transform.GetComponent <EnvironmentTile>();
                tempID = new Vector2Int(tile.xID, tile.yID);
                if (tile != null)
                {
                    Environment tileProperties = tile.GetComponentInParent <Environment>();
                    if (current.itemType == 4 && tile.occupant == true &&
                        characterMgr.health < characterMgr.GetMaxHP())
                    { // Eat grass for health
                        tile.occupant.GetComponent <CharacterManager>().TakeDamage(-1);
                        inventoryMgr.TakeItem(4, 1, inventoryMgr.selected);
                    }

                    if (CheckPositions(mCharacter.CurrentPosition, tile))
                    { // Is he near the tile that needs breaking
                        if (tileProperties.properties[tile.xID][tile.yID].listType != 2 && tileProperties.properties[tile.xID][tile.yID].listType != 4 &&
                            (current.itemType < 10 || current.itemType == 15 || current.placeable))
                        {     // Check if the tile is actually breakable, and you're not holding a tool (Hammer doesn't count)
                            if (tileProperties.properties[tile.xID][tile.yID].listType == 1)
                            { // Tiles that need time to break start a timer
                                InventorySlot item = inventoryMgr.SearchItem(tileProperties.properties[tile.xID][tile.yID].tileType, 0);
                                if (current.itemType != 15)
                                {
                                    gameObject.AddComponent <Timer>().timeLimit = tile.hardness;
                                }
                                else
                                {
                                    gameObject.AddComponent <Timer>().timeLimit = tile.hardness / item.power;
                                }
                                mCharacter.GetComponent <Animator>().SetBool("pickup", true);
                                characterMgr.characterState = 2; // Start working
                                AudioSource audio = GameObject.FindGameObjectWithTag("Player").GetComponent <AudioSource>();
                                audio.Play();
                            }
                            else if (tileProperties.properties[tile.xID][tile.yID].listType == 3)
                            {                                                // Otherwise they get collected instantly
                                tileProperties.SwapTile(tempID.x, tempID.y); // Pick up the tile
                                characterMgr.characterState = 0;             // Set character back to idle
                            }
                        }
                        if (tileProperties.properties[tile.xID][tile.yID].listType == 4 &&
                            tileProperties.properties[tile.xID][tile.yID].tileType == 1)
                        {
                            GameObject.FindGameObjectWithTag("Player").AddComponent <HealTimer>().StartClock(1.0f, 5);
                            tileProperties.properties[tile.xID][tile.yID].listType = 3;
                        }
                    }

                    if (tileProperties.properties[tile.xID][tile.yID].listType == 0)
                    { // Just walk if it's open land
                        if (inventoryMgr.inventory[inventoryMgr.selected].placeable)
                        {
                            if (CheckPositions(mCharacter.CurrentPosition, tile))
                            {
                                tileProperties.SwapTile(tempID.x, tempID.y); // Replace the tile
                                characterMgr.characterState = 0;             // Character is no longer busy
                            }
                        }
                        else if (current.itemType >= 10)
                        {
                            if (tile.occupant != null && CheckPositions(mCharacter.CurrentPosition, tile))
                            {
                                mMap.DamageOccupant(tile, 1);
                                characterMgr.characterState = 2; // Character is hitting something
                            }
                        }
                        List <EnvironmentTile> route = mMap.Solve(mCharacter.CurrentPosition, tile);
                        mCharacter.GoTo(route);
                        mCharacter.GetComponent <Animator>().SetBool("walking", true);
                    }
                    else if (tileProperties.properties[tile.xID][tile.yID].listType == 4)
                    {
                        tileProperties.SwapTile(tempID.x, tempID.y);
                        characterMgr.characterState = 0; // Character is no longer busy
                    }
                }
            }
        }
        if (Input.GetMouseButtonDown(1) && !EventSystem.current.IsPointerOverGameObject(1))
        {
            inventoryMgr.UseHand();
        }

        if (GetComponent <Timer>() == null && characterMgr.characterState == 2)
        {                                                                        // When the timer is up, break the tile
            GetComponentInChildren <Environment>().SwapTile(tempID.x, tempID.y); // Replace the tile
            mCharacter.GetComponent <Animator>().SetBool("pickup", false);       // Stop the pickup animation
            characterMgr.characterState = 0;                                     // Character is no longer busy
        }

        if (Input.GetAxis("Mouse ScrollWheel") < 0)
        { // Scroll backwards through the inventory
            inventoryMgr.SelectSlot(-1);
        }
        else if (Input.GetAxis("Mouse ScrollWheel") > 0)
        { // Scroll forwards through the inventory
            inventoryMgr.SelectSlot(1);
        }

        if (invasion && GetComponentInChildren <Timer>() == null)
        {
            GetComponentInChildren <Environment>().DoomsdaySpawner();
            GetComponentsInChildren <CharacterManager>();
        }

        //if (inventoryMgr.inventory[inventoryMgr.selected].itemType >= 10)
        //{ // Displayer the item in the players hand
        //    inventoryMgr.holding.HoldItem();
        //}
    }