public void Apply(Behaviour behaviour, GameObject caster) { if (!behaviour.IsIgnoresImmunity && Behaviours.Any(element => (element.StatusImmunity & behaviour.StatusFlags) > 0) || CombatEncounter.Active == null && behaviour.IsPreventsMovement()) { AnyBehaviourImmune?.Invoke(gameObject, behaviour); return; } BeforeBehaviourApplied(behaviour); var applied = Behaviours.FirstOrDefault(b => b.Id == behaviour.Id); if (applied != null) { ReApply(applied, behaviour); return; } Behaviours.Add(behaviour); Behaviours = Behaviours.OrderBy(b => b.RemainingDuration).ToList(); behaviour.Removed += OnBehaviourRemoved; behaviour.Apply(caster, gameObject); AnyBehaviourApplied?.Invoke(behaviour); BehaviourApplied?.Invoke(behaviour); }
public void SetStackCount(int behaviourId, int stack) { var behaviour = Behaviours.FirstOrDefault(b => b.Id == behaviourId); if (behaviour == null) { return; } behaviour.StackCount = stack; }
public void RemoveAllStacks(int behaviourId) { var behaviour = Behaviours.FirstOrDefault(b => b.Id == behaviourId); if (behaviour == null) { return; } RemoveStack(behaviour, behaviour.StackCount); }
private void MergeBehaviours(IEnumerable <Behaviour> behaviours) { var inc = 0; foreach (var b in behaviours) { var existing = Behaviours.FirstOrDefault(x => x.Name == b.Name); if (existing != null) { existing.Values.AddRange(b.Values.Where(x => !existing.Values.Contains(x))); } else { Behaviours.Insert(inc++, b); } } }
public Behaviour GetNextPage(Dictionary <string, dynamic> viewModel) { var conditionValidator = new ConditionValidator(); if (Behaviours.Count == 1) { return(Behaviours.FirstOrDefault()); } foreach (var behaviour in Behaviours.OrderByDescending(_ => _.Conditions.Count)) { var isConditionTrue = false; foreach (var condition in behaviour.Conditions) { isConditionTrue = conditionValidator.IsValid(condition, viewModel); if (!isConditionTrue) { break; } } if (isConditionTrue || !behaviour.Conditions.Any()) { return(behaviour); } } var conditionValuesForDebug = Behaviours.OrderByDescending(_ => _.Conditions.Count) .Where(_ => _.Conditions != null) .SelectMany(_ => _.Conditions) .Where(_ => !string.IsNullOrEmpty(_.QuestionId)) .Select(_ => _.QuestionId) .Distinct() .Select(_ => $"QuestionId: {_} with answer {(viewModel.ContainsKey(_) ? viewModel[_] : "'null'")}") .Aggregate((curr, acc) => $"{acc} {curr}"); throw new ApplicationException($"Page::GetNextPage, There was a problem whilst processing behaviors for page '{PageSlug}', Behaviour Answers and conditions: {conditionValuesForDebug}"); }
public void RemoveStack(int behaviourId, int stack = 1) { Behaviours.FirstOrDefault(behaviour => behaviour.Id == behaviourId)?.Remove(stack); }
public void RemoveStack(Behaviour behaviour, int stack = 1) { Behaviours.FirstOrDefault(b => b.Equals(behaviour))?.Remove(stack); }
public BaseBehaviour GetBehaviourByType(Type behType) => Behaviours.FirstOrDefault(b => b.GetType() == behType);