Exemple #1
0
        public void CalculateNewKarma(KarmaType karmaType, int price)
        {
            int old      = this.GetViewerKarma();
            int newKarma = Karma.CalculateNewKarma(old, karmaType, price);

            SetViewerKarma(newKarma);
            Store_Logger.LogKarmaChange(username, old, newKarma);
        }
Exemple #2
0
        private void ExecuteCommand()
        {
            // take user coins
            if (!Settings.UnlimitedCoins)
            {
                this.viewer.TakeViewerCoins(this.calculatedprice);
            }

            // create success message
            if (this.product.type == 0)
            {
                if (this.product.evt.IsPossible())
                {
                    // normal event
                    this.successmessage = Helper.ReplacePlaceholder("TwitchToolkitEventPurchaseConfirm".Translate(), first: this.product.name, viewer: this.viewer.username);
                    this.viewer.SetViewerKarma(Karma.CalculateNewKarma(this.viewer.GetViewerKarma(), this.product.karmatype));

                    if (Settings.EventsHaveCooldowns)
                    {
                        // take of a cooldown for event and schedule for it to be taken off
                        this.product.maxEvents--;
                        Settings.JobManager.AddNewJob(new ScheduledJob(Settings.EventCooldownInterval, new Func <Product, bool>(IncrementProduct), product));
                    }
                }
                else
                {
                    // refund if event not possible anymore
                    this.viewer.GiveViewerCoins(this.calculatedprice);
                    return;
                }
            }
            else if (this.product.type == 1)
            {
                // care package
                try
                {
                    this.product.evt = new Event(80, EventType.Good, EventCategory.Drop, 3, "Gold", () => true, (quote) => this.itemtobuy.PutItemInCargoPod(quote, this.quantity, this.viewer.username));
                }
                catch (InvalidCastException e)
                {
                    Helper.Log("Carepackage error " + e.Message);
                }

                if (this.product.evt == null)
                {
                    Helper.Log("Could not generate care package");
                    return;
                }

                this.successmessage          = Helper.ReplacePlaceholder("TwitchToolkitItemPurchaseConfirm".Translate(), amount: this.quantity.ToString(), item: this.itemtobuy.abr, viewer: this.viewer.username);
                this.product.evt.chatmessage = craftedmessage;
                this.viewer.SetViewerKarma(Karma.CalculateNewKarma(this.viewer.GetViewerKarma(), this.product.karmatype, this.calculatedprice));
            }

            // create purchase event
            Ticker.Events.Enqueue(this.product.evt);
        }