151 lines
3.6 KiB
C++
151 lines
3.6 KiB
C++
#include "precompile.h"
|
|
|
|
#include "android.h"
|
|
#include "room.h"
|
|
#include "app.h"
|
|
#include "android_agent.h"
|
|
#include "movement.h"
|
|
#include "battledatacontext.h"
|
|
|
|
#include "f8/btmgr.h"
|
|
|
|
#include "mt/Equip.h"
|
|
#include "mt/Robot.h"
|
|
|
|
Android::Android():Human()
|
|
{
|
|
#if 0
|
|
++PerfMonitor::Instance()->entity_num[ET_Android];
|
|
#endif
|
|
agent_ = behaviac::Agent::Create<AndroidAgent>();
|
|
if (!agent_) {
|
|
abort();
|
|
}
|
|
agent_->SetOwner(this);
|
|
f8::BtMgr::Instance()->BtLoad(agent_, "android_pvp");
|
|
f8::BtMgr::Instance()->BtSetCurrent(agent_, "android_pvp");
|
|
}
|
|
|
|
Android::~Android()
|
|
{
|
|
if (agent_) {
|
|
f8::BtMgr::Instance()->BtDestory(agent_);
|
|
agent_ = nullptr;
|
|
}
|
|
#if 0
|
|
--PerfMonitor::Instance()->entity_num[ET_Android];
|
|
#endif
|
|
}
|
|
|
|
void Android::Initialize()
|
|
{
|
|
Human::Initialize();
|
|
RandSkin();
|
|
GiveEquip();
|
|
RecalcBaseAttr();
|
|
SetInfiniteBulletMode();
|
|
{
|
|
auto context = std::make_shared<BattleDataContext>();
|
|
SetBattleContext(context);
|
|
context->ForceInit
|
|
(
|
|
App::Instance()->AllocTempHeroUniId(),
|
|
meta,
|
|
App::Instance()->AllocTempWeaponUniId(),
|
|
GetCurrWeapon()->meta,
|
|
0,
|
|
nullptr
|
|
);
|
|
GetBattleContext()->Init(this);
|
|
}
|
|
SetHP(GetBattleContext()->GetMaxHP());
|
|
SetMaxHP(GetHP());
|
|
{
|
|
avatar_url = a8::XValue(50001 + rand() % 10).GetString();
|
|
head_frame = 60000;
|
|
}
|
|
}
|
|
|
|
void Android::Update(int delta_time)
|
|
{
|
|
if (UpdatedTimes() <= 0) {
|
|
if (room->GetFrameNo() % 2 != 0) {
|
|
return;
|
|
}
|
|
}
|
|
InternalUpdate(delta_time);
|
|
++updated_times_;
|
|
}
|
|
|
|
void Android::InternalUpdate(int delta_time)
|
|
{
|
|
if (a8::HasBitFlag(status, CS_Disable)) {
|
|
return;
|
|
}
|
|
if (poisoning) {
|
|
UpdatePoisoning();
|
|
}
|
|
if (action_type != AT_None) {
|
|
UpdateAction();
|
|
}
|
|
if (HasBuffEffect(kBET_Fly)) {
|
|
Global::Instance()->verify_set_pos = 1;
|
|
GetMutablePos().FromGlmVec3(room->plane.curr_pos);
|
|
Global::Instance()->verify_set_pos = 0;
|
|
room->grid_service->MoveCreature(this);
|
|
return;
|
|
}
|
|
if (GetMovement()->GetPathSize() > 0) {
|
|
Global::Instance()->verify_set_pos = 1;
|
|
UpdateMove();
|
|
#ifdef DEBUG1
|
|
a8::XPrintf("updatemove old_pos:%f,%f new_pos:%f,%f\n",
|
|
{
|
|
old_pos.x,
|
|
old_pos.y,
|
|
GetPos().x,
|
|
GetPos().y,
|
|
});
|
|
#endif
|
|
Global::Instance()->verify_set_pos = 0;
|
|
} else {
|
|
if (HasBuffEffect(kBET_Jump)) {
|
|
glm::vec3 dir = GlmHelper::UP;
|
|
GlmHelper::RotateY(dir, (10 + rand() % 360)/ 180.0f);
|
|
GlmHelper::Normalize(dir);
|
|
GetMovement()->CalcTargetPos(60 + rand() % 200);
|
|
return;
|
|
}
|
|
}
|
|
agent_->Exec();
|
|
}
|
|
|
|
void Android::GiveEquip()
|
|
{
|
|
const mt::Equip* weapon_meta = mt::Equip::GetById(robot_meta->weapon_id());
|
|
if (weapon_meta) {
|
|
Weapon& weapon = weapons[GUN_SLOT1];
|
|
weapon.weapon_idx = GUN_SLOT1;
|
|
weapon.weapon_id = weapon_meta->id();
|
|
weapon.ammo = 0;
|
|
weapon.meta = weapon_meta;
|
|
weapon.Recalc();
|
|
SetCurrWeapon(&weapon);
|
|
}
|
|
sex = robot_meta->sex();
|
|
if (sex == 0) {
|
|
sex = rand() % 3;
|
|
}
|
|
}
|
|
|
|
void Android::RandSkin()
|
|
{
|
|
#if 0
|
|
if (!robot_meta->_skin_id.empty()) {
|
|
Skin& skin = skins[0];
|
|
skin.skin_id = 1 + (robot_meta->id() % 3);
|
|
skin.skin_lv = 1;
|
|
}
|
|
#endif
|
|
}
|