public void FDepositItem(InventoryType inventory, byte slot, byte amount, byte newSlot, ref ItemInstance item, ref ItemInstance itemdest) { if (item == null || amount > item.Amount || amount <= 0 || !item.Item.IsTradable || item.IsBound) { return; } FamilyCharacter fhead = Owner.Family?.FamilyCharacters.FirstOrDefault(s => s.Authority == FamilyAuthority.Head); if (fhead == null) { return; } MoveItem(inventory, InventoryType.FamilyWareHouse, slot, amount, newSlot, out item, out itemdest); itemdest.CharacterId = fhead.CharacterId; ItemInstanceDTO itemdest2 = itemdest; DAOFactory.IteminstanceDAO.InsertOrUpdate(ref itemdest2); Owner.Session.SendPacket(item != null ? item.GenerateInventoryAdd() : UserInterfaceHelper.Instance.GenerateInventoryRemove(inventory, slot)); if (itemdest == null) { return; } Owner.Session.SendPacket(itemdest.GenerateFStash()); Owner.Family?.InsertFamilyLog(FamilyLogType.WareHouseAdded, Owner.Name, message: $"{itemdest.ItemVNum}|{amount}"); DeleteById(itemdest.Id); }
public ItemInstance(ItemInstanceDTO inventoryItem) { Id = inventoryItem.Id; Amount = inventoryItem.Amount; ItemVNum = inventoryItem.ItemVNum; _random = new Random(); }
private static void Map(ItemInstanceDTO input, ItemInstance output) { if (input == null) { return; } Mapper.Mappers.ItemInstanceMapper.ToItemInstance(input, output); if (output.EquipmentSerialId == Guid.Empty) { output.EquipmentSerialId = Guid.NewGuid(); } }
public ItemInstanceDTO LoadById(Guid id) { using (OpenNosContext context = DataAccessHelper.CreateContext()) { ItemInstanceDTO ItemInstanceDTO = new ItemInstanceDTO(); if (map(context.ItemInstance.FirstOrDefault(i => i.Id.Equals(id)), ItemInstanceDTO)) { return(ItemInstanceDTO); } return(null); } }
protected static ItemInstanceDTO Update(ItemInstance entity, ItemInstanceDTO inventory, OpenNosContext context) { if (entity != null) { map(inventory, entity); context.SaveChanges(); } if (map(entity, inventory)) { return(inventory); } return(null); }
protected static ItemInstanceDTO InsertOrUpdate(OpenNosContext context, ItemInstanceDTO dto) { try { ItemInstance entity = context.ItemInstance.FirstOrDefault(c => c.Id == dto.Id); return(entity == null?Insert(dto, context) : Update(entity, dto, context)); } catch (Exception e) { Logger.Error(e); return(null); } }
private static bool Map(ItemInstance input, ItemInstanceDTO output) { if (input == null) { return(false); } Mapper.Mappers.ItemInstanceMapper.ToItemInstanceDTO(input, output); if (output.EquipmentSerialId == Guid.Empty) { output.EquipmentSerialId = Guid.NewGuid(); } return(true); }
public IEnumerable <ItemInstanceDTO> LoadByCharacterId(long characterId) { using (OpenNosContext context = DataAccessHelper.CreateContext()) { List <ItemInstanceDTO> result = new List <ItemInstanceDTO>(); foreach (ItemInstance itemInstance in context.ItemInstance.Where(i => i.CharacterId.Equals(characterId))) { ItemInstanceDTO output = new ItemInstanceDTO(); map(itemInstance, output); result.Add(output); } return(result); } }
private bool map(ItemInstanceDTO input, ItemInstance output, bool exists = false) { if (input == null) { output = null; return(false); } Mapper.Mapper.Instance.ItemInstanceMapper.ToItemInstance(input, output); if (output.EquipmentSerialId == Guid.Empty) { output.EquipmentSerialId = Guid.NewGuid(); } return(true); }
public IEnumerable <ItemInstanceDTO> LoadByType(long characterId, InventoryType type) { using (OpenNosContext context = DataAccessHelper.CreateContext()) { List <ItemInstanceDTO> result = new List <ItemInstanceDTO>(); foreach (ItemInstance itemInstance in context.ItemInstance.Where(i => i.CharacterId == characterId && i.Type == type)) { ItemInstanceDTO output = new ItemInstanceDTO(); map(itemInstance, output); result.Add(output); } return(result); } }
protected ItemInstanceDTO Insert(ItemInstanceDTO dto, OpenNosContext context) { ItemInstance entity = new ItemInstance(); map(dto, entity); context.Set <ItemInstance>().Add(entity); context.SaveChanges(); if (map(entity, dto)) { return(dto); } return(null); }
public ItemInstanceDTO InsertOrUpdate(ItemInstanceDTO dto) { try { using (OpenNosContext context = DataAccessHelper.CreateContext()) { return(InsertOrUpdate(context, dto)); } } catch (Exception e) { Logger.Error($"Message: {e.Message}", e); return(null); } }
private static void CheckItemInstanceType(ItemInstanceDTO itemInstance) { if (itemInstance != null) { if (itemInstance.Type == InventoryType.Specialist && !(itemInstance is SpecialistInstance)) { Logger.Error(new Exception("Cannot add an item of type Specialist without beeing a SpecialistInstance.")); return; } if ((itemInstance.Type == InventoryType.Equipment || itemInstance.Type == InventoryType.Wear) && !(itemInstance is WearableInstance)) { Logger.Error(new Exception("Cannot add an item of type Equipment or Wear without beeing a WearableInstance.")); } } }
public DeleteResult DeleteFromSlotAndType(long characterId, short slot, InventoryType type) { try { ItemInstanceDTO dto = LoadBySlotAndType(characterId, slot, type); if (dto != null) { return(Delete(dto.Id)); } return(DeleteResult.Unknown); } catch (Exception e) { Logger.Error($"characterId: {characterId} slot: {slot} type: {type}", e); return(DeleteResult.Error); } }
public ItemInstanceDTO LoadBySlotAndType(long characterId, short slot, InventoryType type) { try { using (OpenNosContext context = DataAccessHelper.CreateContext()) { ItemInstance entity = context.ItemInstance.FirstOrDefault(i => i.CharacterId == characterId && i.Slot == slot && i.Type == type); ItemInstanceDTO output = new ItemInstanceDTO(); if (map(entity, output)) { return(output); } return(null); } } catch (Exception e) { Logger.Error(e); return(null); } }
/// <summary> /// c_buy packet /// </summary> /// <param name="cBuyPacket"></param> public void BuyBazaar(CBuyPacket cBuyPacket) { if (ServerManager.Instance.InShutdown || Session.Character == null || Session.Character.InExchangeOrTrade) { return; } BazaarItemDTO bz = DAOFactory.BazaarItemDAO.FirstOrDefault(s => s.BazaarItemId == cBuyPacket.BazaarId); if (bz != null && cBuyPacket.Amount > 0) { long price = cBuyPacket.Amount * bz.Price; if (Session.Character.Gold >= price) { BazaarItemLink bzcree = new BazaarItemLink { BazaarItem = bz }; if (DAOFactory.CharacterDAO.FirstOrDefault(s => s.CharacterId == bz.SellerId && s.State == (byte)CharacterState.Active) != null) { bzcree.Owner = DAOFactory.CharacterDAO.FirstOrDefault(s => s.CharacterId.Equals(bz.SellerId) && s.State == (byte)CharacterState.Active)?.Name; bzcree.Item = (ItemInstance)DAOFactory.IteminstanceDAO.FirstOrDefault(s => s.Id == bz.ItemInstanceId); } if (cBuyPacket.Amount <= bzcree.Item.Amount) { if (!Session.Character.Inventory.CanAddItem(bzcree.Item.ItemVNum)) { Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0)); return; } if (bzcree.Item == null) { return; } if (bz.IsPackage && cBuyPacket.Amount != bz.Amount) { return; } ItemInstanceDTO bzitemdto = DAOFactory.IteminstanceDAO.FirstOrDefault(s => s.Id == bzcree.BazaarItem.ItemInstanceId); if (bzitemdto.Amount < cBuyPacket.Amount) { return; } bzitemdto.Amount -= cBuyPacket.Amount; Session.Character.Gold -= price; Session.SendPacket(Session.Character.GenerateGold()); DAOFactory.IteminstanceDAO.InsertOrUpdate(ref bzitemdto); ServerManager.Instance.BazaarRefresh(bzcree.BazaarItem.BazaarItemId); Session.SendPacket($"rc_buy 1 {bzcree.Item.Item.VNum} {bzcree.Owner} {cBuyPacket.Amount} {cBuyPacket.Price} 0 0 0"); ItemInstance newBz = bzcree.Item.DeepCopy(); newBz.Id = Guid.NewGuid(); newBz.Amount = cBuyPacket.Amount; newBz.Type = newBz.Item.Type; if (newBz is WearableInstance wear) { wear.EquipmentOptions.ForEach(s => s.WearableInstanceId = newBz.Id); } List <ItemInstance> newInv = Session.Character.Inventory.AddToInventory(newBz); if (newInv.Any()) { Session.SendPacket(Session.Character.GenerateSay($"{Language.Instance.GetMessageFromKey("ITEM_ACQUIRED")}: { bzcree.Item.Item.Name} x {cBuyPacket.Amount}", 10)); } } else { Session.SendPacket(UserInterfaceHelper.Instance.GenerateModal(Language.Instance.GetMessageFromKey("STATE_CHANGED"), 1)); } } else { Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 10)); Session.SendPacket(UserInterfaceHelper.Instance.GenerateModal(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 1)); } } else { Session.SendPacket(UserInterfaceHelper.Instance.GenerateModal(Language.Instance.GetMessageFromKey("STATE_CHANGED"), 1)); } }
/// <summary> /// c_reg packet /// </summary> /// <param name="cRegPacket"></param> public void SellBazaar(CRegPacket cRegPacket) { if (ServerManager.Instance.InShutdown || Session.Character == null || Session.Character.InExchangeOrTrade) { return; } SpinWait.SpinUntil(() => !ServerManager.Instance.InBazaarRefreshMode); StaticBonusDTO medal = Session.Character.StaticBonusList.FirstOrDefault(s => s.StaticBonusType == StaticBonusType.BazaarMedalGold || s.StaticBonusType == StaticBonusType.BazaarMedalSilver); long price = cRegPacket.Price * cRegPacket.Amount; long taxmax = price > 100000 ? price / 200 : 500; long taxmin = price >= 4000 ? (60 + (price - 4000) / 2000 * 30 > 10000 ? 10000 : 60 + (price - 4000) / 2000 * 30) : 50; long tax = medal == null ? taxmax : taxmin; long maxGold = ServerManager.Instance.MaxGold; if (Session.Character.Gold < tax || cRegPacket.Amount <= 0 || Session.Character.ExchangeInfo != null && Session.Character.ExchangeInfo.ExchangeList.Any() || Session.Character.IsShopping) { return; } ItemInstance it = Session.Character.Inventory.LoadBySlotAndType(cRegPacket.Slot, cRegPacket.Inventory == 4 ? 0 : (InventoryType)cRegPacket.Inventory); if (it == null || !it.Item.IsSoldable || it.IsBound) { return; } if (Session.Character.Inventory.CountItemInAnInventory(InventoryType.Bazaar) > 10 * (medal == null ? 1 : 10)) { Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("LIMIT_EXCEEDED"), 0)); return; } if (price > (medal == null ? 100000000 : maxGold)) { Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("PRICE_EXCEEDED"), 0)); return; } if (cRegPacket.Price < 0) { return; } ItemInstance bazar = Session.Character.Inventory.AddIntoBazaarInventory(cRegPacket.Inventory == 4 ? 0 : (InventoryType)cRegPacket.Inventory, cRegPacket.Slot, cRegPacket.Amount); if (bazar == null) { return; } short duration; switch (cRegPacket.Durability) { case 1: duration = 24; break; case 2: duration = 168; break; case 3: duration = 360; break; case 4: duration = 720; break; default: return; } ItemInstanceDTO bazarDto = bazar; DAOFactory.IteminstanceDAO.InsertOrUpdate(ref bazarDto); BazaarItemDTO bazaarItem = new BazaarItemDTO { Amount = bazar.Amount, DateStart = DateTime.Now, Duration = duration, IsPackage = cRegPacket.IsPackage != 0, MedalUsed = medal != null, Price = cRegPacket.Price, SellerId = Session.Character.CharacterId, ItemInstanceId = bazar.Id }; DAOFactory.BazaarItemDAO.InsertOrUpdate(ref bazaarItem); if (bazar is WearableInstance wear) { wear.EquipmentOptions.ForEach(s => s.WearableInstanceId = bazar.Id); IEnumerable <EquipmentOptionDTO> equipmentOptionDtos = wear.EquipmentOptions; DAOFactory.EquipmentOptionDAO.InsertOrUpdate(equipmentOptionDtos); } ServerManager.Instance.BazaarRefresh(bazaarItem.BazaarItemId); Session.Character.Gold -= tax; Session.SendPacket(Session.Character.GenerateGold()); Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("OBJECT_IN_BAZAAR"), 10)); Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("OBJECT_IN_BAZAAR"), 0)); Session.SendPacket("rc_reg 1"); }
public ItemInstance(ItemInstanceDTO inventoryItem) { Id = inventoryItem.Id; Amount = inventoryItem.Amount; ItemVNum = inventoryItem.ItemVNum; }
public static bool ToItemInstanceDTO(ItemInstance input, ItemInstanceDTO output) { if (input == null) { return(false); } output.Ammo = input.Ammo ?? 0; output.Amount = (byte)input.Amount; output.BoundCharacterId = input.BoundCharacterId; output.Cellon = input.Cellon ?? 0; output.CharacterId = input.CharacterId; output.CloseDefence = input.CloseDefence ?? 0; output.Concentrate = input.Concentrate ?? 0; output.CriticalDodge = input.CriticalDodge ?? 0; output.CriticalLuckRate = input.CriticalLuckRate ?? 0; output.CriticalRate = input.CriticalRate ?? 0; output.DamageMaximum = input.DamageMaximum ?? 0; output.DamageMinimum = input.DamageMinimum ?? 0; output.DarkElement = input.DarkElement ?? 0; output.DarkResistance = input.DarkResistance ?? 0; output.DefenceDodge = input.DefenceDodge ?? 0; output.Design = input.Design; output.DistanceDefence = input.DistanceDefence ?? 0; output.DistanceDefenceDodge = input.DistanceDefenceDodge ?? 0; output.DurabilityPoint = input.DurabilityPoint; output.ElementRate = input.ElementRate ?? 0; output.EquipmentSerialId = input.EquipmentSerialId ?? Guid.Empty; output.FireElement = input.FireElement ?? 0; output.FireResistance = input.FireResistance ?? 0; output.HitRate = input.HitRate ?? 0; output.HoldingVNum = input.HoldingVNum ?? 0; output.HP = input.HP ?? 0; output.Id = input.Id; output.IsEmpty = input.IsEmpty ?? false; output.IsFixed = input.IsFixed ?? false; output.ItemDeleteTime = input.ItemDeleteTime; output.ItemVNum = input.ItemVNum; output.LightElement = input.LightElement ?? 0; output.LightResistance = input.LightResistance ?? 0; output.MagicDefence = input.MagicDefence ?? 0; output.MaxElementRate = input.MaxElementRate ?? 0; output.MP = input.MP ?? 0; output.Rare = (sbyte)input.Rare; output.SlDamage = input.SlDamage ?? 0; output.SlDefence = input.SlDefence ?? 0; output.SlElement = input.SlElement ?? 0; output.SlHP = input.SlHP ?? 0; output.Slot = input.Slot; output.SpDamage = input.SpDamage ?? 0; output.SpDark = input.SpDark ?? 0; output.SpDefence = input.SpDefence ?? 0; output.SpElement = input.SpElement ?? 0; output.SpFire = input.SpFire ?? 0; output.SpHP = input.SpHP ?? 0; output.SpLevel = input.SpLevel ?? 0; output.SpLight = input.SpLight ?? 0; output.SpStoneUpgrade = input.SpStoneUpgrade ?? 0; output.SpWater = input.SpWater ?? 0; output.Type = input.Type; output.Upgrade = input.Upgrade; output.WaterElement = input.WaterElement ?? 0; output.WaterResistance = input.WaterResistance ?? 0; output.XP = input.XP ?? 0; output.ShellRarity = input.ShellRarity ?? output.Rare; // automatically "fixes" old shells output.ItemOptions = input.ItemOptions; output.Agility = input.Agility; output.FirstPartnerSkill = input.FirstPartnerSkill; output.SecondPartnerSkill = input.SecondPartnerSkill; output.ThirdPartnerSkill = input.ThirdPartnerSkill; output.FirstPartnerSkillRank = input.FirstPartnerSkillRank; output.SecondPartnerSkillRank = input.SecondPartnerSkillRank; output.ThirdPartnerSkillRank = input.ThirdPartnerSkillRank; output.MinimumLevel = input.MinimumLevel; output.BaseMinDamage = input.BaseMinDamage; output.BaseMaxDamage = input.BaseMaxDamage; output.BaseConcentrate = input.BaseConcentrate; output.BaseHitRate = input.BaseHitRate; output.BaseDefenceDodge = input.BaseDefenceDodge; output.BaseDistanceDefence = input.BaseDistanceDefence; output.BaseDistanceDefenceDodge = input.BaseDistanceDefenceDodge; output.BaseMagicDefence = input.BaseMagicDefence; output.BaseCloseDefence = input.BaseCloseDefence; return(true); }
public bool ToItemInstance(ItemInstanceDTO input, ItemInstance output) { if (input == null) { output = null; return(false); } output.Ammo = input.Ammo; output.Amount = input.Amount; output.BoundCharacterId = input.BoundCharacterId; output.Cellon = input.Cellon; output.CharacterId = input.CharacterId; output.CloseDefence = input.CloseDefence; output.Concentrate = input.Concentrate; output.CriticalDodge = input.CriticalDodge; output.CriticalLuckRate = input.CriticalLuckRate; output.CriticalRate = input.CriticalRate; output.DamageMaximum = input.DamageMaximum; output.DamageMinimum = input.DamageMinimum; output.DarkElement = input.DarkElement; output.DarkResistance = input.DarkResistance; output.DefenceDodge = input.DefenceDodge; output.Design = input.Design; output.DistanceDefence = input.DistanceDefence; output.DistanceDefenceDodge = input.DistanceDefenceDodge; output.DurabilityPoint = input.DurabilityPoint; output.ElementRate = input.ElementRate; output.EquipmentSerialId = input.EquipmentSerialId; output.FireElement = input.FireElement; output.FireResistance = input.FireResistance; output.HitRate = input.HitRate; output.HoldingVNum = input.HoldingVNum; output.HP = input.HP; output.Id = input.Id; output.IsEmpty = input.IsEmpty; output.IsFixed = input.IsFixed; output.ItemDeleteTime = input.ItemDeleteTime; output.ItemVNum = input.ItemVNum; output.LightElement = input.LightElement; output.LightResistance = input.LightResistance; output.MagicDefence = input.MagicDefence; output.MaxElementRate = input.MaxElementRate; output.MP = input.MP; output.Rare = input.Rare; output.SlDamage = input.SlDamage; output.SlDefence = input.SlDefence; output.SlElement = input.SlElement; output.SlHP = input.SlHP; output.Slot = input.Slot; output.SpDamage = input.SpDamage; output.SpDark = input.SpDark; output.SpDefence = input.SpDefence; output.SpElement = input.SpElement; output.SpFire = input.SpFire; output.SpHP = input.SpHP; output.SpLevel = input.SpLevel; output.SpLight = input.SpLight; output.SpStoneUpgrade = input.SpStoneUpgrade; output.SpWater = input.SpWater; output.Type = input.Type; output.Upgrade = input.Upgrade; output.WaterElement = input.WaterElement; output.WaterResistance = input.WaterResistance; output.XP = input.XP; return(true); }