Skip to content

Commit

Permalink
Refactor martial arts buff requirements check (#52501)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettDong authored Oct 29, 2021
1 parent 2ae93dc commit 98d544e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 33 deletions.
48 changes: 15 additions & 33 deletions src/martialarts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,48 +458,30 @@ void clear_techniques_and_martial_arts()
ma_techniques.reset();
}

bool ma_requirements::is_valid_character( const Character &u ) const
bool ma_requirements::buff_requirements_satisfied( const Character &u ) const
{
// Check: Required Buffs All
for( const mabuff_id &buff_id : req_buffs_all ) {
if( !u.has_mabuff( buff_id ) ) {
return false;
}
}
const auto having_buff = [&u]( const mabuff_id & buff_id ) {
return u.has_mabuff( buff_id );
};

// Check: Forbidden Buffs Any
for( const mabuff_id &buff_id : forbid_buffs_any ) {
if( u.has_mabuff( buff_id ) ) {
return false;
}
if( std::any_of( forbid_buffs_any.begin(), forbid_buffs_any.end(), having_buff ) ) {
return false;
}

// Check: Required Buffs Any
if( !req_buffs_any.empty() ) {}
bool req_buff_valid = false;

for( const mabuff_id &buff_id : req_buffs_any ) {
if( u.has_mabuff( buff_id ) ) {
req_buff_valid = true;
}

if( !req_buff_valid ) {
if( !forbid_buffs_all.empty() ) {
if( std::all_of( forbid_buffs_all.begin(), forbid_buffs_all.end(), having_buff ) ) {
return false;
}
}

// Check: Forbidden Buffs All
if( !forbid_buffs_all.empty() ) {}
bool forbid_buff_valid = false;

for( const mabuff_id &buff_id : forbid_buffs_all ) {
if( !u.has_mabuff( buff_id ) ) {
forbid_buff_valid = true;
}
return std::all_of( req_buffs_all.begin(), req_buffs_all.end(), having_buff ) &&
( req_buffs_any.empty() || std::any_of( req_buffs_any.begin(), req_buffs_any.end(), having_buff ) );
}

if( !forbid_buff_valid ) {
return false;
}
bool ma_requirements::is_valid_character( const Character &u ) const
{
if( !buff_requirements_satisfied( u ) ) {
return false;
}

//A technique is valid if it applies to unarmed strikes, if it applies generally
Expand Down
1 change: 1 addition & 0 deletions src/martialarts.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct ma_requirements {

std::string get_description( bool buff = false ) const;

bool buff_requirements_satisfied( const Character &u ) const;
bool is_valid_character( const Character &u ) const;
bool is_valid_weapon( const item &i ) const;

Expand Down

0 comments on commit 98d544e

Please sign in to comment.