public override void TryExecute() { float customMultiplier = CustomSettings.LookupFloatSetting("Toolkit.LevelPawn.XPMultiplier") > 0 ? CustomSettings.LookupFloatSetting("Toolkit.LevelPawn.XPMultiplier") : 0.5f; float xpWon = pawn.skills.GetSkill(skill).XpRequiredForLevelUp *customMultiplier *((float)Verse.Rand.Range(0.5f, 1.5f)); xpWon = IncidentHelper_PointsHelper.RollProportionalGamePoints(storeIncident, pointsWager, xpWon); pawn.skills.Learn(skill, xpWon, true); viewer.TakeViewerCoins(pointsWager); viewer.CalculateNewKarma(this.storeIncident.karmaType, pointsWager); VariablesHelpers.SendPurchaseMessage($"Increasing skill for {pawn.LabelCap} with {pointsWager} coins wagered and {(int)xpWon} xp for {skill.defName} purchased by {viewer.username}", separateChannel); string text = Helper.ReplacePlaceholder("TwitchStoriesDescription55".Translate(), colonist: pawn.Name.ToString(), skill: skill.defName, first: Math.Round(xpWon).ToString()); Current.Game.letterStack.ReceiveLetter("TwitchToolkitIncreaseSkill".Translate(), text, LetterDefOf.PositiveEvent, pawn); }
public void RegisterCustomSettings() { bool ScanningFloats = false; int index = 0; foreach (string key in customSettingKeys) { if (customSettingStringValues != null && customSettingStringValues.Count > index && CustomSettings.LookupStringSetting(key) == null) { Log.Warning("Registering custom setting from " + LabelCap + " " + key + " " + customSettingStringValues[index]); CustomSettings.SetStringSetting(key, customSettingStringValues[index]); index++; continue; } else { index = 0; ScanningFloats = true; } if (ScanningFloats && customSettingFloatValues != null && customSettingFloatValues.Count > index && CustomSettings.LookupFloatSetting(key) <= 0) { Log.Warning("Registering custom setting from " + LabelCap + " " + key + " " + customSettingFloatValues[index]); CustomSettings.SetFloatSetting(key, customSettingFloatValues[index]); index++; continue; } } }
public override void DoWindowContents(Rect inRect) { if (!checkedForBackup || !haveBackup) { MakeSureSaveExists(); return; } Listing_Standard ls = new Listing_Standard(); ls.Begin(inRect); ls.Label(storeIncident.label.CapitalizeFirst()); ls.Gap(); if (storeIncident.cost > 0) { storeIncident.abbreviation = ls.TextEntryLabeled("Purchase Code:", storeIncident.abbreviation); ls.Gap(); ls.AddLabeledNumericalTextField <int>("Cost", ref storeIncident.cost); ls.SliderLabeled("Max times per " + ToolkitSettings.EventCooldownInterval + " ingame day(s)", ref storeIncident.eventCap, storeIncident.eventCap.ToString(), 0, 15); if (variableIncident && storeIncidentVariables.maxWager > 0) { ls.Gap(); ls.SliderLabeled("Maximum coin wager", ref storeIncidentVariables.maxWager, storeIncidentVariables.cost.ToString(), storeIncident.cost, 20000f); } ls.Gap(); ls.AddLabeledRadioList("Karma Type", karmaTypeStrings, ref setKarmaType); storeIncident.karmaType = (KarmaType)Enum.Parse(typeof(KarmaType), setKarmaType); if (variableIncident) { ls.Gap(); ls.GapLine(); ls.Label("Custom Settings"); int KeyIndex = 0; if (storeIncidentVariables.customSettingStringValues != null) { foreach (string str in storeIncidentVariables.customSettingStringValues) { string key = storeIncidentVariables.customSettingKeys[KeyIndex]; CustomSettings.SetStringSetting(key, ls.TextEntryLabeled(StripSettingKey(key), CustomSettings.LookupStringSetting(key))); KeyIndex++; } } if (storeIncidentVariables.customSettingFloatValues != null) { foreach (float flt in storeIncidentVariables.customSettingFloatValues) { string key = storeIncidentVariables.customSettingKeys[KeyIndex]; float newValue = CustomSettings.LookupFloatSetting(key); string newValueBuffer = newValue.ToString(); ls.TextFieldNumericLabeled <float>(StripSettingKey(key), ref newValue, ref newValueBuffer); CustomSettings.SetFloatSetting(key, newValue); KeyIndex++; } } ls.GapLine(); } ls.Gap(); if (ls.ButtonTextLabeled("Disable Store Incident", "Disable")) { storeIncident.cost = -10; } } ls.Gap(); if (storeIncident.defName == "Item") { ls.SliderLabeled("Max times per " + ToolkitSettings.EventCooldownInterval + " ingame day(s)", ref storeIncident.eventCap, storeIncident.eventCap.ToString(), 0, 15); ls.Gap(); } if (storeIncident.defName != "Item" && ls.ButtonTextLabeled("Reset to Default", "Reset")) { Store_IncidentEditor.LoadBackup(storeIncident); if (storeIncident.cost < 1) { storeIncident.cost = 50; } MakeSureSaveExists(true); } if (storeIncident.defName == "Item" && ls.ButtonTextLabeled("Edit item prices", "Edit")) { Type type = typeof(StoreItemsWindow); Find.WindowStack.TryRemove(type); Window window = new StoreItemsWindow(); Find.WindowStack.Add(window); } ls.End(); }
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) { Toolkit.client.SendMessage($"@{viewer.username} syntax is {this.storeIncident.syntax}", separateChannel); return(false); } GameComponentPawns gameComponent = Current.Game.GetComponent <GameComponentPawns>(); if (!gameComponent.HasUserBeenNamed(viewer.username)) { Toolkit.client.SendMessage($"@{viewer.username} you must be in the colony to use this command.", separateChannel); return(false); } pawn = gameComponent.PawnAssignedToUser(viewer.username); float customMaxTraits = CustomSettings.LookupFloatSetting("Toolkit.AddTrait.MaxTraits") > 0 ? CustomSettings.LookupFloatSetting("Toolkit.AddTrait.MaxTraits") : 4; if (pawn.story.traits.allTraits != null && pawn.story.traits.allTraits.Count >= customMaxTraits) { Toolkit.client.SendMessage($"@{viewer.username} your pawn already has max {customMaxTraits} traits.", separateChannel); return(false); } string traitKind = command[2].ToLower(); BuyableTrait search = AllTraits.buyableTraits.Find(s => traitKind == s.label); if (search == null) { Toolkit.client.SendMessage($"@{viewer.username} trait {traitKind} not found.", separateChannel); return(false); } buyableTrait = search; traitDef = buyableTrait.def; if (!pawn.story.traits.allTraits.Any((Trait tr) => traitDef.ConflictsWith(tr)) && (traitDef.conflictingTraits == null || !traitDef.conflictingTraits.Any((TraitDef tr) => pawn.story.traits.HasTrait(tr)))) { return(true); } foreach (Trait tr in pawn.story.traits.allTraits) { if (tr.def.ConflictsWith(trait) || traitDef.ConflictsWith(tr)) { Toolkit.client.SendMessage($"@{viewer.username} {traitDef.defName} conflicts with your pawn's trait {tr.LabelCap}."); return(false); } } return(true); }