Exemplo n.º 1
0
bool Actions::UseItem(Player* player, const Position &pos,const unsigned char stack,
	const unsigned short itemid, const unsigned char index)
{
	if(canUse(player,pos)== TOO_FAR){
		player->sendCancel("Too far away.");
		return false;
	}
	Item *item = dynamic_cast<Item*>(game->getThing(pos,stack,player));
	if(!item){
		#ifdef __DEBUG__
		std::cout << "no item" << std::endl;
		#endif
		player->sendCancel("You can not use this object.");
		return false;
	}

	if(item->getID() != itemid){
		#ifdef __DEBUG__
		std::cout << "no id" << std::endl;
		#endif
		player->sendCancel("You can not use this object.");
		return false;
	}

#ifdef TLM_HOUSE_SYSTEM
	if (Item::items[itemid].isDoor)
	{
		Tile* tile = game->getTile(pos);
		House* house = tile? tile->getHouse() : NULL;

		if (house && player->access < g_config.ACCESS_HOUSE && house->getPlayerRights(pos, player->getName()) <= HOUSE_GUEST)
		{
			player->sendCancel("You are not allowed to open this door.");
			return false;
		}
	}
#endif //TLM_HOUSE_SYSTEM

	//look for the item in action maps
	Action *action = getAction(item);

	//if found execute it
	if(action){
		Position itempos = game->getThingMapPos(player, pos);
		game->autoCloseTrade(item);
		PositionEx posEx(pos,stack);
		if(action->executeUse(player,item,posEx,posEx)){
			return true;
		}
	}

	//if it is a container try to open it
	if(dynamic_cast<Container*>(item)){
		if(openContainer(player,dynamic_cast<Container*>(item),index))
			return true;
	}

  //we dont know what to do with this item
  player->sendCancel("You can not use this object.");
  return false;
}