Exemplo n.º 1
0
        public bool GiveItem(string item)
        {
            var itemID = DBFunctions.GetItemID(item);

            if (itemID == 0)
            {
                return(false);
            }
            var hasItem = HasItem(item);

            using (var con = new SQLiteConnection(Constants.Values.DB_CONNECTION_STRING))
            {
                con.Open();

                string stm = "";
                if (!hasItem)
                {
                    stm = "INSERT INTO USER_ITEMS(USER_ID, ITEM_ID, COUNT) VALUES(@userid, @itemid, 1)";
                }
                else
                {
                    stm = "UPDATE USER_ITEMS SET COUNT = COUNT + 1 WHERE ITEM_ID = @itemid AND USER_ID = @userid";
                }

                using (var com = new SQLiteCommand(stm, con))
                {
                    com.Parameters.AddWithValue("@userid", ID);
                    com.Parameters.AddWithValue("@itemid", itemID);
                    com.ExecuteNonQuery();
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        public void RemoveItem(string item)
        {
            var itemID  = DBFunctions.GetItemID(item);
            var hasItem = DBFunctions.UserHasItem(this, itemID);

            if (!hasItem)
            {
                return;
            }

            using (var con = new SQLiteConnection(Constants.Values.DB_CONNECTION_STRING))
            {
                con.Open();


                var stm = "UPDATE USER_ITEMS SET COUNT = COUNT - 1 WHERE ITEM_ID = @itemid AND USER_ID = @userid";
                using (var com = new SQLiteCommand(stm, con))
                {
                    com.Parameters.AddWithValue("@itemid", itemID);
                    com.Parameters.AddWithValue("@userid", ID);
                    com.ExecuteNonQuery();
                }

                var count = DBFunctions.UserItemCount(this, itemID);
                if (count <= 0)
                {
                    stm = "DELETE FROM USER_ITEMS WHERE ITEM_ID = @itemid AND USER_ID = @userid";
                    using (var com = new SQLiteCommand(stm, con))
                    {
                        com.Parameters.AddWithValue("@itemid", itemID);
                        com.Parameters.AddWithValue("@userid", ID);
                        com.ExecuteNonQuery();
                    }
                }
            }
        }
Exemplo n.º 3
0
        public static async void BidTimerCallBack(object state)
        {
            var posts = MarketPost.GetAllPosts();
            List <MarketPost> expired      = new List <MarketPost>();
            List <MarketPost> expiringSoon = new List <MarketPost>();

            foreach (var post in posts)
            {
                var expiryDate = post.DatePosted + new TimeSpan(14, 0, 0, 0);
                if (expiryDate - Var.CurrentDate() < new TimeSpan(0))
                {
                    expired.Add(post);
                }
                else if (expiryDate - Var.CurrentDate() < new TimeSpan(1, 0, 0, 0))
                {
                    string id = post.ID;
                    if (Properties.Settings.Default.warnedFMs == null)
                    {
                        Properties.Settings.Default.warnedFMs = new System.Collections.Specialized.StringCollection();
                    }
                    if (!Properties.Settings.Default.warnedFMs.Contains(id))
                    {
                        Properties.Settings.Default.warnedFMs.Add(id);
                        Properties.Settings.Default.Save();
                        expiringSoon.Add(post);
                    }
                }
            }

            foreach (MarketPost warn in expiringSoon)
            {
                var    user     = warn.User;
                string postID   = warn.ID;
                int    count    = warn.Amount;
                string itemName = DBFunctions.GetItemName(warn.Item_ID);
                int    price    = warn.Price;
                await user.SendMessageAsync("", embed : new InfoEmbed("WARNING: FREE MARKET POSTING EXPIRATION", "This is your one warning that your Free Market posting of " +
                                                                      $"{count} {itemName} for {price} coins will be expiring in 24 hours. You may remove this posting for a 25% fee, or it will " +
                                                                      $"be auctioned off and the coins will go towards slots.").Build());
            }

            bool removed = false;
            List <MarketPost> newBids = new List <MarketPost>();

            foreach (var expiry in expired)
            {
                var    user     = expiry.User;
                string postID   = expiry.ID;
                int    count    = expiry.Amount;
                string itemName = DBFunctions.GetItemName(expiry.Item_ID);
                int    price    = expiry.Price;
                await user.SendMessageAsync("", embed : new InfoEmbed("FREE MARKET POSTING EXPIRATION", "This message is to inform you that your Free Market posting of " +
                                                                      $"{count} {itemName} for {price} coins has expired. You have not removed it, and now it will " +
                                                                      $"be auctioned off and the coins will go towards slots.").Build());


                var notifyUsers = DBFunctions.GetUsersWhere("Notify_Bid", "1");

                foreach (IUser u in notifyUsers)
                {
                    await u.SendMessageAsync("", embed : new InfoEmbed("New Bid Alert", $"There is a new bid for {count} {itemName}(s)! Get it with the ID: {postID}.\n*You are receiving this message because you have opted in to new bid notifications.*").Build());
                }
                newBids.Add(expiry);

                MarketPost.DeletePost(postID);
            }

            if (removed)
            {
                foreach (var bid in newBids)
                {
                    new Bid(bid.Item_ID, bid.Amount);
                }
            }

            var bids = Bid.GetAllBids();

            for (int i = 0; i < bids.Count(); i++)
            {
                var endDate = bids[i].EndDate;
                var endTime = endDate - Var.CurrentDate();
                if (endTime <= new TimeSpan(0))
                {
                    var itemID     = bids[i].Item_ID;
                    var amount     = bids[i].Amount;
                    var bidder     = bids[i].CurrentBidder;
                    var currentBid = bids[i].CurrentBid;
                    if (bidder != null)
                    {
                        await bidder.SendMessageAsync($"Congratulations! You've won the bid for {DBFunctions.GetItemEmote(itemID)} {amount} {DBFunctions.GetItemName(itemID)}(s).");

                        var user = Functions.GetUser(bidder);
                        Properties.Settings.Default.jackpot += currentBid;
                        Properties.Settings.Default.Save();
                        for (int j = 0; j < amount; j++)
                        {
                            user.GiveItem(itemID);
                        }
                    }
                    Bid.DeleteBid(bids[i].ID);
                }
            }

            if ((Var.CurrentDate().DayOfWeek == DayOfWeek.Friday || Var.CurrentDate().DayOfWeek == DayOfWeek.Wednesday) && Properties.Settings.Default.lastBid.DayOfYear != Var.CurrentDate().DayOfYear)
            {
                Properties.Settings.Default.lastBid = Var.CurrentDate();
                Properties.Settings.Default.Save();

                var bidItems = new string[] { "key", "unicorn", "key2", "package", "santa", "gift", "calling" };
                int amount   = rdm.Next(10) + 3;

                string item   = bidItems[rdm.Next(bidItems.Count())];
                var    itemID = DBFunctions.GetItemID(item);

                var newBid = new Bid(itemID, amount);

                var notifyUsers = DBFunctions.GetUsersWhere("Notify_Bid", "1");
                foreach (IUser u in notifyUsers)
                {
                    await u.SendMessageAsync("", embed : new InfoEmbed("Bi-Weekly Bid Alert", $"The bi-weekly bid is on! This time: {amount} {item}(s)! Get it with the ID: {newBid.ID}.\n*You are receiving this message because you have opted in to new bid notifications.*").Build());
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds the inputted item to the inputted users list. Returns true when successful, false when not, usually when user doesn't have the item.
        /// </summary>
        /// <param name="u">The user adding the item</param>
        /// <param name="item">The item to be added</param>
        /// <returns></returns>
        public bool AddItem(IUser u, string item, int amount)
        {
            if (!Accepted)
            {
                return(false);
            }


            int coins;

            if (u.Id == u1.ID)
            {
                if (int.TryParse(item, out coins))
                {
                    if (coins > 0 && u1.GetCoins() >= coins)
                    {
                        coins1 += coins;
                        u1.GiveCoins(-coins);
                        return(true);
                    }
                }

                var itemList = u1.GetItemList();
                var itemID   = DBFunctions.GetItemID(item);
                if (!itemList.ContainsKey(itemID))
                {
                    return(false);
                }
                int userHas = itemList[itemID];
                if (amount <= userHas)
                {
                    for (int i = 0; i < amount; i++)
                    {
                        items1.Add(item);
                        u1.RemoveItem(item);
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                if (int.TryParse(item, out coins))
                {
                    if (coins > 0 && u2.GetCoins() >= coins)
                    {
                        coins2 += coins;
                        u2.GiveCoins(-coins);
                        return(true);
                    }
                }

                var itemList = u2.GetItemList();
                var itemID   = DBFunctions.GetItemID(item);
                if (!itemList.ContainsKey(itemID))
                {
                    return(false);
                }
                int userHas = itemList[itemID];
                if (amount <= userHas)
                {
                    for (int i = 0; i < amount; i++)
                    {
                        items2.Add(item);
                        u2.RemoveItem(item);
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Exemplo n.º 5
0
 public bool HasItem(string item, int amount = 1)
 {
     return(HasItem(DBFunctions.GetItemID(item), amount));
 }