浏览代码

Added more support for clearing

Fixes #5971

Support clearing for all database keys.
Additionally added support for dropping monster drops.

If you find more nodes that are missing support please report them.

Thanks to @Everade
Lemongrass3110 4 年之前
父节点
当前提交
02438563c5
共有 9 个文件被更改,包括 61 次插入4 次删除
  1. 2 0
      db/import-tmpl/mob_db.yml
  2. 2 0
      db/mob_db.yml
  3. 2 0
      db/pre-re/mob_db.yml
  4. 2 0
      db/re/mob_db.yml
  5. 2 0
      doc/yaml/db/mob_db.yml
  6. 5 1
      src/common/database.cpp
  7. 10 1
      src/common/database.hpp
  8. 34 1
      src/map/mob.cpp
  9. 2 1
      src/map/mob.hpp

+ 2 - 0
db/import-tmpl/mob_db.yml

@@ -65,12 +65,14 @@
 #       Rate                Drop rate of item. (Default: 1)
 #       RandomOptionGroup   Random Option Group applied to item on drop. (Default: None)
 #       Index               Index used for overwriting item. (Optional)
+#       Clear               If an index is given only the specific drop is cleared otherwise all drops are cleared. (Optional)
 #   Drops:                  List of possible normal item drops. Max of MAX_MOB_DROP. (Optional)
 #     - Item                Item name.
 #       Rate                Drop rate of item. (Default: 1)
 #       StealProtected      If the item is shielded from TF_STEAL. (Default: false)
 #       RandomOptionGroup   Random Option Group applied to item on drop. (Default: None)
 #       Index               Index used for overwriting item. (Optional)
+#       Clear               If an index is given only the specific drop is cleared otherwise all drops are cleared. (Optional)
 ###########################################################################
 
 Header:

+ 2 - 0
db/mob_db.yml

@@ -65,12 +65,14 @@
 #       Rate                Drop rate of item. (Default: 1)
 #       RandomOptionGroup   Random Option Group applied to item on drop. (Default: None)
 #       Index               Index used for overwriting item. (Optional)
+#       Clear               If an index is given only the specific drop is cleared otherwise all drops are cleared. (Optional)
 #   Drops:                  List of possible normal item drops. Max of MAX_MOB_DROP. (Optional)
 #     - Item                Item name.
 #       Rate                Drop rate of item. (Default: 1)
 #       StealProtected      If the item is shielded from TF_STEAL. (Default: false)
 #       RandomOptionGroup   Random Option Group applied to item on drop. (Default: None)
 #       Index               Index used for overwriting item. (Optional)
+#       Clear               If an index is given only the specific drop is cleared otherwise all drops are cleared. (Optional)
 ###########################################################################
 
 Header:

+ 2 - 0
db/pre-re/mob_db.yml

@@ -65,12 +65,14 @@
 #       Rate                Drop rate of item.
 #       RandomOptionGroup   Random Option Group applied to item on drop. (Default: None)
 #       Index               Index used for overwriting item. (Optional)
+#       Clear               If an index is given only the specific drop is cleared otherwise all drops are cleared. (Optional)
 #   Drops:                  List of possible normal item drops. Max of MAX_MOB_DROP. (Optional)
 #     - Item                Item name.
 #       Rate                Drop rate of item.
 #       StealProtected      If the item is shielded from TF_STEAL. (Default: false)
 #       RandomOptionGroup   Random Option Group applied to item on drop. (Default: None)
 #       Index               Index used for overwriting item. (Optional)
+#       Clear               If an index is given only the specific drop is cleared otherwise all drops are cleared. (Optional)
 ###########################################################################
 
 Header:

+ 2 - 0
db/re/mob_db.yml

@@ -65,12 +65,14 @@
 #       Rate                Drop rate of item.
 #       RandomOptionGroup   Random Option Group applied to item on drop. (Default: None)
 #       Index               Index used for overwriting item. (Optional)
+#       Clear               If an index is given only the specific drop is cleared otherwise all drops are cleared. (Optional)
 #   Drops:                  List of possible normal item drops. Max of MAX_MOB_DROP. (Optional)
 #     - Item                Item name.
 #       Rate                Drop rate of item.
 #       StealProtected      If the item is shielded from TF_STEAL. (Default: false)
 #       RandomOptionGroup   Random Option Group applied to item on drop. (Default: None)
 #       Index               Index used for overwriting item. (Optional)
+#       Clear               If an index is given only the specific drop is cleared otherwise all drops are cleared. (Optional)
 ###########################################################################
 
 Header:

+ 2 - 0
doc/yaml/db/mob_db.yml

@@ -48,10 +48,12 @@
 #       Rate                Drop rate of item.
 #       RandomOptionGroup   Random Option Group applied to item on drop. (Default: None)
 #       Index               Index used for overwriting item. (Optional)
+#       Clear               If an index is given only the specific drop is cleared otherwise all drops are cleared. (Optional)
 #   Drops:                  List of possible normal item drops. Max of MAX_MOB_DROP. (Optional)
 #     - Item                Item name.
 #       Rate                Drop rate of item.
 #       StealProtected      If the item is shielded from TF_STEAL. (Default: false)
 #       RandomOptionGroup   Random Option Group applied to item on drop. (Default: None)
 #       Index               Index used for overwriting item. (Optional)
+#       Clear               If an index is given only the specific drop is cleared otherwise all drops are cleared. (Optional)
 ###########################################################################

+ 5 - 1
src/common/database.cpp

@@ -150,7 +150,11 @@ void YamlDatabase::parse( const YAML::Node& rootNode ){
 		const char* fileName = this->currentFile.c_str();
 
 		for( const YAML::Node &node : bodyNode ){
-			count += this->parseBodyNode( node );
+			if( this->nodeExists( node, "Remove" ) ){
+				this->removeBodyNode( node );
+			}else{
+				count += this->parseBodyNode( node );
+			}
 
 			ShowStatus( "Loading [%" PRIdPTR "/%" PRIdPTR "] entries from '" CL_WHITE "%s" CL_RESET "'" CL_CLL "\r", ++childNodesProgressed, childNodesCount, fileName );
 		}

+ 10 - 1
src/common/database.hpp

@@ -27,7 +27,6 @@ private:
 	bool load( const std::string& path );
 	void parse( const YAML::Node& rootNode );
 	void parseImports( const YAML::Node& rootNode );
-	template <typename R> bool asType( const YAML::Node& node, const std::string& name, R& out );
 
 // These should be visible/usable by the implementation provider
 protected:
@@ -38,6 +37,7 @@ protected:
 	std::string getCurrentFile();
 
 	// Conversion functions
+	template <typename R> bool asType( const YAML::Node& node, const std::string& name, R& out );
 	bool asBool(const YAML::Node &node, const std::string &name, bool &out);
 	bool asInt16(const YAML::Node& node, const std::string& name, int16& out );
 	bool asUInt16(const YAML::Node& node, const std::string& name, uint16& out);
@@ -70,6 +70,7 @@ public:
 	// Functions that need to be implemented for each type
 	virtual void clear() = 0;
 	virtual const std::string getDefaultLocation() = 0;
+	virtual void removeBodyNode( const YAML::Node& node ) = 0;
 	virtual uint64 parseBodyNode( const YAML::Node& node ) = 0;
 };
 
@@ -133,6 +134,14 @@ public:
 	void erase(keytype key) {
 		this->data.erase(key);
 	}
+
+	void removeBodyNode( const YAML::Node& node ){
+		keytype key;
+
+		if( this->asType<keytype>( node, "Remove", key ) ){
+			this->data.erase( key );
+		}
+	}
 };
 
 template <typename keytype, typename datatype> class TypesafeCachedYamlDatabase : public TypesafeYamlDatabase<keytype, datatype>{

+ 34 - 1
src/map/mob.cpp

@@ -4199,7 +4199,7 @@ const std::string MobDatabase::getDefaultLocation() {
 	return std::string(db_path) + "/mob_db.yml";
 }
 
-bool MobDatabase::parseDropNode(std::string nodeName, YAML::Node node, uint8 max, s_mob_drop *drops) {
+bool MobDatabase::parseDropNode(const std::string& nodeName, const YAML::Node& node, uint8 max, s_mob_drop *drops) {
 	const YAML::Node &dropNode = node[nodeName];
 	uint16 i;
 
@@ -4221,6 +4221,19 @@ bool MobDatabase::parseDropNode(std::string nodeName, YAML::Node node, uint8 max
 				this->invalidWarning(dropit["Index"], "Invalid monster %s index %hu. Must be between 0~%hu, skipping.\n", nodeName.c_str(), index, max - 1);
 				continue;
 			}
+
+			if( this->nodeExists( dropit, "Clear" ) ){
+				bool clear;
+
+				if( !this->asBool( node, "Clear", clear ) ){
+					return false;
+				}
+
+				if( clear ){
+					// Clear specific index
+					drops[index] = {};
+				}
+			}
 		} else {
 			index = i++;
 
@@ -4228,6 +4241,26 @@ bool MobDatabase::parseDropNode(std::string nodeName, YAML::Node node, uint8 max
 				this->invalidWarning(dropit, "Maximum of %d monster %s met, skipping.\n", max, nodeName.c_str());
 				continue;
 			}
+
+			if( this->nodeExists( dropit, "Clear" ) ){
+				bool clear;
+
+				if( !this->asBool( node, "Clear", clear ) ){
+					return false;
+				}
+
+				if( clear ){
+					// Clear all
+					for( uint8 i = 0; i < max; i++ ){
+						drops[i] = {};
+					}
+
+					if( !this->nodeExists( node, "Item" ) ){
+						// Continue with next yaml node
+						continue;
+					}
+				}
+			}
 		}
 
 		std::string item_name;

+ 2 - 1
src/map/mob.hpp

@@ -234,7 +234,7 @@ struct s_mob_db {
 
 class MobDatabase : public TypesafeCachedYamlDatabase <uint32, s_mob_db> {
 private:
-	bool parseDropNode(std::string nodeName, YAML::Node node, uint8 max, s_mob_drop *drops);
+	bool parseDropNode(const std::string& nodeName, const YAML::Node& node, uint8 max, s_mob_drop *drops);
 
 public:
 	MobDatabase() : TypesafeCachedYamlDatabase("MOB_DB", 2, 1) {
@@ -325,6 +325,7 @@ public:
 	}
 
 	void clear() { };
+	void removeBodyNode(const YAML::Node& node) { };
 	const std::string getDefaultLocation();
 	uint64 parseBodyNode(const YAML::Node& node);
 };