diff --git a/server/gameserver/android.ai.cc b/server/gameserver/android.ai.cc index 03333124..0a6d3f66 100644 --- a/server/gameserver/android.ai.cc +++ b/server/gameserver/android.ai.cc @@ -144,7 +144,7 @@ void AndroidNewAI::ChangeToStateOldAI(AndroidState_e to_state) move_dir.Rotate(a8::RandAngle()); move_dir.Normalize(); hum->SetMoveDir(move_dir); - hum->attack_dir = hum->GetMoveDir(); + hum->SetAttackDir(hum->GetMoveDir()); } break; default: @@ -208,7 +208,7 @@ void AndroidNewAI::DoAttackOldAI() std::abs(shot_dir.y) > FLT_EPSILON) { shot_dir.Normalize(); shot_dir.Rotate((rand() % 10) / 180.0f); - sender->attack_dir = shot_dir; + sender->SetAttackDir(shot_dir); bool shot_ok = false; sender->Shot(shot_dir, shot_ok, DEFAULT_FLY_DISTANCE); } @@ -226,7 +226,7 @@ void AndroidNewAI::UpdateNewBieNpc() move_dir.Normalize(); hum->SetMoveDir(move_dir); } - hum->attack_dir = hum->GetMoveDir(); + hum->SetAttackDir(hum->GetMoveDir()); if (hum->GetCurrWeapon()->weapon_idx != 0) { hum->GetCurrWeapon()->ammo = MetaMgr::Instance()->newbie_first_robot_ammo; } @@ -244,7 +244,7 @@ void AndroidNewAI::UpdateNewBieNpc() std::abs(shot_dir.y) > FLT_EPSILON) { shot_dir.Normalize(); shot_dir.Rotate((rand() % 10) / 180.0f); - sender->attack_dir = shot_dir; + sender->SetAttackDir(shot_dir); bool shot_ok = false; sender->Shot(shot_dir, shot_ok, DEFAULT_FLY_DISTANCE); } @@ -262,7 +262,7 @@ void AndroidNewAI::UpdateLastNpc() move_dir.Normalize(); hum->SetMoveDir(move_dir); } - hum->attack_dir = hum->GetMoveDir(); + hum->SetAttackDir(hum->GetMoveDir()); if (hum->GetCurrWeapon()->weapon_idx != 0) { hum->GetCurrWeapon()->ammo = MetaMgr::Instance()->newbie_first_robot_ammo * 2; } @@ -286,7 +286,7 @@ void AndroidNewAI::UpdateLastNpc() std::abs(shot_dir.y) > FLT_EPSILON) { shot_dir.Normalize(); shot_dir.Rotate((rand() % 10) / 180.0f); - sender->attack_dir = shot_dir; + sender->SetAttackDir(shot_dir); bool shot_ok = false; sender->Shot(shot_dir, shot_ok, DEFAULT_FLY_DISTANCE); } @@ -385,7 +385,7 @@ void AndroidNewAI::UpdateNewBieRoomLogic() a8::Vec2 move_dir = target->GetPos() - hum->GetPos(); move_dir.Normalize(); hum->SetMoveDir(move_dir); - hum->attack_dir = hum->GetMoveDir(); + hum->SetAttackDir(hum->GetMoveDir()); speed *= 0.7; for (int i = 0; i < speed; ++i) { hum->SetPos(hum->GetPos() + hum->GetMoveDir()); @@ -401,7 +401,7 @@ void AndroidNewAI::UpdateNewBieRoomLogic() std::abs(shot_dir.y) > FLT_EPSILON) { shot_dir.Normalize(); shot_dir.Rotate((rand() % 10) / 180.0f); - sender->attack_dir = shot_dir; + sender->SetAttackDir(shot_dir); bool shot_ok = false; sender->Shot(shot_dir, shot_ok, DEFAULT_FLY_DISTANCE); } @@ -678,7 +678,7 @@ void AndroidNewAI::ChangeToStateNewAI(AndroidStateEx_e to_state) move_dir.Rotate(a8::RandAngle()); move_dir.Normalize(); hum->SetMoveDir(move_dir); - hum->attack_dir = hum->GetMoveDir(); + hum->SetAttackDir(hum->GetMoveDir()); if (node_.param1 <= 1) { moving_ = false; } @@ -691,7 +691,7 @@ void AndroidNewAI::ChangeToStateNewAI(AndroidStateEx_e to_state) a8::Vec2 move_dir = node_.target.Get()->GetPos() - hum->GetPos(); move_dir.Normalize(); hum->SetMoveDir(move_dir); - hum->attack_dir = hum->GetMoveDir(); + hum->SetAttackDir(hum->GetMoveDir()); } } break; @@ -755,11 +755,11 @@ void AndroidNewAI::DoShotNewAI() } bool shot_ok = false; - a8::Vec2 shot_dir = myself->attack_dir; + a8::Vec2 shot_dir = myself->GetAttackDir(); if (node_.total_shot_times >= node_.next_total_shot_times) { shot_dir = node_.target.Get()->GetPos() - myself->GetPos(); node_.next_total_shot_times += 7 + (rand() % 6); - myself->attack_dir = shot_dir; + myself->SetAttackDir(shot_dir); } if (std::abs(shot_dir.x) > FLT_EPSILON || std::abs(shot_dir.y) > FLT_EPSILON) { @@ -773,10 +773,10 @@ void AndroidNewAI::DoShotNewAI() shot_dir.Rotate(shot_offset_angle / -180.0f); } } - a8::Vec2 old_attack_dir = myself->attack_dir; - myself->attack_dir = shot_dir; + a8::Vec2 old_attack_dir = myself->GetAttackDir(); + myself->SetAttackDir(shot_dir); myself->Shot(shot_dir, shot_ok, DEFAULT_FLY_DISTANCE); - myself->attack_dir = old_attack_dir; + myself->SetAttackDir(old_attack_dir); if (shot_ok) { if (node_.shot_times <= 0) { node_.start_shot_frameno = myself->room->GetFrameNo(); diff --git a/server/gameserver/creature.cc b/server/gameserver/creature.cc index d7c2f7cf..009263f1 100644 --- a/server/gameserver/creature.cc +++ b/server/gameserver/creature.cc @@ -36,7 +36,7 @@ void InternalShot(Creature* c, } for (auto& tuple : weapon_meta->bullet_born_offset) { a8::Vec2 bullet_born_offset = a8::Vec2(std::get<0>(tuple), std::get<1>(tuple)); - bullet_born_offset.Rotate(c->attack_dir.CalcAngle(a8::Vec2::UP)); + bullet_born_offset.Rotate(c->GetAttackDir().CalcAngle(a8::Vec2::UP)); a8::Vec2 bullet_born_pos = c->GetPos() + bullet_born_offset; if (c->room->OverBorder(bullet_born_pos, 0.0f)) { return; @@ -47,9 +47,9 @@ void InternalShot(Creature* c, } for (auto& tuple : weapon_meta->bullet_born_offset) { a8::Vec2 bullet_born_offset = a8::Vec2(std::get<0>(tuple), std::get<1>(tuple)); - bullet_born_offset.Rotate(c->attack_dir.CalcAngle(a8::Vec2::UP)); + bullet_born_offset.Rotate(c->GetAttackDir().CalcAngle(a8::Vec2::UP)); a8::Vec2 bullet_born_pos = c->GetPos() + c->shoot_offset + bullet_born_offset; - a8::Vec2 bullet_dir = c->attack_dir; + a8::Vec2 bullet_dir = c->GetAttackDir(); float bullet_angle = std::get<2>(tuple); if (weapon_meta->i->bullet_angle() >= 0.10f) { int angle = (int)weapon_meta->i->bullet_angle() * 1000; @@ -80,7 +80,7 @@ void InternalShot(Creature* c, if (weapon_meta->i->recoil_force() > 0.000001) { a8::Vec2 old_move_dir = c->GetMoveDir(); c->MustBeAddBuff(c, kRecoilBuffId); - c->SetMoveDir(c->attack_dir * -1); + c->SetMoveDir(c->GetAttackDir() * -1); c->_UpdateMove(weapon_meta->i->recoil_force()); c->SetMoveDir(old_move_dir); } @@ -630,9 +630,10 @@ void Creature::ProcSkillPhase(MetaData::SkillPhase* phase) std::abs(skill_dir_.y) > FLT_EPSILON) { float target_distance = 5; if (bullet_meta && target_distance > 0.00001f) { - a8::Vec2 old_attack_dir = attack_dir; - attack_dir = skill_dir_; + a8::Vec2 old_attack_dir = GetAttackDir(); + a8::Vec2 attack_dir = skill_dir_; attack_dir.Normalize(); + SetAttackDir(attack_dir); InternalShot ( this, @@ -643,7 +644,7 @@ void Creature::ProcSkillPhase(MetaData::SkillPhase* phase) CurrentSkill() ? CurrentSkill()->meta->i->skill_id() : 0, target_distance, false); - attack_dir = old_attack_dir; + SetAttackDir(old_attack_dir); } } } else { @@ -651,8 +652,8 @@ void Creature::ProcSkillPhase(MetaData::SkillPhase* phase) if (entity) { float target_distance = entity->GetPos().Distance(GetPos()); if (bullet_meta && target_distance > 0.00001f) { - a8::Vec2 old_attack_dir = attack_dir; - attack_dir = entity->GetPos() - GetPos(); + a8::Vec2 old_attack_dir = GetAttackDir(); + a8::Vec2 attack_dir = entity->GetPos() - GetPos(); attack_dir.Normalize(); InternalShot ( @@ -664,7 +665,7 @@ void Creature::ProcSkillPhase(MetaData::SkillPhase* phase) CurrentSkill() ? CurrentSkill()->meta->i->skill_id() : 0, target_distance, false); - attack_dir = old_attack_dir; + SetAttackDir(old_attack_dir); } } } diff --git a/server/gameserver/creature.h b/server/gameserver/creature.h index 79fba122..c44abbae 100644 --- a/server/gameserver/creature.h +++ b/server/gameserver/creature.h @@ -42,7 +42,6 @@ class Creature : public MoveableEntity bool aiming = false; std::list aiming_buffs; long long aiming_frameno = 0; - a8::Vec2 attack_dir; a8::Vec2 shoot_offset; HumanAbility ability; a8::Vec2 target_pos; diff --git a/server/gameserver/hero.ai.cc b/server/gameserver/hero.ai.cc index bbb5d56c..a27a415b 100644 --- a/server/gameserver/hero.ai.cc +++ b/server/gameserver/hero.ai.cc @@ -309,7 +309,7 @@ void HeroAI::ChangeToStateAI(HeroState_e to_state) move_dir.Rotate(a8::RandAngle()); move_dir.Normalize(); hero->SetMoveDir(move_dir); - hero->attack_dir = hero->GetMoveDir(); + hero->SetAttackDir(hero->GetMoveDir()); if (node_.param1 <= 1) { moving_ = false; } @@ -322,7 +322,7 @@ void HeroAI::ChangeToStateAI(HeroState_e to_state) a8::Vec2 move_dir = node_.target.Get()->GetPos() - hero->GetPos(); move_dir.Normalize(); hero->SetMoveDir(move_dir); - hero->attack_dir = hero->GetMoveDir(); + hero->SetAttackDir(hero->GetMoveDir()); } } break; @@ -337,7 +337,7 @@ void HeroAI::ChangeToStateAI(HeroState_e to_state) a8::Vec2 move_dir = target_pos - hero->GetPos(); move_dir.Normalize(); hero->SetMoveDir(move_dir); - hero->attack_dir = hero->GetMoveDir(); + hero->SetAttackDir(hero->GetMoveDir()); node_.target_pos = target_pos; } } @@ -402,11 +402,11 @@ void HeroAI::DoShotAI() } bool shot_ok = false; - a8::Vec2 shot_dir = myself->attack_dir; + a8::Vec2 shot_dir = myself->GetAttackDir(); if (node_.total_shot_times >= node_.next_total_shot_times) { shot_dir = node_.target.Get()->GetPos() - myself->GetPos(); node_.next_total_shot_times += 7 + (rand() % 6); - myself->attack_dir = shot_dir; + myself->SetAttackDir(shot_dir); } if (std::abs(shot_dir.x) > FLT_EPSILON || std::abs(shot_dir.y) > FLT_EPSILON) { @@ -420,10 +420,10 @@ void HeroAI::DoShotAI() shot_dir.Rotate(shot_offset_angle / -180.0f); } } - a8::Vec2 old_attack_dir = myself->attack_dir; - myself->attack_dir = shot_dir; + a8::Vec2 old_attack_dir = myself->GetAttackDir(); + myself->SetAttackDir(shot_dir); myself->Shot(shot_dir, shot_ok, DEFAULT_FLY_DISTANCE); - myself->attack_dir = old_attack_dir; + myself->SetAttackDir(old_attack_dir); if (shot_ok) { if (node_.shot_times <= 0) { node_.start_shot_frameno = myself->room->GetFrameNo(); diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index 464d3ce1..e9fa5021 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -121,7 +121,7 @@ void Human::FillMFObjectPart(Room* room, Human* hum, cs::MFObjectPart* part_data p->set_obj_uniid(GetEntityUniId()); p->set_speed(GetSpeed() * SERVER_FRAME_RATE); TypeConvert::ToPb(GetPos(), p->mutable_pos()); - TypeConvert::ToPb(attack_dir, p->mutable_dir()); + TypeConvert::ToPb(GetAttackDir(), p->mutable_dir()); } void Human::FillMFObjectLess(Room* room, Human* hum, cs::MFPlayerFull* full_data) @@ -129,7 +129,7 @@ void Human::FillMFObjectLess(Room* room, Human* hum, cs::MFPlayerFull* full_data cs::MFPlayerFull* p = full_data; p->set_obj_uniid(GetEntityUniId()); TypeConvert::ToPb(GetPos(), p->mutable_pos()); - TypeConvert::ToPb(attack_dir, p->mutable_dir()); + TypeConvert::ToPb(GetAttackDir(), p->mutable_dir()); p->set_health(GetHP()); p->set_max_health(GetMaxHP()); @@ -154,7 +154,7 @@ void Human::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data cs::MFPlayerFull* p = full_data->mutable_union_obj_1(); p->set_obj_uniid(GetEntityUniId()); TypeConvert::ToPb(GetPos(), p->mutable_pos()); - TypeConvert::ToPb(attack_dir, p->mutable_dir()); + TypeConvert::ToPb(GetAttackDir(), p->mutable_dir()); p->set_health(GetHP()); p->set_max_health(GetMaxHP()); @@ -372,7 +372,7 @@ void Human::FillMFTeamData(cs::MFTeamData* team_data, bool is_game_over) team_data->set_player_id(GetEntityUniId()); if (is_game_over || !real_dead || room->GetFrameNo() - GetRealDeadFrameNo(room) < 4) { TypeConvert::ToPb(GetPos(), team_data->mutable_pos()); - TypeConvert::ToPb(attack_dir, team_data->mutable_dir()); + TypeConvert::ToPb(GetAttackDir(), team_data->mutable_dir()); team_data->set_health(GetHP()); team_data->set_max_health(GetMaxHP()); team_data->set_dead(dead); @@ -415,7 +415,7 @@ void Human::FillMFTeamData(cs::MFTeamData* team_data, bool is_game_over) } } -void Human::CarShot(a8::Vec2& target_dir) +void Human::CarShot(const a8::Vec2& target_dir) { if (!second_weapon.meta) { return; diff --git a/server/gameserver/human.h b/server/gameserver/human.h index 6028b8a7..d64096e2 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -154,7 +154,7 @@ class Human : public Creature void FillItemList(::google::protobuf::RepeatedPtrField<::cs::MFPair>* pb_item_list); long long GetRealDeadFrameNo(Room* room); void FillMFTeamData(cs::MFTeamData* team_data, bool is_game_over); - void CarShot(a8::Vec2& target_dir); + void CarShot(const a8::Vec2& target_dir); virtual void RecalcSelfCollider() override; bool IsCollisionInMapService(); void FindPathInMapService(); diff --git a/server/gameserver/moveableentity.h b/server/gameserver/moveableentity.h index 9d67e697..5ac3322e 100644 --- a/server/gameserver/moveableentity.h +++ b/server/gameserver/moveableentity.h @@ -26,10 +26,13 @@ class MoveableEntity : public RoomEntity virtual void SyncAroundPlayers(const char* file, int line, const char* func); virtual const a8::Vec2& GetMoveDir() { return move_dir_; }; virtual void SetMoveDir(const a8::Vec2& move_dir) { move_dir_ = move_dir; }; + virtual const a8::Vec2& GetAttackDir() { return attack_dir_; }; + virtual void SetAttackDir(const a8::Vec2& attack_dir) { attack_dir_ = attack_dir; }; protected: int updated_times_ = 0; a8::Vec2 move_dir_; + a8::Vec2 attack_dir_; private: std::set grid_list_; diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index ed6327fc..14300484 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -192,11 +192,11 @@ void Player::UpdateShot() } if (GetCar() && GetCar()->IsDriver(this)) { bool shot_ok = false; - a8::Vec2 target_dir = attack_dir; - GetCar()->attack_dir = attack_dir; + a8::Vec2 target_dir = GetAttackDir(); + GetCar()->SetAttackDir(GetAttackDir()); GetCar()->Shot(target_dir, shot_ok, fly_distance); if (!moving) { - GetCar()->SetMoveDir(attack_dir); + GetCar()->SetMoveDir(GetAttackDir()); } shot_start = false; return; @@ -424,12 +424,12 @@ void Player::UpdateUseSkill() void Player::Shot() { if (second_weapon.meta) { - CarShot(attack_dir); + CarShot(GetAttackDir()); return; } bool shot_ok = false; - a8::Vec2 target_dir = attack_dir; + a8::Vec2 target_dir = GetAttackDir(); Creature::Shot(target_dir, shot_ok, fly_distance); } @@ -1024,12 +1024,16 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg) std::abs(msg.attack_dir().y()) > 0.00001f ) ){ - TypeConvert::FromPb(attack_dir, &msg.attack_dir()); - attack_dir.Normalize(); + if (!HasBuffEffect(kBET_Vertigo)) { + a8::Vec2 attack_dir; + TypeConvert::FromPb(attack_dir, &msg.attack_dir()); + attack_dir.Normalize(); + SetAttackDir(attack_dir); + } } } else { if (moving) { - attack_dir = GetMoveDir(); + SetAttackDir(GetMoveDir()); } } if (moving) { diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 54953aad..3872d403 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -227,10 +227,11 @@ void Room::AddPlayer(Player* hum) } else { hum->SetPos(hum->born_point->RandPoint()); } - hum->attack_dir = hum->GetPos(); - hum->attack_dir.Normalize(); - hum->attack_dir.Rotate(a8::RandAngle()); - hum->SetMoveDir(hum->attack_dir); + a8::Vec2 attack_dir = hum->GetPos(); + attack_dir.Normalize(); + attack_dir.Rotate(a8::RandAngle()); + hum->SetAttackDir(attack_dir); + hum->SetMoveDir(attack_dir); hum->room = this; hum->join_frameno = GetFrameNo(); @@ -339,10 +340,11 @@ void Room::CreateAndroid(int robot_num) } else { hum->SetPos(hum->born_point->RandPoint()); } - hum->attack_dir = hum->GetPos(); - hum->attack_dir.Normalize(); - hum->attack_dir.Rotate(a8::RandAngle()); - hum->SetMoveDir(hum->attack_dir); + a8::Vec2 attack_dir = hum->GetPos(); + attack_dir.Normalize(); + attack_dir.Rotate(a8::RandAngle()); + hum->SetAttackDir(attack_dir); + hum->SetMoveDir(attack_dir); hum->room = this; hum->Initialize(); AddToEntityHash(hum); @@ -611,7 +613,7 @@ Hero* Room::CreateHero(Creature* master, hero->room = this; hero->SetPos(pos); hero->SetMoveDir(dir); - hero->attack_dir = dir; + hero->SetAttackDir(dir); hero->team_id = team_id; hero->Initialize(); hero->SetAiLevel(7); @@ -1791,7 +1793,7 @@ void Room::ShuaPlane() pair.second->MustBeAddBuff(pair.second, FLY_BUFFID); pair.second->ResetAllSkillCd(); pair.second->SetPos(plane.curr_pos); - pair.second->attack_dir = plane.dir; + pair.second->SetAttackDir(plane.dir); pair.second->SetMoveDir(plane.dir); grid_service->MoveCreature(pair.second); pair.second->AddToNewObjects(pair.second); @@ -3630,7 +3632,7 @@ void Room::FillObjectPositions(Human* hum, cs::SMUpdate& msg) auto p = msg.add_object_positions(); p->set_obj_uniid(pair.second->GetEntityUniId()); TypeConvert::ToPb(pair.second->GetPos(), p->mutable_pos()); - TypeConvert::ToPb(pair.second->attack_dir, p->mutable_dir()); + TypeConvert::ToPb(pair.second->GetAttackDir(), p->mutable_dir()); p->set_race((int)pair.second->GetRace()); } } diff --git a/server/gameserver/zombiemode.ai.cc b/server/gameserver/zombiemode.ai.cc index 63e70209..8d50549e 100644 --- a/server/gameserver/zombiemode.ai.cc +++ b/server/gameserver/zombiemode.ai.cc @@ -351,7 +351,7 @@ void ZombieModeAI::ChangeToState(ZombieState_e to_state) move_dir.Rotate(a8::RandAngle()); move_dir.Normalize(); hum->SetMoveDir(move_dir); - hum->attack_dir = hum->GetMoveDir(); + hum->SetAttackDir(hum->GetMoveDir()); if (node_->param1 <= 1) { node_->moving = false; } @@ -364,7 +364,7 @@ void ZombieModeAI::ChangeToState(ZombieState_e to_state) a8::Vec2 move_dir = node_->target.Get()->GetPos() - hum->GetPos(); move_dir.Normalize(); hum->SetMoveDir(move_dir); - hum->attack_dir = hum->GetMoveDir(); + hum->SetAttackDir(hum->GetMoveDir()); } } break; @@ -437,11 +437,11 @@ void ZombieModeAI::DoShot() } bool shot_ok = false; - a8::Vec2 shot_dir = myself->attack_dir; + a8::Vec2 shot_dir = myself->GetAttackDir(); if (node_->total_shot_times >= node_->next_total_shot_times) { shot_dir = node_->target.Get()->GetPos() - myself->GetPos(); node_->next_total_shot_times += 7 + (rand() % 6); - myself->attack_dir = shot_dir; + myself->SetAttackDir(shot_dir); } if (std::abs(shot_dir.x) > FLT_EPSILON || std::abs(shot_dir.y) > FLT_EPSILON) { @@ -455,10 +455,10 @@ void ZombieModeAI::DoShot() shot_dir.Rotate(shot_offset_angle / -180.0f); } } - a8::Vec2 old_attack_dir = myself->attack_dir; - myself->attack_dir = shot_dir; + a8::Vec2 old_attack_dir = myself->GetAttackDir(); + myself->SetAttackDir(shot_dir); myself->Shot(shot_dir, shot_ok, DEFAULT_FLY_DISTANCE); - myself->attack_dir = old_attack_dir; + myself->SetAttackDir(old_attack_dir); if (shot_ok) { if (node_->shot_times <= 0) { node_->start_shot_frameno = myself->room->GetFrameNo(); diff --git a/third_party/a8engine b/third_party/a8engine index 8b641082..f32b842b 160000 --- a/third_party/a8engine +++ b/third_party/a8engine @@ -1 +1 @@ -Subproject commit 8b6410826da2c0c667abdacadae6d7c00f70300d +Subproject commit f32b842baf3c97def6871a831dd4509842d461ea