internal PlayerItem(Inventory inventory, PlayerItemDto dto) { var shop = GameServer.Instance.ResourceCache.GetShop(); ExistsInDatabase = true; Inventory = inventory; Id = (ulong)dto.Id; var itemInfo = shop.Items.Values.FirstOrDefault(group => group.GetItemInfo(dto.ShopItemInfoId) != null); if (itemInfo == null) { IsInvalid = true; Inventory.RemoveInvalid(this); return; } ItemNumber = itemInfo.ItemNumber; var priceGroup = shop.Prices.Values.FirstOrDefault(group => group.GetPrice(dto.ShopPriceId) != null); if (priceGroup == null) { IsInvalid = true; Inventory.RemoveInvalid(this); return; } var price = priceGroup.GetPrice(dto.ShopPriceId); PriceType = priceGroup.PriceType; PeriodType = price.PeriodType; Period = price.Period; DaysLeft = (ushort)dto.DaysLeft; Color = dto.Color; var raweffects = new List <EffectNumber>(); var effectsText = dto.Effects.Split(",").ToList(); effectsText.ForEach(eff => { raweffects.Add(new EffectNumber(uint.Parse(eff))); }); Effects = raweffects.ToArray(); if (Effects.Length == 0) { Effects = new EffectNumber[] { 0 } } ; _durability = dto.Durability; _count = (uint)dto.Count; if (_count == 0) { _count = 1; } _enchantMP = dto.EnchantMP; _enchantLvl = dto.EnchantLvl; PurchaseDate = DateTimeOffset.FromUnixTimeSeconds(dto.PurchaseDate); }
/// <summary> /// Creates a new item /// </summary> /// <exception cref="CharacterException"></exception> public PlayerItem CreateSilent(ShopItemInfo shopItemInfo, ShopPrice price, byte color, EffectNumber[] effects, uint count) { if (effects.Length == 0) { effects = new EffectNumber[] { 0 } } ; var item = new PlayerItem(this, shopItemInfo, price, color, effects, DateTimeOffset.Now, count); _items.TryAdd(item.Id, item); return(item); }
/// <summary> /// Creates a new item /// </summary> /// <exception cref="CharacterException"></exception> public PlayerItem Create(ShopItemInfo shopItemInfo, ShopPrice price, byte color, EffectNumber[] effects, uint count) { if (effects.Length == 0) { effects = new EffectNumber[] { 0 } } ; var item = new PlayerItem(this, shopItemInfo, price, color, effects, DateTimeOffset.Now, count); _items.TryAdd(item.Id, item); Player.Session.SendAsync( new ItemUpdateInventoryAckMessage(InventoryAction.Add, item.Map <PlayerItem, ItemDto>())); return(item); }