mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-02-21 02:20:00 +01:00
performance optimize
This commit is contained in:
parent
02521589cf
commit
6ba6bc3615
@ -48,7 +48,7 @@ void PlayerbotAIBase::IncreaseNextCheckDelay(uint32 delay)
|
|||||||
|
|
||||||
bool PlayerbotAIBase::CanUpdateAI()
|
bool PlayerbotAIBase::CanUpdateAI()
|
||||||
{
|
{
|
||||||
return nextAICheckDelay < 100;
|
return nextAICheckDelay == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerbotAIBase::YieldThread(bool delay)
|
void PlayerbotAIBase::YieldThread(bool delay)
|
||||||
|
|||||||
@ -633,7 +633,7 @@ void Engine::LogAction(char const* format, ...)
|
|||||||
if (testMode)
|
if (testMode)
|
||||||
{
|
{
|
||||||
FILE* file = fopen("test.log", "a");
|
FILE* file = fopen("test.log", "a");
|
||||||
fprintf(file, "'{}'", buf);
|
fprintf(file, "'%s'", buf);
|
||||||
fprintf(file, "\n");
|
fprintf(file, "\n");
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,31 +22,37 @@ class GenericBossHelper : public AiObject {
|
|||||||
public:
|
public:
|
||||||
GenericBossHelper(PlayerbotAI* botAI, std::string name): AiObject(botAI), name_(name) {}
|
GenericBossHelper(PlayerbotAI* botAI, std::string name): AiObject(botAI), name_(name) {}
|
||||||
virtual bool UpdateBossAI() {
|
virtual bool UpdateBossAI() {
|
||||||
Unit* unit = AI_VALUE2(Unit*, "find target", name_);
|
if(unit_ && !unit_->IsInWorld()) {
|
||||||
if (!unit) {
|
unit_ = nullptr;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
target_ = unit->ToCreature();
|
if (!unit_) {
|
||||||
if (!target_) {
|
unit_ = AI_VALUE2(Unit*, "find target", name_);
|
||||||
return false;
|
if (!unit_) {
|
||||||
}
|
return false;
|
||||||
ai_ = dynamic_cast<BossAiType *>(target_->GetAI());
|
}
|
||||||
if (!ai_) {
|
target_ = unit_->ToCreature();
|
||||||
return false;
|
if (!target_) {
|
||||||
}
|
return false;
|
||||||
event_map_ = &ai_->events;
|
}
|
||||||
if (!event_map_) {
|
ai_ = dynamic_cast<BossAiType *>(target_->GetAI());
|
||||||
return false;
|
if (!ai_) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
event_map_ = &ai_->events;
|
||||||
|
if (!event_map_) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
timer_ = event_map_->GetTimer();
|
timer_ = event_map_->GetTimer();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
Creature* target_;
|
Unit* unit_ = nullptr;
|
||||||
std::string name_;
|
Creature* target_ = nullptr;
|
||||||
BossAiType *ai_;
|
std::string name_ = nullptr;
|
||||||
EventMap* event_map_;
|
BossAiType *ai_ = nullptr;
|
||||||
uint32 timer_;
|
EventMap* event_map_ = nullptr;
|
||||||
|
uint32 timer_ = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class KelthuzadBossHelper: public GenericBossHelper<boss_kelthuzad::boss_kelthuzadAI> {
|
class KelthuzadBossHelper: public GenericBossHelper<boss_kelthuzad::boss_kelthuzadAI> {
|
||||||
|
|||||||
@ -16,7 +16,7 @@ class Unit;
|
|||||||
class AttackersValue : public ObjectGuidListCalculatedValue
|
class AttackersValue : public ObjectGuidListCalculatedValue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AttackersValue(PlayerbotAI* botAI) : ObjectGuidListCalculatedValue(botAI, "attackers", 1) { }
|
AttackersValue(PlayerbotAI* botAI) : ObjectGuidListCalculatedValue(botAI, "attackers", 2) { }
|
||||||
|
|
||||||
GuidVector Calculate();
|
GuidVector Calculate();
|
||||||
static bool IsPossibleTarget(Unit* attacker, Player* bot, float range = sPlayerbotAIConfig->sightDistance);
|
static bool IsPossibleTarget(Unit* attacker, Player* bot, float range = sPlayerbotAIConfig->sightDistance);
|
||||||
|
|||||||
@ -18,7 +18,9 @@ class FindLeastHpTargetStrategy : public FindTargetStrategy
|
|||||||
if (guid && attacker->GetGUID() == guid)
|
if (guid && attacker->GetGUID() == guid)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!attacker->IsAlive()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!result || result->GetHealth() > attacker->GetHealth())
|
if (!result || result->GetHealth() > attacker->GetHealth())
|
||||||
result = attacker;
|
result = attacker;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -81,6 +81,7 @@ bool PartyMemberToHeal::Check(Unit* player)
|
|||||||
|
|
||||||
Unit* PartyMemberToProtect::Calculate()
|
Unit* PartyMemberToProtect::Calculate()
|
||||||
{
|
{
|
||||||
|
return nullptr;
|
||||||
Group* group = bot->GetGroup();
|
Group* group = bot->GetGroup();
|
||||||
if (!group)
|
if (!group)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|||||||
@ -38,7 +38,7 @@ class PartyMemberValue : public UnitCalculatedValue
|
|||||||
class PartyMemberMainTankValue : public PartyMemberValue
|
class PartyMemberMainTankValue : public PartyMemberValue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PartyMemberMainTankValue(PlayerbotAI* botAI) : PartyMemberValue(botAI) {}
|
PartyMemberMainTankValue(PlayerbotAI* botAI) : PartyMemberValue(botAI, "main tank member", 2) {}
|
||||||
virtual Unit* Calculate();
|
virtual Unit* Calculate();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "TargetValue.h"
|
#include "TargetValue.h"
|
||||||
#include "LastMovementValue.h"
|
#include "LastMovementValue.h"
|
||||||
|
#include "ObjectGuid.h"
|
||||||
#include "RtiTargetValue.h"
|
#include "RtiTargetValue.h"
|
||||||
#include "Playerbots.h"
|
#include "Playerbots.h"
|
||||||
#include "ScriptedCreature.h"
|
#include "ScriptedCreature.h"
|
||||||
@ -117,31 +118,24 @@ WorldPosition HomeBindValue::Calculate()
|
|||||||
Unit* FindTargetValue::Calculate()
|
Unit* FindTargetValue::Calculate()
|
||||||
{
|
{
|
||||||
if (qualifier == "") {
|
if (qualifier == "") {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
Group* group = bot->GetGroup();
|
Group* group = bot->GetGroup();
|
||||||
if (!group) {
|
if (!group) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
for (GroupReference *gref = group->GetFirstMember(); gref; gref = gref->next()) {
|
HostileReference *ref = bot->getHostileRefMgr().getFirst();
|
||||||
Player* member = gref->GetSource();
|
while (ref)
|
||||||
if (!member) {
|
{
|
||||||
continue;
|
ThreatMgr *threatManager = ref->GetSource();
|
||||||
}
|
Unit *unit = threatManager->GetOwner();
|
||||||
HostileReference *ref = member->getHostileRefMgr().getFirst();
|
std::wstring wnamepart;
|
||||||
while (ref)
|
Utf8toWStr(unit->GetName(), wnamepart);
|
||||||
{
|
wstrToLower(wnamepart);
|
||||||
ThreatMgr *threatManager = ref->GetSource();
|
if (!qualifier.empty() && qualifier.length() == wnamepart.length() && Utf8FitTo(qualifier, wnamepart)) {
|
||||||
Unit *unit = threatManager->GetOwner();
|
return unit;
|
||||||
std::wstring wnamepart;
|
|
||||||
Utf8toWStr(unit->GetName(), wnamepart);
|
|
||||||
wstrToLower(wnamepart);
|
|
||||||
if (!qualifier.empty() && qualifier.length() == wnamepart.length() && Utf8FitTo(qualifier, wnamepart)) {
|
|
||||||
return unit;
|
|
||||||
}
|
|
||||||
assert(ref);
|
|
||||||
ref = ref->next();
|
|
||||||
}
|
}
|
||||||
|
ref = ref->next();
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,7 +41,7 @@ class FindNonCcTargetStrategy : public FindTargetStrategy
|
|||||||
class TargetValue : public UnitCalculatedValue
|
class TargetValue : public UnitCalculatedValue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TargetValue(PlayerbotAI* botAI, std::string const name = "target") : UnitCalculatedValue(botAI, name) { }
|
TargetValue(PlayerbotAI* botAI, std::string const name = "target", int checkInterval = 1) : UnitCalculatedValue(botAI, name, checkInterval) { }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Unit* FindTarget(FindTargetStrategy* strategy);
|
Unit* FindTarget(FindTargetStrategy* strategy);
|
||||||
@ -101,7 +101,7 @@ class PullTargetValue : public ManualSetValue<ObjectGuid>
|
|||||||
class FindTargetValue : public UnitCalculatedValue, public Qualified
|
class FindTargetValue : public UnitCalculatedValue, public Qualified
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FindTargetValue(PlayerbotAI* ai) : UnitCalculatedValue(ai) {}
|
FindTargetValue(PlayerbotAI* ai) : UnitCalculatedValue(ai, "find target", 2) {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Unit* Calculate();
|
Unit* Calculate();
|
||||||
@ -117,7 +117,7 @@ class FindBossTargetStrategy : public FindTargetStrategy
|
|||||||
class BossTargetValue : public TargetValue, public Qualified
|
class BossTargetValue : public TargetValue, public Qualified
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BossTargetValue(PlayerbotAI* ai) : TargetValue(ai) {}
|
BossTargetValue(PlayerbotAI* ai) : TargetValue(ai, "boss target", 1) {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Unit* Calculate();
|
Unit* Calculate();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user