public void Input(string?message, [CallerMemberName] string?previousMethodName = null, [CallerLineNumber] int callermemberlineNo = 0, [CallerFilePath] string?calledFilePath = null) { if (string.IsNullOrEmpty(message)) { return; } LogMessageReceived?.Invoke(this, new LogMessageEventArgs(LogIdentifier, message, DateTime.Now, LogLevels.Input, previousMethodName, callermemberlineNo, calledFilePath)); OnInputReceived?.Invoke(this, new EventArgsBase(LogIdentifier, DateTime.Now, message, previousMethodName, callermemberlineNo, calledFilePath)); }
private void OnSubscriberReceived(object sender, OnSubscriptionEventArgs e) { OnInputReceived?.Invoke(new object[] { e.UserNotice }); }
public override bool OnInputEvent(SInputEvent arg0) { OnInputReceived?.Invoke(arg0); return(false); }
private async void StatusLoop() { try { Dictionary <string, DateTime> exceptions = new Dictionary <string, DateTime>(); bool connected = false; while (!statusToken.IsCancellationRequested && Running) { try { this.connected = tcp.Client.IsConnected(); if (connected != this.connected) { connected = this.connected; OnConnectChanged?.Invoke(this.connected); } if (!this.connected) { using (Ping ping = new Ping()) { PingReply reply = ping.Send(Host); if (reply.Status == IPStatus.Success) { CreateClient(); } } continue; } OnOutputReceived?.Invoke(GetOutput(OutputStartAddress, OutputChannelNumber)); OnInputReceived?.Invoke(GetInput(InputStartAddress, InputChannelNumber)); } catch (Exception ex) { bool writable = false; if (!exceptions.ContainsKey(ex.Message)) { exceptions.Add(ex.Message, DateTime.Now); writable = true; } else { if ((DateTime.Now - exceptions[ex.Message]) < TimeSpan.FromSeconds(60)) { continue; } exceptions[ex.Message] = DateTime.Now; writable = true; } if (writable) { OnException?.Invoke(ex); } } finally { if (!statusToken.IsCancellationRequested && Running) { await Task.Delay(DelayTime); } } } } catch (OperationCanceledException) { } catch (Exception ex) { OnException?.Invoke(ex); } if (Running) { BeginStatusListener(); } }
public void ExecuteTurn() { if (currentState == State.END) { return; } // Don't do anything if battle is over if (currentState == State.START) { //Add effects of all Pokemon Abilities in battle foreach (Team team in Teams) { foreach (Slot slot in team) { RegisterEffect(slot.Pokemon.Ability.newEffect(this, slot.Pokemon)); } } OnBattleStart?.Invoke(this, BattleArgs); currentState = State.IN_PROGRESS; } OnTurnStart?.Invoke(this, BattleArgs); /* First we enqueue BattleActionRequests for all battle slots that are still in play. The * purpose of this is to allow move effects to trigger based on the enqueue'ing of the * BattleActionRequests. This allows effects from moves like Taunt modify which battlers * we make BattleActionRequests for. */ foreach (Team team in Teams) { foreach (Slot slot in team) { if (slot.IsInPlay) { MessageQueue.Enqueue(new Request(slot)); } } } actionRequests.Clear(); Flush(); RequestInputEventArgs requestInputEventArgs = new RequestInputEventArgs(this, actionRequests); OnRequestInput?.Invoke(this, requestInputEventArgs); List <IAction> actions = new List <IAction>(InputProvider.ProvideActions(this, actionRequests)); InputReceivedEventArgs inputReceivedEventArgs = new InputReceivedEventArgs(this, actionRequests, actions); OnInputReceived?.Invoke(this, inputReceivedEventArgs); actions.Sort(ActionComparer); foreach (IAction action in actions) { MessageQueue.Enqueue(action); } while (true) { Flush(); List <Request> requests = new List <Request>(); foreach (Team team in Teams) { foreach (Slot slot in team) { if (slot.Pokemon.HasFainted() && !slot.Participant.HasLost()) { requests.Add(new Request(slot)); } } } if (requests.Count == 0) { break; } IList <SwapPokemon> swapPokemonActions = InputProvider.ProvideSwapPokemon(this, requests); foreach (SwapPokemon swapPokemonAction in swapPokemonActions) { MessageQueue.Enqueue(swapPokemonAction); } } CurrentWeather.DecrementTurnCounter(); if (CurrentWeather.IsComplete) { WeatherCompletedEventArgs weatherCompletedEventArgs = new WeatherCompletedEventArgs(this, CurrentWeather); OnWeatherCompleted?.Invoke(this, weatherCompletedEventArgs); MessageQueue.AddFirst(new WeatherChange(SurroundingWeather, -1)); Broadcast(); } OnTurnEnd?.Invoke(this, BattleArgs); /* * Why is this loop run after OnTurnEnd is called? * We need to be able to process events that occur just before the end of the turn. */ while (true) { Flush(); List <Request> requests = new List <Request>(); foreach (Team team in Teams) { foreach (Slot slot in team) { if (slot.Pokemon.HasFainted() && !slot.Participant.HasLost()) { requests.Add(new Request(slot)); } } } if (requests.Count == 0) { break; } IList <SwapPokemon> swapPokemonActions = InputProvider.ProvideSwapPokemon(this, requests); foreach (SwapPokemon swapPokemonAction in swapPokemonActions) { MessageQueue.Enqueue(swapPokemonAction); } } if (this.IsComplete()) { BattleEndEventArgs battleEndEventArgs = new BattleEndEventArgs(this, this.Winner()); OnBattleEnd?.Invoke(this, battleEndEventArgs); currentState = State.END; } TurnCounter += 1; }
private void OnChatMessageReceived(object sender, OnChatMessageReceivedEventArgs e) { OnInputReceived?.Invoke(new object[] { e.ChatMessage }); }
private void OnUserJoined(object sender, OnUserJoinedEventArgs e) { OnInputReceived?.Invoke(new object[] { e.UserState }); }
private void OnUserLeft(object sender, OnUserLeaveEventArgs e) { OnInputReceived?.Invoke(new object[] { e.Channel, e.Username }); }
void CmdSendInput(CharacterControllerInput input) { OnInputReceived?.Invoke(input); }
void CmdSendInput(RigidbodyInput state) { OnInputReceived?.Invoke(state); }