This commit is contained in:
aozhiwei 2019-07-17 13:34:11 +08:00
parent a208be87f5
commit 74509caafb
7 changed files with 48 additions and 28 deletions

View File

@ -235,3 +235,15 @@ void Bullet::PostAttack()
}
}
}
void Bullet::ProcMissible(const a8::XParams& param)
{
Human* sender = (Human*)param.sender.GetUserData();
MetaData::Equip* bullet_meta = MetaMgr::Instance()->GetEquip(param.param1);
if (sender && bullet_meta) {
Human* target = sender->room->GetHumanByUniId(param.param2);
if (target && !target->dead) {
target->DecHP(10, sender->entity_uniid, sender->name, bullet_meta->i->id());
}
}
}

View File

@ -28,6 +28,8 @@ class Bullet : public Entity
virtual void Update(int delta_time) override;
void RecalcSelfCollider();
static void ProcMissible(const a8::XParams& param);
private:
void OnHit(std::set<Entity*>& objects);

View File

@ -59,7 +59,7 @@ void FrameEvent::AddShot(Human* hum)
void FrameEvent::AddBullet(Human* hum, int bullet_id, int bullet_lv,
a8::Vec2 born_pos, a8::Vec2 dir, float fly_distance,
int hit_time, int target_id)
int hit_time, int target_id, int skill_id)
{
{
auto& tuple = a8::FastAppend(bullets_);
@ -73,13 +73,8 @@ void FrameEvent::AddBullet(Human* hum, int bullet_id, int bullet_lv,
TypeConvert::ToPb(born_pos, p.mutable_pos());
TypeConvert::ToPb(dir, p.mutable_dir());
p.set_bulletskin(10001);
#if 1
p.set_gun_id(bullet_id);
p.set_gun_lv(bullet_lv);
#else
p.set_gun_id(hum->curr_weapon->meta->i->id());
p.set_gun_lv(hum->curr_weapon->weapon_lv);
#endif
p.set_fly_distance(fly_distance);
if (hit_time != 0) {
p.set_hit_time(hit_time);
@ -87,6 +82,9 @@ void FrameEvent::AddBullet(Human* hum, int bullet_id, int bullet_lv,
if (target_id != 0) {
p.set_target_id(target_id);
}
if (skill_id != 0) {
p.set_skill_id(skill_id);
}
}
{
int bullet_idx = bullets_.size() - 1;

View File

@ -16,7 +16,7 @@ public:
void AddEmote(Human* hum, int emote_id);
void AddShot(Human* hum);
void AddBullet(Human* hum, int bullet_id, int bullet_lv, a8::Vec2 born_pos, a8::Vec2 dir,
float fly_distance, int hit_time, int target_id = 0);
float fly_distance, int hit_time, int target_id = 0, int skill_id = 0);
void AddExplosion(int item_id, a8::Vec2 bomb_pos, int effect);
void AddSmoke(Bullet* bullet, int item_id, a8::Vec2 pos);
void AddDead(Human* hum);

View File

@ -208,7 +208,16 @@ void Human::Shot()
CancelAction();
}
DirectShot(curr_weapon->meta);
DirectShot(curr_weapon->meta, 0);
if (curr_weapon->meta->i->equip_subtype() == BulletType_Missile) {
room->xtimer.AddDeadLineTimerAndAttach(curr_weapon->meta->i->time() * SERVER_FRAME_RATE,
a8::XParams()
.SetSender(this)
.SetParam1(curr_weapon->meta->i->id())
.SetParam2(shot_target_id),
Bullet::ProcMissible,
&xtimer_attacher.timer_list_);
}
--curr_weapon->ammo;
if (curr_weapon->ammo <= 0) {
AutoLoadingBullet();
@ -217,7 +226,7 @@ void Human::Shot()
need_sync_active_player = true;
}
void Human::DirectShot(MetaData::Equip* bullet_meta)
void Human::DirectShot(MetaData::Equip* bullet_meta, int skill_id)
{
for (auto& tuple : bullet_meta->bullet_born_offset) {
a8::Vec2 bullet_born_offset = a8::Vec2(std::get<0>(tuple), std::get<1>(tuple));
@ -246,14 +255,20 @@ void Human::DirectShot(MetaData::Equip* bullet_meta)
hit_time = bullet_meta->i->time() * 1000;
}
if (bullet_meta->i->equip_subtype() == BulletType_Missile) {
if (skill_id != 0) {
room->frame_event.AddBullet(this, bullet_meta->i->id(),
curr_weapon->weapon_lv, bullet_born_pos, bullet_dir,
fly_distance, hit_time, skill_target_id);
fly_distance, hit_time, skill_target_id, skill_id);
} else {
room->frame_event.AddBullet(this, bullet_meta->i->id(),
curr_weapon->weapon_lv, bullet_born_pos, bullet_dir,
fly_distance, hit_time, shot_target_id);
}
} else {
room->frame_event.AddBullet(this, bullet_meta->i->id(),
curr_weapon->weapon_lv,
bullet_born_pos, bullet_dir,
fly_distance, hit_time);
fly_distance, hit_time, 0, skill_id);
}
if (room->BattleStarted()) {
if (bullet_meta->i->equip_subtype() != BulletType_Missile) {
@ -1946,18 +1961,6 @@ void Human::ProcSkillPhase(MetaData::SkillPhase* phase)
});
}
};
auto missile_trace_func =
[] (const a8::XParams& param)
{
Human* sender = (Human*)param.sender.GetUserData();
MetaData::Equip* bullet_meta = MetaMgr::Instance()->GetEquip(param.param1);
if (sender && bullet_meta) {
Human* target = sender->room->GetHumanByUniId(param.param2);
if (target && !target->dead) {
target->DecHP(10, sender->entity_uniid, sender->name, bullet_meta->i->id());
}
}
};
auto explosion_check_func =
[] (const a8::XParams& param)
{
@ -2001,14 +2004,14 @@ void Human::ProcSkillPhase(MetaData::SkillPhase* phase)
{
MetaData::Equip* bullet_meta = MetaMgr::Instance()->GetEquip(phase->param1.GetInt());
if (bullet_meta) {
DirectShot(bullet_meta);
DirectShot(bullet_meta, skill_meta->i->skill_id());
if (bullet_meta->i->equip_subtype() == BulletType_Missile) {
room->xtimer.AddDeadLineTimerAndAttach(bullet_meta->i->time() * SERVER_FRAME_RATE,
a8::XParams()
.SetSender(this)
.SetParam1(phase->param1.GetInt())
.SetParam2(skill_target_id),
missile_trace_func,
Bullet::ProcMissible,
&xtimer_attacher.timer_list_);
}
}

View File

@ -101,6 +101,7 @@ class Human : public Entity
bool shot_start = false;
bool shot_hold = false;
int shot_target_id = 0;
int series_shot_frames = 0;
float fly_distance = 0.0f;
@ -128,7 +129,7 @@ class Human : public Entity
virtual void GetAabbBox(AabbCollider& aabb_box);
void FillMFTeamData(cs::MFTeamData* team_data);
void Shot();
void DirectShot(MetaData::Equip* bullet_meta);
void DirectShot(MetaData::Equip* bullet_meta, int skill_id);
void RecalcSelfCollider();
bool IsCollision();
bool IsCollisionInMapService();

View File

@ -131,11 +131,13 @@ void Player::UpdateShot()
shot_start = false;
shot_hold = false;
series_shot_frames = 0;
shot_target_id = 0;
return;
}
if (shot_start) {
shot_start = false;
Shot();
shot_target_id = 0;
return;
}
if (shot_hold) {
@ -150,6 +152,7 @@ void Player::UpdateShot()
if (series_shot_frames > 8) {
shot_hold = false;
series_shot_frames = 0;
shot_target_id = 0;
}
}
}
@ -401,6 +404,7 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
}
shot_start = msg.shot_start();
shot_hold = msg.shot_hold();
shot_target_id = msg.shot_target_id();
fly_distance = std::min(200.0f, msg.fly_distance());
if (!shot_hold) {
series_shot_frames = 0;