示例#1
0
            public Tile this[int x, int y]
            {
                get
                {
                    Point chunkPos = new Point(
                        (int)Math.Floor((float)x / ChunkSize),
                        (int)Math.Floor((float)y / ChunkSize)
                    );
                    Chunk chunk;
                    if (mm.chunks.TryGetValue(chunkPos, out chunk))
                        return chunk.Tiles[(y - chunkPos.Y * ChunkSize) * ChunkSize + (x - chunkPos.X * ChunkSize)];
                    else
                        return default(Tile); // SPAAAAAAAAAAAAAACE!!!
                }
                set
                {
                    Point chunkPos = new Point(
                        (int)Math.Floor((float)x / ChunkSize),
                        (int)Math.Floor((float)y / ChunkSize)
                    );
                    Chunk chunk;
                    if (!mm.chunks.TryGetValue(chunkPos, out chunk))
                    {
                        if (value.IsSpace)
                            return;
                        else
                            mm.chunks[chunkPos] = chunk = new Chunk();
                    }

                    int index = (y - chunkPos.Y * ChunkSize) * ChunkSize + (x - chunkPos.X * ChunkSize);
                    Tile oldTile = chunk.Tiles[index];
                    if (oldTile == value)
                        return;

                    chunk.Tiles[index] = value;
                    var tileRef = new TileRef(mm, x, y, chunk, index);

                    if (mm.TileChanged != null)
                        mm.TileChanged(tileRef, oldTile);

                    if (!mm.suppressNetworkUpdatesOnTileChanged)
                        mm.NetworkUpdateTile(tileRef);
                }
            }
示例#2
0
        /*
        private void HandleTurfClick(NetIncomingMessage message)
        {
            // Who clicked and on what tile.
            Atom.Atom clicker = SS13Server.Singleton.playerManager.GetSessionByConnection(message.SenderConnection).attachedAtom;
            short x = message.ReadInt16();
            short y = message.ReadInt16();

            if (Vector2.Distance(clicker.position, new Vector2(x * tileSpacing + (tileSpacing / 2), y * tileSpacing + (tileSpacing / 2))) > 96)
            {
                return; // They were too far away to click us!
            }
            bool Update = false;
            if (IsSaneArrayPosition(x, y))
            {
                Update = tileArray[x, y].ClickedBy(clicker);
                if (Update)
                {
                    if (tileArray[x, y].tileState == TileState.Dead)
                    {
                        Tiles.Atmos.GasCell g = tileArray[x, y].gasCell;
                        Tiles.Tile t = GenerateNewTile(x, y, tileArray[x, y].tileType);
                        tileArray[x, y] = t;
                        tileArray[x, y].gasCell = g;
                    }
                    NetworkUpdateTile(x, y);
                }
            }
        }*/ // TODO HOOK ME BACK UP WITH ENTITY SYSTEM

        public void NetworkUpdateTile(TileRef tile)
        {
            NetOutgoingMessage message = IoCManager.Resolve<ISS14NetServer>().CreateMessage();
            message.Write((byte)NetMessage.MapMessage);
            message.Write((byte)MapMessage.TurfUpdate);

            message.Write((int)tile.X);
            message.Write((int)tile.Y);
            message.Write((uint)tile.Tile);
            IoCManager.Resolve<ISS14NetServer>().SendToAll(message);
        }
 public void AttachToTile(TileRef tilePos)
 {
     var transComp = Owner.GetComponent<TransformComponent>(ComponentFamily.Transform);
     if (transComp != null)
         transComp.Position = new Vector2f(tilePos.X + 0.5f, tilePos.Y + 0.5f);
 }