public override bool IsPossible(string message, Viewer viewer, bool separateChannel = false)
        {
            this.separateChannel = separateChannel;
            this.Viewer          = viewer;
            string[] command = message.Split(' ');
            if (command.Length < 3)
            {
                VariablesHelpers.ViewerDidWrongSyntax(viewer.username, storeIncident.syntax, separateChannel);
                return(false);
            }

            if (!VariablesHelpers.PointsWagerIsValid(
                    command[2],
                    viewer,
                    ref pointsWager,
                    ref storeIncident,
                    separateChannel
                    ))
            {
                ToolkitPatchLogger.Log(LOGGER_NAME, "Cannot fire custom manhunter. No valid points wagered");
                return(false);
            }

            target = Current.Game.AnyPlayerHomeMap;
            if (target == null)
            {
                ToolkitPatchLogger.Log(LOGGER_NAME, "Cannot fire custom manhunter. No valid tile");
                return(false);
            }

            parms        = StorytellerUtility.DefaultParmsNow(IncidentCategoryDefOf.RaidBeacon, target);
            parms.points = IncidentHelper_PointsHelper.RollProportionalGamePoints(storeIncident, pointsWager, parms.points);

            IEnumerable <string> animals = Settings.AnimalMap.Where(x => x.Value).Select(x => x.Key);

            ToolkitPatchLogger.Log(LOGGER_NAME, $"{animals.Count()}/{Settings.AnimalMap.Count} animals for selection.");

            string animal = animals.RandomElement();

            ToolkitPatchLogger.Log(LOGGER_NAME, $"Chose animal {animal} for the attack beast");

            ThingDef def = ThingDef.Named(animal);

            worker     = new CustomManhunterIncidentWorker(PawnKindDef.Named(animal));
            worker.def = IncidentDef.Named("BeastAttack");

            bool success = worker.CanFireNow(parms);

            if (!success)
            {
                WorkerCanFireCheck.CheckDefaultFireNowConditions(worker, parms, worker.def);
            }

            return(success);
        }
        public override bool IsPossible(string message, Viewer viewer, bool separateChannel = false)
        {
            this.separateChannel = separateChannel;
            this.viewer          = viewer;
            string[] command = message.Split(' ');
            if (command.Length < 3)
            {
                VariablesHelpers.ViewerDidWrongSyntax(viewer.username, storeIncident.syntax, separateChannel);
                return(false);
            }

            if (!VariablesHelpers.PointsWagerIsValid(
                    command[2],
                    viewer,
                    ref pointsWager,
                    ref storeIncident,
                    separateChannel
                    ))
            {
                return(false);
            }

            target = Current.Game.AnyPlayerHomeMap;
            if (target == null)
            {
                return(false);
            }

            parms        = StorytellerUtility.DefaultParmsNow(IncidentCategoryDefOf.RaidBeacon, target);
            parms.points = IncidentHelper_PointsHelper.RollProportionalGamePoints(storeIncident, pointsWager, parms.points);

            worker     = new IncidentWorker_ManhunterPack();
            worker.def = IncidentDefOf.RaidEnemy;

            return(worker.CanFireNow(parms));
        }
        public override bool IsPossible(string message, Viewer viewer, bool separateChannel = false)
        {
            this.separateChannel = separateChannel;
            this.Viewer          = viewer;
            string[] command = message.Split(' ');
            if (command.Length < 3)
            {
                VariablesHelpers.ViewerDidWrongSyntax(viewer.username, storeIncident.syntax);
                return(false);
            }

            if (!VariablesHelpers.PointsWagerIsValid(
                    command[2],
                    viewer,
                    ref pointsWager,
                    ref storeIncident,
                    separateChannel
                    ))
            {
                return(false);
            }

            target = Current.Game.AnyPlayerHomeMap;
            if (target == null)
            {
                return(false);
            }

            parms        = StorytellerUtility.DefaultParmsNow(IncidentCategoryDefOf.ThreatSmall, target);
            parms.points = IncidentHelper_PointsHelper.RollProportionalGamePoints(storeIncident, pointsWager, parms.points);

            List <string> animals = new List <string>()
            {
                "Bear_Grizzly", "Bear_Polar", "Rhinoceros", "Elephant", "Megasloth", "Thrumbo"
            };

            animals.Shuffle();

            ThingDef def          = ThingDef.Named(animals[0]);
            float    averagePower = 0;

            if (def != null && def.race != null)
            {
                foreach (Tool t in def.tools)
                {
                    averagePower += t.power;
                }
                averagePower = averagePower / def.tools.Count;
            }

            float animalCount = 2.5f;

            if (averagePower > 18)
            {
                animalCount = 2.0f;
            }

            worker     = new IncidentWorker_SpecificAnimalsWanderIn("TwitchStoriesLetterLabelPredators", PawnKindDef.Named(animals[0]), false, (int)animalCount, true, true);
            worker.def = IncidentDef.Named("HerdMigration");

            return(worker.CanFireNow(parms));
        }
예제 #4
0
        public override bool IsPossible(string message, Viewer viewer, bool separateChannel = false)
        {
            this.separateChannel = separateChannel;
            this.viewer          = viewer;
            string[] command = message.Split(' ');
            if (command.Length < 4)
            {
                VariablesHelpers.ViewerDidWrongSyntax(viewer.username, storeIncident.syntax, separateChannel);
                return(false);
            }

            string itemKey = command[2].ToLower();

            if (itemKey == null || itemKey == "")
            {
                VariablesHelpers.ViewerDidWrongSyntax(viewer.username, storeIncident.syntax, separateChannel);
                return(false);
            }

            IEnumerable <Store.Item> itemSearch = StoreInventory.items.Where(s =>
                                                                             s.price > 0 &&
                                                                             (s.abr == itemKey ||
                                                                              s.defname.ToLower() == itemKey)
                                                                             );

            if (itemSearch.Count() > 0)
            {
                item = itemSearch.ElementAt(0);
            }

            if (item == null || item.price < 1)
            {
                Toolkit.client.SendMessage($"@{viewer.username} item not found.", separateChannel);
                return(false);
            }

            string quantityKey = command[3];

            if (quantityKey == null || quantityKey == "")
            {
                VariablesHelpers.ViewerDidWrongSyntax(viewer.username, storeIncident.syntax, separateChannel);
                return(false);
            }

            try
            {
                if (!int.TryParse(quantityKey, out checked (quantity)))
                {
                    return(false);
                }

                price = checked (item.price * quantity);
            }
            catch (OverflowException e)
            {
                Log.Warning(e.Message);
                return(false);
            }

            if (quantity < 1 || price < 1)
            {
                VariablesHelpers.ViewerDidWrongSyntax(viewer.username, storeIncident.syntax, separateChannel);
                return(false);
            }

            if (!Purchase_Handler.CheckIfViewerHasEnoughCoins(viewer, price, separateChannel))
            {
                return(false);
            }

            if (price < ToolkitSettings.MinimumPurchasePrice)
            {
                Toolkit.client.SendMessage(Helper.ReplacePlaceholder(
                                               "TwitchToolkitMinPurchaseNotMet".Translate(),
                                               viewer: viewer.username,
                                               amount: price.ToString(),
                                               first: ToolkitSettings.MinimumPurchasePrice.ToString()
                                               ), separateChannel);
                return(false);
            }

            return(true);
        }
        public override bool IsPossible(string message, Viewer viewer, bool separateChannel = false)
        {
            this.separateChannel = separateChannel;
            this.Viewer          = viewer;
            string[] command = message.Split(' ');
            if (command.Length < 4)
            {
                VariablesHelpers.ViewerDidWrongSyntax(viewer.username, storeIncident.syntax);
                return(false);
            }

            string itemKey = command[2].ToLower();

            if (itemKey == null || itemKey == "")
            {
                VariablesHelpers.ViewerDidWrongSyntax(viewer.username, storeIncident.syntax);
                return(false);
            }

            IEnumerable <Store.Item> itemSearch = StoreInventory.items.Where(s =>
                                                                             s.price > 0 &&
                                                                             (s.abr == itemKey ||
                                                                              s.defname.ToLower() == itemKey)
                                                                             );

            if (itemSearch.Count() > 0)
            {
                item = itemSearch.ElementAt(0);
            }

            if (item == null || item.price < 1)
            {
                TwitchWrapper.SendChatMessage($"@{viewer.username} item not found.");
                return(false);
            }

            ThingDef itemThingDef = ThingDef.Named(item.defname);

            bool isResearched = true;
            ResearchProjectDef researchProject = null;

            Helper.Log("Checking researched");
            if (itemThingDef.recipeMaker != null &&
                itemThingDef.recipeMaker.researchPrerequisite != null &&
                !itemThingDef.recipeMaker.researchPrerequisite.IsFinished)
            {
                Helper.Log("Recipe not researched");
                isResearched    = false;
                researchProject = itemThingDef.recipeMaker.researchPrerequisite;
            }
            else if (!itemThingDef.IsResearchFinished)
            {
                Helper.Log("Building not researched");
                isResearched    = false;
                researchProject = itemThingDef.researchPrerequisites.ElementAt(0);
            }

            if (BuyItemSettings.mustResearchFirst && !isResearched)
            {
                string output = $"@{viewer.username} {itemThingDef.LabelCap} has not been researched yet, must finish research project {researchProject.LabelCap} first.";

                TwitchWrapper.SendChatMessage(output);

                return(false);
            }

            string quantityKey = command[3];

            if (quantityKey == null || quantityKey == "")
            {
                VariablesHelpers.ViewerDidWrongSyntax(viewer.username, storeIncident.syntax);
                return(false);
            }

            try
            {
                if (!int.TryParse(quantityKey, out checked (quantity)))
                {
                    return(false);
                }

                price = checked (item.price * quantity);
            }
            catch (OverflowException e)
            {
                Helper.Log(e.Message);
                return(false);
            }

            if (quantity < 1 || price < 1)
            {
                VariablesHelpers.ViewerDidWrongSyntax(viewer.username, storeIncident.syntax);
                return(false);
            }

            if (!Purchase_Handler.CheckIfViewerHasEnoughCoins(viewer, price))
            {
                return(false);
            }

            if (price < ToolkitSettings.MinimumPurchasePrice)
            {
                TwitchWrapper.SendChatMessage(Helper.ReplacePlaceholder(
                                                  "TwitchToolkitMinPurchaseNotMet".Translate(),
                                                  viewer: viewer.username,
                                                  amount: price.ToString(),
                                                  first: ToolkitSettings.MinimumPurchasePrice.ToString()
                                                  ));
                return(false);
            }

            return(true);
        }