예제 #1
0
        public void requestSaleShipping(int receivingUserID, string saleCode, bool isNewPurchase, bool purchaseAsPresent, string presentNote, string customData)
        {
            storeCatalogueSale pSale = this.getSale(saleCode);

            if (pSale == null)
            {
                Logging.Log("Failed to purchase sale '" + saleCode + "' for user " + receivingUserID + ", the requested sale ('" + saleCode + "') was not found!", Logging.logType.commonWarning);
                return;
            }

            List <stripItem> shippedItems = new List <stripItem>();

            if (purchaseAsPresent)
            {
                stripItem presentBox = this.createPresent(receivingUserID, saleCode, presentNote, customData);
                if (presentBox != null)
                {
                    shippedItems.Add(presentBox);
                }
                else
                {
                    return;
                }
            }
            else
            {
                int itemIdOffset = ObjectTree.Game.Items.getItemIdOffset();
                foreach (stripItem lItem in pSale.getItemInstances())
                {
                    lItem.ID      = ++itemIdOffset;
                    lItem.ownerID = receivingUserID;

                    #region Special events upon purchase
                    if (lItem.Definition.Behaviour.isTeleporter) // Teleporter, create linking teleporter
                    {
                        stripItem Teleporter2 = new stripItem();
                        Teleporter2.ID           = ++itemIdOffset;
                        Teleporter2.ownerID      = receivingUserID;
                        Teleporter2.Definition   = lItem.Definition;
                        Teleporter2.teleporterID = lItem.ID;
                        lItem.teleporterID       = Teleporter2.ID;

                        shippedItems.Add(Teleporter2);
                    }
                    else if (lItem.Definition.Behaviour.isPostIt)
                    {
                        lItem.customData = "20";
                    }
                    else if (lItem.Definition.Behaviour.isDecoration || lItem.Definition.Behaviour.isPrizeTrophy)
                    {
                        lItem.customData = customData;
                    }
                    else if (lItem.Definition.Behaviour.isRedeemable)
                    {
                        int creditValue = 0;
                        if (int.TryParse(lItem.Definition.Sprite.Split('_')[1], out creditValue))
                        {
                            lItem.customData = creditValue.ToString();
                        }
                    }
                    else if (lItem.Definition.Sprite == "nest")
                    {
                        string[] petData = customData.Split(Convert.ToChar(2));
                        string   Name    = petData[0];
                        char     Type    = char.Parse(petData[1]);
                        byte     Race    = byte.Parse(petData[2]);
                        string   Color   = petData[3];

                        ObjectTree.Game.Items.createPet(lItem.ID, Name, Type, Race, Color);
                    }
                    #endregion

                    shippedItems.Add(lItem);
                }

                ObjectTree.Game.Items.createItemInstances(shippedItems);
            }

            Session Receiver = ObjectTree.Game.Users.getUserSession(receivingUserID);
            if (Receiver != null) // Receiver was online
            {
                Receiver.itemStripHandler.addHandItems(shippedItems);

                serverMessage Notification = new serverMessage();
                if (isNewPurchase)
                {
                    Notification.Initialize(67); // "AC"
                }
                else
                #region Open as present box
                {
                    stripItem displayItem = shippedItems[0];

                    Notification.Initialize(129); // "BA"
                    Notification.appendNewLineValue(displayItem.Definition.Sprite);

                    string displaySprite = displayItem.Definition.Sprite;
                    //if (displayItem.Definition.isPartialSprite && displayItem.customData != null)
                    //    displaySprite += " " + displayItem.customData;
                    Notification.appendNewLineValue(displaySprite);

                    if (!displayItem.Definition.Behaviour.isWallItem)
                    {
                        Notification.appendStripValue(displayItem.Definition.Length.ToString());
                        Notification.appendStripValue(displayItem.Definition.Width.ToString());
                        Notification.appendStripValue(displayItem.Definition.Color);
                    }
                }
                #endregion
                Receiver.gameConnection.sendMessage(Notification);
            }
        }