private async Task OnUserChangeSlotPositionRequest(IPacket packet) { packet.Decode <int>(); var inventoryType = (ItemInventoryType)packet.Decode <byte>(); var fromSlot = packet.Decode <short>(); var toSlot = packet.Decode <short>(); var number = packet.Decode <short>(); if (toSlot == 0) { if (Field.Template.Limit.HasFlag(FieldOpt.DropLimit)) { return; } await ModifyInventory(i => { var item = Character.GetInventory(inventoryType).Items .Single(ii => ii.Position == fromSlot); if (!ItemConstants.IsTreatSingly(item.TemplateID)) { if (!(item is ItemSlotBundle bundle)) { return; } if (bundle.Number < number) { return; } item = i.Take(bundle, number); } else { i.Remove(item); } var drop = new FieldDropItem(item) { Position = Position }; Field.Enter(drop, () => drop.GetEnterFieldPacket(0x1, this)); }, true); return; } await ModifyInventory(i => i.Move(inventoryType, fromSlot, toSlot), true); }
public override async Task Handle(RecvPacketOperations operation, IPacket packet, FieldUser user) { packet.Decode <int>(); var type = (ItemInventoryType)packet.Decode <byte>(); var from = packet.Decode <short>(); var to = packet.Decode <short>(); var number = packet.Decode <short>(); if (to == 0) { await user.ModifyInventory(i => { var item = user.Character.Inventories[type].Items[from]; if (!ItemConstants.IsTreatSingly(item.TemplateID)) { if (!(item is ItemSlotBundle bundle)) { return; } if (bundle.Number < number) { return; } item = i[type].Take(from, number); } else { i[type].Remove(from); } var drop = new ItemFieldDrop(item) { Position = user.Position, DateExpire = DateTime.Now.AddMinutes(3) }; user.Field.Enter(drop, () => drop.GetEnterFieldPacket(0x1, user)); }, true); return; } // TODO: equippable checks await user.ModifyInventory(i => i[type].Move(from, to), true); }
public async Task <TrunkResult> Put(short position, int templateID, short count) { var inventory = User.Character.Inventories[(ItemInventoryType)(templateID / 1000000)]; var item = inventory.Items[position]; if (_trunk.Items.Count >= _trunk.SlotMax) { return(TrunkResult.PutNoSpace); } if (User.Character.Money < _template.TrunkPut) { return(TrunkResult.PutNoMoney); } await User.ModifyStats(s => s.Money -= _template.TrunkPut); await User.ModifyInventory(i => { if (!ItemConstants.IsTreatSingly(item.TemplateID) && item is ItemSlotBundle bundle) { if (bundle.Number < count) { count = bundle.Number; } item = i.Take(bundle, count); } else { i.Remove(item); } }); new ModifyInventoryContext(_trunk).Add(item); return(TrunkResult.PutSuccess); }
private async Task OnTrunkPutItemRequest(FieldUser user, IPacket packet) { var pos = packet.Decode <short>(); var templateID = packet.Decode <int>(); var number = packet.Decode <short>(); var inventory = user.Character.GetInventory((ItemInventoryType)(templateID / 1000000)); var item = inventory.Items.FirstOrDefault(i => i.Position == pos); using (var p = new Packet(SendPacketOperations.TrunkResult)) { var result = TrunkResult.PutSuccess; switch (item) { case null: case ItemSlotBundle bundle when bundle.Number < number: result = TrunkResult.PutUnknown; break; } if (user.Character.Money < _putFee) { result = TrunkResult.GetNoMoney; } if (_trunk.Items.Count >= _trunk.SlotMax) { result = TrunkResult.PutNoSpace; } p.Encode <byte>((byte)result); if (result == TrunkResult.PutSuccess) { await user.ModifyStats(s => s.Money -= _putFee); await user.ModifyInventory(i => { if (!ItemConstants.IsTreatSingly(item.TemplateID)) { if (!(item is ItemSlotBundle bundle)) { return; } if (bundle.Number < number) { return; } item = i.Take(bundle, number); } else { i.Remove(item); } }); _trunk.Items.Add(item); EncodeData(user, p); } await user.SendPacket(p); } }
private async Task OnPutItem(FieldUser user, IPacket packet) { if (Users.Count < 2) { return; } if (_locked) { return; } var pair = Users.FirstOrDefault(kv => kv.Value == user); var inventoryType = (ItemInventoryType)packet.Decode <byte>(); var inventory = user.Character.GetInventory(inventoryType); var fromSlot = packet.Decode <short>(); var number = packet.Decode <short>(); var toSlot = packet.Decode <byte>(); var item = inventory.Items.FirstOrDefault(i => i.Position == fromSlot); if (item == null) { return; } if (toSlot < 1 || toSlot > 9) { return; } if (_item[pair.Key].ContainsKey(toSlot)) { return; } IPacket GetPutItemPacket(byte position, byte slot, ItemSlot itemSlot) { using (var p = new Packet(SendPacketOperations.MiniRoom)) { p.Encode <byte>((byte)MiniRoomAction.TRP_PutItem); p.Encode <byte>(position); p.Encode <byte>(slot); itemSlot.Encode(p); return(p); } } await user.ModifyInventory(async i => { if (!ItemConstants.IsTreatSingly(item.TemplateID)) { if (!(item is ItemSlotBundle bundle)) { return; } if (bundle.Number < number) { return; } item = i.Take(bundle, number); } else { i.Remove(item); } _item[pair.Key][toSlot] = item; await user.SendPacket(GetPutItemPacket(0x0, toSlot, item)); await BroadcastPacket(user, GetPutItemPacket(0x1, toSlot, item)); }, true); }