private void GetNeedyModules() { UnityEngine.Object modManager = ModManager; MethodInfo getNeedyModulesMethod = _modManagerType.GetMethod("GetNeedyModules", BindingFlags.Instance | BindingFlags.Public); IList needyModuleList = getNeedyModulesMethod.Invoke(modManager, null) as IList; Type modNeedyComponentType = ReflectionHelper.FindTypeInGame("ModNeedyComponent"); FieldInfo moduleField = modNeedyComponentType.GetField("module", BindingFlags.Instance | BindingFlags.NonPublic); foreach (object needyModule in needyModuleList) { KMNeedyModule module = moduleField.GetValue(needyModule) as KMNeedyModule; string moduleTypeName = module.ModuleType; if (!_allNeedyModules.ContainsKey(moduleTypeName)) { _allNeedyModules[moduleTypeName] = new NeedyModule(module, needyModule); } else { Debug.LogErrorFormat("***** A duplicate needy module was found under the name {0}! *****", moduleTypeName); } } }
public void Start() { bombInfo = GetComponent <KMBombInfo>(); needyModule = GetComponent <KMNeedyModule>(); bombAudio = GetComponent <KMAudio>(); data = GetComponent <TechSupportData>(); interruptableModules = new List <InterruptableModule>(); options = new List <Tuple <string, int> >(); allErrors = new List <ErrorData>(); needyModule.OnActivate += OnActivate; needyModule.OnNeedyActivation += Interrupt; needyModule.OnTimerExpired += OnTimerExpired; screenOverlay.Toggle(false); // TODO: do something with KMSeedable here. monoRandom = new MonoRandom(0); data.Generate(monoRandom, 16, 12, 9, 9, 9); // Adds methods to buttons. okButton.AddListener(OnOKClicked); upButton.AddListener(OnUpClicked); downButton.AddListener(OnDownClicked); StartCoroutine(DelayedStart()); }
public static void HandleForcedSolve(MonoBehaviour bombComponent) { try { TwitchComponentHandle handle = null; KMBombModule module = bombComponent.GetComponent <KMBombModule>(); KMNeedyModule needyModule = bombComponent.GetComponent <KMNeedyModule>(); if (module != null) { handle = BombMessageResponder.Instance.ComponentHandles.Where(x => x.bombComponent.GetComponent <KMBombModule>() != null) .FirstOrDefault(x => x.bombComponent.GetComponent <KMBombModule>() == module); } else if (needyModule != null) { handle = BombMessageResponder.Instance.ComponentHandles.Where(x => x.bombComponent.GetComponent <KMBombModule>() != null) .FirstOrDefault(x => x.bombComponent.GetComponent <KMBombModule>() == needyModule); } if (handle != null) { HandleForcedSolve(handle); } else { CommonReflectedTypeInfo.HandlePassMethod.Invoke(bombComponent, null); foreach (MonoBehaviour behaviour in bombComponent.GetComponentsInChildren <MonoBehaviour>(true)) { behaviour.StopAllCoroutines(); } } } catch (Exception ex) { DebugHelper.LogException(ex, "An exception occured while silently soving a module:"); } }
#pragma warning restore 649 public static string GetModuleID(BombComponent bombComponent) { switch (bombComponent.ComponentType) { case ComponentTypeEnum.Mod: KMBombModule bombModule = bombComponent.GetComponent <KMBombModule>(); if (bombModule != null) { return(bombModule.ModuleType); } break; case ComponentTypeEnum.NeedyMod: KMNeedyModule needyModule = bombComponent.GetComponent <KMNeedyModule>(); if (needyModule != null) { return(needyModule.ModuleType); } break; case ComponentTypeEnum.Empty: case ComponentTypeEnum.Timer: break; default: return(bombComponent.ComponentType.ToString()); } return(null); }
private void Start() { if (TPCoroutineQueue == null) { TPCoroutineQueue = new GameObject().AddComponent <TPCoroutineQueue>(); } if (Module == null) { return; } ModuleID = counter++; IDTextMesh.text = ModuleID.ToString(); FindTwitchCommandMethod(); transform.gameObject.SetActive(true); BombModule = Module.GetComponent <KMBombModule>(); NeedyModule = Module.GetComponent <KMNeedyModule>(); if (BombModule != null) { BombModule.OnPass += HandlePass; BombModule.OnStrike += HandleStrike; } else if (NeedyModule != null) { NeedyModule.OnStrike += HandleStrike; } TwitchPlaysModules.Add(this); if (_moduleCameras == null) { _moduleCameras = ModuleCameras; } }
void Awake() { NeedyModule = GetComponent <KMNeedyModule> (); NeedyModule.OnNeedyActivation += OnNeedyActivation; NeedyModule.OnNeedyDeactivation += OnNeedyDeactivation; NeedyModule.OnTimerExpired += OnTimerExpired; /*MoveLeftButton.OnInteract += delegate() { return MoveLeft (); }; * MoveRightButton.OnInteract += delegate() { return MoveRight (); }; * TurnLeftButton.OnInteract += delegate() { return TurnLeft (); }; * TurnRightButton.OnInteract += delegate() { return TurnRight (); }; * DownButton.OnInteract += delegate() { return Down (); };*/ ObjectGrid = new GameObject[G_WIDTH, G_WIDTH]; GameBoard = new TetrisBoard(G_WIDTH, G_WIDTH); // Populate the grid for (int x = 0; x < G_WIDTH; x++) { GameObject col = Board.transform.Find("Col" + x).gameObject; for (int y = 0; y < G_WIDTH; y++) { GameObject go = col.transform.Find("Quad" + y).gameObject; go.SetActive(false); ObjectGrid [x, G_WIDTH - y - 1] = go; } } tetr = null; piecesLeft = 0; UpdateGrid(); }
public static void Log(this KMNeedyModule module, object message) { if (module.GetIDNumber() == 0) { module.GenerateLogFriendlyName(); } Debug.LogFormat("[{0}] {1}", module.name, message); }
public static void LogFormat(this KMNeedyModule module, string format, params object[] args) { if (module.GetIDNumber() == 0) { module.GenerateLogFriendlyName(); } Debug.LogFormat("[{0}] {1}", module.name, string.Format(format, args)); }
public static ComponentSolver CreateSolver(BombCommander bombCommander, MonoBehaviour bombComponent, ComponentTypeEnum componentType, IRCConnection ircConnection, CoroutineCanceller canceller) { switch (componentType) { case ComponentTypeEnum.Wires: return(new WireSetComponentSolver(bombCommander, bombComponent, ircConnection, canceller)); case ComponentTypeEnum.Keypad: return(new KeypadComponentSolver(bombCommander, bombComponent, ircConnection, canceller)); case ComponentTypeEnum.BigButton: return(new ButtonComponentSolver(bombCommander, bombComponent, ircConnection, canceller)); case ComponentTypeEnum.Memory: return(new MemoryComponentSolver(bombCommander, bombComponent, ircConnection, canceller)); case ComponentTypeEnum.Simon: return(new SimonComponentSolver(bombCommander, bombComponent, ircConnection, canceller)); case ComponentTypeEnum.Venn: return(new VennWireComponentSolver(bombCommander, bombComponent, ircConnection, canceller)); case ComponentTypeEnum.Morse: return(new MorseCodeComponentSolver(bombCommander, bombComponent, ircConnection, canceller)); case ComponentTypeEnum.WireSequence: return(new WireSequenceComponentSolver(bombCommander, bombComponent, ircConnection, canceller)); case ComponentTypeEnum.Password: return(new PasswordComponentSolver(bombCommander, bombComponent, ircConnection, canceller)); case ComponentTypeEnum.Maze: return(new InvisibleWallsComponentSolver(bombCommander, bombComponent, ircConnection, canceller)); case ComponentTypeEnum.WhosOnFirst: return(new WhosOnFirstComponentSolver(bombCommander, bombComponent, ircConnection, canceller)); case ComponentTypeEnum.NeedyVentGas: return(new NeedyVentComponentSolver(bombCommander, bombComponent, ircConnection, canceller)); case ComponentTypeEnum.NeedyCapacitor: return(new NeedyDischargeComponentSolver(bombCommander, bombComponent, ircConnection, canceller)); case ComponentTypeEnum.NeedyKnob: return(new NeedyKnobComponentSolver(bombCommander, bombComponent, ircConnection, canceller)); case ComponentTypeEnum.Mod: KMBombModule solvableModule = bombComponent.GetComponent <KMBombModule>(); return(CreateModComponentSolver(bombCommander, bombComponent, ircConnection, canceller, solvableModule.ModuleType)); case ComponentTypeEnum.NeedyMod: KMNeedyModule needyModule = bombComponent.GetComponent <KMNeedyModule>(); return(CreateModComponentSolver(bombCommander, bombComponent, ircConnection, canceller, needyModule.ModuleType)); default: throw new NotSupportedException(string.Format("Currently {0} is not supported by 'Twitch Plays'.", (string)CommonReflectedTypeInfo.ModuleDisplayNameField.Invoke(bombComponent, null))); } }
private static IEnumerator KeepUnsupportedNeedySilent(KMNeedyModule needyModule) { while (true) { yield return(null); needyModule.SetNeedyTimeRemaining(99f); } }
public void Awake() { KMNeedyModule needy = GetComponent <KMNeedyModule>(); needy.OnNeedyActivation += OnNeedyActivation; needy.OnNeedyDeactivation += OnNeedyDeactivation; needy.OnTimerExpired += OnTimerExpired; trigger = GetComponent <BoxCollider>(); trigger.enabled = false; }
public static void DeactivateNeedyModule(TwitchComponentHandle handle) { handle.ircConnection.SendMessage(TwitchPlaySettings.data.UnsupportedNeedyWarning); KMNeedyModule needyModule = handle.bombComponent.GetComponent <KMNeedyModule>(); needyModule.OnNeedyActivation = () => { needyModule.StartCoroutine(KeepUnsupportedNeedySilent(needyModule)); }; needyModule.OnNeedyDeactivation = () => { needyModule.StopAllCoroutines(); needyModule.HandlePass(); }; needyModule.OnTimerExpired = () => { needyModule.StopAllCoroutines(); needyModule.HandlePass(); }; needyModule.WarnAtFiveSeconds = false; }
private void Start() { _moduleId = _moduleIdCounter++; _module = GetComponent <KMNeedyModule>(); _textMesh = _module.GetComponentInChildren <TextMesh>(); _bomb = _module.GetComponentInParent <FloatingHoldable>(); _module.OnActivate += Activate; _module.OnTimerExpired += TimerExpired; _module.OnNeedyActivation += NeedyActivation; _module.OnNeedyDeactivation += NeedyDeactivation; }
public static int GetIDNumber(this KMNeedyModule module) { int id; string[] split = module.name.Split('#'); if (split.Length < 2) { return(0); } return(int.TryParse(split[1], out id) ? id : 0); }
internal ModuleConfig(KMBombModule kmBombModule = null, KMBossModule kmBossModule = null, KMColorblindMode kmColorblindMode = null, KMNeedyModule kmNeedyModule = null, Tuple <Action, KMBombInfo>?onTimerTick = null) { KMBombModule = kmBombModule; KMBossModule = kmBossModule; KMColorblindMode = kmColorblindMode; KMNeedyModule = kmNeedyModule; OnTimerTick = onTimerTick; }
public static void SetResetDelayTime(this KMNeedyModule module, float min, float max) { if (module.gameObject.GetComponent("NeedyComponent") == null) { return; // Running in the Test Harness? } Type targetType = module.gameObject.GetComponent("NeedyComponent").GetType(); FieldInfo resetMin = targetType.GetField("ResetDelayMin", BindingFlags.Public | BindingFlags.Instance); FieldInfo resetMax = targetType.GetField("ResetDelayMax", BindingFlags.Public | BindingFlags.Instance); resetMin.SetValue(module.gameObject.GetComponent("NeedyComponent"), min); resetMax.SetValue(module.gameObject.GetComponent("NeedyComponent"), max); }
void Awake() { moduleId = moduleIdCounter++; needyModule = GetComponent <KMNeedyModule>(); needyModule.OnNeedyActivation += OnNeedyActivation; needyModule.OnNeedyDeactivation += OnNeedyDeactivation; needyModule.OnTimerExpired += OnTimerExpired; foreach (KMSelectable button in responseButtons) { KMSelectable pressedResponse = button; button.OnInteract += delegate() { ResponsePress(pressedResponse); return(false); }; } }
void Awake() { moduleId = moduleIdCounter++; needyModule = GetComponent <KMNeedyModule>(); needyModule.OnNeedyActivation += OnNeedyActivation; needyModule.OnNeedyDeactivation += OnNeedyDeactivation; needyModule.OnTimerExpired += OnTimerExpired; foreach (LightInformation button in buttons) { LightInformation pressedButton = button; button.selectable.OnInteract += delegate() { ButtonPress(pressedButton); return(false); }; } }
void Start() { //Set module ID moduleId = moduleIdCounter++; //Set up needy module needyModule = GetComponent <KMNeedyModule>(); needyModule.OnNeedyActivation += delegate { RandomizeOrientation(); }; needyModule.OnNeedyDeactivation += delegate { HideTriangles(); }; needyModule.OnTimerExpired += delegate { needyModule.HandleStrike(); HideTriangles(false); }; //Other variables moduleActive = false; rotation = new Vector3(90, 0, 0); //Add solutions to dictionary of solutions solutions = new Dictionary <string, int>() { { "3102", 0 }, { "1320", 2 }, { "0213", 1 }, { "2103", 2 }, { "3120", 3 }, { "2013", 0 }, { "3210", 1 }, { "2031", 1 }, { "1032", 2 }, { "3021", 3 }, { "0123", 3 }, { "2130", 1 }, { "1203", 0 }, { "1302", 3 }, { "0231", 3 }, { "0321", 2 }, { "3201", 1 }, { "3012", 2 }, { "0312", 0 }, { "0132", 1 }, { "1230", 3 }, { "2301", 0 }, { "2310", 2 }, { "1023", 0 } }; //Set up button selections for (int c = 0; c < buttons.Length; c++) { int d = c; buttons[c].OnInteract += delegate { ButtonPress(d); return(false); }; } }
void Awake() { moduleId = moduleIdCounter++; needyModule = GetComponent <KMNeedyModule>(); needyModule.OnNeedyActivation += OnNeedyActivation; needyModule.OnNeedyDeactivation += OnNeedyDeactivation; needyModule.OnTimerExpired += OnTimerExpired; foreach (KMSelectable stack in stacks) { KMSelectable pressedStack = stack; stack.OnInteract += delegate() { StackPress(pressedStack); return(false); }; } }
public virtual void Awake() { string moduleType; this.KMBombModule = this.GetComponent <KMBombModule>(); if (this.KMBombModule != null) { moduleType = this.KMBombModule.ModuleType; } else { this.KMNeedyModule = this.GetComponent <KMNeedyModule>(); if (this.KMNeedyModule != null) { moduleType = this.KMNeedyModule.ModuleType; } else { moduleType = this.gameObject.name; Debug.LogError($"[{moduleType}] Module is missing a KMBombModule or KMNeedyModule component.", this); } } moduleIndices.TryGetValue(moduleType, out var id); this.moduleID = ++id; moduleIndices[moduleType] = id; #if (DEBUG) this.Log("Assembly was compiled in debug mode. Activating test model."); #else var aprilFools = DateTime.Now.Month == 4 && DateTime.Now.Day == 1; // Yes, the whole day. if (!aprilFools) { try { this.AwakeLive(); this.TestModel?.SetActive(false); return; } catch (TypeLoadException) { this.LogError("Can't load BombGenerator. Activating test model."); } } else { this.Log("This is a defective module. April Fools! Activating test model."); } #endif this.TestMode = true; this.TestModel?.SetActive(true); this.AwakeTest(); }
protected string GetModuleType() { KMBombModule bombModule = BombComponent.GetComponent <KMBombModule>(); if (bombModule != null) { return(bombModule.ModuleType); } KMNeedyModule needyModule = BombComponent.GetComponent <KMNeedyModule>(); if (needyModule != null) { return(needyModule.ModuleType); } return(null); }
private void Awake() { KMNeedyModule needy = GetComponent <KMNeedyModule>(); needy.OnNeedyActivation += OnNeedyActivation; needy.OnNeedyDeactivation += OnNeedyDeactivation; needy.OnTimerExpired += OnTimerExpired; planeMats = new Renderer[3]; for (int i = 0; i < 3; i++) { planeMats[i] = planes[i].GetComponentInChildren <KMMaterialInfo>().GetComponent <Renderer>(); planeMats[i].material.color = Color.gray; planes[i].OnInteract += planes[i].GetComponent <PlaneState>().OnInteract; } }
public MonoRandom GetRNG() { if (Application.isEditor) { return(new MonoRandom(_seed)); } GameObject ruleSeedModifierAPIGameObject = GameObject.Find("RuleSeedModifierProperties"); if (ruleSeedModifierAPIGameObject == null) // Rule Seed Modifer is not installed { return(new MonoRandom(1)); } IDictionary <string, object> ruleSeedModifierAPI = ruleSeedModifierAPIGameObject.GetComponent <IDictionary <string, object> >(); if (!ruleSeedModifierAPI.ContainsKey("RuleSeed")) { return(new MonoRandom(1)); } //Add the module to the list of supported modules if possible. if (ruleSeedModifierAPI.ContainsKey("AddSupportedModule")) { string key; KMBombModule bombModule = GetComponent <KMBombModule>(); KMNeedyModule needyModule = GetComponent <KMNeedyModule>(); if (bombModule != null) { key = bombModule.ModuleType; } else if (needyModule != null) { key = needyModule.ModuleType; } else { key = Regex.Replace(gameObject.name, @"\(Clone\)$", ""); } ruleSeedModifierAPI["AddSupportedModule"] = key; } return(new MonoRandom((ruleSeedModifierAPI["RuleSeed"] as int?) ?? 1)); }
void Awake() { moduleId = moduleIdCounter++; Needy = GetComponent <KMNeedyModule>(); Needy.OnNeedyActivation += OnNeedyActivation; Needy.OnNeedyDeactivation += OnNeedyDeactivation; Needy.OnTimerExpired += OnTimerExpired; foreach (KMSelectable button in buttons) { button.OnInteract += delegate() { buttonPress(button); return(false); }; } //button.OnInteract += delegate () { PressButton(); return false; }; }
void Awake() { moduleId = moduleIdCounter++; Needy = GetComponent <KMNeedyModule>(); Needy.OnNeedyActivation += OnNeedyActivation; Needy.OnNeedyDeactivation += OnNeedyDeactivation; Needy.OnTimerExpired += OnTimerExpired; emojiSprite = 0; Activated = 54; EmojiShow.GetComponent <MeshRenderer>().material = Emoji[emojiSprite]; if (Activated <= 1) { Bandage.OnInteract += delegate() { PressPlay(); return(false); }; } else { Bandage.OnInteract += delegate() { PressPlay(); return(true); }; } }
internal static void Unassign(this KMNeedyModule kmNeedyModule, Func <Action> onActivateNeedy = null, Func <Action> onNeedyActivation = null, Func <Action> onNeedyDeactivation = null, Func <Action> onTimerExpired = null, ModuleScript moduleScript = null) { if (kmNeedyModule == null) { throw new ArgumentNullException("The KMNeedyModule is null. You cannot assign events to a KMNeedyModule without a reference to a KMNeedyModule."); } if (onActivateNeedy != null) { kmNeedyModule.OnActivate -= delegate() { onActivateNeedy.Invoke().Invoke(); } } ; if (onNeedyActivation != null) { kmNeedyModule.OnNeedyActivation -= delegate() { if (moduleScript != null) { moduleScript.IsNeedyActive = true; } onNeedyActivation.Invoke().Invoke(); } } ; if (onNeedyDeactivation != null) { kmNeedyModule.OnNeedyDeactivation -= delegate() { if (moduleScript != null) { moduleScript.IsNeedyActive = false; } onNeedyDeactivation.Invoke().Invoke(); } } ; if (onTimerExpired != null) { kmNeedyModule.OnTimerExpired -= delegate() { onTimerExpired.Invoke().Invoke(); } } ; }
public ModSettings(KMNeedyModule module) { ModuleName = module.ModuleType; }
public NeedyModule(KMNeedyModule needyBombModule, object component) { NeedyBombModule = needyBombModule; Component = component; }
public static void FromModule(KMNeedyModule module, float time) { module.GetComponent("BombComponent").GetValue <object>("Bomb").CallMethod <object>("GetTimer").SetValue("TimeRemaining", time); }