1
This commit is contained in:
parent
f032cedb82
commit
67e48dd9a0
@ -37,13 +37,17 @@ behaviac::EBTStatus AndroidAgent::DoIdle(int min_time, int max_time)
|
|||||||
&GetOwner()->xtimer_attacher.timer_list_);
|
&GetOwner()->xtimer_attacher.timer_list_);
|
||||||
std::weak_ptr<a8::XTimerPtr> timer_ptr = GetOwner()->room->xtimer.GetTimerPtr(timer);
|
std::weak_ptr<a8::XTimerPtr> timer_ptr = GetOwner()->room->xtimer.GetTimerPtr(timer);
|
||||||
|
|
||||||
|
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 = GetOwner()->GetTrigger()->AddListener
|
std::weak_ptr<EventHandlerPtr> handler = GetOwner()->GetTrigger()->AddListener
|
||||||
(
|
(
|
||||||
kAttacked,
|
kAttacked,
|
||||||
[this] (const std::vector<std::any>& args)
|
[this, last_attacker, last_attacked_frameno] (const std::vector<std::any>& args)
|
||||||
{
|
{
|
||||||
Creature* c = std::any_cast<Creature*>(args.at(0));
|
Creature* c = std::any_cast<Creature*>(args.at(0));
|
||||||
FireEvent("OnAttacked", c->GetUniId(), c->room->GetFrameNo());
|
*last_attacker = c->GetWeakPtrRef();
|
||||||
|
*last_attacked_frameno = c->room->GetFrameNo();
|
||||||
|
//FireEvent("OnAttacked", c->GetUniId(), c->room->GetFrameNo());
|
||||||
});
|
});
|
||||||
|
|
||||||
return StartCoroutine
|
return StartCoroutine
|
||||||
@ -58,6 +62,10 @@ behaviac::EBTStatus AndroidAgent::DoIdle(int min_time, int max_time)
|
|||||||
}
|
}
|
||||||
return behaviac::BT_SUCCESS;
|
return behaviac::BT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
[this, last_attacker, last_attacked_frameno] (bool& has_event)
|
||||||
|
{
|
||||||
|
|
||||||
},
|
},
|
||||||
"CoIdle"
|
"CoIdle"
|
||||||
);
|
);
|
||||||
@ -100,6 +108,10 @@ behaviac::EBTStatus AndroidAgent::DoRandomWalk()
|
|||||||
} else {
|
} else {
|
||||||
return behaviac::BT_RUNNING;
|
return behaviac::BT_RUNNING;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
[this] (bool& has_event)
|
||||||
|
{
|
||||||
|
|
||||||
},
|
},
|
||||||
"CoRandomWalk"
|
"CoRandomWalk"
|
||||||
);
|
);
|
||||||
@ -146,6 +158,10 @@ behaviac::EBTStatus AndroidAgent::DoRandomShot()
|
|||||||
|
|
||||||
return behaviac::BT_RUNNING;
|
return behaviac::BT_RUNNING;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
[this] (bool& has_event)
|
||||||
|
{
|
||||||
|
|
||||||
},
|
},
|
||||||
"CoRandomShot"
|
"CoRandomShot"
|
||||||
);
|
);
|
||||||
@ -184,6 +200,10 @@ behaviac::EBTStatus AndroidAgent::DoAttack()
|
|||||||
|
|
||||||
return behaviac::BT_RUNNING;
|
return behaviac::BT_RUNNING;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
[this] (bool& has_event)
|
||||||
|
{
|
||||||
|
|
||||||
},
|
},
|
||||||
"CoAttack"
|
"CoAttack"
|
||||||
);
|
);
|
||||||
@ -246,6 +266,10 @@ behaviac::EBTStatus AndroidAgent::DoPursuit()
|
|||||||
}
|
}
|
||||||
return behaviac::BT_RUNNING;
|
return behaviac::BT_RUNNING;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
[this] (bool& has_event)
|
||||||
|
{
|
||||||
|
|
||||||
},
|
},
|
||||||
"CoPursuit"
|
"CoPursuit"
|
||||||
);
|
);
|
||||||
|
@ -62,6 +62,7 @@ behaviac::EBTStatus BaseAgent::DoRunningCb()
|
|||||||
}
|
}
|
||||||
|
|
||||||
behaviac::EBTStatus BaseAgent::StartCoroutine(std::function<behaviac::EBTStatus()> cb,
|
behaviac::EBTStatus BaseAgent::StartCoroutine(std::function<behaviac::EBTStatus()> cb,
|
||||||
|
std::function<void(bool&)> event_cb,
|
||||||
const char* name)
|
const char* name)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -70,6 +71,7 @@ behaviac::EBTStatus BaseAgent::StartCoroutine(std::function<behaviac::EBTStatus(
|
|||||||
status_name_ = name;
|
status_name_ = name;
|
||||||
#endif
|
#endif
|
||||||
runing_cb_ = std::move(cb);
|
runing_cb_ = std::move(cb);
|
||||||
|
event_cb_ = std::move(event_cb);
|
||||||
status_ = behaviac::BT_RUNNING;
|
status_ = behaviac::BT_RUNNING;
|
||||||
return status_;
|
return status_;
|
||||||
}
|
}
|
||||||
@ -133,6 +135,10 @@ behaviac::EBTStatus BaseAgent::CoAttackTarget(int target_id)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return behaviac::BT_RUNNING;
|
return behaviac::BT_RUNNING;
|
||||||
|
},
|
||||||
|
[this] (bool& has_event)
|
||||||
|
{
|
||||||
|
|
||||||
},
|
},
|
||||||
"CoAttackTarget"
|
"CoAttackTarget"
|
||||||
);
|
);
|
||||||
|
@ -27,6 +27,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
behaviac::EBTStatus DoRunningCb();
|
behaviac::EBTStatus DoRunningCb();
|
||||||
behaviac::EBTStatus StartCoroutine(std::function<behaviac::EBTStatus()> cb,
|
behaviac::EBTStatus StartCoroutine(std::function<behaviac::EBTStatus()> cb,
|
||||||
|
std::function<void(bool&)> event_cb,
|
||||||
const char* name);
|
const char* name);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -37,7 +38,7 @@ protected:
|
|||||||
#endif
|
#endif
|
||||||
behaviac::EBTStatus status_= behaviac::BT_SUCCESS;
|
behaviac::EBTStatus status_= behaviac::BT_SUCCESS;
|
||||||
std::function<behaviac::EBTStatus()> runing_cb_;
|
std::function<behaviac::EBTStatus()> runing_cb_;
|
||||||
std::function<bool(bool&)> event_cb_;
|
std::function<void(bool&)> event_cb_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Creature* owner_ = nullptr;
|
Creature* owner_ = nullptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user