Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // precompiled header
- #include <cbase.h>
- // shared includes
- #include <igamemovement.h>
- #include <in_buttons.h>
- #include <takedamageinfo.h>
- // berimbau shared includes
- #include <berimbau/ActionFactory.h>
- #include <berimbau/IStance.h>
- #include <berimbau/scripts/Actions.h>
- #include <berimbau/actions/action.h>
- #include <berimbau/actions/moveaction.h>
- #include <berimbau/actions/blockaction.h>
- #include <berimbau/actions/attackaction.h>
- #ifdef CLIENT_DLL
- // berimbau client includes
- #include <berimbau/c_berimbau_player.h>
- #else
- // berimbau server includes
- #include <berimbau/berimbau_player.h>
- #endif
- // debug, include last
- #include <tier0/memdbgon.h>
- OPEN_KEYS_NAMESPACE
- extern Key move_lock;
- Key block_perfect( "block_perfect" );
- Key block_normal( "block_normal" );
- Key block_weak_left( "block_weak_left" );
- Key block_weak_right( "block_weak_right" );
- Key block_left_weak( "block_left_weak" );
- Key block_right_weak( "block_right_weak" );
- Key block_riposte( "block_forward_riposte" );
- Key block_left_riposte( "block_left_riposte" );
- Key block_right_riposte( "block_right_riposte" );
- CLOSE_KEYS_NAMESPACE
- using namespace Berimbau;
- using namespace Script;
- // CBlock
- void CBlock::Start( CBerimbauActionsData *actionVars )
- {
- // default back direction as forwards since there's no back blocking
- if(actionVars->mDirection == Directions::Back)
- actionVars->mDirection = Directions::Forward;
- actionVars->mTransmitBlockDirection = true;
- CMoveAction::Start(actionVars);
- }
- void CBlock::PlayerMove( CMoveData* move, CBerimbauActionsData *actionVars )
- {
- CMoveAction::PlayerMove( move, actionVars );
- // make sure button stays down
- if ( ( move->m_nButtons & IN_BLOCK ) == 0 && CMoveAction::ShouldExpire(actionVars))
- {
- // stop this action
- CSharedPlayer *pPlayer = ToBerimbauPlayer( actionVars->mPlayer.Get());
- pPlayer->StopAction();
- actionVars->mTransmitBlockDirection = false;
- return;
- }
- if((move->m_nButtons & IN_BLOCK) == false)
- return;
- // when a block animation finishes, restart the base animation
- if ( actionVars->mBlockSequenceFinish > 0
- && gpGlobals->curtime > actionVars->mBlockSequenceFinish)
- {
- #ifdef CLIENT_DLL
- DevMsg( "CBlock animation finished, restarting base animation.\n" );
- #else
- DevMsg( "C_Block animation finished, restarting base animation.\n" );
- #endif
- // StartAnimation( GetAnimation( mPlayer->GetModelPtr() ) );
- actionVars->mBlockSequenceFinish = -1.0f;
- }
- Direction direction = Directions::Forward;
- if ( move->m_nButtons & IN_MOVERIGHT )
- direction = Directions::Right;
- else if ( move->m_nButtons & IN_MOVELEFT )
- direction = Directions::Left;
- else if(move->m_nButtons & IN_BACK)
- direction = Directions::Back;
- if(actionVars->mDirection != direction)
- SetBlockDirection( actionVars, direction );
- }
- bool CBlock::IsMovementLocked(CBerimbauActionsData *actionVars)
- {
- // ignore lock duration and keep movement locked indefinitely
- return GetData(actionVars->mActionId).GetBool( Keys::move_lock );
- }
- void CBlock::SetBlockDirection( CBerimbauActionsData *actionVars, Direction direction )
- {
- CSharedPlayer *pPlayer = ToBerimbauPlayer(actionVars->mPlayer.Get());
- Assert(pPlayer);
- actionVars->mDirection = direction;
- actionVars->mTransmitBlockDirection = true;
- if(actionVars->mDirection == Directions::Back)
- actionVars->mDirection = Directions::Forward;
- //if ( actionVars->mDirection == direction )
- // return;
- StartAnimation( GetAnimation( actionVars, pPlayer->GetModelPtr() ), pPlayer );
- }
- void CBlock::UpdateBlockDirection(CBerimbauActionsData *actionVars){
- CSharedPlayer *pPlayer = ToBerimbauPlayer(actionVars->mPlayer.Get());
- StartAnimation( GetAnimation( actionVars, pPlayer->GetModelPtr() ), pPlayer );
- }
- void CBlock::DefendAttack( CBerimbauActionsData *actionVars, CTakeDamageInfo& defender, CTakeDamageInfo& attacker,
- Direction attackDirection, Activity& reaction, bool& sound, BlockType& blockType )
- {
- CSharedPlayer * defendingPlayer = ToBerimbauPlayer(actionVars->mPlayer.Get());
- CSharedPlayer * attackingPlayer = ToBerimbauPlayer(defender.GetAttacker());
- Assert(defendingPlayer);
- Assert(attackingPlayer);
- CAttackAction *attack = dynamic_cast<CAttackAction*>(attackingPlayer->GetAction());
- Assert(attack);
- Direction blockDirection = actionVars->mDirection;
- int savedAttackerDirection = attackingPlayer->GetActionVars()->mDirection;
- attackingPlayer->GetActionVars()->mDirection = attackingPlayer->GetActionVars()->mAttackDirection;
- // Check whether the attack is in the blocking region
- // First, where did the attack hit
- Vector PlayerCenter;
- QAngle dud;
- defendingPlayer->GetBonePosition(defendingPlayer->LookupBone("ValveBiped.Bip01_Pelvis"),PlayerCenter,dud);
- Vector AttackerCenter;
- attackingPlayer->GetBonePosition(attackingPlayer->LookupBone("ValveBiped.Bip01_Pelvis"),AttackerCenter,dud);
- Vector attackDir = AttackerCenter - PlayerCenter;
- // Compare with player facing
- Vector facing;
- AngleVectors( defendingPlayer->GetAbsAngles(),&facing);
- // Ignore height differences
- attackDir.z = 0;
- facing.z = 0;
- attackDir.NormalizeInPlace();
- facing.NormalizeInPlace();
- //UTIL_AddDebugLine(AttackerCenter,PlayerCenter,true,false);
- CStudioHdr* const model = defendingPlayer->GetModelPtr();
- const Data& data = GetData(actionVars->mActionId);
- int attackerTierIndex = attackingPlayer->GetActionVars()->mTierIndex;
- // The dot product is now the cosine of the angle between them.
- if (attackDir.Dot(facing) < cos(M_PI/2)) {
- // PI/2 is 90 degrees, meaning 180 total (from symmetry)
- // Not in blocking region: no change.
- //DevMsg("Attack not blocked!\n");
- }
- else if ( attack && attackerTierIndex == 2 ){
- // tier 3 unblockable
- blockType = BlockTypes::Unblockable;
- }
- // else if riposte
- else if ( blockDirection == attackDirection )
- {
- blockType = BlockTypes::Riposte;
- // no damage for defender
- defender.SetDamage( -0.0f );
- // set forces
- if(attackingPlayer->InStance( Stances::Heavy ) ){
- attacker.SetDamageForce( -defender.GetDamageForce() * 0.001); // mirror knockback on attacker
- defender.SetDamageForce( defender.GetDamageForce() * 0.65 ); // no knockback for blocker
- }
- else{
- attacker.SetDamageForce( -defender.GetDamageForce() * 1.00f); // mirror knockback on attacker
- defender.SetDamageForce( defender.GetDamageForce() * 0.001f ); // no knockback for blocker
- }
- // set the blocker's riposte animation based on block direction
- Activity act = ACT_INVALID;
- if(blockDirection == Directions::Forward)
- act = data.GetActivity( Keys::block_riposte, model );
- else if(blockDirection == Directions::Left)
- act = data.GetActivity( Keys::block_left_riposte, model );
- else if(blockDirection == Directions::Right)
- act = data.GetActivity( Keys::block_right_riposte, model );
- reaction = act;
- // start interrupt action on attacker
- if ( attackingPlayer && attack)
- {
- Activity activity = ACT_INVALID;
- activity = attack->GetRiposteReaction(attackingPlayer->GetActionVars(), attackingPlayer->GetModelPtr());
- attackingPlayer->SetInterrupt(activity);
- //attackingPlayer->ResetCombo();
- }
- }
- // else if weak block
- // all other blocks
- else
- {
- blockType = BlockTypes::Weak;
- defender.SetDamage( defender.GetDamage() * 0.5f ); // half damage
- defender.SetDamageForce( defender.GetDamageForce() * 0.5f ); // half knockback for defender
- attacker.SetDamageForce( vec3_origin ); // no knockback for attacker
- // get the animation of the defender's sword getting knocked away
- // based on direction of block
- Activity act = ACT_INVALID;
- if(blockDirection == Directions::Forward){
- if(attackDirection == Directions::Left)
- act = data.GetActivity( Keys::block_weak_left, model );
- else if(attackDirection == Directions::Right)
- act = data.GetActivity( Keys::block_weak_right, model );
- }
- else if(blockDirection == Directions::Left){
- act = data.GetActivity( Keys::block_left_weak, model );
- }
- else if(blockDirection == Directions::Right){
- act = data.GetActivity( Keys::block_right_weak, model );
- }
- reaction = act;
- // get the animation for the attacker's sword getting knocked back a bit as well
- act = attack->GetNormalBlock(attackingPlayer->GetActionVars(), attackingPlayer->GetModelPtr());
- attackingPlayer->SetInterrupt( act );
- }
- attackingPlayer->GetActionVars()->mDirection = (Berimbau::Direction)(savedAttackerDirection);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement