예제 #1
0
void RPG_Action_RangedAttack::UpdateInteraction(RPG_BaseEntity* const interactionEntity, hkvVec3 const& interactionPosition)
{
  m_updatedInteractionEntity = interactionEntity;
  m_updatedInteractionPosition = interactionPosition;
  if(!m_interactionEntity && m_updatedInteractionEntity &&
    m_updatedInteractionEntity->GetPosition().getDistanceToSquared(m_interactionPosition) < s_retargetingRadius * s_retargetingRadius)
  {
    m_interactionEntity = m_updatedInteractionEntity;
    ValidateInteractionEntity();
  }
  m_updatedInteraction = true;
}
예제 #2
0
void RPG_Action_RangedAttack::Tick(float const deltaTime)
{
  RPG_Action_AttackBase::Tick(deltaTime);

  if(m_attacking)
  {
    // RangedAttacking was set to true when the action was initiated. Is reset to false by Behavior when the attack anim finishes.
    vHavokBehaviorComponent *const behaviorComponent = m_characterOwner->GetBehaviorComponent();
    VVERIFY_OR_RET(behaviorComponent);

    VASSERT(!m_behaviorTriggerVarName.IsEmpty());
    if (!RPG_VisionHavokBehaviorHelper::BehaviorGetVarNamed<bool>(*behaviorComponent, m_behaviorTriggerVarName.AsChar()))
    {
      if (m_flags == 1)
      {
        if(m_updatedInteraction)
        {
          m_updatedInteraction = false;
          if(!m_updatedInteractionEntity && m_interactionEntity)
          {
            // Do not lose the player's intended target
            ValidateInteractionEntity();
            if(!m_interactionEntity->Components().GetComponentOfType(V_RUNTIME_CLASS(RPG_AttackableComponent)))
            {
              m_interactionEntity = NULL;
            }
            else
            {
              if(m_interactionEntity->GetPosition().getDistanceToSquared(m_updatedInteractionPosition) > s_retargetingRadius * s_retargetingRadius)
              {
                m_interactionEntity = NULL;
              }
            }
          }
          else
          {
            m_interactionEntity = m_updatedInteractionEntity;
            ValidateInteractionEntity();
          }
          m_interactionPosition = m_updatedInteractionPosition;
        }
        m_startTime = Vision::GetTimer()->GetTime();
        StartAttack();
      }
      else
      {
        // if we've gotten to the end and haven't fired the projectile, fire it now
        if (!m_hasFired)
        {
          VString msg;
          msg.Format("RPG_Action_RangedAttack never received expected %s event from Behavior.", m_behaviorFireEventName.AsChar());
          Vision::Error.Warning(msg.AsChar());
          //VASSERT_MSG(false, msg.AsChar());
          FireAttack();
        }
        End();
      }
    }
    else
    {
      // we're currently attacking
      hkvVec3 const targetPosition = m_interactionEntity ? m_interactionEntity->GetPosition() : m_interactionPosition;
      FaceTargetPoint(targetPosition);

#ifdef _DEBUG
      if (m_debugDisplayInfo)
      {
        Vision::Game.DrawSingleLine(m_characterOwner->GetPosition(), targetPosition, VColorRef(255, 0, 255));
      }
#endif
    }
  }
  else
  {
    StartAttack();
  }
}