private void Update() { float l_delta = Time.deltaTime; Battle_Singletons._battleActionSelection.update(l_delta); Battle_Singletons._battleTargetSelection.update(l_delta); SceneGlobalObjects.PlayerTurnInputflow.update(l_delta); Battle_Singletons._battleResolutionStep.update(l_delta); this.AtbUI.Update(l_delta); // Handling damage applied events if (Battle_Singletons._battleResolutionStep.Out_DamageApplied_Events.Count > 0) { for (int i = 0; i < Battle_Singletons._battleResolutionStep.Out_DamageApplied_Events.Count; i++) { BQEOut_FinalDamageApplied l_event = Battle_Singletons._battleResolutionStep.Out_DamageApplied_Events[i]; BattleEntityComponent l_targetEntity = BattleEntityComponent_Container.ComponentsByHandle[l_event.Target]; RectTransform l_instanciatedDamageTextObject = GameObject.Instantiate(this.DamageTextPrefab, SceneGlobalObjects.MainCanvas.transform); Text l_instanciatedDamageText = l_instanciatedDamageTextObject.GetComponentInChildren <Text>(); l_instanciatedDamageText.text = l_event.FinalDamage.ToString(); ((RectTransform)l_instanciatedDamageTextObject.transform).position = SceneGlobalObjects.MainCamera.WorldToScreenPoint(l_targetEntity.DamageDisplay_Transform.transform.position); BattleAnimation.onDamageReceived(l_targetEntity); } } // On battle entity death if (Battle_Singletons._battleResolutionStep.Out_Death_Events.Count > 0) { for (int i = 0; i < Battle_Singletons._battleResolutionStep.Out_Death_Events.Count; i++) { BattleEntity l_deadEntity = Battle_Singletons._battleResolutionStep.Out_Death_Events[i]; BattleEntityComponent l_destroyedEntityComponent = BattleEntityComponent_Container.ComponentsByHandle[l_deadEntity]; SceneGlobalObjects.PlayerTurnInputflow.on_battleEntityDeath(l_destroyedEntityComponent); //handling selection Battle_Singletons._battleActionSelection.on_battleEntityDeath(l_destroyedEntityComponent.BattleEntityHandle); //handling target selection Battle_Singletons._battleTargetSelection.on_battleEntityDeath(i); //We update the BattleTargetSelectionUI is the _battleTargetSelection has changed by taking into account death SceneGlobalObjects.BattleTargetSelectionUI.update(Battle_Singletons._battleTargetSelection); l_destroyedEntityComponent.Dispose(); } // Battle_Singletons._battleResolutionStep.Out_Death_Events.Clear(); } BattleEntityComponent_Container.Update(l_delta); }
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(); } }