void RPG_Pickup::CheckCharacterContact() { VArray<RPG_Character*> const& characters = RPG_GameManager::s_instance.GetCharacters(); hkvVec3 const& currentPosition = GetPosition(); for(int index = 0; index < characters.GetSize(); ++index) { RPG_Character* character = characters.GetAt(index); // only target players if(!character->IsOfType(V_RUNTIME_CLASS(RPG_PlayerCharacter))) { continue; } hkvVec3 const& targetPosition = character->GetPosition(); float currentRangeSquared = (currentPosition - targetPosition).getLengthSquared(); if(currentRangeSquared <= m_pickupRadius * m_pickupRadius) { // call OnPickup for subclasses OnPickup(character); // play the pickup effect CreateEffect(PKFX_Pickup, GetPosition(), GetOrientation()); // setup this object for deletion DisposeObject(); } } }
void PlayerUIDialog::PlayTestEffect() { RPG_Character *characterEntity = static_cast<RPG_Character *>(m_playerController->GetOwner()); VASSERT(characterEntity); const hkvVec3 position = characterEntity->GetPosition(); RPG_VisionEffectHelper::PlayFmodSoundEvent("Characters/Barbarian", "Melee_Basic_Swing", position); // first argument refers to event group names in the FMOD project specified by GameManager::FMOD_EVENT_PROJECT }
/// Finds and sets a target within range to interact with (usually to attack). /// @TODO: Implement teams and team relationships, as target must currently be a player. bool RPG_AiControllerComponent::AcquireTarget() { VArray<RPG_Character*> const& characters = RPG_GameManager::s_instance.GetCharacters(); hkvVec3 const& currentPosition = m_characterOwner->GetPosition(); bool returnVal = false; for(int index = 0; index < characters.GetSize(); ++index) { RPG_Character* character = characters.GetAt(index); // can't target yourself if(character == m_characterOwner) { continue; } // only target apparently alive players if(!character->IsOfType(V_RUNTIME_CLASS(RPG_PlayerCharacter)) || character->IsDead() || character->IsFeigningDeath()) { continue; } float const aggroRadius = m_characterOwner->GetAggroRadius(); hkvVec3 const& targetPosition = character->GetPosition(); float const currentRangeSquared = (currentPosition - targetPosition).getLengthSquared(); // check if they are within range if(currentRangeSquared <= aggroRadius * aggroRadius) { m_target = character; returnVal = true; } } return returnVal; }
bool RPG_AiControllerComponent::HasValidTarget() const { if (m_target) { VArray<RPG_DamageableEntity*> const& attackableEntities = RPG_GameManager::s_instance.GetAttackableEntities(); if(attackableEntities.Find(GetTarget()) < 0) { return false; } if(m_target->IsFrom(RPG_Character)) { float const aggroRadius = GetCharacter()->GetAggroRadius(); hkvVec3 const& currentPosition = GetCharacter()->GetPosition(); RPG_Character* targetCharacter = static_cast<RPG_Character*>(GetTarget()); hkvVec3 const& targetPosition = targetCharacter->GetPosition(); float const currentRangeSquared = (currentPosition - targetPosition).getLengthSquared(); // check if target is still within range if(currentRangeSquared > aggroRadius * aggroRadius) { return false; } else { return !targetCharacter->IsDead() && !targetCharacter->IsFeigningDeath(); } } else { return true; } } return false; }
void PlayerUIDialog::OnTick(float deltaTime) { VDialog::OnTick(deltaTime); #if defined (SUPPORTS_MULTITOUCH) && (HAVOK_VISION_RESTRUCTURING) && !defined(_VISION_ANDROID) if (m_touchInput != NULL) { int count = m_touchInput->GetNumberOfTouchPoints(); if (count > 1) return; } #endif RPG_Character *characterEntity = static_cast<RPG_Character *>(m_playerController->GetOwner()); if (!characterEntity) { // @todo: handle player death properly hkvLog::Warning("Player character has probably died, which isn't yet handled. Set the character's Unlimited Health entity property to true to prevent this."); return; } RPG_PlayerControllerInput input; { if(m_inputMap->GetTrigger(PI_PrimaryAction) > 0.0f) { if(m_inputMap->GetTrigger(PI_ShiftModifier) > 0.0f) { input.m_buttons |= RPG_PlayerControllerInput::B_RANGED; } else if(m_inputMap->GetTrigger(PI_SecondaryShiftModifier) > 0.0f) { input.m_buttons |= RPG_PlayerControllerInput::B_POWER; } else { input.m_buttons |= RPG_PlayerControllerInput::B_PRIMARY; } } if(m_inputMap->GetTrigger(PI_SecondaryAction) > 0.0f) { input.m_buttons |= RPG_PlayerControllerInput::B_POWER; } if(m_inputMap->GetTrigger(PI_SpecialAction01) > 0.0f) { input.m_buttons |= RPG_PlayerControllerInput::B_AOE; } GetFirstAttackableEntityUnderCursor(input.m_targetEntity, input.m_targetPoint, characterEntity); if(!input.m_targetEntity) { hkVector4 hitPoint, characterPos; RPG_VisionHavokConversion::VisionToHavokPoint(characterEntity->GetPosition(), characterPos); if(GetClosestPointOnNavMeshUnderCursor(hitPoint, characterPos)) { RPG_VisionHavokConversion::HavokToVisionPoint(hitPoint, input.m_targetPoint); } } m_playerController->SetInput(input); } RPG_GuiManager::GetInstance()->OnTick(deltaTime); }