public bool Use(int itemID, Packet iPacket) { bool used = false; byte action = iPacket.ReadByte(); TrockType type = itemID == 5040000 ? TrockType.Regular : TrockType.VIP; int destinationMapID = -1; TrockResult result = TrockResult.Success; if (action == 0) // NOTE: Preset map. { int mapID = iPacket.ReadInt(); if (!this.Parent.Trocks.Contains(mapID)) { result = 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 = 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 = TrockResult.CannotGo; } else if (false) // TODO: Origin map field limit check. { result = TrockResult.CannotGo; } else if (originMap.MapleID == destinationMap.MapleID) { result = TrockResult.AlreadyThere; } else if (false) // TODO: Continent check. { result = TrockResult.CannotGo; } } if (result == TrockResult.Success) { this.Parent.ChangeMap(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) { TrockAction action = (TrockAction)iPacket.ReadByte(); TrockType type = (TrockType)iPacket.ReadByte(); switch (action) { case TrockAction.Remove: { int mapID = iPacket.ReadInt(); if (type == TrockType.Regular) { if (!this.Regular.Contains(mapID)) { return; } this.Regular.Remove(mapID); } else if (type == TrockType.VIP) { if (!this.VIP.Contains(mapID)) { return; } this.VIP.Remove(mapID); } } break; case 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 == TrockType.Regular) { this.Regular.Add(mapID); } else if (type == TrockType.VIP) { this.VIP.Add(mapID); } } else { return; } } break; } using (Packet oPacket = new Packet(ServerOperationCode.MapTransferResult)) { oPacket .WriteByte((byte)(action == TrockAction.Remove ? 2 : 3)) .WriteByte((byte)type) .WriteBytes(type == TrockType.Regular ? this.RegularToByteArray() : this.VIPToByteArray()); this.Parent.Client.Send(oPacket); } }