KW

Autostacking Items

Por kwovan, 17 de ago. de 2010 em Linguagens de Programação

23
11.6k
kwovanK
17 de agosto de 2010 às 22:17

Testado no TFS 0.4 e 0.3.6pl1

 

Ache as fuções e modifique.

 

container.cpp

 

Cylinder* Container::__queryDestination(int32_t& index, const Thing* thing, Item** destItem, uint32_t&)
{
if(index == 254 /*move up*/)
{
	index = INDEX_WHEREEVER;
	*destItem = NULL;

	Container* parentContainer = dynamic_cast<Container*>(getParent());
	if(parentContainer)
		return parentContainer;

	return this;
}
else if(index == 255 /*add wherever*/){
	index = INDEX_WHEREEVER;
	*destItem = NULL;
}
else if(index >= (int32_t)capacity()){
		/*
		if you have a container, maximize it to show all 20 slots
		then you open a bag that is inside the container you will have a bag with 8 slots
		and a "grey" area where the other 12 slots where from the container
		if you drop the item on that grey area
		the client calculates the slot position as if the bag has 20 slots
		*/
		index = INDEX_WHEREEVER;
	*destItem = NULL;
}

const Item* item = thing->getItem();
if(item == NULL){
	return this;
}

if(item->isStackable()){
	if(item->getParent() != this){
		//try find a suitable item to stack with
		uint32_t n = 0;
		for(ItemList::iterator cit = itemlist.begin(); cit != itemlist.end(); ++cit){
			if((*cit) != item && (*cit)->getID() == item->getID() && (*cit)->getItemCount() < 100){
				*destItem = (*cit);
				index = n;
				return this;
			}

			++n;
		}
	}
}

if(index != INDEX_WHEREEVER){
	Thing* destThing = __getThing(index);
	if(destThing)
		*destItem = destThing->getItem();

	Cylinder* subCylinder = dynamic_cast<Cylinder*>(*destItem);

	if(subCylinder){
		index = INDEX_WHEREEVER;
		*destItem = NULL;
		return subCylinder;
	}
}

return this;
}

 

item.cpp

 

void Item::setDefaultSubtype()
{
setItemCount(1);
const ItemType& it = items[id];
if(it.charges)
	setCharges(it.charges);
}

 

player.cpp

 

Cylinder* Player::__queryDestination(int32_t& index, const Thing* thing, Item** destItem,
uint32_t& flags)
{
if(index == 0 /*drop to capacity window*/ || index == INDEX_WHEREEVER){
	*destItem = NULL;

	const Item* item = thing->getItem();
	if(item == NULL){
		return this;
	}

	//find an appropiate slot
	std::list<Container*> containerList;
	for(int i = SLOT_FIRST; i < SLOT_LAST; ++i){
		Item* inventoryItem = inventory[i];

		if(inventoryItem == tradeItem){
			continue;
		}

		if(inventoryItem == tradeItem){
			continue;
		}

			if(inventoryItem){
				//try find an already existing item to stack with
			if(inventoryItem != item && item->isStackable() && inventoryItem->getID() == item->getID() && inventoryItem->getItemCount() < 100){
				*destItem = inventoryItem;
				index = i;
				return this;
			}
			//check sub-containers
			else if(Container* subContainer = inventoryItem->getContainer()){
				Cylinder* tmpCylinder = NULL;
				int32_t tmpIndex = INDEX_WHEREEVER;
				Item* tmpDestItem = NULL;

				tmpCylinder = subContainer->__queryDestination(tmpIndex, item, &tmpDestItem, flags);
				if(tmpCylinder && tmpCylinder->__queryAdd(tmpIndex, item, item->getItemCount(), flags) == RET_NOERROR){
					index = tmpIndex;
					*destItem = tmpDestItem;
					return tmpCylinder;
				}

				containerList.push_back(subContainer);
			}
		}
		//empty slot
		else if(__queryAdd(i, item, item->getItemCount(), flags) == RET_NOERROR){
			index = i;
			*destItem = NULL;
			return this;
		}
	}

	//check deeper in the containers
	for(std::list<Container*>::iterator it = containerList.begin(); it != containerList.end(); ++it){
		for(ContainerIterator iit = (*it)->begin(); iit != (*it)->end(); ++iit){
			if(Container* subContainer = (*iit)->getContainer()){

				if(subContainer == tradeItem){
					continue;
				}

				Cylinder* tmpCylinder = NULL;
				int32_t tmpIndex = INDEX_WHEREEVER;
				Item* tmpDestItem = NULL;

				tmpCylinder = subContainer->__queryDestination(tmpIndex, item, &tmpDestItem, flags);
				if(tmpCylinder && tmpCylinder->__queryAdd(tmpIndex, item, item->getItemCount(), flags) == RET_NOERROR){
					index = tmpIndex;
					*destItem = tmpDestItem;
					return tmpCylinder;
				}
			}
		}
	}
	return this;
}

Thing* destThing = __getThing(index);
if(destThing)
	*destItem = destThing->getItem();

Cylinder* subCylinder = dynamic_cast<Cylinder*>(destThing);

if(subCylinder){
	index = INDEX_WHEREEVER;
	*destItem = NULL;
	return subCylinder;
}
else
	return this;
}

 

Créditos: Exedion

Editado Agosto 18 por kwovan

felzanF
17 de agosto de 2010 às 23:23

Não quero ser nubão, mas isso é pra fazer com que os itens do loot(dos corpos) virem direto pra a bag?

dava pra explicar?

quando mata um monstro o loot vem direto?

e quando abre o corpo?

vlw, mt útil, já que mts RPGs usam o sistema de auto-loot

HimmlerH
18 de agosto de 2010 às 00:06

é auto stack, igual ao auto 200 stackitems do elfbot ou auto stack do mage bot.

 

Ele junta todos itens agrupaveis que tiver.

 

Parabens, bom. Nao vou colocar aki pq dependendo do item eh um saco depois quando vc ker dexar separado.

 

Vlw

felzanF
18 de agosto de 2010 às 13:02

Então é com esse código que faz o gold se reuni mesmo pondo só na bag, agora entendi, vlw.

kwovanK
18 de agosto de 2010 às 14:05

Sim, ele junta todos os items que é possível juntar ex: potions, golds, orbs, etc...

felzanF
18 de agosto de 2010 às 15:49

Vlws, para os servidores que ainda não tem o novo TFS da pra segura as pontas...

E por falar nisso, alguém tem alguma notícia do TFS?

Faz quase uma semana que não entro aqui(xtibia)

caarolina12C
22 de agosto de 2010 às 17:50

Creio que irá bugar os first items, mesmo assim, bom trabalho :S

2 meses depois...
calibourC
16 de outubro de 2010 às 14:41

Sim mais como eu faço isso no OT Alissow ?

11 meses depois...
sabrina9292S
02 de setembro de 2011 às 23:14

Desculpe minha ignorancia...

Mas em qual pasta fica esses arquivos?

Ichi666I
04 de setembro de 2011 às 09:44
Desculpe minha ignorancia...

Mas em qual pasta fica esses arquivos?

 

Nas Sources.

1 mês depois...
arkiresA
11 de outubro de 2011 às 12:43

Com esse code e possivel fazer um talkactions/comando para quando o jogadores quiser pode ativar para junta os item ??!! isso para a opeção para cada jogador :)

3 semanas depois...
delmondesD
25 de outubro de 2011 às 15:02

como fazer para não bugar first items?

CoffeTimeC
25 de outubro de 2011 às 16:36

Tutorial muito bom, mas você deveria ao menos explicar o proposito, e formular um tutorial "massa" para ficar "doidao" :D

 

Att, CoffeTime .

25 de outubro de 2011 às 18:44

Título autoexplicativo.

 

Para não bugar o first items teria que atualizar a função de adicionar items/container.

2 meses depois...
angeldoidoA
31 de dezembro de 2011 às 09:47

cara esse ultimo em player.cpp n comsigo indentifica o q tem que substituir no meu, pode ajuda ?