public bool TriggerEvent(IGenericEvent evt) { InitiateListener(evt.GetType()); //Debug.Log("Event Dictionary Type Count" + eventDictionary[evt.GetType()].Count); for (int i = eventDictionary[evt.GetType()].Count - 1; i >= 0; i--) { //Debug.Log("Event Dictionary Type Count" + eventDictionary[evt.GetType()].Count); if (i >= eventDictionary[evt.GetType()].Count) { //Debug.Log("Calling Continue"); continue; } WeakReference <IGenericEventListener> listen = eventDictionary[evt.GetType()][i]; IGenericEventListener check; listen.TryGetTarget(out check); if (check == null) { //Debug.Log("Check was null"); Type type = evt.GetType(); UnregisterListener(check); continue; } if (check.HandleEvent(evt)) { //Debug.Log("Calling HandleEvent"); return(true); } } return(false); }
// Update is called once per frame public bool HandleEvent(IGenericEvent evt) { if (evt is UIUpdateEvent) { UIUpdateEvent ue = (UIUpdateEvent)evt; //Debug.Log("UI Update Event is handled"); if (ue.pID == 1) { player1Health.text = (ue.pHealth.ToString()); player1Mana.text = (ue.pMana.ToString()); //Debug.Log("UI Updated Player 1"); player1HealthBar.SetSize(((float)ue.pHealth) / Constants.PlayerMaximumHealth); player1ManaBar.SetSize((ue.pMana) / Constants.PlayerMaximumMana); } if (ue.pID == 2) { player2Health.text = (ue.pHealth.ToString()); player2Mana.text = (ue.pMana.ToString()); //Debug.Log("UI Updated Player 2"); player2HealthBar.SetSize(((float)ue.pHealth) / Constants.PlayerMaximumHealth); player2ManaBar.SetSize((ue.pMana) / Constants.PlayerMaximumMana); } return(true); } return(false); }
public bool HandleEvent(IGenericEvent evt) { if (evt is EndCollisionEvent) { EndCollisionEvent ece = evt as EndCollisionEvent; HandleEndCollisionEvent(ece.entityA, ece.entityB); return(true); } if (evt is AddCardtoDeckEvent) { //Debug.Log("Add Card to Deck Event recieved"); AddCardtoDeckEvent acd = evt as AddCardtoDeckEvent; bool result = AddCardToDeck(acd.cardID); if (result) { //Debug.Log("Calling Add to Deck List UI"); EventManager.instance.QueueEvent(new AddCardtoDeckScrollListEvent(acd.cardID, acd.cardName, acd.traits, acd.flavor)); return(true); } else { Debug.Log("Add to Deck List failed, too many copies of the same card! The max number is: " + Constants.MaxCopiesPerDeck); return(false); } } if (evt is DeckBuilderHandAdjustEvent) { DeckBuilderHandAdjustEvent se = evt as DeckBuilderHandAdjustEvent; AdjustPlayerHand(se.card); return(true); } return(false); }
public bool HandleEvent(IGenericEvent evt) { if (evt is SoundEvent) { SoundEvent se = evt as SoundEvent; if (library.ContainsKey(se.genre) && library[se.genre].ContainsKey(se.type)) { int max = library[se.genre][se.type].Count; int rand = Random.Range(0, max); // if (se.sound == 1) library[se.sound].pitch = Random.Range(1.0f - 0f, 1.0f + 0.5f); //if (se.sound == 0) library[se.sound].pitch = Random.Range(1.0f - 0f, 1.0f + 0.5f); //Debug.Log(library[se.genre][se.type][0].source.ToString()); if (se.delay != 0) { library[se.genre][se.type][rand].source.PlayDelayed(se.delay); } else { library[se.genre][se.type][rand].source.Play(); } return(true); } return(false); } return(false); }
public bool HandleEvent(IGenericEvent evt) { if (evt is EndCollisionEvent) { EndCollisionEvent ece = evt as EndCollisionEvent; HandleEndCollisionEvent(ece.entityA, ece.entityB); return(true); } return(false); }
/// <summary> /// Appends an event onto the end of the objects to stream next sync /// </summary> /// <param name="item">The event to append</param> public void Append(IGenericEvent item) { if (this.EventsStream != null) { lock (this.EventsStream) { if (this.InclusiveNames.Contains(item.Name) == true) { item.Disposed += GenericEventArgs_Disposed; this.EventsStream.Add(item); } } } }
public bool HandleEvent(IGenericEvent evt) { if (evt is AddCardtoDeckScrollListEvent) { AddCardtoDeckScrollListEvent add = evt as AddCardtoDeckScrollListEvent; AddButtontoDeckListUI(add.cardID, add.cardName, add.traits, add.flavor); return(true); } if (evt is InitializeDeckBuilerDeckUIEvent) { InitializationFunction(); return(true); } return(false); }
public bool HandleEvent(IGenericEvent evt) { if (evt is AddCardtoDeckScrollListEvent) { AddCardtoDeckScrollListEvent add = evt as AddCardtoDeckScrollListEvent; //Debug.Log("Name " + add.cardName + " ID: " + add.cardID + " added to deck list"); return(true); } if (evt is InitializeDeckBuilderListUIEvent) { InitializationFunction(); return(true); } return(false); }
public static GenericEvent FromTyped <T>(IGenericEvent <T> source) { return(new GenericEvent { Id = source.Id, Type = source.Type, CreatedOn = source.CreatedOn, Payload = JsonConvert.SerializeObject(source.Payload, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }), ResourceId = source.ResourceId, ResourceType = source.ResourceType }); }
public bool HandleEvent(IGenericEvent evt) { if (evt is GameOverEvent) { GameOverEvent ge = evt as GameOverEvent; string p1 = game.DeckGenres()[0]; string p2 = game.DeckGenres()[1]; if (ge.pID == 1) { winnerText.text = "Player 2 win!"; EventManager.instance.QueueEvent(new SoundEvent(p1, "Loss", 1f)); EventManager.instance.QueueEvent(new AnimatorEvent(1, "Loss")); EventManager.instance.QueueEvent(new SoundEvent(p2, "Victory")); EventManager.instance.QueueEvent(new AnimatorEvent(2, "Victory")); } if (ge.pID == 2) { winnerText.text = "Player 1 win!"; EventManager.instance.QueueEvent(new SoundEvent(p1, "Victory")); EventManager.instance.QueueEvent(new AnimatorEvent(1, "Victory")); EventManager.instance.QueueEvent(new SoundEvent(p2, "Loss", 1f)); EventManager.instance.QueueEvent(new AnimatorEvent(2, "Loss")); } World.Active.GetExistingSystem <DrawSystem>().Enabled = false; World.Active.GetExistingSystem <CollisionDetectionSystem>().Enabled = false; World.Active.GetExistingSystem <ControlSystem>().Enabled = false; World.Active.GetExistingSystem <DeletionSystem>().Enabled = false; World.Active.GetExistingSystem <MovementSystem>().Enabled = false; World.Active.GetExistingSystem <PlayerValueSystem>().Enabled = false; foreach (Entity e in World.Active.EntityManager.GetAllEntities()) { World.Active.EntityManager.DestroyEntity(e); } deckSelect.gameObject.SetActive(true); mainMenu.gameObject.SetActive(true); //winnerText.gameObject.SetActive(true); return(true); } return(false); }
public bool HandleEvent(IGenericEvent evt) { if (evt is AnimatorEvent) { AnimatorEvent ae = evt as AnimatorEvent; int player = ae.pID; string action = ae.action; if (player == 1) { firstAnimator.SetTrigger(action); } if (player == 2) { secondAnimator.SetTrigger(action); } return(true); } return(false); }
protected String FormatEvent(IGenericEvent item) { String text = null; switch (item.Name) { case "TextCommandRegistered": TextCommandModel firstTextCommand = item.Now.TextCommands.FirstOrDefault(); ConnectionModel firstConnection = item.Scope.Connections.FirstOrDefault(); if (firstTextCommand != null && firstConnection != null) { text = String.Format(@"Registed command(s) ""{0}"" to plugin {1} on connection {2}.", String.Join(", ", firstTextCommand.Commands.ToArray()), this.FormatGuid(firstTextCommand.PluginGuid), this.FormatGuid(firstConnection.ConnectionGuid)); } break; case "ConnectionDisconnected": case "ConnectionDisconnecting": case "ConnectionConnecting": case "ConnectionConnected": case "ConnectionListening": case "ConnectionReady": case "ConnectionLoggedIn": text = this.FormatGuid(item.Scope.Connections.First().ConnectionGuid); break; default: if (String.IsNullOrEmpty(item.Message.Trim()) == false) { text = item.Message; } break; } if (String.IsNullOrEmpty(text) == false) { text = String.Format("[{0}] {1}: {2}", DateTime.Now.ToString("HH:mm:ss"), item.Name, text); } return text; }
protected virtual void OnEventLogged(IGenericEvent e) { EventLoggedHandler handler = this.EventLogged; if (handler != null) { handler(this, e); } }
private bool ValidateType(IGenericEvent @event) { return(@event.GetType() == typeof(Event)); }
/// <summary> /// Called whenever an event is logged. /// </summary> protected void MasterEvents_EventLogged(object sender, IGenericEvent e) { foreach (var endPoint in this.EndPoints) { endPoint.Value.Append(e); } }
public Task CreateGenericEvent <T>(IGenericEvent <T> @event) { return(Task.CompletedTask); }
public void QueueEvent(IGenericEvent evt) { queue.Add(evt); }
protected void Events_EventLogged(object sender, IGenericEvent e) { String text = this.FormatEvent(e); if (String.IsNullOrEmpty(text) == false) Console.WriteLine(text); }
/// <summary> /// Creates a new Generic Event /// </summary> /// <typeparam name="T">The type of the payload</typeparam> /// <param name="event">The generic event to create</param> /// <returns></returns> public async Task CreateGenericEvent <T>(IGenericEvent <T> @event) { var genericEvent = GenericEventMapper.FromTyped <T>(@event); await CreateGenericEvent(genericEvent); }
/* Due to having no other idea how to do this, Projectile Collisions with Player Boundaries will have to have their own * values passed in, meaning there will be yet another Integer key here. Yay! ... ... * Gear = 8 * Cigar = 9 * Rocket = 10 * */ public bool HandleEvent(IGenericEvent evt) { if (evt is CollisionEvent) { CollisionEvent ce = evt as CollisionEvent; // Signifies Player x Projectile Collision if (ce.collisionMask == 1) { //Debug.Log("Player x Projectile Collision before in CollisionListener"); PlayerProjectileCollisionHelper(ce.entityA, ce.entityB); //Debug.Log("Player x Projectile Collision after in CollisionListener"); return(true); } // Projectile x Boundary Collision else if (ce.collisionMask == 2) { ProjectileBoundaryCollisionHelper(ce.entityA, ce.entityB); return(true); } // Player x Boundary Collision else if (ce.collisionMask == 4) { PlayerBoundaryCollisionHelper(ce.entityA, ce.entityB); return(true); } // Gear x Boundary Collision else if (ce.collisionMask == Constants.GearID) { Debug.Log("Collision Between Gear and Player Bound"); GearBoundaryCollisionHelper(ce.entityA, ce.entityB); return(true); } // Cigar x Boundary Colliison else if (ce.collisionMask == Constants.CigarID) { // Check to see if the normal of the boundary passed in is (0, 1) aka the bottom boundary, skip otherwise if (em.GetComponentData <PlayerBoundaryComponent>(ce.entityB).Normal == new Vector2(0, 1)) { CigarBoundaryCollisionHelpler(ce.entityA, ce.entityB); return(true); } else { Debug.Log("Collision between Cigar and Boundary skipped due to normal != (0,1)"); } return(false); } else if (ce.collisionMask == Constants.BettyID) { Debug.Log("Handle Betty collision with Player Boundary"); // Possible that just adding a "BouncingHelper" method is preferable since this is all the Bouncing Betty will do anyways BettyBoundaryCollisionHelper(ce.entityA, ce.entityB); return(true); } else if (ce.collisionMask == Constants.HailID) { Debug.Log("Handle Hail collisoin with Player Boundary"); HailCollisionBoundaryHelpler(ce.entityA, ce.entityB); } // Rocket x Boundary Collision, might not actually collide with player boundaries for now (balance before implementation) /*if (ce.collisionMask == Constants.RocketID) * { * Debug.Log("Handle Rocket collision with Player Boundary"); * return true; * }*/ } return(false); }
/// <summary> /// Log an item to the events list /// </summary> /// <param name="item"></param> public void Log(IGenericEvent item) { // Can be null after disposal. if (this.LoggedEvents != null) { item.Id = this.AcquireEventId; lock (this.LoggedEvents) { this.LoggedEvents.Add(item); } this.OnEventLogged(item); } }
/// <summary> /// Builds a command to send a EventsLog /// </summary> /// <returns>The built command to dispatch</returns> public static ICommand EventsLog(IGenericEvent e) { return new Command() { CommandType = CommandType.EventsLog, Parameters = new List<ICommandParameter>() { new CommandParameter() { Data = { Events = new List<IGenericEvent>() { e } } } } }; }