Exemplo n.º 1
0
        public static bool ToggleCellLock(ref CellDoor door)
        {
            door.isLocked = !door.isLocked; // For some reason doesnt save the isLocked outside of scope

            API.shared.exported.doormanager.setDoorState(door.doorID, door.isLocked, 0);
            return(door.isLocked);
        }
Exemplo n.º 2
0
        public static CellDoor AddCell(int hash, Vector3 pos, bool locked)
        {
            CellDoor door = new CellDoor(hash, pos, locked);

            Cells.Add(door);
            return(door);
        }
Exemplo n.º 3
0
 public bool Explode(CellDoor door)
 {
     if (NewRoomGenerator.instancia.canforcerooms)
     {
         return(ForcedRoom(door));
     }
     else
     {
         return(RandomRoom(door));
     }
 }
Exemplo n.º 4
0
 protected override void LoadTiles(int x, int y, int z, TiledProperties properties, bool interactive, bool animation)
 {
     base.LoadTiles(x, y, z, properties, interactive, animation);
     if (interactive && animation)
     {
         switch (properties.GetProperty("Type"))
         {
         case "CellDoor":
             tiles[x, y] = new CellDoor("cellDoor", new Index3(x, y, z), GetLayer(z).DrawOrder);
             break;
         }
     }
     tiles[x, y].AddProperties(properties);
 }
Exemplo n.º 5
0
    public bool ComprobarLugarDeSpawn(CellDoor cellDoor, NewRoom room, ref int index)
    {
        //obtengo la direccion hacia donde tengo que ir
        //obtengo todas las puertas del vecino
        //agarro una al azar
        var dirtospawn       = cellDoor.doorDir.V3ToSpawn();
        var puertasdelvecino = room.doormanager.GetDoorsByType(cellDoor.doorDir.Counter());

        if (puertasdelvecino.Count <= 0)
        {
            return(false);
        }
        var currentdoor = puertasdelvecino[UnityEngine.Random.Range(0, puertasdelvecino.Count)];

        index = currentdoor.index;


        //calculo la posicion donde la proxima room tiene que spawnear
        //lo posiciono
        //actualizo los valores
        var spawnPosition = new Vector3(
            cellDoor.transform.position.x + dirtospawn.x + currentdoor.x_localdistance_tocore,
            0,
            cellDoor.transform.position.z + dirtospawn.z + currentdoor.z_localdistance_tocore);

        room.transform.position = spawnPosition;
        room.transform.SetParent(NewRoomGenerator.instancia.gameObject.transform);
        room.RefreshValues();

        //me fijo si una vez posicionado realmente puedo posicionarlo ahi
        //
        foreach (var d in room.rangeCornerManager.ranges)
        {
            if (!NewRoomGenerator.instancia.dimensionSectors.CanAddDimensionRange(d.dimensionSectorRange))
            {
                Destroy(room.gameObject);
                return(false);
            }
            else
            {
                continue;
            }
        }

        //esto lo agrego a la lista de dimensiones, tiene que ir afuera
        //porque me tengo que asegurar de que todas sean validas primero

        return(true);
    }
Exemplo n.º 6
0
        public static int GetClosestCellIDToPosition(Vector3 position, float maxRange = 1.5f)
        {
            int   cellIndex = -1;
            float dist      = maxRange;

            for (int i = 0; i < Cells.Count; ++i)
            {
                CellDoor cell = Cells[i];

                float distance = position.DistanceTo(cell.position);
                if (distance < dist)
                {
                    cellIndex = i;
                }
            }

            return(cellIndex);
        }
Exemplo n.º 7
0
    public bool ExplodeBranch(CellDoor door)
    {
        var stackrooms = NewRoomGenerator.instancia.GetStackOffRooms();

        // RECORRO LAS ROOMS
        while (stackrooms.Count > 0)
        {
            var sample = stackrooms.Pop();

            var room = SpawnAndGet(sample.model);

            int index = 0;

            if (ComprobarLugarDeSpawn(door, room, ref index))
            {
                vecinos.Add(room);
                NewRoomGenerator.instancia.AddRangesFromRoom(room);

                SetOcuppiedDoor(door.index);
                room.doormanager.doors[index].Occuppied = true;
                room.gameObject.name = "--Room_" + NewRoomGenerator.instancia.currentCantRoomsBranch.ToString("00");
                Debug.Log("BRANCH_ " + NewRoomGenerator.instancia.currentCantRoomsBranch);
                room.isABranchRoom = true;

                NewRoomGenerator.instancia.currentCantRoomsBranch++;

                NewRoomGenerator.instancia.samples[sample.originalIndex].weight++;

                room.CreateNewRoom(this);

                return(true);
            }
            else
            {
                Destroy(room.gameObject);
                continue;
            }
        }
        return(false);
    }
Exemplo n.º 8
0
    bool ForcedRoom(CellDoor door)
    {
        var room = new NewRoom();

        Debug.Log("tengo " + NewRoomGenerator.instancia.forcerooms.Count + " forced rooms");
        Debug.Log("El current es: " + NewRoomGenerator.instancia.currentCantRooms);

        GameObject trygo = NewRoomGenerator.instancia.forcerooms[NewRoomGenerator.instancia.currentCantRooms - 1];

        if (NewRoomGenerator.instancia.currentCantRooms == NewRoomGenerator.instancia.MaxRooms)
        {
            room = SpawnAndGet(NewRoomGenerator.instancia.lastRoom);
        }
        else
        {
            room = SpawnAndGet(trygo);
        }

        int index = 0;

        if (ComprobarLugarDeSpawn(door, room, ref index))
        {
            vecinos.Add(room);
            NewRoomGenerator.instancia.AddRangesFromRoom(room);
            SetOcuppiedDoor(door.index);
            room.doormanager.doors[index].Occuppied = true;
            room.gameObject.name = "Room_" + NewRoomGenerator.instancia.currentCantRooms.ToString("00");
            NewRoomGenerator.instancia.currentCantRooms++;
            NewRoomGenerator.instancia.listrooms.Add(room);
            room.CreateNewRoom(this);
            return(true);
        }
        else
        {
            Destroy(room.gameObject);
            return(false);
        }
    }
Exemplo n.º 9
0
    bool RandomRoom(CellDoor door)
    {
        foreach (var s in NewRoomGenerator.instancia.samples)
        {
            if (NewRoomGenerator.instancia.currentCantRooms == s.IndexToAppear)
            {
                s.weight = 0;
            }
        }

        var stackrooms = NewRoomGenerator.instancia.GetStackOffRooms();

        // RECORRO LAS ROOMS

        while (stackrooms.Count > 0)
        {
            var  room   = new NewRoom();
            bool last   = false;
            var  sample = stackrooms.Pop();

            if (NewRoomGenerator.instancia.currentCantRooms == NewRoomGenerator.instancia.MaxRooms - 1)
            {
                room = SpawnAndGet(NewRoomGenerator.instancia.lastRoom);
                last = true;
            }
            else
            {
                room = SpawnAndGet(sample.model);
            }

            int index = 0;

            if (ComprobarLugarDeSpawn(door, room, ref index))
            {
                vecinos.Add(room);
                NewRoomGenerator.instancia.AddRangesFromRoom(room);

                SetOcuppiedDoor(door.index);
                room.doormanager.doors[index].Occuppied = true;

                room.gameObject.name = "Room_" + NewRoomGenerator.instancia.currentCantRooms.ToString("00");


                NewRoomGenerator.instancia.currentCantRooms++;

                NewRoomGenerator.instancia.listrooms.Add(room);

                if (!last)
                {
                    NewRoomGenerator.instancia.samples[sample.originalIndex].weight++;

                    if (sample.one_per_dungeon)
                    {
                        sample.weight = int.MaxValue;
                    }
                }


                room.CreateNewRoom(this);

                return(true);
            }
            else
            {
                Destroy(room.gameObject);
                continue;
            }
        }
        return(false);
    }
Exemplo n.º 10
0
    private void ConvertCollectionToGameObject(CellData cellData)
    {
        GameObject        go           = new GameObject(cellData.roomName);
        CellManager       cm           = go.AddComponent <CellManager>();
        BoxCollider2D     backCollider = new BoxCollider2D();
        List <CellDoor>   doors        = new List <CellDoor>();
        List <GameObject> layers       = new List <GameObject>();

        for (int i = 0; i < cellData.textures.Length; i++)
        {
            //Create Layer and center it with parent
            GameObject layerObject = new GameObject("Layer:" + i.ToString());
            layerObject.transform.parent   = go.transform;
            layerObject.transform.position = Vector2.zero;

            //Add spriteRenderer Add sprite from texture
            SpriteRenderer spriteRenderer = layerObject.AddComponent <SpriteRenderer>();
            spriteRenderer.sprite = Sprite.Create(cellData.textures[i], new Rect(0, 0, cellData.textures[i].width, cellData.textures[i].height), new Vector2(0.5f, 0.5f), 100, 0, SpriteMeshType.Tight);

            //Sort DrawLayer
            if (cellData.layer[i] == 0)
            {
                spriteRenderer.sortingLayerName = "Background";
                layerObject.tag = "BackWall";
                layerObject.AddComponent <Rigidbody2D>().gravityScale = 0;
                backCollider           = layerObject.AddComponent <BoxCollider2D>();
                backCollider.isTrigger = true;
            }
            if (cellData.layer[i] == 1)
            {
                spriteRenderer.sortingLayerName = "Midground";
            }
            if (cellData.layer[i] == 2)
            {
                spriteRenderer.sortingLayerName = "Foreground";
            }
            //Add Collision
            if (cellData.collision[i])
            {
                PolygonCollider2D pc2d = layerObject.AddComponent <PolygonCollider2D>();
                if (cellData.points != null)
                {
                    pc2d.points = cellData.points;
                }
            }

            layers.Add(layerObject);
        }

        for (int i = 0; i < cellData.EntranceDir.Length; i++)
        {
            GameObject cellDoor = new GameObject("Cell Door " + cellData.EntranceDir[i]);
            CellDoor   cd       = cellDoor.AddComponent <CellDoor>();
            cellDoor.transform.parent        = go.transform;
            cellDoor.transform.localPosition = cellData.EntrancePos[i];
            cellDoor.AddComponent <BoxCollider2D>();
            cd.Dir      = cellData.EntranceDir[i];
            cd.backWall = backCollider;
            doors.Add(cd);
        }

        //Add and fill CellManager

        cm.cellData  = cellData;
        cm.Layers    = layers.ToArray();
        cm.CellDoors = doors.ToArray();
    }