Page 1 of 1

Item Sets (part 1)

Posted: Wed Nov 08, 2017 4:43 am
by Ememjr
this is Part one of a 2 part update. Part one is the examining of item sets ie.. bags, boxes, crates, of items that can be opened and the contents be added to you invntory. example veteran rewards and armour packs.

Part 2 will update and add code to actually open these items sets and receive your items.
Part 3 will be an update to allow for the selection of one item from the item set ie burynai plant, eggs
ItemSets.JPG
throughout the aritcle, if you update your code yourself and dont rely on svn updated code then you want the following changes, this is becuase of Jab's unability to alter the db due to a technical difficulty. its just a name change so Jab will have to keep references to the old names instead of new names i will be posting in the itemsdb.cpp
original name `item_unknown1` new name `item_stack_size`
original name `item_unknown2` new name `item_list_color`
this is the DB change

Code: Select all

ALTER TABLE `eq2world7`.`item_details_itemset`   
  CHANGE `item_unknown1` `item_stack_size` SMALLINT(5) UNSIGNED DEFAULT 0 NOT NULL,
  CHANGE `item_unknown2` `item_list_color` INT(10) DEFAULT 0 NOT NULL;
Items.h

add (yes its a duplicate number but armorsets use the same code #

Code: Select all

#define ITEM_TYPE_ITEMCRATE		  18
add

Code: Select all

vector<ItemSet*>		item_sets;
ItemSet_Info*			itemset_info;
to the section that starts with

Code: Select all

	#pragma pack()
	Item();
	Item(Item* in_item);
	~Item();
	string					lowername;
	string					name;
	string					description;
	int8					stack_count;
	int32					sell_price;



add the struct ItemSet below

Code: Select all

#pragma pack()
struct ItemStat{
	string					stat_name;
	int8					stat_type;
	sint16					stat_subtype;
	int16					stat_type_combined;
	float					value;
};
struct ItemSet{
	int32					item_id;
	int32					item_crc;
	int16					item_icon;
	int16					item_stack_size;
	int32					item_list_color;
	
};
struct Classifications{
	int32					class_id;  //classifications MJ
	string					class_name;
};
add this to the

Code: Select all

public:
	#pragma pack(1)
section

struct ItemSet_Info{
int32 item_id;
int32 item_crc;
int16 item_icon;
int32 item_stack_size;
int32 item_list_color;
};

add these 2 lines

Code: Select all

void AddSet(ItemSet* in_set);
void AddSet(int32 item_id, int32 item_crc, int16 item_icon, int32 item_stack_size, int32 item_unknown2);
into the section below

Code: Select all

void SetAppearance(int16 type, int8 red, int8 green, int8 blue, int8 highlight_red, int8 highlight_green, int8 highlight_blue);
	void SetAppearance(ItemAppearance* appearance);
	void AddStat(ItemStat* in_stat);
	void AddSet(ItemSet* in_set);
	void AddStatString(ItemStatString* in_stat);
	void AddStat(int8 type, int16 subtype, float value, char* name = 0);
	void AddSet(int32 item_id, int32 item_crc, int16 item_icon, int32 item_stack_size, int32 item_unknown2);
	void SetWeaponType(int8 type);
	int8 GetWeaponType();
	bool HasSlot(int8 slot, int8 slot2 = 255);
	bool HasAdorn0();
	bool HasAdorn1();
	bool HasAdorn2();
Items.cpp

in

Code: Select all

Item::Item(){
add

Code: Select all

itemset_info = 0;
in

Code: Select all

Item::~Item(){
add

Code: Select all

safe_delete(itemset_info);
in

Code: Select all

void Item::SetItem(Item* old_item){
add

Code: Select all

itemset_info = 0;
add

Code: Select all

item_sets.clear();
	for (int32 i = 0; i<old_item->item_sets.size(); i++){
		ItemSet* set = old_item->item_sets[i];
		if (set){
			ItemSet* set2 = new ItemSet;
			set2->item_id = set->item_id;
			set2->item_crc = set->item_crc;
			set2->item_icon = set->item_icon;
			set2->item_stack_size = set->item_stack_size;
			set2->item_list_color = set->item_list_color;
			item_sets.push_back(set2);
		}
	}
right after

Code: Select all

creator = old_item->creator;
	adornment = old_item->adornment;
add

Code: Select all

void Item::AddSet(ItemSet* in_set){
	item_sets.push_back(in_set);
}
right after

Code: Select all

void Item::AddStat(ItemStat* in_stat){
	item_stats.push_back(in_stat);
}
add

Code: Select all

void Item::AddSet(int32 item_id, int32 item_crc, int16 item_icon, int32 item_stack_size, int32 item_list_color){
	ItemSet* set = new ItemSet;
	set->item_id = item_id;
	set->item_icon = item_icon;
	set->item_crc = item_crc;
	set->item_stack_size = item_stack_size;
	set->item_list_color = item_list_color;
	
	AddSet(set);
}
just before

Code: Select all

int16 Item::GetOverrideLevel(int8 adventure_class, int8 tradeskill_class){
add

Code: Select all

if (item_sets.size() > 0){
		packet->setArrayLengthByName("num_pieces", item_sets.size());
		for (int32 i = 0; i < item_sets.size(); i++){
			ItemSet* set = item_sets[i];
			packet->setArrayDataByName("item_id", set->item_id, i);
			packet->setArrayDataByName("item_crc", set->item_crc, i);
			packet->setArrayDataByName("item_icon", set->item_icon, i);
			packet->setArrayDataByName("item_unknown1", set->item_stack_size, i);

			Item* item2 = master_item_list.GetItem(set->item_id);
			//item2 = master_item_list.GetItem(set->item_id);
			string itemname = item2->name;
			packet->setArrayDataByName("item_name", item2->name.c_str(), i);

			packet->setArrayDataByName("item_unknown2", set->item_list_color, i);
			
		}
			
	
	}
just before

Code: Select all

if(!loot_item && item_effects.size() > 0){
		packet->setSubstructArrayLengthByName("footer", "num_effects", item_effects.size());
		for(int32 i=0;i<item_effects.size();i++){
			ItemEffect* effect = item_effects[i];
			packet->setArrayDataByName("subbulletflag", effect->subbulletflag, i);
			packet->setArrayDataByName("effect", &(effect->effect), i);
			packet->setArrayDataByName("percentage", effect->percentage, i);
		}
	}
add

Code: Select all

case ITEM_TYPE_ITEMCRATE:{
				if (merchant_item)
					packet = configReader.getStruct("WS_MerchantItemSet", version);
				else
					packet = configReader.getStruct("WS_ItemSet", version);
				break;
			}
after

Code: Select all

case ITEM_TYPE_BAUBLE:{
				if(merchant_item)
					packet = configReader.getStruct("WS_MerchantItemBauble", version);
				else
					packet = configReader.getStruct("WS_ItemBauble", version);
				break;
			}
WorldDatabase.h

Code: Select all

int32	LoadItemsets();
in

Code: Select all

class WorldDatabase : public Database {
public:
ItemsDB.cpp

add NOTE: if DB your is not updated then change item_stack_size to Item_unknown1, and item_list_color to item_unknown2(emu server this means you

Code: Select all

int32 WorldDatabase::LoadItemsets()
{
	DatabaseResult result;
	int32 total = 0;
	int32 id = 0;

	if (database_new.Select(&result, "SELECT id, itemset_item_id, item_id, item_icon,item_stack_size,item_list_color,language_type FROM item_details_itemset"))
	{
		while (result.Next())
		{
			id = result.GetInt32Str("itemset_item_id");
			Item* item = master_item_list.GetItem(id);

			if (item)
			{
				item->SetItemType(ITEM_TYPE_ITEMCRATE);
				//int32 item_id = result.GetInt32Str("item_id");
				item->AddSet(result.GetInt32Str("item_id"),0, result.GetInt16Str("item_icon"), result.GetInt16Str("item_stack_size"), result.GetInt32Str("item_list_color"));
				

				total++;
			}
			else
				LogWrite(ITEM__ERROR, 0, "Item Set Crate Items", "Error loading `item_details_Items`, ID: %i", id);
		}
	}

	return total;
}
after

Code: Select all

int32 WorldDatabase::LoadBooks()
{
	DatabaseResult result;
	int32 total = 0;
	int32 id = 0;

	if( database_new.Select(&result, "SELECT item_id, language, author, title FROM item_details_book") )
	{
		while( result.Next() )
		{
			id = result.GetInt32Str("item_id");
			Item* item = master_item_list.GetItem(id);

			if(item)
			{
				LogWrite(ITEM__DEBUG, 5, "Items", "\tItem Book for item_id %u", id);
				LogWrite(ITEM__DEBUG, 5, "Items", "\ttype: %i, %i, %s, %s", 
					ITEM_TYPE_BOOK, 
					result.GetInt8Str("language"), 
					result.GetStringStr("author"), 
					result.GetStringStr("title"));

				item->SetItemType(ITEM_TYPE_BOOK);
				item->book_info->language = result.GetInt8Str("language");
				item->book_info->author.data = result.GetStringStr("author");
				item->book_info->author.size = item->book_info->author.data.length();
				item->book_info->title.data = result.GetStringStr("title");
				item->book_info->title.size = item->book_info->title.data.length();

				total++;
			}
			else
				LogWrite(ITEM__ERROR, 0, "Items", "Error loading `item_details_book`, ID: %i", id);
		}
	}

	return total;
}
add

Code: Select all

LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Item Sets", LoadItemsets());
after

Code: Select all

LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Normal Items", normal_items);
	LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Baubles", LoadBaubles());
	LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Bags", LoadBags());
	LogWrite(ITEM__DEBUG, 0, "Items", "\tLoaded %u Books", LoadBooks());

Re: Item Sets (part 1)

Posted: Thu Nov 09, 2017 9:49 am
by Ememjr
FYI althought th e above code works as is, there are a couple changes coming to it to better it,
1. the item_list_color will be tweak. although this is the color of the item in the list, for the client, i haves discovered that its color should be devrived based on the level of the item compared to the the level of the player, and not just a hardcoded value,ie for most of these items in the list, if you are the correct level or above or, you are generally able to use the item its white. if you can not use it for some reason, ie level, class etc, it should be red
2. is the adjustment i forgot to make above when i figure it out

coming soon in part 2 will be unpacking the item crate (set)

Re: Item Sets (part 1)

Posted: Sat Nov 11, 2017 9:15 pm
by Zcoretri
Going through this code, I think you forgot a couple things.

Add to Items.h

Code: Select all

ItemSet_Info*        itemset_info;
vector<ItemSet*>        item_sets
Add to WorldDatabase.h

Code: Select all

int32    LoadItemsets();

Re: Item Sets (part 1)

Posted: Sun Nov 12, 2017 4:14 am
by Ememjr
let me look, it i did it just an ommision in posting,

Re: Item Sets (part 1)

Posted: Sun Nov 12, 2017 4:21 am
by Ememjr
ok i found them all will it the post,
sometimes it is easy to miss a on line change

Re: Item Sets (part 1)

Posted: Sun Nov 12, 2017 9:42 am
by Zcoretri
Yes it is easy to miss little things when immersed incoding :mrgreen:

Re: Item Sets (part 1)

Posted: Mon Nov 13, 2017 7:00 pm
by Scribble
Now if i can only think of somewhere I can use this.