I'm trying to trigger poison effects at the end of each turn in a turn based game. Each Actor in battle has a list of active effects, each of which could be a poison. I simply want to Execute() all of those Poisons.
See my code below; is there a way I can combine my two queries or make them more efficient so that the moment a Poison is found, that Poison executes?
var poisonedActors = from Actor actor in ins.BattleParticipants where actor.ActiveEffects.Any(activeEffect => activeEffect is Poison) select actor; var poisons = from ActiveEffect activeEffect in poisonedActors where activeEffect is Poison select activeEffect; foreach (Poison poison in poisons) poison.Execute();
EDIT: Is this more efficient? Is there a better way to do things?
foreach (Actor actor in ins.BattleParticipants) foreach (ActiveEffect activeEffect in actor.ActiveEffects) if (activeEffect is Poison) activeEffect.Execute();