Skip to content
This repository has been archived by the owner on Feb 5, 2018. It is now read-only.

Commit

Permalink
Merge branch 'feature-tpapi' of github.com:ashbash1987/ktanemod-twitc…
Browse files Browse the repository at this point in the history
…hplays into feature-tpapi
  • Loading branch information
ashbash1987 committed Apr 20, 2017
2 parents 40d22a9 + 194e66f commit 31f9440
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 99 deletions.
20 changes: 18 additions & 2 deletions Assets/Scripts/ComponentSolvers/Modded/ProbingComponentSolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected override IEnumerator RespondToCommandInternal(string inputCommand)
_wires[4] == null || _wires[5] == null)
yield break;


var beforeStrikes = StrikeCount;
if (split.Length == 1 && split[0] == "cycle")
{
yield return "Reading the frequencies";
Expand All @@ -27,6 +27,13 @@ protected override IEnumerator RespondToCommandInternal(string inputCommand)
for (var i = 1; i < 6; i++)
{
yield return ConnectWires(i, 0);
if (beforeStrikes != StrikeCount)
{
//A strike somewhere else on the bomb has the possibility to change the frequencies, and thus
//ruin the reading.
yield return EnsureWiresConnected(4, 4);
yield break;
}
yield return new WaitForSeconds(2.0f);
}
yield return ConnectWires(4, 4); //Leave the blue wire disconnected.
Expand All @@ -41,7 +48,16 @@ protected override IEnumerator RespondToCommandInternal(string inputCommand)

yield return "Probing Solve Attempt";
yield return EnsureWiresConnected(red-1, blue-1);
yield return new WaitForSeconds(6.5f);

for (var i = 0; i < 65; i++)
{
yield return new WaitForSeconds(0.1f);
if (beforeStrikes == StrikeCount) continue;

//A strike somewhere else on the bomb has the possibility to cause a strike here.
yield return EnsureWiresConnected(4, 4);
yield break;
}
}


Expand Down
124 changes: 73 additions & 51 deletions Assets/Scripts/ComponentSolvers/Modded/SafetySafeComponentSolver.cs
Original file line number Diff line number Diff line change
@@ -1,98 +1,120 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;

public class SafetySafeComponentSolver : ComponentSolver
{
private static string[] DialPosNames = {"TL", "TM", "TR", "BL", "BM", "BR"};
private static Dictionary<string, int> DialPosNames = new Dictionary<string, int>()
{
{"tl",0}, {"tm",1}, {"tc",1}, {"tr",2},
{"lt",0}, {"mt",1}, {"ct",1}, {"rt",2},
{"bl",3}, {"bm",4}, {"bc",4}, {"br",5},
{"lb",3}, {"mb",4}, {"cb",4}, {"rb",5},
{"topleft",0}, {"topmiddle",1}, {"topcenter",1}, {"topcentre",1}, {"topright",2},
{"lefttop",0}, {"middletop",1}, {"centertop",1}, {"centretop",1}, {"righttop",2},
{"bottomleft",3}, {"bottommiddle",4}, {"bottomcenter",4}, {"bottomcentre",4}, {"bottomright",5},
{"leftbottom",3}, {"middlebottom",4}, {"centerbottom",4}, {"centrebottom",4}, {"rightbottom",5},
};

public SafetySafeComponentSolver(BombCommander bombCommander, MonoBehaviour bombComponent, IRCConnection ircConnection, CoroutineCanceller canceller) :
base(bombCommander, bombComponent, ircConnection, canceller)
{
_buttons = (Array)_buttonsField.GetValue(bombComponent.GetComponent(_componentType));
_buttons = (MonoBehaviour[])_buttonsField.GetValue(bombComponent.GetComponent(_componentType));
_lever = (MonoBehaviour)_leverField.GetValue(bombComponent.GetComponent(_componentType));
}

protected override IEnumerator RespondToCommandInternal(string inputCommand)
{
if (inputCommand.Equals("submit"))
var split = inputCommand.ToLowerInvariant().Split(new[] {" "}, StringSplitOptions.RemoveEmptyEntries);
int pos;

if (split[0] == "submit" && split.Length == 1)
{
yield return "submit";
DoInteractionStart(_lever);
yield return new WaitForSeconds(0.1f);
DoInteractionEnd(_lever);
yield break;
}
for(int a = 0; a < DialPosNames.Length; a++)
else if (split[0] == "cycle" && split.Length == 1)
{
string id = DialPosNames[a];
if (inputCommand.StartsWith(id, StringComparison.InvariantCultureIgnoreCase))
yield return "cycle";
for (var i = 0; i < 6; i++)
{
string after = inputCommand.Substring(id.Length);
if (after.Length == 0)
for (var j = 0; j < 12; j++)
{
IEnumerator coroutine = HandlePress(a);
while (coroutine.MoveNext())
yield return HandlePress(i);
yield return new WaitForSeconds(0.3f);
if (Canceller.ShouldCancel)
{
yield return coroutine.Current;
Canceller.ResetCancel();
yield break;
}
}
else
if(i < 5)
yield return new WaitForSeconds(0.5f);
}
}
else if (DialPosNames.TryGetValue(split[0], out pos))
{
if (split.Length == 1)
{
yield return split[0];
yield return HandlePress(pos);
}
else if (split.Length == 2)
{
int val = 0;
if (!int.TryParse(split[1], out val)) yield break;
val %= 12;
while (val < 0)
val += 12;
yield return split[0];
for (int z = 0; z < val; z++)
{
int val = 0;
if(!int.TryParse(inputCommand.Substring(2), out val)) yield break;
if(val < 0) yield break;
for(int z = 0; z < val; z++)
yield return HandlePress(pos);
if (Canceller.ShouldCancel)
{
IEnumerator coroutine = HandlePress(a);
while (coroutine.MoveNext())
{
yield return coroutine.Current;
}
if (Canceller.ShouldCancel)
{
Canceller.ResetCancel();
yield break;
}
yield return new WaitForSeconds(0.5f);
Canceller.ResetCancel();
yield break;
}
}
yield break;
}
}

string[] values = inputCommand.Split(new string[]{" "}, 99, StringSplitOptions.RemoveEmptyEntries);
if (values.Length != 6) yield break;

for (int a = 0; a < 6; a++)
else if (split.Length == 6)
{
int val = 0;
if(!int.TryParse(values[a], out val)) yield break;
if(val < 0) yield break;
for(int z = 0; z < val; z++)
int[] values = new int[6];
for (int a = 0; a < 6; a++)
{
IEnumerator coroutine = HandlePress(a);
while (coroutine.MoveNext())
{
yield return coroutine.Current;
}
if (Canceller.ShouldCancel)
{
Canceller.ResetCancel();
if (!int.TryParse(split[a], out values[a]))
yield break;
values[a] %= 12;
while (values[a] < 0)
values[a] += 12;
}

yield return inputCommand;
for (int a = 0; a < 6; a++)
{
for (int z = 0; z < values[a]; z++)
{
yield return HandlePress(a);
if (Canceller.ShouldCancel)
{
Canceller.ResetCancel();
yield break;
}
}
yield return new WaitForSeconds(0.2f);
}
}
}

private IEnumerator HandlePress(int pos)
{
MonoBehaviour button = (MonoBehaviour)_buttons.GetValue(pos);
DoInteractionStart(button);
DoInteractionStart(_buttons[pos]);
yield return new WaitForSeconds(0.1f);
DoInteractionEnd(button);
DoInteractionEnd(_buttons[pos]);
}

static SafetySafeComponentSolver()
Expand All @@ -105,6 +127,6 @@ static SafetySafeComponentSolver()
private static Type _componentType = null;
private static FieldInfo _buttonsField, _leverField = null;

private Array _buttons = null;
private MonoBehaviour[] _buttons = null;
private MonoBehaviour _lever = null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,22 @@ private IEnumerator ReleaseCoroutine(string second)

int timeTarget = sortedTimes[0];
sortedTimes.RemoveAt(0);

int waitTime = (int)((float)CommonReflectedTypeInfo.TimeRemainingField.GetValue(timerComponent) + 0.25f);
waitTime -= timeTarget;
if (waitTime >= 30)
{
_musicPlayer = MusicPlayer.StartRandomMusic();
}

float timeRemaining = float.PositiveInfinity;
while (timeRemaining > 0.0f)
{
if (Canceller.ShouldCancel)
{
if (waitTime >= 30)
_musicPlayer.StopMusic();

Canceller.ResetCancel();
yield break;
}
Expand All @@ -94,9 +105,18 @@ private IEnumerator ReleaseCoroutine(string second)

if (timeRemaining < timeTarget)
{
if (waitTime >= 30)
_musicPlayer.StopMusic();

if(sortedTimes.Count == 0) yield break;
timeTarget = sortedTimes[0];
sortedTimes.RemoveAt(0);

waitTime = (int)timeRemaining;
waitTime -= timeTarget;
if (waitTime >= 30)
_musicPlayer = MusicPlayer.StartRandomMusic();

continue;
}
if (timeRemaining == timeTarget)
Expand All @@ -108,6 +128,8 @@ private IEnumerator ReleaseCoroutine(string second)
}
DoInteractionEnd(_button);
_held = false;
if (waitTime >= 30)
_musicPlayer.StopMusic();
break;
}

Expand All @@ -126,4 +148,5 @@ static SquareButtonComponentSolver()

private MonoBehaviour _button = null;
private bool _held = false;
private MusicPlayer _musicPlayer = null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,21 @@ private IEnumerator ReleaseCoroutine(string second)

int timeTarget = sortedTimes[0];
sortedTimes.RemoveAt(0);
int waitingTime = (int)((float)CommonReflectedTypeInfo.TimeRemainingField.GetValue(timerComponent) + 0.25f);
waitingTime -= timeTarget;

if (waitingTime >= 30)
{
_musicPlayer = MusicPlayer.StartRandomMusic();
}

float timeRemaining = float.PositiveInfinity;
while (timeRemaining > 0.0f)
{
if (Canceller.ShouldCancel)
{
Canceller.ResetCancel();
yield break;
break;
}

timeRemaining = (int)((float)CommonReflectedTypeInfo.TimeRemainingField.GetValue(timerComponent) + 0.25f);
Expand All @@ -82,6 +90,12 @@ private IEnumerator ReleaseCoroutine(string second)

yield return null;
}

if (waitingTime >= 30)
{
_musicPlayer.StopMusic();
}

}

static TurnTheKeyComponentSolver()
Expand All @@ -94,4 +108,5 @@ static TurnTheKeyComponentSolver()
private static FieldInfo _lockField = null;

private MonoBehaviour _lock = null;
private MusicPlayer _musicPlayer = null;
}
Loading

0 comments on commit 31f9440

Please sign in to comment.