-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSectorSystem.cpp
102 lines (89 loc) · 2.8 KB
/
SectorSystem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "pch.h"
#include "SectorSystem.h"
#include "VisPredComponents.h"
#include "EventManager.h"
SectorSystem::SectorSystem(std::shared_ptr<SceneManager> scenemanager) :System(scenemanager)
{
EventManager::GetInstance().Subscribe("OnEnemyKilled", CreateSubscriber(&SectorSystem::OnEnemyKilled));
EventManager::GetInstance().Subscribe("OnHideEnemyCount", CreateSubscriber(&SectorSystem::OnHideEnemyCount));
}
void SectorSystem::OnEnemyKilled(std::any enemyid)
{
auto entityid = std::any_cast<uint32_t>(enemyid);
auto sectorcomp = GetSceneManager()->GetParentEntityComp_HasComp<SectorClearComponent>(entityid);
if (!sectorcomp)
return;
//auto sectorcomp = sectorentity->GetComponent<SectorClearComponent>();
CheckSectorClear(sectorcomp);
}
void SectorSystem::CheckSectorClear(SectorClearComponent* sectorcomp)
{
bool isSectorclear = true;
auto enemys =GetSceneManager()->GetChildEntityComps_HasComp<EnemyComponent>(sectorcomp->GetEntityID());
if (enemys.empty())
isSectorclear = true;
int LiveEnemy = 0;
for (auto enemy : enemys)
{
if (enemy->BehaviorState != &EnemyBehaviorState::s_Dead)
{
isSectorclear = false;
LiveEnemy++;
}
}
if (!isSectorclear && sectorcomp->HasComponent<TextComponent>())
{
auto text = sectorcomp->GetComponent<TextComponent>();
// Set the message with the enemy count
text->Text = sectorcomp->Ment + std::to_wstring(LiveEnemy);
if (sectorcomp->HasComponent<TextBounceComponent>())
{
sectorcomp->GetComponent<TextBounceComponent>()->AddedBounce = true;
}
}
if (isSectorclear)
{
auto entity = GetSceneManager()->GetEntity(sectorcomp->GetEntityID());
std::pair<std::shared_ptr<Entity>, std::shared_ptr<Entity>> eventData(entity, nullptr);
EventManager::GetInstance().ImmediateEvent("OnInterected", eventData);
EventManager::GetInstance().ImmediateEvent("OnChangeTopic", VisPred::Game::TopicType::FINDBELL);
if (sectorcomp->HasComponent<TextComponent>())
{
auto text = sectorcomp->GetComponent<TextComponent>();
text->Text = {};
}
}
}
void SectorSystem::OnHideEnemyCount(std::any null)
{
COMPLOOP(SectorClearComponent, sectorcomp)
{
if (sectorcomp.HasComponent<TextComponent>())
{
auto text = sectorcomp.GetComponent<TextComponent>();
// Set the message with the enemy count
text->Text = {};
}
}
}
void SectorSystem::Initialize()
{
COMPLOOP(SectorClearComponent, comp)
{
Start(comp.GetEntityID());
}
}
void SectorSystem::Start(uint32_t gameObjectId)
{
auto entity = GetSceneManager()->GetEntity(gameObjectId);
if (!entity || !entity->HasComponent<SectorClearComponent>())
return;
CheckSectorClear(entity->GetComponent<SectorClearComponent>());
EventManager::GetInstance().ImmediateEvent("OnChangeTopic", VisPred::Game::TopicType::KILLALL);
}
void SectorSystem::Finish(uint32_t gameObjectId)
{
}
void SectorSystem::Finalize()
{
}