Пример #1
0
        /// <summary>
        /// Loads all the items this user currently has in her/hand and stores them in the item collection.
        /// </summary>
        public void loadHandItems()
        {
            this.handItems.Clear();

            Database dbClient = new Database(false, true);

            dbClient.addParameterWithValue("userid", this.userID);

            dbClient.Open();
            if (dbClient.Ready)
            {
                foreach (DataRow dItem in dbClient.getTable("SELECT id,definitionid,customdata,teleporterid FROM items WHERE ownerid = @userid AND roomid = '0' ORDER BY id ASC").Rows)
                {
                    stripItem pItem = new stripItem();
                    pItem.ID         = (int)dItem["id"];
                    pItem.ownerID    = this.userID;
                    pItem.Definition = Engine.Game.Items.getItemDefinition((int)dItem["definitionid"]);
                    if (dItem["customdata"] != DBNull.Value)
                    {
                        pItem.customData = (string)dItem["customdata"];
                    }
                    else
                    {
                        pItem.customData = null;
                    }
                    if (pItem.Definition.Behaviour.isTeleporter)
                    {
                        pItem.teleporterID = (int)dItem["teleporterid"];
                    }

                    this.handItems.Add(pItem);
                }
            }
        }
Пример #2
0
        public stripItem createItemFromDefinition(itemDefinition pDefinition, int specialSpriteID)
        {
            stripItem pItem = new stripItem();

            pItem.Definition = pDefinition;
            if (specialSpriteID > 0)
            {
                pItem.customData = specialSpriteID.ToString();
            }

            return(pItem);
        }
Пример #3
0
        /// <summary>
        /// Returns a string with all the offered trade items represented as a string.
        /// </summary>
        public string getTradeOfferItems()
        {
            fuseStringBuilder FSB = new fuseStringBuilder();

            if (this.isTrading)
            {
                for (int slotID = 0; slotID < this.tradeOfferItemIDs.Count; slotID++)
                {
                    stripItem pItem = this.getHandItem(this.tradeOfferItemIDs[slotID]);
                    if (pItem != null)
                    {
                        FSB.Append(pItem.ToStripString(slotID));
                    }
                }
            }
            return(FSB.ToString());
        }
Пример #4
0
        public stripItem createItemInstance(int definitionID, int ownerID, string customData)
        {
            int newID = this.createItemInstanceReturnID(definitionID, ownerID, customData);

            if (newID > 0)
            {
                stripItem ret = new stripItem();
                ret.ID         = newID;
                ret.Definition = this.getItemDefinition(definitionID);
                ret.ownerID    = ownerID;
                ret.customData = customData;

                return(ret);
            }
            else
            {
                return(null);
            }
        }
Пример #5
0
        /// <summary>
        /// Swaps the trade offer items of two trade partners and updates the database, hand item collection etc. The swap is aborted if the trade is invalid.
        /// </summary>
        /// <param name="partnerItemStrip">The itemStripHandler object of the trade partner session.</param>
        public void swapTradeOffers(itemStripHandler partnerItemStrip)
        {
            if (this.isTrading && partnerItemStrip.isTrading && (this.tradeOfferItemCount > 0 || partnerItemStrip.tradeOfferItemCount > 0)) // Can swap items
            {
                Database dbClient = new Database(true, false);
                if (!dbClient.Ready)
                {
                    return;
                }

                foreach (int myTradeOfferItemID in this.tradeOfferItemIDs)
                {
                    stripItem lItem = this.getHandItem(myTradeOfferItemID);
                    if (lItem == null)
                    {
                        return;                                                                                                              // Trade invalid
                    }
                    this.removeHandItem(myTradeOfferItemID, false);                                                                          // Remove from this item strip
                    partnerItemStrip.addHandItem(lItem);                                                                                     // Add to partner item strip
                    dbClient.runQuery("UPDATE items SET ownerid = '" + partnerItemStrip.userID + "' WHERE id = '" + lItem.ID + "' LIMIT 1"); // Update database
                }

                foreach (int partnerTradeOfferItemID in partnerItemStrip.tradeOfferItemIDs)
                {
                    stripItem lItem = partnerItemStrip.getHandItem(partnerTradeOfferItemID);
                    if (lItem == null)
                    {
                        return;                                                                                                  // Trade invalid
                    }
                    partnerItemStrip.removeHandItem(partnerTradeOfferItemID, false);                                             // Remove from partner item strip
                    this.addHandItem(lItem);                                                                                     // Add to this item strip
                    dbClient.runQuery("UPDATE items SET ownerid = '" + this.userID + "' WHERE id = '" + lItem.ID + "' LIMIT 1"); // Update database
                }

                dbClient.Close(); // Close database connection
            }
        }
Пример #6
0
 /// <summary>
 /// Adds a given strip item to the hand item collection.
 /// </summary>
 /// <param name="Item">The strip item to add.</param>
 public void addHandItem(stripItem Item)
 {
     this.handItems.Add(Item);
 }
Пример #7
0
        /// <summary>
        /// Loads all the items this user currently has in her/hand and stores them in the item collection.
        /// </summary>
        public void loadHandItems()
        {
            this.handItems.Clear();

            Database dbClient = new Database(false, true);
            dbClient.addParameterWithValue("userid", this.userID);

            dbClient.Open();
            if (dbClient.Ready)
            {
                foreach (DataRow dItem in dbClient.getTable("SELECT id,definitionid,customdata,teleporterid FROM items WHERE ownerid = @userid AND roomid = '0' ORDER BY id ASC").Rows)
                {
                    stripItem pItem = new stripItem();
                    pItem.ID = (int)dItem["id"];
                    pItem.ownerID = this.userID;
                    pItem.Definition = ObjectTree.Game.Items.getItemDefinition((int)dItem["definitionid"]);
                    if (dItem["customdata"] != DBNull.Value)
                        pItem.customData = (string)dItem["customdata"];
                    else
                        pItem.customData = null;
                    if (pItem.Definition.Behaviour.isTeleporter)
                        pItem.teleporterID = (int)dItem["teleporterid"];

                    this.handItems.Add(pItem);
                }
            }
        }
Пример #8
0
 /// <summary>
 /// Adds a given strip item to the hand item collection.
 /// </summary>
 /// <param name="Item">The strip item to add.</param>
 public void addHandItem(stripItem Item)
 {
     this.handItems.Add(Item);
 }
Пример #9
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);
            }
        }