Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor martial arts buff requirements check #52501

Merged
merged 1 commit into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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