game2006/server/gameserver/target_agent.cc
aozhiwei d2f6636635 1
2023-10-24 10:42:31 +08:00

112 lines
1.7 KiB
C++

#include "precompile.h"
#include "target_agent.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()->level;
}
void TargetAgent::Abandon(int 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()
{
}
float TargetAgent::GetHPRate()
{
return GetHp() / std::max(1.0f, GetMaxHp());
}