77 lines
2.2 KiB
C++
77 lines
2.2 KiB
C++
#include "precompile.h"
|
|
|
|
#include "mt/Robot.h"
|
|
#include "mt/Hero.h"
|
|
|
|
IMPL_TABLE(mt::Robot)
|
|
|
|
namespace mt
|
|
{
|
|
|
|
void Robot::Init1()
|
|
{
|
|
std::vector<std::string> strings;
|
|
a8::Split(skin_id(), strings, '|');
|
|
for (auto& str : strings) {
|
|
_skin_id.push_back(a8::XValue(str));
|
|
}
|
|
if (_skin_id.size() != 3) {
|
|
A8_ABORT();
|
|
}
|
|
{
|
|
std::vector<std::string> strings;
|
|
a8::Split(bullet_offset(), strings, '|');
|
|
for (auto& str : strings) {
|
|
std::vector<std::string> strings2;
|
|
a8::Split(str, strings2, ':');
|
|
if (strings2.size() != 2) {
|
|
abort();
|
|
}
|
|
float angle = a8::XValue(strings2[0]).GetDouble();
|
|
int rnd = a8::XValue(strings2[1]).GetInt();
|
|
_bullet_offset_rand_space += rnd;
|
|
_bullet_offset.push_back(std::make_tuple(angle, _bullet_offset_rand_space));
|
|
}
|
|
}
|
|
hero_meta_ = mt::Hero::GetById(hero_id());
|
|
}
|
|
|
|
const mt::Robot* Robot::RandRobot(std::set<int>& refreshed_robot_set)
|
|
{
|
|
int try_count = 0;
|
|
while (true) {
|
|
const mt::Robot* tmp_robot_meta = raw_list[rand() % raw_list.size()];
|
|
if (!tmp_robot_meta->hero_meta_ ||
|
|
!tmp_robot_meta->hero_meta_->default_weapon()){
|
|
continue;
|
|
}
|
|
#ifdef MYDEBUG1
|
|
if (tmp_robot_meta->hero_id() != 30300) {
|
|
continue;
|
|
}
|
|
#endif
|
|
if (refreshed_robot_set.find(tmp_robot_meta->id()) == refreshed_robot_set.end()) {
|
|
return tmp_robot_meta;
|
|
}
|
|
++try_count;
|
|
if (try_count > 3000) {
|
|
return nullptr;
|
|
}
|
|
}
|
|
}
|
|
|
|
float Robot::RandBulletAngleOfsset() const
|
|
{
|
|
if (_bullet_offset_rand_space > 0) {
|
|
int rnd = rand() % _bullet_offset_rand_space;
|
|
for (auto& tuple : _bullet_offset) {
|
|
if (rnd < std::get<1>(tuple)) {
|
|
return std::get<0>(tuple);
|
|
}
|
|
}
|
|
}
|
|
return 0.0f;
|
|
}
|
|
|
|
}
|