combat_state_processor.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "combat_state_processor.h"
  2. #include "../../core/component.h"
  3. #include "../../core/world.h"
  4. namespace Game::Systems::Combat {
  5. void process_combat_state(Engine::Core::World *world, float delta_time) {
  6. auto units = world->get_entities_with<Engine::Core::CombatStateComponent>();
  7. for (auto *unit : units) {
  8. if (unit->has_component<Engine::Core::PendingRemovalComponent>()) {
  9. continue;
  10. }
  11. auto *combat_state =
  12. unit->get_component<Engine::Core::CombatStateComponent>();
  13. if (combat_state == nullptr) {
  14. continue;
  15. }
  16. if (combat_state->is_hit_paused) {
  17. combat_state->hit_pause_remaining -= delta_time;
  18. if (combat_state->hit_pause_remaining <= 0.0F) {
  19. combat_state->is_hit_paused = false;
  20. combat_state->hit_pause_remaining = 0.0F;
  21. }
  22. continue;
  23. }
  24. combat_state->state_time += delta_time;
  25. if (combat_state->state_time >= combat_state->state_duration) {
  26. using CS = Engine::Core::CombatAnimationState;
  27. using CSC = Engine::Core::CombatStateComponent;
  28. switch (combat_state->animation_state) {
  29. case CS::Advance:
  30. combat_state->animation_state = CS::WindUp;
  31. combat_state->state_duration = CSC::kWindUpDuration;
  32. break;
  33. case CS::WindUp:
  34. combat_state->animation_state = CS::Strike;
  35. combat_state->state_duration = CSC::kStrikeDuration;
  36. break;
  37. case CS::Strike:
  38. combat_state->animation_state = CS::Impact;
  39. combat_state->state_duration = CSC::kImpactDuration;
  40. break;
  41. case CS::Impact:
  42. combat_state->animation_state = CS::Recover;
  43. combat_state->state_duration = CSC::kRecoverDuration;
  44. break;
  45. case CS::Recover:
  46. combat_state->animation_state = CS::Reposition;
  47. combat_state->state_duration = CSC::kRepositionDuration;
  48. break;
  49. case CS::Reposition:
  50. case CS::Idle:
  51. default:
  52. combat_state->animation_state = CS::Idle;
  53. combat_state->state_duration = 0.0F;
  54. break;
  55. }
  56. combat_state->state_time = 0.0F;
  57. }
  58. }
  59. }
  60. } // namespace Game::Systems::Combat