private static void decide_nextAction_default(BattleResolutionStep p_battle, BattleEntity p_actingEntity, AttackDefinition p_attack) { BattleEntity l_targettedEntity = null; switch (p_actingEntity.Team) { case BattleEntity_Team.PLAYER: { l_targettedEntity = BattleDecision.Utils.find_battleEntity_ofTeam_random(p_battle, BattleEntity_Team.FOE); } break; case BattleEntity_Team.FOE: { l_targettedEntity = BattleDecision.Utils.find_battleEntity_ofTeam_random(p_battle, BattleEntity_Team.PLAYER); } break; } if (l_targettedEntity != null) { BQE_Attack l_attackEvent = new BQE_Attack { Attack = p_attack, Source = p_actingEntity, Target = l_targettedEntity }; Battle_Singletons._battleResolutionStep.push_attack_event(p_actingEntity, l_attackEvent); } }
// (this.CurrentlySelectedEntity != null) condition is verified before public void pushAction_forCurrentSelectedEntity(BQE_Attack p_attackEvent) { //Optional, as it must be provided, but just to be safe p_attackEvent.Source = this.CurrentlySelectedEntity; this.BattleResolution.push_attack_event(this.CurrentlySelectedEntity, p_attackEvent); this.PlayerControlledEntity_ExecutingAction.Add(this.CurrentlySelectedEntity); this.PlayerControlledEntity_WaitingForInput.Remove(this.CurrentlySelectedEntity); this.set_CurrentlySelectedEntity(null); }
public static Initialize_ReturnCode initialize_attackAnimation(BattleQueueEvent p_event) { switch (p_event.Type) { case BattleQueueEvent_Type.ATTACK: { BQE_Attack l_event = (BQE_Attack)p_event.Event; if (!l_event.Source.IsDead && !l_event.Target.IsDead) { switch (l_event.Attack.AttackType) { case Attack_Type.DEFAULT: { switch (l_event.Source.Type) { case BattleEntity_Type.PLAYER_1: { BattleEntityComponent l_battleEntity = BattleEntityComponent_Container.ComponentsByHandle[l_event.Source]; l_event.Context_UserObject = new Anim_BattleAttack_Default(); ((Anim_BattleAttack_Default)l_event.Context_UserObject).Initialize(BattleEntityComponent_Container.ComponentsByHandle[l_event.Source], BattleEntityComponent_Container.ComponentsByHandle[l_event.Target], ((PLAYER_1_conf)l_battleEntity.BattleEntityConfiguration).Animation_DefaultAttack, l_event.Attack); l_battleEntity.BattleAnimations.push_attackAnimation(l_event, Anim_BattleAttack_Default.Update); return(Initialize_ReturnCode.NEEDS_TO_BE_PROCESSED); } case BattleEntity_Type.PLAYER_2: { BattleEntityComponent l_battleEntity = BattleEntityComponent_Container.ComponentsByHandle[l_event.Source]; l_event.Context_UserObject = new Anim_BattleAttack_Default(); ((Anim_BattleAttack_Default)l_event.Context_UserObject).Initialize(BattleEntityComponent_Container.ComponentsByHandle[l_event.Source], BattleEntityComponent_Container.ComponentsByHandle[l_event.Target], ((PLAYER_2_conf)l_battleEntity.BattleEntityConfiguration).Animation_DefaultAttack, l_event.Attack); l_battleEntity.BattleAnimations.push_attackAnimation(l_event, Anim_BattleAttack_Default.Update); return(Initialize_ReturnCode.NEEDS_TO_BE_PROCESSED); } case BattleEntity_Type.SOLIDER_MACHINEGUN_0: { BattleEntityComponent l_battleEntity = BattleEntityComponent_Container.ComponentsByHandle[l_event.Source]; l_event.Context_UserObject = new Anim_BattleAttack_Distance(); ((Anim_BattleAttack_Distance)l_event.Context_UserObject).Initialize(BattleEntityComponent_Container.ComponentsByHandle[l_event.Source], BattleEntityComponent_Container.ComponentsByHandle[l_event.Target]); l_battleEntity.BattleAnimations.push_attackAnimation(l_event, Anim_BattleAttack_Distance.Update); return(Initialize_ReturnCode.NEEDS_TO_BE_PROCESSED); } } } break; } } } break; } return(Initialize_ReturnCode.NOTHING); }
public void Update(float d) { if (this.AnimationUpdateFunction != null && this.CurrentAnimationObject != null) { this.AnimationUpdateFunction.Invoke(this.CurrentAnimationObject, d); if (this.CurrentAnimationObject.HasEnded) { this.AnimationUpdateFunction = null; this.CurrentAnimationObject = null; } } }
public static void Update(BQE_Attack p_attackEvent, float d) { Anim_BattleAttack_Distance l_battleAttack = (Anim_BattleAttack_Distance)p_attackEvent.Context_UserObject; switch (l_battleAttack.State) { case Anim_BattleAttack_Distance_State.End: { if (p_attackEvent.Out_DamageSteps == null) { p_attackEvent.Out_DamageSteps = new List <BaseDamageStep>(); } p_attackEvent.Out_DamageSteps.Add(BaseDamageStep.build(p_attackEvent.Source, p_attackEvent.Target, p_attackEvent.Attack)); l_battleAttack.AnimatedTransform.transform.rotation = l_battleAttack.InitalAnimatedTransform_Rotation; p_attackEvent.HasEnded = true; } break; } }
public void update(float d) { if (Battle_Singletons._battleActionSelection.CurrentlySelectedEntity != null) { if (!SceneGlobalObjects.BattleActionSelectionUI.isEnabled) { SceneGlobalObjects.BattleActionSelectionUI.enable(); this.set_state(BattleSelectionFlowState.IN_ACTIONSELECTION_MENU); } switch (this.State) { case BattleSelectionFlowState.NOTHING: break; case BattleSelectionFlowState.IN_ACTIONSELECTION_MENU: { if (Input.GetKeyDown(KeyCode.Space)) { this.set_state(BattleSelectionFlowState.TARGETTING_ENTITY); } else if (Input.GetKeyDown(KeyCode.LeftControl)) { Battle_Singletons._battleActionSelection.switch_selection(); } } break; case BattleSelectionFlowState.TARGETTING_ENTITY: { if (Input.GetKeyDown(KeyCode.Space)) { BQE_Attack l_attackEvent = new BQE_Attack { Attack = BattleAttackConfiguration_Algorithm.find_defaultAttackDefinition(BattleEntityComponent_Container.ComponentsByHandle[Battle_Singletons._battleActionSelection.CurrentlySelectedEntity]), Source = Battle_Singletons._battleActionSelection.CurrentlySelectedEntity, Target = Battle_Singletons._battleResolutionStep.BattleEntities[Battle_Singletons._battleTargetSelection.CurrentlySelectedEntity_BattleIndex] }; Battle_Singletons._battleActionSelection.pushAction_forCurrentSelectedEntity(l_attackEvent); this.state_switchToActionSelectionMenu(); } else if (Input.GetKeyDown(KeyCode.LeftControl)) { Battle_Singletons._battleTargetSelection.switch_target(); } else if (Input.GetKeyDown(KeyCode.Backspace)) { this.state_switchToActionSelectionMenu(); } } break; } SceneGlobalObjects.BattleActionSelectionUI.update(Battle_Singletons._battleActionSelection); SceneGlobalObjects.BattleTargetSelectionUI.update(Battle_Singletons._battleTargetSelection); } else { if (SceneGlobalObjects.BattleActionSelectionUI.isEnabled) { this.set_state(BattleSelectionFlowState.NOTHING); SceneGlobalObjects.BattleActionSelectionUI.disable(); } } }
public void update(float d) { this.Out_DamageApplied_Events.Clear(); this.Out_Death_Events.Clear(); this.Out_CompletedBattlequeue_Events.Clear(); // Update ATB_Values if (!this.ATB_Locked) { for (int i = 0; i < this.BattleEntities.Count; i++) { BattleEntity l_entity = this.BattleEntities[i]; if (!l_entity.IsDead) { l_entity.ATB_Value = Math.Min(l_entity.ATB_Value + (l_entity.ATB_Speed * d), 1.0f); if (l_entity.ATB_Value >= 1.0f) { if (!l_entity.IsControlledByPlayer) { this.BattleActionDecision_UserFunction.Invoke(this, l_entity); } } } this.BattleEntities[i] = l_entity; } } // A step takes the first entry of the BattleQueueEvents and initialize it step: if (this.CurrentExecutingEvent == null) { if (this.BattleQueueEvents.Count > 0) { this.CurrentExecutingEvent = this.BattleQueueEvents.Dequeue(); switch (this.BattleQueueEventInitialize_UserFunction.Invoke(this.CurrentExecutingEvent)) { case Initialize_ReturnCode.NOTHING: // When initialization doesn't require further processing, then we perform another step. this.on_currentActionFinished(); goto step; } } } if (this.CurrentExecutingEvent != null) { this.ATB_Locked = true; // We perform specific operation every frame for the current executing event switch (this.CurrentExecutingEvent.Type) { case BattleQueueEvent_Type.ATTACK: { // We consume damage events of the BQE_Attack event and push it to the global queue. BQE_Attack l_event = (BQE_Attack)this.CurrentExecutingEvent.Event; if (l_event.Out_DamageSteps != null && l_event.Out_DamageSteps.Count > 0) { for (int i = 0; i < l_event.Out_DamageSteps.Count; i++) { this.DamageEvents.Add(l_event.Out_DamageSteps[i]); } l_event.Out_DamageSteps.Clear(); } if (l_event.HasEnded) { on_currentActionFinished(); } } break; } } else { this.ATB_Locked = false; } // Effectively apply damage events if (this.DamageEvents.Count > 0) { for (int i = 0; i < this.DamageEvents.Count; i++) { BaseDamageStep l_damageEvent = this.DamageEvents[i]; int l_appliedDamage = DamageCalculation_Algorithm.calculate(l_damageEvent); if (DamageCalculation_Algorithm.apply_damage_raw(l_appliedDamage, l_damageEvent.Target)) { l_damageEvent.Target.IsDead = true; push_death_event(l_damageEvent.Target); this.BattleEntities.Remove(l_damageEvent.Target); this.DeadBattleEntities.Add(l_damageEvent.Target); } this.Out_DamageApplied_Events.Add(BQEOut_FinalDamageApplied.Alloc(l_damageEvent.Target, l_appliedDamage)); } this.DamageEvents.Clear(); } }
public void push_attackAnimation(BQE_Attack p_attackAnimation, Action <BQE_Attack, float> p_animationUpdateFunction) { this.CurrentAnimationObject = p_attackAnimation; this.AnimationUpdateFunction = p_animationUpdateFunction; }
public static void Update(BQE_Attack p_attackEvent, float delta) { Anim_BattleAttack_Default l_battleAttack = (Anim_BattleAttack_Default)p_attackEvent.Context_UserObject; switch (l_battleAttack.State) { case Anim_BattleAttack_Default_State.Preparing: { } break; case Anim_BattleAttack_Default_State.MovingForward: { float l_distance = Vector3.Distance(l_battleAttack.AnimatedTransform.transform.position, l_battleAttack.TargetPosition_MovingForward); if ((l_distance > l_battleAttack.LastFrameDistace) || (l_distance <= 0.001f)) { // We terminate the movement l_battleAttack.AnimatedTransform.transform.position = l_battleAttack.TargetPosition_MovingForward; if (p_attackEvent.Out_DamageSteps == null) { p_attackEvent.Out_DamageSteps = new List <BaseDamageStep>(); } p_attackEvent.Out_DamageSteps.Add(BaseDamageStep.build(p_attackEvent.Source, p_attackEvent.Target, p_attackEvent.Attack)); l_battleAttack.State = Anim_BattleAttack_Default_State.Slashing; l_battleAttack.LastFrameDistace = Vector3.Distance(l_battleAttack.InitalAnimatedTransform_Position, l_battleAttack.TargetPosition_MovingForward); return; } float l_distanceRatio = 1.0f - (l_distance / Vector3.Distance(l_battleAttack.TargetPosition_MovingForward, l_battleAttack.InitalAnimatedTransform_Position)); l_battleAttack.AnimatedTransform.transform.position += l_battleAttack.Movement_ForwardDirection * l_battleAttack.Conf.AnimatedTransform_Speed_V2.Evaluate(l_distanceRatio) * l_battleAttack.Conf.AnimatedTransform_Speed_Forward * delta; l_battleAttack.LastFrameDistace = l_distance; if (!l_battleAttack.IsSlashAnimationTriggered && l_distanceRatio >= l_battleAttack.Conf.DistanceRatio_MoveForward_StartMovingLegs) { l_battleAttack.IsSlashAnimationTriggered = true; l_battleAttack.AnimatedTransform.AnimatorDispatcher.Animator.Play(AnimatorStateConstants.Attack_Close_Slash); } } break; case Anim_BattleAttack_Default_State.Slashing: { if (l_battleAttack.IsSlashAnimationOver) { l_battleAttack.StandingStill_AfterSlash_Timer += delta; if (l_battleAttack.StandingStill_AfterSlash_Timer >= l_battleAttack.Conf.TimeStandingStill_AfterSlashing) { l_battleAttack.AnimatedTransform.AnimatorDispatcher.Animator.Play(AnimatorStateConstants.Attack_Close_MoveBackward); l_battleAttack.State = Anim_BattleAttack_Default_State.MovingBackward; Update(p_attackEvent, delta); } } } break; case Anim_BattleAttack_Default_State.MovingBackward: { float l_distance = Vector3.Distance(l_battleAttack.AnimatedTransform.transform.position, l_battleAttack.InitalAnimatedTransform_Position); if ((l_distance > l_battleAttack.LastFrameDistace) || (l_distance <= 0.001f)) { // We terminate the movement l_battleAttack.AnimatedTransform.transform.position = l_battleAttack.InitalAnimatedTransform_Position; l_battleAttack.AnimatedTransform.transform.rotation = l_battleAttack.InitalAnimatedTransform_Rotation; p_attackEvent.HasEnded = true; l_battleAttack.State = Anim_BattleAttack_Default_State.End; l_battleAttack.AnimatedTransform.AnimatorDispatcher.Animator.CrossFadeInFixedTime(AnimatorStateConstants.Attack_Close_Idle, 0.1f); return; } l_battleAttack.AnimatedTransform.transform.position += (-l_battleAttack.Movement_ForwardDirection) * l_battleAttack.Conf.AnimatedTransform_Speed_Backward * delta; l_battleAttack.LastFrameDistace = l_distance; } break; } return; }