1
This commit is contained in:
parent
060def0715
commit
377a3b5cbc
@ -425,10 +425,8 @@ void AndroidAI::UpdatePursuit()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (node_->exec_frame_num > 100 * 2) {
|
|
||||||
ChangeToStateNewAI(ASE_RandomWalk);
|
ChangeToStateNewAI(ASE_RandomWalk);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AndroidAI::DoMoveNewAI()
|
void AndroidAI::DoMoveNewAI()
|
||||||
|
@ -771,6 +771,10 @@ void Creature::DoSkill(int skill_id,
|
|||||||
float skill_distance,
|
float skill_distance,
|
||||||
const a8::Vec2& target_pos)
|
const a8::Vec2& target_pos)
|
||||||
{
|
{
|
||||||
|
if (HasBuffEffect(kBET_Jump) ||
|
||||||
|
HasBuffEffect(kBET_Fly)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
DoSkillPreProc(skill_id, target_id, target_pos);
|
DoSkillPreProc(skill_id, target_id, target_pos);
|
||||||
Skill* skill = GetSkill(skill_id);
|
Skill* skill = GetSkill(skill_id);
|
||||||
if (skill && CanUseSkill(skill_id)) {
|
if (skill && CanUseSkill(skill_id)) {
|
||||||
@ -963,6 +967,13 @@ Skill* Creature::CurrentSkill()
|
|||||||
return curr_skill_;
|
return curr_skill_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Creature::ActiveAllSkill()
|
||||||
|
{
|
||||||
|
for (auto& pair : skill_hash_) {
|
||||||
|
pair.second->Accelerate(-10000000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Creature::ProcBuffEffect(Creature* caster, Buff* buff)
|
void Creature::ProcBuffEffect(Creature* caster, Buff* buff)
|
||||||
{
|
{
|
||||||
MetaData::Buff* buff_meta = buff->meta;
|
MetaData::Buff* buff_meta = buff->meta;
|
||||||
@ -2077,16 +2088,37 @@ void Creature::SummonHero(Buff* buff,
|
|||||||
MetaData::Player* hero_meta = MetaMgr::Instance()->GetPlayer(hero_id);
|
MetaData::Player* hero_meta = MetaMgr::Instance()->GetPlayer(hero_id);
|
||||||
if (hero_meta) {
|
if (hero_meta) {
|
||||||
for (int j = 0; j < num; ++j) {
|
for (int j = 0; j < num; ++j) {
|
||||||
|
Hero* hero = nullptr;
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
a8::Vec2 born_dir = dir;
|
a8::Vec2 born_dir = dir;
|
||||||
a8::Vec2 born_offset(x, y);
|
a8::Vec2 born_offset(x, y);
|
||||||
born_offset.Rotate(born_dir.CalcAngle(a8::Vec2::UP));
|
born_offset.Rotate(born_dir.CalcAngle(a8::Vec2::UP));
|
||||||
born_offset.Rotate(i * 0.5);
|
born_offset.Rotate(i * 0.5);
|
||||||
a8::Vec2 hero_pos = pos + born_offset;
|
a8::Vec2 hero_pos = pos + born_offset;
|
||||||
Hero* hero = InternalSummonHero(hero_meta,
|
hero = InternalSummonHero(hero_meta,
|
||||||
dir,
|
dir,
|
||||||
hero_pos,
|
hero_pos,
|
||||||
through_wall);
|
through_wall);
|
||||||
|
if (hero) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}//end for i
|
||||||
|
if (!hero) {
|
||||||
|
hero = InternalSummonHero(hero_meta,
|
||||||
|
GetAttackDir(),
|
||||||
|
GetPos(),
|
||||||
|
through_wall);
|
||||||
|
#ifdef DEBUG
|
||||||
|
SendDebugMsg(a8::Format("second summon hero id:%d pos:%f,%f rad:%d ok:%d",
|
||||||
|
{
|
||||||
|
hero_meta->i->id(),
|
||||||
|
GetPos().x,
|
||||||
|
GetPos().y,
|
||||||
|
hero_meta->i->radius(),
|
||||||
|
hero ? 1 : 0
|
||||||
|
}));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
if (hero) {
|
if (hero) {
|
||||||
RemoveSurplusHero(buff->meta->i->buff_id(), hero_id, num);
|
RemoveSurplusHero(buff->meta->i->buff_id(), hero_id, num);
|
||||||
slave_heros_.push_back(std::make_tuple(buff->meta->i->buff_id(), hero));
|
slave_heros_.push_back(std::make_tuple(buff->meta->i->buff_id(), hero));
|
||||||
@ -2102,10 +2134,8 @@ void Creature::SummonHero(Buff* buff,
|
|||||||
{
|
{
|
||||||
|
|
||||||
});
|
});
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}//end for j
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2544,9 +2574,17 @@ void Creature::TraverseBuff(std::function<void (Buff*, bool&)> func)
|
|||||||
|
|
||||||
Hero* Creature::InternalSummonHero(MetaData::Player* hero_meta, a8::Vec2 dir, a8::Vec2 born_pos, bool through_wall)
|
Hero* Creature::InternalSummonHero(MetaData::Player* hero_meta, a8::Vec2 dir, a8::Vec2 born_pos, bool through_wall)
|
||||||
{
|
{
|
||||||
|
#if 1
|
||||||
|
AabbCollider collider;
|
||||||
|
collider._min.x = -hero_meta->i->radius();
|
||||||
|
collider._min.y = -hero_meta->i->radius();
|
||||||
|
collider._max.x = hero_meta->i->radius();
|
||||||
|
collider._max.y = hero_meta->i->radius();
|
||||||
|
collider.MoveCenter(hero_meta->i->move_offset_x(), hero_meta->i->move_offset_y());
|
||||||
|
#else
|
||||||
CircleCollider collider;
|
CircleCollider collider;
|
||||||
collider.pos = born_pos;
|
|
||||||
collider.rad = hero_meta->i->radius();
|
collider.rad = hero_meta->i->radius();
|
||||||
|
#endif
|
||||||
if (!room->map_service->CollisionDetection
|
if (!room->map_service->CollisionDetection
|
||||||
(
|
(
|
||||||
room,
|
room,
|
||||||
@ -2561,6 +2599,14 @@ Hero* Creature::InternalSummonHero(MetaData::Player* hero_meta, a8::Vec2 dir, a8
|
|||||||
dir,
|
dir,
|
||||||
team_id
|
team_id
|
||||||
);
|
);
|
||||||
|
#ifdef DEBUG
|
||||||
|
SendDebugMsg(a8::Format("summon hero id:%d pos:%f,%f",
|
||||||
|
{
|
||||||
|
hero_meta->i->id(),
|
||||||
|
born_pos.x,
|
||||||
|
born_pos.y
|
||||||
|
}));
|
||||||
|
#endif
|
||||||
return hero;
|
return hero;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -135,6 +135,7 @@ class Creature : public MoveableEntity
|
|||||||
);
|
);
|
||||||
void ResetSkill();
|
void ResetSkill();
|
||||||
Skill* CurrentSkill();
|
Skill* CurrentSkill();
|
||||||
|
void ActiveAllSkill();
|
||||||
MetaData::SkillPhase* GetCurrSkillPhase();
|
MetaData::SkillPhase* GetCurrSkillPhase();
|
||||||
bool CanSee(const Creature* c) const;
|
bool CanSee(const Creature* c) const;
|
||||||
virtual std::string GetName() { return "";};
|
virtual std::string GetName() { return "";};
|
||||||
|
@ -169,7 +169,7 @@ void HeroAI::UpdateAttack()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
float distance = myself->GetPos().Distance(node_->target.Get()->GetPos());
|
float distance = myself->GetPos().Distance(node_->target.Get()->GetPos());
|
||||||
if (distance > GetAttackRange()) {
|
if (distance > GetShotRange()) {
|
||||||
if (ai_meta->i->pursuit_radius() <= 0) {
|
if (ai_meta->i->pursuit_radius() <= 0) {
|
||||||
//站桩
|
//站桩
|
||||||
ChangeToStateAI(HSE_Thinking);
|
ChangeToStateAI(HSE_Thinking);
|
||||||
@ -226,16 +226,28 @@ void HeroAI::UpdateRandomWalk()
|
|||||||
void HeroAI::UpdatePursuit()
|
void HeroAI::UpdatePursuit()
|
||||||
{
|
{
|
||||||
Hero* myself = (Hero*)owner;
|
Hero* myself = (Hero*)owner;
|
||||||
|
if (node_->target.Get()) {
|
||||||
float distance = myself->GetPos().Distance(node_->target.Get()->GetPos());
|
float distance = myself->GetPos().Distance(node_->target.Get()->GetPos());
|
||||||
if (!myself->HasBuffEffect(kBET_Jump) &&
|
if (!myself->HasBuffEffect(kBET_Jump) &&
|
||||||
!myself->HasBuffEffect(kBET_PeaceMode) &&
|
!myself->HasBuffEffect(kBET_PeaceMode) &&
|
||||||
distance < GetAttackRange()) {
|
distance < GetShotRange()) {
|
||||||
ChangeToStateAI(HSE_Attack);
|
ChangeToStateAI(HSE_Attack);
|
||||||
} else {
|
} else {
|
||||||
|
if (node_->exec_frame_num % SERVER_FRAME_RATE == 0) {
|
||||||
|
a8::Vec2 move_dir = node_->target.Get()->GetPos() - myself->GetPos();
|
||||||
|
if (distance > 10) {
|
||||||
|
move_dir.Normalize();
|
||||||
|
myself->SetMoveDir(move_dir);
|
||||||
|
myself->SetAttackDir(myself->GetMoveDir());
|
||||||
|
}
|
||||||
|
}
|
||||||
if (node_->exec_frame_num > 100 * 2) {
|
if (node_->exec_frame_num > 100 * 2) {
|
||||||
ChangeToStateAI(HSE_RandomWalk);
|
ChangeToStateAI(HSE_RandomWalk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
ChangeToStateAI(HSE_RandomWalk);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeroAI::UpdateFollowMaster()
|
void HeroAI::UpdateFollowMaster()
|
||||||
@ -428,12 +440,20 @@ Creature* HeroAI::GetTarget()
|
|||||||
float HeroAI::GetAttackRange()
|
float HeroAI::GetAttackRange()
|
||||||
{
|
{
|
||||||
float attack_range = 0;
|
float attack_range = 0;
|
||||||
|
attack_range = std::max(ai_meta->i->attack_range(), 1);
|
||||||
|
return attack_range;
|
||||||
|
}
|
||||||
|
|
||||||
|
float HeroAI::GetShotRange()
|
||||||
|
{
|
||||||
|
float shot_range = 0;
|
||||||
Hero* myself = (Hero*)owner;
|
Hero* myself = (Hero*)owner;
|
||||||
if (myself->GetCurrWeapon() && myself->GetCurrWeapon()->meta) {
|
if (myself->GetCurrWeapon() && myself->GetCurrWeapon()->meta) {
|
||||||
attack_range = myself->GetCurrWeapon()->meta->i->range();
|
shot_range = myself->GetCurrWeapon()->meta->i->range();
|
||||||
|
shot_range += myself->GetCurrWeapon()->meta->i->bullet_rad();
|
||||||
}
|
}
|
||||||
attack_range = std::min(ai_meta->i->attack_range(), (int)attack_range);
|
shot_range = std::max(shot_range - 1, 1.0f);
|
||||||
return attack_range;
|
return shot_range;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeroAI::DoShotAI()
|
void HeroAI::DoShotAI()
|
||||||
@ -442,12 +462,16 @@ void HeroAI::DoShotAI()
|
|||||||
if (!node_->target.Get()) {
|
if (!node_->target.Get()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!myself->GetCurrWeapon()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bool shot_ok = false;
|
bool shot_ok = false;
|
||||||
a8::Vec2 shot_dir = myself->GetAttackDir();
|
a8::Vec2 shot_dir = myself->GetAttackDir();
|
||||||
if (node_->total_shot_times >= node_->next_total_shot_times) {
|
if (node_->total_shot_times >= node_->next_total_shot_times) {
|
||||||
shot_dir = node_->target.Get()->GetPos() - myself->GetPos();
|
shot_dir = node_->target.Get()->GetPos() - myself->GetPos();
|
||||||
node_->next_total_shot_times += 7 + (rand() % 6);
|
node_->next_total_shot_times += 7 + (rand() % 6);
|
||||||
|
shot_dir.Normalize();
|
||||||
myself->SetAttackDir(shot_dir);
|
myself->SetAttackDir(shot_dir);
|
||||||
}
|
}
|
||||||
if (std::abs(shot_dir.x) > FLT_EPSILON ||
|
if (std::abs(shot_dir.x) > FLT_EPSILON ||
|
||||||
@ -554,3 +578,12 @@ RoomObstacle* HeroAI::FindObstacleTarget()
|
|||||||
}
|
}
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HeroAI::ForceRandomWalk(int time, int idle_time)
|
||||||
|
{
|
||||||
|
Hero* myself = (Hero*)owner;
|
||||||
|
ChangeToStateAI(HSE_RandomWalk);
|
||||||
|
node_->param1 = time / FRAME_RATE_MS;
|
||||||
|
node_->next_random_move_frameno = myself->room->GetFrameNo() +
|
||||||
|
idle_time / FRAME_RATE_MS;
|
||||||
|
}
|
||||||
|
@ -46,6 +46,7 @@ public:
|
|||||||
virtual ~HeroAI() override;
|
virtual ~HeroAI() override;
|
||||||
virtual void Update(int delta_time) override;
|
virtual void Update(int delta_time) override;
|
||||||
float GetAttackRate();
|
float GetAttackRate();
|
||||||
|
void ForceRandomWalk(int time, int idle_time);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void UpdateAI();
|
void UpdateAI();
|
||||||
@ -63,6 +64,7 @@ protected:
|
|||||||
Creature* GetTarget();
|
Creature* GetTarget();
|
||||||
RoomObstacle* FindObstacleTarget();
|
RoomObstacle* FindObstacleTarget();
|
||||||
float GetAttackRange();
|
float GetAttackRange();
|
||||||
|
float GetShotRange();
|
||||||
int GetAttackTimes();
|
int GetAttackTimes();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -32,6 +32,8 @@ void Hero::Initialize()
|
|||||||
{
|
{
|
||||||
Creature::Initialize();
|
Creature::Initialize();
|
||||||
RecalcSelfCollider();
|
RecalcSelfCollider();
|
||||||
|
SetHP(meta->i->health());
|
||||||
|
SetMaxHP(GetHP());
|
||||||
MetaData::Equip* weapon_meta = MetaMgr::Instance()->GetEquip(meta->i->default_weapon());
|
MetaData::Equip* weapon_meta = MetaMgr::Instance()->GetEquip(meta->i->default_weapon());
|
||||||
if (weapon_meta) {
|
if (weapon_meta) {
|
||||||
weapons[GUN_SLOT1].weapon_idx = GUN_SLOT1;
|
weapons[GUN_SLOT1].weapon_idx = GUN_SLOT1;
|
||||||
@ -52,7 +54,7 @@ void Hero::FillMFObjectPart(Room* room, Human* hum, cs::MFObjectPart* part_data)
|
|||||||
cs::MFHeroPart* p = part_data->mutable_union_obj_10();
|
cs::MFHeroPart* p = part_data->mutable_union_obj_10();
|
||||||
p->set_obj_uniid(GetUniId());
|
p->set_obj_uniid(GetUniId());
|
||||||
TypeConvert::ToPb(GetPos(), p->mutable_pos());
|
TypeConvert::ToPb(GetPos(), p->mutable_pos());
|
||||||
TypeConvert::ToPb(GetMoveDir(), p->mutable_dir());
|
TypeConvert::ToPb(GetAttackDir(), p->mutable_dir());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hero::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data)
|
void Hero::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data)
|
||||||
@ -61,7 +63,7 @@ void Hero::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data)
|
|||||||
cs::MFHeroFull* p = full_data->mutable_union_obj_10();
|
cs::MFHeroFull* p = full_data->mutable_union_obj_10();
|
||||||
p->set_obj_uniid(GetUniId());
|
p->set_obj_uniid(GetUniId());
|
||||||
TypeConvert::ToPb(GetPos(), p->mutable_pos());
|
TypeConvert::ToPb(GetPos(), p->mutable_pos());
|
||||||
TypeConvert::ToPb(GetMoveDir(), p->mutable_dir());
|
TypeConvert::ToPb(GetAttackDir(), p->mutable_dir());
|
||||||
p->set_heroid(meta->i->id());
|
p->set_heroid(meta->i->id());
|
||||||
p->set_master_uniid(master.Get() ? master.Get()->GetUniId() : 0);
|
p->set_master_uniid(master.Get() ? master.Get()->GetUniId() : 0);
|
||||||
p->set_dead(dead);
|
p->set_dead(dead);
|
||||||
@ -199,6 +201,7 @@ void Hero::GetAabbBox(AabbCollider& aabb_box)
|
|||||||
aabb_box._min.y = -GetRadius();
|
aabb_box._min.y = -GetRadius();
|
||||||
aabb_box._max.x = GetRadius();
|
aabb_box._max.x = GetRadius();
|
||||||
aabb_box._max.y = GetRadius();
|
aabb_box._max.y = GetRadius();
|
||||||
|
aabb_box.MoveCenter(meta->i->move_offset_x(), meta->i->move_offset_y());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hero::GetHitAabbBox(AabbCollider& aabb_box)
|
void Hero::GetHitAabbBox(AabbCollider& aabb_box)
|
||||||
@ -315,4 +318,9 @@ void Hero::InitAI()
|
|||||||
room->xtimer.ModifyTimer(buff->remover_timer, peace_time / FRAME_RATE_MS);
|
room->xtimer.ModifyTimer(buff->remover_timer, peace_time / FRAME_RATE_MS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (ai_meta->i->ai_kind() == kAI_MineSweeper) {
|
||||||
|
int time = 500 + rand() % 1500;
|
||||||
|
int idle_time = 300 + rand() % 300;
|
||||||
|
((HeroAI*)ai)->ForceRandomWalk(time, idle_time);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1815,6 +1815,7 @@ void Room::ShuaPlane()
|
|||||||
pair.second->SetMoveDir(plane.dir);
|
pair.second->SetMoveDir(plane.dir);
|
||||||
grid_service->MoveCreature(pair.second);
|
grid_service->MoveCreature(pair.second);
|
||||||
pair.second->AddToNewObjects(pair.second);
|
pair.second->AddToNewObjects(pair.second);
|
||||||
|
pair.second->ActiveAllSkill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user