void AShooterWeapon_Instant::ProcessInstantHit_Confirmed(const FHitResult& Impact, const FVector& Origin, const FVector& ShootDir, int32 RandomSeed, float ReticleSpread) { // handle damage if (ShouldDealDamage(Impact.GetActor())) { DealDamage(Impact, ShootDir); } // play FX on remote clients if (Role == ROLE_Authority) { HitNotify.Origin = Origin; HitNotify.RandomSeed = RandomSeed; HitNotify.ReticleSpread = ReticleSpread; } // play FX locally if (GetNetMode() != NM_DedicatedServer) { const FVector EndTrace = Origin + ShootDir * InstantConfig.WeaponRange; const FVector EndPoint = Impact.GetActor() ? Impact.ImpactPoint : EndTrace; SpawnTrailEffect(EndPoint); SpawnImpactEffects(Impact); } }
//¸ó½ºÅ͸¦ ¶§¸®´Â ÇÔ¼ö. °ø°ÝÆÇÁ¤À» Àû¿ëÇÑ´Ù. bool Player::HitMonsters(BoundingSphere& attacksphere,int damage) { bool collision = false; if (!monsters.empty()) { for (auto iter = monsters.begin(); iter != monsters.end(); ++iter) { collision = Collision::IsSphereToSphere(attacksphere, (*iter)->GetBoundingSphereValue()); if (collision) { //ÀÌ¹Ì ÇÇ°ÝÁßÀÏ ¶§´Â ¸ÂÁö ¾Ê°í, ÇÇ°ÝÁßÀÌ ¾Æ´Ï¶ó¸é ¸Â´Â´Ù. bool monsterHit = (*iter)->GetIsHit(); if (monsterHit) { } else { //¸ó½ºÅÍÀÇ ÇÇ°ÝÇÔ¼ö¸¦ È£Ãâ. ÀÌ ÇÔ¼ö´Â ij¸¯ÅÍ Å¬·¡½º¿¡ ÀÖ´Ù. DealDamage(*iter, damage); } } } } return collision; }
void Unit::DealMeleeDamage(CalcDamageInfo* damageInfo) { Unit* victim = damageInfo->target; if (!victim->IsAlive()) return; DealDamage(victim, damageInfo->damage); }
void Unit::DealSpellDamage(SpellNonMeleeDamage* damageInfo) { if (damageInfo == 0) return; Unit* victim = damageInfo->target; if (!victim || !victim->IsAlive()) return; DealDamage(victim, damageInfo->damage); }
void DamageHandler(Unit *U, Tower *T, UnitList *PDUL) { if (TowerEffect(T) == EFFECT_DOT) { // Puts a DoT on the unit UnitAddDoT(U, TowerDamage(T)); } else { // Deal the damage DealDamage(U, TowerDamage(T), PDUL); } }
void AWeaponBase::DoFire(){ FHitResult Hit(ForceInit); FVector Start = WeaponMesh->GetSocketLocation(MuzzleSocketName); FVector End = Start + CalcSpread() * MaxRange; GetWorld()->LineTraceSingleByChannel(Hit, Start, End, ECC_Weapon, TraceParams); UE_LOG(LogTemp, Warning, TEXT("Fire!")); CurrentAmmo--; SpawnFireEffect(); if(Hit.GetActor()){ UE_LOG(LogTemp, Warning, TEXT("Hit! %s"), *Hit.GetActor()->GetName()); DealDamage(Hit); SpawnImpactEffect(Hit); } }
void ASWeaponInstant::ProcessInstantHitConfirmed(const FHitResult& Impact, const FVector& Origin, const FVector& ShootDir) { // Handle damage if (ShouldDealDamage(Impact.GetActor())) { DealDamage(Impact, ShootDir); } // Play FX on remote clients if (Role == ROLE_Authority) { HitImpactNotify = Impact.ImpactPoint; } // Play FX locally if (GetNetMode() != NM_DedicatedServer) { SimulateInstantHit(Impact.ImpactPoint); } }
void Drone::OnCollision(const GameObjectList& objects) { SmartPtr<GameObject> object; GameObjectType const* type = NULL; GameObjectList::const_iterator it = objects.begin(); GameObjectList::const_iterator end = objects.end(); for (; it != end; ++it) { // const GameObjectType * type = &((*it)->GetType() ); object = *it; type = &(object->GetType()); // const char * type_name = object->GetType().GetTypeName(); // cout << type_name << ";" << endl; // Compare Object type if((*type) == GameObjectType("Bullet")) { // TODO add damage related stuff to GameObject which should allow you to bypass this whole awkward pointer stuff here... Bullet* b = (Bullet*) object.GetPtr(); // cout << "colision with bullet" << endl; // Bullet* b = dynamic_cast<Bullet*>(object.GetPtr()); int damage = b->GetDamage(); int health = mHealth; int newHealth = mHealth - damage; DealDamage(b->GetDamage()); //cout << "HEALTH " << mHealth << endl; // Check if alive if(mHealth <= 0) mWorld->RemoveObject(this); } } }
void CSpammerEnemy::Attack(float fDamage) { AudioSystemWwise::Get()->PostEvent(AK::EVENTS::PLAY_3D_HUNTER_ATTACK, this); DealDamage(fDamage); }
void Minion::ProcessState() { D3DXVECTOR3 pos = position; D3DXVECTOR3 direction; D3DXVECTOR3 right; D3DXVECTOR3 up = D3DXVECTOR3(0, 1, 0); float toPlayerRotationAngle; D3DXMatrixRotationY(&rotation, rotationAngle); D3DXVECTOR3 forward = D3DXVECTOR3(rotation._31, rotation._32, rotation._33); if (target) { direction = *target - position; D3DXVec3Normalize(&direction, &direction); D3DXVec3Cross(&right, &up, &direction); toPlayerRotationAngle = atan2f(direction.x,direction.z); } else direction = forward; switch (currentState) { case CharacterState::CHARACTER_IDLE: { float tick = GameManager::GetTick(); idleTime += tick; if (hm->GetHeight(pos.y, pos.x, pos.z) != false) { } SelectPatrolPosition(); if (!player->GetIsDead()) { ChangeCharacterState(CharacterState::CHARACTER_PATROL); } else { if (idleTime < (float)rand() / RAND_MAX * 2) { ChangeCharacterState(CharacterState::CHARACTER_PATROL); } } }break; case CharacterState::CHARACTER_PATROL: { if (hm->GetHeight(pos.y, pos.x, pos.z) != false) { if (player) { if (Collision::IsSphereToSphere(sight_wide, player->GetBoundingSphereValue())) { D3DXVECTOR3 toPlayer = player->GetPosition() - position; D3DXVec3Normalize(&toPlayer, &toPlayer); //cos60°ú ºñ±³¸¦ Çؼ ³»Àû°ªÀÌ ¾È¿¡ ÀÖÀ¸¸é ¦i¾Æ°¨ //Áß°£¿¡ ¾î´ÀÂÊÀ¸·Î µ¹¾Æ¾ß ÇÒÁö ¿ø·¡ ȸÀü°¢¿¡ 90À» ´õÇؼ ºÎÈ£°¡ ¹Ù²î´ÂÁö ÆÇÁ¤ÇÑ´Ù. DX±âº» ȸÀüÀº CWÀÌ´Ù. if (D3DXVec3Dot(&forward, &toPlayer) > cosf(D3DX_PI*0.33f)) { if (D3DXVec3Dot(&toPlayer, &D3DXVECTOR3(cosf(rotationAngle + D3DX_PI*0.5f), 0, sinf(rotationAngle + D3DX_PI*0.5f))) > 0) { rotateCW = true; } else rotateCW = false; target = player->GetPositionAddress(); ChangeCharacterState(CharacterState::CHARACTER_TRACE); } else { //½Ã¾ß°¢ ¹Û¿¡ ÀÖ´Ù. //Á¼Àº ¿ø ¾È¿¡ µé¾î¿À¸é ÆÇÁ¤À» ÇÔ. µÑ´Ù ¾Æ´Ï¸é °¡´ø ±æÀ» °£´Ù. if (Collision::IsSphereToSphere(sight_narrow, player->GetBoundingSphereValue())) { if (D3DXVec3Dot(&toPlayer, &D3DXVECTOR3(cosf(rotationAngle + D3DX_PI*0.5f), 0, sinf(rotationAngle + D3DX_PI*0.5f))) > 0) { rotateCW = true; } else rotateCW = false; target = player->GetPositionAddress(); if (player->GetIsDead()) { } else { ChangeCharacterState(CharacterState::CHARACTER_TRACE); } } } } } if (isHit) { hp -= inDamage; if (hp > 0) { ChangeCharacterState(CharacterState::CHARACTER_HIT); } else ChangeCharacterState(CharacterState::CHARACTER_DEAD); } } }break; case CharacterState::CHARACTER_ATTACK: { float tick = (float)GameManager::GetTick(); currentAnimationTime += tick; attackSphere.center = meshCenter+position + direction*0.5f; if (currentAnimationTime >= selectedAnimationLength) { ChangeCharacterState(CharacterState::CHARACTER_TRACE); } else { bool playerInivisible = player->GetInvisible(); bool playerHit = player->GetIsHit(); bool playerDead = player->GetIsDead(); if (!playerInivisible && !playerHit&&!playerDead&&!attackHit) { if(Collision::IsSphereToSphere(attackSphere, player->GetBoundingSphereValue())) { if (Collision::IsBoxToSphere(player->GetBoundingBoxValue(), attackSphere)) { DealDamage(player, ATTACK_DAMAGE); attackHit = true; } } } if (isHit) { hp -= inDamage; if (hp > 0) { ChangeCharacterState(CharacterState::CHARACTER_HIT); } else ChangeCharacterState(CharacterState::CHARACTER_DEAD); } } } break; case CharacterState::CHARACTER_DODGE: { } break; case CharacterState::CHARACTER_HIT: { float tick = (float)GameManager::GetTick(); currentAnimationTime += tick; animController->SetTrackSpeed(0, 0.2f); if (currentAnimationTime >= selectedAnimationLength*5.0f) { isHit = false; ChangeCharacterState(CharacterState::CHARACTER_TRACE); } } break; case CharacterState::CHARACTER_TRACE: { if (hm->GetHeight(pos, pos.x, pos.z) != false) { float tick = (float)GameManager::GetTick(); bool move = false; D3DXVECTOR3 collisionDirection; if (CollisionMonsters(&collisionDirection)) { direction += collisionDirection; D3DXVec3Normalize(&direction, &direction); } if (Collision::IsSphereToSphere(player->GetBoundingSphereValue(), boundingSphere)) { attackHit = false; ChangeCharacterState(CharacterState::CHARACTER_ATTACK); } else { pos -= (-direction * moveSpeed * tick); forwardBoundingSphere.center = pos; } rotationAngle = toPlayerRotationAngle; } if (isHit) { hp -= inDamage; if (hp > 0) { ChangeCharacterState(CharacterState::CHARACTER_HIT); } else ChangeCharacterState(CharacterState::CHARACTER_DEAD); } if (player->GetIsDead()) { ChangeCharacterState(CharacterState::CHARACTER_PATROL); } } break; case CharacterState::CHARACTER_RETURN: { } break; case CharacterState::CHARACTER_DEAD: { float tick = (float)GameManager::GetTick(); currentAnimationTime += tick; if (currentAnimationTime >= selectedAnimationLength) { ChangeCharacterState(CharacterState::CHARACTER_DIED); } } break; case CharacterState::CHARACTER_DIED: { float tick=GameManager::GetTick(); animController->SetTrackSpeed(0, 0.0f); currentAnimationTime += tick; if (pos.y > -10.0) { pos.y -= tick; } else { isDead = true; } } break; } position = pos; }
void SSProjectiles::UpdateSimLayer( const float timestep ) { for ( auto& it : m_Projectiles ) { it.TimeLeft -= timestep; if ( it.Active && it.TimeLeft < 0.0f ) { it.Active = false; if ( it.Effect ) { it.Effect->TimeToLive = it.Effect->ParticlesTimeToLive; it.Effect->EmitterPosition = glm::vec3( FLT_MIN ); it.Effect = nullptr; } if ( it.Type == PROJECTILE_TYPE_GRENADE ) { unsigned int entityID = 0; EntityMask agentFlag = GetDenseComponentFlag<AgentComponent>( ); for ( auto& mask : g_EntityManager.GetEntityMasks( ) ) { if ( mask & agentFlag ) { PlacementComponent* pos = GetDenseComponent<PlacementComponent>( entityID ); float lngth = glm::distance(pos->Position,it.Destination); if (lngth < it.AoE && !g_Alliances.IsAllied(GetDenseComponent<OwnerComponent>(entityID)->OwnerID, it.OwnerID)) { it.Target = entityID; float damageSaved = it.Damage; it.Damage = it.Damage - lngth; if (it.Damage < 1) it.Damage = 1; DealDamage( it ); it.Damage = damageSaved; } } ++entityID; } gfx::ParticleSystem effect = g_SSParticle.GetDefaultParticleSystem( PARTICLE_TYPE_FIRE_BALL ); effect.EmitterPosition = it.Destination + glm::vec3( 0, 1, 0 ); effect.ParticlesSpeed = ( it.AoE - effect.Size.x ) / effect.ParticlesTimeToLive; g_SSParticle.SpawnParticleSystem( PARTICLE_TYPE_FIRE_BALL, effect ); ///Play boomboom sound when hitting ground ///TODO: Place this here? SFXEvent event; event.AtBeat = BeatType::NONE; event.Name = "../../../asset/audio/collection/misc/explosion.sfxc"; event.Info3D.DistMin = 100.0f; event.Info3D.DistMax = 1000.0f; event.Info3D.Is3D = true; event.Info3D.Position = it.Destination; g_SSAudio.PostEventSFX(event); g_SSDecaling.AddTimedDecal( it.Position, m_DecalTextureNameExplosion.c_str( ), 15.0f, glm::vec4( 1.0f ), 3.0f, 2.0f ); } else if ( it.Type == PROJECTILE_TYPE_CONE || it.Weapon == WEAPON_PIERCING_LASER ) { unsigned int entityID = 0; EntityMask agentFlag = GetDenseComponentFlag<AgentComponent>( ); for ( auto& mask : g_EntityManager.GetEntityMasks( ) ) { if ( mask & agentFlag ) { PlacementComponent* pos = GetDenseComponent<PlacementComponent>( entityID ); float distanceSquared; bool inRange = false; // Calculate minimum distance from line segment { float lineLength = it.Scale.z; glm::vec3 lineStart = it.Origin; glm::vec3 lineEnd = lineLength * glm::normalize( it.Destination - it.Origin ) + it.Origin; glm::vec3 point = pos->Position; float dist2 = glm::length2( lineEnd - lineStart ); float t = glm::dot( point - lineStart, lineEnd - lineStart ) / dist2; if ( t < 0.0f ) distanceSquared = glm::length2( point - lineStart ); else if ( t > 1.0f ) distanceSquared = glm::length2( point - lineEnd ); glm::vec3 projection = lineStart + t * (lineEnd - lineStart); distanceSquared = glm::length2( point - projection ); if ( it.Type == PROJECTILE_TYPE_CONE && 0.0f <= t && t <= 1.0f ) inRange = distanceSquared <= (it.AoE * t) * (it.AoE * t); else if ( it.Weapon == WEAPON_PIERCING_LASER ) inRange = distanceSquared <= it.AoE * it.AoE; } if ( inRange && !g_Alliances.IsAllied( GetDenseComponent<OwnerComponent>( entityID )->OwnerID, it.OwnerID ) ) // TODODP: Move owner check one step out ? { it.Target = entityID; DealDamage( it ); } } ++entityID; } } else { DealDamage( it ); } } else { UpdateProjectileMovement( it, timestep ); } } }