コード例 #1
0
ファイル: NpcPacketHandler.cs プロジェクト: OpenNos/OpenNos
        public void CreateShop(string packet)
        {
            Logger.Debug(packet, Session.SessionId);
            string[] packetsplit = packet.Split(' ');
            InventoryType[] type = new InventoryType[20];
            long[] gold = new long[20];
            short[] slot = new short[20];
            byte[] qty = new byte[20];
            string shopname = String.Empty;
            if (packetsplit.Length > 2)
            {
                short typePacket;
                short.TryParse(packetsplit[2], out typePacket);
                if ((Session.Character.HasShopOpened && typePacket != 1) || !Session.HasCurrentMap)
                {
                    return;
                }
                foreach (PortalDTO por in Session.CurrentMap.Portals)
                {
                    if (Session.Character.MapX < por.SourceX + 6 && Session.Character.MapX > por.SourceX - 6 && Session.Character.MapY < por.SourceY + 6 && Session.Character.MapY > por.SourceY - 6)
                    {
                        Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("SHOP_NEAR_PORTAL"), 0));
                        return;
                    }
                }
                if (!Session.CurrentMap.ShopAllowed)
                {
                    Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("SHOP_NOT_ALLOWED"), 0));
                    return;
                }
                if (typePacket == 2)
                {
                    Session.SendPacket("ishop");
                }
                else if (typePacket == 0)
                {
                    if (Session.CurrentMap.UserShops.Count(s => s.Value.OwnerId == Session.Character.CharacterId) != 0)
                    {
                        return;
                    }
                    MapShop myShop = new MapShop();

                    if (packetsplit.Length > 82)
                    {
                        short shopSlot = 0;

                        for (short j = 3, i = 0; j < 82; j += 4, i++)
                        {
                            Enum.TryParse(packetsplit[j], out type[i]);
                            short.TryParse(packetsplit[j + 1], out slot[i]);
                            byte.TryParse(packetsplit[j + 2], out qty[i]);

                            long.TryParse(packetsplit[j + 3], out gold[i]);
                            if (gold[i] < 0)
                            {
                                return;
                            }
                            if (qty[i] > 0)
                            {
                                ItemInstance inv = Session.Character.Inventory.LoadBySlotAndType(slot[i], type[i]);
                                if (inv.Amount < qty[i])
                                {
                                    return;
                                }
                                if (!inv.Item.IsTradable || inv.IsBound)
                                {
                                    Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("SHOP_ONLY_TRADABLE_ITEMS"), 0));
                                    Session.SendPacket("shop_end 0");
                                    return;
                                }

                                PersonalShopItem personalshopitem = new PersonalShopItem()
                                {
                                    ShopSlot = shopSlot,
                                    Price = gold[i],
                                    ItemInstance = inv,
                                    SellAmount = qty[i]
                                };
                                myShop.Items.Add(personalshopitem);
                                shopSlot++;
                            }
                        }
                    }
                    if (myShop.Items.Count != 0)
                    {
                        if (!myShop.Items.Any(s => !s.ItemInstance.Item.IsSoldable || s.ItemInstance.IsBound))
                        {
                            for (int i = 83; i < packetsplit.Length; i++)
                            {
                                shopname += $"{packetsplit[i]} ";
                            }

                            // trim shopname
                            shopname = shopname.TrimEnd(' ');

                            // create default shopname if it's empty
                            if (string.IsNullOrWhiteSpace(shopname) || string.IsNullOrEmpty(shopname))
                            {
                                shopname = Language.Instance.GetMessageFromKey("SHOP_PRIVATE_SHOP");
                            }

                            // truncate the string to a max-length of 20
                            shopname = StringHelper.Truncate(shopname, 20);
                            myShop.OwnerId = Session.Character.CharacterId;
                            myShop.Name = shopname;
                            Session.CurrentMap.UserShops.Add(Session.CurrentMap.LastUserShopId++, myShop);

                            Session.Character.HasShopOpened = true;

                            Session.CurrentMap?.Broadcast(Session, Session.Character.GeneratePlayerFlag(Session.CurrentMap.LastUserShopId), ReceiverType.AllExceptMe);
                            Session.CurrentMap?.Broadcast(Session.Character.GenerateShop(shopname));
                            Session.SendPacket(Session.Character.GenerateInfo(Language.Instance.GetMessageFromKey("SHOP_OPEN")));

                            Session.Character.IsSitting = true;
                            Session.Character.IsShopping = true;

                            Session.Character.LoadSpeed();
                            Session.SendPacket(Session.Character.GenerateCond());
                            Session.CurrentMap?.Broadcast(Session.Character.GenerateRest());
                        }
                        else
                        {
                            Session.SendPacket("shop_end 0");
                            Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("ITEM_NOT_SOLDABLE"), 10));
                        }
                    }
                    else
                    {
                        Session.SendPacket("shop_end 0");
                        Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("SHOP_EMPTY"), 10));
                    }
                }
                else if (typePacket == 1)
                {
                    Session.Character.CloseShop(true);
                }
            }
        }
コード例 #2
0
ファイル: WorldPacketHandler.cs プロジェクト: 0xNear/OpenNos
        public void createShop(string packet)
        {
            string[] packetsplit = packet.Split(' ');
            short[] type = new short[20];
            long[] gold = new long[20];
            short[] slot = new short[20];
            short[] qty = new short[20];

            string shopname = "";
            if (packetsplit.Length > 2)
            {
                short typePacket; short.TryParse(packetsplit[2], out typePacket);
                if (typePacket == 2)
                {
                    Session.Client.SendPacket("ishop");
                }
                else if (typePacket == 0)
                {
                    MapShop myShop = new MapShop();
                    if (packetsplit.Length > 2)
                        for (short j = 3, i = 0; j <= packetsplit.Length - 5; j += 4, i++)
                        {
                            short.TryParse(packetsplit[j], out type[i]);
                            short.TryParse(packetsplit[j + 1], out slot[i]);
                            short.TryParse(packetsplit[j + 2], out qty[i]);
                            long.TryParse(packetsplit[j + 3], out gold[i]);
                            if (qty[i] != 0)
                            {
                                Inventory inv = Session.Character.InventoryList.LoadBySlotAndType(slot[i], type[i]);
                                PersonalShopItem personalshopitem = new PersonalShopItem()
                                {
                                    InvSlot = slot[i],
                                    InvType = type[i],
                                    Amount = qty[i],
                                    Price = gold[i],
                                    Slot = i,
                                    Color = inv.InventoryItem.Color,
                                    Concentrate = inv.InventoryItem.Concentrate,
                                    CriticalLuckRate = inv.InventoryItem.CriticalLuckRate,
                                    CriticalRate = inv.InventoryItem.CriticalRate,
                                    DamageMaximum = inv.InventoryItem.DamageMaximum,
                                    DamageMinimum = inv.InventoryItem.DamageMinimum,
                                    DarkElement = inv.InventoryItem.DarkElement,
                                    DistanceDefence = inv.InventoryItem.DistanceDefence,
                                    DistanceDefenceDodge = inv.InventoryItem.DistanceDefenceDodge,
                                   DefenceDodge = inv.InventoryItem.DefenceDodge,
                                    ElementRate = inv.InventoryItem.ElementRate,
                                    FireElement = inv.InventoryItem.FireElement,
                                    HitRate = inv.InventoryItem.HitRate,
                                    InventoryItemId = inv.InventoryItemId,
                                    ItemVNum = inv.InventoryItem.ItemVNum,
                                    LightElement = inv.InventoryItem.LightElement,
                                    MagicDefence = inv.InventoryItem.MagicDefence,
                                    RangeDefence = inv.InventoryItem.RangeDefence,
                                    Rare = inv.InventoryItem.Rare,
                                    SpXp = inv.InventoryItem.SpXp,
                                    SpLevel = inv.InventoryItem.SpLevel,
                                    SlDefence = inv.InventoryItem.SlDefence,
                                    SlElement = inv.InventoryItem.SlElement,
                                    SlHit = inv.InventoryItem.SlHit,
                                    SlHP = inv.InventoryItem.SlHP,
                                    Upgrade = inv.InventoryItem.Upgrade,
                                    WaterElement = inv.InventoryItem.WaterElement
                                };
                                myShop.Items.Add(personalshopitem);
                            }


                        }

                    for (int i = 83; i < packetsplit.Length; i++)
                        shopname += String.Format("{0} ", packetsplit[i]);
                    shopname.TrimEnd(' ');
                    myShop.OwnerId = Session.Character.CharacterId;
                    myShop.Name = shopname;
                    Session.CurrentMap.ShopUserList.Add(Session.CurrentMap.ShopUserList.Count(), myShop);

                    ClientLinkManager.Instance.Broadcast(Session, Session.Character.GeneratePlayerFlag(Session.CurrentMap.ShopUserList.Count()), ReceiverType.AllOnMapExceptMe);

                    ClientLinkManager.Instance.Broadcast(Session, Session.Character.GenerateShop(shopname), ReceiverType.AllOnMap);

                    Session.Client.SendPacket(Session.Character.GenerateInfo(Language.Instance.GetMessageFromKey("SHOP_OPEN")));
                    Session.Character.Rested = 1;
                    Session.Character.LastSpeed = Session.Character.Speed;
                    Session.Character.Speed = 0;
                    Session.Client.SendPacket(Session.Character.GenerateCond());

                    ClientLinkManager.Instance.Broadcast(Session, Session.Character.GenerateRest(), ReceiverType.AllOnMap);


                }
                else if (typePacket == 1)
                {

                    KeyValuePair<long, MapShop> shop = Session.CurrentMap.ShopUserList.FirstOrDefault(mapshop => mapshop.Value.OwnerId.Equals(Session.Character.CharacterId));
                    Session.CurrentMap.ShopUserList.Remove(shop.Key);

                    ClientLinkManager.Instance.Broadcast(Session, Session.Character.GenerateShopEnd(), ReceiverType.AllOnMap);
                    ClientLinkManager.Instance.Broadcast(Session, Session.Character.GeneratePlayerFlag(0), ReceiverType.AllOnMapExceptMe);
                    Session.Character.Speed = Session.Character.LastSpeed;
                    Session.Character.Rested = 0;
                    Session.Client.SendPacket(Session.Character.GenerateCond());
                    ClientLinkManager.Instance.Broadcast(Session, Session.Character.GenerateRest(), ReceiverType.AllOnMap);



                }
            }

        }