action_vfx.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "action_vfx.h"
  2. #include "../../game/core/component.h"
  3. #include "../../game/core/entity.h"
  4. #include "../../game/core/world.h"
  5. #include "../../game/game_config.h"
  6. #include "../../game/systems/arrow_system.h"
  7. #include <qvectornd.h>
  8. namespace App::Controllers {
  9. void ActionVFX::spawnAttackArrow(Engine::Core::World *world,
  10. Engine::Core::EntityID target_id) {
  11. if (world == nullptr) {
  12. return;
  13. }
  14. auto *arrow_system = world->getSystem<Game::Systems::ArrowSystem>();
  15. if (arrow_system == nullptr) {
  16. return;
  17. }
  18. auto *target_entity = world->getEntity(target_id);
  19. if (target_entity == nullptr) {
  20. return;
  21. }
  22. auto *target_trans =
  23. target_entity->getComponent<Engine::Core::TransformComponent>();
  24. if (target_trans == nullptr) {
  25. return;
  26. }
  27. QVector3D const target_pos(target_trans->position.x,
  28. target_trans->position.y + 1.0F,
  29. target_trans->position.z);
  30. QVector3D const above_target = target_pos + QVector3D(0, 2.0F, 0);
  31. arrow_system->spawnArrow(above_target, target_pos,
  32. QVector3D(1.0F, 0.2F, 0.2F),
  33. Game::GameConfig::instance().arrow().speedAttack);
  34. }
  35. } // namespace App::Controllers