public void Add(int templateID, short quantity = 1, ItemVariationType type = ItemVariationType.None) { var template = _fieldUser.Service.TemplateManager .Get <ItemTemplate>(templateID); _fieldUser.ModifyInventory(i => i.Add(template, quantity)).Wait(); _fieldUser.Effect(new QuestEffect(templateID, quantity)).Wait(); }
public static async Task <QuestResult> Act(this QuestTemplate template, QuestState state, FieldUser user) { var act = template.Act[state]; if (!user.Character.HasSlotFor(act.Items .Select(i => { var item = user.Service.TemplateManager.Get <ItemTemplate>(i.TemplateID); var slot = item.ToItemSlot(); if (slot is ItemSlotBundle bundle) { bundle.Number = (short)i.Quantity; } return(slot); }) .ToList())) { return(QuestResult.ActFailedInventory); } if (act.EXP != 0) { await user.ModifyStats(s => s.EXP += act.EXP); await user.Message(new IncEXPMessage { EXP = act.EXP, OnQuest = true }); } if (act.Items.Any()) { await user.ModifyInventory(i => act.Items.ForEach(ii => { if (ii.Quantity > 0) { i.Add( user.Service.TemplateManager.Get <ItemTemplate>(ii.TemplateID), (short)ii.Quantity ); } else { i.Remove(ii.TemplateID, (short)ii.Quantity); } } )); await user.Effect(new QuestEffect(act.Items .Select(i => Tuple.Create(i.TemplateID, i.Quantity)) .ToList())); } return(QuestResult.ActSuccess); }
protected override async Task ExecuteAfter( FieldUser sender, ItemTemplate template, ItemCommandOption option ) { await sender.ModifyInventory(i => i.Add(template, option.Quantity ?? 1)); }
public override async Task Leave(FieldUser user, MiniRoomLeaveType type = MiniRoomLeaveType.Kicked) { var pair = Users.FirstOrDefault(kv => kv.Value == user); var items = _item[pair.Key].Values; var money = _money[pair.Key]; await user.ModifyInventory(i => items.ForEach(i.Add)); await user.ModifyStats(s => s.Money += money); _item.Remove(pair.Key); _money.Remove(pair.Key); await base.Leave(user, type); }
public override async Task Handle( RecvPacketOperations operation, IPacket packet, FieldUser user, StatChangeItemTemplate template, ItemSlot item ) { var stats = template.GetTemporaryStats(); if (stats.Count > 0) { await user.ModifyTemporaryStats(ts => { if (template.Time > 0) { var expire = DateTime.Now.AddSeconds(template.Time); stats.ForEach(t => ts.Set(t.Key, -template.ID, t.Value, expire)); } else { stats.ForEach(t => ts.Set(t.Key, -template.ID, t.Value)); } }); } if (!stats.ContainsKey(TemporaryStatType.Morph)) { var incHP = 0; var incMP = 0; incHP += template.HP; incMP += template.MP; incHP += user.BasicStat.MaxHP * (template.HPr / 100); incMP += user.BasicStat.MaxMP * (template.MPr / 100); if (incHP > 0 || incMP > 0) { await user.ModifyStats(s => { s.HP += incHP; s.MP += incMP; }); } } await user.ModifyInventory(i => i.Remove(item, 1), 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 override async Task Handle( RecvPacketOperations operation, IPacket packet, FieldUser user, PortalScrollItemTemplate template, ItemSlot item ) { var fieldID = template.MoveTo == 999999999 ? user.Field.Template.FieldReturn ?? user.Field.ID : template.MoveTo; var field = user.Service.FieldManager.Get(fieldID); await field.Enter(user, 0); await user.ModifyInventory(i => i.Remove(item, 1), true); }
public override async Task Handle(RecvPacketOperations operation, IPacket packet, FieldUser user) { packet.Decode <int>(); var inventoryType = (ItemInventoryType)packet.Decode <byte>(); var inventoryCopy = user.Character.Inventories[inventoryType].Items .Where(kv => kv.Key > 0) .OrderBy(kv => kv.Value.TemplateID) .ToList(); short position = 1; await user.ModifyInventory(i => { inventoryCopy.ForEach(kv => i.Remove(kv.Value)); inventoryCopy.ForEach(kv => i.Set(position++, kv.Value)); }, true); using var p = new Packet(SendPacketOperations.SortItemResult); p.Encode <bool>(false); p.Encode <byte>((byte)inventoryType); await user.SendPacket(p); }
private async Task OnTrunkGetItemRequest(FieldUser user, IPacket packet) { packet.Decode <byte>(); var pos = packet.Decode <byte>(); var item = _trunk.Items.ToList()[pos]; using (var p = new Packet(SendPacketOperations.TrunkResult)) { var result = TrunkResult.GetSuccess; if (item == null) { result = TrunkResult.GetUnknown; } if (user.Character.Money < _getFee) { result = TrunkResult.GetNoMoney; } if (!user.Character.HasSlotFor(item)) { result = TrunkResult.GetHavingOnlyItem; } p.Encode <byte>((byte)result); if (result == TrunkResult.GetSuccess) { item.ID = 0; item.ItemTrunk = null; _trunk.Items.Remove(item); await user.ModifyStats(s => s.Money -= _getFee); await user.ModifyInventory(i => i.Add(item)); EncodeData(user, p); } await user.SendPacket(p); } }
public override async Task Handle( RecvPacketOperations operation, IPacket packet, FieldUser user, MobSummonItemTemplate template, ItemSlot item) { var random = new Random(); await Task.WhenAll(template.Mobs .Where(m => random.Next(100) <= m.Prob) .Select(m => { var mob = user.Service.TemplateManager.Get <MobTemplate>(m.TemplateID); return(user.Field.Enter(new FieldMob(mob, random.NextDouble() >= 0.5) { Position = user.Position, Foothold = user.Foothold })); })); await user.ModifyInventory(i => i.Remove(item, 1), true); }
private void OnUserShopRequest(FieldUser user, InPacket packet) { var type = packet.Decode <byte>(); switch (type) { case 0: // Buy { var pos = packet.Decode <short>(); var templateID = packet.Decode <int>(); var count = packet.Decode <short>(); var shopItem = _shop.Items .OrderBy(i => i.Position) .ToList()[pos]; using (var p = new OutPacket(GameSendOperations.ShopResult)) { byte result = 0x0; if (shopItem != null) { if (shopItem.TemplateID != templateID) { result = 0x10; } if (shopItem.Quantity > 1) { count = 1; } if (count > shopItem.MaxPerSlot) { count = shopItem.MaxPerSlot; } if (shopItem.Price > 0) { if (user.Character.Money < shopItem.Price * count) { result = 0xA; } } if (shopItem.TokenTemplateID > 0) { if (user.Character.GetItemCount(shopItem.TokenTemplateID) < shopItem.TokenPrice * count) { result = 0xD; } } if (shopItem.Stock == 0) { result = 0x1; } // TODO: level limits var templates = user.Socket.WvsGame.ItemTemplates; var item = templates.Get(shopItem.TemplateID).ToItemSlot(); if (item is ItemSlotBundle bundle) { bundle.Number = (short)(count * shopItem.Quantity); } if (!user.Character.HasSlotFor(item)) { result = 0x3; } if (result == 0x0) { if (shopItem.Price > 0) { user.ModifyStats(s => s.Money -= shopItem.Price * count); } if (shopItem.TokenTemplateID > 0) { user.ModifyInventory(i => i.Remove( shopItem.TokenTemplateID, shopItem.TokenPrice * count )); } if (shopItem.Stock > 0) { shopItem.Stock--; } if (shopItem.ItemPeriod > 0) { item.DateExpire = DateTime.Now.AddMinutes(shopItem.ItemPeriod); } user.ModifyInventory(i => i.Add(item)); } } else { result = 0x10; } p.Encode <byte>(result); user.SendPacket(p); } break; } case 1: // Sell { var pos = packet.Decode <short>(); var templateID = packet.Decode <int>(); var count = packet.Decode <short>(); var inventory = user.Character.GetInventory((ItemInventoryType)(templateID / 1000000)); var item = inventory.Items.FirstOrDefault(i => i.Position == pos); using (var p = new OutPacket(GameSendOperations.ShopResult)) { byte result = 0x0; if (item != null) { user.ModifyInventory(i => { if (item is ItemSlotBundle bundle) { if (!ItemInfo.IsRechargeableItem(item.TemplateID)) { if (count < bundle.Number) { bundle.Number -= count; i.UpdateQuantity(bundle); return; } } } count = 1; i.Remove(item); }); var templates = user.Socket.WvsGame.ItemTemplates; var template = templates.Get(item.TemplateID); var price = template.SellPrice * count; if (ItemInfo.IsRechargeableItem(item.TemplateID)) { price += ((ItemSlotBundle)item).Number; } user.ModifyStats(s => s.Money += price); } else { result = 0x10; } p.Encode <byte>(result); user.SendPacket(p); } break; } case 2: // Recharge { // TODO: recharge using (var p = new OutPacket(GameSendOperations.ShopResult)) { p.Encode <byte>(0x3); user.SendPacket(p); } break; } case 3: // Close user.Dialogue = null; break; } }
public override void PickUp(FieldUser user) { user.ModifyInventory(i => i.Add(Item), true); }
protected override Task ExecuteAfter(FieldUser user, ItemTemplate template, TemplateCommandOption option) => user.ModifyInventory(i => i.Add(template));