ROAAi.cpp
资源名称:ROA3.40.rar [点击查看]
上传用户:tianheyiqi
上传日期:2010-04-16
资源大小:282k
文件大小:21k
源码类别:
外挂编程
开发平台:
Visual C++
- #include <stdafx.h>
- #include "ROA.h"
- #include "ROAUtils.h"
- AICOMMANDQUEUE::AICOMMANDQUEUE()
- {
- priority = eAiPriMax;
- dwTarget = 0xFFFFFFFF;
- }
- AICOMMANDQUEUE::~AICOMMANDQUEUE()
- {
- }
- BOOL AICOMMANDQUEUE::update(AICOMMAND command)
- {
- // CString strOutput;
- // strOutput.Format("------ Update %s(%X)", utlGetStatusDescription(command.eAction), command.dwTarget);
- // utlLogout(strOutput, eLogInfo, true);
- SetAt(0, command);
- return(true);
- }
- BOOL AICOMMANDQUEUE::cancelAll()
- {
- if(GetSize() <= 0)
- return(false);
- int nSize = GetSize();
- for(int i=0; i<nSize; i++)
- cancel();
- return(TRUE);
- }
- BOOL AICOMMANDQUEUE::cancel()
- {
- CString strOutput;
- if(GetSize() <= 0)
- return(false);
- AICOMMAND command;
- int nIndex;
- command = GetAt(0);
- strOutput.Format("------ Cancel %s(%X)", utlGetStatusDescription(command.eAction), command.dwTarget);
- utlLogout(strOutput, eLogCommon, true);
- nIndex = monsters.FindId(command.dwTarget);
- if(-1 != nIndex)
- {
- monsters[nIndex].bAiIgnore = true;
- } else
- {
- nIndex = items.FindId(command.dwTarget);
- if(-1 != nIndex)
- {
- items[nIndex].bAiIgnore = true;
- }
- }
- finish();
- return(TRUE);
- }
- BOOL AICOMMANDQUEUE::finishAll()
- {
- int nSize = GetSize();
- if(nSize <= 0)
- return(false);
- for(int i=0; i<nSize; i++)
- finish();
- return(true);
- }
- BOOL AICOMMANDQUEUE::finish()
- {
- CString strOutput;
- if(GetSize() <= 0)
- return(false);
- AICOMMAND command;
- command = GetAt(0);
- strOutput.Format("------ Removing %s(%X)", utlGetStatusDescription(command.eAction), command.dwTarget);
- utlLogout(strOutput, eLogInfo, true);
- RemoveAt(0);
- if(0 == GetSize())
- {
- priority = eAiPriMax;
- dwTarget = 0xFFFFFFFF;
- utlChangeGlobalAction(eAiIdle);
- }
- return(true);
- }
- BOOL AICOMMANDQUEUE::extend(AICOMMAND command)
- {
- BOOL bRtn = false;
- CString strOutput;
- if(GetSize() > 0)
- {
- strOutput.Format("------ Extend %s(%X)", utlGetStatusDescription(command.eAction), command.dwTarget);
- utlLogout(strOutput, eLogInfo, true);
- InsertAt(0, command);
- bRtn = true;
- }
- else
- {
- ASSERT(false);
- }
- return(bRtn);
- }
- BOOL AICOMMANDQUEUE::push(AICOMMAND command, AIPRIORITY ePri)
- {
- ASSERT(GetSize() == 0);
- BOOL bRtn = false;
- CString strOutput;
- if(ePri < priority)
- {
- Add(command);
- priority = ePri;
- dwTarget = command.dwTarget;
- bRtn = true;
- strOutput.Format("------ Add %s(%X)", utlGetStatusDescription(command.eAction), command.dwTarget);
- utlLogout(strOutput, eLogInfo, true);
- }
- return(bRtn);
- }
- BOOL AICOMMANDQUEUE::pop(AICOMMAND &command)
- {
- BOOL bFound = false;
- if(GetSize() > 0)
- {
- command = GetAt(0);
- bFound = true;
- }
- return(bFound);
- }
- int doAi()
- {
- //check for status
- AICOMMAND command;
- DWORD dwTarget;
- CString strOutput, strTemp;
- DWORD dwDamage;
- int nMinDist, nDist;
- BOOL bFound = false;
- int i;
- pos pos1, pos2;
- pos_list *poslist = (pos_list*)&route.size;
- DWORD dwDamage1;
- int nMinLevel, nLevel;
- CDWordArray dwTargetArray;
- CDWordArray dwDamageArray;
- // Check for eAiPriItem0
- if(aiQueue.priority <= eAiPriItem0)
- {
- // already in eAiPriItem0, no compare
- goto DONE;
- }
- if(aiGetItemToPickup(eIpGrab, dwTarget))
- {
- // ignore weight
- if(aiQueue.dwTarget != dwTarget)
- {
- aiQueue.finishAll();
- command.eAction = eAiPickup;
- command.ePhase = ePhaseNone;
- command.dwTarget = dwTarget;
- strOutput.Format("------ Prepare to pickup %s", utlFindTargetItem(dwTarget));
- utlLogout(strOutput, eLogCommon, true);
- aiQueue.push(command, eAiPriItem0);
- }
- goto DONE;
- }
- // Check for eAiPriFlee
- /*
- if(aiCheckTeleportCondition())
- {
- BOOL bFound = false;
- for(int i=0; i<inventory.GetSize(); i++)
- {
- if(inventory[i].dwId == 601)
- {
- bFound = true;
- break;
- }
- }
- if(bUseFlywing && bFound)
- {
- aiQueue.finishAll();
- sendUseItem((WORD)inventory[i].dwIndex, dwAccountId);
- }
- else
- {
- if(bFlyUsed)
- {
- aiQueue.finishAll();
- sendTeleport("Random");
- }
- else
- {
- if(bFound)
- {
- aiQueue.finishAll();
- sendUseItem(i, dwAccountId);
- sendTeleport("Random");
- }
- else
- {
- // ....
- }
- }
- }
- goto DONE;
- }
- */
- // Check for eAiPriCounter
- if(aiQueue.priority < eAiPriCounter)
- {
- goto DONE;
- }
- bFound = false;
- dwTarget = 0;
- dwDamage = 0;
- nMinDist = 999;
- if(damages.FindDamageFrom(dwAccountId, dwTargetArray, dwDamageArray))
- {
- // Choose a monster by distance and damage
- for(i=0; i<dwTargetArray.GetSize(); i++)
- {
- nDist = (int)utlDistanceFrom(you.pntTo, monsters[monsters.FindId(dwTargetArray[i])].pntTo);
- dwDamage1 = dwDamageArray[i];
- if(nMinDist - nDist > 2)
- {
- dwTarget = dwTargetArray[i];
- dwDamage = dwDamage1;
- nMinDist = nDist;
- continue;
- }
- if(dwDamage1 > dwDamage)
- {
- dwTarget = dwTargetArray[i];
- dwDamage = dwDamage1;
- nMinDist = nDist;
- continue;
- }
- }
- if(dwTarget != aiQueue.dwTarget)
- {
- aiQueue.finishAll();
- command.eAction = eAiAttack;
- command.ePhase = ePhaseNone;
- command.dwTarget = dwTarget;
- strOutput.Format("------ Prepare to counter-attack %s", utlFindTarget(dwTarget));
- utlLogout(strOutput, eLogCommon, true);
- aiQueue.push(command, eAiPriCounter);
- }
- goto DONE;
- }
- //Aggresive monster
- if(action == eAtkPhaseAttacking)
- {
- // Attacking
- goto DONE;
- }
- // Check for eAiPriRecess
- if(aiQueue.priority < eAiPriRecess)
- {
- goto DONE;
- }
- if(you.bSit && you.wHp < you.wHpMax * 0.6)
- {
- goto DONE;
- }
- if(you.wHp < you.wHpMax * 0.3 && !you.bSit && aiQueue.priority != eAiPriRecess)
- {
- command.eAction = eAiSit;
- command.ePhase = ePhaseNone;
- aiQueue.finishAll();
- aiQueue.push(command, eAiPriRecess);
- goto DONE;
- }
- // Check for eAiPriItem1
- if(aiQueue.priority <= eAiPriItem1)
- {
- goto DONE;
- }
- if(aiGetItemToPickup(eIpGather, dwTarget) && ((double)you.dwWeight / you.dwWeightMax)< 0.48)
- {
- // weight
- if(aiQueue.dwTarget != dwTarget)
- {
- aiQueue.finishAll();
- command.eAction = eAiPickup;
- command.ePhase = ePhaseNone;
- command.dwTarget = dwTarget;
- strOutput.Format("------ Prepare to pickup %s", utlFindTargetItem(dwTarget));
- utlLogout(strOutput, eLogCommon, true);
- aiQueue.push(command, eAiPriItem1);
- }
- goto DONE;
- }
- // Check for eAiPriMonster
- if(aiQueue.priority <= eAiPriMonster)
- {
- goto DONE;
- }
- bFound = false;
- nMinLevel = 0;
- nMinDist = 999;
- nLevel = -1;
- dwTarget = 0;
- for(i=0; i<monsters.GetSize(); i++)
- {
- if(!monsters[i].bClean)
- {
- // no kill steal
- continue;
- }
- if(monsters[i].bAiIgnore)
- {
- // Ignore
- continue;
- }
- nDist = (int)utlDistanceFrom(you.pntTo, monsters[i].pntTo);
- // nLevel = atoi(mapMonsterInfo.FindValue(monsters[i].wType, eMonsterLev));
- if(nMinDist - nDist > 2)
- {
- dwTarget = monsters[i].dwId;
- nMinDist = nDist;
- nMinLevel = nLevel;
- bFound = true;
- continue;
- }
- if(nLevel > nMinLevel)
- {
- dwTarget = monsters[i].dwId;
- nMinDist = nDist;
- nMinLevel = nLevel;
- bFound = true;
- }
- }
- if(bFound)
- {
- if(dwTarget != aiQueue.dwTarget)
- {
- aiQueue.finishAll();
- command.eAction = eAiAttack;
- command.ePhase = ePhaseNone;
- command.dwTarget = dwTarget;
- strOutput.Format("------ Prepare to attack %s", utlFindTarget(dwTarget));
- utlLogout(strOutput, eLogCommon, true);
- aiQueue.push(command, eAiPriMonster);
- }
- goto DONE;
- }
- // Check for eAiPriItem2
- if(aiQueue.priority <= eAiPriItem2)
- {
- goto DONE;
- }
- if(aiGetItemToPickup(eIpPickup, dwTarget) && ((double)you.dwWeight / you.dwWeightMax)< 0.40 )
- {
- // weight
- if(aiQueue.dwTarget != dwTarget)
- {
- aiQueue.finishAll();
- command.eAction = eAiPickup;
- command.ePhase = ePhaseNone;
- command.dwTarget = dwTarget;
- strOutput.Format("------ Prepare to pickup %s", utlFindTargetItem(dwTarget));
- utlLogout(strOutput, eLogCommon, true);
- aiQueue.push(command, eAiPriItem2);
- }
- goto DONE;
- }
- // Random walk
- if(aiQueue.priority <= eAiPriRandom)
- {
- goto DONE;
- }
- bFound = true;
- if( route.size == 0 ||
- route.curPoint > route.size-1 ||
- (you.pntTo.x != route.array[route.curPoint].x ||
- you.pntTo.y != route.array[route.curPoint].y))
- {
- // need recalculate
- // if((you.wHp < you.wHpMax * 0.8 || you.wSp < you.wSpMax * 0.8) && !you.bSit)
- // {
- // // Take a rest while calculating, mmmm....
- // sendSit();
- // }
- pos1.x = (WORD)you.pntTo.x;
- pos1.y = (WORD)you.pntTo.y;
- while(true)
- {
- pos2.x = (int)((double)rand()/RAND_MAX * field.m_szField.cx);
- pos2.y = (int)((double)rand()/RAND_MAX * field.m_szField.cy);
- if(!field.m_byFields[pos2.x + field.m_szField.cx * pos2.y])
- {
- break;
- }
- }
- DWORD session = (*CalcPath_init)(poslist, (char*)field.m_byFields, field.m_szField.cx, field.m_szField.cy,
- &pos2, &pos1, MAX_ROUTE_TIMEOUT);
- bFound = !((*CalcPath_pathStep)(session));
- (*CalcPath_destory)(session);
- route.curPoint = 0;
- }
- if(bFound && route.size > 0)
- {
- route.curPoint += (int)((double)rand()/RAND_MAX *MAX_ROUTE_STEPONCE + MAX_ROUTE_STEPONCE);
- if(route.curPoint > (int)route.size-1)
- route.curPoint = route.size-1;
- command.eAction = eAiMove;
- command.ePhase = ePhaseNone;
- command.dwTarget = 0;
- command.pntMoveTo.x = route.array[route.curPoint].x;
- command.pntMoveTo.y = route.array[route.curPoint].y;
- strOutput.Format("------ Prepare to walk to (%d, %d), step: %d/%d", command.pntMoveTo.x, command.pntMoveTo.y, route.curPoint, route.size-1);
- utlLogout(strOutput, eLogCommon, true);
- aiQueue.push(command, eAiPriRandom);
- if(route.curPoint >= (int)route.size-1)
- route.curPoint = 0;
- goto DONE;
- }
- DONE:
- processCommandQueue();
- return(0);
- }
- int processCommandQueue()
- {
- AICOMMAND command;
- CString strOutput;
- if(!aiQueue.pop(command))
- {
- return(-1);
- }
- switch(command.eAction)
- {
- case eAiAttack:
- aiProcessAttackCommand(&command);
- break;
- case eAiSit:
- aiProcessSitCommand(&command);
- break;
- case eAiStand:
- aiProcessStandCommand(&command);
- break;
- case eAiMove:
- aiProcessMoveCommand(&command);
- break;
- case eAiPickup:
- aiProcessPickupCommand(&command);
- break;
- }
- return(0);
- }
- int aiProcessAttackCommand(AICOMMAND *pCommand)
- {
- POINT pnt;
- int nIndex = monsters.FindId(pCommand->dwTarget);
- CString strOutput;
- AICOMMAND *pNewCommand = NULL;
- static DWORD dwQuiken = GetTickCount();
- MONSTER monster;
- // Check if finish
- if(-1 == nIndex)
- {
- aiQueue.finish();
- goto DONE;
- }
- monster = monsters[nIndex];
- while(true)
- {
- switch(pCommand->ePhase)
- {
- case ePhaseNone:
- if(utlDistanceFrom(monster.pntTo, you.pntTo) > 3)
- {
- // move needed
- if(field.FindNearestPoint(you.pntTo, monster.pntTo, &pnt))
- {
- pNewCommand = new AICOMMAND;
- pNewCommand->eAction = eAiMove;
- pNewCommand->pntMoveTo = pnt;
- pNewCommand->dwTarget = monster.dwId;
- }
- else
- {
- strOutput.Format("%s can not be reached.",
- utlFindTarget(monster.dwId));
- utlLogout(strOutput, eLogError, true);
- aiQueue.cancelAll();
- }
- goto DONE;
- }
- else
- {
- // Proceed
- utlChangeAttackPhase(pCommand, eAtkPhaseEquip);
- }
- break;
- case eAtkPhaseEquip:
- // Change equipment
- utlChangeAttackPhase(pCommand, eAtkPhaseSkillUse);
- break;
- case eAtkPhaseEquipping:
- //
- break;
- case eAtkPhaseSkillUse:
- // Use Skill
- utlChangeAttackPhase(pCommand, eAtkPhaseAttack);
- if(you.wSp > 30 && !you.bTwoHandsQuiken && GetTickCount() > dwQuiken + 300000)
- {
- // sendUseSkill(10, 60, dwAccountId);
- dwQuiken = GetTickCount();
- goto DONE;
- }
- break;
- case eAtkPhaseAttack:
- if(utlDistanceFrom(monster.pntTo, you.pntTo) > 3)
- {
- // Re-move
- utlChangeAttackPhase(pCommand, (AIATTACKPHASE)ePhaseNone);
- }
- else
- {
- // Attack
- nIndex = damages.FindDamage(dwAccountId, pCommand->dwTarget);
- if(-1 != nIndex)
- {
- pCommand->dwLastDamage = damages[nIndex].dwDamage;
- }
- else
- {
- pCommand->dwLastDamage =0;
- }
- pCommand->dwTimeout = GetTickCount() + TIMEOUT_ATTACK;
- utlChangeAttackPhase(pCommand, eAtkPhaseAttacking);
- sendAttack(pCommand->dwTarget, 7);
- goto DONE;
- }
- break;
- case eAtkPhaseAttacking:
- if(utlDistanceFrom(monster.pntTo, you.pntTo) > 3)
- {
- // Re-move
- utlChangeAttackPhase(pCommand, (AIATTACKPHASE)ePhaseNone);
- }
- else
- {
- if(GetTickCount() > pCommand->dwTimeout)
- {
- DWORD intCurDamage = 0;
- nIndex = damages.FindDamage(dwAccountId, pCommand->dwTarget);
- if(-1 != nIndex)
- {
- intCurDamage = damages[nIndex].dwDamage;
- }
- if(intCurDamage == pCommand->dwLastDamage)
- {
- strOutput.Format("%s can not be attacked!",
- utlFindTarget(monster.dwId));
- utlLogout(strOutput, eLogError, true);
- // Can not hurt target
- aiQueue.cancelAll();
- }
- else
- {
- // Keep on attacking
- pCommand->dwLastDamage = intCurDamage;
- pCommand->dwTimeout = GetTickCount() + TIMEOUT_ATTACK;
- utlChangeAttackPhase(pCommand, (AIATTACKPHASE)eAtkPhaseAttacking);
- }
- }
- goto DONE;
- }
- break;
- }
- }
- DONE:
- if(pNewCommand)
- {
- aiQueue.extend(*pNewCommand);
- delete pNewCommand;
- }
- return(0);
- }
- int aiProcessPickupCommand(AICOMMAND *pCommand)
- {
- POINT pnt;
- int nIndex = items.FindId(pCommand->dwTarget);
- CString strOutput;
- AICOMMAND *pNewCommand = NULL;
- ITEM item;
- // Check if finish
- if(-1 == nIndex)
- {
- aiQueue.finishAll();
- goto DONE;
- }
- item = items[nIndex];
- while(true)
- {
- switch(pCommand->ePhase)
- {
- case ePhaseNone:
- if(utlDistanceFrom(item.pntPos, you.pntTo) > 3)
- {
- // Calculate route
- if(field.FindNearestPoint(you.pntTo, item.pntPos, &pnt))
- {
- pNewCommand = new AICOMMAND;
- pNewCommand->eAction = eAiMove;
- pNewCommand->pntMoveTo = pnt;
- pNewCommand->dwTarget = item.dwId;
- }
- else
- {
- strOutput.Format("%s@ can not be reached!", utlFindTargetItem(item.dwId));
- utlLogout(strOutput, eLogError, true);
- aiQueue.cancelAll();
- }
- goto DONE;
- }
- else
- {
- // Proceed
- utlChangePickupPhase(pCommand, ePickupPhasePick);
- }
- break;
- case ePickupPhaseLook:
- utlChangePickupPhase(pCommand, ePickupPhasePick);
- break;
- case ePickupPhaseLooking:
- //
- break;
- case ePickupPhasePick:
- if(utlDistanceFrom(items[nIndex].pntPos, you.pntTo) > 3)
- {
- // Retry
- utlChangePickupPhase(pCommand, (AIPICKUPPHASE)ePhaseNone);
- }
- else
- {
- // Start pickup
- pCommand->dwTimeout = GetTickCount() + TIMEOUT_PICKUP;
- utlChangePickupPhase(pCommand, ePickupPhasePicking);
- sendTake(pCommand->dwTarget);
- goto DONE;
- }
- break;
- case ePickupPhasePicking:
- sendTake(pCommand->dwTarget);
- if(item.nPickupFailed)
- {
- // Retry
- utlChangePickupPhase(pCommand, (AIPICKUPPHASE)ePhaseNone);
- items[nIndex].nPickupFailed = 0;
- strOutput.Format("Failed to pickup %s, retry!", utlFindTargetItem(item.dwId));
- utlLogout(strOutput, eLogError, true);
- }
- else
- {
- if(GetTickCount() > pCommand->dwTimeout)
- {
- strOutput.Format("Pickup %s timeout!", utlFindTargetItem(item.dwId));
- utlLogout(strOutput, eLogError, true);
- aiQueue.cancelAll();
- }
- goto DONE;
- }
- break;
- }
- }
- DONE:
- if(pNewCommand)
- {
- aiQueue.extend(*pNewCommand);
- delete pNewCommand;
- }
- return(0);
- }
- int aiProcessSitCommand(AICOMMAND *pCommand)
- {
- if(you.bSit)
- {
- aiQueue.finish();
- }
- else
- {
- switch(pCommand->ePhase)
- {
- case ePhaseNone:
- pCommand->dwTimeout = GetTickCount() + TIMEOUT_SIT;
- utlChangeSitPhase(pCommand, eSitPhaseSitting);
- sendSit();
- break;
- case eSitPhaseSitting:
- if(GetTickCount() > pCommand->dwTimeout)
- aiQueue.cancelAll();
- break;
- }
- }
- return(0);
- }
- int aiProcessStandCommand(AICOMMAND *pCommand)
- {
- if(!you.bSit)
- {
- aiQueue.finish();
- }
- else
- {
- switch(pCommand->ePhase)
- {
- case ePhaseNone:
- pCommand->dwTimeout = GetTickCount() + TIMEOUT_STAND;
- utlChangeStandPhase(pCommand, eStandPhaseStanding);
- sendStand();
- break;
- case eStandPhaseStanding:
- if(GetTickCount() > pCommand->dwTimeout)
- aiQueue.cancelAll();
- break;
- }
- }
- return(0);
- }
- int aiProcessMoveCommand(AICOMMAND *pCommand)
- {
- CString strOutput;
- BOOL bFound = false;
- BOOL bNeedRemove = false;
- AICOMMAND *pNewCommand = NULL;
- // check for cancel
- do
- {
- if(pCommand->dwTarget != 0 &&
- -1 == monsters.FindId(pCommand->dwTarget) &&
- -1 == items.FindId(pCommand->dwTarget))
- {
- // lost target
- strOutput.Format("Lost target(%X), giveup!", pCommand->dwTarget);
- bNeedRemove = true;
- break;
- }
- if(pCommand->dwTarget != 0 && -1 != monsters.FindId(pCommand->dwTarget))
- {
- if(GetTickCount() - monsters[monsters.FindId(pCommand->dwTarget)].dwAppearTime > 120000)
- {
- // lost target
- strOutput.Format("Target(%X) timeout, giveup!", pCommand->dwTarget);
- bNeedRemove = true;
- break;
- }
- }
- if(pCommand->dwTarget != 0 && -1 != items.FindId(pCommand->dwTarget))
- {
- if(GetTickCount() - items[items.FindId(pCommand->dwTarget)].dwAppearTime > 120000)
- {
- // lost target
- strOutput.Format("Target(%X) timeout, giveup!", pCommand->dwTarget);
- bNeedRemove = true;
- break;
- }
- }
- if(utlDistanceFrom(you.pntTo, pCommand->pntMoveTo) > 30)
- {
- // Too far
- strOutput.Format("Target(%X) is too far from you, giveup!", pCommand->dwTarget);
- bNeedRemove = true;
- break;
- }
- // Check for portals
- for(int i=0; i<portals.GetSize(); i++)
- {
- if(utlDistanceFrom(portals[i].pntPos, pCommand->pntMoveTo) <= 10)
- {
- // lost target
- strOutput.Format("Portal found, giveup!", pCommand->dwTarget);
- bNeedRemove = true;
- break;
- }
- }
- }while(0);
- if(bNeedRemove)
- {
- utlLogout(strOutput, eLogError, true);
- aiQueue.cancelAll();
- goto DONE;
- }
- // Process phase change
- while(true)
- {
- switch(pCommand->ePhase)
- {
- case ePhaseNone:
- if(!you.bSit)
- {
- // Proceed
- utlChangeMovePhase(pCommand, (AIMOVEPHASE)eMovePhaseMove);
- }
- else
- {
- // Generate stand command
- pNewCommand = new AICOMMAND;
- pNewCommand->eAction = eAiStand;
- pNewCommand->ePhase = ePhaseNone;
- goto DONE;
- }
- break;
- case eMovePhaseMove:
- pCommand->pntMoveFrom = you.pntTo;
- pCommand->dwTimeout = GetTickCount()+(DWORD)(SECOND_PER_BLOCK*utlDistanceFrom(pCommand->pntMoveFrom, pCommand->pntMoveTo));
- utlChangeMovePhase(pCommand, eMovePhaseMoving);
- sendMove(pCommand->pntMoveTo);
- goto DONE;
- break;
- case eMovePhaseMoving:
- if(GetTickCount() > pCommand->dwTimeout)
- {
- if(you.pntTo.x == pCommand->pntMoveTo.x &&
- you.pntTo.y == pCommand->pntMoveTo.y)
- {
- aiQueue.finish();
- goto DONE;
- }
- if(you.pntTo.x == pCommand->pntMoveFrom.x &&
- you.pntTo.y == pCommand->pntMoveFrom.y)
- {
- // Timeup: not moved, maybe can not reach
- if(GetTickCount() > pCommand->dwTimeout + TIMEOUT_MOVE)
- {
- strOutput.Format("Move to %s@(%d, %d) timeout, giveup!", utlFindTarget(pCommand->dwTarget), pCommand->pntMoveTo.x, pCommand->pntMoveTo.y);
- utlLogout(strOutput, eLogError, true);
- aiQueue.cancelAll();
- }
- goto DONE;
- }
- // Timeup: moved but has not reached, try again
- utlChangeMovePhase(pCommand, eMovePhaseMove);
- }
- else
- {
- goto DONE;
- }
- break;
- }
- }
- DONE:
- if(pNewCommand)
- {
- aiQueue.extend(*pNewCommand);
- delete pNewCommand;
- }
- return(0);
- }
- BOOL aiGetUnderAttackFrom(DWORD &dwTarget)
- {
- BOOL bRtn = false;
- for(int i=0; i<monsters.GetSize(); i++)
- {
- if(-1 != damages.FindDamage(monsters[i].dwId, dwAccountId))
- {
- dwTarget = monsters[i].dwId;
- bRtn = true;
- break;
- }
- }
- return(bRtn);
- }
- BOOL aiGetItemToPickup(ITEMPRIORITY priority, DWORD &dwTarget)
- {
- BOOL bRtn = false;
- int nPriFound;
- for(int i=0; i<items.GetSize(); i++)
- {
- nPriFound = atoi(mapItem.FindValue(items[i].wType, eItemPriority));
- if(nPriFound <= priority && !items[i].bAiIgnore)
- {
- dwTarget = items[i].dwId;
- bRtn = true;
- break;
- }
- }
- return(bRtn);
- }
- BOOL aiCheckTeleportCondition()
- {
- BOOL bRtn = false;
- CDWordArray dwTargetArray, dwDamageArray;
- if(action == eAiAttack && you.wHp < you.wHpMax * 0.2)
- {
- bRtn = true;
- }
- if(damages.FindDamageFrom(dwAccountId, dwTargetArray, dwDamageArray))
- {
- if(dwTargetArray.GetSize() > 6)
- bRtn = true;
- }
- return(bRtn);
- }