ai添加机器人

This commit is contained in:
aozhiwei 2019-07-20 17:16:36 +08:00
parent 8eec4e7b55
commit 45445369c0
4 changed files with 59 additions and 13 deletions

View File

@ -132,19 +132,45 @@ void AndroidAI::DoAttack()
!enemy->HasBuffEffect(BET_InGrass)
) {
Human* sender = (Human*)owner;
a8::Vec2 shot_dir = enemy->pos - sender->pos;
if (std::abs(shot_dir.x) > FLT_EPSILON ||
std::abs(shot_dir.y) > FLT_EPSILON) {
shot_dir.Normalize();
shot_dir.Rotate((rand() % 10) / 180.0f);
sender->attack_dir = shot_dir;
if (sender->curr_weapon->meta->NeedTrace()) {
sender->shot_target_id = enemy->entity_uniid;
} else {
sender->shot_target_id = 0;
}
sender->Shot();
if (sender->CanUseSkill()) {
UseSkill(enemy);
} else {
Shot(enemy);
}
}
}
}
void AndroidAI::Shot(Human* enemy)
{
Human* sender = (Human*)owner;
a8::Vec2 shot_dir = enemy->pos - sender->pos;
if (std::abs(shot_dir.x) > FLT_EPSILON ||
std::abs(shot_dir.y) > FLT_EPSILON) {
shot_dir.Normalize();
shot_dir.Rotate((rand() % 10) / 180.0f);
sender->attack_dir = shot_dir;
if (sender->curr_weapon->meta->NeedTrace()) {
sender->shot_target_id = enemy->entity_uniid;
} else {
sender->shot_target_id = 0;
}
sender->Shot();
}
}
void AndroidAI::UseSkill(Human* enemy)
{
Human* sender = (Human*)owner;
a8::Vec2 shot_dir = enemy->pos - sender->pos;
if (std::abs(shot_dir.x) > FLT_EPSILON ||
std::abs(shot_dir.y) > FLT_EPSILON) {
sender->curr_skill_phase = 0;
sender->skill_target_id = enemy->entity_uniid;
sender->skill_dir = shot_dir;
sender->skill_target_pos = enemy->pos;
sender->skill_param1 = 0;
sender->playing_skill = false;
sender->DoSkill();
}
}

View File

@ -27,4 +27,6 @@ private:
void DoMove();
void DoAttack();
void Shot(Human* enemy);
void UseSkill(Human* enemy);
};

View File

@ -541,9 +541,26 @@ bool Human::HasLiveTeammate()
return false;
}
bool Human::CanUseSkill()
{
if (!skill_meta_) {
return false;
}
if (GetSkillLeftTime() > 0) {
return false;
}
if (a8::HasBitFlag(status, HS_Assaulting) ||
HasBuffEffect(BET_Vertigo) ||
HasBuffEffect(BET_Dcgr)
) {
return false;
}
return true;
}
void Human::DoSkill()
{
if (skill_meta_ && GetSkillLeftTime() <= 0 && !a8::HasBitFlag(status, HS_Assaulting)) {
if (CanUseSkill()) {
use_skill = false;
curr_skill_phase = 0;
skill_dir = a8::Vec2();

View File

@ -136,6 +136,7 @@ class Human : public Entity
void AddOutObjects(Entity* entity);
void RemoveOutObjects(Entity* entity);
bool HasLiveTeammate();
bool CanUseSkill();
void DoSkill();
void FindLocation();
void RefreshView();