101 lines
3.1 KiB
C++
101 lines
3.1 KiB
C++
#include "precompile.h"
|
|
|
|
#include "mt/Grasp.h"
|
|
|
|
IMPL_TABLE(mt::Grasp)
|
|
std::map<long long, std::tuple<int, std::set<int>>> mt::Grasp::hero_id_lv_gun_hash_;
|
|
|
|
namespace mt
|
|
{
|
|
|
|
void Grasp::Init1()
|
|
{
|
|
{
|
|
std::vector<std::string> strings;
|
|
a8::Split(add_buff_list(), strings, '|');
|
|
for (auto& str : strings) {
|
|
_add_buff_list.insert(a8::XValue(str));
|
|
}
|
|
}
|
|
{
|
|
std::vector<std::string> strings;
|
|
a8::Split(remove_buff_list(), strings, '|');
|
|
for (auto& str : strings) {
|
|
_remove_buff_list.insert(a8::XValue(str));
|
|
}
|
|
}
|
|
if (hero_id() == 0) {
|
|
abort();
|
|
}
|
|
if (hero_lv() == 0) {
|
|
abort();
|
|
}
|
|
if (weapon_id() == 0) {
|
|
abort();
|
|
}
|
|
}
|
|
|
|
void Grasp::Init2()
|
|
{
|
|
|
|
}
|
|
|
|
void Grasp::StaticPostInit()
|
|
{
|
|
int last_hero_id = 0;
|
|
int last_hero_lv = 0;
|
|
int last_weapon_id = 0;
|
|
Grasp::MutTraverse
|
|
(
|
|
[&last_hero_id, &last_hero_lv, &last_weapon_id] (mt::Grasp* meta, bool& stop) mutable
|
|
{
|
|
long long key = a8::MakeInt64(meta->hero_id(), meta->hero_lv());
|
|
if (!last_hero_id) {
|
|
last_hero_id = meta->hero_id();
|
|
last_hero_lv = meta->hero_lv();
|
|
last_weapon_id = meta->weapon_id();
|
|
if (meta->hero_lv() != 1) {
|
|
abort();
|
|
}
|
|
auto itr = hero_id_lv_gun_hash_.find(key);
|
|
if (itr != hero_id_lv_gun_hash_.end()) {
|
|
abort();
|
|
}
|
|
auto tuple = std::make_tuple(meta->weapon_id(), std::set<int>());
|
|
for (int buff_id : meta->_add_buff_list) {
|
|
std::get<1>(tuple).insert(buff_id);
|
|
}
|
|
for (int buff_id : meta->_remove_buff_list) {
|
|
std::get<1>(tuple).erase(buff_id);
|
|
}
|
|
hero_id_lv_gun_hash_[key] = tuple;
|
|
} else {
|
|
if (5 * (last_hero_lv / 5 + 1) != meta->hero_lv()) {
|
|
abort();
|
|
}
|
|
last_hero_id = meta->hero_id();
|
|
last_hero_lv = meta->hero_lv();
|
|
last_weapon_id = meta->weapon_id();
|
|
if (last_hero_lv == 15) {
|
|
last_hero_id = 0;
|
|
last_hero_lv = 0;
|
|
last_weapon_id = 0;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
std::set<int>* Grasp::GetBuffs(int hero_id, int hero_lv, int gun_id)
|
|
{
|
|
long long key = a8::MakeInt64(hero_id, hero_lv);
|
|
auto itr = hero_id_lv_gun_hash_.find(key);
|
|
if (itr != hero_id_lv_gun_hash_.end()) {
|
|
if (std::get<0>(itr->second) == gun_id) {
|
|
return &std::get<1>(itr->second);
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
}
|