public override void HandleMessageContents(NetworkMessage message, Connection connection) { var useOnPacket = new ItemUseOnPacket(message); var player = Game.Instance.GetCreatureWithId(connection.PlayerId) as Player; if (player == null) { return; } player.ClearPendingActions(); // Before actually using the item, check if we're close enough to use it. if (useOnPacket.FromLocation.Type == LocationType.Ground) { var locationDiff = useOnPacket.FromLocation - player.Location; if (locationDiff.Z != 0) // it's on a different floor... { ResponsePackets.Add(new TextMessagePacket { Type = MessageType.StatusSmall, Message = "There is no way." }); return; } if (locationDiff.MaxValueIn2D > 1) { // Too far away to use it. Location retryLoc; var directions = Game.Instance.Pathfind(player.Location, useOnPacket.FromLocation, out retryLoc).ToArray(); player.SetPendingAction(new UseItemOnPlayerAction(player, useOnPacket, retryLoc)); if (directions.Length > 0) { player.AutoWalk(directions); } else // we found no way... { ResponsePackets.Add(new TextMessagePacket { Type = MessageType.StatusSmall, Message = "There is no way." }); } return; } } new UseItemOnPlayerAction(player, useOnPacket, useOnPacket.FromLocation).Perform(); }
public static ItemUseOnPacket Parse(NetworkMessage message) { ItemUseOnPacket packet = new ItemUseOnPacket(); packet.FromLocation = message.GetLocation(); packet.FromSpriteId = message.GetUInt16(); packet.FromStackPosition = message.GetByte(); packet.ToLocation = message.GetLocation(); packet.ToSpriteId = message.GetUInt16(); packet.ToStackPosition = message.GetByte(); return(packet); }
public UseItemOnPlayerAction(IPlayer player, ItemUseOnPacket useOnPacket, Location retryLocation) : base(player, useOnPacket, retryLocation) { }
public void ParseItemUseOn(NetworkMessage message) { ItemUseOnPacket packet = ItemUseOnPacket.Parse(message); Game.ItemUseOn(Player, packet.FromSpriteId, packet.FromLocation, packet.FromStackPosition, packet.ToSpriteId, packet.ToLocation, packet.ToStackPosition); }