void EntertainingSessionImplementation::doPerformanceAction() {
	ManagedReference<CreatureObject*> entertainer = this->entertainer.get();

	if (entertainer == NULL)
		return;

	Locker locker(entertainer);

	Performance* performance = NULL;

	PerformanceManager* performanceManager = SkillManager::instance()->getPerformanceManager();
	ManagedReference<Instrument*> instrument = getInstrument(entertainer);

	if (isDancing())
		performance = performanceManager->getDance(performanceName);
	else if (isPlayingMusic() && instrument)
		performance = performanceManager->getSong(performanceName, instrument->getInstrumentType());
	else {
		cancelSession();
		return;
	}

	if (performance == NULL) { // shouldn't happen
		StringBuffer msg;
		msg << "Performance was null.  Please report to www.swgemu.com/bugs ! Name: " << performanceName << " and Type: " << dec << instrument->getInstrumentType();

		entertainer->sendSystemMessage(msg.toString());
		return;
	}

	int actionDrain = performance->getActionPointsPerLoop();

	//Adjust cost based upon player's quickness
	actionDrain = entertainer->calculateCostAdjustment(CreatureAttribute::QUICKNESS, actionDrain);

	if (entertainer->getHAM(CreatureAttribute::ACTION) <= actionDrain) {
		if (isDancing()) {
			stopDancing();
			entertainer->sendSystemMessage("@performance:dance_too_tired");
		}

		if (isPlayingMusic()) {
			stopPlayingMusic();
			entertainer->sendSystemMessage("@performance:music_too_tired");
		}
	} else {
		entertainer->inflictDamage(entertainer, CreatureAttribute::ACTION, actionDrain, false, true);
	}
}
void EntertainingSessionImplementation::increaseEntertainerBuff(CreatureObject* patron){
	ManagedReference<CreatureObject*> entertainer = this->entertainer.get();

	PerformanceManager* performanceManager = SkillManager::instance()->getPerformanceManager();
	Performance* performance = NULL;

	ManagedReference<Instrument*> instrument = getInstrument(entertainer);

	if (performanceName == "")
		return;

	if (dancing) {
		performance = performanceManager->getDance(performanceName);
	} else if (playingMusic && instrument != NULL) {
		performance = performanceManager->getSong(performanceName, instrument->getInstrumentType());
	} else {
		cancelSession();
		return;
	}

	if(!canGiveEntertainBuff())
		return;

	if (performance == NULL) { // shouldn't happen
		return;
	}

	ManagedReference<PlayerObject*> entPlayer = entertainer->getPlayerObject();
	//Check if the patron is a valid buff target
	//Whether it be passive(in the same group) or active (/setPerform target)
	if ((!entertainer->isGrouped() || entertainer->getGroupID() != patron->getGroupID())
			&& entPlayer->getPerformanceBuffTarget() != patron->getObjectID()) {
		return;
	}

	if(isInDenyServiceList(patron))
		return;

	float buffAcceleration = 1 + ((float)entertainer->getSkillMod("accelerate_entertainer_buff") / 100.f);

	addEntertainerBuffDuration(patron, performance->getType(), 2.0f * buffAcceleration);
	addEntertainerBuffStrength(patron, performance->getType(), performance->getHealShockWound());

}
Exemplo n.º 3
0
int main(int argc, char *argv[]){

    QApplication application(argc, argv);

    /*
     * XML configuration parser
     */
    ParseNetworkConfigurationXML parser;
    Sink* sink = new Sink();
    vector<Camera*>* cameras = Camera::getCameras();
    vector<Link*> links;
    vector<NetworkItem*> items;

    parser.parse(XML_NETWORK_PATH, items, links, cameras, sink);
    std::cout << "main: XML sink: " << *sink << endl;
    Camera::printCameras();

    /*
     * PKLot configuration parser
     */
    for (uint camIdx = 0;camIdx < cameras->size(); camIdx++){
        Camera* cam = cameras->at(camIdx);
        std::vector<PKLot> pklots;
        cv::Size imgSize(FRAME_W,FRAME_H);
        stringstream ss;
        ss << PKLOT_XML_PATH << cam->getId() << ".xml";
        PKLot::parse(ss.str(),pklots);
        cam->setPKLots(pklots,imgSize);
    }

    /*
     * GUI
     */
    QDesktopWidget desktop;
    QRect mainScreenSize = desktop.availableGeometry(desktop.primaryScreen());

    std::vector<CameraView*> cam_views(cameras->size());



    /* Create the server */
    IoThread* ioThread = IoThread::getInstance(GUI_LISTENING_TCP_PORT);

    //cam_views.reserve(cameras.size());
    for (uint camIdx = 0; camIdx < cameras->size(); camIdx++){

        Camera* curCam = cameras->at(camIdx);
        curCam->setGuiIdx(camIdx);

        std::stringstream ss;
        ss << "Camera " << camIdx+1;
        QString wTitle(ss.str().c_str());

        CameraView* curCamView = new CameraView(curCam, 0, camIdx);

        curCamView->setWindowTitle(wTitle);
        int cwTLx = (10 + curCamView->width())*camIdx;
        int cwTLy = 10;

        curCamView->setGeometry(cwTLx, cwTLy, curCamView->width(), curCamView->height());
        curCamView->show();

        cam_views[camIdx] = curCamView;
    }

    ObjectTracking * task_track = ObjectTracking::getObjectTracking(DB_PATH);

    task_track->setCameras(cameras);
    task_track->setCamViews(cam_views);

    for (vector<Camera*>::iterator camIt = cameras->begin(); camIt != cameras->end(); camIt++){
        task_track->connectTasks(*camIt);
    }

    GuiProcessingSystem* guiProcessingSistem = GuiProcessingSystem::getInstance();

    inverse_BRISK * invBRISK = inverse_BRISK::getinverse_BRISK(guiProcessingSistem->getBriskExtractor(),FRAME_W, FRAME_H);
    invBRISK->build_database(DB_IMAGE_PATH);
    invBRISK->setNCameras(cameras->size());
    invBRISK->setCameras(cameras);

    invBRISK->connectTasks(cameras->size());

    PerformanceManager * perf = PerformanceManager::getPerformanceManager(cameras, 40*1000/1000, 1000,5);

    CameraSettings camSet;

    NetworkTopology net(&camSet, &items, &links, 0);
    camSet.setNetworkTopology(&net);

    int netTLx = 10;
    int netTLy = mainScreenSize.height() - net.geometry().height();

    net.setGeometry(netTLx, netTLy, net.geometry().width(), net.geometry().height());
    /*net.show();*/

    int csTLy = 10;
    int csTLx = mainScreenSize.width() - camSet.geometry().width() - 10;

    camSet.setGeometry(csTLx, csTLy, camSet.geometry().width(), camSet.geometry().height());

    camSet.show();

    std::vector<Plot*> cam_plots(cameras->size());

    for (uint8_t cam = 0; cam < cameras->size(); cam++){

        Plot * p = new Plot(*perf, cam, *(cameras->at(cam)));
        p->setWindowTitle("Camera " + QString::number(cam + 1));
        int plotTLx = mainScreenSize.width() - (10 + p->width())*(cameras->size() - cam);
        int plotTLy = mainScreenSize.height() - p->height();

        p->setGeometry(plotTLx, plotTLy, p->width(), p->height());
        p->show();

        cam_plots.push_back(p);
    }

    MainWindow mainWindow(&camSet, cam_views, &net, cam_plots);

    int wTLx = 20 + net.geometry().width();
    int wTLy = mainScreenSize.height() - net.geometry().height();

    mainWindow.setGeometry(wTLx, wTLy, mainWindow.geometry().width(), mainWindow.geometry().height());
    mainWindow.show();

    // inverse BRISK thread
    QThread* inverseBriskThread = new QThread;
    invBRISK->moveToThread(inverseBriskThread);
    inverseBriskThread->start();

    // object tracking+recognition thread
    QThread* recognitionTrackingThread = new QThread;
    task_track->moveToThread(recognitionTrackingThread);
    recognitionTrackingThread->start();

    perf->connectTasks();

    /* Gentle shutdown */
    signal(SIGINT, GuiNetworkSystem::shutdown);
    signal(SIGQUIT, GuiNetworkSystem::shutdown);

    /* Start the network system */
    ioThread->start();

    return application.exec();
}
void EntertainingSessionImplementation::doFlourish(int flourishNumber) {
	ManagedReference<CreatureObject*> entertainer = this->entertainer.get();

	int fid = flourishNumber;

	if (!dancing && !playingMusic) {
		entertainer->sendSystemMessage("@performance:flourish_not_performing");
		return;
	}

	PerformanceManager* performanceManager = SkillManager::instance()->getPerformanceManager();
	Performance* performance = NULL;
	ManagedReference<Instrument*> instrument = getInstrument(entertainer);

	if (dancing)
		performance = performanceManager->getDance(performanceName);
	else if (playingMusic && instrument)
		performance = performanceManager->getSong(performanceName, instrument->getInstrumentType());
	else {
		cancelSession();
		return;
	}

	if (!performance) { // shouldn't happen
		StringBuffer msg;
		msg << "Performance was null.  Please report to www.swgemu.com/bugs ! Name: " << performanceName << " and Type: " << dec << instrument->getInstrumentType();

		entertainer->sendSystemMessage(msg.toString());
		return;
	}

	float baseActionDrain = performance->getActionPointsPerLoop() - (int)(entertainer->getHAM(CreatureAttribute::QUICKNESS)/35.f);

	//float baseActionDrain = -40 + (getQuickness() / 37.5);
	float flourishActionDrain = baseActionDrain / 2.0;

	int actionDrain = (int)round((flourishActionDrain * 10 + 0.5) / 10.0); // Round to nearest dec for actual int cost

	if (entertainer->getHAM(CreatureAttribute::ACTION) <= actionDrain) {
		entertainer->sendSystemMessage("@performance:flourish_too_tired");
	} else {
		entertainer->inflictDamage(entertainer, CreatureAttribute::ACTION, actionDrain, false, true);

		if (dancing) {
			StringBuffer msg;
			msg << "skill_action_" << fid;
			entertainer->doAnimation(msg.toString());
		} else if (playingMusic) {
			Flourish* flourish = new Flourish(entertainer, fid);
			entertainer->broadcastMessage(flourish, true);
		}

		//check to see how many flourishes have occurred this tick
		if(flourishCount < 5) {
			// Add buff
			addEntertainerFlourishBuff();

			// Grant Experience
			if(flourishCount < 2)
				flourishXp += performance->getBaseXp() + performance->getFlourishXpMod();

			flourishCount++;
		}
		entertainer->notifyObservers(ObserverEventType::FLOURISH, entertainer, fid);

		entertainer->sendSystemMessage("@performance:flourish_perform");
	}
}
void EntertainingSessionImplementation::doEntertainerPatronEffects() {
	ManagedReference<CreatureObject*> creo = entertainer.get();

	if (creo == NULL)
		return;

	if (performanceName == "")
		return;

	Locker locker(creo);

	//**DECLARATIONS**
	VectorMap<ManagedReference<CreatureObject*>, EntertainingData>* patrons = NULL;

	SkillManager* skillManager = creo->getZoneServer()->getSkillManager();

	PerformanceManager* performanceManager = skillManager->getPerformanceManager();
	Performance* performance = NULL;

	ManagedReference<Instrument*> instrument = getInstrument(creo);

	float woundHealingSkill = 0.0f;
	float playerShockHealingSkill = 0.0f;
	float buildingShockHealingSkill = creo->getSkillMod("private_med_battle_fatigue");
	float factionPerkSkill = creo->getSkillMod("private_faction_mind_heal");

	//**LOAD PATRONS, GET THE PERFORMANCE AND ENT'S HEALING SKILL.**
	if (dancing) {
		patrons = &watchers;
		performance = performanceManager->getDance(performanceName);
		woundHealingSkill = (float) creo->getSkillMod("healing_dance_wound");
		playerShockHealingSkill = (float) creo->getSkillMod("healing_dance_shock");
	} else if (playingMusic && instrument != NULL) {
		patrons = &listeners;
		performance = performanceManager->getSong(performanceName, instrument->getInstrumentType());
		woundHealingSkill = (float) creo->getSkillMod("healing_music_wound");
		playerShockHealingSkill = (float) creo->getSkillMod("healing_music_shock");

	} else {
		cancelSession();
		return;
	}

	if (performance == NULL) {
		return;
	}

	ManagedReference<BuildingObject*> building = creo->getRootParent().get().castTo<BuildingObject*>();

	if (building != NULL && factionPerkSkill > 0 && building->isPlayerRegisteredWithin(creo->getObjectID())) {
		unsigned int buildingFaction = building->getFaction();
		unsigned int healerFaction = creo->getFaction();
		PlayerObject* ghost = creo->getPlayerObject();

		if (ghost != NULL && healerFaction != 0 && healerFaction == buildingFaction && ghost->getFactionStatus() == FactionStatus::OVERT) {
			woundHealingSkill += factionPerkSkill;
			playerShockHealingSkill += factionPerkSkill;
		}
	}

	//**DETERMINE WOUND HEAL AMOUNTS.**
	int woundHeal = ceil(performance->getHealMindWound() * (woundHealingSkill / 100.0f));
	int shockHeal = ceil(performance->getHealShockWound() * ((playerShockHealingSkill + buildingShockHealingSkill) / 100.0f));

	//**ENTERTAINER HEALS THEIR OWN MIND.**
	healWounds(creo, woundHeal*(flourishCount+1), shockHeal*(flourishCount+1));

	//**APPLY EFFECTS TO PATRONS.**
	if (patrons != NULL && patrons->size() > 0) {

		for (int i = 0; i < patrons->size(); ++i) {
			ManagedReference<CreatureObject*> patron = patrons->elementAt(i).getKey();

			try {
				//**VERIFY THE PATRON IS NOT ON THE DENY SERVICE LIST

				if (creo->isInRange(patron, 10.0f)) {
					healWounds(patron, woundHeal*(flourishCount+1), shockHeal*(flourishCount+1));
					increaseEntertainerBuff(patron);

				} else { //patron is not in range, force to stop listening
					ManagedReference<PlayerManager*> playerManager = patron->getZoneServer()->getPlayerManager();

					Locker locker(patron, entertainer.get());

					if (dancing) {
						if (playerManager != NULL)
							playerManager->stopWatch(patron, creo->getObjectID(), true, false, false, true);

						if (!patron->isListening())
							sendEntertainmentUpdate(patron, 0, "", true);

					} else if (playingMusic) {
						if (playerManager != NULL)
							playerManager->stopListen(patron, creo->getObjectID(), true, false, false, true);

						if (!patron->isWatching())
							sendEntertainmentUpdate(patron, 0, "", true);
					}
				}

			} catch (Exception& e) {
				error("Unreported exception caught in EntertainingSessionImplementation::doEntertainerPatronEffects()");
			}
		}
	} //else
	//System::out << "There are no patrons.\n";


	info("EntertainingSessionImplementation::doEntertainerPatronEffects() end");
}