Esempio n. 1
0
        public static bool CheckTimesKarmaTypeHasBeenUsedRecently(StoreIncident incident)
        {
            // if they have max event setting off always return false
            if (!ToolkitSettings.MaxEvents)
            {
                return(false);
            }

            Store_Component component = Current.Game.GetComponent <Store_Component>();

            switch (incident.karmaType)
            {
            case KarmaType.Bad:
                return(component.KarmaTypesInLogOf(incident.karmaType) >= ToolkitSettings.MaxBadEventsPerInterval);

            case KarmaType.Good:
                return(component.KarmaTypesInLogOf(incident.karmaType) >= ToolkitSettings.MaxGoodEventsPerInterval);

            case KarmaType.Neutral:
                return(component.KarmaTypesInLogOf(incident.karmaType) >= ToolkitSettings.MaxNeutralEventsPerInterval);

            case KarmaType.Doom:
                return(component.KarmaTypesInLogOf(incident.karmaType) >= ToolkitSettings.MaxBadEventsPerInterval);
            }

            return(false);
        }
        public static void ResolvePurchaseVariables(Viewer viewer, IRCMessage message, StoreIncidentVariables incident, bool separateChannel = false)
        {
            int cost = incident.cost;

            if (cost < 1 && incident.defName != "Item")
            {
                return;
            }

            if (CheckIfViewerIsInVariableCommandList(viewer.username, separateChannel))
            {
                return;
            }

            if (!CheckIfViewerHasEnoughCoins(viewer, cost, separateChannel))
            {
                return;
            }

            if (CheckIfKarmaTypeIsMaxed(incident.karmaType, viewer.username, separateChannel))
            {
                return;
            }

            if (CheckIfIncidentIsOnCooldown(incident, viewer.username, separateChannel))
            {
                return;
            }

            viewerNamesDoingVariableCommands.Add(viewer.username);

            IncidentHelperVariables helper = StoreIncidentMaker.MakeIncidentVariables(incident);

            if (helper == null)
            {
                Log.Warning("Missing helper for incident " + incident.defName);
                return;
            }

            if (!helper.IsPossible(message.Message, viewer, separateChannel))
            {
                if (viewerNamesDoingVariableCommands.Contains(viewer.username))
                {
                    viewerNamesDoingVariableCommands.Remove(viewer.username);
                }
                return;
            }

            Store_Component component = Current.Game.GetComponent <Store_Component>();

            QueuePlayerMessage(viewer, message.Message, incident.variables);

            Ticker.IncidentHelperVariables.Enqueue(helper);
            Store_Logger.LogPurchase(viewer.username, message.Message);
            component.LogIncident(incident);
        }
Esempio n. 3
0
        public static bool CheckIfKarmaTypeIsMaxed(StoreIncident incident, string username, bool separateChannel = false)
        {
            bool maxed = CheckTimesKarmaTypeHasBeenUsedRecently(incident);

            if (maxed)
            {
                Store_Component component = Current.Game.GetComponent <Store_Component>();
                Toolkit.client.SendMessage($"@{username} {incident.label.CapitalizeFirst()} is maxed from karmatype, wait " + component.DaysTillIncidentIsPurchaseable(incident) + " days to purchase.", separateChannel);
            }

            return(maxed);
        }
Esempio n. 4
0
        public static bool CheckIfIncidentIsOnCooldown(StoreIncident incident, string username, bool separateChannel = false)
        {
            if (!ToolkitSettings.EventsHaveCooldowns)
            {
                return(false);
            }

            Store_Component component = Current.Game.GetComponent <Store_Component>();

            bool maxed = component.IncidentsInLogOf(incident.abbreviation) >= incident.eventCap;

            if (maxed)
            {
                float days = component.DaysTillIncidentIsPurchaseable(incident);
                Toolkit.client.SendMessage($"@{username} {incident.label.CapitalizeFirst()} is maxed, wait " + days + $" day{(days != 1 ? "s" : "")} to purchase.", separateChannel);
            }

            return(maxed);
        }
Esempio n. 5
0
        public static bool CheckIfCarePackageIsOnCooldown(string username, bool separateChannel = false)
        {
            if (!ToolkitSettings.MaxEvents)
            {
                return(false);
            }

            Store_Component        component = Current.Game.GetComponent <Store_Component>();
            StoreIncidentVariables incident  = DefDatabase <StoreIncidentVariables> .GetNamed("Item");

            if (component.IncidentsInLogOf(incident.abbreviation) >= ToolkitSettings.MaxCarePackagesPerInterval)
            {
                float daysTill = component.DaysTillIncidentIsPurchaseable(incident);
                Toolkit.client.SendMessage($"@{username} care packages are on cooldown, wait " + daysTill + $" day{(daysTill != 1 ? "s" : "")}.", separateChannel);
                return(true);
            }

            return(false);
        }
        public static bool CheckIfIncidentIsOnCooldown(StoreIncident incident, string username, bool separateChannel = false)
        {
            if (!ToolkitSettings.EventsHaveCooldowns)
            {
                return(false);
            }

            Store_Component component = Current.Game.GetComponent <Store_Component>();

            bool maxed = component.IncidentsInLogOf(incident.abbreviation) >= incident.eventCap;

            if (maxed)
            {
                Log.Message("StoreIncident max per day reached for " + incident.label);
                client.SendMessage($"@{username} " + "TwitchToolkitEventOnCooldown".Translate(), separateChannel);
            }

            return(maxed);
        }
Esempio n. 7
0
        public static void ResolvePurchaseSimple(Viewer viewer, TwitchIRCMessage message, StoreIncidentSimple incident, bool separateChannel = false)
        {
            int cost = incident.cost;

            if (cost < 1)
            {
                return;
            }

            if (CheckIfViewerIsInVariableCommandList(viewer.username, separateChannel))
            {
                return;
            }

            if (!CheckIfViewerHasEnoughCoins(viewer, cost, separateChannel))
            {
                return;
            }

            if (CheckIfKarmaTypeIsMaxed(incident, viewer.username, separateChannel))
            {
                return;
            }

            if (CheckIfIncidentIsOnCooldown(incident, viewer.username, separateChannel))
            {
                return;
            }

            IncidentHelper helper = StoreIncidentMaker.MakeIncident(incident);

            if (helper == null)
            {
                Helper.Log("Missing helper for incident " + incident.defName);
                return;
            }

            if (!helper.IsPossible())
            {
                Toolkit.client.SendMessage($"@{viewer.username} " + "TwitchToolkitEventNotPossible".Translate(), separateChannel);
                return;
            }

            if (!ToolkitSettings.UnlimitedCoins)
            {
                viewer.TakeViewerCoins(cost);
            }

            Store_Component component = Current.Game.GetComponent <Store_Component>();

            helper.Viewer  = viewer;
            helper.message = message.Message;

            Ticker.IncidentHelpers.Enqueue(helper);
            Store_Logger.LogPurchase(viewer.username, message.Message);
            component.LogIncident(incident);
            viewer.CalculateNewKarma(incident.karmaType, cost);

            if (ToolkitSettings.PurchaseConfirmations)
            {
                Toolkit.client.SendMessage(
                    Helper.ReplacePlaceholder(
                        "TwitchToolkitEventPurchaseConfirm".Translate(),
                        first: incident.label.CapitalizeFirst(),
                        viewer: viewer.username
                        ),
                    separateChannel
                    );
            }
        }
        public static void ResolvePurchaseVariables(Viewer viewer, ITwitchMessage twitchMessage, StoreIncidentVariables incident, string formattedMessage, bool separateChannel = false)
        {
            int cost = incident.cost;

            if (cost < 1 && incident.defName != "Item")
            {
                return;
            }

            if (CheckIfViewerIsInVariableCommandList(viewer.username))
            {
                return;
            }

            if (!CheckIfViewerHasEnoughCoins(viewer, cost))
            {
                return;
            }

            if (incident != DefDatabase <StoreIncidentVariables> .GetNamed("Item"))
            {
                if (CheckIfKarmaTypeIsMaxed(incident, viewer.username))
                {
                    return;
                }
            }
            else
            {
                if (CheckIfCarePackageIsOnCooldown(viewer.username))
                {
                    return;
                }
            }

            if (CheckIfIncidentIsOnCooldown(incident, viewer.username))
            {
                return;
            }

            viewerNamesDoingVariableCommands.Add(viewer.username);

            IncidentHelperVariables helper = StoreIncidentMaker.MakeIncidentVariables(incident);

            if (helper == null)
            {
                Helper.Log("Missing helper for incident " + incident.defName);
                return;
            }

            if (!helper.IsPossible(formattedMessage, viewer))
            {
                if (viewerNamesDoingVariableCommands.Contains(viewer.username))
                {
                    viewerNamesDoingVariableCommands.Remove(viewer.username);
                }
                return;
            }

            Store_Component component = Current.Game.GetComponent <Store_Component>();

            helper.Viewer  = viewer;
            helper.message = formattedMessage;

            Ticker.IncidentHelperVariables.Enqueue(helper);
            Store_Logger.LogPurchase(viewer.username, twitchMessage.Message);
            component.LogIncident(incident);
        }
Esempio n. 9
0
        public float DaysTillIncidentIsPurchaseable(StoreIncident incident)
        {
            Store_Component component = Current.Game.GetComponent <Store_Component>();

            List <int> associateLogIDS = new List <int>();

            bool onCooldownByKarmaType;
            bool onCooldownByIncidentCap;

            float ticksTillExpires        = -1;
            float daysTillCooldownExpires = -1;

            if (incident.defName == "Item")
            {
                if (ToolkitSettings.MaxEvents)
                {
                    int logged = component.IncidentsInLogOf(incident.abbreviation);
                    onCooldownByKarmaType = logged >= ToolkitSettings.MaxCarePackagesPerInterval;
                }

                if (ToolkitSettings.EventsHaveCooldowns)
                {
                    int logged = component.IncidentsInLogOf(incident.abbreviation);
                    onCooldownByIncidentCap = logged >= incident.eventCap;
                }

                foreach (KeyValuePair <int, string> pair in abbreviationHistory)
                {
                    if (pair.Value == incident.abbreviation)
                    {
                        associateLogIDS.Add(pair.Key);
                    }
                }
            }
            else
            {
                if (ToolkitSettings.MaxEvents)
                {
                    int logged = component.KarmaTypesInLogOf(incident.karmaType);
                    onCooldownByKarmaType = Purchase_Handler.CheckTimesKarmaTypeHasBeenUsedRecently(incident);
                }

                if (ToolkitSettings.EventsHaveCooldowns)
                {
                    int logged = component.IncidentsInLogOf(incident.abbreviation);
                    onCooldownByIncidentCap = logged >= incident.eventCap;
                }

                foreach (KeyValuePair <int, string> pair in abbreviationHistory)
                {
                    if (pair.Value == incident.abbreviation)
                    {
                        associateLogIDS.Add(pair.Key);
                    }
                }

                foreach (KeyValuePair <int, string> pair in karmaHistory)
                {
                    if (pair.Value == incident.karmaType.ToString())
                    {
                        associateLogIDS.Add(pair.Key);
                    }
                }
            }

            foreach (int id in associateLogIDS)
            {
                float ticksAgo            = Find.TickManager.TicksGame - tickHistory[id];
                float daysAgo             = ticksAgo / GenDate.TicksPerDay;
                float ticksTillExpiration = (ToolkitSettings.EventCooldownInterval * GenDate.TicksPerDay) - ticksAgo;
                if (ticksTillExpires == -1 || ticksAgo < ticksTillExpiration)
                {
                    ticksTillExpires        = ticksAgo;
                    daysTillCooldownExpires = ticksTillExpiration / GenDate.TicksPerDay;
                }
            }

            return((float)Math.Round(daysTillCooldownExpires, 1));
        }