void HacksComponent::handleHackActivatedEvent(Event_HackActivated* e)
{
	bool existed = false;

	for(unsigned int i = 0; i < activeHacks_[e->hackType].size(); i++)
	{
		if(e->player == activeHacks_[e->hackType][i]->second)
		{
			if(activeHacks_[e->hackType][i]->first->getTimeLeft() < e->time)
			{
				activeHacks_[e->hackType][i]->first->setStartTime(e->time);
				activeHacks_[e->hackType][i]->first->resetTimer();

				DEBUGPRINT("Existing hack " << Converter::IntToStr(e->hackType) << " #" << Converter::IntToStr(i) << " was reset with value " << Converter::FloatToStr(e->time));
			}
			existed = true;

			break;
		}
	}

	if(!existed)
	{
		Timer* timer = new Timer(e->time);
		activeHacks_[e->hackType].push_back(new std::pair<Timer*, AttributePtr<Attribute_Player>>(timer, e->player));
		setPlayerAttributeHackFlags(e->player, timer, e->hackType, true);

		DEBUGPRINT("Player picked up hack " << Converter::IntToStr(e->hackType) << " with value " << Converter::FloatToStr(e->time));
	}
}
void HacksComponent::onUpdate(float delta)
{
	Timer* timer;

	for(unsigned int i = 0; i < XKILL_Enums::NROFHACKTYPES; i++)
	{
		for(unsigned int j = 0; j < activeHacks_[i].size(); j++)
		{
			timer = activeHacks_[i][j]->first;

			if(shouldUpdateTimer(activeHacks_[i][j]->second, static_cast<XKILL_Enums::HackType>(i)))
			{
				timer->update(delta);
			}

			if(timer->hasTimerExpired())
			{
				setPlayerAttributeHackFlags(activeHacks_[i][j]->second, nullptr, static_cast<XKILL_Enums::HackType>(i), false);
				SEND_EVENT(&Event_StopSound(XKILL_Enums::Sound::SOUND_JETPACK, itrPlayer.ownerIdAt(activeHacks_[i][j]->second.index())));
				removeIndexFromVector(activeHacks_[i], j);

				DEBUGPRINT("Hack " << Converter::IntToStr(i) << " expired.");
			}
			else
			{
				updateHack(activeHacks_[i][j]->second, static_cast<XKILL_Enums::HackType>(i));
			}
		}
	}
}
Example #3
0
void HacksComponent::removeAllPlayerHacks(AttributePtr<Attribute_Player> playerAttribute)
{
	for(unsigned int i = 0; i < XKILL_Enums::HackType::NROFHACKTYPES; i++)
	{
		for(unsigned int j = 0; j < activeHacks_[i].size(); j++)
		{
			if(playerAttribute == activeHacks_[i][j]->second)
			{
				setPlayerAttributeHackFlags(activeHacks_[i][j]->second, activeHacks_[i][j]->first, static_cast<XKILL_Enums::HackType>(i), false);
				removeIndexFromVector(activeHacks_[i], j);
			}
		}
	}
}