Ejemplo n.º 1
0
/*virtual*/ void Bullet::HandleCollision(const IEntity* other) /*override*/
{
	const Character* temp = reinterpret_cast<const Character*>(other);

	if (temp && owner && owner->GetOwner() && (temp->GetIsEnemy() != owner->GetOwner()->GetIsEnemy()))
	{
		// create a hit marker to indicate damage
		SGD::Color enemyColor;
		if (temp->GetIsEnemy())
			enemyColor = SGD::Color::Yellow;
		else
			enemyColor = SGD::Color::Blue;

		// dispatch a hit marker message only if the other object actually has health
		if (temp->GetCurrHealth() > 0.f)
		{
			CreateHitMarkerMsg* msg = new CreateHitMarkerMsg((int)(GetDamage()), m_ptPosition, m_fRotation - Math::to_radians(180.f), enemyColor);
			SGD::MessageManager::GetInstance()->QueueMessage(msg);
		}
	}

	// avoid shooting yourself unless its a deflected bullet
	if ((owner->GetOwner() != temp && !deflectBullet) || (owner->GetOwner() == temp && deflectBullet))
	{

#pragma region Brawler
		const Character* testCharacter = reinterpret_cast<const Character*>(other);
		Character* testNonConstCharacter = const_cast<Character*>(testCharacter);

		// player hit by bullet 
		if (GameplayState::GetInstance()->player && testCharacter->GetLevel() >= 1)
		{
			if (testCharacter && testCharacter->GetClass() == ClassType::Brawler && testCharacter == GameplayState::GetInstance()->player->GetCharacter())
			{
				// damage player Takes
				GameplayState::GetInstance()->fBaseDamageTaken = GetDamage();
				GameplayState::GetInstance()->fPassiveDamageTaken = testNonConstCharacter->GetWeapon()->GetDamage();
			}
		}

		if (owner->GetGunType() == Weapon::GunType::chainsawLauncher && owner->GetOwner()->GetClass() == ClassType::Brawler)
		{
			if (reinterpret_cast<BuzzsawLauncher*>(owner)->GetisBrawlActive())
			{
				if (owner->GetOwner()->GetLevel() >= 21)
					owner->GetOwner()->SetCurrCooldown(owner->GetOwner()->GetCurrCoolDown() - 0.5f);
				
				if (owner->GetOwner()->GetLevel() >= 11)
					owner->GetOwner()->ModifyHealth(owner->GetOwner()->GetStat(StatType::strength)*0.35f);
			}
		}
#pragma endregion

		if (temp && owner && owner->GetOwner() && owner->GetOwner()->GetClass() == ClassType::Cyborg && owner->GetOwner()->GetLevel() >= 18 && damage >= temp->GetCurrHealth())
		{
			vector<NPC*> hits = GameplayState::GetInstance()->npcs;
			int lightning = 0;
			for (unsigned int x = 0; x < hits.size() && lightning <= 2; x++)
			{
				float length = (hits[x]->getCharacter()->GetPosition() - temp->GetPosition()).ComputeLength();
				if (length < 300.0f && hits[x]->getCharacter()->GetIsEnemy() != owner->GetOwner()->GetIsEnemy() && hits[x]->getCharacter() != temp)
				{
					hits[x]->getCharacter()->ModifyHealth(-owner->GetOwner()->GetStat(StatType::accuracy)*0.5f);
					lightning++;

					if (owner->GetOwner()->GetLevel() >= 24)
					{
						Stun* stun = new Stun(hits[x]->getCharacter());
						stun->SetDuration(1.0f);
						Radiation* rad = new Radiation(hits[x]->getCharacter());
						rad->SetStacks(5);
						hits[x]->getCharacter()->AddStatusAilment(stun);
						hits[x]->getCharacter()->AddStatusAilment(rad);
					}
				}
			}

			if (lightning > 0)
				SGD::AudioManager::GetInstance()->PlayAudio(GameplayState::GetInstance()->chain_lightnin);
		}

		const Character* tempEnemy = dynamic_cast<const Character*>(other);
		Character* newEnemy = const_cast<Character*>(tempEnemy);

		if (tempEnemy && owner && owner->GetOwner() && owner->GetOwner()->GetClass() == ClassType::Gunslinger && owner->GetOwner()->GetLevel() >= 24)
		{
			int theOdds = rand() % 100 + 1;
			// gunslinger passive debug code
			GameplayState::GetInstance()->nRiccochetOdds = theOdds;

			if (theOdds < 45 && tempEnemy->GetIsEnemy() != owner->GetOwner()->GetIsEnemy())
			{
				// adjust angle to aim at another enemy (see chain lightning: cyborg lv 18 - line 120)
				// instead of destroying, redirect to another (and don't destroy)
				// if no other near, destroy this
				Weapon* tempWeapon = newEnemy->GetWeapon();

				// gunslinger debug code
				for (unsigned i = 0; i < GameplayState::GetInstance()->npcs.size(); i++)
				{
					if (GameplayState::GetInstance()->npcs[i]->getCharacter() != tempEnemy)
					{
						SGD::Vector tempDiff = GameplayState::GetInstance()->npcs[i]->getCharacter()->GetPosition() - GetPosition();
						//tempDiff.Normalize();

						float tempDist = tempDiff.ComputeLength();

						if (tempDist < 300)
						{
							// calculate angle to new target
							float toTarget = atan2(tempDiff.y, tempDiff.x);

							SGD::Vector newVelocity = GetVelocity();

							// set the velocity to the newly rotated velocity
							SetVelocity(newVelocity.ComputeRotated(toTarget));
							SetRotation(toTarget);
							SGD::AudioManager::GetInstance()->PlayAudio(GameplayState::GetInstance()->trickShot);
							break;
						}
					}
				}
			}
		}
		if (owner && owner->GetOwner() && owner->GetOwner()->GetClass() == ClassType::Medic && owner->GetOwner()->GetLevel() >= 24 && temp && damage >= temp->GetCurrHealth()*1.2f)
		{
			vector<NPC*> hits = GameplayState::GetInstance()->npcs;
			if ((GameplayState::GetInstance()->player->GetCharacter()->GetPosition() - temp->GetPosition()).ComputeLength() < 300.0f)
			{
				GameplayState::GetInstance()->player->GetCharacter()->ModifyHealth((temp->GetHealth())*0.1f);
				Emitter* heals = GameplayState::GetInstance()->CreateEmitter("heals", (temp != nullptr));
				heals->lifeTime = 0.25f;
			}

			for (unsigned int x = 0; x < hits.size(); x++)
			{
				float length = (hits[x]->getCharacter()->GetPosition() - temp->GetPosition()).ComputeLength();
				if (length < 300.0f && !hits[x]->getCharacter()->GetIsEnemy())
				{
					hits[x]->getCharacter()->ModifyHealth((temp->GetHealth())*0.05f);
					Emitter* heals = GameplayState::GetInstance()->CreateEmitter("heals", (temp != nullptr));
					heals->lifeTime = 0.25f;
					//visual effect
				}
			}
			SGD::AudioManager::GetInstance()->PlayAudio(GameplayState::GetInstance()->tranfusion);
		}
		if (GetOwner()->bulType.size() == 0)
		{
			if (tempEnemy && owner && owner->GetOwner() && (tempEnemy->GetIsEnemy() != owner->GetOwner()->GetIsEnemy()))
			{
				if (critPassive)
					SGD::AudioManager::GetInstance()->PlayAudio(GameplayState::GetInstance()->crit_shot);

				// allocate a message to destroy this instance
				DestroyEntityMsg* msg = new DestroyEntityMsg(this);

				// dispatch destroy message
				SGD::MessageManager::GetInstance()->QueueMessage(msg);
			}
		}
		// allocate a message to destroy this instance if the bullet is not peircing
		for (unsigned int i = 0; i < GetOwner()->bulType.size(); i++)
		{
			//if its a peircing bullet, don't continue to where you delete the bullet
			if (GetOwner()->bulType[i] == BulletType::fmj || GetOwner()->bulType[i] == BulletType::FMJFTW)
			{
				break;
			}

			if (owner && owner->GetOwner() && owner->GetOwner()->GetClass() == ClassType::Gunslinger && owner->GetOwner()->GetLevel() >= 24 && GameplayState::GetInstance()->nTheOdds < 45); // do nothing
			else if (!deflectBullet && i == GetOwner()->bulType.size() - 1)
			{
				// allocate a message to destroy this instance if you make it through the entire vector of bullet types and don't find fmj or fmjftw
				DestroyEntityMsg* msg = new DestroyEntityMsg(this);

				// dispatch destroy message
				SGD::MessageManager::GetInstance()->QueueMessage(msg);
			}
		}
		deflectBullet = false;
	}

}