2020-04-28 23:54:23 +02:00
|
|
|
/*
|
2022-01-12 21:44:26 +01:00
|
|
|
Copyright (c) 2019-2022 Péter Magyar
|
2020-04-28 23:54:23 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "entity_resource_speed.h"
|
|
|
|
|
|
|
|
#include "../../database/ess_resource_db.h"
|
|
|
|
#include "../../singletons/ess.h"
|
|
|
|
#include "../entity.h"
|
2020-06-20 15:26:21 +02:00
|
|
|
#include "entity_resource.h"
|
2020-04-28 23:54:23 +02:00
|
|
|
|
|
|
|
void EntityResourceSpeed::_init() {
|
|
|
|
set_current_value(base_value);
|
|
|
|
|
|
|
|
speed_stat_id = 0;
|
|
|
|
|
2020-05-23 16:29:47 +02:00
|
|
|
if (ESS::get_singleton()->stat_is_property("Speed"))
|
|
|
|
speed_stat_id = ESS::get_singleton()->stat_get_id("Speed");
|
2020-04-28 23:54:23 +02:00
|
|
|
}
|
|
|
|
void EntityResourceSpeed::_ons_added(Node *entity) {
|
|
|
|
refresh();
|
|
|
|
}
|
2020-05-01 17:15:44 +02:00
|
|
|
void EntityResourceSpeed::_notification_sstat_changed(int statid, float current) {
|
|
|
|
if (statid == speed_stat_id)
|
2020-04-28 23:54:23 +02:00
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
void EntityResourceSpeed::refresh() {
|
2020-04-29 01:05:31 +02:00
|
|
|
ERR_FAIL_COND(get_owner() == NULL);
|
|
|
|
|
2020-05-01 17:15:44 +02:00
|
|
|
float speed_stat = get_owner()->stat_gets_current(speed_stat_id);
|
2020-04-28 23:54:23 +02:00
|
|
|
|
2020-05-01 17:15:44 +02:00
|
|
|
set_max_value(base_value + speed_stat * 0.01);
|
|
|
|
set_current_value(base_value + speed_stat * 0.01);
|
2020-04-28 23:54:23 +02:00
|
|
|
}
|
|
|
|
|
2020-04-29 01:05:31 +02:00
|
|
|
void EntityResourceSpeed::resolve_references() {
|
|
|
|
}
|
|
|
|
|
2020-04-28 23:54:23 +02:00
|
|
|
EntityResourceSpeed::EntityResourceSpeed() {
|
|
|
|
speed_stat_id = 0;
|
|
|
|
base_value = 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
EntityResourceSpeed::~EntityResourceSpeed() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void EntityResourceSpeed::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("_init"), &EntityResourceSpeed::_init);
|
|
|
|
ClassDB::bind_method(D_METHOD("_ons_added", "entity"), &EntityResourceSpeed::_ons_added);
|
2020-05-01 17:15:44 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("_notification_sstat_changed", "statid", "current"), &EntityResourceSpeed::_notification_sstat_changed);
|
2020-04-28 23:54:23 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("refresh"), &EntityResourceSpeed::refresh);
|
|
|
|
}
|