예제 #1
0
        private bool setFloorDescription(NetworkMessage incMsg, NetworkMessage outMsg, int x, int y, int z, int width, int height, int offset)
        {
            for (int nx = 0; nx < width; nx++)
            {
                for (int ny = 0; ny < height; ny++)
                {
                    if (skipTiles == 0)
                    {
                        ushort tileOpt = incMsg.PeekUInt16();
                        //Decide if we have to skip tiles
                        // or if it is a real tile
                        if (tileOpt >= 0xFF00)
                        {
                            ushort skip = incMsg.GetUInt16();
                            outMsg.AddUInt16(skip);
                            skipTiles = (ushort)(skip & 0xFF);
                        }
                        else
                        {
                            //real tile so read tile
                            Position pos = new Position((uint)(x + nx + offset), (uint)(y + ny + offset), (uint)z);
                            if (!setTileDescription(incMsg, outMsg, pos))
                            {
                                Logger.Log("Falha ao setar a descrição do tile. Posição: " + pos.ToString(), LogType.ERROR);
                                return false;
                            }

                            //read skip tiles info
                            ushort skip = incMsg.GetUInt16();
                            outMsg.AddUInt16(skip);
                            skipTiles = (ushort)(skip & 0xFF);
                        }
                    }
                    //skipping tiles...
                    else
                    {
                        skipTiles--;
                    }
                }
            }
            return true;
        }
예제 #2
0
        private bool setTileDescription(NetworkMessage incMsg, NetworkMessage outMsg, Position pos)
        {
            //set the tile in the map
            Tile tile = Map.GetInstance().SetTile(pos);

            if (tile == null)
                return false;

            //and clear it
            tile.Clear();

            int n = 0;
            while (true)
            {
                //avoid infinite loop
                n++;

                ushort inspectTileId = incMsg.PeekUInt16();

                if (inspectTileId >= 0xFF00)
                {
                    //end of the tile
                    //Notifications::onTileUpdate(pos);
                    return true;
                }
                else
                {
                    if (n > 10)
                    {
                        Logger.Log("Muitos objetos no tile. Posição: " + pos.ToString(), LogType.ERROR);
                        return false;
                    }

                    //read tile things: items and creatures
                    Thing thing = internalGetThing(incMsg, outMsg);

                    if (thing == null)
                    {
                        Logger.Log("Falha ao obter o objeto. Posição: " + pos.ToString(), LogType.ERROR);
                        return false;
                    }

                    //and add to the tile
                    if (!tile.AddThing(thing))
                    {
                        Logger.Log("Falha ao adicionar um objeto. Posição: " + pos.ToString(), LogType.ERROR);
                        return false;
                    }
                }
            }
        }
예제 #3
0
        private bool parseUpdateTile(NetworkMessage incMsg, NetworkMessage outMsg)
        {
            Position tilePos = incMsg.GetPosition();
            outMsg.AddPosition(tilePos);

            ushort thingId = incMsg.PeekUInt16();

            if (thingId == 0xFF01)
            {
                outMsg.AddUInt16(incMsg.GetUInt16());

                Tile tile = Map.GetInstance().GetTile(tilePos);

                if (tile == null)
                    Logger.Log("Erro ao atualizar o tile. Posição: " + tilePos.ToString(), LogType.ERROR);

                tile.Clear();
            }
            else
            {
                if (!setTileDescription(incMsg, outMsg, tilePos))
                    Logger.Log("Erro ao atualizar o tile. Posição: " + tilePos.ToString(), LogType.ERROR);

                outMsg.AddUInt16(incMsg.GetUInt16());
            }

            return true;
        }