Пример #1
0
        public override bool CanHappen(string msg, [NotNull] Viewer viewer)
        {
            if (!PurchaseHelper.TryGetPawn(viewer.username, out _pawn))
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.NoPawn".Localize());

                return(false);
            }

            var worker = ArgWorker.CreateInstance(CommandFilter.Parse(msg).Skip(2));

            if (!worker.TryGetNextAsTrait(out _thisShop) || !worker.TryGetNextAsTrait(out _thatShop))
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.InvalidTraitQuery".LocalizeKeyed(worker.GetLast()));

                return(false);
            }

            if (!IsUsable(_thisShop, _thatShop))
            {
                MessageHelper.ReplyToUser(
                    viewer.username,
                    $"TKUtils.{(_thisShop.CanRemove ? "" : "Remove")}Trait.Disabled".LocalizeKeyed((_thisShop.CanRemove ? _thatShop : _thisShop).Name.CapitalizeFirst())
                    );

                return(false);
            }

            if (TraitHelper.GetTotalTraits(_pawn) >= AddTraitSettings.maxTraits && WouldExceedLimit())
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.ReplaceTrait.Violation".LocalizeKeyed(_thisShop.Name, _thatShop.Name));

                return(false);
            }

            if (!viewer.CanAfford(TotalPrice))
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.InsufficientBalance".LocalizeKeyed(TotalPrice.ToString("N0"), viewer.GetViewerCoins().ToString("N0")));

                return(false);
            }

            if (!PassesCharacterCheck(viewer))
            {
                return(false);
            }

            if (!PassesModCheck(viewer))
            {
                return(false);
            }

            if (!PassesValidationCheck(viewer))
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
        public override bool CanHappen(string msg, [NotNull] Viewer viewer)
        {
            if (!viewer.CanAfford(storeIncident.cost))
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.InsufficientBalance".Localize());

                return(false);
            }

            if (Current.Game.Maps.Any(m => m.IsPlayerHome))
            {
                return(Current.Game.Maps.All(map => !map.GameConditionManager.ConditionIsActive(GameConditionDefOf.Sanctuary)));
            }

            MessageHelper.ReplyToUser(viewer.username, "TKUtils.NoMap".Localize());

            return(false);
        }
Пример #3
0
        private static bool CanPurchaseRace([NotNull] Viewer viewer, [NotNull] IShopItemBase target)
        {
            if (!target.Enabled && TkSettings.PurchasePawnKinds)
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.InformativeDisabledItem".LocalizeKeyed(target.Name));

                return(false);
            }

            if (viewer.CanAfford(target.Cost))
            {
                return(true);
            }

            MessageHelper.ReplyToUser(viewer.username, "TKUtils.InsufficientBalance".LocalizeKeyed(target.Cost.ToString("N0"), viewer.GetViewerCoins().ToString("N0")));

            return(false);
        }
Пример #4
0
        public override void Execute()
        {
            var healed     = 0;
            var iterations = 0;

            while (true)
            {
                if (!Viewer.CanAfford(storeIncident.cost))
                {
                    break;
                }

                object healable = HealHelper.GetPawnHealable(_pawn);

                if (healable == null)
                {
                    break;
                }

                healed      = Heal(healable, healed);
                iterations += 1;

                if (iterations < 500)
                {
                    continue;
                }

                TkUtils.Logger.Warn("Exceeded the maximum number of iterations during full heal.");

                break;
            }

            MessageHelper.SendConfirmation(
                Viewer.username,
                healed > 1 ? "TKUtils.FullHeal.CompletePlural".LocalizeKeyed(healed.ToString("N0")) : "TKUtils.FullHeal.Complete".Localize()
                );

            Current.Game.letterStack.ReceiveLetter(
                "TKUtils.FullHealLetter.Title".Localize(),
                "TKUtils.FullHealLetter.Description".LocalizeKeyed(Viewer.username),
                LetterDefOf.PositiveEvent,
                _pawn
                );
        }
Пример #5
0
        public override bool CanHappen(string msg, [NotNull] Viewer viewer)
        {
            if (!PurchaseHelper.TryGetPawn(viewer.username, out _pawn))
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.NoPawn".Localize());

                return(false);
            }

            List <Trait> traits = _pawn !.story.traits.allTraits;

            if (traits?.Count <= 0)
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.RemoveTrait.None".Localize());

                return(false);
            }

            var worker = ArgWorker.CreateInstance(CommandFilter.Parse(msg).Skip(2));

            if (!worker.TryGetNextAsTrait(out _buyable))
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.InvalidTraitQuery".LocalizeKeyed(worker.GetLast()));

                return(false);
            }

            if (!_buyable !.CanRemove)
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.RemoveTrait.Disabled".LocalizeKeyed(worker.GetLast()));

                return(false);
            }

            if (!viewer.CanAfford(_buyable.CostToRemove))
            {
                MessageHelper.ReplyToUser(
                    viewer.username,
                    "TKUtils.InsufficientBalance".LocalizeKeyed(_buyable.CostToRemove.ToString("N0"), viewer.GetViewerCoins().ToString("N0"))
                    );

                return(false);
            }

            Trait target = traits?.FirstOrDefault(t => TraitHelper.CompareToInput(_buyable.GetDefaultName(_pawn.gender) !, t.Label));

            if (target == null)
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.RemoveTrait.Missing".LocalizeKeyed(worker.GetLast()));

                return(false);
            }

            if (!PassesModChecks(viewer, target, worker))
            {
                return(false);
            }

            _trait = target;

            return(true);
        }
Пример #6
0
        public override bool CanHappen(string msg, Viewer viewer)
        {
            string[] traitQueries = CommandFilter.Parse(msg).Skip(2).ToArray();

            if (traitQueries.Length <= 0)
            {
                return(false);
            }

            if (!PurchaseHelper.TryGetPawn(viewer.username, out _pawn))
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.NoPawn".Localize());

                return(false);
            }

            var worker             = ArgWorker.CreateInstance(CommandFilter.Parse(msg).Skip(2));
            List <TraitItem> items = worker.GetAllAsTrait().ToList();

            if (worker.HasNext() && !worker.GetLast().NullOrEmpty())
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.InvalidTraitQuery".LocalizeKeyed(worker.GetLast()));

                return(false);
            }

            if (!TryProcessTraits(_pawn !, items, out _events))
            {
                TraitEvent errored = _events.FirstOrDefault(e => !e.Error.NullOrEmpty());

                if (errored != null)
                {
                    MessageHelper.ReplyToUser(viewer.username, errored.Error);
                }

                return(false);
            }

            if (_events.Count(e => e.ContributesToLimit) > AddTraitSettings.maxTraits)
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.Trait.LimitReached".LocalizeKeyed(AddTraitSettings.maxTraits));

                return(false);
            }

            int total = _events.Sum(
                i =>
            {
                switch (i.Type)
                {
                case EventType.Add:
                    return(i.Item.CostToAdd);

                case EventType.Remove:
                    return(i.Item.CostToRemove);

                default:
                    return(0);
                }
            }
                );

            if (!viewer.CanAfford(total))
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.InsufficientBalance".LocalizeKeyed(total.ToString("N0"), viewer.GetViewerCoins().ToString("N0")));

                return(false);
            }

            return(true);
        }
Пример #7
0
        public override bool CanHappen(string msg, [NotNull] Viewer viewer)
        {
            if (!PurchaseHelper.TryGetPawn(viewer.username, out _pawn))
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.NoPawn".Localize());

                return(false);
            }

            var worker = ArgWorker.CreateInstance(CommandFilter.Parse(msg).Skip(2));

            if (!worker.TryGetNextAsItem(out ArgWorker.ItemProxy item) || !item.IsValid())
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.InvalidItemQuery".LocalizeKeyed(item?.Thing?.Name ?? worker.GetLast()));

                return(false);
            }

            _buyableItem = item.Thing;

            if (item.TryGetError(out string error))
            {
                MessageHelper.ReplyToUser(viewer.username, error);

                return(false);
            }

            if (!worker.TryGetNextAsInt(out _amount, 1, viewer.GetMaximumPurchaseAmount(_buyableItem.Cost)))
            {
                _amount = 1;
            }

            if (!PurchaseHelper.TryMultiply(_buyableItem.Cost, _amount, out int cost))
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.Overflowed".Localize());

                return(false);
            }

            if (!viewer.CanAfford(cost))
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.InsufficientBalance".LocalizeKeyed(cost.ToString("N0"), viewer.GetViewerCoins().ToString("N0")));

                return(false);
            }

            List <ResearchProjectDef> prerequisites = item.Thing.Thing.GetUnfinishedPrerequisites();

            if (BuyItemSettings.mustResearchFirst && prerequisites.Count > 0)
            {
                MessageHelper.ReplyToUser(
                    viewer.username,
                    "TKUtils.ResearchRequired".LocalizeKeyed(item.Thing.Thing.LabelCap.RawText, prerequisites.Select(p => p.LabelCap.RawText).SectionJoin())
                    );

                return(false);
            }

            foreach (IUsabilityHandler h in CompatRegistry.AllUsabilityHandlers)
            {
                if (!h.IsUsable(item.Thing.Thing))
                {
                    continue;
                }

                _handler = h;

                break;
            }

            if (_handler == null || item.Thing.ItemData?.IsUsable != true)
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.DisabledItem".Localize());

                return(false);
            }

            _buyableItem = item !.Thing;

            return(true);
        }
Пример #8
0
        public override bool CanHappen(string msg, [NotNull] Viewer viewer)
        {
            string[] segments  = CommandFilter.Parse(msg).Skip(2).ToArray();
            string   partQuery = segments.FirstOrFallback();

            if (!PurchaseHelper.TryGetPawn(viewer.username, out Pawn pawn))
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.NoPawn".Localize());

                return(false);
            }

            _appointment = Appointment.ParseInput(pawn, segments);

            if (_appointment.ThingDef == null || _appointment.Item == null)
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.InvalidItemQuery".LocalizeKeyed(partQuery));

                return(false);
            }

            if (_appointment.ThingDef.IsMedicine || _appointment.Surgery == null)
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.Surgery.HasNoSurgery".LocalizeKeyed(partQuery));

                return(false);
            }

            if (BuyItemSettings.mustResearchFirst && _appointment.ThingDef.GetUnfinishedPrerequisites() is { } projects&& projects.Count > 0)
            {
                MessageHelper.ReplyToUser(
                    viewer.username,
                    "TKUtils.ResearchRequired".LocalizeKeyed(_appointment.ThingDef.LabelCap.RawText, projects.Select(p => p.LabelCap.RawText).SectionJoin())
                    );

                return(false);
            }

            if (!viewer.CanAfford(_appointment.Cost))
            {
                MessageHelper.ReplyToUser(
                    viewer.username,
                    "TKUtils.InsufficientBalance".LocalizeKeyed(_appointment.Cost.ToString("N0"), viewer.GetViewerCoins().ToString("N0"))
                    );

                return(false);
            }

            if (_appointment.Overflowed)
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.Overflowed".Localize());

                return(false);
            }

            if (_appointment.BodyParts.NullOrEmpty())
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.Surgery.NoSlotAvailable".Localize());

                return(false);
            }

            _map = Current.Game.AnyPlayerHomeMap;

            if (_map != null)
            {
                return(true);
            }

            MessageHelper.ReplyToUser(viewer.username, "TKUtils.NoMap".Localize());

            return(false);
        }
Пример #9
0
        public override bool CanHappen(string msg, [NotNull] Viewer viewer)
        {
            var worker = ArgWorker.CreateInstance(CommandFilter.Parse(msg).Skip(2));

            if (!PurchaseHelper.TryGetPawn(viewer.username, out Pawn pawn) || !pawn !.Spawned)
            {
                return(false);
            }

            if (!worker.TryGetNextAsItem(out ArgWorker.ItemProxy proxy) || !proxy.IsValid() || proxy !.Thing.Thing.race != null)
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.InvalidItemQuery".LocalizeKeyed(worker.GetLast()));

                return(false);
            }

            if (proxy.TryGetError(out string error))
            {
                MessageHelper.ReplyToUser(viewer.username, error);

                return(false);
            }

            if (!worker.TryGetNextAsInt(out int amount, 1, viewer.GetMaximumPurchaseAmount(proxy !.Thing.Cost)))
            {
                amount = 1;
            }

            if (PurchaseHelper.TryGetUnfinishedPrerequisites(proxy.Thing.Thing, out List <ResearchProjectDef> projects))
            {
                MessageHelper.ReplyToUser(
                    viewer.username,
                    "TKUtils.ResearchRequired".LocalizeKeyed(proxy.Thing.Thing !.LabelCap.RawText, projects.Select(p => p.LabelCap.RawText).SectionJoin())
                    );

                return(false);
            }

            if (worker.GetLast().Equals("*"))
            {
                amount = viewer.GetMaximumPurchaseAmount(proxy.Thing.Cost);
            }

            if (proxy.Thing.ItemData?.HasQuantityLimit == true)
            {
                amount = Mathf.Clamp(amount, 1, proxy.Thing.ItemData.QuantityLimit);
            }

            _purchaseRequest = new PurchaseBackpackRequest {
                Proxy = proxy, Quantity = amount, Purchaser = viewer, Pawn = pawn
            };

            if (_purchaseRequest.Price < ToolkitSettings.MinimumPurchasePrice)
            {
                MessageHelper.ReplyToUser(
                    viewer.username,
                    "TKUtils.Item.MinimumViolation".LocalizeKeyed(_purchaseRequest.Price.ToString("N0"), ToolkitSettings.MinimumPurchasePrice.ToString("N0"))
                    );

                return(false);
            }

            if (_purchaseRequest.Overflowed)
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.Overflowed".Localize());

                return(false);
            }

            if (viewer.CanAfford(_purchaseRequest.Price))
            {
                return(_purchaseRequest.Map != null);
            }

            MessageHelper.ReplyToUser(
                viewer.username,
                "TKUtils.InsufficientBalance".LocalizeKeyed(_purchaseRequest.Price.ToString("N0"), viewer.GetViewerCoins().ToString("N0"))
                );

            return(false);
        }
Пример #10
0
        public override bool CanHappen(string msg, [NotNull] Viewer viewer)
        {
            var worker = ArgWorker.CreateInstance(CommandFilter.Parse(msg).Skip(2));

            if (!worker.TryGetNextAsItem(out ArgWorker.ItemProxy product) || !product.IsValid())
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.InvalidItemQuery".LocalizeKeyed(worker.GetLast()));

                return(false);
            }

            if (product.TryGetError(out string error))
            {
                MessageHelper.ReplyToUser(viewer.username, error);

                return(false);
            }

            int amount = product.Thing.ItemData?.HasQuantityLimit == true?worker.GetNextAsInt(1, product.Thing.ItemData.QuantityLimit) : worker.GetNextAsInt(1);

            List <ResearchProjectDef> projects = product !.Thing.Thing.GetUnfinishedPrerequisites();

            if (BuyItemSettings.mustResearchFirst && projects.Count > 0)
            {
                MessageHelper.ReplyToUser(
                    viewer.username,
                    "TKUtils.ResearchRequired".LocalizeKeyed(product.Thing.Thing.LabelCap.RawText, projects.Select(p => p.LabelCap.RawText).SectionJoin())
                    );

                return(false);
            }

            if (worker.GetLast()?.Equals("*") ?? false)
            {
                amount = viewer.GetMaximumPurchaseAmount(product.Thing.Cost);
            }

            _purchaseRequest = new PurchaseRequest {
                Proxy = product, Quantity = amount, Purchaser = viewer, Map = Helper.AnyPlayerMap
            };

            if (_purchaseRequest.Price < ToolkitSettings.MinimumPurchasePrice)
            {
                MessageHelper.ReplyToUser(
                    viewer.username,
                    "TKUtils.Item.MinimumViolation".LocalizeKeyed(_purchaseRequest.Price.ToString("N0"), ToolkitSettings.MinimumPurchasePrice.ToString("N0"))
                    );

                return(false);
            }

            if (_purchaseRequest.Overflowed)
            {
                MessageHelper.ReplyToUser(viewer.username, "TKUtils.Overflowed".Localize());

                return(false);
            }

            if (viewer.CanAfford(_purchaseRequest.Price))
            {
                return(_purchaseRequest.Map != null);
            }

            MessageHelper.ReplyToUser(
                viewer.username,
                "TKUtils.InsufficientBalance".LocalizeKeyed(_purchaseRequest.Price.ToString("N0"), viewer.GetViewerCoins().ToString("N0"))
                );

            return(false);
        }