Skip to content

Commit d4810f3

Browse files
committed
Update src/npctalk.cpp
1 parent dd9274f commit d4810f3

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
@@ -3499,18 +3499,22 @@ talk_effect_fun_t::func f_add_trait( const JsonObject &jo, std::string_view memb
34993499

35003500
const auto &new_types = trait->types;
35013501

3502-
for( const std::string &t : existing_types ) {
3503-
bool match = false;
3504-
if constexpr( std::is_same_v<decltype( new_types ), const std::set<std::string> & > ) {
3505-
match = new_types.count( t ) > 0;
3506-
} else {
3507-
match = new_types.count( t ) > 0;
3508-
}
3509-
if( match ) {
3510-
guy->unset_mutation( existing );
3511-
break;
3502+
for( const trait_id &existing : guy->get_mutations() ) {
3503+
if( existing == trait ) {
3504+
continue;
35123505
}
3513-
}
3506+
const auto &existing_types = existing->types;
3507+
for( const std::string &t : existing_types ) {
3508+
bool match = false;
3509+
if constexpr( std::is_same<decltype( new_types ), const std::set<std::string> &>::value ) {
3510+
match = new_types.count( t ) > 0;
3511+
} else {
3512+
match = std::find( new_types.begin(), new_types.end(), t ) != new_types.end();
3513+
}
3514+
if( match ) {
3515+
guy->unset_mutation( existing );
3516+
break;
3517+
}
35143518

35153519
d.actor( is_npc )->set_mutation( trait, variant );
35163520
};

0 commit comments

Comments
 (0)