/** * Handler for player data * $Id$ * $HeadURL$ * $Author$ * Created by hjl, SLSE, 2017-02-20 */ #include "handler_blocked_areas.h" #include "handler_participant_building.h" #include namespace CesParticipantBuildings { HandlerBlockedAreas::HandlerBlockedAreas(const std::shared_ptr &ddsHandler, const std::shared_ptr &participantHandler, const std::shared_ptr &participantBuildingHandler, QObject *parent) : QObject(parent) , m_ddsHandler(ddsHandler) , m_handlerParticipant(participantHandler) , m_handlerParticipantBuilding(participantBuildingHandler) , m_logger(CentralEffectSimulation::getLogger("Plugin.ParticipantBuildings.HandlerBlockedAreas")) { } // end of ctor() //----------------------------------------------------------------------------- HandlerBlockedAreas::~HandlerBlockedAreas() { } // end of dtor() //----------------------------------------------------------------------------- bool HandlerBlockedAreas::init() { DEBUG_LOG(m_logger) << "init"; connect(m_handlerParticipant.get(), &CentralEffectSimulation::HandlerParticipant::newIndoorPosition, this, &HandlerBlockedAreas::onParticipantPositionChanged); connect(m_handlerParticipant.get(), &CentralEffectSimulation::HandlerParticipant::newOutdoorPosition, this, &HandlerBlockedAreas::onParticipantPositionChanged); connect(m_handlerParticipantBuilding.get(), &HandlerParticipantBuilding::newBuildingState, this, &HandlerBlockedAreas::onBuildingStateChanged); return true; } // end of init() //----------------------------------------------------------------------------- void HandlerBlockedAreas::onSendParticipantBlockedAreaReply(const Core::FunctionReplyObject &replyObject) { if (replyObject.error()) WARNING_LOG(m_logger) << "Can not send blocked Area to participant : " << replyObject(); else DEBUG_LOG(m_logger) << "onSendParticipantBlockedAreaReply for id " << replyObject.id() << " success"; } void HandlerBlockedAreas::onParticipantPositionChanged(const CentralEffectSimulation::HandlerParticipant::CesParticipantData &partPos) { const int participantId = partPos.participantId(); int damagePercentBlockedAreas = 90; // From the percentage damage, blocked area applies Todo Config Value DEBUG_LOG(m_logger) << "HandlerBlockedAreas onParticipantPositionChanged participantId=" << participantId; TrainingAreaBase::SendParticipantBlockedAreaRequest pba; pba.equipmentNumber(m_ddsHandler->participantId2EquipNo(partPos.participantId())); pba.participantId(partPos.participantId()); // if (partPos.vulnerabilityState == ProjectDataManagement::VulnerabilityState_def::CombatReady) // m_blockedAreas.remove(participantId); if (!partPos.insideBuilding()) { auto it = m_blockedAreas.find(participantId); if (it != m_blockedAreas.end()) { DEBUG_LOG(m_logger) << "Blocked Area Leave equipment-No. =" << pba.equipmentNumber(); pba.blockedAreaMode(TrainingAreaBase::BlockedAreaMode_def::Leave); m_ddsHandler->ftcTab()->sendParticipantBlockedAreaRequest(pba, this); m_blockedAreas.erase(it); } return; } else { // check leave if (m_blockedAreas.contains(participantId) && (m_handlerParticipantBuilding->getDamagePercentFromRoom(partPos.roomId()) < damagePercentBlockedAreas)) { DEBUG_LOG(m_logger) << "Blocked Area Leave equipment-No. =" << pba.equipmentNumber(); pba.blockedAreaMode(TrainingAreaBase::BlockedAreaMode_def::Leave); m_ddsHandler->ftcTab()->sendParticipantBlockedAreaRequest(pba, this); m_blockedAreas.remove(participantId); return; } } DEBUG_LOG(m_logger) << "Room =" << partPos.roomId() << " DamagePercentRoom=" << m_handlerParticipantBuilding->getDamagePercentFromRoom(partPos.roomId()); DEBUG_LOG(m_logger) << "1: " << m_handlerParticipantBuilding->getDamagePercentFromRoom(partPos.roomId()) << " damagePercentBlockedAreas= " << damagePercentBlockedAreas << "\n" << " getDamagePercentFromBuilding=" << m_handlerParticipantBuilding->getDamagePercentFromBuilding(partPos.buildingId()) << "\n" << "m_blockedAreas.contains(participantId) = " << m_blockedAreas.contains(participantId) ; if ((m_handlerParticipantBuilding->getDamagePercentFromRoom(partPos.roomId()) >= damagePercentBlockedAreas || m_handlerParticipantBuilding->getDamagePercentFromBuilding(partPos.buildingId()) == 100) && !m_blockedAreas.contains(participantId)) { DEBUG_LOG(m_logger) << "Send Enter Blocked Area to Participant:" << participantId; pba.blockedAreaMode(TrainingAreaBase::BlockedAreaMode_def::Enter); m_ddsHandler->ftcTab()->sendParticipantBlockedAreaRequest(pba, this); m_blockedAreas.insert(participantId, partPos.roomId()); } } // end of onParticipantPositionChanged() void HandlerBlockedAreas::onBuildingStateChanged(const int32_t buildingId) { DEBUG_LOG(m_logger) << "onBuildingStateChanged buildingId:" << buildingId; int damagePercent = m_handlerParticipantBuilding->getDamagePercentFromBuilding(buildingId); if (damagePercent == 0 && !m_blockedAreas.isEmpty()) // init { const auto participants = m_handlerParticipant->getParticipantsBuilding(buildingId); for (int participantId : participants) { if (m_blockedAreas.contains(participantId)) { DEBUG_LOG(m_logger) << "remove participantId: " << participantId; TrainingAreaBase::SendParticipantBlockedAreaRequest pba; pba.equipmentNumber(m_ddsHandler->participantId2EquipNo(participantId)); pba.participantId(participantId); pba.blockedAreaMode(TrainingAreaBase::BlockedAreaMode_def::Leave); m_ddsHandler->ftcTab()->sendParticipantBlockedAreaRequest(pba, this); m_blockedAreas.remove(participantId); } } } } } // namespace CesParticipantBuildings