private void ExecuteHandler(ClientSession session)
        {
            if (session.Character.Family == null ||
                !(session.Character.FamilyCharacter.Authority == FamilyAuthority.Head ||
                  session.Character.FamilyCharacter.Authority == FamilyAuthority.Assistant ||
                  (session.Character.FamilyCharacter.Authority == FamilyAuthority.Member &&
                   session.Character.Family.MemberAuthorityType == FamilyAuthorityType.All) ||
                  (session.Character.FamilyCharacter.Authority == FamilyAuthority.Manager &&
                   session.Character.Family.ManagerAuthorityType == FamilyAuthorityType.All)))
            {
                session.SendPacket(
                    UserInterfaceHelper.GenerateInfo(Language.Instance.GetMessageFromKey("NO_FAMILY_RIGHT")));
                return;
            }

            ItemInstance previousInventory =
                session.Character.Family.Warehouse.LoadBySlotAndType(Slot,
                                                                     InventoryType.FamilyWareHouse);

            if (Amount <= 0 || previousInventory == null ||
                Amount > previousInventory.Amount)
            {
                return;
            }

            ItemInstance item2 = previousInventory.DeepCopy();

            item2.Id          = Guid.NewGuid();
            item2.Amount      = Amount;
            item2.CharacterId = session.Character.CharacterId;

            previousInventory.Amount -= Amount;
            if (previousInventory.Amount <= 0)
            {
                previousInventory = null;
            }

            session.Character.Inventory.AddToInventory(item2, item2.Item.Type);
            session.SendPacket(UserInterfaceHelper.Instance.GenerateFStashRemove(Slot));
            if (previousInventory != null)
            {
                DAOFactory.ItemInstanceDAO.InsertOrUpdate(previousInventory);
            }
            else
            {
                FamilyCharacter fhead =
                    session.Character.Family.FamilyCharacters.Find(s => s.Authority == FamilyAuthority.Head);
                if (fhead == null)
                {
                    return;
                }

                DAOFactory.ItemInstanceDAO.DeleteFromSlotAndType(fhead.CharacterId, Slot,
                                                                 InventoryType.FamilyWareHouse);
            }

            session.Character.Family.InsertFamilyLog(FamilyLogType.WareHouseRemoved, session.Character.Name,
                                                     message: $"{item2.ItemVNum}|{Amount}");
        }
        /// <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");
            }
        }
        /// <summary>
        /// f_withdraw packet
        /// </summary>
        /// <param name="packet"></param>
        public void FamilyWithdraw(FWithdrawPacket packet)
        {
            if (Session.Character.Family == null ||
                !
                (Session.Character.FamilyCharacter.Authority == FamilyAuthority.Head ||
                 Session.Character.FamilyCharacter.Authority == FamilyAuthority.Assistant ||
                 Session.Character.FamilyCharacter.Authority == FamilyAuthority.Member && Session.Character.Family.MemberAuthorityType == FamilyAuthorityType.ALL ||
                 Session.Character.FamilyCharacter.Authority == FamilyAuthority.Manager && Session.Character.Family.ManagerAuthorityType == FamilyAuthorityType.ALL
                )
                )
            {
                Session.SendPacket(UserInterfaceHelper.Instance.GenerateInfo(Language.Instance.GetMessageFromKey("NO_FAMILY_RIGHT")));
                return;
            }
            ItemInstance previousInventory = Session.Character.Family.Warehouse.LoadBySlotAndType(packet.Slot, InventoryType.FamilyWareHouse);

            if (packet.Amount <= 0 || previousInventory == null || packet.Amount > previousInventory.Amount)
            {
                return;
            }
            ItemInstance item2 = previousInventory.DeepCopy();

            item2.Id          = Guid.NewGuid();
            item2.Amount      = packet.Amount;
            item2.CharacterId = Session.Character.CharacterId;

            previousInventory.Amount -= packet.Amount;
            if (previousInventory.Amount <= 0)
            {
                previousInventory = null;
            }
            List <ItemInstance> newInv = Session.Character.Inventory.AddToInventory(item2, item2.Item.Type);

            Session.SendPacket(UserInterfaceHelper.Instance.GenerateFStashRemove(packet.Slot));
            if (previousInventory != null)
            {
                DAOFactory.IteminstanceDAO.InsertOrUpdate(previousInventory);
            }
            else
            {
                FamilyCharacter fhead = Session.Character.Family.FamilyCharacters.FirstOrDefault(s => s.Authority == FamilyAuthority.Head);
                if (fhead == null)
                {
                    return;
                }
                DAOFactory.IteminstanceDAO.DeleteFromSlotAndType(fhead.CharacterId, packet.Slot, InventoryType.FamilyWareHouse);
            }
            Session.Character.Family.InsertFamilyLog(FamilyLogType.WareHouseRemoved, Session.Character.Name, message: $"{item2.ItemVNum}|{packet.Amount}");
        }
 private void ExecuteHandler(ClientSession session)
 {
     if (_isParsed)
     {
         Logger.LogUserEvent("GMCOMMAND", session.GenerateIdentity(), $"[Clone]Slot: {Slot}");
         ItemInstance item =
             session.Character.Inventory.LoadBySlotAndType(Slot, InventoryType.Equipment);
         if (item != null)
         {
             item    = item.DeepCopy();
             item.Id = Guid.NewGuid();
             session.Character.Inventory.AddToInventory(item);
         }
     }
     else
     {
         session.SendPacket(session.Character.GenerateSay(ReturnHelp(), 10));
     }
 }
        /// <summary>
        /// f_repos packet
        /// </summary>
        /// <param name="fReposPacket"></param>
        public void FamilyRepos(FReposPacket fReposPacket)
        {
            if (Session.Character.Family == null || !(Session.Character.FamilyCharacter.Authority == FamilyAuthority.Head ||
                                                      Session.Character.FamilyCharacter.Authority == FamilyAuthority.Assistant ||
                                                      Session.Character.FamilyCharacter.Authority == FamilyAuthority.Member && Session.Character.Family.MemberAuthorityType == FamilyAuthorityType.ALL ||
                                                      Session.Character.FamilyCharacter.Authority == FamilyAuthority.Manager && Session.Character.Family.ManagerAuthorityType == FamilyAuthorityType.ALL))
            {
                Session.SendPacket(UserInterfaceHelper.Instance.GenerateInfo(Language.Instance.GetMessageFromKey("NO_FAMILY_RIGHT")));
                return;
            }

            // check if the character is allowed to move the item
            if (Session.Character.InExchangeOrTrade || fReposPacket.Amount <= 0)
            {
                return;
            }
            if (fReposPacket.NewSlot > Session.Character.Family.WarehouseSize)
            {
                return;
            }

            ItemInstance sourceInventory      = Session.Character.Family.Warehouse.LoadBySlotAndType(fReposPacket.OldSlot, InventoryType.FamilyWareHouse);
            ItemInstance destinationInventory = Session.Character.Family.Warehouse.LoadBySlotAndType(fReposPacket.NewSlot, InventoryType.FamilyWareHouse);

            if (sourceInventory != null && fReposPacket.Amount <= sourceInventory.Amount)
            {
                if (destinationInventory == null)
                {
                    destinationInventory        = sourceInventory.DeepCopy();
                    sourceInventory.Amount     -= fReposPacket.Amount;
                    destinationInventory.Amount = fReposPacket.Amount;
                    destinationInventory.Slot   = fReposPacket.NewSlot;
                    if (sourceInventory.Amount > 0)
                    {
                        destinationInventory.Id = Guid.NewGuid();
                    }
                    else
                    {
                        sourceInventory = null;
                    }
                }
                else
                {
                    if (destinationInventory.ItemVNum == sourceInventory.ItemVNum && (byte)sourceInventory.Item.Type != 0)
                    {
                        if (destinationInventory.Amount + fReposPacket.Amount > 99)
                        {
                            int saveItemCount = destinationInventory.Amount;
                            destinationInventory.Amount = 99;
                            sourceInventory.Amount      = (byte)(saveItemCount + sourceInventory.Amount - 99);
                        }
                        else
                        {
                            destinationInventory.Amount += fReposPacket.Amount;
                            sourceInventory.Amount      -= fReposPacket.Amount;
                            if (sourceInventory.Amount == 0)
                            {
                                DAOFactory.IteminstanceDAO.Delete(sourceInventory.Id);
                                sourceInventory = null;
                            }
                        }
                    }
                    else
                    {
                        destinationInventory.Slot = fReposPacket.OldSlot;
                        sourceInventory.Slot      = fReposPacket.NewSlot;
                    }
                }
            }
            if (sourceInventory != null && sourceInventory.Amount > 0)
            {
                DAOFactory.IteminstanceDAO.InsertOrUpdate(sourceInventory);
            }
            if (destinationInventory != null && destinationInventory.Amount > 0)
            {
                DAOFactory.IteminstanceDAO.InsertOrUpdate(destinationInventory);
            }
            Session.SendPacket((destinationInventory != null) ? destinationInventory.GenerateFStash() : UserInterfaceHelper.Instance.GenerateFStashRemove(fReposPacket.NewSlot));
            Session.SendPacket((sourceInventory != null) ? sourceInventory.GenerateFStash() : UserInterfaceHelper.Instance.GenerateFStashRemove(fReposPacket.OldSlot));
            ServerManager.Instance.FamilyRefresh(Session.Character.Family.FamilyId);
        }
        private void ExecuteHandler(ClientSession session)
        {
            if (session.Character.Family == null ||
                !(session.Character.FamilyCharacter.Authority == FamilyAuthority.Head ||
                  session.Character.FamilyCharacter.Authority == FamilyAuthority.Assistant ||
                  (session.Character.FamilyCharacter.Authority == FamilyAuthority.Member &&
                   session.Character.Family.MemberAuthorityType == FamilyAuthorityType.All) ||
                  (session.Character.FamilyCharacter.Authority == FamilyAuthority.Manager &&
                   session.Character.Family.ManagerAuthorityType == FamilyAuthorityType.All)))
            {
                session.SendPacket(
                    UserInterfaceHelper.GenerateInfo(Language.Instance.GetMessageFromKey("NO_FAMILY_RIGHT")));
                return;
            }

            // check if the character is allowed to move the item
            if (session.Character.InExchangeOrTrade || Amount <= 0)
            {
                return;
            }

            if (NewSlot > session.Character.Family.WarehouseSize)
            {
                return;
            }

            ItemInstance sourceInventory =
                session.Character.Family.Warehouse.LoadBySlotAndType(OldSlot,
                                                                     InventoryType.FamilyWareHouse);
            ItemInstance destinationInventory =
                session.Character.Family.Warehouse.LoadBySlotAndType(NewSlot,
                                                                     InventoryType.FamilyWareHouse);

            if (sourceInventory != null && Amount <= sourceInventory.Amount)
            {
                if (destinationInventory == null)
                {
                    destinationInventory        = sourceInventory.DeepCopy();
                    sourceInventory.Amount     -= Amount;
                    destinationInventory.Amount = Amount;
                    destinationInventory.Slot   = NewSlot;
                    if (sourceInventory.Amount > 0)
                    {
                        destinationInventory.Id = Guid.NewGuid();
                    }
                    else
                    {
                        sourceInventory = null;
                    }
                }
                else if (destinationInventory.ItemVNum == sourceInventory.ItemVNum && (byte)sourceInventory.Item.Type != 0)
                {
                    if (destinationInventory.Amount + Amount > 255)
                    {
                        int saveItemCount = destinationInventory.Amount;
                        destinationInventory.Amount = 255;
                        sourceInventory.Amount      = (byte)(saveItemCount + sourceInventory.Amount - 255);
                    }
                    else
                    {
                        destinationInventory.Amount += Amount;
                        sourceInventory.Amount      -= Amount;
                        if (sourceInventory.Amount == 0)
                        {
                            DAOFactory.ItemInstanceDAO.Delete(sourceInventory.Id);
                            sourceInventory = null;
                        }
                    }
                }
                else
                {
                    destinationInventory.Slot = OldSlot;
                    sourceInventory.Slot      = NewSlot;
                }
            }

            if (sourceInventory?.Amount > 0)
            {
                DAOFactory.ItemInstanceDAO.InsertOrUpdate(sourceInventory);
            }

            if (destinationInventory?.Amount > 0)
            {
                DAOFactory.ItemInstanceDAO.InsertOrUpdate(destinationInventory);
            }

            session.SendPacket((destinationInventory != null)
                ? destinationInventory.GenerateFStash()
                : UserInterfaceHelper.Instance.GenerateFStashRemove(NewSlot));
            session.SendPacket((sourceInventory != null)
                ? sourceInventory.GenerateFStash()
                : UserInterfaceHelper.Instance.GenerateFStashRemove(OldSlot));
            ServerManager.Instance.FamilyRefresh(session.Character.Family.FamilyId);
        }
        private void ExecuteHandler(ClientSession session)
        {
            if (Gold < 0 || GoldBank < 0 || session.Character.Gold < Gold || session.Character.GoldBank < GoldBank || session.Character.ExchangeInfo == null ||
                session.Character.ExchangeInfo.ExchangeList.Count > 0)
            {
                return;
            }

            ClientSession targetSession =
                ServerManager.Instance.GetSessionByCharacterId(session.Character.ExchangeInfo.TargetCharacterId);

            if (session.Character.HasShopOpened || targetSession?.Character.HasShopOpened == true)
            {
                session.CloseExchange(targetSession);
                return;
            }

            int    i          = 0;
            string packetList = string.Empty;

            foreach (Item item in Items)
            {
                if (item.Type == InventoryType.Bazaar || item.Type == InventoryType.FamilyWareHouse)
                {
                    session.CloseExchange(targetSession);
                    return;
                }

                ItemInstance itemInstance = session.Character.Inventory.LoadBySlotAndType(item.Slot, item.Type);
                if (itemInstance == null)
                {
                    return;
                }

                if (item.Amount <= 0 || itemInstance.Amount < item.Amount)
                {
                    return;
                }
                ItemInstance it = itemInstance.DeepCopy();
                if (it.Item.IsTradable && (!it.IsBound || (it.Item.Type == InventoryType.Equipment &&
                                                           (it.Item.ItemType == ItemType.Armor || it.Item.ItemType == ItemType.Weapon))))
                {
                    it.Amount = item.Amount;
                    session.Character.ExchangeInfo.ExchangeList.Add(it);
                    if (item.Type != InventoryType.Equipment)
                    {
                        packetList += $"{i}.{(byte)item.Type}.{it.ItemVNum}.{item.Amount} ";
                    }
                    else
                    {
                        packetList += $"{i}.{(byte)item.Type}.{it.ItemVNum}.{it.Rare}.{it.Upgrade} ";
                    }
                }
                else if (it.IsBound && !(it.Item.Type == InventoryType.Equipment &&
                                         (it.Item.ItemType == ItemType.Armor || it.Item.ItemType == ItemType.Weapon)))

                {
                    session.SendPacket("exc_close 0");
                    session.CurrentMapInstance?.Broadcast(session, "exc_close 0", ReceiverType.OnlySomeone,
                                                          string.Empty, session.Character.ExchangeInfo.TargetCharacterId);

                    if (targetSession != null)
                    {
                        targetSession.Character.ExchangeInfo = null;
                    }

                    session.Character.ExchangeInfo = null;
                    return;
                }

                i++;
            }
            session.Character.ExchangeInfo.Gold     = Gold;
            session.Character.ExchangeInfo.GoldBank = GoldBank;
            session.CurrentMapInstance?.Broadcast(session,
                                                  $"exc_list 1 {session.Character.CharacterId} {Gold} {GoldBank} {packetList}", ReceiverType.OnlySomeone,
                                                  string.Empty, session.Character.ExchangeInfo.TargetCharacterId);
            session.Character.ExchangeInfo.Validated = true;
        }
Example #8
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");
            }
        }