xeijvro Posted May 31 Group: Members Topic Count: 7 Topics Per Day: 0.01 Content Count: 23 Reputation: 0 Joined: 12/02/22 Last Seen: 23 hours ago Share Posted May 31 +// Card Collection +const std::string CardCollectionDatabase::getDefaultLocation() { + return std::string(db_path) + "/card_collection.yml"; +} + +uint64 CardCollectionDatabase::parseBodyNode( const YAML::Node &node ){ + t_itemid card_id; + + { + std::string card; + + if( !this->asString( node, "Card", card ) ){ + return 0; + } + + std::shared_ptr<item_data> id = item_db.search_aegisname( card.c_str() ); + + if( id == nullptr ){ + this->invalidWarning( node["Item"], "Unknown item \"%s\".\n", card.c_str() ); + return 0; + } + + card_id = id->nameid; + } + + if (this->nodeExists(node, "Map")) { + std::string map; + + if (!this->asString(node, "Map", map)) + return 0; + + collect->map = map; + } + + if (this->nodeExists(node, "Count")){ + uint16 count; + + if (!this->asUInt16(node, "Count", count)) + return 0; + + collect->count = count; + } else { + if (!exists) + collect->count = 0; + } + + if (this->nodeExists(node, "Script")) { + std::string script; + + if (!this->asString(node, "Script", script)) + return 0; + + if (exists) { + script_free_code(collect->script); + collect->script = nullptr; + collect->desc = nullptr; + } + } else { + if (!exists) { + collect->script = nullptr; + collect->desc = nullptr; + } + } + + if (!exists) + this->put(collect->card,collect); + + return 1; +} + +CardCollectionDatabase card_collection_db; + /*========================================== * Return item data from item name. (lookup) * @param str Item Name @@ -3596,6 +3678,7 @@ static void itemdb_read(void) { itemdb_combo.load(); laphine_synthesis_db.load(); laphine_upgrade_db.load(); + card_collection_db.load(); if (battle_config.feature_roulette) itemdb_parse_roulette_db(); @@ -3662,6 +3745,7 @@ void do_final_itemdb(void) { random_option_group.clear(); laphine_synthesis_db.clear(); laphine_upgrade_db.clear(); + card_collection_db.clear(); if (battle_config.feature_roulette) itemdb_roulette_free(); } diff --git a/src/map/itemdb.hpp b/src/map/itemdb.hpp index 40381a5..a4915f5 100644 --- a/src/map/itemdb.hpp +++ b/src/map/itemdb.hpp @@ -1290,6 +1290,32 @@ public: extern LaphineUpgradeDatabase laphine_upgrade_db; +// Card Collection +struct s_card_collection{ + t_itemid card; + std::string map; + uint16 count; + script_code *script; + std::string desc; + + ~s_card_collection() { + if (script) + script_free_code(script); + } +}; + +class CardCollectionDatabase : public TypesafeYamlDatabase<t_itemid, s_card_collection>{ +public: + CardCollectionDatabase() : TypesafeYamlDatabase( "CARDCOLLECTION", 1 ){ + + } + + const std::string getDefaultLocation(); + uint64 parseBodyNode( const YAML::Node& node ); +}; + +extern CardCollectionDatabase card_collection_db; + // Extended Vending system [Lilith] struct s_item_vend_db { t_itemid nameid; diff --git a/src/map/script.cpp b/src/map/script.cpp index 0279168..ee98efe 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -26236,6 +26236,31 @@ BUILDIN_FUNC(party_summon_list) return SCRIPT_CMD_SUCCESS; } +// Card Collection +BUILDIN_FUNC(getcollectionlist) +{ + TBL_PC *sd; + int i=0; + + if( !script_rid2sd(sd) ) + return SCRIPT_CMD_FAILURE; + + const char* map = script_getstr( st, 2 ); + + for (const auto &collect : card_collection_db) { + std::shared_ptr<s_card_collection> card_collect = collect.second; + if (card_collect->map == map) { + pc_setreg(sd,reference_uid(add_str("@collection_card"), i),card_collect->card); + pc_setregstr(sd,reference_uid(add_str("@collection_map$"), i),card_collect->map.c_str()); + pc_setreg(sd,reference_uid(add_str("@collection_count"), i),card_collect->count); + pc_setregstr(sd,reference_uid(add_str("@collection_script$"), i),card_collect->desc.c_str()); + i++; + } + } + pc_setreg(sd,add_str("@collection_size"),i); + return SCRIPT_CMD_SUCCESS; +} + #include "../custom/script.inc" // declarations that were supposed to be exported from npc_chat.cpp @@ -26990,6 +27015,9 @@ struct script_function buildin_func[] = { BUILDIN_DEF(party_summon_kill,"ii"), BUILDIN_DEF(party_summon_count,"i"), BUILDIN_DEF(party_summon_list,"i??"), + + // Card Collection + BUILDIN_DEF(getcollectionlist,"s"), Quote Link to comment Share on other sites More sharing options...
Question
xeijvro
+// Card Collection
+const std::string CardCollectionDatabase::getDefaultLocation() {
+ return std::string(db_path) + "/card_collection.yml";
+}
+
+uint64 CardCollectionDatabase::parseBodyNode( const YAML::Node &node ){
+ t_itemid card_id;
+
+ {
+ std::string card;
+
+ if( !this->asString( node, "Card", card ) ){
+ return 0;
+ }
+
+ std::shared_ptr<item_data> id = item_db.search_aegisname( card.c_str() );
+
+ if( id == nullptr ){
+ this->invalidWarning( node["Item"], "Unknown item \"%s\".\n", card.c_str() );
+ return 0;
+ }
+
+ card_id = id->nameid;
+ }
+
+ if (this->nodeExists(node, "Map")) {
+ std::string map;
+
+ if (!this->asString(node, "Map", map))
+ return 0;
+
+ collect->map = map;
+ }
+
+ if (this->nodeExists(node, "Count")){
+ uint16 count;
+
+ if (!this->asUInt16(node, "Count", count))
+ return 0;
+
+ collect->count = count;
+ } else {
+ if (!exists)
+ collect->count = 0;
+ }
+
+ if (this->nodeExists(node, "Script")) {
+ std::string script;
+
+ if (!this->asString(node, "Script", script))
+ return 0;
+
+ if (exists) {
+ script_free_code(collect->script);
+ collect->script = nullptr;
+ collect->desc = nullptr;
+ }
+ } else {
+ if (!exists) {
+ collect->script = nullptr;
+ collect->desc = nullptr;
+ }
+ }
+
+ if (!exists)
+ this->put(collect->card,collect);
+
+ return 1;
+}
+
+CardCollectionDatabase card_collection_db;
+
/*==========================================
* Return item data from item name. (lookup)
* @param str Item Name
@@ -3596,6 +3678,7 @@ static void itemdb_read(void) {
itemdb_combo.load();
laphine_synthesis_db.load();
laphine_upgrade_db.load();
+ card_collection_db.load();
if (battle_config.feature_roulette)
itemdb_parse_roulette_db();
@@ -3662,6 +3745,7 @@ void do_final_itemdb(void) {
random_option_group.clear();
laphine_synthesis_db.clear();
laphine_upgrade_db.clear();
+ card_collection_db.clear();
if (battle_config.feature_roulette)
itemdb_roulette_free();
}
diff --git a/src/map/itemdb.hpp b/src/map/itemdb.hpp
index 40381a5..a4915f5 100644
--- a/src/map/itemdb.hpp
+++ b/src/map/itemdb.hpp
@@ -1290,6 +1290,32 @@ public:
extern LaphineUpgradeDatabase laphine_upgrade_db;
+// Card Collection
+struct s_card_collection{
+ t_itemid card;
+ std::string map;
+ uint16 count;
+ script_code *script;
+ std::string desc;
+
+ ~s_card_collection() {
+ if (script)
+ script_free_code(script);
+ }
+};
+
+class CardCollectionDatabase : public TypesafeYamlDatabase<t_itemid, s_card_collection>{
+public:
+ CardCollectionDatabase() : TypesafeYamlDatabase( "CARDCOLLECTION", 1 ){
+
+ }
+
+ const std::string getDefaultLocation();
+ uint64 parseBodyNode( const YAML::Node& node );
+};
+
+extern CardCollectionDatabase card_collection_db;
+
// Extended Vending system [Lilith]
struct s_item_vend_db {
t_itemid nameid;
diff --git a/src/map/script.cpp b/src/map/script.cpp
index 0279168..ee98efe 100644
--- a/src/map/script.cpp
+++ b/src/map/script.cpp
@@ -26236,6 +26236,31 @@ BUILDIN_FUNC(party_summon_list)
return SCRIPT_CMD_SUCCESS;
}
+// Card Collection
+BUILDIN_FUNC(getcollectionlist)
+{
+ TBL_PC *sd;
+ int i=0;
+
+ if( !script_rid2sd(sd) )
+ return SCRIPT_CMD_FAILURE;
+
+ const char* map = script_getstr( st, 2 );
+
+ for (const auto &collect : card_collection_db) {
+ std::shared_ptr<s_card_collection> card_collect = collect.second;
+ if (card_collect->map == map) {
+ pc_setreg(sd,reference_uid(add_str("@collection_card"), i),card_collect->card);
+ pc_setregstr(sd,reference_uid(add_str("@collection_map$"), i),card_collect->map.c_str());
+ pc_setreg(sd,reference_uid(add_str("@collection_count"), i),card_collect->count);
+ pc_setregstr(sd,reference_uid(add_str("@collection_script$"), i),card_collect->desc.c_str());
+ i++;
+ }
+ }
+ pc_setreg(sd,add_str("@collection_size"),i);
+ return SCRIPT_CMD_SUCCESS;
+}
+
#include "../custom/script.inc"
// declarations that were supposed to be exported from npc_chat.cpp
@@ -26990,6 +27015,9 @@ struct script_function buildin_func[] = {
BUILDIN_DEF(party_summon_kill,"ii"),
BUILDIN_DEF(party_summon_count,"i"),
BUILDIN_DEF(party_summon_list,"i??"),
+
+ // Card Collection
+ BUILDIN_DEF(getcollectionlist,"s"),
Link to comment
Share on other sites
0 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.