Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.46 KB | None | 0 0
  1. // precompiled header
  2. #include <cbase.h>
  3.  
  4. // shared includes
  5. #include <igamemovement.h>
  6. #include <in_buttons.h>
  7. #include <takedamageinfo.h>
  8.  
  9. // berimbau shared includes
  10. #include <berimbau/ActionFactory.h>
  11. #include <berimbau/IStance.h>
  12. #include <berimbau/scripts/Actions.h>
  13. #include <berimbau/actions/action.h>
  14. #include <berimbau/actions/moveaction.h>
  15. #include <berimbau/actions/blockaction.h>
  16. #include <berimbau/actions/attackaction.h>
  17.  
  18. #ifdef CLIENT_DLL
  19.     // berimbau client includes
  20.     #include <berimbau/c_berimbau_player.h>
  21. #else
  22.     // berimbau server includes
  23.     #include <berimbau/berimbau_player.h>
  24. #endif
  25.  
  26. // debug, include last
  27. #include <tier0/memdbgon.h>
  28.  
  29.  
  30. OPEN_KEYS_NAMESPACE
  31.  
  32.     extern Key move_lock;
  33.     Key block_perfect( "block_perfect" );
  34.     Key block_normal( "block_normal" );
  35.  
  36.     Key block_weak_left( "block_weak_left" );
  37.     Key block_weak_right( "block_weak_right" );
  38.  
  39.     Key block_left_weak( "block_left_weak" );
  40.     Key block_right_weak( "block_right_weak" );
  41.  
  42.     Key block_riposte( "block_forward_riposte" );
  43.     Key block_left_riposte( "block_left_riposte" );
  44.     Key block_right_riposte( "block_right_riposte" );
  45.  
  46. CLOSE_KEYS_NAMESPACE
  47.  
  48.  
  49. using namespace Berimbau;
  50. using namespace Script;
  51.  
  52.  
  53.  
  54. // CBlock
  55.  
  56. void CBlock::Start( CBerimbauActionsData *actionVars )
  57. {
  58.     //  default back direction as forwards since there's no back blocking
  59.     if(actionVars->mDirection == Directions::Back)
  60.         actionVars->mDirection = Directions::Forward;
  61.  
  62.     actionVars->mTransmitBlockDirection = true;
  63.  
  64.     CMoveAction::Start(actionVars);
  65. }
  66.  
  67.  
  68. void CBlock::PlayerMove( CMoveData* move, CBerimbauActionsData *actionVars )
  69. {
  70.     CMoveAction::PlayerMove( move, actionVars );
  71.  
  72.     // make sure button stays down
  73.     if ( ( move->m_nButtons & IN_BLOCK ) == 0 && CMoveAction::ShouldExpire(actionVars))
  74.     {
  75.         // stop this action
  76.         CSharedPlayer *pPlayer = ToBerimbauPlayer( actionVars->mPlayer.Get());
  77.         pPlayer->StopAction();
  78.         actionVars->mTransmitBlockDirection = false;
  79.         return;
  80.     }
  81.  
  82.     if((move->m_nButtons & IN_BLOCK) == false)
  83.         return;
  84.  
  85.     // when a block animation finishes, restart the base animation
  86.    
  87.     if ( actionVars->mBlockSequenceFinish > 0
  88.         && gpGlobals->curtime > actionVars->mBlockSequenceFinish)
  89.     {
  90.  
  91. #ifdef CLIENT_DLL
  92.         DevMsg( "CBlock animation finished, restarting base animation.\n" );
  93. #else
  94.         DevMsg( "C_Block animation finished, restarting base animation.\n" );
  95. #endif
  96. //      StartAnimation( GetAnimation( mPlayer->GetModelPtr() ) );
  97.         actionVars->mBlockSequenceFinish = -1.0f;      
  98.     }
  99.    
  100.  
  101.     Direction direction = Directions::Forward;
  102.    
  103.     if ( move->m_nButtons & IN_MOVERIGHT )
  104.         direction = Directions::Right;
  105.     else if ( move->m_nButtons & IN_MOVELEFT )
  106.         direction = Directions::Left;      
  107.     else if(move->m_nButtons & IN_BACK)
  108.         direction = Directions::Back;
  109.  
  110.     if(actionVars->mDirection != direction)
  111.         SetBlockDirection( actionVars, direction );
  112. }
  113.  
  114. bool CBlock::IsMovementLocked(CBerimbauActionsData *actionVars)
  115. {
  116.     // ignore lock duration and keep movement locked indefinitely
  117.     return GetData(actionVars->mActionId).GetBool( Keys::move_lock );
  118. }
  119.  
  120. void CBlock::SetBlockDirection( CBerimbauActionsData *actionVars, Direction direction )
  121. {
  122.     CSharedPlayer *pPlayer = ToBerimbauPlayer(actionVars->mPlayer.Get());
  123.     Assert(pPlayer);
  124.  
  125.     actionVars->mDirection = direction;
  126.     actionVars->mTransmitBlockDirection = true;
  127.  
  128.     if(actionVars->mDirection == Directions::Back)
  129.         actionVars->mDirection = Directions::Forward;
  130.  
  131.     //if ( actionVars->mDirection == direction )
  132.     //  return;
  133.     StartAnimation( GetAnimation( actionVars, pPlayer->GetModelPtr() ), pPlayer );
  134. }
  135.  
  136.  
  137. void CBlock::UpdateBlockDirection(CBerimbauActionsData *actionVars){
  138.     CSharedPlayer *pPlayer = ToBerimbauPlayer(actionVars->mPlayer.Get());
  139.     StartAnimation(  GetAnimation( actionVars, pPlayer->GetModelPtr() ), pPlayer );
  140. }
  141.  
  142. void CBlock::DefendAttack( CBerimbauActionsData *actionVars, CTakeDamageInfo& defender, CTakeDamageInfo& attacker,
  143.     Direction attackDirection, Activity& reaction, bool& sound, BlockType& blockType )
  144. {
  145.     CSharedPlayer * defendingPlayer = ToBerimbauPlayer(actionVars->mPlayer.Get());
  146.     CSharedPlayer * attackingPlayer = ToBerimbauPlayer(defender.GetAttacker());
  147.  
  148.     Assert(defendingPlayer);
  149.     Assert(attackingPlayer);
  150.  
  151.     CAttackAction *attack = dynamic_cast<CAttackAction*>(attackingPlayer->GetAction());
  152.  
  153.     Assert(attack);
  154.  
  155.     Direction blockDirection = actionVars->mDirection;
  156.  
  157.     int savedAttackerDirection = attackingPlayer->GetActionVars()->mDirection;
  158.     attackingPlayer->GetActionVars()->mDirection = attackingPlayer->GetActionVars()->mAttackDirection;
  159.  
  160.     // Check whether the attack is in the blocking region
  161.     // First, where did the attack hit
  162.     Vector PlayerCenter;
  163.     QAngle dud;
  164.     defendingPlayer->GetBonePosition(defendingPlayer->LookupBone("ValveBiped.Bip01_Pelvis"),PlayerCenter,dud);
  165.  
  166.     Vector AttackerCenter;
  167.     attackingPlayer->GetBonePosition(attackingPlayer->LookupBone("ValveBiped.Bip01_Pelvis"),AttackerCenter,dud);
  168.     Vector attackDir = AttackerCenter - PlayerCenter;
  169.  
  170.     // Compare with player facing
  171.     Vector facing;
  172.     AngleVectors( defendingPlayer->GetAbsAngles(),&facing);
  173.     // Ignore height differences
  174.     attackDir.z = 0;
  175.     facing.z = 0;
  176.     attackDir.NormalizeInPlace();
  177.     facing.NormalizeInPlace();
  178.  
  179.     //UTIL_AddDebugLine(AttackerCenter,PlayerCenter,true,false);
  180.  
  181.     CStudioHdr* const model = defendingPlayer->GetModelPtr();
  182.     const Data& data = GetData(actionVars->mActionId);
  183.  
  184.     int attackerTierIndex = attackingPlayer->GetActionVars()->mTierIndex;
  185.  
  186.     // The dot product is now the cosine of the angle between them.
  187.     if (attackDir.Dot(facing) < cos(M_PI/2)) {
  188.         // PI/2 is 90 degrees, meaning 180 total (from symmetry)
  189.         // Not in blocking region: no change.
  190.         //DevMsg("Attack not blocked!\n");
  191.     }
  192.  
  193.     else if ( attack && attackerTierIndex == 2 ){
  194.         //  tier 3 unblockable
  195.         blockType = BlockTypes::Unblockable;
  196.     }
  197.  
  198.  
  199.     // else if riposte
  200.     else if ( blockDirection == attackDirection )
  201.     {
  202.         blockType = BlockTypes::Riposte;
  203.  
  204.         //  no damage for defender
  205.         defender.SetDamage( -0.0f );
  206.  
  207.         //  set forces
  208.         if(attackingPlayer->InStance( Stances::Heavy ) ){
  209.             attacker.SetDamageForce( -defender.GetDamageForce() * 0.001); // mirror knockback on attacker
  210.             defender.SetDamageForce( defender.GetDamageForce() * 0.65 ); // no knockback for blocker
  211.         }
  212.         else{
  213.             attacker.SetDamageForce( -defender.GetDamageForce() * 1.00f); // mirror knockback on attacker
  214.             defender.SetDamageForce( defender.GetDamageForce() * 0.001f ); // no knockback for blocker
  215.         }
  216.  
  217.         //  set the blocker's riposte animation based on block direction
  218.         Activity act = ACT_INVALID;
  219.         if(blockDirection == Directions::Forward)
  220.             act = data.GetActivity( Keys::block_riposte, model );      
  221.         else if(blockDirection == Directions::Left)
  222.             act = data.GetActivity( Keys::block_left_riposte, model );     
  223.         else if(blockDirection == Directions::Right)
  224.             act = data.GetActivity( Keys::block_right_riposte, model );
  225.         reaction = act;
  226.  
  227.         // start interrupt action on attacker
  228.         if ( attackingPlayer && attack)
  229.         {          
  230.             Activity activity = ACT_INVALID;
  231.             activity = attack->GetRiposteReaction(attackingPlayer->GetActionVars(), attackingPlayer->GetModelPtr());
  232.             attackingPlayer->SetInterrupt(activity);
  233.             //attackingPlayer->ResetCombo();
  234.         }
  235.  
  236.     }
  237.  
  238.     // else if weak block
  239.     //  all other blocks
  240.     else
  241.     {
  242.         blockType = BlockTypes::Weak;
  243.         defender.SetDamage( defender.GetDamage() * 0.5f ); // half damage
  244.         defender.SetDamageForce( defender.GetDamageForce() * 0.5f ); // half knockback for defender
  245.         attacker.SetDamageForce( vec3_origin ); // no knockback for attacker
  246.  
  247.         //  get the animation of the defender's sword getting knocked away
  248.         //  based on direction of block
  249.         Activity act = ACT_INVALID;
  250.         if(blockDirection == Directions::Forward){
  251.             if(attackDirection == Directions::Left)
  252.                 act = data.GetActivity( Keys::block_weak_left, model );
  253.             else if(attackDirection == Directions::Right)
  254.                 act = data.GetActivity( Keys::block_weak_right, model );
  255.         }
  256.         else if(blockDirection == Directions::Left){
  257.             act = data.GetActivity( Keys::block_left_weak, model );
  258.         }
  259.         else if(blockDirection == Directions::Right){
  260.             act = data.GetActivity( Keys::block_right_weak, model );
  261.         }
  262.         reaction = act;
  263.  
  264.         //  get the animation for the attacker's sword getting knocked back a bit as well
  265.         act = attack->GetNormalBlock(attackingPlayer->GetActionVars(), attackingPlayer->GetModelPtr());
  266.         attackingPlayer->SetInterrupt( act );
  267.     }
  268.  
  269.     attackingPlayer->GetActionVars()->mDirection = (Berimbau::Direction)(savedAttackerDirection);
  270.  
  271. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement