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); }
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 _buyableTrait) || !_buyableTrait.CanAdd || _buyableTrait.TraitDef == null) { MessageHelper.ReplyToUser(viewer.username, "TKUtils.InvalidTraitQuery".LocalizeKeyed(worker.GetLast())); return(false); } if (!viewer.CanAfford(_buyableTrait !.CostToAdd)) { MessageHelper.ReplyToUser( viewer.username, "TKUtils.InsufficientBalance".LocalizeKeyed(_buyableTrait.CostToAdd.ToString("N0"), viewer.GetViewerCoins().ToString("N0")) ); return(false); } if (TraitHelper.GetTotalTraits(_pawn) >= AddTraitSettings.maxTraits && _buyableTrait.TraitData?.CanBypassLimit != true) { MessageHelper.ReplyToUser(viewer.username, "TKUtils.Trait.LimitReached".LocalizeKeyed(AddTraitSettings.maxTraits)); return(false); } if (!PassesCharacterChecks(viewer, worker)) { return(false); } _trait = new Trait(_buyableTrait.TraitDef, _buyableTrait.Degree); return(PassesValidationChecks(viewer) && PassesModChecks(viewer)); }