This commit is contained in:
aozhiwei 2022-09-27 11:10:19 +08:00
parent f66d2ab72c
commit 9a085fc04f
5 changed files with 53 additions and 42 deletions

View File

@ -50,11 +50,7 @@ void Bullet::Initialize()
void Bullet::Update(int delta_time) void Bullet::Update(int delta_time)
{ {
if (trace_target_id) { if (!trace_target_id) {
ClearBuffList();
room->RemoveObjectLater(this);
later_removed_ = true;
} else {
MapServiceUpdate(); MapServiceUpdate();
++updated_times_; ++updated_times_;
} }
@ -831,3 +827,10 @@ void Bullet::ProcFlyHook(Entity* target)
&sender.Get()->xtimer_attacher.timer_list_ &sender.Get()->xtimer_attacher.timer_list_
); );
} }
void Bullet::ForceRemove()
{
ClearBuffList();
room->RemoveObjectLater(this);
later_removed_ = true;
}

View File

@ -43,13 +43,14 @@ class Bullet : public MoveableEntity
float GetExplosionRange(); float GetExplosionRange();
bool IsCurrWeapon(); bool IsCurrWeapon();
bool IsPreBattleBullet(); bool IsPreBattleBullet();
void ForceRemove();
void OnHit(std::set<Entity*>& objects);
protected: protected:
Bullet(); Bullet();
private: private:
void OnHit(std::set<Entity*>& objects);
void ProcBomb(); void ProcBomb();
void ProcSmokeBomb(); void ProcSmokeBomb();
void ProcFragBomb(int delay_time); void ProcFragBomb(int delay_time);

View File

@ -113,12 +113,10 @@ static void InternalCreateBullet(BulletInfo& bullet_info)
Entity* target = c->room->GetEntityByUniId(bullet_info.trace_target_uniid); Entity* target = c->room->GetEntityByUniId(bullet_info.trace_target_uniid);
if (target->IsCreature(c->room)) { if (target->IsCreature(c->room)) {
bullet->trace_target_id = bullet_info.trace_target_uniid; bullet->trace_target_id = bullet_info.trace_target_uniid;
float finaly_dmg = ((Creature*)target)->GetBattleContext()->CalcDmg((Creature*)target, bullet);
c->AddTraceBullet( c->AddTraceBullet(
bullet_uniid, bullet_uniid,
bullet_info.trace_target_uniid, bullet_info.trace_target_uniid,
bullet_info.weapon_meta->i->id(), bullet_info.weapon_meta->i->id()
finaly_dmg
); );
} }
} }
@ -3574,9 +3572,9 @@ void Creature::AutoNavigation(a8::Vec2 target_pos, float speed)
} }
void Creature::AddTraceBullet(int bullet_uniid, int target_uniid, int gun_id, float dmg) void Creature::AddTraceBullet(int bullet_uniid, int target_uniid, int gun_id)
{ {
trace_bullet_hash_[bullet_uniid] = std::make_tuple(target_uniid, gun_id, dmg); trace_bullet_hash_[bullet_uniid] = std::make_tuple(target_uniid, gun_id);
room->xtimer.AddDeadLineTimerAndAttach room->xtimer.AddDeadLineTimerAndAttach
( (
SERVER_FRAME_RATE * 10, SERVER_FRAME_RATE * 10,
@ -3587,6 +3585,11 @@ void Creature::AddTraceBullet(int bullet_uniid, int target_uniid, int gun_id, fl
{ {
Creature* c = (Creature*)param.sender.GetUserData(); Creature* c = (Creature*)param.sender.GetUserData();
c->trace_bullet_hash_.erase(param.param1); c->trace_bullet_hash_.erase(param.param1);
Entity* entity = c->room->GetEntityByUniId(param.param1);
if (entity && entity->GetEntityType() == ET_Bullet) {
Bullet* bullet = (Bullet*)bullet;
bullet->ForceRemove();
}
}, },
&xtimer_attacher.timer_list_); &xtimer_attacher.timer_list_);
} }

View File

@ -276,7 +276,7 @@ class Creature : public MoveableEntity
float GetAttrRate(int attr_id); float GetAttrRate(int attr_id);
void RecalcDtoAttr(); void RecalcDtoAttr();
void AutoNavigation(a8::Vec2 target_pos, float speed); void AutoNavigation(a8::Vec2 target_pos, float speed);
void AddTraceBullet(int bullet_uniid, int target_uniid, int gun_id, float dmg); void AddTraceBullet(int bullet_uniid, int target_uniid, int gun_id);
protected: protected:
virtual void OnBuffRemove(Buff& buff); virtual void OnBuffRemove(Buff& buff);
@ -322,8 +322,8 @@ protected:
long long last_follow_move_frameno_ = 0; long long last_follow_move_frameno_ = 0;
int follow_target_last_chg_move_dir_times_ = -1; int follow_target_last_chg_move_dir_times_ = -1;
xtimer_list* follow_target_timer_ = nullptr; xtimer_list* follow_target_timer_ = nullptr;
//target_uniid, gun_id, dmg //target_uniid, gun_id
std::map<int, std::tuple<int, int, float>> trace_bullet_hash_; std::map<int, std::tuple<int, int>> trace_bullet_hash_;
private: private:
CreatureWeakPtr weak_ptr_; CreatureWeakPtr weak_ptr_;

View File

@ -1116,34 +1116,38 @@ void Player::_CMRequestBulletDmg(f8::MsgHdr& hdr, const cs::CMRequestBulletDmg&
} }
auto& tuple = itr->second; auto& tuple = itr->second;
Entity* entity = room->GetEntityByUniId(std::get<0>(tuple)); Entity* bullet_entity = room->GetEntityByUniId(msg.bullet_uniid());
if (entity && entity->IsCreature(room) && entity != this) { if (bullet_entity && bullet_entity->GetEntityType() == ET_Bullet) {
Creature* c = (Creature*)entity; Bullet* bullet = (Bullet*)bullet_entity;
float dmg = std::get<2>(tuple); Entity* entity = room->GetEntityByUniId(msg.target_uniid());
if (msg.strengthen_wall_uniid()) { if (entity && entity->IsCreature(room) && entity != this && !entity->IsDead(room)) {
dmg *= 2; Creature* c = (Creature*)entity;
} float dmg = c->GetBattleContext()->CalcDmg(c, bullet);
bool shield = false; if (msg.strengthen_wall_uniid()) {
if (dmg > 0.00001f) { dmg *= 2;
if (msg.shield_hit()) {
Buff* hold_shield_buff = c->GetBuffByEffectId(kBET_HoldShield);
if (hold_shield_buff) {
c->shield_hp_ = std::max(0.0f, c->shield_hp_ - dmg);
room->frame_event.AddPropChg(c->GetWeakPtrRef(),
kPropShieldHp,
c->shield_max_hp_,
c->shield_hp_);
if (c->shield_hp_ <= 0) {
c->RemoveBuffByUniId(hold_shield_buff->buff_uniid);
}
shield = true;
}
} }
if (!shield) { bool shield = false;
DecHP(dmg, if (dmg > 0.00001f) {
GetUniId(), if (msg.shield_hit()) {
GetName(), Buff* hold_shield_buff = c->GetBuffByEffectId(kBET_HoldShield);
std::get<1>(tuple)); if (hold_shield_buff) {
c->shield_hp_ = std::max(0.0f, c->shield_hp_ - dmg);
room->frame_event.AddPropChg(c->GetWeakPtrRef(),
kPropShieldHp,
c->shield_max_hp_,
c->shield_hp_);
if (c->shield_hp_ <= 0) {
c->RemoveBuffByUniId(hold_shield_buff->buff_uniid);
}
shield = true;
}
}
if (!shield) {
DecHP(dmg,
GetUniId(),
GetName(),
std::get<1>(tuple));
}
} }
} }
} }
@ -1308,7 +1312,7 @@ void Player::AsyncRequestWatchWar(bool send_rsp_msg)
target->StartRefreshViewTimer(); target->StartRefreshViewTimer();
} else { } else {
respmsg.set_error_code(1); respmsg.set_error_code(1);
respmsg.set_error_msg("无法观战"); respmsg.set_error_msg("no watch war");
hum->SendNotifyMsg(respmsg); hum->SendNotifyMsg(respmsg);
} }
}; };