private void OnRemoveThing(Packet props) { MapPosition Position = (MapPosition)props["Position"]; int StackIndex = (int)props["StackIndex"]; Map[Position].Remove(StackIndex); }
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); }
private void OnAddThing(Packet props) { MapPosition Position = (MapPosition)props["Position"]; ClientThing Thing = (ClientThing)props["Thing"]; Boolean Push = (Boolean)props["Push"]; Map[Position].Add(Thing, Push); }
public override bool Equals(object obj) { if (obj is MapPosition) { MapPosition o = (MapPosition)obj; return(X == o.X && Y == o.Y && Z == o.Z); } return(false); }
public void Move(MapPosition FromPosition, MapPosition ToPosition) { if (ToPosition.X < FromPosition.X) Direction = Direction.West; else if (ToPosition.X > FromPosition.X) Direction = Direction.East; else if (ToPosition.Y < FromPosition.Y) Direction = Direction.North; else if (ToPosition.Y > FromPosition.Y) Direction = Direction.South; }
private void OnMagicEffect(Packet props) { MapPosition Position = (MapPosition)props["Position"]; MagicEffect Effect = new MagicEffect(Viewport.GameData, (int)props["Effect"]); TileAnimations Animations = null; if (!PlayingAnimations.TryGetValue(Position, out Animations)) { Animations = new TileAnimations(); PlayingAnimations.Add(Position, Animations); } Animations.Effects.Add(Effect); }
public ClientTile this[MapPosition Position] { get { ClientTile Tile = null; if (Tiles.TryGetValue(Position, out Tile)) return Tile; return null; } set { Tiles[value.Position] = value; } }
private void OnMapDescription(Packet props) { ViewPosition = (MapPosition)props["Center"]; List <ClientTile> tiles = (List <ClientTile>)props["Tiles"]; Map.Clear(ViewPosition); foreach (ClientTile Tile in tiles) { if (Tile != null) { ProbeTileForCreatures(Tile); Map[Tile.Position] = Tile; } } }
private void OnAnimatedText(Packet props) { MapPosition Position = (MapPosition)props["Position"]; String Text = (String)props["Text"]; int Color = (int)props["Color"]; TileAnimations Animations = null; if (!PlayingAnimations.TryGetValue(Position, out Animations)) { Animations = new TileAnimations(); PlayingAnimations.Add(Position, Animations); } Animations.Effects.Add(new AnimatedText(Text, Color)); }
private void OnTransformThing(Packet props) { MapPosition Position = (MapPosition)props["Position"]; int StackIndex = (int)props["StackIndex"]; ClientThing Thing = (ClientThing)props["Thing"]; if (props.Has("Direction")) { if (Thing is ClientCreature) { ((ClientCreature)Thing).Direction = (Direction)props["Direction"]; } } Map[Position].Replace(StackIndex, Thing); }
public ClientTile this [MapPosition Position] { get { ClientTile Tile = null; if (Tiles.TryGetValue(Position, out Tile)) { return(Tile); } return(null); } set { Tiles[value.Position] = value; } }
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); } }
public void Move(MapPosition FromPosition, MapPosition ToPosition) { if (ToPosition.X < FromPosition.X) { Direction = Direction.West; } else if (ToPosition.X > FromPosition.X) { Direction = Direction.East; } else if (ToPosition.Y < FromPosition.Y) { Direction = Direction.North; } else if (ToPosition.Y > FromPosition.Y) { Direction = Direction.South; } }
/// <summary> /// Removes all tiles outside the viewport. /// </summary> /// <param name="Center">Center of the Viewport</param> public void Clear(MapPosition Center) { List<MapPosition> ToRemove = new List<MapPosition>(); foreach (MapPosition Position in Tiles.Keys) { int ZAdjustment = Center.Z - Position.Z; if (Position.X < Center.X - 9 + ZAdjustment || Position.X > Center.X + 9 + ZAdjustment || Position.Y < Center.Y - 7 + ZAdjustment || Position.Y > Center.Y + 7 + ZAdjustment) { ToRemove.Add(Position); } } foreach (MapPosition Position in ToRemove) Tiles.Remove(Position); }
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); } } }
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); }
private void OnShootEffect(Packet props) { MapPosition FromPosition = (MapPosition)props["From"]; MapPosition ToPosition = (MapPosition)props["To"]; int Type = (int)props["Effect"]; MapPosition Max = new MapPosition(); Max.X = Math.Max(FromPosition.X, ToPosition.X); Max.Y = Math.Max(FromPosition.Y, ToPosition.Y); Max.Z = ToPosition.Z; TileAnimations Animations = null; if (!PlayingAnimations.TryGetValue(Max, out Animations)) { Animations = new TileAnimations(); PlayingAnimations.Add(Max, Animations); } Animations.Effects.Add(new DistanceEffect(Viewport.GameData, Type, FromPosition, ToPosition)); }
/// <summary> /// Removes all tiles outside the viewport. /// </summary> /// <param name="Center">Center of the Viewport</param> public void Clear(MapPosition Center) { List <MapPosition> ToRemove = new List <MapPosition>(); foreach (MapPosition Position in Tiles.Keys) { int ZAdjustment = Center.Z - Position.Z; if (Position.X < Center.X - 9 + ZAdjustment || Position.X > Center.X + 9 + ZAdjustment || Position.Y < Center.Y - 7 + ZAdjustment || Position.Y > Center.Y + 7 + ZAdjustment) { ToRemove.Add(Position); } } foreach (MapPosition Position in ToRemove) { Tiles.Remove(Position); } }
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); }
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; }
public DistanceEffect(TibiaGameData GameData, int ID, MapPosition From, MapPosition To) { this.ID = ID; Sprite = GameData.GetDistanceEffectSprite(ID); int dx = To.X - From.X; int dy = To.Y - From.Y; /* * 0 = NW * 1 = N * 2 = NE * 3 = W * 4 = C * 5 = E * 6 = SW * 7 = S * 8 = SE * */ double tan = 10; if (dx != 0) { tan = (float)dy / (float)dx; } if (Math.Abs(tan) < 0.4142f) { if (dx > 0) { Frame = 5; // EAST } else { Frame = 3;// WEST } } else if (Math.Abs(tan) < 2.4142f) { if (tan > 0) { if (dy > 0) { Frame = 8;// SOUTH EAST } else { Frame = 0;// NORTH WEST; } } else { //tan < 0 if (dx > 0) { Frame = 2;// NORTH EAST; } else { Frame = 6;// SOUTH WEST } } } else { if (dy > 0) { Frame = 7;// SOUTH } else { Frame = 1;// NORTH } } Duration = Math.Sqrt(dx * dx + dy * dy) / 10; Offset = new Vector2( (From.X - Math.Max(From.X, To.X)) * 32, (From.Y - Math.Max(From.Y, To.Y)) * 32 ); Speed = new Vector2(Math.Sign(dx) * 160, Math.Sign(dy) * 160); //Speed -= Offset; }
/// <summary> /// Internal use only, fetches the correct handler for a given handler name. One packet name may map to multiple handler names. /// </summary> /// <param name="parserName">The packet handler to fetch</param> /// <returns></returns> private GamePacketParser GetPacketParser(String parserName) { if (parserName == "ErrorMessage") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Message"] = nmsg.ReadString(); return props; } } ; else if (parserName == "MOTD") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Message"] = nmsg.ReadString(); return props; } } ; else if (parserName == "Ping") { return delegate(NetworkMessage nmsg) { return new Packet(parserName); } } ; else if (parserName == "PlayerLogin") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); Player = new ClientPlayer(nmsg.ReadU32()); props["DrawSpeed"] = nmsg.ReadU16(); props["CanReportBugs"] = nmsg.ReadByte() != 0; props["Player"] = Player; KnownCreatures[Player.ID] = Player; return props; } } ; else if (parserName == "MapDescription") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); CurrentPosition = ReadMapPosition(nmsg); props["Center"] = CurrentPosition; props["Tiles"] = ReadMapDescription(nmsg, CurrentPosition.X - 8, CurrentPosition.Y - 6, CurrentPosition.Z, 18, 14); return props; } } ; else if (parserName == "UpdateInventory") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Slot"] = (int)nmsg.ReadByte(); props["Thing"] = ReadThing(nmsg); return props; } } ; else if (parserName == "ClearInventory") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Slot"] = (int)nmsg.ReadByte(); return props; } } ; else if (parserName == "OpenContainer") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); int ContainerID = (int)nmsg.ReadByte(); props["ContainerID"] = ContainerID; int ClientID = nmsg.ReadU16(); ItemType it = GameData.GetItemType(ClientID); if (it == null) { Log.Warning("OpenContainer contains unrecognized item type (" + ClientID.ToString() + ").", this); it = ItemType.NullType; } props["Thing"] = new ClientContainer(it, ContainerID); props["Name"] = nmsg.ReadString(); props["Volume"] = (int)nmsg.ReadByte(); props["IsChild"] = nmsg.ReadByte() != 0; int ItemCount = nmsg.ReadByte(); props["ItemCount"] = (int)ItemCount; List <ClientItem> contents = new List <ClientItem>(); for (int i = 0; i < ItemCount; ++i) { contents.Add((ClientItem)ReadThing(nmsg)); } props["Contents"] = contents; return props; } } ; else if (parserName == "CloseContainer") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["ContainerID"] = (int)nmsg.ReadByte(); return props; } } ; else if (parserName == "ContainerAddItem") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["ContainerID"] = (int)nmsg.ReadByte(); props["Item"] = ReadItem(nmsg); return props; } } ; else if (parserName == "ContainerTransformItem") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["ContainerID"] = (int)nmsg.ReadByte(); props["Slot"] = (int)nmsg.ReadByte(); props["Item"] = ReadItem(nmsg); return props; } } ; else if (parserName == "ContainerRemoveItem") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["ContainerID"] = (int)nmsg.ReadByte(); props["Slot"] = (int)nmsg.ReadByte(); return props; } } ; else if (parserName == "UpdateStats") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Health"] = (int)nmsg.ReadU16(); props["MaxHealth"] = (int)nmsg.ReadU16(); props["Capacity"] = (int)nmsg.ReadU16(); props["Experience"] = (int)nmsg.ReadU32(); props["Level"] = (int)nmsg.ReadByte(); props["LevelPercent"] = (int)nmsg.ReadByte(); props["Mana"] = (int)nmsg.ReadU16(); props["MaxMana"] = (int)nmsg.ReadU16(); props["MagicLevel"] = (int)nmsg.ReadByte(); props["MagicLevelPercent"] = (int)nmsg.ReadByte(); // TODO: Stamina for some versions //int soul = nmsg.ReadByte(); //int staminaMinutes = nmsg.ReadU16(); return props; } } ; else if (parserName == "UpdateSkills") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Fist"] = (int)nmsg.ReadByte(); props["FistPercent"] = (int)nmsg.ReadByte(); props["Club"] = (int)nmsg.ReadByte(); props["ClubPercent"] = (int)nmsg.ReadByte(); props["Sword"] = (int)nmsg.ReadByte(); props["SwordPercent"] = (int)nmsg.ReadByte(); props["Axe"] = (int)nmsg.ReadByte(); props["AxePercent"] = (int)nmsg.ReadByte(); props["Dist"] = (int)nmsg.ReadByte(); props["DistPercent"] = (int)nmsg.ReadByte(); props["Shield"] = (int)nmsg.ReadByte(); props["ShieldPercent"] = (int)nmsg.ReadByte(); props["Fish"] = (int)nmsg.ReadByte(); props["FishPercent"] = (int)nmsg.ReadByte(); return props; } } ; else if (parserName == "PlayerIcons") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["ConditionState"] = (ConditionState)nmsg.ReadByte(); return props; } } ; else if (parserName == "CancelAttack") { return delegate(NetworkMessage nmsg) { return new Packet(parserName); } } ; else if (parserName == "CancelWalk") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Direction"] = (Direction)nmsg.ReadByte(); return props; } } ; else if (parserName == "Death") { return delegate(NetworkMessage nmsg) { return new Packet(parserName); } } ; else if (parserName == "CanReport") { return delegate(NetworkMessage nmsg) { return new Packet(parserName); } } ; else if (parserName == "MoveNorth") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); CurrentPosition.Y--; props["Center"] = CurrentPosition; props["Tiles"] = ReadMapDescription(nmsg, CurrentPosition.X - 8, CurrentPosition.Y - 6, CurrentPosition.Z, 18, 1); return props; } } ; else if (parserName == "MoveSouth") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); CurrentPosition.Y++; props["Center"] = CurrentPosition; props["Tiles"] = ReadMapDescription(nmsg, CurrentPosition.X - 8, CurrentPosition.Y + 7, CurrentPosition.Z, 18, 1); return props; } } ; else if (parserName == "MoveWest") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); CurrentPosition.X--; props["Center"] = CurrentPosition; props["Tiles"] = ReadMapDescription(nmsg, CurrentPosition.X - 8, CurrentPosition.Y - 6, CurrentPosition.Z, 1, 14); return props; } } ; else if (parserName == "MoveEast") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); CurrentPosition.X++; props["Center"] = CurrentPosition; props["Tiles"] = ReadMapDescription(nmsg, CurrentPosition.X + 9, CurrentPosition.Y - 6, CurrentPosition.Z, 1, 14); return props; } } ; else if (parserName == "FloorUp") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); List <ClientTile> Tiles = new List <ClientTile>(); int skipTiles = 0; CurrentPosition.Z--; if (CurrentPosition.Z == 7) { for (int i = 5; i >= 0; i--) { Tiles.AddRange(ReadFloorDescription(nmsg, ref skipTiles, CurrentPosition.X - 8, CurrentPosition.Y - 6, i, 18, 14, 8 - i)); } } else if (CurrentPosition.Z > 7) { Tiles.AddRange(ReadFloorDescription(nmsg, ref skipTiles, CurrentPosition.X - 8, CurrentPosition.Y - 6, CurrentPosition.Z - 2, 18, 14, 3)); } CurrentPosition.X++; CurrentPosition.Y++; props["Tiles"] = Tiles; props["Center"] = CurrentPosition; return props; } } ; else if (parserName == "FloorDown") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); List <ClientTile> Tiles = new List <ClientTile>(); int skipTiles = 0; CurrentPosition.Z++; if (CurrentPosition.Z == 8) { int j = -1; for (int i = CurrentPosition.Z; i < CurrentPosition.Z + 3; ++i, --j) { Tiles.AddRange(ReadFloorDescription(nmsg, ref skipTiles, CurrentPosition.X - 8, CurrentPosition.Y - 6, i, 18, 14, j)); } } else if (CurrentPosition.Z > 8 && CurrentPosition.Z < 14) { Tiles.AddRange(ReadFloorDescription(nmsg, ref skipTiles, CurrentPosition.X - 8, CurrentPosition.Y - 6, CurrentPosition.Z + 2, 18, 14, -3)); } CurrentPosition.X--; CurrentPosition.Y--; props["Tiles"] = Tiles; props["Center"] = CurrentPosition; return props; } } ; else if (parserName == "RefreshTile") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); MapPosition pos = ReadMapPosition(nmsg); props["Position"] = pos; props["Clear"] = false; if (nmsg.PeekU16() == 0xFF01) { nmsg.ReadU16(); props["Clear"] = true; return props; } else { props["NewTile"] = ReadTileDescription(nmsg, pos); // Skip extra bytes after data (it signifies the end of data) nmsg.ReadU16(); return props; } } } ; else if (parserName == "AddThing") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Position"] = ReadMapPosition(nmsg); props["Thing"] = ReadThing(nmsg); props["Push"] = true; // TODO: >= 8.53, push thing should be false return props; } } ; else if (parserName == "TransformThing") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Position"] = ReadMapPosition(nmsg); props["StackIndex"] = (int)nmsg.ReadByte(); if (nmsg.PeekU16() == 0x63) { nmsg.Skip(2); // CreatureTurn2 props["Thing"] = KnownCreatures[nmsg.ReadU32()]; props["Direction"] = (Direction)nmsg.ReadByte(); } else { props["Thing"] = ReadThing(nmsg); } return props; } } ; else if (parserName == "RemoveThing") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Position"] = ReadMapPosition(nmsg); props["StackIndex"] = (int)nmsg.ReadByte(); return props; } } ; else if (parserName == "CreatureMove") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["OldPosition"] = ReadMapPosition(nmsg); props["OldStackIndex"] = (int)nmsg.ReadByte(); props["Position"] = ReadMapPosition(nmsg); if ((int)props["OldStackIndex"] > 9) { Log.Warning("CreatureMove - Old stack pos out of range.", this); } props["Push"] = true; // TODO: >= 8.53, pushThing = false return props; } } ; else if (parserName == "WorldLight") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Level"] = (int)nmsg.ReadByte(); props["Color"] = (int)nmsg.ReadByte(); return props; } } ; else if (parserName == "Effect") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Position"] = ReadMapPosition(nmsg); props["Effect"] = 1 + (int)nmsg.ReadByte(); return props; } } ; else if (parserName == "AnimatedText") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Position"] = ReadMapPosition(nmsg); props["Color"] = (int)nmsg.ReadByte(); props["Text"] = nmsg.ReadString(); return props; } } ; else if (parserName == "ShootEffect") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["From"] = ReadMapPosition(nmsg); props["To"] = ReadMapPosition(nmsg); props["Effect"] = (int)nmsg.ReadByte(); return props; } } ; else if (parserName == "SquareEffect") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Creature"] = KnownCreatures[nmsg.ReadU32()]; props["Color"] = nmsg.ReadByte(); return props; } } ; else if (parserName == "CreatureHealth") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Creature"] = KnownCreatures[nmsg.ReadU32()]; props["Health"] = (int)nmsg.ReadByte(); return props; } } ; else if (parserName == "CreatureLight") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Creature"] = KnownCreatures[nmsg.ReadU32()]; props["Level"] = (int)nmsg.ReadByte(); props["Color"] = (int)nmsg.ReadByte(); return props; } } ; else if (parserName == "CreatureRefresh") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Creature"] = KnownCreatures[nmsg.ReadU32()]; return props; } } ; else if (parserName == "CreatureTurn") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Creature"] = KnownCreatures[nmsg.ReadU32()]; props["Direction"] = (Direction)nmsg.ReadByte(); return props; } } ; else if (parserName == "CreatureSpeed") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Creature"] = KnownCreatures[nmsg.ReadU32()]; props["Speed"] = (int)nmsg.ReadU16(); return props; } } ; else if (parserName == "CreatureSkull") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Creature"] = KnownCreatures[nmsg.ReadU32()]; props["Skull"] = (CreatureSkull)nmsg.ReadByte(); return props; } } ; else if (parserName == "CreatureShield") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Creature"] = KnownCreatures[nmsg.ReadU32()]; props["PartyShield"] = (PartyShield)nmsg.ReadByte(); return props; } } ; else if (parserName == "CreatureSpeak") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); ClientMessage Message = new ClientMessage(); //props["Creature"] = KnownCreatures[nmsg.ReadU32()]; Message.Speaker = nmsg.ReadString(); //props["Level"] = nmsg.ReadU16(); Message.Type = (MessageType)nmsg.ReadByte(); switch (Message.Type) { case MessageType.Say: case MessageType.Whisper: case MessageType.Yell: case MessageType.MonsterSay: case MessageType.MonsterYell: case MessageType.PrivateNPCToPlayer: case MessageType.PrivatePlayerToNPC: { props["Position"] = ReadMapPosition(nmsg); Message.Text = nmsg.ReadString(); break; } case MessageType.ChannelAnonymousRed: case MessageType.ChannelOrange: case MessageType.ChannelRed: case MessageType.ChannelYellow: { props["ChannelID"] = nmsg.ReadU16(); Message.Text = nmsg.ReadString(); break; } case MessageType.Private: case MessageType.Broadcast: case MessageType.PrivateRed: { Message.Text = nmsg.ReadString(); break; } case MessageType.ReportRuleViolation: { Message.Time = Common.UnixTime(nmsg.ReadU32()); // time Message.Text = nmsg.ReadString(); break; } case MessageType.RuleViolationGameMaster: case MessageType.RuleViolationPlayer: { Message.Text = nmsg.ReadString(); break; } default: Log.Warning("Unknown speak class " + (int)props["MessageType"], this); return null; } props["Message"] = Message; return props; } } ; else if (parserName == "ChannelList") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); int count = nmsg.ReadByte(); props["ChannelCount"] = count; while (count > 0) { int channelID = nmsg.ReadU16(); string channelName = nmsg.ReadString(); --count; } return null; } } ; else if (parserName == "OpenChannel") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["ChannelID"] = nmsg.ReadU16(); props["ChannelName"] = nmsg.ReadString(); return props; } } ; else if (parserName == "OpenPrivateChat") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["PlayerName"] = nmsg.ReadString(); return props; } } ; else if (parserName == "TextMessage") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); MessageType Type = (MessageType)nmsg.ReadByte(); String Text = nmsg.ReadString(); props["Message"] = new ClientMessage(Type, DateTime.Now, Text); return props; } } ; else if (parserName == "VIPState") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["CreatureID"] = nmsg.ReadU32(); props["Name"] = nmsg.ReadString(); props["Online"] = nmsg.ReadByte() != 0; return props; } } ; else if (parserName == "VIPLogin") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["CreatureID"] = nmsg.ReadU32(); return props; } } ; else if (parserName == "VIPLogout") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["CreatureID"] = nmsg.ReadU32(); return props; } } ; else if (parserName == "RuleViolationChannel") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); return props; } } ; else if (parserName == "RuleViolationRemove") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); return props; } } ; else if (parserName == "RuleViolationCancel") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); return props; } } ; else if (parserName == "RuleViolationLock") { return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); return props; } } ; throw new System.ArgumentException("Unknown packet handler."); }
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; }
public ClientTile(MapPosition Position) { this.Position = Position; }
/// <summary> /// Internal use only, fetches the correct handler for a given handler name. One packet name may map to multiple handler names. /// </summary> /// <param name="parserName">The packet handler to fetch</param> /// <returns></returns> private GamePacketParser GetPacketParser(String parserName) { if (parserName == "ErrorMessage") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Message"] = nmsg.ReadString(); return props; }; else if (parserName == "MOTD") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Message"] = nmsg.ReadString(); return props; }; else if (parserName == "Ping") return delegate(NetworkMessage nmsg) { return new Packet(parserName); }; else if (parserName == "PlayerLogin") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); Player = new ClientPlayer(nmsg.ReadU32()); props["DrawSpeed"] = nmsg.ReadU16(); props["CanReportBugs"] = nmsg.ReadByte() != 0; props["Player"] = Player; KnownCreatures[Player.ID] = Player; return props; }; else if (parserName == "MapDescription") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); CurrentPosition = ReadMapPosition(nmsg); props["Center"] = CurrentPosition; props["Tiles"] = ReadMapDescription(nmsg, CurrentPosition.X - 8, CurrentPosition.Y - 6, CurrentPosition.Z, 18, 14); return props; }; else if (parserName == "UpdateInventory") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Slot"] = (int)nmsg.ReadByte(); props["Thing"] = ReadThing(nmsg); return props; }; else if (parserName == "ClearInventory") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Slot"] = (int)nmsg.ReadByte(); return props; }; else if (parserName == "OpenContainer") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); int ContainerID = (int)nmsg.ReadByte(); props["ContainerID"] = ContainerID; int ClientID = nmsg.ReadU16(); ItemType it = GameData.GetItemType(ClientID); if (it == null) { Log.Warning("OpenContainer contains unrecognized item type (" + ClientID.ToString() + ").", this); it = ItemType.NullType; } props["Thing"] = new ClientContainer(it, ContainerID); props["Name"] = nmsg.ReadString(); props["Volume"] = (int)nmsg.ReadByte(); props["IsChild"] = nmsg.ReadByte() != 0; int ItemCount = nmsg.ReadByte(); props["ItemCount"] = (int)ItemCount; List<ClientItem> contents = new List<ClientItem>(); for (int i = 0; i < ItemCount; ++i) contents.Add((ClientItem)ReadThing(nmsg)); props["Contents"] = contents; return props; }; else if (parserName == "CloseContainer") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["ContainerID"] = (int)nmsg.ReadByte(); return props; }; else if (parserName == "ContainerAddItem") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["ContainerID"] = (int)nmsg.ReadByte(); props["Item"] = ReadItem(nmsg); return props; }; else if (parserName == "ContainerTransformItem") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["ContainerID"] = (int)nmsg.ReadByte(); props["Slot"] = (int)nmsg.ReadByte(); props["Item"] = ReadItem(nmsg); return props; }; else if (parserName == "ContainerRemoveItem") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["ContainerID"] = (int)nmsg.ReadByte(); props["Slot"] = (int)nmsg.ReadByte(); return props; }; else if (parserName == "UpdateStats") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Health"] = (int)nmsg.ReadU16(); props["MaxHealth"] = (int)nmsg.ReadU16(); props["Capacity"] = (int)nmsg.ReadU16(); props["Experience"] = (int)nmsg.ReadU32(); props["Level"] = (int)nmsg.ReadByte(); props["LevelPercent"] = (int)nmsg.ReadByte(); props["Mana"] = (int)nmsg.ReadU16(); props["MaxMana"] = (int)nmsg.ReadU16(); props["MagicLevel"] = (int)nmsg.ReadByte(); props["MagicLevelPercent"] = (int)nmsg.ReadByte(); // TODO: Stamina for some versions //int soul = nmsg.ReadByte(); //int staminaMinutes = nmsg.ReadU16(); return props; }; else if (parserName == "UpdateSkills") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Fist"] = (int)nmsg.ReadByte(); props["FistPercent"] = (int)nmsg.ReadByte(); props["Club"] = (int)nmsg.ReadByte(); props["ClubPercent"] = (int)nmsg.ReadByte(); props["Sword"] = (int)nmsg.ReadByte(); props["SwordPercent"] = (int)nmsg.ReadByte(); props["Axe"] = (int)nmsg.ReadByte(); props["AxePercent"] = (int)nmsg.ReadByte(); props["Dist"] = (int)nmsg.ReadByte(); props["DistPercent"] = (int)nmsg.ReadByte(); props["Shield"] = (int)nmsg.ReadByte(); props["ShieldPercent"] = (int)nmsg.ReadByte(); props["Fish"] = (int)nmsg.ReadByte(); props["FishPercent"] = (int)nmsg.ReadByte(); return props; }; else if (parserName == "PlayerIcons") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["ConditionState"] = (ConditionState)nmsg.ReadByte(); return props; }; else if (parserName == "CancelAttack") return delegate(NetworkMessage nmsg) { return new Packet(parserName); }; else if (parserName == "CancelWalk") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Direction"] = (Direction)nmsg.ReadByte(); return props; }; else if (parserName == "Death") return delegate(NetworkMessage nmsg) { return new Packet(parserName); }; else if (parserName == "CanReport") return delegate(NetworkMessage nmsg) { return new Packet(parserName); }; else if (parserName == "MoveNorth") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); CurrentPosition.Y--; props["Center"] = CurrentPosition; props["Tiles"] = ReadMapDescription(nmsg, CurrentPosition.X - 8, CurrentPosition.Y - 6, CurrentPosition.Z, 18, 1); return props; }; else if (parserName == "MoveSouth") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); CurrentPosition.Y++; props["Center"] = CurrentPosition; props["Tiles"] = ReadMapDescription(nmsg, CurrentPosition.X - 8, CurrentPosition.Y + 7, CurrentPosition.Z, 18, 1); return props; }; else if (parserName == "MoveWest") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); CurrentPosition.X--; props["Center"] = CurrentPosition; props["Tiles"] = ReadMapDescription(nmsg, CurrentPosition.X - 8, CurrentPosition.Y - 6, CurrentPosition.Z, 1, 14); return props; }; else if (parserName == "MoveEast") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); CurrentPosition.X++; props["Center"] = CurrentPosition; props["Tiles"] = ReadMapDescription(nmsg, CurrentPosition.X + 9, CurrentPosition.Y - 6, CurrentPosition.Z, 1, 14); return props; }; else if (parserName == "FloorUp") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); List<ClientTile> Tiles = new List<ClientTile>(); int skipTiles = 0; CurrentPosition.Z--; if (CurrentPosition.Z == 7) { for (int i = 5; i >= 0; i--) { Tiles.AddRange(ReadFloorDescription(nmsg, ref skipTiles, CurrentPosition.X - 8, CurrentPosition.Y - 6, i, 18, 14, 8 - i)); } } else if (CurrentPosition.Z > 7) { Tiles.AddRange(ReadFloorDescription(nmsg, ref skipTiles, CurrentPosition.X - 8, CurrentPosition.Y - 6, CurrentPosition.Z - 2, 18, 14, 3)); } CurrentPosition.X++; CurrentPosition.Y++; props["Tiles"] = Tiles; props["Center"] = CurrentPosition; return props; }; else if (parserName == "FloorDown") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); List<ClientTile> Tiles = new List<ClientTile>(); int skipTiles = 0; CurrentPosition.Z++; if (CurrentPosition.Z == 8) { int j = -1; for (int i = CurrentPosition.Z; i < CurrentPosition.Z + 3; ++i, --j) { Tiles.AddRange(ReadFloorDescription(nmsg, ref skipTiles, CurrentPosition.X - 8, CurrentPosition.Y - 6, i, 18, 14, j)); } } else if (CurrentPosition.Z > 8 && CurrentPosition.Z < 14) { Tiles.AddRange(ReadFloorDescription(nmsg, ref skipTiles, CurrentPosition.X - 8, CurrentPosition.Y - 6, CurrentPosition.Z + 2, 18, 14, -3)); } CurrentPosition.X--; CurrentPosition.Y--; props["Tiles"] = Tiles; props["Center"] = CurrentPosition; return props; }; else if (parserName == "RefreshTile") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); MapPosition pos = ReadMapPosition(nmsg); props["Position"] = pos; props["Clear"] = false; if (nmsg.PeekU16() == 0xFF01) { nmsg.ReadU16(); props["Clear"] = true; return props; } else { props["NewTile"] = ReadTileDescription(nmsg, pos); // Skip extra bytes after data (it signifies the end of data) nmsg.ReadU16(); return props; } }; else if (parserName == "AddThing") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Position"] = ReadMapPosition(nmsg); props["Thing"] = ReadThing(nmsg); props["Push"] = true; // TODO: >= 8.53, push thing should be false return props; }; else if (parserName == "TransformThing") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Position"] = ReadMapPosition(nmsg); props["StackIndex"] = (int)nmsg.ReadByte(); if (nmsg.PeekU16() == 0x63) { nmsg.Skip(2); // CreatureTurn2 props["Thing"] = KnownCreatures[nmsg.ReadU32()]; props["Direction"] = (Direction)nmsg.ReadByte(); } else { props["Thing"] = ReadThing(nmsg); } return props; }; else if (parserName == "RemoveThing") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Position"] = ReadMapPosition(nmsg); props["StackIndex"] = (int)nmsg.ReadByte(); return props; }; else if (parserName == "CreatureMove") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["OldPosition"] = ReadMapPosition(nmsg); props["OldStackIndex"] = (int)nmsg.ReadByte(); props["Position"] = ReadMapPosition(nmsg); if ((int)props["OldStackIndex"] > 9) Log.Warning("CreatureMove - Old stack pos out of range.", this); props["Push"] = true; // TODO: >= 8.53, pushThing = false return props; }; else if (parserName == "WorldLight") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Level"] = (int)nmsg.ReadByte(); props["Color"] = (int)nmsg.ReadByte(); return props; }; else if (parserName == "Effect") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Position"] = ReadMapPosition(nmsg); props["Effect"] = 1 + (int)nmsg.ReadByte(); return props; }; else if (parserName == "AnimatedText") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Position"] = ReadMapPosition(nmsg); props["Color"] = (int)nmsg.ReadByte(); props["Text"] = nmsg.ReadString(); return props; }; else if (parserName == "ShootEffect") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["From"] = ReadMapPosition(nmsg); props["To"] = ReadMapPosition(nmsg); props["Effect"] = (int)nmsg.ReadByte(); return props; }; else if (parserName == "SquareEffect") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Creature"] = KnownCreatures[nmsg.ReadU32()]; props["Color"] = nmsg.ReadByte(); return props; }; else if (parserName == "CreatureHealth") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Creature"] = KnownCreatures[nmsg.ReadU32()]; props["Health"] = (int)nmsg.ReadByte(); return props; }; else if (parserName == "CreatureLight") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Creature"] = KnownCreatures[nmsg.ReadU32()]; props["Level"] = (int)nmsg.ReadByte(); props["Color"] = (int)nmsg.ReadByte(); return props; }; else if (parserName == "CreatureRefresh") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Creature"] = KnownCreatures[nmsg.ReadU32()]; return props; }; else if (parserName == "CreatureTurn") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Creature"] = KnownCreatures[nmsg.ReadU32()]; props["Direction"] = (Direction)nmsg.ReadByte(); return props; }; else if (parserName == "CreatureSpeed") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Creature"] = KnownCreatures[nmsg.ReadU32()]; props["Speed"] = (int)nmsg.ReadU16(); return props; }; else if (parserName == "CreatureSkull") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Creature"] = KnownCreatures[nmsg.ReadU32()]; props["Skull"] = (CreatureSkull)nmsg.ReadByte(); return props; }; else if (parserName == "CreatureShield") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["Creature"] = KnownCreatures[nmsg.ReadU32()]; props["PartyShield"] = (PartyShield)nmsg.ReadByte(); return props; }; else if (parserName == "CreatureSpeak") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); ClientMessage Message = new ClientMessage(); //props["Creature"] = KnownCreatures[nmsg.ReadU32()]; Message.Speaker = nmsg.ReadString(); //props["Level"] = nmsg.ReadU16(); Message.Type = (MessageType)nmsg.ReadByte(); switch (Message.Type) { case MessageType.Say: case MessageType.Whisper: case MessageType.Yell: case MessageType.MonsterSay: case MessageType.MonsterYell: case MessageType.PrivateNPCToPlayer: case MessageType.PrivatePlayerToNPC: { props["Position"] = ReadMapPosition(nmsg); Message.Text = nmsg.ReadString(); break; } case MessageType.ChannelAnonymousRed: case MessageType.ChannelOrange: case MessageType.ChannelRed: case MessageType.ChannelYellow: { props["ChannelID"] = nmsg.ReadU16(); Message.Text = nmsg.ReadString(); break; } case MessageType.Private: case MessageType.Broadcast: case MessageType.PrivateRed: { Message.Text = nmsg.ReadString(); break; } case MessageType.ReportRuleViolation: { Message.Time = Common.UnixTime(nmsg.ReadU32()); // time Message.Text = nmsg.ReadString(); break; } case MessageType.RuleViolationGameMaster: case MessageType.RuleViolationPlayer: { Message.Text = nmsg.ReadString(); break; } default: Log.Warning("Unknown speak class " + (int)props["MessageType"], this); return null; } props["Message"] = Message; return props; }; else if (parserName == "ChannelList") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); int count = nmsg.ReadByte(); props["ChannelCount"] = count; while (count > 0) { int channelID = nmsg.ReadU16(); string channelName = nmsg.ReadString(); --count; } return null; }; else if (parserName == "OpenChannel") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["ChannelID"] = nmsg.ReadU16(); props["ChannelName"] = nmsg.ReadString(); return props; }; else if (parserName == "OpenPrivateChat") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["PlayerName"] = nmsg.ReadString(); return props; }; else if (parserName == "TextMessage") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); MessageType Type = (MessageType)nmsg.ReadByte(); String Text = nmsg.ReadString(); props["Message"] = new ClientMessage(Type, DateTime.Now, Text); return props; }; else if (parserName == "VIPState") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["CreatureID"] = nmsg.ReadU32(); props["Name"] = nmsg.ReadString(); props["Online"] = nmsg.ReadByte() != 0; return props; }; else if (parserName == "VIPLogin") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["CreatureID"] = nmsg.ReadU32(); return props; }; else if (parserName == "VIPLogout") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); props["CreatureID"] = nmsg.ReadU32(); return props; }; else if (parserName == "RuleViolationChannel") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); return props; }; else if (parserName == "RuleViolationRemove") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); return props; }; else if (parserName == "RuleViolationCancel") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); return props; }; else if (parserName == "RuleViolationLock") return delegate(NetworkMessage nmsg) { Packet props = new Packet(parserName); return props; }; throw new System.ArgumentException("Unknown packet handler."); }
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; } }
public DistanceEffect(TibiaGameData GameData, int ID, MapPosition From, MapPosition To) { this.ID = ID; Sprite = GameData.GetDistanceEffectSprite(ID); int dx = To.X - From.X; int dy = To.Y - From.Y; /* * 0 = NW * 1 = N * 2 = NE * 3 = W * 4 = C * 5 = E * 6 = SW * 7 = S * 8 = SE * */ double tan = 10; if (dx != 0) tan = (float)dy / (float)dx; if(Math.Abs(tan) < 0.4142f) { if(dx > 0) Frame = 5;// EAST else Frame = 3;// WEST } else if(Math.Abs(tan) < 2.4142f) { if(tan > 0) { if(dy > 0) Frame = 8;// SOUTH EAST else Frame = 0;// NORTH WEST; } else { //tan < 0 if(dx > 0) Frame = 2;// NORTH EAST; else Frame = 6;// SOUTH WEST } } else { if(dy > 0) Frame = 7;// SOUTH else Frame = 1;// NORTH } Duration = Math.Sqrt(dx * dx + dy * dy) / 10; Offset = new Vector2( (From.X - Math.Max(From.X, To.X)) * 32, (From.Y - Math.Max(From.Y, To.Y)) * 32 ); Speed = new Vector2(Math.Sign(dx) * 160, Math.Sign(dy) * 160); //Speed -= Offset; }
private void OnMapDescription(Packet props) { ViewPosition = (MapPosition)props["Center"]; List<ClientTile> tiles = (List<ClientTile>)props["Tiles"]; Map.Clear(ViewPosition); foreach (ClientTile Tile in tiles) { if (Tile != null) { ProbeTileForCreatures(Tile); Map[Tile.Position] = Tile; } } }