private CombatRequest getFirst() { CombatRequest result = new CombatRequest(); foreach (var request in combatRequests) { result = request; combatRequests.Remove(result); break; } return(result); }
public void update(float elapsed) { while (this.combatRequests.Count > 0) { CombatRequest request = getFirst(); if (request.Skill != null) { SkillResult skillResult = request.Skill.perform(request.Source.Range); if (skillResult != null) { foreach (var target in request.Targets) { if (target != null) { if (request.Source != null) { // can we see the target? target.damage(skillResult.Damage); // did we kill the target? if (target.AmIDead) { removeRequests(target); // if we had a death effect it needs to go to the front of the list of actions and apply against all targets in the area Skill deathEffect = target.die(); if (deathEffect != null) { List <Character> charactersInRange = target.CharactersInRange.Invoke(target); this.combatRequests.Insert(0, new CombatRequest() { Skill = deathEffect, Source = target, Targets = charactersInRange }); } } } } } } } } }
private void removeRequests(Character source) { if (this.combatRequests.Count > 0) { lock (this.combatRequests) { for (int j = combatRequests.Count - 1; j >= 0; j--) { CombatRequest request = combatRequests[j]; if (request.Source != null && source != null) { if (request.Source.Equals(source)) { this.combatRequests.RemoveAt(j); } } } } } }