示例#1
0
        public void AddToBazaar(BazaarItemDTO bazaarItem)
        {
            // we are not supposed to save each addition! we will only save them on Save() function.
            // that might be hard to overcome i guess...

            // we should never add more than 1 instance of iteminstance to bazaar!
            if (bazaarItem != null && !BazaarList.Any(s => s.BazaarItem.ItemInstanceId.Equals(bazaarItem.ItemInstanceId)))
            {
                ItemInstance item = new ItemInstance(DAOFactory.ItemInstanceDAO.LoadById(bazaarItem.ItemInstanceId));
                string       name = DAOFactory.CharacterDAO.LoadById(bazaarItem.SellerId)?.Name;
                if (item != null && !string.IsNullOrEmpty(name))
                {
                    BazaarList[bazaarItem.BazaarItemId] = new BazaarItemLink()
                    {
                        BazaarItem = bazaarItem,
                        Item       = item,
                        OwnerName  = name
                    };

                    // we will propably need to also update the iteminstance.
                }
            }
            else
            {
                // log or return something
            }
        }
        public SaveResult InsertOrUpdate(ref BazaarItemDTO bazaarItem)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    long       bazaarItemId = bazaarItem.BazaarItemId;
                    BazaarItem entity       = context.BazaarItem.FirstOrDefault(c => c.BazaarItemId.Equals(bazaarItemId));

                    if (entity == null)
                    {
                        bazaarItem = Insert(bazaarItem, context);
                        return(SaveResult.Inserted);
                    }

                    bazaarItem = Update(entity, bazaarItem, context);
                    return(SaveResult.Updated);
                }
            }
            catch (Exception e)
            {
                Logger.Error($"BazaarItemId: {bazaarItem.BazaarItemId} Message: {e.Message}", e);
                return(SaveResult.Error);
            }
        }
示例#3
0
        public void Save()
        {
            // this will need extensive testing, it needs to be the most stable piece of code in the
            // entire project!

            // add
            foreach (BazaarItemLink link in BazaarList.GetAllItems())
            {
                if (DAOFactory.BazaarItemDAO.LoadById(link.BazaarItem.BazaarItemId) == null)
                {
                    BazaarItemDTO item = link.BazaarItem;
                    DAOFactory.BazaarItemDAO.InsertOrUpdate(ref item);
                    DAOFactory.ItemInstanceDAO.InsertOrUpdate(link.Item);
                }
            }

            // remove
            foreach (BazaarItemDTO item in DAOFactory.BazaarItemDAO.LoadAll())
            {
                if (!BazaarList.Any(s => s.BazaarItem.ItemInstanceId.Equals(item.ItemInstanceId)))
                {
                    DAOFactory.BazaarItemDAO.Delete(item.BazaarItemId);
                    DAOFactory.ItemInstanceDAO.Delete(item.ItemInstanceId);
                }
            }
            DAOFactory.BazaarItemDAO.RemoveOutDated();
        }
        /// <summary>
        /// c_scalc packet
        /// </summary>
        /// <param name="cScalcPacket"></param>
        public void GetBazaar(CScalcPacket cScalcPacket)
        {
            SpinWait.SpinUntil(() => !ServerManager.Instance.InBazaarRefreshMode);
            BazaarItemDTO bz = DAOFactory.BazaarItemDAO.LoadAll().FirstOrDefault(s => s.BazaarItemId == cScalcPacket.BazaarId);

            if (bz != null)
            {
                ItemInstance Item = (ItemInstance)DAOFactory.IteminstanceDAO.LoadById(bz.ItemInstanceId);
                if (Item == null || bz.SellerId != Session.Character.CharacterId)
                {
                    return;
                }
                int  soldedamount = bz.Amount - Item.Amount;
                long taxes        = bz.MedalUsed ? 0 : (long)(bz.Price * 0.10 * soldedamount);
                long price        = bz.Price * soldedamount - taxes;
                if (Session.Character.Inventory.CanAddItem(Item.ItemVNum))
                {
                    if (Session.Character.Gold + price <= ServerManager.Instance.MaxGold)
                    {
                        Session.Character.Gold += price;
                        Session.SendPacket(Session.Character.GenerateGold());
                        Session.SendPacket(Session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("REMOVE_FROM_BAZAAR"), price), 10));
                        if (Item.Amount != 0)
                        {
                            ItemInstance newBz = Item.DeepCopy();
                            newBz.Id   = Guid.NewGuid();
                            newBz.Type = newBz.Item.Type;

                            List <ItemInstance> newInv = Session.Character.Inventory.AddToInventory(newBz);
                        }
                        Session.SendPacket($"rc_scalc 1 {bz.Price} {bz.Amount - Item.Amount} {bz.Amount} {taxes} {price + taxes}");

                        if (DAOFactory.BazaarItemDAO.LoadById(bz.BazaarItemId) != null)
                        {
                            DAOFactory.BazaarItemDAO.Delete(bz.BazaarItemId);
                        }

                        DAOFactory.IteminstanceDAO.Delete(Item.Id);

                        ServerManager.Instance.BazaarRefresh(bz.BazaarItemId);
                    }
                    else
                    {
                        Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("MAX_GOLD"), 0));
                        Session.SendPacket($"rc_scalc 1 {bz.Price} 0 {bz.Amount} 0 0");
                    }
                }
                else
                {
                    Session.SendPacket(UserInterfaceHelper.Instance.GenerateInfo(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE")));
                    Session.SendPacket($"rc_scalc 1 {bz.Price} 0 {bz.Amount} 0 0");
                }
            }
            else
            {
                Session.SendPacket("rc_scalc 1 0 0 0 0 0");
            }
        }
 public IEnumerable <BazaarItemDTO> LoadAll()
 {
     using (OpenNosContext context = DataAccessHelper.CreateContext())
     {
         List <BazaarItemDTO> result = new List <BazaarItemDTO>();
         foreach (BazaarItem bazaarItem in context.BazaarItem.AsNoTracking())
         {
             BazaarItemDTO dto = new BazaarItemDTO();
             Mapper.Mappers.BazaarItemMapper.ToBazaarItemDTO(bazaarItem, dto);
             result.Add(dto);
         }
         return(result);
     }
 }
        private static BazaarItemDTO Update(BazaarItem entity, BazaarItemDTO bazaarItem, OpenNosContext context)
        {
            if (entity != null)
            {
                Mapper.Mappers.BazaarItemMapper.ToBazaarItem(bazaarItem, entity);
                context.SaveChanges();
            }
            if (Mapper.Mappers.BazaarItemMapper.ToBazaarItemDTO(entity, bazaarItem))
            {
                return(bazaarItem);
            }

            return(null);
        }
        private static BazaarItemDTO Insert(BazaarItemDTO bazaarItem, OpenNosContext context)
        {
            BazaarItem entity = new BazaarItem();

            Mapper.Mappers.BazaarItemMapper.ToBazaarItem(bazaarItem, entity);
            context.BazaarItem.Add(entity);
            context.SaveChanges();
            if (Mapper.Mappers.BazaarItemMapper.ToBazaarItemDTO(entity, bazaarItem))
            {
                return(bazaarItem);
            }

            return(null);
        }
示例#8
0
 public static bool ToBazaarItemDTO(BazaarItem input, BazaarItemDTO output)
 {
     if (input == null)
     {
         return(false);
     }
     output.Amount         = input.Amount;
     output.BazaarItemId   = input.BazaarItemId;
     output.DateStart      = input.DateStart;
     output.Duration       = input.Duration;
     output.IsPackage      = input.IsPackage;
     output.ItemInstanceId = input.ItemInstanceId;
     output.MedalUsed      = input.MedalUsed;
     output.Price          = input.Price;
     output.SellerId       = input.SellerId;
     return(true);
 }
示例#9
0
        public void RefreshBazaar(long bazaarItemId)
        {
            BazaarItemDTO  bzdto  = DAOFactory.BazaarItemDAO.LoadById(bazaarItemId);
            BazaarItemLink bzlink = BazaarList[bazaarItemId];

            // maybe we shouldnt lock the entire list.
            lock (BazaarList)
            {
                if (bzdto != null)
                {
                    CharacterDTO chara = DAOFactory.CharacterDAO.LoadById(bzdto.SellerId);
                    if (bzlink != null)
                    {
                        // why do we do this update? this is a copy of code from ServerManager
                        BazaarList.Remove(bzlink);
                        bzlink.BazaarItem        = bzdto;
                        bzlink.OwnerName         = chara.Name;
                        bzlink.Item              = new ItemInstance(DAOFactory.ItemInstanceDAO.LoadById(bzdto.ItemInstanceId));
                        BazaarList[bazaarItemId] = bzlink;
                    }
                    else
                    {
                        BazaarItemLink item = new BazaarItemLink
                        {
                            BazaarItem = bzdto
                        };
                        if (chara != null)
                        {
                            item.OwnerName = chara.Name;
                            item.Item      = new ItemInstance(DAOFactory.ItemInstanceDAO.LoadById(bzdto.ItemInstanceId));
                        }
                        BazaarList[bazaarItemId] = item;
                    }
                }
                else if (bzlink != null)
                {
                    BazaarList.Remove(bzlink);
                }
            }
            InBazaarRefreshMode = false;
        }
        public BazaarItemDTO LoadById(long bazaarItemId)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    BazaarItemDTO dto = new BazaarItemDTO();
                    if (Mapper.Mappers.BazaarItemMapper.ToBazaarItemDTO(context.BazaarItem.AsNoTracking().FirstOrDefault(i => i.BazaarItemId.Equals(bazaarItemId)), dto))
                    {
                        return(dto);
                    }

                    return(null);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(null);
            }
        }
示例#11
0
        /// <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));
            }
        }
示例#12
0
        /// <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");
        }
        private void ExecuteHandler(ClientSession session)
        {
            SpinWait.SpinUntil(() => !ServerManager.Instance.InBazaarRefreshMode);
            StaticBonusDTO medal = session.Character.StaticBonusList.Find(s =>
                                                                          s.StaticBonusType == StaticBonusType.BazaarMedalGold ||
                                                                          s.StaticBonusType == StaticBonusType.BazaarMedalSilver);

            long price  = Price * 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.Configuration.MaxGold;

            if (session.Character.Gold < tax || Amount <= 0 ||
                session.Character.ExchangeInfo?.ExchangeList.Count > 0 || session.Character.IsShopping)
            {
                return;
            }

            ItemInstance it = session.Character.Inventory.LoadBySlotAndType(Slot,
                                                                            InventoryType == 4 ? 0 : (InventoryType)InventoryType);

            if (it?.Item.IsSoldable != true || !it.Item.IsTradable || (it.IsBound &&
                                                                       !(it.Item.Type == Domain.InventoryType.Equipment &&
                                                                         (it.Item.ItemType == ItemType.Armor || it.Item.ItemType == ItemType.Weapon))))
            {
                return;
            }

            if (session.Character.Inventory.CountItemInAnInventory(Domain.InventoryType.Bazaar)
                > 10 * (medal == null ? 1 : 10))
            {
                session.SendPacket(
                    UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("LIMIT_EXCEEDED"), 0));
                return;
            }

            if (price >= (medal == null ? 1000000 : maxGold))
            {
                session.SendPacket(
                    UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("PRICE_EXCEEDED"), 0));
                return;
            }

            if (Price < 0)
            {
                return;
            }

            ItemInstance bazaar = session.Character.Inventory.AddIntoBazaarInventory(
                InventoryType == 4 ? 0 : (InventoryType)InventoryType, Slot,
                Amount);

            if (bazaar == null)
            {
                return;
            }

            short duration;

            switch (Durability)
            {
            case 1:
                duration = 24;
                break;

            case 2:
                duration = 168;
                break;

            case 3:
                duration = 360;
                break;

            case 4:
                duration = 720;
                break;

            default:
                return;
            }

            DAOFactory.ItemInstanceDAO.InsertOrUpdate(bazaar);

            BazaarItemDTO bazaarItem = new BazaarItemDTO
            {
                Amount         = bazaar.Amount,
                DateStart      = DateTime.UtcNow,
                Duration       = duration,
                IsPackage      = IsPackage != 0,
                MedalUsed      = medal != null,
                Price          = Price,
                SellerId       = session.Character.CharacterId,
                ItemInstanceId = bazaar.Id
            };

            DAOFactory.BazaarItemDAO.InsertOrUpdate(ref bazaarItem);
            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.GenerateMsg(Language.Instance.GetMessageFromKey("OBJECT_IN_BAZAAR"),
                                                               0));

            GameLogger.Instance.LogBazaarInsert(ServerManager.Instance.ChannelId, session.Character.Name,
                                                session.Character.CharacterId, bazaarItem, bazaar.ItemVNum);

            session.SendPacket("rc_reg 1");
        }
示例#14
0
        private void ExecuteHandler(ClientSession session)
        {
            BazaarItemDTO bzItem = DAOFactory.BazaarItemDAO.LoadById(BazaarId);

            if (bzItem != null && Amount > 0)
            {
                long price = Amount * bzItem.Price;

                if (session.Character.Gold >= price)
                {
                    BazaarItemLink bzItemLink = new BazaarItemLink {
                        BazaarItem = bzItem
                    };
                    if (DAOFactory.CharacterDAO.LoadById(bzItem.SellerId) != null)
                    {
                        bzItemLink.OwnerName = DAOFactory.CharacterDAO.LoadById(bzItem.SellerId)?.Name;
                        bzItemLink.Item      = new ItemInstance(DAOFactory.ItemInstanceDAO.LoadById(bzItem.ItemInstanceId));
                    }
                    else
                    {
                        return;
                    }

                    if (Amount <= bzItemLink.Item.Amount)
                    {
                        if (!session.Character.Inventory.CanAddItem(bzItemLink.Item.ItemVNum))
                        {
                            session.SendPacket(
                                UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"),
                                                                0));
                            return;
                        }
                        if (bzItemLink.Item == null || (bzItem.IsPackage && Amount != bzItem.Amount))
                        {
                            return;
                        }

                        ItemInstance itemInstance =
                            new ItemInstance(DAOFactory.ItemInstanceDAO.LoadById(bzItemLink.BazaarItem.ItemInstanceId));
                        if (Amount > itemInstance.Amount)
                        {
                            return;
                        }

                        itemInstance.Amount    -= Amount;
                        session.Character.Gold -= price;
                        session.SendPacket(session.Character.GenerateGold());
                        DAOFactory.ItemInstanceDAO.InsertOrUpdate(itemInstance);
                        ServerManager.Instance.BazaarRefresh(bzItemLink.BazaarItem.BazaarItemId);
                        session.SendPacket(
                            $"rc_buy 1 {itemInstance.ItemVNum} {bzItemLink.OwnerName} {Amount} {Price} 0 0 0");

                        ItemInstance newBz = bzItemLink.Item.DeepCopy();
                        newBz.Id     = Guid.NewGuid();
                        newBz.Amount = Amount;
                        newBz.Type   = newBz.Item.Type;
                        List <ItemInstance> newInv = session.Character.Inventory.AddToInventory(newBz);

                        if (newInv.Count > 0)
                        {
                            session.SendPacket(session.Character.GenerateSay(
                                                   $"{Language.Instance.GetMessageFromKey("ITEM_ACQUIRED")}: {itemInstance.Item.Name} x {Amount}",
                                                   10));
                        }

                        GameLogger.Instance.LogBazaarBuy(ServerManager.Instance.ChannelId, session.Character.Name,
                                                         session.Character.CharacterId, bzItem, itemInstance.ItemVNum, Amount, price);
                    }
                    else
                    {
                        session.SendPacket(
                            UserInterfaceHelper.GenerateModal(Language.Instance.GetMessageFromKey("STATE_CHANGED"), 1));
                    }
                }
                else
                {
                    session.SendPacket(
                        session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 10));
                    session.SendPacket(
                        UserInterfaceHelper.GenerateModal(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 1));
                }
            }
            else
            {
                session.SendPacket(
                    UserInterfaceHelper.GenerateModal(Language.Instance.GetMessageFromKey("STATE_CHANGED"), 1));
            }
        }
示例#15
0
        private void ExecuteHandler(ClientSession session)
        {
            SpinWait.SpinUntil(() => !ServerManager.Instance.InBazaarRefreshMode);
            BazaarItemDTO bz = DAOFactory.BazaarItemDAO.LoadById(BazaarId);

            if (bz != null)
            {
                ItemInstance itemInstance = new ItemInstance(DAOFactory.ItemInstanceDAO.LoadById(bz.ItemInstanceId));
                if (bz.SellerId != session.Character.CharacterId)
                {
                    return;
                }

                int  solddamount = bz.Amount - itemInstance.Amount;
                long taxes       = bz.MedalUsed ? 0 : (long)(bz.Price * 0.10 * solddamount);
                long price       = (bz.Price * solddamount) - taxes;
                if (session.Character.Inventory.CanAddItem(itemInstance.ItemVNum))
                {
                    if (session.Character.Gold + price <= ServerManager.Instance.Configuration.MaxGold)
                    {
                        session.Character.Gold += price;
                        session.SendPacket(session.Character.GenerateGold());
                        session.SendPacket(session.Character.GenerateSay(
                                               string.Format(Language.Instance.GetMessageFromKey("REMOVE_FROM_BAZAAR"), price), 10));

                        // Edit this soo we dont generate new guid every single time we take something out.
                        if (itemInstance.Amount != 0)
                        {
                            ItemInstance newBz = itemInstance.DeepCopy();
                            newBz.Id   = Guid.NewGuid();
                            newBz.Type = newBz.Item.Type;
                            session.Character.Inventory.AddToInventory(newBz);
                        }

                        session.SendPacket(
                            $"rc_scalc 1 {bz.Price} {bz.Amount - itemInstance.Amount} {bz.Amount} {taxes} {price + taxes}");

                        GameLogger.Instance.LogBazaarRemove(ServerManager.Instance.ChannelId, session.Character.Name,
                                                            session.Character.CharacterId, bz, itemInstance, price, taxes);

                        if (DAOFactory.BazaarItemDAO.LoadById(bz.BazaarItemId) != null)
                        {
                            DAOFactory.BazaarItemDAO.Delete(bz.BazaarItemId);
                        }

                        DAOFactory.ItemInstanceDAO.Delete(itemInstance.Id);

                        ServerManager.Instance.BazaarRefresh(bz.BazaarItemId);
                    }
                    else
                    {
                        session.SendPacket(
                            UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("MAX_GOLD"), 0));
                        session.SendPacket($"rc_scalc 1 {bz.Price} 0 {bz.Amount} 0 0");
                    }
                }
                else
                {
                    session.SendPacket(
                        UserInterfaceHelper.GenerateInfo(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE")));
                    session.SendPacket($"rc_scalc 1 {bz.Price} 0 {bz.Amount} 0 0");
                }
            }
            else
            {
                session.SendPacket("rc_scalc 1 0 0 0 0 0");
            }
        }