public static Packet TrockTransferResult(ItemConstants.TrockResult result, ItemConstants.TrockType type) { Packet trockTransferResultPacket = new Packet(ServerOperationCode.MapTransferResult); trockTransferResultPacket .WriteByte((byte)result) .WriteByte((byte)type); return(trockTransferResultPacket); }
public static Packet TrockInventoryUpdate(ItemConstants.TrockMapAction action, ItemConstants.TrockType type) { Packet trockInventoryUpdatePacket = new Packet(ServerOperationCode.MapTransferResult); trockInventoryUpdatePacket .WriteByte((byte)action) .WriteByte((byte)type) .WriteBytes(type == ItemConstants.TrockType.Regular ? CharacterTrocks.RegularTrockToByteArray() : CharacterTrocks.VIPTrockToByteArray()); return(trockInventoryUpdatePacket); }
public bool Use(int itemID, Packet iPacket) { bool used = false; byte action = iPacket.ReadByte(); ItemConstants.TrockType type = itemID == 5040000 ? ItemConstants.TrockType.Regular : ItemConstants.TrockType.VIP; int destinationMapID = -1; ItemConstants.TrockResult result = ItemConstants.TrockResult.Success; if (action == 0) // NOTE: Preset map. { int mapID = iPacket.ReadInt(); if (!this.Parent.Trocks.Contains(mapID)) { result = ItemConstants.TrockResult.CannotGo; } destinationMapID = mapID; } else if (action == 1) // NOTE: IGN. { string targetName = iPacket.ReadString(); Character target = null;// this.Parent.Client.Channel.Characters.GetCharacter(targetName); if (target == null) { result = ItemConstants.TrockResult.DifficultToLocate; } else { destinationMapID = target.Map.MapleID; } } iPacket.ReadInt(); // NOTE: Ticks. if (destinationMapID != -1) { Map originMap = this.Parent.Map; Map destinationMap = DataProvider.Maps[destinationMapID]; if (false) // TODO: Field limit check. { result = ItemConstants.TrockResult.CannotGo; } else if (false) // TODO: Origin map field limit check. { result = ItemConstants.TrockResult.CannotGo; } else if (originMap.MapleID == destinationMap.MapleID) { result = ItemConstants.TrockResult.AlreadyThere; } else if (false) // TODO: Continent check. { result = ItemConstants.TrockResult.CannotGo; } } if (result == ItemConstants.TrockResult.Success) { this.Parent.SendChangeMapRequest(destinationMapID); used = true; } else { using (Packet oPacket = new Packet(ServerOperationCode.MapTransferResult)) { oPacket .WriteByte((byte)result) .WriteByte((byte)type); this.Parent.Client.Send(oPacket); } } return(used); }
public void Update(Packet iPacket) { ItemConstants.TrockAction action = (ItemConstants.TrockAction)iPacket.ReadByte(); ItemConstants.TrockType type = (ItemConstants.TrockType)iPacket.ReadByte(); switch (action) { case ItemConstants.TrockAction.Remove: { int mapID = iPacket.ReadInt(); if (type == ItemConstants.TrockType.Regular) { if (!this.Regular.Contains(mapID)) { return; } this.Regular.Remove(mapID); } else if (type == ItemConstants.TrockType.VIP) { if (!this.VIP.Contains(mapID)) { return; } this.VIP.Remove(mapID); } } break; case ItemConstants.TrockAction.Add: { int mapID = this.Parent.Map.MapleID; // TODO: Check if the map field limits allow trocks (e.g. Maple Island is forbidden). if (true) { if (type == ItemConstants.TrockType.Regular) { this.Regular.Add(mapID); } else if (type == ItemConstants.TrockType.VIP) { this.VIP.Add(mapID); } } else { return; } } break; } using (Packet oPacket = new Packet(ServerOperationCode.MapTransferResult)) { oPacket .WriteByte((byte)(action == ItemConstants.TrockAction.Remove ? 2 : 3)) .WriteByte((byte)type) .WriteBytes(type == ItemConstants.TrockType.Regular ? this.RegularToByteArray() : this.VIPToByteArray()); this.Parent.Client.Send(oPacket); } }
public bool UseTrockHandler(int trockID, Packet inPacket) { bool used = false; byte action = inPacket.ReadByte(); ItemConstants.TrockType type = ItemConstants.TrockType.Regular; switch (trockID) { case (int)ItemConstants.UsableCashItems.TeleportRock: type = ItemConstants.TrockType.Regular; break; case (int)ItemConstants.UsableCashItems.VIPTeleportRock: type = ItemConstants.TrockType.VIP; break; default: throw new ArgumentOutOfRangeException(); } int destinationMapID = -1; ItemConstants.TrockResult result = ItemConstants.TrockResult.Success; if (action == (int)ItemConstants.TrockUseAction.TeleportToPresetMap) { int mapID = inPacket.ReadInt(); if (!Contains(mapID)) { result = ItemConstants.TrockResult.CannotGo; } destinationMapID = mapID; } else if (action == (int)ItemConstants.TrockUseAction.TeleportToIGN) { string targetName = inPacket.ReadString(); Character target = TrockParent.GetCharacterByName(targetName); if (target == null) { result = ItemConstants.TrockResult.DifficultToLocate; } else { destinationMapID = target.Map.MapleID; } } int ticks = inPacket.ReadInt(); if (destinationMapID != -1) { Map originMap = TrockParent.Map; Map destinationMap = DataProvider.Maps[destinationMapID]; if (destinationMap.FieldLimit == (int)MapConstants.FieldLimit.CannotUseVIPTrock) { result = ItemConstants.TrockResult.CannotGo; } else if (originMap.FieldLimit == (int)MapConstants.FieldLimit.CannotUseVIPTrock) { result = ItemConstants.TrockResult.CannotGo; } else if (originMap.MapleID == destinationMap.MapleID) { result = ItemConstants.TrockResult.AlreadyThere; } /*else if (false) // TODO: Continent check. * { * result = ItemConstants.TrockResult.CannotGo; * }*/ } if (result == ItemConstants.TrockResult.Success) { TrockParent.SendChangeMapRequest(destinationMapID); used = true; } else { TrockParent.Client.Send(CharacterTrocksPackets.TrockTransferResult(result, type)); } return(used); }
public void UpdateTrockHandler(Packet inPacket) { ItemConstants.TrockMapAction action = (ItemConstants.TrockMapAction)inPacket.ReadByte(); ItemConstants.TrockType type = (ItemConstants.TrockType)inPacket.ReadByte(); switch (action) { case ItemConstants.TrockMapAction.RemoveMapTrock: { int mapID = inPacket.ReadInt(); switch (type) { case ItemConstants.TrockType.Regular: if (!RegularTrocks.Contains(mapID)) { return; } VIPTrocks.Remove(mapID); break; case ItemConstants.TrockType.VIP: if (!VIPTrocks.Contains(mapID)) { return; } VIPTrocks.Remove(mapID); break; default: throw new ArgumentOutOfRangeException(); } } break; case ItemConstants.TrockMapAction.AddMapTrock: { int mapID = TrockParent.Map.MapleID; if (TrockParent.Map.FieldLimit != (int)MapConstants.FieldLimit.CannotUseVIPTrock) { switch (type) { case ItemConstants.TrockType.Regular: if (RegularTrocks.Contains(mapID)) { return; } RegularTrocks.Add(mapID); break; case ItemConstants.TrockType.VIP: if (VIPTrocks.Contains(mapID)) { return; } VIPTrocks.Add(mapID); break; default: throw new ArgumentOutOfRangeException(); } } else { Character.Notify(TrockParent, "[TrockHandler] This map cannot be added to teleport rock!"); } } break; default: throw new ArgumentOutOfRangeException(); } TrockParent.Client.Send(CharacterTrocksPackets.TrockInventoryUpdate(action, type)); }