void UpdateAI(uint32 diff) override
{
if (!UpdateVictim())
return;
if (me->HasReactState(REACT_AGGRESSIVE) && !_gateIsOpen && !IsOnSameSide(me, me->GetVictim()))
{
// NBD: this should only happen in practice if there is nobody left alive on our side (we should open gate)
// thus we only do a cursory check to make sure (edge cases?)
if (Player* newTarget = FindEligibleTarget(me, _gateIsOpen))
{
me->getThreatManager().resetAllAggro();
me->AddThreat(newTarget, 1.0f);
AttackStart(newTarget);
}
else
OpenGate();
}
events.Update(diff);
if (!_gateIsOpen && HealthBelowPct(30) && events.IsInPhase(PHASE_TWO))
OpenGate();
while (uint32 eventId = events.ExecuteEvent())
{
switch (eventId)
{
case EVENT_SUMMON:
{
if (RAID_MODE(waves10,waves25).size() <= _waveCount) // bounds check
{
TC_LOG_INFO("scripts", "GothikAI: Wave count %d is out of range for difficulty %d.", _waveCount, GetDifficulty());
break;
}
std::list<Creature*> triggers;
me->GetCreatureListWithEntryInGrid(triggers, NPC_TRIGGER, 150.0f);
for (GothikWaveEntry entry : RAID_MODE(waves10, waves25)[_waveCount].first)
for (uint8 i = 0; i < entry.second; ++i)
{
// GUID layout is as follows:
// CGUID+4: center (back of platform) - primary rider spawn
// CGUID+5: north (back of platform) - primary knight spawn
// CGUID+6: center (front of platform) - second spawn
// CGUID+7: south (front of platform) - primary trainee spawn
uint32 targetDBGuid;
switch (entry.first)
{
case NPC_LIVE_RIDER: // only spawns from center (back) > north
targetDBGuid = (CGUID_TRIGGER + 4) + (i % 2);
break;
case NPC_LIVE_KNIGHT: // spawns north > center (front) > south
targetDBGuid = (CGUID_TRIGGER + 5) + (i % 3);
break;
case NPC_LIVE_TRAINEE: // spawns south > center (front) > north
targetDBGuid = (CGUID_TRIGGER + 7) - (i % 3);
break;
default:
targetDBGuid = 0;
}
for (Creature* trigger : triggers)
if (trigger && trigger->GetSpawnId() == targetDBGuid)
{
DoSummon(entry.first, trigger, 1.0f, 15 * IN_MILLISECONDS, TEMPSUMMON_CORPSE_TIMED_DESPAWN);
break;
}
}
if (uint8 timeToNext = RAID_MODE(waves10, waves25)[_waveCount].second)
events.ScheduleEvent(EVENT_SUMMON, timeToNext * IN_MILLISECONDS, 0, PHASE_ONE);
++_waveCount;
break;
}
case EVENT_DOORS_UNLOCK:
_gateCanOpen = true;
for (ObjectGuid summonGuid : summons)
if (Creature* summon = ObjectAccessor::GetCreature(*me, summonGuid))
if (summon->IsAlive() && (!summon->IsInCombat() || summon->IsInEvadeMode()))
{
OpenGate();
break;
}
break;
case EVENT_PHASE_TWO:
events.SetPhase(PHASE_TWO);
events.ScheduleEvent(EVENT_TELEPORT, 20 * IN_MILLISECONDS, 0, PHASE_TWO);
events.ScheduleEvent(EVENT_HARVEST, 15 * IN_MILLISECONDS, 0, PHASE_TWO);
events.ScheduleEvent(EVENT_RESUME_ATTACK, 2 * IN_MILLISECONDS, 0, PHASE_TWO);
Talk(SAY_PHASE_TWO);
Talk(EMOTE_PHASE_TWO);
me->SetReactState(REACT_PASSIVE);
me->getThreatManager().resetAllAggro();
DoCastAOE(SPELL_TELEPORT_LIVE);
break;
case EVENT_TELEPORT:
if (!HealthBelowPct(30))
{
//.........这里部分代码省略.........
/**
* @note Do not add or change anything in the information returned by this
* method. `getinfo` exists for backwards-compatibility only. It combines
* information from wildly different sources in the program, which is a mess,
* and is thus planned to be deprecated eventually.
*
* Based on the source of the information, new information should be added to:
* - `getblockchaininfo`,
* - `getnetworkinfo` or
* - `getwalletinfo`
*
* Or alternatively, create a specific query method for the information.
**/
UniValue getinfo(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() != 0)
throw std::runtime_error(
"getinfo\n"
"\nDEPRECATED. Returns an object containing various state info.\n"
"\nResult:\n"
"{\n"
" \"deprecation-warning\": \"...\" (string) warning that the getinfo command is deprecated and will be removed in 0.16\n"
" \"version\": xxxxx, (numeric) the server version\n"
" \"protocolversion\": xxxxx, (numeric) the protocol version\n"
" \"walletversion\": xxxxx, (numeric) the wallet version\n"
" \"balance\": xxxxxxx, (numeric) the total bitcoin balance of the wallet\n"
" \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n"
" \"timeoffset\": xxxxx, (numeric) the time offset\n"
" \"connections\": xxxxx, (numeric) the number of connections\n"
" \"proxy\": \"host:port\", (string, optional) the proxy used by the server\n"
" \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
" \"testnet\": true|false, (boolean) if the server is using testnet or not\n"
" \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since Unix epoch) of the oldest pre-generated key in the key pool\n"
" \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated\n"
" \"unlocked_until\": ttt, (numeric) the timestamp in seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is unlocked for transfers, or 0 if the wallet is locked\n"
" \"paytxfee\": x.xxxx, (numeric) the transaction fee set in " + CURRENCY_UNIT + "/kB\n"
" \"relayfee\": x.xxxx, (numeric) minimum relay fee for transactions in " + CURRENCY_UNIT + "/kB\n"
" \"errors\": \"...\" (string) any error messages\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getinfo", "")
+ HelpExampleRpc("getinfo", "")
);
#ifdef ENABLE_WALLET
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
LOCK2(cs_main, pwallet ? &pwallet->cs_wallet : NULL);
#else
LOCK(cs_main);
#endif
proxyType proxy;
GetProxy(NET_IPV4, proxy);
UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("deprecation-warning", "WARNING: getinfo is deprecated and will be fully removed in 0.16."
" Projects should transition to using getblockchaininfo, getnetworkinfo, and getwalletinfo before upgrading to 0.16"));
obj.push_back(Pair("version", CLIENT_VERSION));
obj.push_back(Pair("protocolversion", PROTOCOL_VERSION));
#ifdef ENABLE_WALLET
if (pwallet) {
obj.push_back(Pair("walletversion", pwallet->GetVersion()));
obj.push_back(Pair("balance", ValueFromAmount(pwallet->GetBalance())));
}
#endif
obj.push_back(Pair("blocks", (int)chainActive.Height()));
obj.push_back(Pair("timeoffset", GetTimeOffset()));
if(g_connman)
obj.push_back(Pair("connections", (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL)));
obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() : std::string())));
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
obj.push_back(Pair("testnet", Params().NetworkIDString() == CBaseChainParams::TESTNET));
#ifdef ENABLE_WALLET
if (pwallet) {
obj.push_back(Pair("keypoololdest", pwallet->GetOldestKeyPoolTime()));
obj.push_back(Pair("keypoolsize", (int)pwallet->GetKeyPoolSize()));
}
if (pwallet && pwallet->IsCrypted()) {
obj.push_back(Pair("unlocked_until", pwallet->nRelockTime));
}
obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())));
#endif
obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
return obj;
}
bool CBaseBot::FindEnemy()
{
// check if the health is decreased
bool fHealthDecreased = m_iPrevHealth > GetHealth();
m_iPrevHealth = GetHealth(); // store away the current health value
float cur_dist;
if (m_pEnemy && (!m_pEnemy->IsValid() || !m_pEnemy->IsAlive()))
m_pEnemy = NULL; // null out the enemy pointer as it's no longer valid
Vector vecHisPos;
unsigned char cHit;
// see if we can still see the current enemy...
if (m_pEnemy) {
if (FBoxVisible(m_pEnemy, &vecHisPos, &cHit)) {
m_vecEnemy = vecHisPos;
m_ucVisibility = cHit;
} else {
m_pEnemy = NULL; // we can no longer see this enemy
}
}
// if we already have an enemy...
if (m_pEnemy) {
// don't discard important enemies (bomb/flag/hostage carrier, VIP, etc)
if (g_pServer->ClientIsImportant(EnemyClient()))
return false;
// calculate the distance to the enemy
cur_dist = (m_pEnemy->GetOrigin() - GetOrigin()).Length();
} else {
cur_dist = FLT_MAX; // just some crazy value
}
// loop through all the clients...
for (int i = 0; i < g_pServer->GetMaxClients(); i++) {
if (i == entindex() - 1 || (m_pEnemy && i == m_pEnemy->entindex() - 1))
continue; // skip myself and the current enemy
CClient *pClient = g_pServer->m_rgpClients[i];
if (!pClient || !pClient->IsValid() || !pClient->IsAlive())
continue;
float dist = (pClient->GetOrigin() - GetOrigin()).Length();
// if this enemy is further away than the current one...
if (dist > cur_dist && !g_pServer->ClientIsImportant(pClient))
continue; // skip it
if (dist > 900 + 4000 * ((GetDifficulty() - 1) / 4.0))
continue; // enemy is too far
if (g_pServer->IsTeamplay() && GetTeam() == g_pServer->GetTeam(pClient))
continue; // skip our teammates
float fov;
// if the bot's health decreased or the enemy is shooting
if (!m_pEnemy && (fHealthDecreased || pClient->IsShooting()))
fov = 360;
else
fov = GetFov() * 2 - (GetFov() - (dist > GetFov() * 9 ? GetFov() * 9 : dist) / 9);
// check if enemy is in the view cone
if (!FInViewCone(pClient, fov))
continue; // enemy isn't in bot's view cone
// check if enemy is visible
if (!FBoxVisible(pClient, &vecHisPos, &cHit)) {
continue; // skip this enemy
}
// if the enemy is quite far away, not shooting and the bot is not damaged
if (!m_pEnemy && dist > 200 && !fHealthDecreased && !pClient->IsShooting()) {
// if the bot isn't in the fov of the enemy and the bot doesn't really want to fight
if (!pClient->FInViewCone(this, 120) /*&& BotWantsToRetreat()*/)
continue; // skip this enemy
}
m_pEnemy = pClient; // found a new enemy
m_vecEnemy = vecHisPos;
m_ucVisibility = cHit;
DebugMsg(DEBUG_BOTCOMBAT, "Found new enemy: %s", m_pEnemy->GetNetName());
return true;
}
return false; // no new enemy is found
}
请发表评论