private void AddTriggeredEffects( AbilityActivatedMessage abilityActivatedMessage, AbilityActivatedMessage selfEffectsMessage, int entityId, ActivationType trigger, GameManager manager) { foreach (var ability in GetTriggeredAbilities(entityId, trigger, manager)) { // TODO: Trigger non-modifier abilities as separate activations Debug.Assert(ability.Ability.Action != AbilityAction.Modifier); foreach (var effectEntity in manager.EffectsToContainingAbilityRelationship[ability.Id]) { if (effectEntity.Effect.ShouldTargetActivator) { selfEffectsMessage.EffectsToApply = selfEffectsMessage.EffectsToApply.Add(effectEntity); } else { abilityActivatedMessage.EffectsToApply = abilityActivatedMessage.EffectsToApply.Add(effectEntity); } } } }
private List <AbilityActivation> GetActivations( AbilityActivatedMessage activationMessage, AbilityActivatedMessage selfEffectsMessage, HashSet <AbilityComponent> activatedAbilities) { var activations = new List <AbilityActivation>(); activatedAbilities.Add(activationMessage.AbilityEntity.Ability); GetActivations(activationMessage, null, selfEffectsMessage, null, activatedAbilities, activations); return(activations); }
private List <(GameEntity ActivatingEffect, GameEntity ActivatedAbility)> GetActivatedAbilities( AbilityActivatedMessage targetEffectsMessage, AbilityActivatedMessage selfEffectsMessage) { var manager = targetEffectsMessage.ActivatorEntity.Manager; var abilityTrigger = targetEffectsMessage.Trigger; List <(GameEntity Effect, GameEntity Ability)> activatedAbilities = null; foreach (var effectEntity in manager.EffectsToContainingAbilityRelationship[targetEffectsMessage.AbilityEntity.Id]) { var effect = effectEntity.Effect; if (effect.EffectType == EffectType.Activate) { var activatableId = effect.TargetEntityId.Value; var activatable = manager.FindEntity(activatableId); if (activatable == null) { throw new InvalidOperationException( $"Couldn't find the entity to activate '{activatableId}' referenced from the effect '{effectEntity.Id}'" + $" on ability '{effect.ContainingAbilityId}'"); } Debug.Assert(abilityTrigger != ActivationType.Default || activatable.HasComponent(EntityComponent.Ability)); var triggeredAbility = activatable.HasComponent(EntityComponent.Ability) ? activatable : GetSingleTriggeredAbility(abilityTrigger, activatableId, manager); if (activatedAbilities == null) { activatedAbilities = new List <(GameEntity, GameEntity)>(); } activatedAbilities.Add((effectEntity, triggeredAbility)); } else if (effect.ShouldTargetActivator) { selfEffectsMessage.EffectsToApply = selfEffectsMessage.EffectsToApply.Add(effectEntity); } else { targetEffectsMessage.EffectsToApply = targetEffectsMessage.EffectsToApply.Add(effectEntity); } } return(activatedAbilities); }
private void EnqueueAbilityActivated(AbilityActivatedMessage abilityActivatedMessage, GameManager manager) { Debug.Assert(abilityActivatedMessage.EffectsToApply != null); manager.Enqueue(abilityActivatedMessage); }
private void GetActivations( AbilityActivatedMessage activationMessage, AbilityActivatedMessage targetMessage, AbilityActivatedMessage selfEffectsMessage, GameEntity activatingEffect, HashSet <AbilityComponent> activatedAbilities, List <AbilityActivation> activations) { var manager = activationMessage.AbilityEntity.Manager; var messageToProcess = targetMessage ?? activationMessage; var perAbilityActivations = GetActivatedAbilities(messageToProcess, selfEffectsMessage); if (perAbilityActivations != null) { foreach (var subActivation in perAbilityActivations) { activatedAbilities.Add(subActivation.ActivatedAbility.Ability); var subAbilityMessage = messageToProcess.Clone(manager); subAbilityMessage.AbilityEntity = subActivation.ActivatedAbility; AbilityActivatedMessage nextActivationMessage; var nextTargetMessage = targetMessage; if (subActivation.ActivatedAbility.Ability.Range != 0 && nextTargetMessage == null) { nextActivationMessage = subAbilityMessage; } else { nextActivationMessage = activationMessage.Clone(manager); if (nextTargetMessage == null && activatingEffect != null) { activationMessage.EffectsToApply = activationMessage.EffectsToApply.Add(activatingEffect); } nextTargetMessage = subAbilityMessage; } GetActivations(nextActivationMessage, nextTargetMessage, selfEffectsMessage, subActivation.ActivatingEffect, activatedAbilities, activations); } manager.ReturnMessage(activationMessage); if (targetMessage != null) { manager.ReturnMessage(targetMessage); } } else { Debug.Assert(activationMessage.AbilityEntity.Ability.Action != AbilityAction.Modifier); if (activatingEffect != null) { if (targetMessage == null) { activationMessage.EffectsToApply = activationMessage.EffectsToApply.Add(activatingEffect); } else { targetMessage.EffectsToApply = targetMessage.EffectsToApply.Add(activatingEffect); } } activations.Add(new AbilityActivation { ActivationMessage = activationMessage, TargetMessage = targetMessage }); } }