|
@@ -410,6 +410,7 @@ uint64 BarterDatabase::parseBodyNode( const ryml::NodeRef& node ){
|
|
if( !exists ){
|
|
if( !exists ){
|
|
barter = std::make_shared<s_npc_barter>();
|
|
barter = std::make_shared<s_npc_barter>();
|
|
barter->name = npcname;
|
|
barter->name = npcname;
|
|
|
|
+ barter->npcid = 0;
|
|
}
|
|
}
|
|
|
|
|
|
if( this->nodeExists( node, "Map" ) ){
|
|
if( this->nodeExists( node, "Map" ) ){
|
|
@@ -729,59 +730,64 @@ void BarterDatabase::loadingFinished(){
|
|
|
|
|
|
std::shared_ptr<s_npc_barter> barter = pair.second;
|
|
std::shared_ptr<s_npc_barter> barter = pair.second;
|
|
|
|
|
|
- struct npc_data* nd = npc_create_npc( barter->m, barter->x, barter->y );
|
|
|
|
-
|
|
|
|
- npc_parsename( nd, barter->name.c_str(), nullptr, nullptr, __FILE__ ":" QUOTE(__LINE__) );
|
|
|
|
-
|
|
|
|
- nd->class_ = barter->sprite;
|
|
|
|
- nd->speed = 200;
|
|
|
|
-
|
|
|
|
- nd->bl.type = BL_NPC;
|
|
|
|
- nd->subtype = NPCTYPE_BARTER;
|
|
|
|
-
|
|
|
|
- nd->u.barter.extended = false;
|
|
|
|
|
|
+ bool extended = false;
|
|
|
|
|
|
// Check if it has to use the extended barter feature or not
|
|
// Check if it has to use the extended barter feature or not
|
|
for( const auto& itemPair : barter->items ){
|
|
for( const auto& itemPair : barter->items ){
|
|
// Normal barter cannot have zeny requirements
|
|
// Normal barter cannot have zeny requirements
|
|
if( itemPair.second->price > 0 ){
|
|
if( itemPair.second->price > 0 ){
|
|
- nd->u.barter.extended = true;
|
|
|
|
|
|
+ extended = true;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
// Normal barter needs to have exchange items defined
|
|
// Normal barter needs to have exchange items defined
|
|
if( itemPair.second->requirements.empty() ){
|
|
if( itemPair.second->requirements.empty() ){
|
|
- nd->u.barter.extended = true;
|
|
|
|
|
|
+ extended = true;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
// Normal barter can only exchange 1:1
|
|
// Normal barter can only exchange 1:1
|
|
if( itemPair.second->requirements.size() > 1 ){
|
|
if( itemPair.second->requirements.size() > 1 ){
|
|
- nd->u.barter.extended = true;
|
|
|
|
|
|
+ extended = true;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
// Normal barter cannot handle refine
|
|
// Normal barter cannot handle refine
|
|
for( const auto& requirement : itemPair.second->requirements ){
|
|
for( const auto& requirement : itemPair.second->requirements ){
|
|
if( requirement.second->refine >= 0 ){
|
|
if( requirement.second->refine >= 0 ){
|
|
- nd->u.barter.extended = true;
|
|
|
|
|
|
+ extended = true;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// Check if a refine requirement has been set in the loop above
|
|
// Check if a refine requirement has been set in the loop above
|
|
- if( nd->u.barter.extended ){
|
|
|
|
|
|
+ if( extended ){
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if( nd->u.barter.extended && !battle_config.feature_barter_extended ){
|
|
|
|
|
|
+ if( extended && !battle_config.feature_barter_extended ){
|
|
#ifndef BUILDBOT
|
|
#ifndef BUILDBOT
|
|
- ShowError( "Barter %s uses extended mechanics but this is not enabled.\n", nd->name );
|
|
|
|
|
|
+ ShowError( "Barter %s uses extended mechanics but this is not enabled.\n", barter->name.c_str() );
|
|
#endif
|
|
#endif
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ struct npc_data* nd = npc_create_npc( barter->m, barter->x, barter->y );
|
|
|
|
+
|
|
|
|
+ // Store the npcid for the destructor
|
|
|
|
+ barter->npcid = nd->bl.id;
|
|
|
|
+
|
|
|
|
+ npc_parsename( nd, barter->name.c_str(), nullptr, nullptr, __FILE__ ":" QUOTE(__LINE__) );
|
|
|
|
+
|
|
|
|
+ nd->class_ = barter->sprite;
|
|
|
|
+ nd->speed = 200;
|
|
|
|
+
|
|
|
|
+ nd->bl.type = BL_NPC;
|
|
|
|
+ nd->subtype = NPCTYPE_BARTER;
|
|
|
|
+
|
|
|
|
+ nd->u.barter.extended = extended;
|
|
|
|
+
|
|
if( nd->bl.m >= 0 ){
|
|
if( nd->bl.m >= 0 ){
|
|
map_addnpc( nd->bl.m, nd );
|
|
map_addnpc( nd->bl.m, nd );
|
|
npc_setcells( nd );
|
|
npc_setcells( nd );
|
|
@@ -840,6 +846,20 @@ void BarterDatabase::loadingFinished(){
|
|
TypesafeYamlDatabase::loadingFinished();
|
|
TypesafeYamlDatabase::loadingFinished();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+s_npc_barter::~s_npc_barter(){
|
|
|
|
+ if( this->npcid != 0 ){
|
|
|
|
+ struct npc_data* nd = map_id2nd( this->npcid );
|
|
|
|
+
|
|
|
|
+ // Check if the NPC still exists or has been removed already
|
|
|
|
+ if( nd != nullptr ){
|
|
|
|
+ // Delete the NPC
|
|
|
|
+ npc_unload( nd, true );
|
|
|
|
+ // Update NPC event database
|
|
|
|
+ npc_read_event_script();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
BarterDatabase barter_db;
|
|
BarterDatabase barter_db;
|
|
|
|
|
|
/**
|
|
/**
|