game2006/server/gameserver/select_target.cc
2021-03-19 16:40:57 +08:00

128 lines
4.0 KiB
C++

#include "precompile.h"
#include "creature.h"
#include "metamgr.h"
#include "room.h"
#include "skill.h"
#include "human.h"
void Creature::SelectSkillTargets(Skill* skill, const a8::Vec2& target_pos, std::set<Entity*>& target_list)
{
switch (skill->meta->i->skill_target()) {
case kST_All:
{
TouchAllLayerHumanList
(
[this, skill, &target_pos, &target_list] (Human* hum, bool& stop)
{
if (hum->GetPos().Distance(target_pos) < skill->meta->i->skill_distance()) {
target_list.insert(hum);
}
});
}
break;
case kST_Self:
{
target_list.insert(this);
}
break;
case kST_FriendlyIncludeSelf:
{
target_list.insert(this);
TouchAllLayerHumanList
(
[this, skill, &target_pos, &target_list] (Human* hum, bool& stop)
{
if ((hum == this || hum->team_id == team_id) &&
hum->GetPos().Distance(target_pos) < skill->meta->i->skill_distance()) {
target_list.insert(hum);
}
});
}
break;
case kST_FriendlyExcludeSelf:
{
TouchAllLayerHumanList
(
[this, skill, &target_pos, &target_list] (Human* hum, bool& stop)
{
if ((hum != this && hum->team_id == team_id) &&
hum->GetPos().Distance(target_pos) < skill->meta->i->skill_distance()) {
target_list.insert(hum);
}
});
}
break;
case kST_EnemySingle:
{
#if 0
Entity* entity = room->GetEntityByUniId(skill_target_id_);
if (entity && entity->IsEntityType(ET_Player)) {
Human* hum = (Human*)entity;
if (IsEnemy(hum)) {
target_list.insert(hum);
}
}
#endif
}
break;
case kST_EnemyGroup:
{
TouchAllLayerHumanList
(
[this, skill, &target_pos, &target_list] (Human* hum, bool& stop)
{
if ((hum->team_id != team_id) &&
hum->GetPos().Distance(target_pos) < skill->meta->i->skill_distance()) {
target_list.insert(hum);
}
});
}
break;
case kST_EnemyAndObject:
{
TouchAllLayerHumanList
(
[this, skill, &target_pos, &target_list] (Human* hum, bool& stop)
{
if ((hum->team_id != team_id) &&
hum->GetPos().Distance(target_pos) < skill->meta->i->skill_distance()) {
target_list.insert(hum);
}
});
}
break;
case kST_EnemyAndSelf:
{
#if 0
TouchAllLayerHumanList
(
[this, skill, &target_pos, &target_list] (Human* hum, bool& stop)
{
if ((hum == this || this->IsEnemy(hum)) &&
hum->GetPos().Distance(target_pos) < skill->meta->i->skill_distance()) {
target_list.insert(hum);
}
});
#endif
}
break;
case kST_SingleEnemyAndSelf:
{
Entity* entity = room->GetEntityByUniId(skill_target_id_);
if (entity && entity->IsEntityType(ET_Player)) {
Human* hum = (Human*)entity;
#if 0
if (IsEnemy(hum)) {
target_list.insert(hum);
}
#endif
}
target_list.insert(this);
}
break;
default:
break;
}
}