Exemplo n.º 1
0
        private List <ClientTile> ReadFloorDescription(NetworkMessage nmsg, ref int skipTiles, int startX, int startY, int Z, int width, int height, int offset)
        {
            List <ClientTile> tiles = new List <ClientTile>();

            for (int x = 0; x < width; ++x)
            {
                for (int y = 0; y < height; ++y)
                {
                    if (skipTiles > 0)
                    {
                        skipTiles--;
                    }
                    else
                    {
                        MapPosition pos  = new MapPosition(startX + x + offset, startY + y + offset, Z);
                        ClientTile  Tile = ReadTileDescription(nmsg, pos);
                        skipTiles = nmsg.ReadByte();
                        if (nmsg.ReadByte() != 0xFF)
                        {
                            Log.Warning("Server did not follow Tile skip by 0xFF");
                        }
                        tiles.Add(Tile);
                    }
                }
            }

            return(tiles);
        }
Exemplo n.º 2
0
        private void OnRefreshTile(Packet props)
        {
            ClientTile Tile  = Map[(MapPosition)props["Position"]];
            Boolean    Clear = (Boolean)props["Clear"];

            if (Clear)
            {
                Tile.Objects.Clear();
            }
            else
            {
                Map[Tile.Position] = (ClientTile)props["NewTile"];
            }
        }
Exemplo n.º 3
0
 public ClientTile this [MapPosition Position]
 {
     get
     {
         ClientTile Tile = null;
         if (Tiles.TryGetValue(Position, out Tile))
         {
             return(Tile);
         }
         return(null);
     }
     set
     {
         Tiles[value.Position] = value;
     }
 }
Exemplo n.º 4
0
        public void DrawScene(SpriteBatch Batch, GameTime Time, ClientViewport Viewport, Dictionary <MapPosition, TileAnimations> PlayingAnimations = null)
        {
            MapPosition Center = Viewport.ViewPosition;

            int StartZ = 7;
            int EndZ   = Center.Z;

            if (Center.Z <= 7)
            {
                Center.Y -= (7 - Center.Z);
                Center.X -= (7 - Center.Z);
            }
            else
            {
                StartZ    = Math.Min(Center.Z + 2, 15);
                EndZ      = Center.Z;
                Center.X -= 2;
                Center.Y -= 2;
            }

            Vector2 TopLeft = new Vector2(
                -(Center.X - 7) * 32,
                -(Center.Y - 5) * 32
                );


            for (int Z = StartZ; Z >= EndZ; --Z)
            {
                for (int X = Center.X - 8; X <= Center.X + 9; ++X)
                {
                    for (int Y = Center.Y - 6; Y <= Center.Y + 7; ++Y)
                    {
                        ClientTile Tile = Viewport.Map[new MapPosition(X, Y, Z)];

                        Vector2 pos = new Vector2(32 * X + TopLeft.X, 32 * Y + TopLeft.Y);

                        TileAnimations Animations = null;
                        if (PlayingAnimations != null && Tile != null)
                        {
                            PlayingAnimations.TryGetValue(Tile.Position, out Animations);
                        }
                        DrawTile(Batch, Time, pos, Tile, Animations);
                    }
                }
                TopLeft -= new Vector2(32, 32);
            }
        }
Exemplo n.º 5
0
        public void DrawTile(SpriteBatch Batch, GameTime Time, Vector2 Position, ClientTile Tile, TileAnimations Animations)
        {
            if (Tile == null)
            {
                return;
            }

            // Draw ground
            if (Tile.Ground != null)
            {
                DrawSprite(Batch, Time, Tile, Tile.Ground.Sprite, Tile.Ground.Subtype, -1, ref Position, Color.White);
            }

            foreach (ClientThing Thing in Tile.ObjectsByDrawOrder)
            {
                if (Thing is ClientCreature)
                {
                    DrawCreature(Batch, Time, (ClientCreature)Thing, Position, Color.White);
                }
                else
                {
                    ClientItem Item = (ClientItem)Thing;
                    DrawSprite(Batch, Time, Tile, Item.Sprite, Item.Subtype, -1, ref Position, Color.White);
                }
            }

            if (Animations != null)
            {
                foreach (GameEffect Effect in Animations.Effects)
                {
                    if (!Effect.Expired)
                    {
                        if (Effect is MagicEffect)
                        {
                            MagicEffect Magic = (MagicEffect)Effect;
                            DrawSprite(Batch, Time, Tile, Magic.Sprite, -1, Magic.Frame, Position, Color.White);
                        }
                        else if (Effect is DistanceEffect)
                        {
                            DistanceEffect Distance = (DistanceEffect)Effect;
                            DrawSprite(Batch, Time, Tile, Distance.Sprite, Distance.Frame, 0, Position + Distance.Offset, Color.White);
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        private void ProbeTileForCreatures(ClientTile Tile)
        {
            if (Tile.CreatureCount == 0)
            {
                return;
            }

            foreach (ClientThing Thing in Tile.Objects)
            {
                if (Thing is ClientCreature)
                {
                    ClientCreature Creature = (ClientCreature)Thing;
                    if (!Creatures.ContainsKey(Creature.ID))
                    {
                        Creatures.Add(Creature.ID, Creature);
                    }
                }
            }
        }
Exemplo n.º 7
0
        public void DrawSceneForeground(SpriteBatch Batch, Vector2 ScreenOffset, Vector2 Scale, GameTime Time, ClientViewport Viewport, Dictionary <MapPosition, TileAnimations> PlayingAnimations = null)
        {
            MapPosition Center = Viewport.ViewPosition;


            Vector2 TopLeft = new Vector2(
                -(Center.X - 7) * 32,
                -(Center.Y - 5) * 32
                );

            int StartZ = 7;
            int EndZ   = Center.Z;

            if (Center.Z <= 7)
            {
                Center.Y -= (7 - Center.Z);
                Center.X -= (7 - Center.Z);
            }
            else
            {
                StartZ = Math.Min(Center.Z + 2, 15);
                EndZ   = Center.Z;
            }

            for (int X = Center.X - 8; X <= Center.X + 8; ++X)
            {
                for (int Y = Center.Y - 6; Y <= Center.Y + 6; ++Y)
                {
                    ClientTile Tile = Viewport.Map[new MapPosition(X, Y, Center.Z)];

                    Vector2 DrawOffset = new Vector2(32 * X + TopLeft.X, 32 * Y + TopLeft.Y);
                    DrawOffset *= Scale;

                    TileAnimations Animations = null;
                    if (PlayingAnimations != null && Tile != null)
                    {
                        PlayingAnimations.TryGetValue(Tile.Position, out Animations);
                    }
                    DrawTileForeground(Batch, Time, ScreenOffset + DrawOffset, Tile, Animations);
                }
            }
        }
Exemplo n.º 8
0
        private ClientTile ReadTileDescription(NetworkMessage nmsg, MapPosition pos)
        {
            ClientTile Tile   = new ClientTile(pos);
            int        nStuff = 0;

            while (nStuff < 10)
            {
                if (nmsg.PeekU16() >= 0xFF00)
                {
                    return(Tile);
                }
                else
                {
                    Tile.Add(ReadThing(nmsg));
                }
                ++nStuff;
            }

            return(Tile);
        }
Exemplo n.º 9
0
        private void OnCreatureMove(Packet props)
        {
            MapPosition OldPosition = (MapPosition)props["OldPosition"];
            int         StackIndex  = (int)props["OldStackIndex"];
            MapPosition ToPosition  = (MapPosition)props["Position"];

            ClientTile FromTile = Map[OldPosition];
            ClientTile ToTile   = Map[ToPosition];

            if (FromTile == null || ToTile == null)
            {
                Log.Warning("OnCreatureMove - Tile is missing.");
                return;
            }

            ClientCreature Creature = (ClientCreature)FromTile.GetByIndex(StackIndex);

            FromTile.Remove(Creature);
            ToTile.Add(Creature, true);

            Creature.Move(OldPosition, ToPosition);
        }
Exemplo n.º 10
0
        public void DrawSprite(SpriteBatch Batch, GameTime Time, ClientTile Tile, GameSprite Sprite, int SubType, int Frame, ref Vector2 Position, Color clr)
        {
            if (Sprite == null)
            {
                return;
            }

            int xdiv = 0, ydiv = 0, zdiv = 0;

            if (Tile != null)
            {
                MapPosition mPos = Tile.Position;
                xdiv = mPos.X % Sprite.XDiv;
                ydiv = mPos.Y % Sprite.YDiv;
                zdiv = mPos.Z % Sprite.ZDiv;
            }

            /*
             * if (Sprite.IsHangable)
             * {
             *  if (Tile->hasProperty(ISVERTICAL))
             *  {
             *      xdiv = 2;
             *  }
             *  else if (Tile->hasProperty(ISHORIZONTAL))
             *  {
             *      xdiv = 1;
             *  }
             *  else
             *  {
             *      xdiv = -0;
             *  }
             * }
             * else */if (Sprite.IsStackable)
            {
                if (SubType <= 1)
                {
                    SubType = 0;
                }
                else if (SubType <= 2)
                {
                    SubType = 1;
                }
                else if (SubType <= 3)
                {
                    SubType = 2;
                }
                else if (SubType <= 4)
                {
                    SubType = 3;
                }
                else if (SubType < 10)
                {
                    SubType = 4;
                }
                else if (SubType < 25)
                {
                    SubType = 5;
                }
                else if (SubType < 50)
                {
                    SubType = 6;
                }
                else
                {
                    SubType = 7;
                }
            }

            Vector2 Offset = Position;

            Offset.X += Sprite.RenderOffset;
            Offset.Y += Sprite.RenderOffset;

            if (Frame == -1)
            {
                Frame = (int)(Time.TotalGameTime.TotalMilliseconds / Sprite.AnimationSpeed);
            }

            for (int cx = 0; cx != Sprite.Width; cx++)
            {
                for (int cy = 0; cy != Sprite.Height; cy++)
                {
                    for (int cf = 0; cf != Sprite.BlendFrames; cf++)
                    {
                        GameImage Image = Sprite.GetImage(
                            cx, cy, cf,
                            SubType,
                            xdiv,
                            ydiv,
                            zdiv,
                            Frame
                            );

                        Rectangle rect = new Rectangle((int)Offset.X - 32 * cx, (int)Offset.Y - 32 * cy, 32, 32);
                        DrawImage(Batch, Image, rect, clr);
                    }
                }
            }

            if (Sprite.RenderHeight > 0)
            {
                Position.X -= Sprite.RenderHeight;
                Position.Y -= Sprite.RenderHeight;
            }
        }
Exemplo n.º 11
0
        public void DrawSprite(SpriteBatch Batch, GameTime Time, ClientTile Tile, GameSprite Sprite, int SubType, int Frame, Vector2 Position, Color clr)
        {
            Vector2 tmp = Position;

            DrawSprite(Batch, Time, Tile, Sprite, SubType, Frame, ref tmp, clr);
        }
Exemplo n.º 12
0
        public void DrawTileForeground(SpriteBatch Batch, GameTime Time, Vector2 Offset, ClientTile Tile, TileAnimations Animations)
        {
            if (Tile == null)
            {
                return;
            }

            foreach (ClientThing Thing in Tile.Objects)
            {
                if (Thing is ClientCreature)
                {
                    DrawCreatureBars(Batch, (ClientCreature)Thing, Offset);
                }
            }

            if (Animations != null)
            {
                foreach (GameEffect Effect in Animations.Effects)
                {
                    if (!Effect.Expired && Effect is AnimatedText)
                    {
                        AnimatedText Text       = (AnimatedText)Effect;
                        Vector2      DrawOffset = Offset + Text.Offset;
                        // DrawOffset.X += 16;
                        // DrawOffset.Y += 26;
                        DrawBoldedText(Batch, Text.Text, DrawOffset, true, MakeColor(Text.Color));
                    }
                }
            }
        }