1
This commit is contained in:
parent
3a13c07d59
commit
a414d52795
@ -20,7 +20,7 @@
|
||||
<property ReferenceFilename="hero_help_attack" />
|
||||
<property Task="Self.HeroAgent::OnMasterAttackTarget(0)" />
|
||||
<property TriggeredOnce="false" />
|
||||
<property TriggerMode="Transfer" />
|
||||
<property TriggerMode="Return" />
|
||||
</attachment>
|
||||
</node>
|
||||
</node>
|
||||
|
@ -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,
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include <a8/holder.h>
|
||||
|
||||
#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<CreatureWeakPtr> last_attacker = std::make_shared<CreatureWeakPtr>();
|
||||
std::shared_ptr<long long> last_attacked_frameno = std::make_shared<long long>(0);
|
||||
std::weak_ptr<EventHandlerPtr> 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<Creature*>(1);
|
||||
*last_attacker = c->GetWeakPtrRef();
|
||||
*last_attacked_frameno = c->room->GetFrameNo();
|
||||
});
|
||||
}
|
||||
auto holder = std::make_shared<a8::Holder>
|
||||
(
|
||||
[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"
|
||||
);
|
||||
|
@ -20,7 +20,4 @@ public:
|
||||
behaviac::EBTStatus DoAttack();
|
||||
behaviac::EBTStatus DoPursuit();
|
||||
behaviac::EBTStatus DoHelpAttack(int target_uniid);
|
||||
|
||||
private:
|
||||
Hero* owner_ = nullptr;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user