重构shot

This commit is contained in:
aozhiwei 2019-07-11 09:43:44 +08:00
parent 721fa5ffd5
commit ab1a404ede
5 changed files with 6 additions and 65 deletions

View File

@ -129,7 +129,7 @@ void AndroidAI::DoAttack()
shot_dir.Normalize();
shot_dir.Rotate((rand() % 10) / 180.0f);
sender->attack_dir = shot_dir;
sender->Shot(shot_dir);
sender->Shot();
}
}
}

View File

@ -188,7 +188,7 @@ void Human::FillMFTeamData(cs::MFTeamData* team_data)
team_data->set_downed(downed);
}
void Human::Shot(a8::Vec2& target_dir)
void Human::Shot()
{
if (!curr_weapon->meta) {
return;
@ -203,9 +203,6 @@ void Human::Shot(a8::Vec2& target_dir)
CancelAction();
}
#if 1
float fly_distance = 5;
#endif
for (auto& tuple : curr_weapon->meta->bullet_born_offset) {
a8::Vec2 bullet_born_offset = a8::Vec2(std::get<0>(tuple), std::get<1>(tuple));
bullet_born_offset.Rotate(attack_dir.CalcAngle(a8::Vec2::UP));
@ -232,7 +229,9 @@ void Human::Shot(a8::Vec2& target_dir)
}
bullet_dir.Rotate(bullet_angle / 180.0f);
room->frame_event.AddBullet(this, bullet_born_pos, attack_dir, fly_distance);
room->CreateBullet(this, curr_weapon, bullet_born_pos, attack_dir, fly_distance);
if (room->BattleStarted()) {
room->CreateBullet(this, curr_weapon, bullet_born_pos, bullet_dir, fly_distance);
}
}
--curr_weapon->ammo;
if (curr_weapon->ammo <= 0) {

View File

@ -136,7 +136,7 @@ class Human : public Entity
virtual void FillMFPlayerStats(cs::MFPlayerStats* stats);
virtual void GetAabbBox(AabbCollider& aabb_box);
void FillMFTeamData(cs::MFTeamData* team_data);
void Shot(a8::Vec2& target_dir);
void Shot();
void RecalcSelfCollider();
bool IsCollision();
bool IsCollisionInMapService();

View File

@ -247,63 +247,6 @@ void Player::UpdateUseSkill()
DoSkill();
}
void Player::Shot()
{
if (!curr_weapon->meta) {
return;
}
if (curr_weapon->ammo <= 0) {
AutoLoadingBullet();
return;
}
if (action_type == AT_Reload) {
CancelAction();
}
if (true) {
for (auto& tuple : curr_weapon->meta->bullet_born_offset) {
a8::Vec2 bullet_born_offset = a8::Vec2(std::get<0>(tuple), std::get<1>(tuple));
bullet_born_offset.Rotate(attack_dir.CalcAngle(a8::Vec2::UP));
a8::Vec2 bullet_born_pos = pos + bullet_born_offset;
if (room->OverBorder(bullet_born_pos, 0)) {
return;
}
}
room->frame_event.AddShot(this);
for (auto& tuple : curr_weapon->meta->bullet_born_offset) {
a8::Vec2 bullet_born_offset = a8::Vec2(std::get<0>(tuple), std::get<1>(tuple));
bullet_born_offset.Rotate(attack_dir.CalcAngle(a8::Vec2::UP));
a8::Vec2 bullet_born_pos = pos + bullet_born_offset;
a8::Vec2 bullet_dir = attack_dir;
float bullet_angle = std::get<2>(tuple);
if (curr_weapon->meta->i->bullet_angle() >= 0.01f) {
int angle = (int)curr_weapon->meta->i->bullet_angle() * 1000;
if (curr_weapon->upgrade_meta) {
angle -= curr_weapon->upgrade_meta->GetAttrValue(curr_weapon->weapon_lv, EA_BulletAngle) * 1000;
}
if (angle > 0) {
bullet_angle += (rand() % angle) / 1000.0f * (rand() % 2 == 0 ? 1 : -1);
}
}
bullet_dir.Rotate(bullet_angle / 180.0f);
room->frame_event.AddBullet(this, bullet_born_pos, bullet_dir, fly_distance);
if (room->BattleStarted()) {
room->CreateBullet(this, curr_weapon, bullet_born_pos, bullet_dir, fly_distance);
}
}
} else {
return;
}
--curr_weapon->ammo;
if (curr_weapon->ammo <= 0) {
AutoLoadingBullet();
}
last_shot_frameno_ = room->frame_no;
need_sync_active_player = true;
}
void Player::ProcInteraction()
{
for (auto obj_id : interaction_objids) {

View File

@ -69,7 +69,6 @@ class Player : public Human
void UpdateSpectate();
void UpdateEmote();
void UpdateUseSkill();
void Shot();
void ProcInteraction();
void ObstacleInteraction(Obstacle* entity);
void LootInteraction(Loot* entity);