Example #1
0
int moveToSeller(CConfigData *config, int traderNum) {
	CMemReaderProxy reader;
	CMemConstData memConstData = reader.getMemConstData();

	static int positionFound=0;
	if (shouldKeepWalking()){
		//Find a location close enough to NPC
		if (!positionFound){
			CTibiaCharacter* self = reader.readSelfCharacter();
			CModuleUtil::executeWalk(self->x,self->y,self->z,config->path);
			if (self->x == config->targetX && self->y == config->targetY && self->z == config->targetZ) {
				positionFound=1;
			}
			delete self;
		} else { //Approach NPC after finding them
			for (int i=0;i<memConstData.m_memMaxCreatures;i++){
				CTibiaCharacter* mon=reader.readVisibleCreature(i);
				if (mon->tibiaId==0){
					delete mon;
					break;
				}
				int len=strlen(mon->name);
				// since sellerList[traderNum].sellerName may include city, match first part of name
				if (strncmp(config->sellerList[traderNum].sellerName,mon->name,len)==0 && (config->sellerList[traderNum].sellerName[len]==0 || config->sellerList[traderNum].sellerName[len]==' ')){
					for (int tries=0;tries<2;tries++){ // should only need 1 try, but we'd need to start over if we don't make it
						CTibiaCharacter* self = reader.readSelfCharacter();
						delete mon;
						mon=reader.readVisibleCreature(i);

						struct point nearestSell=point(0,0,0);
						int rad=2;
						while (nearestSell.x==0 && rad<=3){//find paths increasingly farther away
							nearestSell= CModuleUtil::findPathOnMap(self->x, self->y, self->z, mon->x, mon->y, mon->z, 0, config->path,rad++);
						}
						if (nearestSell.x && nearestSell.y && nearestSell.z==self->z){
							CModuleUtil::executeWalk(self->x,self->y,self->z,config->path);
							if (CModuleUtil::waitToStandOnSquare(nearestSell.x, nearestSell.y)){
								delete mon;
								mon=reader.readVisibleCreature(i);
								if (!(abs(self->x - mon->x) <=3 && abs(self->y - mon->y) <=3 && self->z == mon->z)){
									delete self;
									continue;
								}
								delete mon;
								delete self;
								return 1;
							}
						}
						delete self;
					}
				}
				delete mon;
			}
			positionFound=0;
		}
	}
	return 0;
}
Example #2
0
int moveToBanker(CConfigData *config)
{
	CMemReader& reader = CMemReader::getMemReader();	

	static int positionFound = 0;
	CTibiaCharacter self;
	if (shouldKeepWalking())
	{
		//Find a location close enough to NPC
		if (!positionFound)
		{
			reader.readSelfCharacter(&self);
			CModuleUtil::executeWalk(self.x, self.y, self.z, config->path);
			if (self.x == config->targetX && self.y == config->targetY && self.z == config->targetZ)
				positionFound = 1;
		}
		else     //Approach NPC after finding them
		{
			for (int i = 0; i < reader.m_memMaxCreatures; i++)
			{
				CTibiaCharacter mon;
				reader.readVisibleCreature(&mon, i);
				// since banker.bankerName may include city, match first part of name
				if (mon.tibiaId == 0)
				{
					break;
				}
				int len = strlen(mon.name);
				if (strncmp(config->banker.bankerName, mon.name, len) == 0 && (config->banker.bankerName[len] == 0 || config->banker.bankerName[len] == ' '))
				{
					for (int tries = 0; tries < 2; tries++) // should only need 1 try, but we'd need to start over if we don't make it
					{
						reader.readSelfCharacter(&self);
						reader.readVisibleCreature(&mon, i);

						struct point nearestBank = point(0, 0, 0);
						int rad                  = 2;
						while (nearestBank.x == 0 && rad <= 3)//find paths increasingly farther away
						{
							nearestBank = CModuleUtil::findPathOnMap(self.x, self.y, self.z, mon.x, mon.y, mon.z, 0, config->path, rad++);
						}
						if (nearestBank.x && nearestBank.y && nearestBank.z == self.z)
						{
							CModuleUtil::executeWalk(self.x, self.y, self.z, config->path);
							if (CModuleUtil::waitToStandOnSquare(nearestBank.x, nearestBank.y))
							{
								return 1;
							}
						}
					}
				}
			}
			positionFound = 0;
		}
	}
	return 0;
}