Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Improvements #3

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Languages/English/Keyed/Help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,26 @@
<SendChatResponsesToTwitch_Help>Normally if a viewer is using Puppeteer, all Twitch Toolkit responses go to their browser. This option makes the response also go to Twitch chat.</SendChatResponsesToTwitch_Help>
<CreateAreaHelp>Areas for restrictions. Each area is either global if it has no cells or specific to the cells marked (use +/- buttons to edit). You then turn areas on/off for each colonist in the previous list. Displaying areas can be turned on/off with a button in the bottom right of the screen.</CreateAreaHelp>
<EditAreaHelp>The list of restrictions is global and you can select (green checkmark) which are active for this area.</EditAreaHelp>



<SendDrop_Help>Allows the Viewer to Drop their Gear/Items/Food etc. through Puppeteer</SendDrop_Help>
<SendAction_Help>Allows the Viewer to Command their Pawn Through the Map. (Haul, Harvest, Jail, etc.)</SendAction_Help>
<SendDrafted_Help>Allows the Viewer to Draft/Undraft their Pawn</SendDrafted_Help>
<SendHostileresponse_Help>Allows the Viewer to change the reaction the Pawn has to being Shot (default is flee)</SendHostileresponse_Help>
<SendPriority_Help>Allow the Viewer to change their Work Prios (Very Buggy, only works if streamer has the workinterface open)</SendPriority_Help>
<SendSchedule_Help>Allow the Viewer to change their Sleepschedule (Very Buggy, only works if streamer has the Scheduleinterface open)</SendSchedule_Help>
<SendGizmo_Help>Allow Custom Map Interactions (Mod Items). This is a very dangerous one as far as I can tell.</SendGizmo_Help>
<SendZone_Help>Allow Viewers to change their Area Restrictions</SendZone_Help>
<SendGoto_Help>Allows the Viewer to Move their Pawn when drafted.</SendGoto_Help>
<SendSelect_Help>I honestly haven't quite figured out yet how far this permission stretches</SendSelect_Help>
<SendConsume_Help>Nom Nom</SendConsume_Help>
<SendGrid_Help>This will stop your Client from sending the Puppeteer map to the Server. This should in theory massively increase Performance.</SendGrid_Help>

<SendJob_Help>This permissions allows viewers to: Choose a target to attack, Change their Weapon, Select Outfit policy, select Drug policy, and a few other minor things.</SendJob_Help>

<ForcePuppeteerChat_Help>NUCLEAR OPTION: No TTK Botmessage will appear in your chat anymore. Forces Viewer to use Puppeteer website if they want to see the response.</ForcePuppeteerChat_Help>

<TryMagic_Help>Will try to automagically assign Viewers to their TTK Pawns</TryMagic_Help>

</LanguageData>
20 changes: 19 additions & 1 deletion Languages/English/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,23 @@
<PlayerActionCooldownTicks>Control cooldown preventing respawn (game hours)</PlayerActionCooldownTicks>

<SendChatResponsesToTwitch>Send Toolkit chat responses to Twitch</SendChatResponsesToTwitch>


<SendDrop>Enable Dropping Gear/Items</SendDrop>
<SendAction>Enable General Map Interaction</SendAction>
<SendDrafted>Enable Drafting</SendDrafted>
<SendHostileresponse>Enable Changing Combat Response</SendHostileresponse>
<SendPriority>Enable Changing Priority</SendPriority>
<SendSchedule>Enable Changing Schedule</SendSchedule>
<SendGizmo>Allow Custom Map Interactions (Mod Items)</SendGizmo>
<SendZone>Allow Changing allowed Zones</SendZone>
<SendGoto>Enable Moving Drafted Pawns</SendGoto>
<SendSelect>Allow Selecting of Areas</SendSelect>
<SendConsume>Enable Force Consuming Items/Food</SendConsume>
<SendGrid>Enable Puppeteer Map (reduces Performance)</SendGrid>

<SendJob>Enable Multiple Features</SendJob>

<ForcePuppeteerChat>Remove every single TTK Chatresponse</ForcePuppeteerChat>

<TryMagic>Automatically Assign Pawns</TryMagic>
</LanguageData>
6 changes: 6 additions & 0 deletions Source/Core/Jobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void RunOnQueue(Func<Pawn, string[], object> action, string actionName = null)

case "attack-target":
if (settings.enabled == false) return;
if (!PuppeteerMod.Settings.SendGlobalJob) return;
RunOnQueue(AttackTarget, job.method);
break;

Expand All @@ -55,6 +56,7 @@ void RunOnQueue(Func<Pawn, string[], object> action, string actionName = null)

case "select-weapon":
if (settings.enabled == false) return;
if (!PuppeteerMod.Settings.SendGlobalJob) return;
RunOnQueue(SelectWeapon, job.method);
break;

Expand All @@ -64,6 +66,7 @@ void RunOnQueue(Func<Pawn, string[], object> action, string actionName = null)

case "select-outfit":
if (settings.enabled == false) return;
if (!PuppeteerMod.Settings.SendGlobalJob) return;
RunOnQueue(SelectOutfit, job.method);
break;

Expand All @@ -73,6 +76,7 @@ void RunOnQueue(Func<Pawn, string[], object> action, string actionName = null)

case "select-drug":
if (settings.enabled == false) return;
if (!PuppeteerMod.Settings.SendGlobalJob) return;
RunOnQueue(SelectDrug, job.method);
break;

Expand All @@ -82,6 +86,7 @@ void RunOnQueue(Func<Pawn, string[], object> action, string actionName = null)

case "do-rest":
if (settings.enabled == false) return;
if (!PuppeteerMod.Settings.SendGlobalJob) return;
RunOnQueue(DoRest, job.method);
break;

Expand All @@ -91,6 +96,7 @@ void RunOnQueue(Func<Pawn, string[], object> action, string actionName = null)

case "do-tend":
if (settings.enabled == false) return;
if (!PuppeteerMod.Settings.SendGlobalJob) return;
RunOnQueue(DoTend, job.method);
break;

Expand Down
12 changes: 12 additions & 0 deletions Source/Core/StateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,30 @@ public static void Set(Connection connection, IncomingState state)
{
case "hostile-response":
if (settings.enabled == false) return;
if (!PuppeteerMod.Settings.SendHostileresponse) return;
var responseMode = (HostilityResponseMode)Enum.Parse(typeof(HostilityResponseMode), state.val.ToString());
pawn.playerSettings.hostilityResponse = responseMode;
pawn.RemoteLog($"Response Mode to {responseMode}");
break;
case "drafted":
if (settings.enabled == false) return;
if (!PuppeteerMod.Settings.SendDrafted) return;
var drafted = Convert.ToBoolean(state.val);
if (Tools.CannotMoveOrDo(pawn) == false)
pawn.FakeDraft(drafted);
pawn.RemoteLog(drafted ? "Drafted" : "Undrafted");
break;
case "zone":
if (settings.enabled == false) return;
if (!PuppeteerMod.Settings.SendZone) return;
var area = pawn.Map.areaManager.AllAreas.Where(a => a.AssignableAsAllowed()).FirstOrDefault(a => a.Label == state.val.ToString());
pawn.playerSettings.AreaRestriction = area;
pawn.RemoteLog(area == null ? "Area unrestricted" : $"Area restricted to {area.Label}");
break;
case "priority":
{
if (settings.enabled == false) return;
if (!PuppeteerMod.Settings.SendPriority) return;
var val = Convert.ToInt32(state.val);
var idx = val / 100;
var prio = val % 100;
Expand All @@ -66,6 +70,7 @@ public static void Set(Connection connection, IncomingState state)
case "schedule":
{
if (settings.enabled == false) return;
if (!PuppeteerMod.Settings.SendSchedule) return;
var pair = Convert.ToString(state.val).Split(':');
if (pair.Length == 2)
{
Expand All @@ -86,13 +91,15 @@ public static void Set(Connection connection, IncomingState state)
}
case "grid":
{
if (!PuppeteerMod.Settings.SendGrid) return;
var grid = Tools.SafeParse(state.val, 4);
Renderer.RenderMap(puppeteer, grid);
break;
}
case "goto":
{
if (settings.enabled == false) return;
if (!PuppeteerMod.Settings.SendGoto) return;
var val = Convert.ToString(state.val);
var coordinates = val.Split(',').Select(v => { if (int.TryParse(v, out var n)) return n; else return -1000; }).ToArray();
if (coordinates.Length == 2)
Expand Down Expand Up @@ -154,13 +161,15 @@ public static void Set(Connection connection, IncomingState state)
case "action":
{
if (settings.enabled == false) return;
if (!PuppeteerMod.Settings.SendAction) return;
var id = Convert.ToString(state.val);
_ = Actions.RunAction(pawn, id);
break;
}
case "select":
{
var val = Convert.ToString(state.val);
if (!PuppeteerMod.Settings.SendSelect) return;
var coordinates = val.Split(',').Select(v => { if (int.TryParse(v, out var n)) return n; else return -1000; }).ToArray();
if (coordinates.Length == 2)
{
Expand Down Expand Up @@ -256,13 +265,15 @@ void renderOp()
case "gizmo":
{
if (settings.enabled == false) return;
if (!PuppeteerMod.Settings.SendGizmo) return;
var id = Convert.ToString(state.val);
_ = GizmosHandler.RunAction(pawn, id);
break;
}
case "consume":
{
if (settings.enabled == false) return;
if (!PuppeteerMod.Settings.SendConsume) return;
var id = Convert.ToString(state.val);
var thing = pawn.inventory.GetDirectlyHeldThings().FirstOrDefault(t => t.ThingID == id);
if (thing != null)
Expand All @@ -277,6 +288,7 @@ void renderOp()
case "drop":
{
if (settings.enabled == false) return;
if (!PuppeteerMod.Settings.SendDrop) return;
var id = Convert.ToString(state.val);
var thing = pawn.inventory.GetDirectlyHeldThings().FirstOrDefault(t => t.ThingID == id);
if (thing != null)
Expand Down
35 changes: 34 additions & 1 deletion Source/Mod/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Reflection;
using System.Timers;
using TwitchToolkit.PawnQueue;
using UnityEngine;
using Verse;
using static HarmonyLib.AccessTools;
Expand Down Expand Up @@ -147,6 +148,20 @@ public void SetEvent(PuppeteerEvent evt)
}
}

public static Pawn trygetpawnfromviewer(ViewerID thebase)
{

if (!((GameComponentPawns)Current.Game.GetComponent<GameComponentPawns>()).HasUserBeenNamed(thebase.name))
{
//Log.Warning("User " + thebase.name + " joined and tried to claim a unassigned TTK Pawn.");
return null;
}

return Find.Maps
.SelectMany(map => PlayerPawns.FreeColonists(map, false))
.FirstOrDefault(pawn => ((NameTriple)pawn.Name).Nick == thebase.name);
}

public void Message(byte[] msg)
{
if (connection == null) return;
Expand All @@ -164,7 +179,25 @@ public void Message(byte[] msg)
break;
}
case "join":
GeneralCommands.Join(connection, Join.Create(msg).viewer);
var joiner = Join.Create(msg).viewer;

GeneralCommands.Join(connection, joiner);

//Automagically assigning Pawns to Viewers with the same name (Sudo TTK automation)

if (!PuppeteerMod.Settings.TryMagic) break;

var Pup = State.Instance.PuppeteerForViewer(joiner);

if (Pup.puppet == null)
{
Pawn viewerpawn = trygetpawnfromviewer(joiner);
if (viewerpawn != null)
{
AssignViewerToPawn(joiner, viewerpawn);
Log.Warning("Automagically assigned " + joiner.name + " to his assigned TTK pawn.");
}
}
break;
case "leave":
GeneralCommands.Leave(Leave.Create(msg).viewer);
Expand Down
61 changes: 61 additions & 0 deletions Source/Mod/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ public class Settings
public int playerActionCooldownTicks = GenDate.TicksPerHour;
public bool sendChatResponsesToTwitch = false;

public bool SendAction = false;
public bool SendDrop = false;
public bool SendDrafted = false;
public bool SendHostileresponse = false;
public bool SendSchedule = true;
public bool SendGizmo = false;
public bool SendZone = false;
public bool SendGoto = true;
public bool SendSelect = false;
public bool SendConsume = true;
public bool SendGrid = true;
public bool SendGlobalJob = true;
public bool SendPriority = true;
public bool ForcePuppeteerChat = false;
public bool TryMagic = true;

public HashSet<string> menuCommands = new HashSet<string>();
}

Expand Down Expand Up @@ -63,6 +79,51 @@ public static void DoWindowContents(ref Settings settings, Rect inRect)

list.Gap(10f);
list.Dialog_Checkbox("SendChatResponsesToTwitch", ref settings.sendChatResponsesToTwitch);

list.Gap(10f);
list.Dialog_Checkbox("ForcePuppeteerChat", ref settings.ForcePuppeteerChat);

list.Gap(10f);
list.Dialog_Checkbox("TryMagic", ref settings.TryMagic);

list.Gap(10f);
list.Dialog_Checkbox("SendGrid", ref settings.SendGrid);

list.Gap(10f);
list.Dialog_Checkbox("SendAction", ref settings.SendAction);

list.Gap(10f);
list.Dialog_Checkbox("SendGizmo", ref settings.SendGizmo);

list.Gap(10f);
list.Dialog_Checkbox("SendSchedule", ref settings.SendSchedule);

list.Gap(10f);
list.Dialog_Checkbox("SendPriority", ref settings.SendSchedule);

list.Gap(10f);
list.Dialog_Checkbox("SendDrafted", ref settings.SendDrafted);

list.Gap(10f);
list.Dialog_Checkbox("SendDrop", ref settings.SendDrop);

list.Gap(10f);
list.Dialog_Checkbox("SendGoto", ref settings.SendGoto);

list.Gap(10f);
list.Dialog_Checkbox("SendHostileresponse", ref settings.SendHostileresponse);

list.Gap(10f);
list.Dialog_Checkbox("SendZone", ref settings.SendZone);

list.Gap(10f);
list.Dialog_Checkbox("SendSelect", ref settings.SendSelect);

list.Gap(10f);
list.Dialog_Checkbox("SendConsume", ref settings.SendConsume);

list.Gap(10f);
list.Dialog_Checkbox("SendJob", ref settings.SendGlobalJob);
}

list.End();
Expand Down
Loading