Spell's get_description can now replace some words with value of it's properties. e.g. "%%cast_cast_time " (not the whitespace at the end) will be replaced to the value stored in cast_cast_time. This value can scaled with class level like %#cast_cast_time, and with character level like %$cast_cast_time. Also made get_description overrideabe from scripts. And bound text_translation_key.

This commit is contained in:
Relintai 2020-02-26 16:49:52 +01:00
parent 89c558d1ba
commit 58e62da501
2 changed files with 51 additions and 0 deletions

View File

@ -723,6 +723,10 @@ String Spell::get_name_translated() const {
}
String Spell::get_description(const int class_level, const int character_level) {
return call("_get_description", class_level, character_level);
}
String Spell::_get_description(const int class_level, const int character_level) {
String str;
if (_text_translation_key != "") {
@ -731,6 +735,45 @@ String Spell::get_description(const int class_level, const int character_level)
str = _text_description;
int pos = str.find_char('%');
while (pos > 0) {
if (pos == str.size() - 1)
break;
CharType o = str[pos + 1];
if (o == '#' || o == '$' || o == '%') {
int nsp = str.find_char(' ', pos + 1);
if (pos < 0)
break;
String prop = str.substr(pos + 2, nsp - pos - 2);
StringName psm = prop;
bool valid = false;
Variant value = get(psm, &valid);
if (valid) {
if (o == '#') {
value = Variant::evaluate(Variant::OP_MULTIPLY, value, class_level / static_cast<float>(EntityEnums::MAX_CLASS_LEVEL));
value = static_cast<int>(value);
}
if (o == '$') {
value = Variant::evaluate(Variant::OP_MULTIPLY, value, character_level / static_cast<float>(EntityEnums::MAX_CHARACTER_LEVEL));
value = static_cast<int>(value);
}
str = str.replace(str.substr(pos, nsp - pos) + " ", value);
}
}
pos = str.find_char('%', pos + 1);
}
return str;
}
@ -1140,14 +1183,21 @@ void Spell::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "on_learn_auras", PROPERTY_HINT_NONE, "17/17:Aura", PROPERTY_USAGE_DEFAULT, "Aura"), "set_on_learn_auras", "get_on_learn_auras");
ADD_GROUP("Texts", "text");
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::STRING, "desc"), "_get_description", PropertyInfo(Variant::INT, "class_level"), PropertyInfo(Variant::INT, "character_level")));
ADD_PROPERTY(PropertyInfo(Variant::STRING, "text_name"), "set_name", "get_name");
ClassDB::bind_method(D_METHOD("get_text_translation_key"), &Spell::get_text_translation_key);
ClassDB::bind_method(D_METHOD("set_text_translation_key", "value"), &Spell::set_text_description);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "text_translation_key"), "set_text_translation_key", "get_text_translation_key");
ClassDB::bind_method(D_METHOD("get_text_description"), &Spell::get_text_description);
ClassDB::bind_method(D_METHOD("set_text_description", "value"), &Spell::set_text_description);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "text_description", PROPERTY_HINT_MULTILINE_TEXT), "set_text_description", "get_text_description");
ClassDB::bind_method(D_METHOD("get_name_translated"), &Spell::get_name_translated);
ClassDB::bind_method(D_METHOD("get_description", "class_level", "character_level"), &Spell::get_description);
ClassDB::bind_method(D_METHOD("_get_description", "class_level", "character_level"), &Spell::_get_description);
ADD_GROUP("Scaling", "scale");
ClassDB::bind_method(D_METHOD("get_scale_with_level"), &Spell::get_scale_with_level);

View File

@ -319,6 +319,7 @@ public:
String get_name_translated() const;
String get_description(const int class_level, const int character_level);
String _get_description(const int class_level, const int character_level);
Spell();
~Spell();