2020-01-31 19:34:47 +01:00
|
|
|
/*
|
|
|
|
Copyright (c) 2019-2020 Péter Magyar
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2019-04-20 14:02:55 +02:00
|
|
|
#include "character_spec.h"
|
|
|
|
|
2020-02-03 13:01:17 +01:00
|
|
|
#include "../../data/auras/aura.h"
|
2019-08-13 23:58:42 +02:00
|
|
|
|
2019-10-19 12:47:30 +02:00
|
|
|
int CharacterSpec::get_id() {
|
|
|
|
return _id;
|
2019-04-20 14:02:55 +02:00
|
|
|
}
|
2019-10-19 12:47:30 +02:00
|
|
|
void CharacterSpec::set_id(int value) {
|
|
|
|
_id = value;
|
2019-04-20 14:02:55 +02:00
|
|
|
}
|
|
|
|
|
2019-09-09 01:48:14 +02:00
|
|
|
int CharacterSpec::get_num_talent_rows() {
|
|
|
|
return _rows.size();
|
|
|
|
}
|
|
|
|
void CharacterSpec::set_num_talent_rows(int value) {
|
|
|
|
_rows.resize(value);
|
|
|
|
}
|
|
|
|
|
2019-04-20 14:02:55 +02:00
|
|
|
Ref<TalentRowData> CharacterSpec::get_talent_row(int index) const {
|
2019-09-09 01:48:14 +02:00
|
|
|
ERR_FAIL_INDEX_V(index, _rows.size(), Ref<TalentRowData>(NULL));
|
2019-04-20 14:02:55 +02:00
|
|
|
|
2019-08-13 23:58:42 +02:00
|
|
|
return _rows[index];
|
2019-04-20 14:02:55 +02:00
|
|
|
}
|
2019-08-13 23:58:42 +02:00
|
|
|
void CharacterSpec::set_talent_row(const int index, const Ref<TalentRowData> row) {
|
2019-09-09 01:48:14 +02:00
|
|
|
ERR_FAIL_INDEX(index, _rows.size());
|
|
|
|
|
|
|
|
_rows.set(index, row);
|
|
|
|
}
|
2019-04-20 14:02:55 +02:00
|
|
|
|
2019-09-09 01:48:14 +02:00
|
|
|
Vector<Variant> CharacterSpec::get_talent_rows() {
|
|
|
|
Vector<Variant> r;
|
|
|
|
for (int i = 0; i < _rows.size(); i++) {
|
|
|
|
r.push_back(_rows[i].get_ref_ptr());
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
void CharacterSpec::set_talent_rows(const Vector<Variant> &talent_rows) {
|
|
|
|
_rows.clear();
|
|
|
|
for (int i = 0; i < talent_rows.size(); i++) {
|
|
|
|
Ref<TalentRowData> talent_row = Ref<TalentRowData>(talent_rows[i]);
|
|
|
|
|
|
|
|
_rows.push_back(talent_row);
|
|
|
|
}
|
2019-04-20 14:02:55 +02:00
|
|
|
}
|
|
|
|
|
2019-10-06 18:19:04 +02:00
|
|
|
Ref<Aura> CharacterSpec::get_talent(const int row_index, const int culomn, const int rank) const {
|
|
|
|
ERR_FAIL_INDEX_V(row_index, _rows.size(), Ref<Aura>(NULL));
|
2019-04-20 14:02:55 +02:00
|
|
|
|
2019-08-13 23:58:42 +02:00
|
|
|
if (_rows[row_index].is_valid()) {
|
2019-10-06 16:47:03 +02:00
|
|
|
return _rows[row_index]->get_talent(culomn, rank);
|
2019-08-13 23:58:42 +02:00
|
|
|
}
|
2019-04-20 14:02:55 +02:00
|
|
|
|
2019-10-06 18:19:04 +02:00
|
|
|
return Ref<Aura>(NULL);
|
2019-04-20 14:02:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CharacterSpec::CharacterSpec() {
|
2019-10-19 12:47:30 +02:00
|
|
|
_id = 0;
|
2019-04-20 14:02:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CharacterSpec::~CharacterSpec() {
|
2019-09-09 01:48:14 +02:00
|
|
|
_rows.clear();
|
2019-04-20 14:02:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CharacterSpec::_bind_methods() {
|
2019-10-19 12:47:30 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_id"), &CharacterSpec::get_id);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_id", "value"), &CharacterSpec::set_id);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "id"), "set_id", "get_id");
|
2019-04-20 14:02:55 +02:00
|
|
|
|
2019-11-09 17:49:05 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "text_name"), "set_name", "get_name");
|
2019-04-20 14:02:55 +02:00
|
|
|
|
2019-09-09 01:48:14 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_num_talent_rows"), &CharacterSpec::get_num_talent_rows);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_num_talent_rows", "value"), &CharacterSpec::set_num_talent_rows);
|
|
|
|
|
2019-08-13 23:58:42 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_talent_row", "index"), &CharacterSpec::get_talent_row);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_talent_row", "index", "row"), &CharacterSpec::set_talent_row);
|
2019-04-20 14:02:55 +02:00
|
|
|
|
2019-10-06 16:47:03 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_talent", "row_index", "culomn", "rank"), &CharacterSpec::get_talent);
|
|
|
|
|
2019-09-09 01:48:14 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_talent_rows"), &CharacterSpec::get_talent_rows);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_talent_rows", "auras"), &CharacterSpec::set_talent_rows);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "talent_rows", PROPERTY_HINT_NONE, "17/17:TalentRowData", PROPERTY_USAGE_DEFAULT, "TalentRowData"), "set_talent_rows", "get_talent_rows");
|
2019-04-20 14:02:55 +02:00
|
|
|
}
|