/// <summary> /// TODO: FINISH THIS /// </summary> public async void TestRunMassConversion() { var even = new CommandManagerTests.DebugEvent("!testMe"); var odd = new CommandManagerTests.DebugEvent("!ignoreMe"); Assert.True(await EQ.AddEvent(even)); Assert.True(await EQ.AddEvent(odd)); Assert.True(await EQ.AddEvent(odd)); Assert.True(await EQ.AddEvent(even)); var(_, foundCommand, commandSuccessful, _, commandTask) = EQ.StartEvent(); await commandTask; Assert.True(foundCommand); Assert.True(commandSuccessful); Assert.True(didDebug); (_, foundCommand, commandSuccessful, _, commandTask) = EQ.StartEvent(); await commandTask; Assert.True(foundCommand); Assert.True(commandSuccessful); Assert.False(didDebug); (_, foundCommand, commandSuccessful, _, commandTask) = EQ.StartEvent(); await commandTask; Assert.True(foundCommand); Assert.False(commandSuccessful); Assert.False(didDebug); (_, foundCommand, commandSuccessful, _, commandTask) = EQ.StartEvent(); await commandTask; Assert.True(foundCommand); Assert.True(commandSuccessful); Assert.True(didDebug); }
public void ReturnsEventsInProperOrder() { var eventQueue = new EventQueue(); var eventStub1 = new EventStub(0); var eventStub2 = new EventStub(0); eventQueue.AddEvent(eventStub1); eventQueue.AddEvent(eventStub2); Assert.AreSame(eventStub1, eventQueue.GetNextEventFor(0)); Assert.AreSame(eventStub2, eventQueue.GetNextEventFor(0)); }
public void AddQuest(Transform Quest) { QuestTemplate tempQuest = Quest.GetComponent <QuestTemplate>(); tempEvent.Setup(EventTypeEnum.QuestStarted, tempQuest.QuestName); eventQueue.AddEvent(tempEvent); Quest.parent = transform; ActiveQuests.Add(Quest.gameObject); tempQuest.QuestStart(); if (FocusedQuestReference == null) { QuestSetFocus(Quest.gameObject); } }
public void ObjectiveFinished() { CompletedObjectiveList.Add(ActiveObjective); ///// EventData tempEvent = new EventData(); tempEvent.Setup(EventTypeEnum.QuestObjCompleted, GetComponentInParent <QuestTemplate>().QuestName); eventQueue.AddEvent(tempEvent); ///// if (HiddenObjectiveList.Count > 0) { ActiveObjective = HiddenObjectiveList[0]; HiddenObjectiveList.RemoveAt(0); ActiveObjective.GetComponent <QuestObjective>().initialize(); ///////// QHud.QuestDisplay(this); //////// } else { ActiveObjective = null; questsHolder.FullQuestCompleted(gameObject); ZF.SetFlag(Quest_Set_Flag.name); //Has to be after } }
public void SendReliableMessage(ITypedMessage typedMessage, ushort sourceId, ushort destinationId, ushort realDestinationId, IEndPoint to, MessageFlags messageFlags = MessageFlags.None) { try { if (!typedMessage.GetMessageType().IsReliable()) { throw new DnmpException("Message is not reliable"); } var id = Guid.NewGuid(); var message = new BaseMessage(typedMessage, sourceId, destinationId, realClient.SelfClient?.Id ?? 0xFFFF, realDestinationId, id, messageFlags); var messageInfo = new BaseMessagePair { Message = message, EndPoint = to }; reliableMessages.TryAdd(id, messageInfo); SendBaseMessage(message, to); EventQueue.AddEvent(ReliableCallback, new KeyValuePair <Guid, BaseMessagePair>(id, messageInfo), DateTime.Now.AddMilliseconds(500), id); } catch (Exception) { if (realClient.CurrentStatus == DnmpClient.ClientStatus.Disconnecting || realClient.CurrentStatus == DnmpClient.ClientStatus.NotConnected) { return; } throw; } }
public void ConcurrentRemoving() { var guid = EventQueue.AddEvent(x => { }, null, DateTime.Now.AddMilliseconds(100)); Thread.Sleep(100); EventQueue.RemoveEvent(guid); }
public async Task ConnectManyAsync(IEndPoint[] endPoints, IEndPoint sourceEndPoint, bool invokeEvents, IAsymmetricKey key, ISymmetricKey dummySymmetricKey, byte[] selfCustomData) { if (CurrentStatus != ClientStatus.NotConnected) { return; } if (selfCustomData.Length > 65000) { throw new DnmpException("Custom data length is larger than 65000 bytes"); } SelfCustomData = selfCustomData; Initialize(sourceEndPoint, key, dummySymmetricKey); CurrentStatus = ClientStatus.Connecting; if (invokeEvents) { connectionTimeoutEvent = EventQueue.AddEvent(_ => { NetworkHandler.Stop(); MessageHandler.Stop(); ClientsById.Clear(); CurrentStatus = ClientStatus.NotConnected; OnConnectionTimeout?.Invoke(); }, null, DateTime.Now.AddMilliseconds(Config.ConnectionTimeout)); } else { connectionTimeoutEvent = EventQueue.AddEvent(_ => { CurrentStatus = ClientStatus.NotConnected; }, null, DateTime.Now.AddMilliseconds(Config.ConnectionTimeout)); } logger.Debug($"Trying to connect to {endPoints.Length} endpoints. First: {endPoints.FirstOrDefault()}"); foreach (var endPoint in endPoints) { logger.Debug($"Trying to connect to {endPoint}"); try { NetworkHandler.SendBaseMessage( new BaseMessage(new ConnectionRequestMessage(key.GetNetworkId(), true), 0xFFFF, 0xFFFF), endPoint); } catch (Exception e) { logger.Warn($"Caught exception while trying to connect: {e.GetType().Name}('{e.Message}')"); } } if (invokeEvents) { return; } SpinWait.SpinUntil(() => CurrentStatus == ClientStatus.Connecting || CurrentStatus == ClientStatus.Handshaking); if (CurrentStatus == ClientStatus.NotConnected) { throw new TimeoutException("Connection timeout"); } await Task.Delay(0); }
public void EventFromQueueIsTheSameAsEventAddedToQueue() { var eventQueue = new EventQueue(); var eventStub = new EventStub(0); eventQueue.AddEvent(eventStub); Assert.AreSame(eventStub, eventQueue.GetNextEventFor(0)); }
public void DoAction() { int damage = Random.Range(1, 10); Player.instance.health -= damage; EventQueue.AddMessage(Name() + " bites!"); EventQueue.AddEvent(Player.instance.gameObject, damage, DamageTypes.Physical); }
public void ParameterPass() { var val = 0; EventQueue.AddEvent(x => val = (int)x, 42, DateTime.Now.AddMilliseconds(50)); Thread.Sleep(100); Assert.AreEqual(42, val); }
public void NotEmptyQueueHasEventsAtTheTimeOfEvent() { var eventQueue = new EventQueue(); var eventStub = new EventStub(0); eventQueue.AddEvent(eventStub); Assert.IsTrue(eventQueue.HasMoreEventsFor(0)); }
public void NotEmptyQueueDoesNotHaveEventsAtTheTimeOfEvent() { var eventQueue = new EventQueue(); var eventStub = new EventStub(0); eventQueue.AddEvent(eventStub); Assert.IsFalse(eventQueue.HasMoreEventsFor(1)); }
public override void Enter() { // call the ability's start method abilityComponent.ActivateWithCallback((cooldownDuration) => this.UpdateState(cooldownDuration)); if (Owner is Hero) { EventQueue.AddEvent(new AreaStateChangeEventArgs(Owner, null, AreaStateTypes.Active)); } }
public void ReturnsNullWhenThereIsNoEventForTheGivenTime() { var eventQueue = new EventQueue(); var eventStub1 = new EventStub(0); eventQueue.AddEvent(eventStub1); eventQueue.GetNextEventFor(0); Assert.IsNull(eventQueue.GetNextEventFor(0)); }
public void UsualEventRemove() { var val = -1; var guid = EventQueue.AddEvent(x => val = 0, null, DateTime.Now.AddMilliseconds(200)); Thread.Sleep(100); Assert.AreEqual(-1, val); EventQueue.RemoveEvent(guid); Thread.Sleep(150); Assert.AreEqual(-1, val); }
void Explode(int index) { index = EventQueue.AddMessage("the bomb explodes!", index + 1); EventQueue.AddDestroy(gameObject, index + 1); foreach (GameObject item in room.AllEntities()) { if (item != gameObject) { EventQueue.AddEvent(item, 20, DamageTypes.Fire); } } }
public void Usual2Events() { int val1 = -1, val2 = -2; EventQueue.AddEvent(x => val1 = 0, null, DateTime.Now.AddMilliseconds(200)); EventQueue.AddEvent(x => val2 = 0, null, DateTime.Now.AddMilliseconds(400)); Thread.Sleep(300); Assert.AreEqual(0, val1); Assert.AreEqual(-2, val2); Thread.Sleep(200); Assert.AreEqual(0, val1); Assert.AreEqual(0, val2); }
public void Attack() { if (turnAvailable && !GameController.frozen) { UIController.instance.Reset(); SpeechBubble.mainBubble.Activate(); int damage = Random.Range(1, 10); EventQueue.AddMessage("you attack!"); EventQueue.AddEvent(Target(), damage, DamageTypes.Physical); if (BattleController.inCombat) { turnAvailable = false; } } }
public void UpdateState() { if (!Owner) { return; } // should probably only fire when area is in setupstate if (Owner is Hero) { EventQueue.AddEvent(new AreaStateChangeEventArgs(Owner, null, AreaStateTypes.Active)); } // Owner.gameObject.GetComponentInChildren<Renderer> ().material.color = c; state = new AIIdleState(Owner); }
public void Heal() { if (turnAvailable && !GameController.frozen && Player.instance.magic > 0) { UIController.instance.Reset(); Player.instance.magic -= 1; int damage = Random.Range(10, 20); EventQueue.AddMessage("you cast heal!"); EventQueue.AddEvent(Target(), -damage, DamageTypes.Physical); if (BattleController.inCombat) { turnAvailable = false; } } }
public void EqualEvents() { var val1 = -1; var val2 = -2; var calltime = DateTime.Now.AddMilliseconds(200); EventQueue.AddEvent(x => val1 = 0, null, calltime); EventQueue.AddEvent(x => val1 = 0, null, calltime); EventQueue.AddEvent(x => val2 = 0, null, calltime); Assert.AreEqual(-2, val2); Assert.AreEqual(-1, val1); Thread.Sleep(calltime.AddMilliseconds(50) - DateTime.Now); Assert.AreEqual(0, val2); Assert.AreEqual(0, val1); }
public void Fire() { if (turnAvailable && !GameController.frozen && Player.instance.magic > 0) { UIController.instance.Reset(); Player.instance.magic -= 1; SpeechBubble.mainBubble.Activate(); int damage = Random.Range(10, 20); EventQueue.AddMessage("you cast fire!"); EventQueue.AddEvent(Target(), damage, DamageTypes.Fire); if (BattleController.inCombat) { turnAvailable = false; } } }
public void MultiplyAddRemove() { var guid = new Guid(); var val = -1; EventQueue.AddEvent(x => val = 0, null, DateTime.Now.AddMilliseconds(50), guid); for (var i = 0; i < 100; i++) { Assert.AreEqual(-1, val); Thread.Sleep(25); EventQueue.RemoveEvent(guid); EventQueue.AddEvent(x => val = 0, null, DateTime.Now.AddMilliseconds(50), guid); } Thread.Sleep(100); Assert.AreEqual(0, val); }
public void add_xp(int xp_in) { needed_xp = current_level * 2000; current_xp += xp_in; if (current_level < ReturnLevelCap() && current_xp >= needed_xp) { ///// EventData tempEvent = new EventData(); tempEvent.Setup(EventTypeEnum.AbilityLevelUp, AbilityName); eventQueue.AddEvent(tempEvent); ///// current_xp -= needed_xp; current_level += 1; needed_xp = current_level * 2000; } }
private void ReliableCallback(object messageObject) { try { var currentMessageInfo = (KeyValuePair <Guid, BaseMessagePair>)messageObject; currentMessageInfo.Value.Tries++; if (currentMessageInfo.Value.Tries > realClient.Config.MaxReliableRetries || !realClient.ClientsById.ContainsKey(currentMessageInfo.Value.Message.RealDestinationId)) { reliableMessages.TryRemove(currentMessageInfo.Key, out var _); return; } realClient.NetworkHandler.SendBaseMessage(currentMessageInfo.Value.Message, currentMessageInfo.Value.EndPoint); EventQueue.AddEvent(ReliableCallback, new KeyValuePair <Guid, BaseMessagePair>(currentMessageInfo.Key, currentMessageInfo.Value), DateTime.Now.AddMilliseconds(500), currentMessageInfo.Key); } catch (Exception e) { logger.Error(e, "Exception in ReliableCallback"); } }
private void LevelUp() { if (!LevelUpQued) { current_exp -= level * 1000; LevelUpQued = true; ///// EventData tempEvent = new EventData(); tempEvent.Setup(EventTypeEnum.LevelUp, ""); eventQueue.AddEvent(tempEvent); ///// } if (!combatChecker.enemies_nearby) { EXPBar.fillAmount = 0f; modifyImplantPoints(3); level += 1; uIController.LevelUpMenuBool(true); LevelUpQued = false; } }
public void AddEvent(EventAction e) { EventQueue queue = queues[queues.Count - 1]; queue.AddEvent(e); }
private void CleanUpVoid(object _) { CleanUpOldEndPoints(TimeSpan.FromMilliseconds(config.SavedEndPointTtl)); EventQueue.AddEvent(CleanUpVoid, null, DateTime.Now + TimeSpan.FromMilliseconds(config.SavedEndPointsCleanUpInterval)); }