예제 #1
0
 private StateWrapper BuildPursuit()
 {
     StateWrapper stateWrapper = new StateWrapper();
       FSMState state = new ActionState(this.stateName);
       state.WithDefaultBehaviours(this.gameObject);
       if (this.animationBehaviour != null) {
     state.AddStartBehaviour(this.animationBehaviour);
       }
       state.AddStartBehaviour(new VariableCalculatorBehaviour(this.gameObject, CharVars.SPEED_MULTIPLIER.ToS()).Add(this.speedIncrease));
       if (this.counterVariable != null) {
     state.AddStartBehaviour(new VariableCalculatorBehaviour(this.gameObject, this.counterVariable.ToS()).Add(1));
       }
       state.AddStartBehaviour(new SetVariableBehaviour(this.gameObject, CharVars.IGNORE_DRAG.ToS(), true));
       foreach (FSMBehaviour behaviour in this.customStartBehaviours) {
     state.AddStartBehaviour(behaviour);
       }
       foreach (FSMBehaviour behaviour in this.customUpdateBehaviours) {
     state.AddUpdateBehaviour(behaviour);
       }
       MoveTowardsBehaviour moveTowardsBehaviour = BehavioursBuilder.BuildMoveTowards(this.gameObject, true, true);
       if (this.target != null) {
     moveTowardsBehaviour = moveTowardsBehaviour.WithTarget(this.target);
       }
       if (this.targetVariable != null) {
     moveTowardsBehaviour = moveTowardsBehaviour.WithTargetVariable(this.targetVariable);
       }
       state.AddUpdateBehaviour(moveTowardsBehaviour);
       state.AddUpdateBehaviour(BehavioursBuilder.BuildKeepInsideBounds(this.gameObject, true, true));
       foreach (ComboWrapper combo in this.combos.Values) {
     SetVariableBehaviour behaviour = new SetVariableBehaviour(this.gameObject, CharVars.COMBO_VARIANT.ToS(), combo.variant);
     foreach (ICondition condition in combo.conditions) {
       behaviour = behaviour.WithCondition(condition);
     }
     state.AddUpdateBehaviour(behaviour);
       }
       state.AddExitBehaviour(new VariableCalculatorBehaviour(this.gameObject, CharVars.SPEED_MULTIPLIER.ToS()).Subtract(this.speedIncrease));
       state.AddExitBehaviour(new SetVariableBehaviour(this.gameObject, CharVars.IGNORE_DRAG.ToS(), false));
       foreach (FSMBehaviour behaviour in this.customExitBehaviours) {
     state.AddExitBehaviour(behaviour);
       }
       stateWrapper.state = state;
       //TRANSITIONS
       FSMTransition transition = null;
       foreach (string startingState in this.startingStates) {
     transition = new FSMTransition(startingState, this.stateName);
     VarConditionsBuilder builder = new VarConditionsBuilder()
     .IgnoringInputs().IgnoringAttributes().IgnoringDirections().IgnoringPositions().IgnoringFlags().IgnoringCombat()
     .WithVar(CharVars.FromInputMode(this.input), new InputCondition(CharVars.FromInputMode(this.input).ToS(), Operators.EQUAL, InputModes.PRESS, InputModes.DOUBLE_TAP))
     .WithVar(CharVars.TARGET, new ObjectCondition(this.targetVariable));
     if (this.counterVariable != null) {
       builder = builder.WithVar(this.counterVariable, new IntCondition(this.counterVariable.ToS(), Operators.LESS_THAN, this.maxPursuits));
     }
     transition.AddConditions(builder.Build());
     stateWrapper.transitions.Add(transition);
       }
       //RETURN
       foreach (string animationName in this.animationNames) {
     foreach (ComboWrapper combo in this.combos.Values) {
       transition = new FSMTransition(this.stateName, combo.toState);
       transition.AddCondition(new AnimationEndCondition(this.gameObject.GetComponent<Animator>(), animationName));
       transition.AddConditions(
     new VarConditionsBuilder()
     .IgnoringInputs().IgnoringAttributes().IgnoringDirections().IgnoringPositions().IgnoringFlags().IgnoringCombat()
     .WithVar(CharVars.COMBO_VARIANT, new IntCondition(CharVars.COMBO_VARIANT.ToS(), Operators.EQUAL, combo.variant))
     .Build()
       );
       stateWrapper.transitions.Add(transition);
     }
       }
       transition = new FSMTransition(this.stateName, CharStates.FALL.ToS());
       transition.AddCondition(new TimeCondition(this.timeout));
       transition.AddConditions(
     new VarConditionsBuilder()
     .IgnoringInputs().IgnoringAttributes().IgnoringDirections().IgnoringPositions().IgnoringFlags().IgnoringCombat()
     .WithVar(CharVars.IS_FLYING, new BoolCondition(CharVars.IS_FLYING.ToS(), Operators.EQUAL, false))
     .Build()
       );
       stateWrapper.transitions.Add(transition);
       transition = new FSMTransition(this.stateName, CharStates.FLY.ToS());
       transition.AddCondition(new TimeCondition(this.timeout));
       transition.AddConditions(
     new VarConditionsBuilder()
     .IgnoringInputs().IgnoringAttributes().IgnoringDirections().IgnoringPositions().IgnoringFlags().IgnoringCombat()
     .WithVar(CharVars.IS_FLYING, new BoolCondition(CharVars.IS_FLYING.ToS(), Operators.EQUAL, true))
     .Build()
       );
       stateWrapper.transitions.Add(transition);
       return stateWrapper;
 }
예제 #2
0
 private StateWrapper BuildTeleport()
 {
     StateWrapper stateWrapper = new StateWrapper();
       FSMState state = new ActionState(this.stateName);
       state.WithDefaultBehaviours(this.gameObject);
       if (this.animationBehaviour != null) {
     state.AddStartBehaviour(this.animationBehaviour);
       }
       if (this.counterVariable != null) {
     state.AddStartBehaviour(new VariableCalculatorBehaviour(this.gameObject, this.counterVariable.ToS()).Add(1));
       }
       if (this.flip && this.waitStateName == null) {
     state.AddStartBehaviour(BehavioursBuilder.BuildFlip(this.gameObject, false).Invert());
       }
       if (this.soundStart != null) {
     state.AddStartBehaviour(new PlaySoundBehaviour(this.gameObject, this.soundStart).Force());
       }
       if (this.effectStart != null) {
     state.AddStartBehaviour(new InstantiateBehaviour(this.gameObject, this.effectStart));
       }
       foreach (FSMBehaviour behaviour in this.customStartBehaviours) {
     state.AddStartBehaviour(behaviour);
       }
       if (this.soundUpdate != null) {
     state.AddUpdateBehaviour(new PlaySoundBehaviour(this.gameObject, this.soundUpdate));
     state.AddExitBehaviour(new StopSoundBehaviour(this.gameObject, this.soundUpdate));
       }
       if (this.effectUpdate != null) {
     state.AddUpdateBehaviour(new InstantiateBehaviour(this.gameObject, this.effectUpdate));
       }
       foreach (FSMBehaviour behaviour in this.customUpdateBehaviours) {
     state.AddUpdateBehaviour(behaviour);
       }
       state.AddUpdateBehaviour(BehavioursBuilder.BuildKeepInsideBounds(this.gameObject, true, true));
       if (this.waitStateName == null) {
     foreach (ComboWrapper combo in this.combos.Values) {
       SetVariableBehaviour behaviour = new SetVariableBehaviour(this.gameObject, CharVars.COMBO_VARIANT.ToS(), combo.variant);
       foreach (ICondition condition in combo.conditions) {
     behaviour = behaviour.WithCondition(condition);
       }
       state.AddUpdateBehaviour(behaviour);
     }
       }
       TeleportToBehaviour teleportToBehaviour = new TeleportToBehaviour(this.gameObject, this.obstacles).TeleportAhead(this.distance);
       if (this.target != null) {
     teleportToBehaviour = teleportToBehaviour.WithTarget(this.target);
       }
       if (this.targetVariable != null) {
     teleportToBehaviour = teleportToBehaviour.WithTargetVariable(this.targetVariable);
       }
       state.AddExitBehaviour(teleportToBehaviour);
       foreach (FSMBehaviour behaviour in this.customExitBehaviours) {
     state.AddExitBehaviour(behaviour);
       }
       if (this.soundExit != null) {
     state.AddExitBehaviour(new PlaySoundBehaviour(this.gameObject, this.soundExit).Force());
       }
       if (this.effectExit != null) {
     state.AddExitBehaviour(new InstantiateBehaviour(this.gameObject, this.effectExit));
       }
       stateWrapper.state = state;
       //TRANSITIONS
       FSMTransition transition = null;
       foreach (string startingState in this.startingStates) {
     transition = new FSMTransition(startingState, this.stateName);
     VarConditionsBuilder builder = new VarConditionsBuilder()
     .IgnoringInputs().IgnoringAttributes().IgnoringDirections().IgnoringPositions().IgnoringFlags().IgnoringCombat()
     .WithVar(CharVars.FromInputMode(this.input), new InputCondition(CharVars.FromInputMode(this.input).ToS(), Operators.EQUAL, InputModes.PRESS, InputModes.DOUBLE_TAP))
     .WithVar(CharVars.TARGET, new ObjectCondition(this.targetVariable));
     if (this.counterVariable != null) {
       builder = builder.WithVar(this.counterVariable, new IntCondition(this.counterVariable.ToS(), Operators.LESS_THAN, this.maxTeleports));
     }
     transition.AddConditions(builder.Build());
     stateWrapper.transitions.Add(transition);
       }
       //RETURN
       if (this.waitStateName == null) {
     foreach (string animationName in this.animationNames) {
       foreach (ComboWrapper combo in this.combos.Values) {
     transition = new FSMTransition(this.stateName, combo.toState);
     transition.AddCondition(new AnimationEndCondition(this.gameObject.GetComponent<Animator>(), animationName));
     transition.AddConditions(
       new VarConditionsBuilder()
       .IgnoringInputs().IgnoringAttributes().IgnoringDirections().IgnoringPositions().IgnoringFlags().IgnoringCombat()
       .WithVar(CharVars.COMBO_VARIANT, new IntCondition(CharVars.COMBO_VARIANT.ToS(), Operators.EQUAL, combo.variant))
       .Build()
     );
     stateWrapper.transitions.Add(transition);
       }
     }
     transition = new FSMTransition(this.stateName, CharStates.FALL.ToS());
     transition.AddCondition(new TimeCondition(this.timeout));
     transition.AddConditions(
       new VarConditionsBuilder()
       .IgnoringInputs().IgnoringAttributes().IgnoringDirections().IgnoringPositions().IgnoringFlags().IgnoringCombat()
       .WithVar(CharVars.IS_FLYING, new BoolCondition(CharVars.IS_FLYING.ToS(), Operators.EQUAL, false))
       .Build()
     );
     stateWrapper.transitions.Add(transition);
     transition = new FSMTransition(this.stateName, CharStates.FLY.ToS());
     transition.AddCondition(new TimeCondition(this.timeout));
     transition.AddConditions(
       new VarConditionsBuilder()
       .IgnoringInputs().IgnoringAttributes().IgnoringDirections().IgnoringPositions().IgnoringFlags().IgnoringCombat()
       .WithVar(CharVars.IS_FLYING, new BoolCondition(CharVars.IS_FLYING.ToS(), Operators.EQUAL, true))
       .Build()
     );
     stateWrapper.transitions.Add(transition);
       }
       return stateWrapper;
 }
예제 #3
0
 private StateWrapper BuildWait()
 {
     StateWrapper stateWrapper = new StateWrapper();
       FSMState state = new ActionState(this.waitStateName);
       state.WithDefaultBehaviours(this.gameObject);
       if (this.waitAnimationBehaviour != null) {
     state.AddStartBehaviour(this.waitAnimationBehaviour);
       }
       state.AddStartBehaviour(new StopMovementBehaviour(this.gameObject).WithXAxis().WithYAxis());
       state.AddStartBehaviour(new IgnoreGravityBehaviour(this.gameObject));
       state.AddStartBehaviour(new SetVariableBehaviour(this.gameObject, CharVars.IGNORE_DRAG.ToS(), false));
       if (this.flip) {
     state.AddStartBehaviour(BehavioursBuilder.BuildFlip(this.gameObject, false).Invert());
       }
       foreach (FSMBehaviour behaviour in this.customStartBehaviours) {
     state.AddStartBehaviour(behaviour);
       }
       foreach (FSMBehaviour behaviour in this.customUpdateBehaviours) {
     state.AddUpdateBehaviour(behaviour);
       }
       state.AddUpdateBehaviour(BehavioursBuilder.BuildKeepInsideBounds(this.gameObject, true, true));
       foreach (ComboWrapper combo in this.combos.Values) {
     SetVariableBehaviour behaviour = new SetVariableBehaviour(this.gameObject, CharVars.COMBO_VARIANT.ToS(), combo.variant);
     foreach (ICondition condition in combo.conditions) {
       behaviour = behaviour.WithCondition(condition);
     }
     state.AddUpdateBehaviour(behaviour);
       }
       state.AddExitBehaviour(new RestoreGravityBehaviour(this.gameObject, CharVars.ORIGINAL_GRAVITY_SCALE.ToS()));
       foreach (FSMBehaviour behaviour in this.customExitBehaviours) {
     state.AddExitBehaviour(behaviour);
       }
       stateWrapper.state = state;
       //TRANSITIONS
       FSMTransition transition = null;
       foreach (string animationName in this.animationNames) {
     transition = new FSMTransition(this.stateName, this.waitStateName);
     transition.AddCondition(new AnimationEndCondition(this.gameObject.GetComponent<Animator>(), animationName));
     stateWrapper.transitions.Add(transition);
       }
       //RETURN
       foreach (ComboWrapper combo in this.combos.Values) {
     transition = new FSMTransition(this.waitStateName, combo.toState);
     transition.AddConditions(
       new VarConditionsBuilder()
       .IgnoringInputs().IgnoringAttributes().IgnoringDirections().IgnoringPositions().IgnoringFlags().IgnoringCombat()
       .WithVar(CharVars.COMBO_VARIANT, new IntCondition(CharVars.COMBO_VARIANT.ToS(), Operators.EQUAL, combo.variant))
       .Build()
     );
     stateWrapper.transitions.Add(transition);
       }
       transition = new FSMTransition(this.waitStateName, CharStates.FALL.ToS());
       transition.AddCondition(new TimeCondition(this.timeout));
       transition.AddConditions(
     new VarConditionsBuilder()
     .IgnoringInputs().IgnoringAttributes().IgnoringDirections().IgnoringPositions().IgnoringFlags().IgnoringCombat()
     .WithVar(CharVars.IS_FLYING, new BoolCondition(CharVars.IS_FLYING.ToS(), Operators.EQUAL, false))
     .Build()
       );
       stateWrapper.transitions.Add(transition);
       transition = new FSMTransition(this.waitStateName, CharStates.FLY.ToS());
       transition.AddCondition(new TimeCondition(this.timeout));
       transition.AddConditions(
     new VarConditionsBuilder()
     .IgnoringInputs().IgnoringAttributes().IgnoringDirections().IgnoringPositions().IgnoringFlags().IgnoringCombat()
     .WithVar(CharVars.IS_FLYING, new BoolCondition(CharVars.IS_FLYING.ToS(), Operators.EQUAL, true))
     .Build()
       );
       stateWrapper.transitions.Add(transition);
       return stateWrapper;
 }
 private StateWrapper BuildAttack()
 {
     StateWrapper stateWrapper = new StateWrapper();
       FSMState state = new ActionState(this.stateName);
       state.WithDefaultBehaviours(this.gameObject);
       if (this.animationBehaviour != null) {
     state.AddStartBehaviour(this.animationBehaviour);
       }
       state.AddStartBehaviour(new SetVariableBehaviour(this.gameObject, CharVars.ATTACK_EFFECT.ToS(), (int) AttackEffects.NONE));
       if (this.stepForce != 0) {
     state.AddStartBehaviour(
       new ApplyForceBehaviour(this.gameObject)
       .WithDirection(new Vector2(1f, 0f))
       .WithForce(this.stepForce)
       .WithRelativeXDirection(CharVars.FACING_DIRECTION.ToS(), false)
     );
       }
       foreach (ComboWrapper combo in this.combos.Values) {
     SetVariableBehaviour behaviour = new SetVariableBehaviour(this.gameObject, CharVars.COMBO_VARIANT.ToS(), combo.variant);
     foreach (ICondition condition in combo.conditions) {
       behaviour = behaviour.WithCondition(condition);
     }
     state.AddUpdateBehaviour(behaviour);
       }
       foreach (FSMBehaviour behaviour in this.customStartBehaviours) {
     state.AddStartBehaviour(behaviour);
       }
       foreach (FSMBehaviour behaviour in this.customUpdateBehaviours) {
     state.AddUpdateBehaviour(behaviour);
       }
       foreach (FSMBehaviour behaviour in this.customExitBehaviours) {
     state.AddExitBehaviour(behaviour);
       }
       stateWrapper.state = state;
       FSMTransition transition = null;
       foreach (string startingState in this.startingStates) {
     transition = new FSMTransition(startingState, this.stateName);
     VarConditionsBuilder conditions = new VarConditionsBuilder()
     .IgnoringInputs().IgnoringAttributes().IgnoringDirections().IgnoringPositions().IgnoringFlags().IgnoringCombat();
     if (this.fromCharge) {
       conditions.WithVar(CharVars.FromInputMode(this.input), new InputCondition(CharVars.FromInputMode(this.input).ToS(), Operators.EQUAL, InputModes.RELEASE, InputModes.NONE));
     } else {
       conditions.WithVar(CharVars.FromInputMode(this.input), new InputCondition(CharVars.FromInputMode(this.input).ToS(), Operators.EQUAL, InputModes.PRESS, InputModes.DOUBLE_TAP));
     }
     foreach (CharVar charVar in this.customTransitions.Keys) {
       conditions.WithVar(charVar, this.customTransitions[charVar]);
     }
     transition.AddConditions(conditions.Build());
     stateWrapper.transitions.Add(transition);
       }
       // // RETURN
       foreach (string animationName in this.animationNames) {
     foreach (ComboWrapper combo in this.combos.Values) {
       transition = new FSMTransition(this.stateName, combo.toState);
       transition.AddCondition(new AnimationEndCondition(this.gameObject.GetComponent<Animator>(), animationName));
       transition.AddConditions(
     new VarConditionsBuilder()
     .IgnoringInputs().IgnoringAttributes().IgnoringDirections().IgnoringPositions().IgnoringFlags().IgnoringCombat()
     .WithVar(CharVars.COMBO_VARIANT, new IntCondition(CharVars.COMBO_VARIANT.ToS(), Operators.EQUAL, combo.variant))
     .Build()
       );
       stateWrapper.transitions.Add(transition);
     }
     transition = new FSMTransition(this.stateName, CharStates.IDLE.ToS());
     transition.AddCondition(new AnimationEndCondition(this.gameObject.GetComponent<Animator>(), animationName));
     transition.AddConditions(
       new VarConditionsBuilder()
       .IgnoringInputs().IgnoringAttributes().IgnoringDirections().IgnoringPositions().IgnoringFlags().IgnoringCombat()
       .WithVar(CharVars.IS_FLYING, new BoolCondition(CharVars.IS_FLYING.ToS(), Operators.EQUAL, false))
       .Build()
     );
     stateWrapper.transitions.Add(transition);
     transition = new FSMTransition(this.stateName, CharStates.FLY.ToS());
     transition.AddCondition(new AnimationEndCondition(this.gameObject.GetComponent<Animator>(), animationName));
     transition.AddConditions(
       new VarConditionsBuilder()
       .IgnoringInputs().IgnoringAttributes().IgnoringDirections().IgnoringPositions().IgnoringFlags().IgnoringCombat()
       .WithVar(CharVars.IS_FLYING, new BoolCondition(CharVars.IS_FLYING.ToS(), Operators.EQUAL, true))
       .Build()
     );
     stateWrapper.transitions.Add(transition);
       }
       return stateWrapper;
 }