/// <summary>
    /// Tries to move - handles different cases when the player can and cannot move
    /// </summary>
    private void AttemptMove(Vector2Int dir)
    {
        if (hitDirection == dir)
        {
            return;
        }

        // Hit to see if something is in the way
        RaycastHit2D hit;

        if (!CanMove(dir, out hit))
        {
            Stats       destructible = hit.transform.GetComponent <Stats>();
            Chest       chest        = hit.transform.GetComponent <Chest>();
            NPC         npc          = hit.transform.GetComponent <NPC>();
            DungeonDoor door         = hit.transform.GetComponent <DungeonDoor>();

            if (destructible && hitDirection == Vector2Int.zero)
            {
                hitDirection = dir;
                Invoke("ResetHitDirection", PlayerStats.instance.hitDelay.GetValue());
                Attack(destructible);
            }
            else if (chest)
            {
                ChestInventory.instance.OpenChest(chest);
            }
            else if (npc)
            {
                npc.OnNPCClicked();
            }
            else if (door)
            {
                door.Open();
            }
            else
            {
                animatorHandler.SetIdle(dir);
            }

            lighting.GenerateLight();

            return;
        }

        SetMoveSpeed(PlayerStats.instance.movementDelay.GetValue());

        // Initiate the movement
        Vector2 start = transform.position;
        Vector2 end   = start + dir;

        MovementTracker.instance.ClaimSpot(this, Vector2Int.FloorToInt(end));
        StartCoroutine(SmoothMovement(end));

        // Update certain other events
        DialoguePanel.instance.EndDialogue();
        ShopManager.instance.CloseShop();
        ChestInventory.instance.CloseChest();
        animatorHandler.AnimateMovement(dir);
    }
Exemple #2
0
        public void DungeonReset() // register and update spawners method
        {
            IPooledEnumerable eable = m_Stone.GetItemsInRange(m_Stone.Size);

            ArrayList trash = new ArrayList();

            //Here we set all spawners to global values(if bool)
            if (this != null && m_Stone != null && m_UseGlobalRespawn) // error check & global bool
            {
                // Find all spawners within the dungeon, and set their values.
                foreach (Item s in eable)
                {
                    if (s is Spawner)
                    {
                        Spawner sp = (Spawner)s;
                        sp.MaxDelay = sp.MinDelay = m_RespawnDelay;
                        sp.Respawn();
                    }

                    /*else if (s is XmlSpawner) //// comment out if XMLSpawner is not installed
                     * {
                     *  XmlSpawner sp = (XmlSpawner)s;
                     *  sp.MaxDelay = sp.MinDelay = m_RespawnDelay;
                     *  sp.Respawn();
                     * }*//*
                     * else if (s is PremiumSpawner) //// comment out if PremiumSpawner is not installed
                     * {
                     *  PremiumSpawner sp = (PremiumSpawner)s;
                     *  sp.MaxDelay = sp.MinDelay = m_RespawnDelay;
                     *  sp.Respawn();
                     * }*/
                    else if (s.Movable || s is Corpse)
                    {
                        trash.Add(s);
                    }
                    else if (s is DungeonDoor)
                    {
                        DungeonDoor dd = (DungeonDoor)s;
                        dd.Locked = true;
                    }
                }
            }

            // delete trash and corpses
            for (int i = 0; i < trash.Count; i++)
            {
                ((Item)trash[i]).Delete();
            }
        }
Exemple #3
0
        /// <summary>
        /// Generates each door for the DungeonRoom.
        /// </summary>
        /// <param name="dungeon">The current dungeon.</param>
        /// <param name="prefabDoorLR">The prefab for doors that face either left or right.</param>
        /// <param name="prefabDoorUD">The prefab for doors that face either up or down.</param>
        /// <param name="roomDungeonId">The id of the DungeonRoom to where the doors should be generated to.</param>
        /// <param name="dungeonRoomObject">The GameObject that the dungeon room is generated on.</param>
        /// <param name="dungeonRoom">The DungeonRoom.</param>
        private void SetDoors(Dungeon dungeon, GameObject prefabDoorLR, GameObject prefabDoorUD, int roomDungeonId, GameObject dungeonRoomObject, DungeonRoom dungeonRoom)
        {
            DoorLocations[] doorLocs = dungeon.GetDoorsOfRoom(roomDungeonId);
            for (int i = 0; i < doorLocs.Length; i++)
            {
                DoorLocations doorLoc = doorLocs[i];
                GameObject    door    = Instantiate(doorLoc.IsLeftRight ? prefabDoorLR : prefabDoorUD,
                                                    new Vector3(doorLoc.Position.x + 0.5f, doorLoc.Position.y + 0.5f, 0f), Quaternion.identity);

                DungeonDoor dungeonDoor = door.GetComponent <DungeonDoor>();
                dungeonDoor.IsLeftRight = doorLoc.IsLeftRight;

                door.transform.parent = dungeonRoomObject.transform;
                // Is the DungeonRoom the start room?
                if (roomDungeonId == 0)
                {
                    dungeonDoor.IsLocked = false;
                }

                dungeonRoom.doors.Add(dungeonDoor);
            }
        }
    /// <summary>
    /// Place doors in an already generated dungeons, searching for a certain pattern in space
    /// </summary>
    public void PlaceDoors()
    {
        placedDoors = new Dictionary <Vector2Int, bool>();
        for (int y = 2; y < DungeonLevel.Height - 2; y++)
        {
            for (int x = 2; x < DungeonLevel.Width - 2; x++)
            {
                if (map[x, y] == Tiles.floorTile)
                {
                    Vector2Int[]   up         = { Vector2Int.up, Vector2Int.left, Vector2Int.right };
                    Vector2Int[]   down       = { Vector2Int.down, Vector2Int.right, Vector2Int.left };
                    Vector2Int[]   left       = { Vector2Int.left, Vector2Int.down, Vector2Int.up };
                    Vector2Int[]   right      = { Vector2Int.right, Vector2Int.up, Vector2Int.down };
                    Vector2Int[][] directions = { up, down, left, right };
                    foreach (var direction in directions)
                    {
                        /*
                         * Doors are detected in a certain pattern, where 'o' is open space, 'w' is wall, and 'd' is the Door:
                         *
                         *      o
                         *    o o o
                         *    w d w
                         *      o
                         * The other complexity is the need to rotate the Door
                         */
                        Vector2Int crossCenter      = new Vector2Int(x + direction[0].x, y + direction[0].y);
                        Vector2Int crossUp          = new Vector2Int(x + direction[0].x * 2, y + direction[0].y * 2);
                        Vector2Int crossLeft        = new Vector2Int(x + direction[0].x + direction[1].x, y + direction[0].y + direction[1].y);
                        Vector2Int crossRight       = new Vector2Int(x + direction[0].x + direction[2].x, y + direction[0].y + direction[2].y);
                        Vector2Int crossBottomLeft  = new Vector2Int(x + direction[1].x, y + direction[1].y);
                        Vector2Int crossBottomRight = new Vector2Int(x + direction[2].x, y + direction[2].y);
                        Vector2Int crossDown        = new Vector2Int(x - direction[0].x, y - direction[0].y);

                        if (map[crossCenter.x, crossCenter.y] == Tiles.floorTile &&
                            map[crossUp.x, crossUp.y] == Tiles.floorTile &&
                            (map[crossLeft.x, crossLeft.y] == Tiles.floorTile || map[crossRight.x, crossRight.y] == Tiles.floorTile) &&
                            IsWallTile(map[crossBottomLeft.x, crossBottomLeft.y]) &&
                            IsWallTile(map[crossBottomRight.x, crossBottomRight.y]) &&
                            map[crossDown.x, crossDown.y] == Tiles.floorTile &&
                            !placedDoors.ContainsKey(new Vector2Int(x, y)) &&
                            !placedDoors.ContainsKey(new Vector2Int(x + 1, y)) &&
                            !placedDoors.ContainsKey(new Vector2Int(x - 1, y)) &&
                            !placedDoors.ContainsKey(new Vector2Int(x, y + 1)) &&
                            !placedDoors.ContainsKey(new Vector2Int(x, y - 1)))
                        {
                            DungeonDoor instance = Instantiate(door, new Vector3(x, y), Quaternion.identity,
                                                               mapGameObjects);
                            instance.spriteRenderer.sprite = DungeonLevel.Door;
                            if (direction == left || direction == right)
                            {
                                walls.SetTile(new Vector3Int(x, y + 1, 0), DungeonLevel.WallTile.GetTile());
                                if (Random.Range(0, 1f) < DungeonLevel.HiddenDoorDensity)
                                {
                                    instance.spriteRenderer.sprite = DungeonLevel.HiddenSideDoor;
                                }
                            }
                            else if (Random.Range(0, 1f) < DungeonLevel.HiddenDoorDensity)
                            {
                                instance.spriteRenderer.sprite = DungeonLevel.HiddenDoor;
                            }

                            if (Lighting.instance.LightingType == Lighting.LightType.smooth)
                            {
                                instance.spriteRenderer.material = Lighting.instance.SmoothLighting;
                            }

                            placedDoors.Add(new Vector2Int(x, y), true);
                        }
                    }
                }
            }
        }
    }
Exemple #5
0
    void SpawnEnterExit()
    {
        Rectangle startRoom = rooms[0];
        Rectangle endRoom   = rooms[rooms.Count - 1];

        Point spawnPos = new Point(startRoom.left + 1 + startRoom.width / 2 + rnd.Next(0, startRoom.width / 2), startRoom.top + 1 + startRoom.height / 2 + rnd.Next(0, startRoom.height / 2));
        Point exitPos  = new Point(endRoom.left + 1 + endRoom.width / 2 + rnd.Next(0, endRoom.width / 2), endRoom.top + 1 + endRoom.height / 2 + rnd.Next(0, endRoom.height / 2));

        int count = 0;

        while (Map[spawnPos.x, spawnPos.y].HaveObject || !Map[spawnPos.x, spawnPos.y].Walkable)
        {
            spawnPos = new Point(startRoom.left + 1 + startRoom.width / 2 + rnd.Next(0, startRoom.width / 2), startRoom.top + 1 + startRoom.height / 2 + rnd.Next(0, startRoom.height / 2));
            count++;
            if (count > 500)
            {
                spawnPos = new Point(rnd.Next(startRoom.x + 1, startRoom.right - 1), rnd.Next(startRoom.y + 1, startRoom.bottom - 1));
            }

            if (count > 1000)
            {
                return;
            }
        }

        count = 0;

        while (Map[exitPos.x, exitPos.y].HaveObject || !Map[exitPos.x, exitPos.y].Walkable)
        {
            exitPos = new Point(endRoom.left + 1 + endRoom.width / 2 + rnd.Next(0, endRoom.width / 2), endRoom.top + 1 + endRoom.height / 2 + rnd.Next(0, endRoom.height / 2));
            count++;

            if (count > 500)
            {
                exitPos = new Point(rnd.Next(endRoom.left, endRoom.right - 1), rnd.Next(endRoom.top, endRoom.bottom - 1));
            }

            if (count > 1000)
            {
                return;
            }
        }

        DungeonDoor enterDoor = Instantiate(Door, ToWorldPosition(new Vector2(spawnPos.x, spawnPos.y)), new Quaternion()).GetComponent <DungeonDoor>();

        enterDoor.IsEnter = true;
        DungeonDoor exitDoor = Instantiate(Door, ToWorldPosition(new Vector2(exitPos.x, exitPos.y)), new Quaternion()).GetComponent <DungeonDoor>();

        exitDoor.IsEnter = false;
        GameObject player = GameObject.FindGameObjectWithTag("Player");

        if (player != null)
        {
            SceneManager.MoveGameObjectToScene(player, SceneManager.GetActiveScene());
            player.transform.position = Level.wasHere ? ToWorldPosition(new Vector2(exitPos.x, exitPos.y)) : ToWorldPosition(new Vector2(spawnPos.x, spawnPos.y));
            Camera.main.GetComponent <CameraManager>().Target = player;
        }
        else
        {
            Instantiate(Player, Level.wasHere ? ToWorldPosition(new Vector2(exitPos.x, exitPos.y)) : ToWorldPosition(new Vector2(spawnPos.x, spawnPos.y)), new Quaternion());
        }
    }
        public void DungeonReset()
        {
            IPooledEnumerable eable = m_Stone.GetItemsInRange(m_Stone.Size);

            ArrayList trash = new ArrayList();

            //Here we set all spawners to global values(if bool)
            if (this != null && m_Stone != null) // error check & global bool
            {
                // Find all spawners within the dungeon, and set their values.
                foreach (Item s in eable)
                {
                    if (m_UseGlobalRespawn) // control spawners
                    {
                        if (s is Spawner)
                        {
                            Spawner sp = (Spawner)s;
                            sp.MaxDelay = sp.MinDelay = m_RespawnDelay;
                            sp.Respawn();
                        }
                        else if (s is XmlSpawner) //// comment out if XMLSpawner is not installed
                        {
                            XmlSpawner sp = (XmlSpawner)s;
                            sp.MaxDelay = sp.MinDelay = m_RespawnDelay;
                            sp.Respawn();
                        }
                        else if (s is PremiumSpawner) //// comment out if PremiumSpawner is not installed
                        {
                            PremiumSpawner sp = (PremiumSpawner)s;
                            sp.MaxDelay = sp.MinDelay = m_RespawnDelay;
                            sp.Respawn();
                        }
                    }
                    // add trash to the list
                    if (s.Movable || s is Corpse)
                    {
                        trash.Add(s);
                    }
                    // Lock Dungeon Doors.
                    else if (s is DungeonDoor)
                    {
                        DungeonDoor dd = (DungeonDoor)s;
                        dd.Locked = true;
                    }
                }
            }

            // delete trash and corpses
            for (int i = 0; i < trash.Count; i++)
            {
                ((Item)trash[i]).Delete();
            }

            // Reset AFK list and restart the timers.
            if (m_PlayerMovements != null)
            {
                m_PlayerMovements.Clear();
            }
            if (m_AFKTimer != null)
            {
                if (m_AFKTimer.Running)
                {
                    m_AFKTimer.Stop();
                }
                m_AFKTimer.Start();
            }
        }
Exemple #7
0
 /// <summary>
 /// Sets all required variables.
 /// </summary>
 /// <param name="rect">The bounding rectangle of the zone.</param>
 /// <param name="onDoor">The door that is next to this zone.</param>
 public void Set(Rect rect, DungeonDoor onDoor)
 {
     OnDoor               = onDoor;
     transform.position   = rect.position;
     transform.localScale = rect.size;
 }
Exemple #8
0
    IEnumerator FindInventory()
    {
        UIManager.instance.OnPressInteractionButton += Interact;
        while (true)
        {
            yield return(new WaitForSecondsRealtime(0.2f));

            if (inInteraction)
            {
                if (!new List <Collider2D>(Physics2D.OverlapCircleAll(transform.position, SearchRadius)).Contains(findedInventory.GetComponent <Collider2D>()))
                {
                    findedInventory = null;
                    UIManager.instance.HideUIInventory();
                    inInteraction = false;
                }
            }
            else
            {
                findedItem      = null;
                findedInventory = null;
                findedDoor      = null;
                Collider2D[] things  = Physics2D.OverlapCircleAll(transform.position, SearchRadius);
                float        minDist = float.MaxValue;
                Collider2D   col     = null;
                for (int i = 0; i < things.Length; i++)
                {
                    Inventory   inv  = things[i].GetComponent <Inventory>();
                    DungeonDoor door = things[i].GetComponent <DungeonDoor>();

                    if (inv == null && things[i].GetComponent <Item>() == null && door == null)
                    {
                        continue;
                    }

                    if (door != null)
                    {
                        findedDoor = door;
                    }

                    if (inv != null)
                    {
                        PawnBehaviour pawn = inv.GetComponent <PawnBehaviour>();
                        if (pawn != null)
                        {
                            if (pawn == this || !pawn.IsDead)
                            {
                                continue;
                            }
                        }
                    }

                    float dist = Vector2.Distance(this.transform.position, things[i].transform.position);

                    if (dist < minDist)
                    {
                        minDist = dist;
                        col     = things[i];
                    }
                }

                if (col != null)
                {
                    findedInventory = col.GetComponent <Inventory>();
                    findedItem      = col.GetComponent <Item>();
                }

                if (findedInventory != null)
                {
                    UIManager.instance.ShowTextInfo("Press E to Loot");
                }
                else if (findedItem != null)
                {
                    UIManager.instance.ShowTextInfo("Press E to pick Up " + findedItem.itemName);
                }
                else if (findedDoor != null)
                {
                    UIManager.instance.ShowTextInfo(findedDoor.IsEnter ? "Press E to enter previous dungeon" : "Press E to enter next dungeon");
                }
                else
                {
                    UIManager.instance.HideTextInfo();
                }
            }
        }
    }