void Update() { UpdateConditionVars(); List <Reaction> possibleReactions = reactions.reactions .Where(reaction => reaction.condition.applyCondition(conditionVars)).ToList(); if (possibleReactions.Count > 0) { currentAction = possibleReactions.First(); animator.SetTrigger(currentAction.getTriggerName()); _count = 0; } else { currentMode = aiBlueprint.GetCurrentCombatMode(conditionVars); combatSequencer.Mode = currentMode; actions = combatSequencer.actions.ToList(); if (_count > currentAction.getDuration()) { animator.ResetTrigger(currentAction.getTriggerName()); currentAction = combatSequencer.NextAction(currentMode.generateActionMode); animator.SetTrigger(currentAction.getTriggerName()); _count = 0; } } _count += Time.deltaTime; }
// Start is called before the first frame update void Start() { conditionVars = new ConditionVars(); animator = GetComponent <Animator>(); currentMode = aiBlueprint.GetCurrentCombatMode(conditionVars); combatSequencer = new CombatSequencer(currentMode, sequencesCount); currentAction = combatSequencer.NextAction(currentMode.generateActionMode); animator.SetTrigger(currentAction.getTriggerName()); }
public void should_ReturnActionsByInsertionOrder_When_GenerateActionsBySequence() { // Given Mode mode = new Mode(); mode.generateActionMode = GenerateActionMode.InSequence; mode.actions = new List <Action>(); mode.actions.Add(new Action("first", 10, 0)); mode.actions.Add(new Action("second", 10, 100)); mode.actions.Add(new Action("third", 10, 50)); com = new CombatSequencer(mode, 3); // When List <Action> result = new List <Action>(); result.Add(com.NextAction(GenerateActionMode.InSequence)); result.Add(com.NextAction(GenerateActionMode.InSequence)); result.Add(com.NextAction(GenerateActionMode.InSequence)); // Then Assert.AreSame(result[0].getTriggerName(), "first"); Assert.AreSame(result[1].getTriggerName(), "second"); Assert.AreSame(result[2].getTriggerName(), "third"); }
public void should_ReturnActionAlways100_When_GenerateNextActionByPropability() { // Given Mode mode = new Mode(); mode.actions = new List <Action>(); mode.actions.Add(new Action("never", 10, 0)); mode.actions.Add(new Action("always", 10, 100)); com = new CombatSequencer(mode, 1); // When Action result = com.NextAction(GenerateActionMode.ByPropability); // Then Assert.True(result.getTriggerName().Equals("always")); Assert.True(Math.Abs(result.getDuration() - 10) < 0.01f); }