Пример #1
0
bool ChatHandler::HandleAddInvItemCommand(const char *args, WorldSession *m_session)
{
	uint32 itemid, count=1;
	int32 randomprop=0;

	if(strlen(args) < 1)
	{
		return false;
	}

	if(sscanf(args, "%u %u %d", &itemid, &count, &randomprop) < 1)
		return false;

	Player * chr = getSelectedChar( m_session, false );
	if ( chr == NULL )
		chr = m_session->GetPlayer();
	
	ItemPrototype* it = ItemPrototypeStorage.LookupEntry(itemid);
	if(it)
	{
		sGMLog.writefromsession(m_session, "used add item command, item id %u [%s] to %s", it->ItemId, it->Name1, chr->GetName());
		Item *item;
		item = objmgr.CreateItem( itemid, chr);
		item->SetUInt32Value(ITEM_FIELD_STACK_COUNT, ((count > it->MaxCount) ? it->MaxCount : count));
		if(it->Bonding==ITEM_BIND_ON_PICKUP)
			item->SoulBind();
		if(randomprop!=0)
		{
			if(randomprop<0)
				item->SetRandomSuffix(abs(int(randomprop)));
			else
				item->SetRandomProperty(randomprop);

			item->ApplyRandomProperties(false);
		}
	  
		if(!chr->GetItemInterface()->AddItemToFreeSlot(item))
		{
			m_session->SendNotification("No free slots were found in your inventory!");
			item->DeleteMe();
			return true;
		}

		char messagetext[512];
		snprintf(messagetext, 512, "Adding item %s (id: %d) to %s's inventory.", GetItemLinkByProto(it, m_session->language).c_str(), (unsigned int)it->ItemId, chr->GetName());
		SystemMessage(m_session, messagetext);
		snprintf(messagetext, 128, "%s added item %d (%s) to your inventory.", m_session->GetPlayer()->GetName(), (unsigned int)itemid, it->Name1);
		snprintf(messagetext, 512, "%s added item %s to your inventory.", m_session->GetPlayer()->GetName(), GetItemLinkByProto(it, chr->GetSession()->language).c_str());
		
		SystemMessageToPlr(chr,  messagetext);

		SlotResult *lr = chr->GetItemInterface()->LastSearchResult();
		chr->GetSession()->SendItemPushResult(item,false,true,false,true,lr->ContainerSlot,lr->Slot,count);

		return true;
	} else {
		RedSystemMessage(m_session, "Item %d is not a valid item!", itemid);
		return true;
	}
}
Пример #2
0
	void AIUpdate() 
	{
		//check and remove player items
		for( uint32 i=0;i<RENTED_ITEM_COUNT;i++)
		{
			ItemPrototype *iProto = ItemPrototypeStorage.LookupEntry( RentedItemIDs[ i ] );
			if( iProto == NULL )
				continue;
			char ItemLink[ 500 ];
			GetItemLinkByProto(iProto, ItemLink );
			int64 *Reserved = _unit->GetCreateIn64Extension( GOLD_SINK_ITEM_NPC_ID + i * EXTENSION_ITEM_INFO_SIZE + EXTENSION_ITEM_INFO_INDEX_TIME );
			//check if item is still reserved
			if( *Reserved + MAXIMIM_RESERVE_MINUTES > UNIXTIME )
				continue;
			//remove item
			int64 *ItemGUID = _unit->GetCreateIn64Extension( GOLD_SINK_ITEM_NPC_ID + i * EXTENSION_ITEM_INFO_SIZE + EXTENSION_ITEM_INFO_INDEX_IGUID );
			if( *ItemGUID )
			{
				//tell the player we have an item available if he agrees to pay more
				int64 *PlayerGUID = _unit->GetCreateIn64Extension( GOLD_SINK_ITEM_NPC_ID + i * EXTENSION_ITEM_INFO_SIZE + EXTENSION_ITEM_INFO_INDEX_PGUID );
				RemoveItemFromPlayer( *PlayerGUID, *ItemGUID, _unit, ItemLink );
				*ItemGUID = 0;
			}
			else
			{
				int64 *Cost = _unit->GetCreateIn64Extension( GOLD_SINK_ITEM_NPC_ID + i * EXTENSION_ITEM_INFO_SIZE + EXTENSION_ITEM_INFO_INDEX_COST );
				*Cost = *Cost * ITEM_PRICE_DECREASE_PCT_PER_REFRESH / 100;
			}
		}
	}
Пример #3
0
	void send_MainPage(Object * pObject, Player* Plr)
	{
		if( pObject == NULL || Plr == NULL )
			return; 

		GossipMenu *Menu;
		objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), GOLD_SINK_ITEM_NPC_DESC_TEXT_ID, Plr);
		char WriteBuff[500];
		char WriteBuff2[500];
		char ItemLink[ 500 ];

		for( uint32 i=0;i<RENTED_ITEM_COUNT;i++)
		{
			ItemPrototype *iProto = ItemPrototypeStorage.LookupEntry( RentedItemIDs[ i ] );
			if( iProto == NULL )
				continue;
			GetItemLinkByProto(iProto, ItemLink );
			int64 *Holder;
			Holder = pObject->GetCreateIn64Extension( GOLD_SINK_ITEM_NPC_ID + i * EXTENSION_ITEM_INFO_SIZE + EXTENSION_ITEM_INFO_INDEX_TIME );
			//check if item is still reserved
			if( *Holder > UNIXTIME )
			{
				int64 ReservedSecondsRemaining = *Holder - UNIXTIME;
				sprintf( WriteBuff, "Item %s is reserved for %d seconds",ItemLink, ReservedSecondsRemaining );
				Menu->AddItem( 0, WriteBuff, 2);
				continue;
			}
			//tell the player we have an item available if he agrees to pay more
			Holder = pObject->GetCreateIn64Extension( GOLD_SINK_ITEM_NPC_ID + i * EXTENSION_ITEM_INFO_SIZE + EXTENSION_ITEM_INFO_INDEX_COST );
			uint32 NeededGold = ( RENTED_ITEM_MIN_GOLD + *Holder ) * ITEM_RESERVE_GOLD_INCREMENT_PCT / 100;
			sprintf( WriteBuff, "Pay at least %u to reserve %s for min %u max %u minutes", NeededGold, ItemLink, MINIMUM_RESERVE_MINUTES, MINIMUM_RESERVE_MINUTES + MAXIMIM_RESERVE_MINUTES );
			sprintf( WriteBuff2, "Steal %s from other player?", ItemLink );
			Menu->AddMenuItem( 0, WriteBuff, 0, 0, WriteBuff2, NeededGold * 10000, true, 2 + i );
		}
		Menu->SendTo(Plr);
	}
Пример #4
0
string Item::GetItemLink(uint32 language = NULL)
{
	return GetItemLinkByProto(GetProto(), language);
}
Пример #5
0
	void GossipSelectOption(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code)
	{
		Creature * pCreature = (pObject->IsCreature())?((Creature*)pObject):NULL;
		if( pCreature==NULL || Plr == NULL )
			return;
		uint32 ChosenItemSlot = IntId - 2;
		if( ChosenItemSlot >= 0 && ChosenItemSlot < RENTED_ITEM_COUNT )
		{
			int64 *Reserved = pObject->GetCreateIn64Extension( GOLD_SINK_ITEM_NPC_ID + ChosenItemSlot * EXTENSION_ITEM_INFO_SIZE + EXTENSION_ITEM_INFO_INDEX_TIME );
			//check if item is still reserved
			if( *Reserved > UNIXTIME )
			{
				Plr->BroadcastMessage("Item got already reserved by someone else");
				Plr->CloseGossip();
				return;
			}
			//check if offering enough money for the item
			//tell the player we have an item available if he agrees to pay more
			int64 *Cost = pObject->GetCreateIn64Extension( GOLD_SINK_ITEM_NPC_ID + ChosenItemSlot * EXTENSION_ITEM_INFO_SIZE + EXTENSION_ITEM_INFO_INDEX_COST );
			int32 NeededGold = ( RENTED_ITEM_MIN_GOLD + *Cost ) * ITEM_RESERVE_GOLD_INCREMENT_PCT / 100 * 10000;
			int32 BetGoldAmount;
			if( Code != NULL )
				BetGoldAmount = atoi( Code ) * 10000;
			else
				BetGoldAmount = 0;
			if( Plr->GetGold() < NeededGold || Plr->GetGold() < BetGoldAmount )
			{
				Plr->BroadcastMessage("You do not have enough gold");
				Plr->CloseGossip();
				return;
			}
			if( BetGoldAmount < NeededGold )
			{
				Plr->BroadcastMessage("You need to pay more then the other player to rent this item");
				Plr->CloseGossip();
				return;
			}
			Plr->ModGold( -BetGoldAmount );
			//mark the new gold reserver limit
			*Cost = NeededGold / 10000;
			//avoid threading issues, lock this item asp
			*Reserved = UNIXTIME + MINIMUM_RESERVE_MINUTES * 60;
			//take the item away from the other player if possible
			int64 *ItemGUID = pObject->GetCreateIn64Extension( GOLD_SINK_ITEM_NPC_ID + ChosenItemSlot * EXTENSION_ITEM_INFO_SIZE + EXTENSION_ITEM_INFO_INDEX_IGUID );
			int64 *PlayerGUID = pObject->GetCreateIn64Extension( GOLD_SINK_ITEM_NPC_ID + ChosenItemSlot * EXTENSION_ITEM_INFO_SIZE + EXTENSION_ITEM_INFO_INDEX_PGUID );
			{
				ItemPrototype *iProto = ItemPrototypeStorage.LookupEntry( RentedItemIDs[ ChosenItemSlot ] );
				char ItemLink[ 500 ];
				GetItemLinkByProto(iProto, ItemLink );
				RemoveItemFromPlayer( *PlayerGUID, *ItemGUID, pCreature, ItemLink );
			}
			//create and add a new item to the new player
/*
FILE *f = fopen( "gold.txt","at");
if( f )
{
	fprintf( f, "Adding %d to %d at %d cost %d expire %d\n", RentedItemIDs[ ChosenItemSlot ], (uint32)Plr->GetGUID(), UNIXTIME, *Cost, *Reserved );
	fclose( f );
}*/
			Item *It = Plr->GetItemInterface()->AddItemById( RentedItemIDs[ ChosenItemSlot ], 1, 0 );
			if( It )
			{
				*ItemGUID = It->GetGUID();
				*PlayerGUID = Plr->GetGUID();
				It->SetFlag( ITEM_FIELD_FLAGS, ITEM_FLAG_CONJURED );
			}
		}
		Plr->CloseGossip();
	}
Пример #6
0
bool ChatHandler::HandleRemoveItemCommand(const char* args, WorldSession* m_session)
{
	uint32 item_id;
	int32 count, ocount;
	int argc = sscanf(args, "%u %u", (unsigned int*)&item_id, (unsigned int*)&count);
	if(argc == 1)
		count = 1;
	else if(argc != 2 || !count)
		return false;

	ocount = count;
	Player* plr = getSelectedChar(m_session, true);
	if(!plr)
		return true;

	// loop until they're all gone.
	int32 loop_count = 0;
	int32 start_count = plr->GetItemInterface()->GetItemCount(item_id, true);
	int32 start_count2 = start_count;
	if(count > start_count)
		count = start_count;

	while(start_count >= count && (count > 0) && loop_count < 20) // Prevent a loop here.
	{
		plr->GetItemInterface()->RemoveItemAmt(item_id, count);
		start_count2 = plr->GetItemInterface()->GetItemCount(item_id, true);
		count -= (start_count - start_count2);
		start_count = start_count2;
		++loop_count;
	}

	ItemPrototype* iProto = ItemPrototypeStorage.LookupEntry(item_id);

	if(iProto)
	{
		sGMLog.writefromsession(m_session, "used remove item %s (id: %u) count %u from %s", iProto->Name1, item_id, ocount, plr->GetName());
		BlueSystemMessage(m_session, "Removing %u copies of item %s (id: %u) from %s's inventory.", ocount, GetItemLinkByProto(iProto, m_session->language).c_str(), item_id, plr->GetName());
		BlueSystemMessage(plr->GetSession(), "%s removed %u copies of item %s from your inventory.", m_session->GetPlayer()->GetName(), ocount, GetItemLinkByProto(iProto, plr->GetSession()->language).c_str());
	}
	else
		RedSystemMessage(m_session, "Cannot remove non valid item id: %u .", item_id);

	return true;
}
Пример #7
0
bool ChatHandler::HandleAddInvItemCommand(const char* args, WorldSession* m_session)
{
	uint32 itemid, count = 1;
	int32 randomprop = 0;
	int32 numadded = 0;

	if(strlen(args) < 1)
		return false;

	if(sscanf(args, "%u %u %d", &itemid, &count, &randomprop) < 1)
	{
		// check for item link
		uint16 ofs = GetItemIDFromLink(args, &itemid);
		if(!itemid)
			return false;

		sscanf(args + ofs, "%u %d", &count, &randomprop); // these may be empty
	}

	Player* chr = getSelectedChar(m_session, false);
	if(!chr)
		chr = m_session->GetPlayer();

	ItemPrototype* it = ItemPrototypeStorage.LookupEntry(itemid);
	if(it)
	{
		numadded -= chr->GetItemInterface()->GetItemCount(itemid);
		bool result = false;
		result = chr->GetItemInterface()->AddItemById(itemid, count, randomprop);
		numadded += chr->GetItemInterface()->GetItemCount(itemid);
		if(result == true)
		{
			if(count == 0)
				sGMLog.writefromsession(m_session, "used add item command, item id %u [%s], quantity %u, to %s", it->ItemId, it->Name1, numadded, chr->GetName());
			else
				sGMLog.writefromsession(m_session, "used add item command, item id %u [%s], quantity %u (only %lu added due to full inventory), to %s", it->ItemId, it->Name1, numadded, numadded, chr->GetName());

			char messagetext[512];

			snprintf(messagetext, 512, "Added item %s (id: %d), quantity %u, to %s's inventory.", GetItemLinkByProto(it, m_session->language).c_str(), (unsigned int)it->ItemId, numadded, chr->GetName());
			SystemMessage(m_session, messagetext);
			//snprintf(messagetext, 128, "%s added item %d (%s) to your inventory.", m_session->GetPlayer()->GetName(), (unsigned int)itemid, it->Name1);
			snprintf(messagetext, 512, "%s added item %s, quantity %u, to your inventory.", m_session->GetPlayer()->GetName(), GetItemLinkByProto(it, chr->GetSession()->language).c_str(), numadded);

			SystemMessageToPlr(chr,  messagetext);
		}
		else
			SystemMessageToPlr(chr, "Failed to add item.");

		return true;
	}
	else
	{
		RedSystemMessage(m_session, "Item %d is not a valid item!", itemid);
		return false;
	}
}
Пример #8
0
bool ChatHandler::HandleQuestRewardCommand(const char * args, WorldSession * m_session)
{
	if(!*args) return false;

	stringstream recout;

	uint32 qu_id = atol(args);
	if(qu_id== 0)
	{
		qu_id = GetQuestIDFromLink(args);
		if(qu_id== 0)
			return false;
	}
	Quest* q = QuestStorage.LookupEntry(qu_id);
	if(q)
	{
		for( uint32 r = 0; r < q->count_reward_item; r++ )
		{
			uint32 itemid = q->reward_item[r];
			ItemPrototype *itemProto = ItemPrototypeStorage.LookupEntry(itemid);
			if(!itemProto)
			{
				recout << "Unknown item id %lu" << itemid;
				sLog.outError( "WORLD: Unknown item id 0x%08x", itemid );
			}
			else
			{
				recout << "Reward (" << itemid << "): " << GetItemLinkByProto(itemProto,m_session->language);
				if(q->reward_itemcount[r]==1)
					recout << "\n";
				else
					recout << "[x" << q->reward_itemcount[r] << "]\n";
			}
		}
		for( uint32 r = 0; r < q->count_reward_choiceitem; r++ )
		{
			uint32 itemid = q->reward_choiceitem[r];
			ItemPrototype *itemProto = ItemPrototypeStorage.LookupEntry(itemid);
			if(!itemProto)
			{
				recout << "Unknown item id %lu" << itemid;
				sLog.outError( "WORLD: Unknown item id 0x%08x", itemid );
			}
			else
			{
				recout << "Reward choice (" << itemid << "): " << GetItemLinkByProto(itemProto,m_session->language);
				if(q->reward_choiceitemcount[r] == 1)
					recout << "\n";
				else
					recout << "[x" << q->reward_choiceitemcount[r] << "]\n";
			}
		}
		if((q->count_reward_choiceitem == 0) && (q->count_reward_item == 0))
		{
			recout << "Quest " << qu_id << " has no item rewards.";
		}
	}
	else
	{
		recout << "Quest ID " << qu_id << " not found.\n";
		sLog.outError("Quest ID %lu not found.", qu_id);
	}

	SendMultilineMessage(m_session, recout.str().data());

	return true;
}