aozhiwei 8b477e257d 1
2023-12-28 11:52:07 +08:00

218 lines
5.4 KiB
C++

#include "precompile.h"
#include "android.h"
#include "room.h"
#include "app.h"
#include "android_agent.h"
#include "movement.h"
#include "netdata.h"
#include "car.h"
#include "f8/btmgr.h"
#include "mt/Equip.h"
#include "mt/Robot.h"
#include "mt/Text.h"
#include "mt/Hero.h"
#include "mt/Item.h"
Android::Android():Human()
{
#if 0
++PerfMonitor::Instance()->entity_num[ET_Android];
#endif
agent_ = behaviac::Agent::Create<AndroidAgent>();
if (!agent_) {
abort();
}
}
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;
}
{
std::vector<int> skill_list;
GetBattleContext()->GetSkillList(skill_list);
for (auto& skill_id : skill_list) {
AddSkill(skill_id);
}
}
agent_->SetOwner(this);
f8::BtMgr::Instance()->BtLoad(agent_, "hero/standard");
f8::BtMgr::Instance()->BtSetCurrent(agent_, "hero/standard");
}
void Android::Update(int delta_time)
{
if (UpdatedTimes() <= 0) {
if (room->GetFrameNo() % 2 != 0) {
return;
}
}
#ifdef MYDEBUG
if (!dead &&
room->debug_params.find(119) != room->debug_params.end()) {
BeKill(VP_Gas,
TEXT("battle_server_killer_gas", "毒圈"),
VW_Gas,
VP_Gas,
TEXT("battle_server_killer_gas", "毒圈"));
a8::UnSetBitFlag(status, CS_Disable);
}
#endif
InternalUpdate(delta_time);
shot_hold = false;
CheckShotHold();
++updated_times_;
}
void Android::InternalUpdate(int delta_time)
{
if (a8::HasBitFlag(status, CS_Disable)) {
return;
}
if (poisoning) {
poisoning_time += delta_time;
UpdatePoisoning();
}
if (action_type != AT_None) {
UpdateAction();
}
if (HasBuffEffect(kBET_Fly)) {
App::Instance()->verify_set_pos = 1;
GetMutablePos().FromGlmVec3(room->plane.curr_pos);
App::Instance()->verify_set_pos = 0;
room->grid_service->MoveCreature(this);
return;
}
if (GetMovement()->GetPathSize() > 0 ||
HasBuffEffect(kBET_Sprint)) {
UpdateMoving();
} 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;
}
}
if (playing_skill) {
UpdateSkill();
}
#ifdef MYDEBUG
if (!room->stop_world) {
agent_->Exec();
}
#else
agent_->Exec();
#endif
}
void Android::GiveEquip()
{
const mt::Item* item_meta = mt::Item::GetById(meta->default_weapon());
if (item_meta) {
const mt::Equip* weapon_meta = mt::Equip::GetById(item_meta->relationship());
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
}
void Android::UpdateMoving()
{
if (GetCar()) {
GetCar()->SetAttackDir(GetAttackDir());
if (GetCar()->HasBuffEffect(kBET_Vertigo)) {
return;
}
if (!GetCar()->HasOil()) {
return;
}
}
if (HasBuffEffect(kBET_Passenger)) {
return;
}
Position old_pos = GetPos();
App::Instance()->verify_set_pos = 1;
UpdateMove();
#ifdef MYDEBUG1
a8::XPrintf("updatemove old_pos:%f,%f new_pos:%f,%f\n",
{
old_pos.x,
old_pos.y,
GetPos().x,
GetPos().y,
});
#endif
App::Instance()->verify_set_pos = 0;
if (GetCar() && GetCar()->IsDriver(this)) {
if (!GetCar()->HasBuffEffect(kBET_Sprint)) {
GetCar()->SyncPos();
float dec_oil = old_pos.Distance2D2(GetPos()) * GetCar()->meta->average_oil() / 100;
GetCar()->DecOil(dec_oil);
room->frame_event.AddPropChg(GetCar()->GetWeakPtrRef(),
kPropCarOil,
GetCar()->GetCurOil(),
GetCar()->GetMaxOil());
}
}
}