DarkflameServer/dScripts/TouchMissionUpdateServer.cpp

52 lines
1.2 KiB
C++
Raw Normal View History

#include "TouchMissionUpdateServer.h"
#include "Entity.h"
#include "GameMessages.h"
#include "MissionComponent.h"
2022-07-28 13:39:57 +00:00
void TouchMissionUpdateServer::OnStartup(Entity* self) {
self->SetProximityRadius(20, "touchCheck"); // Those does not have a collider for some reason?
}
2022-07-28 13:39:57 +00:00
void TouchMissionUpdateServer::OnCollisionPhantom(Entity* self, Entity* target) {
int32_t missionId = self->GetVar<int32_t>(u"TouchCompleteID");
2022-07-28 13:39:57 +00:00
if (missionId == 0) {
return;
}
2022-07-28 13:39:57 +00:00
auto* missionComponent = static_cast<MissionComponent*>(target->GetComponent(COMPONENT_TYPE_MISSION));
2022-07-28 13:39:57 +00:00
if (missionComponent == nullptr) {
return;
}
auto* mission = missionComponent->GetMission(missionId);
2022-07-28 13:39:57 +00:00
if (mission == nullptr) {
return;
}
const auto state = mission->GetMissionState();
2022-07-28 13:39:57 +00:00
if (state >= MissionState::MISSION_STATE_COMPLETE || mission->GetCompletions() > 1) {
return;
}
2022-07-28 13:39:57 +00:00
for (auto* task : mission->GetTasks()) {
if (!task->IsComplete()) {
task->Complete();
}
}
mission->CheckCompletion();
}
2022-07-28 13:39:57 +00:00
void TouchMissionUpdateServer::OnProximityUpdate(Entity* self, Entity* entering, const std::string name, const std::string status) {
if (name != "touchCheck" || status != "ENTER") {
return;
}
OnCollisionPhantom(self, entering);
}