Exemple #1
0
    void setRoom(string file)
    {
        TextAsset sr        = Resources.Load("rooms/" + file) as TextAsset;
        string    roomTiles = sr.text;

        Debug.Log(roomTiles);
        RoomTile[] positions = new RoomTile[roomTiles.Length / 3];

        for (int i = 0; i < roomTiles.Length; i += 3)
        {
            RoomTile tile = new RoomTile(new Vector2(int.Parse(roomTiles[i].ToString()),
                                                     int.Parse(roomTiles[i + 1].ToString())),
                                         int.Parse(roomTiles[i + 2].ToString()));
            positions[i / 3] = tile;
        }

        Room newRoom = new Room(positions);

        Room[] curRooms = new Room[rooms.Length + 1];

        for (int i = 0; i < rooms.Length; i++)
        {
            curRooms[i] = rooms[i];
        }

        curRooms[curRooms.Length - 1] = newRoom;
        //debugRoom(newRoom);
        rooms = curRooms;
    }
    public RoomTile[,] GenerateRoom(int size)
    {
        // instantiate tiles
        size += 2;
        RoomTile[,] tiles = new RoomTile[size, size];
        roomTypes         = new RoomTile.Type[size, size];
        for (int j = 0; j < tiles.GetLength(1); ++j)
        {
            for (int i = 0; i < tiles.GetLength(0); ++i)
            {
                RoomTile _tile = Instantiate(roomTile, Vector2.up * j + Vector2.right * i, Quaternion.Euler(Vector3.zero));
                tiles[i, j] = _tile;
            }
        }

        SetupTileTypes(tiles);
        if (PlayerPrefs.GetInt("Level") % 6 != 5)
        {
            try
            {
                SetupWalls(tiles);
            }
            catch (System.Exception e)
            {
                print(e.Message);
                SceneManager.LoadScene(SceneManager.GetActiveScene().name);
            }
        }
        PaintBackground(tiles);
        PaintWalls(tiles);
        //DebugTiles();

        return(tiles);
    }
Exemple #3
0
        public RoomTemplate(RoomTemplate other)
        {
            Template = new RoomTile[other.Template.GetLength(0), other.Template.GetLength(1)];

            for (int x = 0; x < other.Template.GetLength(0); x++)
            {
                for (int y = 0; y < other.Template.GetLength(1); y++)
                {
                    Template[x, y] = other.Template[x, y];
                }
            }

            Accessories = new RoomTile[other.Accessories.GetLength(0), other.Accessories.GetLength(1)];

            for (int x = 0; x < other.Accessories.GetLength(0); x++)
            {
                for (int y = 0; y < other.Accessories.GetLength(1); y++)
                {
                    Accessories[x, y] = other.Accessories[x, y];
                }
            }

            PlacementType = other.PlacementType;
            Rotation      = other.Rotation;
            CanRotate     = other.CanRotate;
            Probability   = other.Probability;
        }
        public override void OnCycle()
        {
            if (SpeechTimer <= 0)
            {
                Entity.OnChat("testing", 1, ChatType.CHAT);
                SpeechTimer = 20;
            }
            else
            {
                SpeechTimer--;
            }

            if (Entity.CanWalk)
            {
                if (ActionTimer <= 0)
                {
                    RoomTile tile = CurrentRoom.Mapping.RandomWalkableTile;
                    if (tile != null)
                    {
                        Entity.TargetPosition = new UserPosition()
                        {
                            X = tile.Position.X,
                            Y = tile.Position.Y
                        };
                        Entity.Path = CurrentRoom.PathFinder.Path(Entity);
                    }
                    ActionTimer = Randomness.RandomNumber(5, 20);
                }
                else
                {
                    ActionTimer--;
                }
            }
        }
 private void PaintWall(RoomTile tile, int code)
 {
     if (code == 255)
     {
         tile.SetWallStyle(4);
     }
     else if ((code & 253) == 253)
     {
         tile.SetWallStyle(6);
     }
     else if ((code & 247) == 247)
     {
         tile.SetWallStyle(11);
     }
     else if ((code & 223) == 223)
     {
         tile.SetWallStyle(12);
     }
     else if ((code & 127) == 127)
     {
         tile.SetWallStyle(7);
     }
     else if ((code & 124) == 124)
     {
         tile.SetWallStyle(1);
     }
     else if ((code & 241) == 241)
     {
         tile.SetWallStyle(5);
     }
     else if ((code & 199) == 199)
     {
         tile.SetWallStyle(9);
     }
     else if ((code & 31) == 31)
     {
         tile.SetWallStyle(3);
     }
     else if ((code & 7) == 7)
     {
         tile.SetWallStyle(8);
     }
     else if ((code & 28) == 28)
     {
         tile.SetWallStyle(0);
     }
     else if ((code & 112) == 112)
     {
         tile.SetWallStyle(2);
     }
     else if ((code & 193) == 193)
     {
         tile.SetWallStyle(10);
     }
     else
     {
         tile.SetWallStyle(13);
     }
 }
Exemple #6
0
 public RoomUserOnRollerComposer(RoomEntity roomUser, RoomItem roller, RoomTile oldTile, RoomTile newTile, double offset = 0)
 {
     this.roomUser = roomUser;
     this.roller   = roller;
     this.oldTile  = oldTile;
     this.newTile  = newTile;
     this.offset   = offset;
 }
 public FloorItemOnRollerComposer(RoomItem item, RoomItem roller, RoomTile oldTile, RoomTile newTile, double offset = 0)
 {
     this.item    = item;
     this.roller  = roller;
     this.oldTile = oldTile;
     this.newTile = newTile;
     this.offset  = offset;
 }
Exemple #8
0
 void debugRoom(Room room)
 {
     Debug.Log("ROOMSTART");
     for (int i = 0; i < room.roomtiles.Length; i++)
     {
         RoomTile tile = room.roomtiles[i];
         Debug.Log("x: " + tile.pos.x + ", y: " + tile.pos.y + ", type; " + tile.type);
     }
     Debug.Log("ROOMEND");
 }
Exemple #9
0
        static JsonData SerializeRoomTile(RoomTile tile, BackgroundInfo[] bgs)
        {
            var r = CreateObj();

            r["pos"]       = SerializePoint(tile.Position);
            r["bg"]        = bgs[tile.DefIndex].Name;
            r["sourcepos"] = SerializePoint(tile.SourcePosition);
            r["size"]      = SerializeSize(tile.Size);
            r["scale"]     = SerializePoint(tile.Scale);
            r["colour"]    = tile.Colour.ToHexString();

            return(r);
        }
Exemple #10
0
        private static void WriteRoomTile(BBData data, RoomTile rt)
        {
            data.Buffer.Write(new RoomTileEntry
            {
                DefIndex  = rt.DefIndex ?? 0xFFFFFFFF,
                Position  = rt.Position,
                SourcePos = rt.SourcePosition,
                Size      = rt.Size,
                Scale     = rt.Scale,
                Colour    = rt.Colour,

                TileDepth  = rt.Depth,
                InstanceID = rt.InstanceID
            });
        }
Exemple #11
0
        public RoomTemplate(int sx, int sy)
        {
            Template    = new RoomTile[sx, sy];
            Accessories = new RoomTile[sx, sy];

            for (int x = 0; x < sx; x++)
            {
                for (int y = 0; y < sy; y++)
                {
                    Template[x, y]    = RoomTile.None;
                    Accessories[x, y] = RoomTile.None;
                }
            }
            Probability = 1.0f;
        }
        static RoomTile       ReadRoomTile(GMFileContent content, IntPtr p)
        {
            var entry = (RoomTileEntry *)p;

            var t = new RoomTile();

            t.DefIndex       = entry->DefIndex;
            t.Position       = entry->Position;
            t.SourcePosition = entry->SourcePos;
            t.Size           = entry->Size;
            t.Scale          = entry->Scale;
            t.Colour         = entry->Colour;

            return(t);
        }
Exemple #13
0
        static JsonData SerializeRoomTile(RoomTile tile, LazyArray <BackgroundInfo> bgs)
        {
            var r = CreateObj();

            r["pos"]       = SerializePoint(tile.Position);
            r["bg"]        = bgs[tile.DefIndex].Name;
            r["sourcepos"] = SerializePoint(tile.SourcePosition);
            r["size"]      = SerializeSize(tile.Size);
            r["scale"]     = SerializePoint(tile.Scale);
            r["colour"]    = tile.Colour.ToHexString();

            r["tiledepth"]  = tile.Depth;
            r["instanceid"] = tile.InstanceID;

            return(r);
        }
Exemple #14
0
        public void RegenerateMap()
        {
            Tiles = new RoomTile[model.MapSizeX, model.MapSizeY];

            for (int y = 0; y < model.MapSizeY; y++)
            {
                for (int x = 0; x < model.MapSizeX; x++)
                {
                    Tiles[x, y] = new RoomTile(
                        room,
                        new Position(x, y),
                        model.TileHeights[x, y],
                        model.TileStates[x, y]
                        );
                }
            }
        }
    private int GetAmountOfTilesOfType(RoomTile tileType)
    {
        int amount = 0;

        foreach (List <(RoomTile, GameObject)> tiles in room.content)
        {
            foreach ((RoomTile, GameObject)tile in tiles)
            {
                if (tile.Item1 == tileType)
                {
                    amount++;
                }
            }
        }

        return(amount);
    }
Exemple #16
0
        public static RoomTile[,] CreateFromRoom(Room room, ChunkManager chunks)
        {
            BoundingBox box0   = room.GetBoundingBox();
            BoundingBox box    = new BoundingBox(box0.Min + Vector3.Up, box0.Max + Vector3.Up);
            BoundingBox bigBox = new BoundingBox(box0.Min + Vector3.Up + new Vector3(-1, 0, -1), box0.Max + Vector3.Up + new Vector3(1, 0, 1));
            int         nr     = Math.Max((int)(box.Max.X - box.Min.X), 1);
            int         nc     = Math.Max((int)(box.Max.Z - box.Min.Z), 1);

            RoomTile[,] toReturn = new RoomTile[nr + 2, nc + 2];

            Dictionary <Point, Voxel> voxelDict = new Dictionary <Point, Voxel>();
            List <Voxel> voxelsInRoom           = chunks.GetVoxelsIntersecting(bigBox);

            foreach (Voxel vox in voxelsInRoom)
            {
                voxelDict[new Point((int)(vox.Position.X - box.Min.X) + 1, (int)(vox.Position.Z - box.Min.Z) + 1)] = vox;
            }

            for (int r = 0; r < nr + 2; r++)
            {
                for (int c = 0; c < nc + 2; c++)
                {
                    toReturn[r, c] = RoomTile.Edge;
                }
            }

            foreach (KeyValuePair <Point, Voxel> voxPair in voxelDict)
            {
                Voxel vox = voxPair.Value;
                Point p   = voxPair.Key;

                if (vox.IsEmpty && p.X > 0 && p.X < nr + 1 && p.Y > 0 && p.Y < nc + 1)
                {
                    toReturn[p.X, p.Y] = RoomTile.Open;
                }
                else if (vox.TypeName != "empty")
                {
                    toReturn[p.X, p.Y] = RoomTile.Wall;
                }
            }

            return(toReturn);
        }
Exemple #17
0
        static RoomTile       ReadRoomTile(GMFileContent content, IntPtr p)
        {
            var entry = (RoomTileEntry *)p;

            var t = new RoomTile();

            t.Position       = entry->Position;
            t.SourcePosition = entry->SourcePos;
            t.Size           = entry->Size;
            t.Scale          = entry->Scale;
            t.Colour         = entry->Colour;

            t.Depth      = entry->TileDepth;
            t.InstanceID = entry->InstanceID;

            t.DefIndex = entry->DefIndex == 0xFFFFFFFF ? null : (uint?)entry->DefIndex;

            return(t);
        }
Exemple #18
0
        public static RoomTile[,] CreateFromRoom(List <VoxelHandle> voxelsInRoom, ChunkManager chunks)
        {
            var         box0   = VoxelHelpers.GetVoxelBoundingBox(voxelsInRoom);
            BoundingBox box    = new BoundingBox(box0.Min + Vector3.Up, box0.Max + Vector3.Up);
            BoundingBox bigBox = new BoundingBox(box0.Min - Vector3.One, box0.Max + Vector3.One);
            int         nr     = Math.Max((int)(box.Max.X - box.Min.X), 1);
            int         nc     = Math.Max((int)(box.Max.Z - box.Min.Z), 1);

            RoomTile[,] toReturn = new RoomTile[nr + 2, nc + 2];

            var voxelDict = new Dictionary <Point, VoxelHandle>();

            foreach (var vox in voxelsInRoom)
            {
                voxelDict[new Point((int)(vox.Coordinate.X - box.Min.X) + 1, (int)(vox.Coordinate.Z - box.Min.Z) + 1)] = vox;
            }

            for (int r = 0; r < nr + 2; r++)
            {
                for (int c = 0; c < nc + 2; c++)
                {
                    toReturn[r, c] = RoomTile.Edge;
                }
            }

            foreach (var voxPair in voxelDict)
            {
                var   vox = VoxelHelpers.GetVoxelAbove(voxPair.Value);
                Point p   = voxPair.Key;

                if (vox.IsEmpty && p.X > 0 && p.X < nr + 1 && p.Y > 0 && p.Y < nc + 1)
                {
                    toReturn[p.X, p.Y] = RoomTile.Open;
                }
                else if (vox.IsValid && !vox.IsEmpty)
                {
                    toReturn[p.X, p.Y] = RoomTile.Wall;
                }
            }

            return(toReturn);
        }
Exemple #19
0
        static RoomTile       DeserializeRoomTile(dynamic j, BackgroundInfo[] bgs)
        {
            var r = new RoomTile
            {
                Position       = DeserializePoint(j.pos),
                SourcePosition = DeserializePoint(j.sourcepos),
                Size           = DeserializeSize(j.size),
                Scale          = DeserializePointF(j.scale),
                Colour         = ParseColour((JsonData)j.colour)
            };

            var i = Array.FindIndex(bgs, b => b.Name == (string)j.bg);

            if (i > -1)
            {
                r.DefIndex = (uint)i;
            }
            //TODO: emit warning instead

            return(r);
        }
Exemple #20
0
    // Use this for initialization
    void Start()
    {
        RoomTile[] roomtiles1 = new RoomTile[17];

        roomtiles1[0]  = new RoomTile(Vector2.zero, 2);
        roomtiles1[1]  = new RoomTile(new Vector2(), 2);
        roomtiles1[2]  = new RoomTile(new Vector2(), 2);
        roomtiles1[3]  = new RoomTile(new Vector2(), 2);
        roomtiles1[4]  = new RoomTile(new Vector2(), 2);
        roomtiles1[5]  = new RoomTile(new Vector2(), 2);
        roomtiles1[6]  = new RoomTile(new Vector2(), 2);
        roomtiles1[7]  = new RoomTile(new Vector2(), 2);
        roomtiles1[8]  = new RoomTile(new Vector2(), 2);
        roomtiles1[9]  = new RoomTile(new Vector2(), 2);
        roomtiles1[10] = new RoomTile(new Vector2(), 2);
        roomtiles1[11] = new RoomTile(new Vector2(), 2);
        roomtiles1[12] = new RoomTile(new Vector2(), 2);
        roomtiles1[13] = new RoomTile(new Vector2(), 2);
        roomtiles1[14] = new RoomTile(new Vector2(), 2);
        roomtiles1[15] = new RoomTile(new Vector2(), 2);
        roomtiles1[16] = new RoomTile(new Vector2(), 2);
    }
Exemple #21
0
        static RoomTile DeserializeRoomTile(JsonData j, BackgroundInfo[] bgs)
        {
            var r = new RoomTile
            {
                Position       = DeserializePoint(j["pos"]),
                SourcePosition = DeserializePoint(j["sourcepos"]),
                Size           = DeserializeSize(j["size"]),
                Scale          = DeserializePointF(j["scale"]),
                Colour         = ParseColour(j["colour"]),
                Depth          = (uint)j["tiledepth"],
                InstanceID     = (uint)j["instanceid"]
            };

            var i = Array.FindIndex(bgs, b => b.Name == (string)j["bg"]);

            if (i > -1)
            {
                r.DefIndex = (uint)i;
            }
            //TODO: emit warning instead

            return(r);
        }
Exemple #22
0
        public int PlaceTemplate(ref RoomTile[,] room, ref float[,] rotations, int seedR, int seedC)
        {
            int nr = room.GetLength(0);
            int nc = room.GetLength(1);
            int tr = Template.GetLength(0);
            int tc = Template.GetLength(1);

            for(int r = 0; r < tr; r++)
            {
                for(int c = 0; c < tc; c++)
                {
                    int x = seedR + r;
                    int y = seedC + c;

                    RoomTile desired = Template[r, c];

                    // Ignore tiles with unspecified conditions
                    if(desired == RoomTile.None)
                    {
                        continue;
                    }

                    bool hasWall = Has(desired, RoomTile.Wall);
                    bool hasOpen = Has(desired, RoomTile.Open);
                    bool hasEdge = Has(desired, RoomTile.Edge);
                    bool onEdge = (x >= nr - 1 || y >= nc - 1 || x < 1 || y < 1);
                    bool outOfBounds = onEdge && (x >= nr  || y >= nc  || x < 0 || y < 0);
                    if(onEdge && !hasEdge)
                    {
                        return -1;
                    }
                    else if(outOfBounds && desired != RoomTile.None)
                    {
                        return -1;
                    }
                    else if(outOfBounds)
                    {
                        continue;
                    }

                    RoomTile curent = room[x, y];

                    bool meetsWallRequirements = !hasWall || (curent == RoomTile.Wall);
                    bool meetsEdgeRequirements = (!hasEdge && !hasWall) || (hasEdge && curent == RoomTile.Edge);
                    bool meetsOpenRequriments = !hasOpen || (curent == RoomTile.Open);
                    bool doesntIntersect = hasEdge || hasWall || curent == RoomTile.Open;

                    // Tiles conflict when walls exist in the BuildRoom already, or other objects
                    // block the template.
                    if (!(((meetsWallRequirements || meetsEdgeRequirements) && meetsOpenRequriments && doesntIntersect)))
                    {
                        return -1;
                    }
                }
            }

            int toReturn = 0;
            // Otherwise, we return the number of tiles which could be successfully placed.
            for(int r = 0; r < tr; r++)
            {
                for(int c = 0; c < tc; c++)
                {
                    int x = seedR + r;
                    int y = seedC + c;

                    if(x >= nr - 1 || y >= nc - 1 || x <= 0 || y <= 0)
                    {
                        continue;
                    }

                    RoomTile desiredTile = Template[r, c];
                    RoomTile unimport = Accessories[r, c];
                    RoomTile currentTile = room[x, y];

                    if((currentTile == RoomTile.Open || currentTile == RoomTile.Edge) && desiredTile != RoomTile.None && !Has(desiredTile, RoomTile.Edge) && ! Has(desiredTile, RoomTile.Wall) && desiredTile != RoomTile.Open)
                    {
                        room[x, y] = desiredTile;
                        rotations[x, y] = Rotation;
                        toReturn++;
                    }

                    if((currentTile != RoomTile.Open && currentTile != RoomTile.Edge) || unimport == RoomTile.Open || unimport == RoomTile.None || unimport == RoomTile.Edge)
                    {
                        continue;
                    }

                    room[x, y] = unimport;
                    toReturn++;
                }
            }

            return toReturn;
        }
Exemple #23
0
 public static bool Has(RoomTile requirements, RoomTile value)
 {
     return (requirements & value) == value;
 }
Exemple #24
0
        public static RoomTile[,] CreateFromRoom(Room room, ChunkManager chunks)
        {
            BoundingBox box0 = room.GetBoundingBox();
            BoundingBox box = new BoundingBox(box0.Min + Vector3.Up, box0.Max + Vector3.Up);
            BoundingBox bigBox = new BoundingBox(box0.Min + Vector3.Up + new Vector3(-1, 0, -1), box0.Max + Vector3.Up + new Vector3(1, 0, 1));
            int nr = Math.Max((int) (box.Max.X - box.Min.X), 1);
            int nc = Math.Max((int) (box.Max.Z - box.Min.Z), 1);

            RoomTile[,] toReturn = new RoomTile[nr + 2, nc + 2];

            Dictionary<Point, Voxel> voxelDict = new Dictionary<Point, Voxel>();
            List<Voxel> voxelsInRoom = chunks.GetVoxelsIntersecting(bigBox);
            foreach(Voxel vox in voxelsInRoom)
            {
                voxelDict[new Point((int)(vox.Position.X - box.Min.X) + 1, (int)(vox.Position.Z - box.Min.Z) + 1)] = vox;
            }

            for(int r = 0; r < nr + 2; r++)
            {
                for(int c = 0; c < nc + 2; c++)
                {
                    toReturn[r, c] = RoomTile.Edge;
                }
            }

            foreach(KeyValuePair<Point, Voxel> voxPair in voxelDict)
            {
                Voxel vox = voxPair.Value;
                Point p = voxPair.Key;

                if(vox.IsEmpty && p.X > 0 && p.X < nr + 1 && p.Y > 0 && p.Y < nc + 1)
                {
                    toReturn[p.X, p.Y] = RoomTile.Open;
                }
                else if(vox.TypeName != "empty")
                {
                    toReturn[p.X, p.Y] = RoomTile.Wall;
                }
            }

            return toReturn;
        }
Exemple #25
0
        public RoomTemplate(int sx, int sy)
        {
            Template = new RoomTile[sx, sy];
            Accessories = new RoomTile[sx, sy];

            for(int x = 0; x < sx; x++)
            {
                for(int y = 0; y < sy; y++)
                {
                    Template[x, y] = RoomTile.None;
                    Accessories[x, y] = RoomTile.None;
                }
            }
            Probability = 1.0f;
        }
    void Start()
    {
        NodeTiles = new List <RoomTile>();
        Debug.Log("SpriteSheetName: " + SpriteSheet.name + ", Boss: " + BossRoom + ", Start: " + StarterRoom);
        TileSprites = Resources.LoadAll <Sprite>(SpriteSheet.name);

        for (int i = 0; i < tilemap.transform.childCount; i++)
        {
            GateScript gate = tilemap.transform.GetChild(i).GetComponent <GateScript>();
            if (gate != null)
            {
                Gates.Add(gate);
            }
            GateTriggerScript trigger = tilemap.transform.GetChild(i).GetComponent <GateTriggerScript>();
            if (trigger != null)
            {
                trigger.parentRoom = this;
            }
            RoomTile tile = tilemap.transform.GetChild(i).GetComponent <RoomTile>();
            //Debug.Log("TileID: " + tile.ID + ", TileNodeID: " + tile.NodeID);
            if (tile.Node)
            {
                bool Node = false;
                foreach (GenerationNode GenNode in FloorHandler.generationRooms[respresentedX, respresentedY].Nodes)
                {
                    if (GenNode.exitDirection == tile.Direction)
                    {
                        Node = true;
                    }
                }
                if (Node)
                {
                    tile.spriteRenderer.sprite = TileSprites[tile.NodeID];
                    if (gate != null)
                    {
                        gate.Node = true;
                    }
                }
                else
                {
                    if (tile.ColliderIfNotNode)
                    {
                        tilemap.transform.GetChild(i).GetComponent <BoxCollider2D>().enabled = true;
                        if (tile.DefaultLayer == false)
                        {
                            tilemap.transform.GetChild(i).gameObject.layer = 9;
                        }
                    }
                    if (gate != null)
                    {
                        gate.Node = false;
                        gate.GetComponent <Animator>().enabled = false;
                    }
                    tile.spriteRenderer.sprite = TileSprites[tile.ID];
                }
            }
            else if (!tile.Node)
            {
                if (tile.ColliderIfNotNode)
                {
                    tilemap.transform.GetChild(i).GetComponent <BoxCollider2D>().enabled = true;
                    if (tile.DefaultLayer == false)
                    {
                        tilemap.transform.GetChild(i).gameObject.layer = 9;
                    }
                }
                tile.spriteRenderer.sprite = TileSprites[tile.ID];
            }
        }

        for (int i = 0; i < transform.childCount; i++)
        {
            Enemy TempEnemy = transform.GetChild(i).GetComponentInChildren <Enemy>();
            if (TempEnemy != null)
            {
                TempEnemy.OnDeath.AddListener(OnDeath);
                RoomEnemies.Add(TempEnemy);
                TotalSpawnedEnemiesInRoom++;
            }
        }
    }
Exemple #27
0
        public static void Start(List <RoomEntity> users)
        {
            users.ForEach(usr =>
            {
                if (!usr.Disposing)
                {
                    if (usr.TargetPosition != null && usr.Path != null && usr.Path.Count > 0)
                    {
                        if (usr.Actions.Has("mv"))
                        {
                            usr.Actions.Remove("mv");
                        }
                        if (usr.Actions.Has("sit"))
                        {
                            usr.Actions.Remove("sit");
                        }
                        if (usr.Actions.Has("lay"))
                        {
                            usr.Actions.Remove("lay");
                        }

                        RoomTile oldTile = usr.Room.Mapping.Tiles[usr.Position.X, usr.Position.Y];
                        oldTile.RemoveEntity(usr);

                        Point p       = usr.Path.First();
                        RoomTile tile = usr.Room.Mapping.Tiles[p.X, p.Y];
                        tile.AddEntity(usr);

                        double height = 0.0;

                        if (oldTile.TopItem != null)
                        {
                            // walk off
                            if (tile.TopItem == null || tile.TopItem != oldTile.TopItem)
                            {
                                oldTile.TopItem.GetInteractor().OnUserWalkOff(usr, usr.Room, oldTile.TopItem);
                            }
                        }

                        if (tile.TopItem != null)
                        {
                            // walk on
                            if (oldTile.TopItem == null || oldTile.TopItem != tile.TopItem)
                            {
                                tile.TopItem.GetInteractor().OnUserWalkOn(usr, usr.Room, tile.TopItem);
                            }

                            height += tile.TopItem.Position.Z;
                            if (!tile.TopItem.ItemData.CanSit && !tile.TopItem.ItemData.CanLay)
                            {
                                // todo: multiheight furni
                                height += tile.TopItem.ItemData.Height;
                            }
                        }
                        else
                        {
                            height += tile.Position.Z;
                        }

                        usr.Actions.Add("mv", p.X + "," + p.Y + "," + height);
                        usr.Position.Rotation     = usr.Room.PathFinder.Rotation(usr.Position.X, usr.Position.Y, p.X, p.Y);
                        usr.Position.HeadRotation = usr.Position.Rotation;
                        usr.Path.RemoveFirst();
                        usr.Room.EntityManager.Send(new RoomUserStatusComposer(usr));
                        usr.Position.X = p.X;
                        usr.Position.Y = p.Y;
                        usr.Position.Z = height;

                        if (usr.Path.Count() != 0)
                        {
                            usr.Path = usr.Room.PathFinder.Path(usr);
                        }
                    }
                    else
                    {
                        if (usr.TargetPosition.X == usr.Position.X && usr.TargetPosition.Y == usr.Position.Y)
                        {
                            bool update = false;
                            if (usr.Actions.Has("mv"))
                            {
                                usr.Actions.Remove("mv");
                                update = true;
                            }

                            RoomTile tile = usr.Room.Mapping.Tiles[usr.TargetPosition.X, usr.TargetPosition.Y];

                            if (tile.TopItem != null && tile.TopItem.ItemData.CanSit)
                            {
                                usr.Actions.Add("sit", tile.TopItem.ItemData.Height.ToString());
                                usr.Position.Rotation     = tile.TopItem.Position.Rotation;
                                usr.Position.HeadRotation = usr.Position.Rotation;
                                usr.Position.Z            = tile.TopItem.ItemData.Height + tile.TopItem.Position.Z;
                                usr.isSitting             = false;
                                update = true;
                            }
                            else if (tile.TopItem != null && tile.TopItem.ItemData.CanLay)
                            {
                                usr.Actions.Add("lay", tile.TopItem.ItemData.Height.ToString());
                                usr.Position.Rotation     = tile.TopItem.Position.Rotation;
                                usr.Position.HeadRotation = usr.Position.Rotation;
                                usr.Position.Z            = tile.TopItem.ItemData.Height + tile.TopItem.Position.Z;
                                usr.isSitting             = false;
                                update = true;
                            }
                            else
                            {
                                if (!usr.isSitting && usr.Actions.Has("sit"))
                                {
                                    usr.Actions.Remove("sit");
                                    usr.Position.Z = tile.Position.Z;
                                    update         = true;
                                }

                                if (usr.Actions.Has("lay"))
                                {
                                    usr.Actions.Remove("lay");
                                    usr.Position.Z = tile.Position.Z;
                                    update         = true;
                                }
                            }

                            if (update)
                            {
                                usr.Room.EntityManager.Send(new RoomUserStatusComposer(usr));
                            }

                            if (usr.Room.Model.Door.X == usr.Position.X && usr.Room.Model.Door.Y == usr.Position.Y)
                            {
                                usr.Room.EntityManager.OnUserLeave(usr);
                                usr.Player.Session.Send(new HotelViewComposer());
                            }
                        }
                    }
                }
            });
        }
Exemple #28
0
 public static bool Has(RoomTile requirements, RoomTile value)
 {
     return((requirements & value) == value);
 }
Exemple #29
0
        public void WalkCycle()
        {
            try
            {
                if (this.TargetPosition != null && this.Path != null && this.Path.Count > 0)
                {
                    if (this.Actions.Has("mv"))
                    {
                        this.Actions.Remove("mv");
                    }
                    if (this.Actions.Has("sit"))
                    {
                        this.Actions.Remove("sit");
                    }
                    if (this.Actions.Has("lay"))
                    {
                        this.Actions.Remove("lay");
                    }

                    RoomTile oldTile = this.Room.Mapping.Tiles[this.Position.X, this.Position.Y];
                    oldTile.RemoveEntity(this);

                    Point    p    = this.Path.First();
                    RoomTile tile = this.Room.Mapping.Tiles[p.X, p.Y];
                    tile.AddEntity(this);

                    double height = 0.0;

                    if (oldTile.TopItem != null)
                    {
                        // walk off
                        if (tile.TopItem == null || tile.TopItem != oldTile.TopItem)
                        {
                            oldTile.TopItem.GetInteractor().OnUserWalkOff(this, this.Room, oldTile.TopItem);
                        }
                    }

                    if (tile.TopItem != null)
                    {
                        // walk on
                        if (oldTile.TopItem == null || oldTile.TopItem != tile.TopItem)
                        {
                            tile.TopItem.GetInteractor().OnUserWalkOn(this, this.Room, tile.TopItem);
                        }

                        height += tile.TopItem.Position.Z;
                        if (!tile.TopItem.ItemData.CanSit && !tile.TopItem.ItemData.CanLay)
                        {
                            // todo: multiheight furni
                            height += tile.TopItem.ItemData.Height;
                        }
                    }
                    else
                    {
                        height += tile.Position.Z;
                    }

                    this.Actions.Add("mv", p.X + "," + p.Y + "," + height);
                    this.Position.Rotation     = this.Room.PathFinder.Rotation(this.Position.X, this.Position.Y, p.X, p.Y);
                    this.Position.HeadRotation = this.Position.Rotation;
                    this.Path.RemoveFirst();
                    this.Room.EntityManager.Send(new RoomUserStatusComposer(this));
                    this.Position.X = p.X;
                    this.Position.Y = p.Y;
                    this.Position.Z = height;

                    if (this.Path.Count() != 0)
                    {
                        this.Path = this.Room.PathFinder.Path(this);
                    }
                }
                else
                {
                    bool update = false;
                    if (this.Actions.Has("mv"))
                    {
                        this.Actions.Remove("mv");
                        update = true;
                    }
                    RoomTile tile = this.Room.Mapping.Tiles[this.TargetPosition.X, this.TargetPosition.Y];

                    if (tile.TopItem != null && tile.TopItem.ItemData.CanSit)
                    {
                        this.Actions.Add("sit", tile.TopItem.ItemData.Height + 0.1 + "");
                        this.Position.Rotation     = tile.TopItem.Position.Rotation;
                        this.Position.HeadRotation = this.Position.Rotation;
                        this.Position.Z            = tile.TopItem.Position.Z;
                        this.isSitting             = false;
                        update = true;
                    }
                    else if (tile.TopItem != null && tile.TopItem.ItemData.CanLay)
                    {
                        this.Actions.Add("lay", tile.TopItem.ItemData.Height + 0.1 + "");
                        this.Position.Rotation     = tile.TopItem.Position.Rotation;
                        this.Position.HeadRotation = this.Position.Rotation;
                        this.Position.Z            = tile.TopItem.Position.Z;
                        this.isSitting             = false;
                        update = true;
                    }
                    else
                    {
                        if (!this.isSitting && this.Actions.Has("sit"))
                        {
                            this.Actions.Remove("sit");
                            this.Position.Z = tile.Position.Z;
                            update          = true;
                        }

                        if (this.Actions.Has("lay"))
                        {
                            this.Actions.Remove("lay");
                            this.Position.Z = tile.Position.Z;
                            update          = true;
                        }
                    }

                    if (update)
                    {
                        this.Room.EntityManager.Send(new RoomUserStatusComposer(this));
                    }

                    if ((this.Room.Model.Door.X == this.Position.X && this.Room.Model.Door.Y == this.Position.Y) &&
                        this.Type == RoomEntityType.Player)
                    {
                        //this.Player.Session.Send(new HotelViewComposer());
                        //this.Room.EntityManager.OnUserLeave(this);
                    }
                }
            }
            catch { }
        }
Exemple #30
0
 public RoomTemplate(PlacementType type, RoomTile[,] template, RoomTile[,] accessories)
 {
     PlacementType = type;
     Template = template;
     Accessories = accessories;
     CanRotate = true;
     Probability = 1.0f;
     Rotation = 0.0f;
 }
Exemple #31
0
    public void createLevel()
    {
        doors     = 0;     // Reset doors to 0
        levelSize = new Vector2(levelSize.x + level, levelSize.y + level);
        map       = new int[(int)levelSize.x, (int)levelSize.y];
        shop      = false;
        level++;

        int rooms      = Random.Range(4 + (int)Mathf.Floor(level / 6), 7 + (int)Mathf.Floor((float)level / 3)); //TODO Make global vars for these values
        int eventRooms = Random.Range(0, 2 + (int)Mathf.Floor(level / 5));                                      //TODO Make global vars for these values


        //TODO Improve placement of these so that they are further apart from eachother
        Vector2 startPos = new Vector2(Mathf.Floor(Random.Range(1, levelSize.x - 2)), Mathf.Floor(Random.Range(1, levelSize.y - 2)));
        Vector2 exitPos  = new Vector2(Mathf.Floor(Random.Range(1, levelSize.x - 2)), Mathf.Floor(Random.Range(1, levelSize.y - 2)));

        createRoom(startPos, "start");
        createRoom(exitPos, "exit");


        GameObject player = GameObject.Find("player");

        player.transform.position = new Vector3((startPos.x * 5), 4, (startPos.y * 5));
        for (int i = 0; i < rooms; i++)
        {
            createRoom(new Vector2(Mathf.Floor(Random.Range(1, levelSize.x - 2)), Mathf.Floor(Random.Range(1, levelSize.y - 2))), "room");
        }

        while (doors > 0)
        {
            int num = 1000;
            for (int x = 0; x < levelSize.x; x++)
            {
                for (int y = 0; y < levelSize.y; y++)
                {
                    num++;
                    if (map[x, y] == 3)
                    {
                        if (!whereHall(new Vector2(x, y), num))
                        {
                            //Debug.Log("x: " + x + ", y: " + y);
                            map[x, y] = 6;
                            doors--;
                        }
                    }
                }
            }
        }

        for (int a = 0; a < levelSize.x; a++)
        {
            for (int b = 0; b < levelSize.y; b++)
            {
                if (a == 0 || a == levelSize.x - 1 || b == 0 || b == levelSize.y - 1)
                {
                    if (map[a, b] >= 1000)
                    {
                        removeExcessHall(new Vector2(a, b));
                    }
                }
            }
        }

        RoomTile[] halls = new RoomTile[0];

        for (int x = 0; x < levelSize.x; x++)
        {
            for (int y = 0; y < levelSize.y; y++)
            {
                if (map[x, y] >= 1000)
                {
                    RoomTile[] curHalls = new RoomTile[halls.Length + 1];

                    for (var h = 0; h < halls.Length; h++)
                    {
                        curHalls[h] = halls[h];
                    }

                    curHalls[curHalls.Length - 1] = new RoomTile(new Vector2(x, y), 1000);
                    halls = curHalls;
                }
            }
        }



        // add secret rooms here
        for (int i = 0; i < eventRooms; i++)
        {
            createSecretRoom(halls);
        }

        for (int x = 0; x < levelSize.x; x++)
        {
            for (int y = 0; y < levelSize.y; y++)
            {
                if (map[x, y] != 0)
                {
                    GameObject plane = createFloor();
                    if (map[x, y] == 4)                      // Start Level
                    {
                        Destroy(plane);
                        plane = Instantiate(startPlane, transform.position, transform.rotation) as GameObject;
                    }
                    else if (map[x, y] == 5)                       // Exit Level
                    {
                        Destroy(plane);
                        plane = Instantiate(exitPlane, transform.position, transform.rotation) as GameObject;
                    }
                    Vector3 pos = new Vector3(x * 5, 0, y * 5);
                    plane.transform.position = pos;
                    plane.layer                = 8;
                    plane.name                 = "ground";
                    plane.transform.parent     = GameObject.Find("LevelGenerator").transform;
                    plane.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
                    plane.name                 = "x" + x + "y" + y + "t" + map[x, y];

                    GameObject ceiling = createCeiling();
                    pos = new Vector3(x * 5, 5, y * 5);
                    ceiling.transform.position = pos;
                    Quaternion rotation = Quaternion.Euler(0, 0, 180);
                    ceiling.transform.rotation   = rotation;
                    ceiling.transform.parent     = GameObject.Find("LevelGenerator").transform;
                    ceiling.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
                    placeWallsAround(new Vector2(x, y));


                    if (map[x, y] >= 40 && map[x, y] <= 99)
                    {
                        plane.renderer.material.mainTexture = eventFloorTexture[0];
                        spawnPickup(plane.transform.position, map[x, y]);
                    }
                }
//				else {
//					GameObject cube = Instantiate(walls[0], transform.position, transform.rotation) as GameObject;
//					Vector3 pos = new Vector3(x*10, 0, y*10);
//					Quaternion rotation = Quaternion.Euler(90, 0, 0);
//					cube.transform.position = pos;
//					cube.layer = 9;
//
//					cube.transform.localScale = new Vector3(10, 10, 10);
//					cube.transform.parent = GameObject.Find("LevelGenerator").transform;
//				}
            }
        }
        spawnEnemies();
        if (GameObject.FindGameObjectWithTag("Evil"))
        {
            GameObject.FindGameObjectWithTag("Evil").GetComponent <Evil>().ignoreEnemyCollisions();
        }
        AstarPath.active.astarData.gridGraph.width  = (int)levelSize.x * 5;
        AstarPath.active.astarData.gridGraph.depth  = (int)levelSize.y * 5;
        AstarPath.active.astarData.gridGraph.center = new Vector3(AstarPath.active.astarData.gridGraph.width / 2, -0.1f, AstarPath.active.astarData.gridGraph.depth / 2);

        AstarPath.active.astarData.gridGraph.UpdateSizeFromWidthDepth();
        AstarPath.active.Scan();
    }
Exemple #32
0
        public static void GenerateRoomComponentsTemplate(Room room, ComponentManager componentManager, Microsoft.Xna.Framework.Content.ContentManager content, GraphicsDevice graphics)
        {
            RoomTile[,] currentTiles = RoomTemplate.CreateFromRoom(room, room.Chunks);
            float[,] rotations       = new float[currentTiles.GetLength(0), currentTiles.GetLength(1)];
            foreach (RoomTemplate template in room.RoomData.Templates)
            {
                for (int r = -2; r < currentTiles.GetLength(0) + 1; r++)
                {
                    for (int c = -2; c < currentTiles.GetLength(1) + 1; c++)
                    {
                        for (int rotation = 0; rotation < 5; rotation++)
                        {
                            if (MathFunctions.RandEvent(template.Probability))
                            {
                                template.PlaceTemplate(ref currentTiles, ref rotations, r, c);
                                template.RotateClockwise(1);
                            }
                        }
                    }
                }
            }

            BoundingBox box = room.GetBoundingBox();

            int thingsMade = 0;

            for (int r = 0; r < currentTiles.GetLength(0); r++)
            {
                for (int c = 0; c < currentTiles.GetLength(1); c++)
                {
                    RoomTile tile             = currentTiles[r, c];
                    Body     createdComponent = null;
                    Vector3  noise            =
                        VertexNoise.GetNoiseVectorFromRepeatingTexture(box.Min +
                                                                       new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1));
                    switch (tile)
                    {
                    case RoomTile.Wheat:
                        createdComponent = EntityFactory.CreateEntity <Body>("Wheat", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Mushroom:
                        createdComponent = EntityFactory.CreateEntity <Body>("Mushroom", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Table:
                        createdComponent = EntityFactory.CreateEntity <Body>("Table", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Lamp:
                        createdComponent = EntityFactory.CreateEntity <Body>("Lamp", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Flag:
                        createdComponent = EntityFactory.CreateEntity <Body>("Flag", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Chair:
                        createdComponent = EntityFactory.CreateEntity <Body>("Chair", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.BookTable:
                        createdComponent = EntityFactory.CreateEntity <Body>(MathFunctions.RandEvent(0.5f) ? "BookTable" : "PotionTable", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Anvil:
                        createdComponent = EntityFactory.CreateEntity <Body>("Anvil", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Forge:
                        createdComponent = EntityFactory.CreateEntity <Body>("Forge", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Target:
                        createdComponent = EntityFactory.CreateEntity <Body>("Target", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Strawman:
                        createdComponent = EntityFactory.CreateEntity <Body>("Strawman", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.BookShelf:
                        createdComponent = EntityFactory.CreateEntity <Body>("Bookshelf", box.Min + new Vector3(r - 1 + 0.5f, 1.5f, c - 1 + 0.5f) + noise);
                        thingsMade++;
                        break;

                    case RoomTile.Pillow:

                        for (int dx = -1; dx < 2; dx++)
                        {
                            for (int dy = -1; dy < 2; dy++)
                            {
                                if (Math.Abs(dx) + Math.Abs(dy) != 1 || r + dx < 0 || r + dx >= currentTiles.GetLength(0) || c + dy < 0 || c + dy >= currentTiles.GetLength(1))
                                {
                                    continue;
                                }

                                if (currentTiles[r + dx, c + dy] != RoomTile.Bed)
                                {
                                    continue;
                                }

                                createdComponent = EntityFactory.CreateEntity <Body>("Bed", box.Min + new Vector3(r - 1 + 0.5f, 1.5f, c - 1 + 0.5f) + noise);

                                /*
                                 * float angle = (float) Math.Atan2(dx, dy);
                                 *
                                 * Vector3 translation = createdComponent.LocalTransform.Translation;
                                 * Matrix bedRotation = Matrix.CreateRotationY(angle);
                                 * createdComponent.LocalTransform = Matrix.CreateTranslation(new Vector3(-0.5f, 0, -0.5f)) * bedRotation * Matrix.CreateTranslation(new Vector3(0.5f, 0, 0.5f)) * Matrix.CreateTranslation(translation);
                                 * createdComponent.BoundingBoxPos = Vector3.Transform(createdComponent.BoundingBoxPos, bedRotation);
                                 * createdComponent.BoundingBox.Min = Vector3.Transform(createdComponent.BoundingBox.Min - translation, bedRotation) + translation;
                                 * createdComponent.BoundingBox.Max = Vector3.Transform(createdComponent.BoundingBox.Max - translation, bedRotation) + translation;
                                 */
                                break;
                            }
                        }


                        thingsMade++;
                        break;

                    default:
                        break;
                    }

                    if (createdComponent != null)
                    {
                        createdComponent.LocalTransform = Matrix.CreateRotationY(-(rotations[r, c] + (float)Math.PI * 0.5f)) * createdComponent.LocalTransform;
                        Vector3 endPos          = createdComponent.LocalTransform.Translation;
                        Matrix  offsetTransform = createdComponent.LocalTransform;
                        offsetTransform.Translation    += new Vector3(0, -1, 0);
                        createdComponent.LocalTransform = offsetTransform;
                        createdComponent.AnimationQueue.Add(new EaseMotion(0.8f, offsetTransform, endPos));
                        room.AddBody(createdComponent);
                        PlayState.ParticleManager.Trigger("puff", endPos + new Vector3(0.5f, 0.5f, 0.5f), Color.White, 10);
                    }
                }
            }
        }
    override public void OnInspectorGUI()
    {
        RoomTile tile = target as RoomTile;

        if (AssetDatabase.Contains(tile.gameObject))
        {
            DrawDefaultInspector();
        }
        else
        {
            Object[] objects   = Selection.objects;
            Object[] selection = new Object[objects.Length];
            Object[] prefabs   = Resources.LoadAll("Tile");
            RoomTile prefab;

            string[] strList        = new string[prefabs.Length];
            string   selectionName  = null;
            int      selectionIndex = 0;
            int      j;
            int      i;

            for (i = 0; i < prefabs.Length; i++)
            {
                prefab     = (prefabs[i] as GameObject).GetComponent <RoomTile>();
                strList[i] = prefab.referenceName;
                for (j = 0; j < objects.Length; j++)
                {
                    tile = (objects[j] as GameObject).GetComponent <RoomTile>();
                    if (tile.referenceName == prefab.referenceName)
                    {
                        if (selectionName == null)
                        {
                            selectionName  = tile.referenceName;
                            selectionIndex = i;
                        }
                        else if (selectionName != tile.referenceName)
                        {
                            selectionIndex = -1;
                        }
                    }
                }
            }

            int selected = EditorGUILayout.Popup("Tile:", selectionIndex, strList);
            if (selectionIndex != selected)
            {
                GameObject newTile;
                GameObject obj;

                for (i = 0; i < objects.Length; i++)
                {
                    newTile = PrefabUtility.InstantiatePrefab(prefabs[selected] as GameObject) as GameObject;
                    obj     = objects[i] as GameObject;
                    Undo.RegisterCreatedObjectUndo(newTile, "Created replacement tile");

                    newTile.transform.position   = obj.transform.position;
                    newTile.transform.rotation   = obj.transform.rotation;
                    newTile.transform.localScale = obj.transform.localScale;
                    newTile.transform.parent     = obj.transform.parent;
                    newTile.transform.SetSiblingIndex(obj.transform.GetSiblingIndex());

                    obj.transform.parent.transform.parent.GetComponent <RoomUnit>().ReplaceTile(newTile.GetComponent <RoomTile>(), obj.GetComponent <RoomTile>().index);

                    Undo.DestroyObjectImmediate(obj);
                    selection[i] = newTile;
                }

                Selection.objects = selection;
            }
        }
    }
Exemple #34
0
        public void OnCycle(RoomItem item)
        {
            Room room = item.Room;

            if (room.RollerTick == 0)
            {
                RoomTile oldTile = room.Mapping.Tiles[item.Position.X, item.Position.Y];
                RoomTile newTile = room.Mapping.GetTileInFront(oldTile, item.Position.Rotation);

                if (newTile == null || newTile.State == RoomTileState.CLOSED || newTile.Entities.Count > 0)
                {
                    return;
                }

                List <RoomEntity> habbosOnRoller = oldTile.Entities;
                List <RoomItem>   itemsOnRoller  = oldTile.Items;
                List <RoomItem>   itemsNewTile   = newTile.Items;
                RoomItem          newRoller      = null;
                RoomItem          topItem        = newTile.TopItem;

                bool allowUsers          = true;
                bool allowFurniture      = true;
                bool stackContainsRoller = false;
                foreach (RoomItem rItem in itemsNewTile)
                {
                    if (!(rItem.ItemData.CanWalk || rItem.ItemData.CanSit))
                    {
                        allowUsers = false;
                    }
                    if (rItem.ItemData.Interaction == ItemInteraction.ROLLER)
                    {
                        newRoller           = item;
                        stackContainsRoller = true;

                        if (itemsNewTile.Count > 1 && item != topItem)
                        {
                            allowUsers     = false;
                            allowFurniture = false;
                            continue;
                        }

                        break;
                    }
                    else
                    {
                        allowFurniture = false;
                    }
                }

                double zOffset = 0;
                if (newRoller == null)
                {
                    zOffset = -item.ItemData.Height;
                }

                if (allowFurniture || (!allowFurniture && !stackContainsRoller))
                {
                    foreach (RoomItem rItem in itemsOnRoller)
                    {
                        if (rItem != item)
                        {
                            room.RollerMessages.Add(new FloorItemOnRollerComposer(rItem, item, oldTile, newTile, zOffset));
                        }
                    }
                }

                if (allowUsers)
                {
                    foreach (RoomEntity user in habbosOnRoller)
                    {
                        if (stackContainsRoller && !allowFurniture && !(topItem != null && topItem.ItemData.CanWalk))
                        {
                            continue;
                        }

                        if (!user.Actions.Has("mv"))
                        {
                            if (user.Actions.Has("sit"))
                            {
                                user.Actions.Remove("sit");
                            }
                            if (user.Actions.Has("lay"))
                            {
                                user.Actions.Remove("lay");
                            }

                            room.RollerMessages.Add(new RoomUserOnRollerComposer(user, item, oldTile, newTile, zOffset));
                        }
                    }
                }
            }
        }
Exemple #35
0
        public int PlaceTemplate(ref RoomTile[,] room, ref float[,] rotations, int seedR, int seedC)
        {
            int nr = room.GetLength(0);
            int nc = room.GetLength(1);
            int tr = Template.GetLength(0);
            int tc = Template.GetLength(1);

            for (int r = 0; r < tr; r++)
            {
                for (int c = 0; c < tc; c++)
                {
                    int x = seedR + r;
                    int y = seedC + c;

                    RoomTile desired = Template[r, c];


                    // Ignore tiles with unspecified conditions
                    if (desired == RoomTile.None)
                    {
                        continue;
                    }

                    bool hasWall     = Has(desired, RoomTile.Wall);
                    bool hasOpen     = Has(desired, RoomTile.Open);
                    bool hasEdge     = Has(desired, RoomTile.Edge);
                    bool onEdge      = (x >= nr - 1 || y >= nc - 1 || x < 1 || y < 1);
                    bool outOfBounds = onEdge && (x >= nr || y >= nc || x < 0 || y < 0);
                    if (onEdge && !hasEdge)
                    {
                        return(-1);
                    }
                    else if (outOfBounds && desired != RoomTile.None)
                    {
                        return(-1);
                    }
                    else if (outOfBounds)
                    {
                        continue;
                    }

                    RoomTile curent = room[x, y];

                    bool meetsWallRequirements = !hasWall || (curent == RoomTile.Wall);
                    bool meetsEdgeRequirements = (!hasEdge && !hasWall) || (hasEdge && curent == RoomTile.Edge);
                    bool meetsOpenRequriments  = !hasOpen || (curent == RoomTile.Open);
                    bool doesntIntersect       = hasEdge || hasWall || curent == RoomTile.Open;

                    // Tiles conflict when walls exist in the BuildRoom already, or other objects
                    // block the template.
                    if (!(((meetsWallRequirements || meetsEdgeRequirements) && meetsOpenRequriments && doesntIntersect)))
                    {
                        return(-1);
                    }
                }
            }

            int toReturn = 0;

            // Otherwise, we return the number of tiles which could be successfully placed.
            for (int r = 0; r < tr; r++)
            {
                for (int c = 0; c < tc; c++)
                {
                    int x = seedR + r;
                    int y = seedC + c;

                    if (x >= nr - 1 || y >= nc - 1 || x <= 0 || y <= 0)
                    {
                        continue;
                    }

                    RoomTile desiredTile = Template[r, c];
                    RoomTile unimport    = Accessories[r, c];
                    RoomTile currentTile = room[x, y];

                    if ((currentTile == RoomTile.Open || currentTile == RoomTile.Edge) && desiredTile != RoomTile.None && !Has(desiredTile, RoomTile.Edge) && !Has(desiredTile, RoomTile.Wall) && desiredTile != RoomTile.Open)
                    {
                        room[x, y]      = desiredTile;
                        rotations[x, y] = Rotation;
                        toReturn++;
                    }

                    if ((currentTile != RoomTile.Open && currentTile != RoomTile.Edge) || unimport == RoomTile.Open || unimport == RoomTile.None || unimport == RoomTile.Edge)
                    {
                        continue;
                    }

                    room[x, y] = unimport;
                    toReturn++;
                }
            }

            return(toReturn);
        }