This commit is contained in:
aozhiwei 2022-09-26 21:53:52 +08:00
parent 85328929c9
commit c78f325412
2 changed files with 21 additions and 4 deletions

View File

@ -105,6 +105,22 @@ static void InternalCreateBullet(BulletInfo& bullet_info)
bullet_info.bullet_born_pos, bullet_info.bullet_born_pos,
bullet_info.bullet_dir, bullet_info.bullet_dir,
bullet_info.fly_distance); bullet_info.fly_distance);
if (bullet_uniid && bullet_info.trace_target_uniid) {
Entity* entity = c->room->GetEntityByUniId(bullet_uniid);
if (entity->GetEntityType() == ET_Bullet) {
Bullet* bullet = (Bullet*)bullet;
Entity* target = c->room->GetEntityByUniId(bullet_info.trace_target_uniid);
if (target->IsCreature(c->room)) {
float finaly_dmg = ((Creature*)target)->GetBattleContext()->CalcDmg((Creature*)target, bullet);
c->AddTraceBullet(
bullet_uniid,
bullet_info.trace_target_uniid,
bullet_info.weapon_meta->i->id(),
finaly_dmg
);
}
}
}
} else { } else {
BulletInfo* info_copy = new BulletInfo(); BulletInfo* info_copy = new BulletInfo();
*info_copy = bullet_info; *info_copy = bullet_info;
@ -3556,7 +3572,7 @@ void Creature::AutoNavigation(a8::Vec2 target_pos, float speed)
} }
void Creature::AddTraceBullet(int bullet_uniid, int target_uniid, float dmg) void Creature::AddTraceBullet(int bullet_uniid, int target_uniid, int gun_id, float dmg)
{ {
trace_bullet_hash_[bullet_uniid] = std::make_tuple(target_uniid, dmg); trace_bullet_hash_[bullet_uniid] = std::make_tuple(target_uniid, gun_id, dmg);
} }

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, float dmg); void AddTraceBullet(int bullet_uniid, int target_uniid, int gun_id, float dmg);
protected: protected:
virtual void OnBuffRemove(Buff& buff); virtual void OnBuffRemove(Buff& buff);
@ -322,7 +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;
std::map<int, std::tuple<int, float>> trace_bullet_hash_; //target_uniid, gun_id, dmg
std::map<int, std::tuple<int, int, float>> trace_bullet_hash_;
private: private:
CreatureWeakPtr weak_ptr_; CreatureWeakPtr weak_ptr_;