diff --git a/server/bin/exported/hero_9011.xml b/server/bin/exported/hero_9011.xml
index 4c29b7a8..861f5b04 100644
--- a/server/bin/exported/hero_9011.xml
+++ b/server/bin/exported/hero_9011.xml
@@ -20,7 +20,7 @@
-
+
diff --git a/server/gameserver/creature.h b/server/gameserver/creature.h
index 6964fbaf..7494039f 100644
--- a/server/gameserver/creature.h
+++ b/server/gameserver/creature.h
@@ -226,9 +226,11 @@ class Creature : public MoveableEntity
bool IsAndroid() const;
bool IsHuman() const;
bool IsCar() const;
+ bool IsHero() const { return IsEntityType(ET_Hero); };
Human* AsHuman() { return IsHuman() ? (Human*)this : nullptr; };
Player* AsPlayer() { return IsPlayer() ? (Player*)this : nullptr; };
Car* AsCar() { return IsCar() ? (Car*)this : nullptr; };
+ Hero* AsHero() { return IsHero() ? (Hero*)this : nullptr; };
virtual void DecHP(float dec_hp, int killer_id,
const std::string killer_name, int weapon_id,
int real_killer_id, const std::string real_killer_name,
diff --git a/server/gameserver/hero_agent.cc b/server/gameserver/hero_agent.cc
index efafb382..ecddfbab 100644
--- a/server/gameserver/hero_agent.cc
+++ b/server/gameserver/hero_agent.cc
@@ -1,5 +1,7 @@
#include "precompile.h"
+#include
+
#include "hero_agent.h"
#include "hero.h"
#include "room.h"
@@ -227,11 +229,39 @@ behaviac::EBTStatus HeroAgent::DoAttack()
GetOwner()->Shot(shot_dir, shot_ok, 0, 0);
}
+ std::shared_ptr last_attacker = std::make_shared();
+ std::shared_ptr last_attacked_frameno = std::make_shared(0);
+ std::weak_ptr handler;
+ if (GetOwner()->AsHero()->master.Get()) {
+ handler = GetOwner()->AsHero()->master.Get()->GetTrigger()->AddListener
+ (
+ kBulletHitEvent,
+ [this, last_attacker, last_attacked_frameno] (const a8::Args& args)
+ {
+ Creature* c = args.Get(1);
+ *last_attacker = c->GetWeakPtrRef();
+ *last_attacked_frameno = c->room->GetFrameNo();
+ });
+ }
+ auto holder = std::make_shared
+ (
+ [owner = GetOwner()->GetWeakPtrRef(), handler] (const a8::Args& args) mutable
+ {
+ if (!handler.expired() && owner.Get()) {
+ if (owner.Get()->IsEntityType(ET_Hero)) {
+ Hero* hero = (Hero*)owner.Get();
+ if (hero->master.Get()) {
+ hero->master.Get()->GetTrigger()->RemoveEventHandler(handler);
+ }
+ }
+ }
+ });
+
CreatureWeakPtr target = enemy->GetWeakPtrRef();
long long last_frameno = GetOwner()->room->GetFrameNo();
return StartCoroutine
(
- [this, last_frameno, target] () mutable
+ [this, last_frameno, target, holder] () mutable
{
if (GetOwner()->room->GetFrameNo() - last_frameno > SERVER_FRAME_RATE * 3) {
status_ = behaviac::BT_SUCCESS;
@@ -260,9 +290,12 @@ behaviac::EBTStatus HeroAgent::DoAttack()
return behaviac::BT_RUNNING;
}
},
- [this] (bool is_test, bool& has_event)
+ [this, last_attacker, last_attacked_frameno] (bool is_test, bool& has_event)
{
-
+ has_event = last_attacker->Get() && !last_attacker->Get()->dead ? true : false;
+ if (!is_test && has_event) {
+ FireEvent("OnMasterAttackTarget", last_attacker->Get()->GetUniId());
+ }
},
"CoAttack"
);
diff --git a/server/gameserver/hero_agent.h b/server/gameserver/hero_agent.h
index 38013547..f6189faf 100644
--- a/server/gameserver/hero_agent.h
+++ b/server/gameserver/hero_agent.h
@@ -20,7 +20,4 @@ public:
behaviac::EBTStatus DoAttack();
behaviac::EBTStatus DoPursuit();
behaviac::EBTStatus DoHelpAttack(int target_uniid);
-
-private:
- Hero* owner_ = nullptr;
};