Skip to content

Commit d9400fb

Browse files
authored
Update src/npctalk.cpp
1 parent 8d9a19a commit d9400fb

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/npctalk.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3511,18 +3511,22 @@ talk_effect_fun_t::func f_add_trait( const JsonObject &jo, std::string_view memb
35113511

35123512
const auto &new_types = trait->types;
35133513

3514-
for( const std::string &t : existing_types ) {
3515-
bool match = false;
3516-
if constexpr( std::is_same_v<decltype( new_types ), const std::set<std::string> & > ) {
3517-
match = new_types.count( t ) > 0;
3518-
} else {
3519-
match = new_types.count( t ) > 0;
3520-
}
3521-
if( match ) {
3522-
guy->unset_mutation( existing );
3523-
break;
3514+
for( const trait_id &existing : guy->get_mutations() ) {
3515+
if( existing == trait ) {
3516+
continue;
35243517
}
3525-
}
3518+
const auto &existing_types = existing->types;
3519+
for( const std::string &t : existing_types ) {
3520+
bool match = false;
3521+
if constexpr( std::is_same<decltype( new_types ), const std::set<std::string> &>::value ) {
3522+
match = new_types.count( t ) > 0;
3523+
} else {
3524+
match = std::find( new_types.begin(), new_types.end(), t ) != new_types.end();
3525+
}
3526+
if( match ) {
3527+
guy->unset_mutation( existing );
3528+
break;
3529+
}
35263530

35273531
d.actor( is_npc )->set_mutation( trait, variant );
35283532
};

0 commit comments

Comments
 (0)