123 lines
2.0 KiB
C++
123 lines
2.0 KiB
C++
#include "precompile.h"
|
|
|
|
#include "target_agent.h"
|
|
#include "room.h"
|
|
|
|
#include "mt/Hero.h"
|
|
#include "mt/Equip.h"
|
|
|
|
TargetAgent::TargetAgent():BaseAgent()
|
|
{
|
|
|
|
}
|
|
|
|
TargetAgent::~TargetAgent()
|
|
{
|
|
}
|
|
|
|
int TargetAgent::GetUniId()
|
|
{
|
|
if (target_.Get()) {
|
|
return target_.Get()->GetUniId();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
bool TargetAgent::IsValid()
|
|
{
|
|
return target_.Get() && !target_.Get()->dead && target_.Get()->team_id != owner_->team_id;
|
|
}
|
|
|
|
bool TargetAgent::IsDead()
|
|
{
|
|
if (target_.Get()) {
|
|
return target_.Get()->dead;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
glm::vec3 TargetAgent::GetPos()
|
|
{
|
|
return target_.Get()->GetPos().ToGlmVec3();
|
|
}
|
|
|
|
float TargetAgent::GetHp()
|
|
{
|
|
if (!target_.Get()) {
|
|
abort();
|
|
}
|
|
return target_.Get()->GetHP();
|
|
}
|
|
|
|
float TargetAgent::GetMaxHp()
|
|
{
|
|
if (!target_.Get()) {
|
|
abort();
|
|
}
|
|
return target_.Get()->GetMaxHP();
|
|
}
|
|
|
|
int TargetAgent::GetHeroId()
|
|
{
|
|
if (!target_.Get()) {
|
|
abort();
|
|
}
|
|
return target_.Get()->GetHeroMeta()->id();
|
|
}
|
|
|
|
int TargetAgent::GetLevel()
|
|
{
|
|
if (!target_.Get()) {
|
|
abort();
|
|
}
|
|
return target_.Get()->GetHeroLevel();
|
|
}
|
|
|
|
void TargetAgent::Abandon(int min_time, int max_time)
|
|
{
|
|
int time = a8::RandEx(min_time, max_time);
|
|
if (target_.Get()) {
|
|
owner_->DelIgnoreTarget(target_.Get()->GetUniId());
|
|
owner_->AddIgnoreTarget(target_.Get()->GetUniId(), time);
|
|
}
|
|
target_.Reset();
|
|
}
|
|
|
|
void TargetAgent::SetOwner(Creature* owner)
|
|
{
|
|
owner_ = owner;
|
|
}
|
|
|
|
Room* TargetAgent::GetRoom()
|
|
{
|
|
return owner_->room;
|
|
}
|
|
|
|
float TargetAgent::GetShotRange()
|
|
{
|
|
if (target_.Get() && target_.Get()->GetCurrWeapon()) {
|
|
return target_.Get()->GetCurrWeapon()->meta->range();
|
|
}
|
|
return 0.0f;
|
|
}
|
|
|
|
void TargetAgent::SetTarget(Creature* target)
|
|
{
|
|
target_ = target->GetWeakPtrRef();
|
|
}
|
|
|
|
void TargetAgent::ClearAbandon()
|
|
{
|
|
owner_->ClearIgnoreTarget();
|
|
}
|
|
|
|
float TargetAgent::GetHPRate()
|
|
{
|
|
return GetHp() / std::max(1.0f, GetMaxHp());
|
|
}
|
|
|
|
bool TargetAgent::HasBuffEffect(int effect_id)
|
|
{
|
|
return target_.Get() && target_.Get()->HasBuffEffect(effect_id);
|
|
}
|