Port fixes until b4094bf - flying, mount animations, bot attack range, free food option

This commit is contained in:
郑佩茹
2022-03-22 17:13:10 -06:00
parent 44600080ec
commit f1bcca1a7b
25 changed files with 224 additions and 32 deletions

View File

@@ -15,6 +15,14 @@ bool AcceptDuelAction::Execute(Event event)
ObjectGuid playerGuid;
p >> playerGuid;
// do not auto duel with low hp
if ((!botAI->HasRealPlayerMaster() || (botAI->GetMaster() && botAI->GetMaster()->GetGUID() != playerGuid)) && AI_VALUE2(uint8, "health", "self target") < 90)
{
WorldPacket packet(CMSG_DUEL_CANCELLED, 8);
packet << flagGuid;
bot->GetSession()->HandleDuelCancelledOpcode(packet);
}
WorldPacket packet(CMSG_DUEL_ACCEPTED, 8);
packet << flagGuid;
bot->GetSession()->HandleDuelAcceptedOpcode(packet);

View File

@@ -219,6 +219,7 @@ class ActionContext : public NamedObjectContext<Action>
creators["rpg craft"] = &ActionContext::rpg_craft;
creators["rpg trade useful"] = &ActionContext::rpg_trade_useful;
creators["rpg duel"] = &ActionContext::rpg_duel;
creators["rpg mount anim"] = &ActionContext::rpg_mount_anim;
}
private:
@@ -377,6 +378,7 @@ class ActionContext : public NamedObjectContext<Action>
static Action* rpg_craft(PlayerbotAI* botAI) { return new RpgCraftAction(botAI); }
static Action* rpg_trade_useful(PlayerbotAI* botAI) { return new RpgTradeUsefulAction(botAI); }
static Action* rpg_duel(PlayerbotAI* botAI) { return new RpgDuelAction(botAI); }
static Action* rpg_mount_anim(PlayerbotAI* botAI) { return new RpgMountAnimAction(botAI); }
};
#endif

View File

@@ -692,7 +692,7 @@ bool BGLeaveAction::Execute(Event event)
uint16 unk = 0x1F90;
uint8 unk2 = 0x0;
bool isArena = false;
bool IsRandomBot = sRandomPlayerbotMgr->IsRandomBot(bot->GetGUID().GetCounter());
bool IsRandomBot = sRandomPlayerbotMgr->IsRandomBot(bot);
ArenaType arenaType = ArenaType(BattlegroundMgr::BGArenaType(queueTypeId));
if (arenaType)
@@ -801,7 +801,7 @@ bool BGStatusAction::Execute(Event event)
break;
}
bool IsRandomBot = sRandomPlayerbotMgr->IsRandomBot(bot->GetGUID().GetCounter());
bool IsRandomBot = sRandomPlayerbotMgr->IsRandomBot(bot);
BattlegroundQueueTypeId queueTypeId = bot->GetBattlegroundQueueTypeId(QueueSlot);
BattlegroundTypeId _bgTypeId = BattlegroundMgr::BGTemplateId(queueTypeId);
if (!queueTypeId)

View File

@@ -72,7 +72,28 @@ Unit* GiveFoodAction::GetTarget()
return AI_VALUE(Unit*, "party member without food");
}
bool GiveFoodAction::isUseful()
{
if (!GetTarget())
return false;
bool isRandomBot = GetTarget()->IsPlayer() && sRandomPlayerbotMgr->IsRandomBot((Player*) GetTarget());
return !isRandomBot || (isRandomBot && !sPlayerbotAIConfig->freeFood);
}
Unit* GiveWaterAction::GetTarget()
{
return AI_VALUE(Unit*, "party member without water");
}
bool GiveWaterAction::isUseful()
{
if (!GetTarget())
return false;
bool isRandomBot = GetTarget()->IsPlayer() && sRandomPlayerbotMgr->IsRandomBot((Player*)GetTarget());
return !isRandomBot || (isRandomBot && !sPlayerbotAIConfig->freeFood);
}

View File

@@ -27,7 +27,8 @@ class GiveFoodAction : public GiveItemAction
public:
GiveFoodAction(PlayerbotAI* botAI) : GiveItemAction(botAI, "give food", "conjured food") { }
Unit* GetTarget() override;
bool isUseful() override;
Unit* GetTarget() override;
};
class GiveWaterAction : public GiveItemAction
@@ -35,7 +36,8 @@ class GiveWaterAction : public GiveItemAction
public:
GiveWaterAction(PlayerbotAI* botAI) : GiveItemAction(botAI, "give water", "conjured water") { }
Unit* GetTarget() override;
bool isUseful() override;
Unit* GetTarget() override;
};
#endif

View File

@@ -11,6 +11,44 @@ bool DrinkAction::Execute(Event event)
if (bot->IsInCombat())
return false;
bool hasMana = AI_VALUE2(bool, "has mana", "self target");
if (!hasMana)
return false;
if (sPlayerbotAIConfig->freeFood)
{
if (bot->IsNonMeleeSpellCast(true))
return false;
bot->ClearUnitState(UNIT_STATE_CHASE);
bot->ClearUnitState(UNIT_STATE_FOLLOW);
if (bot->isMoving())
{
bot->StopMoving();
botAI->SetNextCheckDelay(sPlayerbotAIConfig->globalCoolDown);
return false;
}
bot->AddUnitState(UNIT_STAND_STATE_SIT);
botAI->InterruptSpell();
//float hp = bot->GetHealthPercent();
float mp = bot->GetPowerPct(POWER_MANA);
float p = mp;
float delay;
if (!bot->InBattleground())
delay = 27000.0f * (100 - p) / 100.0f;
else
delay = 20000.0f * (100 - p) / 100.0f;
botAI->CastSpell(24707, bot);
botAI->SetNextCheckDelay(delay);
return true;
}
return UseItemAction::Execute(event);
}
@@ -19,11 +57,50 @@ bool DrinkAction::isUseful()
return UseItemAction::isUseful() && AI_VALUE2(uint8, "mana", "self target") < 85;
}
bool DrinkAction::isPossible()
{
return sPlayerbotAIConfig->freeFood || UseItemAction::isPossible();
}
bool EatAction::Execute(Event event)
{
if (bot->IsInCombat())
return false;
if (sPlayerbotAIConfig->freeFood)
{
if (bot->IsNonMeleeSpellCast(true))
return false;
bot->ClearUnitState(UNIT_STATE_CHASE);
bot->ClearUnitState(UNIT_STATE_FOLLOW);
if (bot->isMoving())
{
bot->StopMoving();
botAI->SetNextCheckDelay(sPlayerbotAIConfig->globalCoolDown);
return false;
}
bot->AddUnitState(UNIT_STAND_STATE_SIT);
botAI->InterruptSpell();
float hp = bot->GetHealthPct();
//float mp = bot->HasMana() ? bot->GetPowerPercent() : 0.f;
float p = hp;
float delay;
if (!bot->InBattleground())
delay = 27000.0f * (100 - p) / 100.0f;
else
delay = 20000.0f * (100 - p) / 100.0f;
botAI->CastSpell(24707, bot);
botAI->SetNextCheckDelay(delay);
return true;
}
return UseItemAction::Execute(event);
}
@@ -31,3 +108,8 @@ bool EatAction::isUseful()
{
return UseItemAction::isUseful() && AI_VALUE2(uint8, "health", "self target") < sPlayerbotAIConfig->lowHealth;
}
bool EatAction::isPossible()
{
return sPlayerbotAIConfig->freeFood || UseItemAction::isPossible();
}

View File

@@ -16,6 +16,7 @@ class DrinkAction : public UseItemAction
bool Execute(Event event) override;
bool isUseful() override;
bool isPossible() override;
};
class EatAction : public UseItemAction
@@ -25,6 +26,7 @@ class EatAction : public UseItemAction
bool Execute(Event event) override;
bool isUseful() override;
bool isPossible() override;
};
#endif

View File

@@ -26,7 +26,7 @@ bool ReachTargetAction::Execute(Event event)
bool inLos = bot->IsWithinLOSInMap(target);
bool isFriend = bot->IsFriendlyTo(target);
float chaseDist = inLos ? distance : isFriend ? distance / 2 : distance;
return ChaseTo(target, chaseDist + combatReach, bot->GetAngle(target));
return ChaseTo(target, chaseDist - sPlayerbotAIConfig->contactDistance, bot->GetAngle(target));
}
}

View File

@@ -470,10 +470,6 @@ bool RpgDuelAction::isUseful()
return false;
}
// Less spammy duels
if (bot->getLevel() == 1)
return false;
return true;
}
@@ -488,3 +484,17 @@ bool RpgDuelAction::Execute(Event event)
return botAI->DoSpecificAction("cast custom spell", Event("rpg action", chat->FormatWorldobject(player) + " 7266"), true);
}
bool RpgMountAnimAction::isUseful()
{
return AI_VALUE2(bool, "mounted", "self target") && !AI_VALUE2(bool, "moving", "self target");
}
bool RpgMountAnimAction::Execute(Event event)
{
WorldPacket p;
bot->GetSession()->HandleMountSpecialAnimOpcode(p);
return true;
}

View File

@@ -255,4 +255,13 @@ class RpgDuelAction : public RpgSubAction
bool Execute(Event event) override;
};
class RpgMountAnimAction : public RpgSubAction
{
public:
RpgMountAnimAction(PlayerbotAI* botAI, std::string const name = "rpg mount anim") : RpgSubAction(botAI, name) {}
bool isUseful() override;
bool Execute(Event event) override;
};
#endif

View File

@@ -14,7 +14,7 @@ bool StayActionBase::Stay()
//if (!urand(0, 10))
//botAI->PlaySound(TEXT_EMOTE_YAWN);
if (bot->GetMotionMaster()->GetCurrentMovementGeneratorType() == FLIGHT_MOTION_TYPE || bot->IsFlying())
if (bot->GetMotionMaster()->GetCurrentMovementGeneratorType() == FLIGHT_MOTION_TYPE)
return false;
uint32 sitDelay = sPlayerbotAIConfig->sitDelay / 1000;