public void Lookup(string perp, int bits, string userInput) { KeyValuePair <string, EventInfo> Event = EventDictionary.Where(it => it.Value.BitCost > 0 && it.Value.BitCost <= bits)?.OrderByDescending(it => it.Value.BitCost)?.FirstOrDefault() ?? default; if (!Event.Equals(default(KeyValuePair <string, EventInfo>))) { switch (Event.Value) { case TimedEventInfo timed: TimedEventInfo tei = new TimedEventInfo(perp, timed); //controller._log.LogMessage(Event.Key); ActionQueue.Add(new KeyValuePair <string, EventInfo>(Event.Key, tei)); controller.timer.AddQueueEvent(Event.Key); break; case DataEvent dataEvent: DataEvent de = new DataEvent(perp, dataEvent, userInput); ActionQueue.Add(new KeyValuePair <string, EventInfo>(Event.Key, de)); controller.timer.AddQueueEvent(Event.Key); break; default: EventInfo ei = new EventInfo(perp, Event.Value); //controller._log.LogMessage(Event.Key); ActionQueue.Add(new KeyValuePair <string, EventInfo>(Event.Key, ei)); controller.timer.AddQueueEvent(Event.Key); break; } } }
public static void Postfix() { TimerCooldown.Update(); try { while (EventLookup.TimedActionsQueue.Count > 0) { // Execute all the timed event cleanup code BEFORE any of the other events Action localAction = EventLookup.TimedActionsQueue[0]; localAction(); EventLookup.TimedActionsQueue.RemoveAt(0); } if (EventLookup.ActionQueue.Count > 0) { KeyValuePair <string, EventInfo> localEventInfo = new KeyValuePair <string, EventInfo>(); int eventIndex = -1; for (int i = 0; i < EventLookup.ActionQueue.Count; i++) { KeyValuePair <string, EventInfo> keyValuePair = EventLookup.ActionQueue[i]; if (EventLookup.RunningEventIDs.Contains(keyValuePair.Key) || EventLookup.Cooldowns.ContainsKey(keyValuePair.Key)) { continue; } // Safe to use, doesnt have cooldown / is currently in use localEventInfo = keyValuePair; eventIndex = i; } if (eventIndex >= 0) { EventLookup.ActionQueue.RemoveAt(eventIndex); TimerCooldown.RemoveQueueText(localEventInfo.Key); if (localEventInfo.Value is TimedEventInfo) { // If its a timed event, pass that info to the TimerCooldown TimedEventInfo timedEventInfo = (TimedEventInfo)localEventInfo.Value; TimerCooldown.AddCooldown(localEventInfo.Key, timedEventInfo); // Don't start the cooldown yet, cooldown starts after the cleanup code } else { // Otherwise quickly make it pop up in the UI TimerCooldown.AddCooldown(localEventInfo.Key, 1, localEventInfo.Value); EventLookup.Cooldowns.Add(localEventInfo.Key, Time.time); TimerCooldown.AddCooldownText(localEventInfo.Key, localEventInfo.Value.CooldownSeconds, localEventInfo.Value); } localEventInfo.Value.Action.Invoke(); } } } catch (Exception e) { Console.WriteLine("Failed to invoke action " + e.Message); Console.WriteLine(e.StackTrace); } }
internal void AddCooldown(string text, TimedEventInfo timedEvent) { CustomEvent cooldownText = new CustomEvent(timedEvent.TimerLength); cooldownText.SetTimedEvent(new KeyValuePair <string, TimedEventInfo>(text, timedEvent)); controller.eventLookup.RunningEventIDs.Add(text); customTimerEvents.Add(cooldownText); }
public static void AddCooldown(string text, TimedEventInfo timedEvent) { if (!initialised) { Initialise(); } CustomText cooldownText = new CustomText(text, timedEvent.TimerLength, 0, true); cooldownText.SetTimedEvent(new KeyValuePair <string, TimedEventInfo>(text, timedEvent)); EventLookup.RunningEventIDs.Add(text); customTimerTexts.Add(cooldownText); }
public void Lookup(string EventText, string perp, string userInput) { if (EventDictionary.TryGetValue(EventText.Trim(), out EventInfo eventInfo)) { switch (eventInfo) { case TimedEventInfo timed: TimedEventInfo tei = new TimedEventInfo(perp, timed); ActionQueue.Add(new KeyValuePair <string, EventInfo>(EventText, tei)); break; default: EventInfo ei = new EventInfo(perp, eventInfo); ActionQueue.Add(new KeyValuePair <string, EventInfo>(EventText, ei)); break; } } }
public static void Postfix() { TimerCooldown.Update(); try { while (EventLookup.TimedActionsQueue.Count > 0) { // Execute all the timed event cleanup code BEFORE any of the other events Tuple <string, string, TimedEventInfo> localAction = EventLookup.TimedActionsQueue[0]; localAction.Item3.TimedAction.Invoke(); EventLookup.TimedActionsQueue.RemoveAt(0); } if (EventLookup.ActionQueue.Count > 0) { Tuple <string, string, EventInfo> localEventInfo = null; int eventIndex = -1; for (int i = 0; i < EventLookup.ActionQueue.Count; i++) { Tuple <string, string, EventInfo> data = EventLookup.ActionQueue[i]; if (!EventLookup.IsRunningOrCooldown(data.Item1)) { // Safe to use, doesnt have cooldown / is currently in use localEventInfo = data; eventIndex = i; } } if (eventIndex >= 0) { EventLookup.ActionQueue.RemoveAt(eventIndex); TimerCooldown.RemoveQueueText(localEventInfo.Item1); if (localEventInfo.Item3 is TimedEventInfo) { // If its a timed event, pass that info to the TimerCooldown TimedEventInfo timedEventInfo = (TimedEventInfo)localEventInfo.Item3; TimerCooldown.AddCooldown(localEventInfo.Item1, new Tuple <string, string, TimedEventInfo>(localEventInfo.Item1, localEventInfo.Item2, timedEventInfo)); // Don't start the cooldown yet, cooldown starts after the cleanup code } else { // Otherwise quickly make it pop up in the UI TimerCooldown.AddCooldown(localEventInfo.Item1, 1, localEventInfo); EventLookup.Cooldowns.Add(localEventInfo.Item1, Time.time); TimerCooldown.AddCooldownText(localEventInfo.Item1, localEventInfo.Item3.CooldownSeconds, localEventInfo); } if (localEventInfo.Item3.RequiresUsername) { localEventInfo.Item3.ActionWithUsername.Invoke(localEventInfo.Item2); } else { localEventInfo.Item3.Action.Invoke(); } } } } catch (Exception e) { Console.WriteLine("Failed to invoke action " + e.Message); Console.WriteLine(e.StackTrace); } }