Beispiel #1
0
 public static void SendCloseCharacterTradeShopToOwnerResponse(IRealmClient client,
                                                               Asda2PrivateShopClosedToOwnerResult status)
 {
     using (RealmPacketOut shopToOwnerResponse =
                Asda2PrivateShopHandler.CreateCloseCharacterTradeShopToOwnerResponse(status))
         client.Send(shopToOwnerResponse, false);
 }
Beispiel #2
0
 public static void CloseCharacterTradeShopRequest(IRealmClient client, RealmPacketIn packet)
 {
     if (client.ActiveCharacter.PrivateShop == null)
     {
         Asda2PrivateShopHandler.SendCloseCharacterTradeShopToOwnerResponse(client,
                                                                            Asda2PrivateShopClosedToOwnerResult.Ok);
     }
     else
     {
         client.ActiveCharacter.PrivateShop.Exit(client.ActiveCharacter);
     }
 }
Beispiel #3
0
 public void ShowOnLogin(Character character)
 {
     if (character == Owner)
     {
         Asda2PrivateShopHandler.SendPrivateShopOpenedResponse(Owner.Client, PrivateShopOpenedResult.Ok,
                                                               ItemsOnTrade);
     }
     else
     {
         Asda2PrivateShopHandler.SendCharacterPrivateShopInfoResponse(character.Client,
                                                                      Asda2ViewTradeShopInfoStatus.Ok, this);
     }
 }
Beispiel #4
0
 public PrivateShopOpenedResult StartTrade(List <Asda2ItemTradeRef> itemsToTrade, string title)
 {
     Owner.Asda2TradeDescription = title;
     for (int index = 0; index < ItemsOnTrade.Length; ++index)
     {
         ItemsOnTrade[index] = itemsToTrade.Count <= index ? null : itemsToTrade[index];
     }
     Asda2PrivateShopHandler.SendPrivateShopOpenedResponse(Owner.Client, PrivateShopOpenedResult.Ok,
                                                           ItemsOnTrade);
     Owner.IsSitting = true;
     Owner.IsAsda2TradeDescriptionEnabled = true;
     Trading = true;
     return(PrivateShopOpenedResult.Ok);
 }
Beispiel #5
0
        public void Exit(Character activeCharacter)
        {
            if (activeCharacter == Owner)
            {
                using (RealmPacketOut shopToOwnerResponse =
                           Asda2PrivateShopHandler.CreateCloseCharacterTradeShopToOwnerResponse(
                               Asda2PrivateShopClosedToOwnerResult.HostClosedShop))
                {
                    foreach (Character joinedCharacter in JoinedCharacters)
                    {
                        joinedCharacter.Send(shopToOwnerResponse, false);
                        joinedCharacter.PrivateShop = null;
                        --joinedCharacter.Stunned;
                    }
                }

                JoinedCharacters.Clear();
                _joinedCharacters           = null;
                _itemsOnTrade               = null;
                activeCharacter.PrivateShop = null;
                activeCharacter.IsAsda2TradeDescriptionEnabled = false;
                activeCharacter.Asda2TradeDescription          = "";
                Asda2PrivateShopHandler.SendCloseCharacterTradeShopToOwnerResponse(activeCharacter.Client,
                                                                                   Asda2PrivateShopClosedToOwnerResult.Ok);
            }
            else
            {
                JoinedCharacters.Remove(activeCharacter);
                List <Character> characterList = new List <Character>
                {
                    Owner
                };
                characterList.AddRange(JoinedCharacters);
                using (RealmPacketOut notificationResponse =
                           Asda2PrivateShopHandler.CreatePrivateShopChatNotificationResponse(activeCharacter.AccId,
                                                                                             Asda2PrivateShopNotificationType.Left))
                {
                    foreach (Character character in characterList)
                    {
                        character.Send(notificationResponse, false);
                    }
                }

                --activeCharacter.Stunned;
                activeCharacter.PrivateShop = null;
                Asda2PrivateShopHandler.SendCloseCharacterTradeShopToOwnerResponse(activeCharacter.Client,
                                                                                   Asda2PrivateShopClosedToOwnerResult.Ok);
            }
        }
Beispiel #6
0
        public void SendMessage(string msg, Character activeCharacter, Locale locale)
        {
            List <Character> characterList = new List <Character>
            {
                Owner
            };

            characterList.AddRange(JoinedCharacters);
            using (RealmPacketOut shopChatResResponse =
                       Asda2PrivateShopHandler.CreatePrivateShopChatResResponse(activeCharacter, msg, locale))
            {
                foreach (Character character in characterList)
                {
                    if (locale == Locale.Any || character.Client.Locale == locale)
                    {
                        character.Send(shopChatResResponse, false);
                    }
                }
            }
        }
Beispiel #7
0
        public static void ViewCharacterTradeShopRequest(IRealmClient client, RealmPacketIn packet)
        {
            RealmAccount loggedInAccount =
                ServerApp <WCell.RealmServer.RealmServer> .Instance.GetLoggedInAccount(packet.ReadUInt32());

            if (loggedInAccount == null || loggedInAccount.ActiveCharacter == null)
            {
                Asda2PrivateShopHandler.SendCharacterPrivateShopInfoResponse(client,
                                                                             Asda2ViewTradeShopInfoStatus.TheCapacityHasExided, (Asda2PrivateShop)null);
            }
            else
            {
                Character activeCharacter = loggedInAccount.ActiveCharacter;
                if (activeCharacter.PrivateShop == null || !activeCharacter.PrivateShop.Trading)
                {
                    return;
                }
                activeCharacter.PrivateShop.Join(client.ActiveCharacter);
            }
        }
Beispiel #8
0
 public static void OpenPrivateShopWindowRequest(IRealmClient client, RealmPacketIn packet)
 {
     if (client.ActiveCharacter.IsAsda2BattlegroundInProgress)
     {
         client.ActiveCharacter.SendInfoMsg("You can't trade on war.");
         Asda2PrivateShopHandler.SendPrivateShopWindoOpenedResponse(client, PrivateShopWindowOpenedResult.Fail);
     }
     else if (client.ActiveCharacter.Asda2TradeWindow != null)
     {
         client.ActiveCharacter.YouAreFuckingCheater("Is trying to open private shop window while trading.", 1);
         Asda2PrivateShopHandler.SendPrivateShopWindoOpenedResponse(client, PrivateShopWindowOpenedResult.Fail);
     }
     else if (client.ActiveCharacter.PrivateShop == null)
     {
         client.ActiveCharacter.PrivateShop = new Asda2PrivateShop(client.ActiveCharacter);
         Asda2PrivateShopHandler.SendPrivateShopWindoOpenedResponse(client, PrivateShopWindowOpenedResult.Ok);
     }
     else
     {
         Asda2PrivateShopHandler.SendPrivateShopWindoOpenedResponse(client,
                                                                    PrivateShopWindowOpenedResult.YouAreInYourShop);
     }
 }
Beispiel #9
0
        public void Join(Character activeCharacter)
        {
            List <Character> characterList = new List <Character>
            {
                Owner
            };

            characterList.AddRange(JoinedCharacters);
            using (RealmPacketOut notificationResponse =
                       Asda2PrivateShopHandler.CreatePrivateShopChatNotificationResponse(activeCharacter.AccId,
                                                                                         Asda2PrivateShopNotificationType.Joined))
            {
                foreach (Character character in characterList)
                {
                    character.Send(notificationResponse, false);
                }
            }

            ++activeCharacter.Stunned;
            JoinedCharacters.Add(activeCharacter);
            Asda2PrivateShopHandler.SendCharacterPrivateShopInfoResponse(activeCharacter.Client,
                                                                         Asda2ViewTradeShopInfoStatus.Ok, this);
            activeCharacter.PrivateShop = this;
        }
Beispiel #10
0
        public void BuyItems(Character activeCharacter, List <Asda2ItemTradeRef> itemsToBuyRefs)
        {
            Owner.Map.AddMessage(() =>
            {
                List <Asda2ItemTradeRef> source = new List <Asda2ItemTradeRef>();
                foreach (Asda2ItemTradeRef itemsToBuyRef in itemsToBuyRefs)
                {
                    Asda2ItemTradeRef asda2ItemTradeRef = ItemsOnTrade[itemsToBuyRef.TradeSlot];
                    if (asda2ItemTradeRef == null || asda2ItemTradeRef.Amount == -1 || asda2ItemTradeRef.Amount != 0 &&
                        asda2ItemTradeRef.Amount < itemsToBuyRef.Amount)
                    {
                        Asda2PrivateShopHandler.SendItemBuyedFromPrivateShopResponse(activeCharacter,
                                                                                     PrivateShopBuyResult.RequestedNumberOfItemsIsNoLongerAvaliable, null);
                        return;
                    }

                    source.Add(new Asda2ItemTradeRef
                    {
                        Amount    = itemsToBuyRef.Amount,
                        Item      = asda2ItemTradeRef.Item,
                        Price     = asda2ItemTradeRef.Price,
                        TradeSlot = asda2ItemTradeRef.TradeSlot
                    });
                }

                ulong num1 = source.Aggregate(0UL,
                                              (current, asda2ItemTradeRef) =>
                                              current + (ulong)(asda2ItemTradeRef.Price * asda2ItemTradeRef.Amount));
                if (num1 > int.MaxValue)
                {
                    activeCharacter.YouAreFuckingCheater("Trying to buy items with wrong money amount.", 50);
                    Asda2PrivateShopHandler.SendItemBuyedFromPrivateShopResponse(activeCharacter,
                                                                                 PrivateShopBuyResult.NotEnoghtGold, null);
                }
                else if (activeCharacter.Money < num1)
                {
                    Asda2PrivateShopHandler.SendItemBuyedFromPrivateShopResponse(activeCharacter,
                                                                                 PrivateShopBuyResult.NotEnoghtGold, null);
                }
                else if (Owner.Money + num1 > int.MaxValue)
                {
                    Asda2PrivateShopHandler.SendItemBuyedFromPrivateShopResponse(activeCharacter,
                                                                                 PrivateShopBuyResult.Error, null);
                    SendMessage(Owner.Name + " has to much gold.", Owner, Locale.Start);
                }
                else if (source.Any(asda2ItemTradeRef =>
                {
                    if (asda2ItemTradeRef.Item == null || asda2ItemTradeRef.Item.IsDeleted)
                    {
                        return(true);
                    }
                    if (asda2ItemTradeRef.Item.Amount != 0)
                    {
                        return(asda2ItemTradeRef.Item.Amount < asda2ItemTradeRef.Amount);
                    }
                    return(false);
                }))
                {
                    Owner.YouAreFuckingCheater("Trying to cheat while trading items from private shop", 10);
                    Exit(Owner);
                }
                else if (activeCharacter.Asda2Inventory.FreeRegularSlotsCount <
                         source.Count(i =>
                                      i.Item.InventoryType == Asda2InventoryType.Regular) ||
                         activeCharacter.Asda2Inventory.FreeShopSlotsCount < source.Count(
                             i => i.Item.InventoryType == Asda2InventoryType.Shop))
                {
                    Asda2PrivateShopHandler.SendItemBuyedFromPrivateShopResponse(activeCharacter,
                                                                                 PrivateShopBuyResult.NoSlotAreAvailable, null);
                }
                else
                {
                    activeCharacter.SubtractMoney((uint)num1);
                    Owner.AddMoney((uint)num1);
                    List <Asda2Item> buyedItems         = new List <Asda2Item>();
                    List <Asda2ItemTradeRef> itemsBuyed = new List <Asda2ItemTradeRef>();
                    foreach (Asda2ItemTradeRef asda2ItemTradeRef1 in source)
                    {
                        if (asda2ItemTradeRef1.Amount == 0)
                        {
                            asda2ItemTradeRef1.Amount = 1;
                        }
                        if (asda2ItemTradeRef1.Amount >= asda2ItemTradeRef1.Item.Amount)
                        {
                            LogHelperEntry lgDelete = Log
                                                      .Create(Log.Types.ItemOperations, LogSourceType.Character, Owner.EntryId)
                                                      .AddAttribute("source", 0.0, "selled_from_private_shop")
                                                      .AddItemAttributes(asda2ItemTradeRef1.Item, "")
                                                      .AddAttribute("buyer_id", activeCharacter.EntryId, "")
                                                      .AddAttribute("amount", asda2ItemTradeRef1.Amount, "").Write();
                            Asda2Item itemToCopyStats = asda2ItemTradeRef1.Item;
                            Asda2Item asda2Item       = null;
                            int num2 = (int)activeCharacter.Asda2Inventory.TryAdd(itemToCopyStats.ItemId,
                                                                                  itemToCopyStats.Amount, true, ref asda2Item, new Asda2InventoryType?(),
                                                                                  itemToCopyStats);
                            Log.Create(Log.Types.ItemOperations, LogSourceType.Character, activeCharacter.EntryId)
                            .AddAttribute("source", 0.0, "buyed_from_private_shop").AddItemAttributes(asda2Item, "")
                            .AddAttribute("seller_id", Owner.EntryId, "").AddReference(lgDelete)
                            .AddAttribute("amount", asda2ItemTradeRef1.Amount, "").Write();
                            buyedItems.Add(asda2Item);
                            itemToCopyStats.Destroy();
                            ItemsOnTrade[asda2ItemTradeRef1.TradeSlot].Amount = -1;
                            ItemsOnTrade[asda2ItemTradeRef1.TradeSlot].Price  = 0;
                        }
                        else
                        {
                            LogHelperEntry lgDelete = Log
                                                      .Create(Log.Types.ItemOperations, LogSourceType.Character, Owner.EntryId)
                                                      .AddAttribute("source", 0.0, "selled_from_private_shop_split")
                                                      .AddItemAttributes(asda2ItemTradeRef1.Item, "")
                                                      .AddAttribute("buyer_id", activeCharacter.EntryId, "")
                                                      .AddAttribute("amount", asda2ItemTradeRef1.Amount, "").Write();
                            asda2ItemTradeRef1.Item.Amount -= asda2ItemTradeRef1.Amount;
                            Asda2Item asda2Item             = null;
                            int num2 = (int)activeCharacter.Asda2Inventory.TryAdd(
                                (int)asda2ItemTradeRef1.Item.Template.ItemId, asda2ItemTradeRef1.Amount, true,
                                ref asda2Item, new Asda2InventoryType?(), asda2ItemTradeRef1.Item);
                            Log.Create(Log.Types.ItemOperations, LogSourceType.Character, activeCharacter.EntryId)
                            .AddAttribute("source", 0.0, "buyed_from_private_shop_split")
                            .AddItemAttributes(asda2Item, "new_item")
                            .AddItemAttributes(asda2ItemTradeRef1.Item, "old_item")
                            .AddAttribute("amount", asda2ItemTradeRef1.Amount, "")
                            .AddAttribute("seller_id", Owner.EntryId, "").AddReference(lgDelete)
                            .Write();
                            asda2ItemTradeRef1.Item.Save();
                            buyedItems.Add(asda2Item);
                        }

                        Asda2ItemTradeRef asda2ItemTradeRef2 = ItemsOnTrade[asda2ItemTradeRef1.TradeSlot];
                        itemsBuyed.Add(asda2ItemTradeRef2);
                        if (asda2ItemTradeRef2 != null && asda2ItemTradeRef2.Amount > 0)
                        {
                            asda2ItemTradeRef2.Amount -= asda2ItemTradeRef1.Amount;
                            if (asda2ItemTradeRef2.Amount <= 0)
                            {
                                asda2ItemTradeRef2.Amount = -1;
                            }
                        }
                    }

                    Asda2PrivateShopHandler.SendItemBuyedFromPrivateShopResponse(activeCharacter,
                                                                                 PrivateShopBuyResult.Ok, buyedItems);
                    Asda2PrivateShopHandler.SendItemBuyedFromPrivateShopToOwnerNotifyResponse(this, itemsBuyed,
                                                                                              activeCharacter);
                    Asda2PrivateShopHandler.SendPrivateShopChatNotificationAboutBuyResponse(this, itemsBuyed,
                                                                                            activeCharacter);
                    Owner.SendMoneyUpdate();
                    activeCharacter.SendMoneyUpdate();
                }
            });
        }
Beispiel #11
0
        public static void OpenPrivateShopRequest(IRealmClient client, RealmPacketIn packet)
        {
            if (client.ActiveCharacter.PrivateShop == null)
            {
                Asda2PrivateShopHandler.SendPrivateShopOpenedResponse(client, PrivateShopOpenedResult.Error,
                                                                      (Asda2ItemTradeRef[])null);
                client.ActiveCharacter.YouAreFuckingCheater("Trying to open not existing private shop", 2);
            }
            else
            {
                ++packet.Position;
                List <Asda2ItemTradeRef> asda2ItemTradeRefList = new List <Asda2ItemTradeRef>();
                for (int index = 0; index < 10; ++index)
                {
                    bool flag = false;
                    if (packet.ReadInt32() == 0)
                    {
                        flag = true;
                    }
                    Asda2InventoryType asda2InventoryType = (Asda2InventoryType)packet.ReadByte();
                    short num1 = packet.ReadInt16();
                    short num2 = packet.ReadInt16();
                    packet.Position += 4;
                    if (num1 < (short)0 || (int)num1 >= client.ActiveCharacter.Asda2Inventory.ShopItems.Length ||
                        num2 < (short)0)
                    {
                        flag = true;
                    }
                    int num3 = packet.ReadInt32();
                    if (!flag)
                    {
                        Asda2Item asda2Item = asda2InventoryType == Asda2InventoryType.Regular
                            ? client.ActiveCharacter.Asda2Inventory.RegularItems[(int)num1]
                            : client.ActiveCharacter.Asda2Inventory.ShopItems[(int)num1];
                        if (asda2Item == null)
                        {
                            Asda2PrivateShopHandler.SendPrivateShopOpenedResponse(client,
                                                                                  PrivateShopOpenedResult.ThereIsNoItemInfo, (Asda2ItemTradeRef[])null);
                            return;
                        }

                        if (asda2Item.Amount < (int)num2)
                        {
                            num2 = (short)asda2Item.Amount;
                        }
                        foreach (Asda2ItemTradeRef asda2ItemTradeRef in asda2ItemTradeRefList)
                        {
                            if (asda2ItemTradeRef.Item.InventoryType == asda2Item.InventoryType &&
                                (int)asda2ItemTradeRef.Item.Slot == (int)asda2Item.Slot)
                            {
                                flag = true;
                                break;
                            }
                        }

                        if (!flag)
                        {
                            asda2ItemTradeRefList.Add(new Asda2ItemTradeRef()
                            {
                                Item      = asda2Item,
                                Amount    = (int)num2,
                                Price     = num3,
                                TradeSlot = (byte)asda2ItemTradeRefList.Count <Asda2ItemTradeRef>()
                            });
                        }
                    }

                    packet.Position += 28;
                }

                string str = packet.ReadAsdaString(50, Locale.Start);
                if (!Asda2EncodingHelper.IsPrueEnglish(str))
                {
                    client.ActiveCharacter.SendOnlyEnglishCharactersAllowed("Shop title");
                    Asda2PrivateShopHandler.SendPrivateShopOpenedResponse(client, PrivateShopOpenedResult.Error,
                                                                          (Asda2ItemTradeRef[])null);
                }
                else
                {
                    int num = (int)client.ActiveCharacter.PrivateShop.StartTrade(asda2ItemTradeRefList, str);
                }
            }
        }