using BrewMonster.ELEMENT_DATA; using ModelRenderer.Scripts.GameData; using BrewMonster; using System.Runtime.InteropServices; using System.Collections.Generic; using System.Linq; using System; public static class generate_item_temp { public static int generate_weapon(uint id, ID_SPACE idspace, out byte[] data, out uint size, RAND_CLASS cls, GEN_ADDON_MODE normal_addon ,item_tag_t tag,List sa_list = null) { DATA_TYPE datatype = DATA_TYPE.DT_INVALID; data = new byte[0]; size = 0; int i=0; object obj = itemdataman._edm.get_data_ptr(id, idspace,ref datatype); if(obj == null || datatype != DATA_TYPE.DT_WEAPON_ESSENCE) { return -1; } WEAPON_ESSENCE ess = (WEAPON_ESSENCE)obj; //$$$$$$$$$$$ ���ڼ�����Ʒû�ж��������Բ������� if(ess.id_sub_type == 300 || ess.id_sub_type == 293 || ess.id_sub_type == 76 || ess.id_sub_type == 291) { return -1; } size =(uint)(Marshal.SizeOf(typeof(item_data)) + Marshal.SizeOf(typeof(_item_content)) + Marshal.SizeOf(typeof(_weapon_essence))); // ����׶ï¿? uint hole_num = 0; if(normal_addon == GEN_ADDON_MODE.ADDON_LIST_DROP) { float[] drop_probability_socket = { ess.drop_probability_socket0, ess.drop_probability_socket1, ess.drop_probability_socket2 }; hole_num = element_data.RandSelect_SPECIFIC_LOWER(drop_probability_socket.ToList(), SPECIFIC.SPECIFIC_RAND, LOWER.LOWER_TREND); //�׶�����Ŀ } else //if(normal_addon == element_data::ADDON_LIST_PRODUCE || normal_addon == element_data::ADDON_LIST_SPEC) { float[] make_probability_socket = { ess.make_probability_socket0, ess.make_probability_socket1, ess.make_probability_socket2 }; hole_num = element_data.RandSelect_SPECIFIC_LOWER(make_probability_socket.ToList(), SPECIFIC.SPECIFIC_RAND, LOWER.LOWER_TREND); //�׶�����Ŀ } size += hole_num*sizeof(int); // size ����hole_num������type //����tag size //ASSERT(tag_size >= sizeof(short)); size += tag.size; // ���addons uint candidate_num = itemdataman.ELEMENTDATAMAN_MAX_NUM_ADDONS; byte[] addon_buf = new byte[candidate_num*Marshal.SizeOf(typeof(itemdataman._addon))]; float[] probability_addon_num = { ess.probability_addon_num0, ess.probability_addon_num1, ess.probability_addon_num2, ess.probability_addon_num3, ess.probability_addon_num4, ess.probability_addon_num5 }; uint addon_num = element_data.RandSelect_SPECIFIC_LOWER(probability_addon_num.ToList(), SPECIFIC.SPECIFIC_RAND, LOWER.LOWER_TREND); //���Ա���Ŀ����Ŀ uint addon_size = 0; if(ess.fixed_props!=0) { // this list store the addon id // addon_size = generate_equipment_addon_buffer_2(DT_WEAPON_ESSENCE, (int*)&(ess->addons[0]), sizeof(int)+sizeof(float),32, addon_buf,addon_num); List addon_list = ess.addons.Select(a => (int)a.id_addon).ToList(); addon_size = itemdataman.generate_equipment_addon_buffer_2(DATA_TYPE.DT_WEAPON_ESSENCE, addon_list, addon_buf,0, ref addon_num); } else { if(addon_num > 0 || normal_addon == GEN_ADDON_MODE.ADDON_LIST_SPEC) { List unique_list = ess.uniques.Select(a => (int)a.id_unique).ToList(); List produce_list = ess.rands.Select(a => (int)a.id_rand).ToList(); List addons_list = ess.addons.Select(a => (int)a.id_addon).ToList(); itemdataman.generate_template_addon( DATA_TYPE.DT_WEAPON_ESSENCE,ess.probability_unique, unique_list,produce_list,addons_list, addon_buf,ref addon_num,ref addon_size,cls,normal_addon,sa_list); } else { if (normal_addon == GEN_ADDON_MODE.ADDON_LIST_SPEC) { addon_size = itemdataman.generate_spec_addon_buffer(DATA_TYPE.DT_WEAPON_ESSENCE,addon_buf,0,itemdataman.ELEMENTDATAMAN_MAX_NUM_ADDONS, ref addon_num,sa_list); } } } size += addon_size; // allocate the buffer with exact length // *data = (char *)abase::fastalloc(size); data = new byte[size]; //byte[] buf = data; int offset = 0; // *(unsigned int*)buf = id; buf += sizeof(unsigned int); //��Ʒ��ģ��ID // *(size_t*)buf = 1; buf += sizeof(size_t); //��Ʒ������ // *(size_t*)buf = ess->pile_num_max; buf += sizeof(size_t); //��Ʒ�Ķѵ����� // *(int*)buf = ELEMENTDATAMAN_EQUIP_MASK_WEAPON|(addon_num?0x40000000:0); buf += sizeof(int); //��Ʒ�Ŀ�װ����־���̶�ֵ���� // *(int*)buf = ess->proc_type; buf += sizeof(int); //��Ʒ�Ĵ�����ʽ // *(int*)buf = DT_WEAPON_ESSENCE; buf += sizeof(int); //��Ʒ��Ӧ�����ID WriteUInt(data, ref offset, id); WriteUInt(data, ref offset, 1); WriteInt(data, ref offset, ess.pile_num_max); WriteInt(data, ref offset,(int)(itemdataman.ELEMENTDATAMAN_EQUIP_MASK_WEAPON|(addon_num>0?0x40000000:0))); WriteUInt(data, ref offset, ess.proc_type); WriteInt(data, ref offset, (int)DATA_TYPE.DT_WEAPON_ESSENCE); // if(ess->has_guid == 1){ // int g1,g2; // get_item_guid(id,g1,g2); // *(int*)buf = g1; buf += sizeof(int); //��Ʒ��Ӧ�����ID guid // *(int*)buf = g2; buf += sizeof(int); //��Ʒ��Ӧ�����ID guid // } // else{ // *(int*)buf = 0; buf += sizeof(int); //��Ʒ��Ӧ�����ID guid // *(int*)buf = 0; buf += sizeof(int); //��Ʒ��Ӧ�����ID guid // } // *(int*)buf = ess->price; buf += sizeof(int); //��Ʒ�ļ۸� // *(int*)buf = 0; buf += sizeof(int); //����ʱ�� if(ess.has_guid == 1) { int g1,g2; itemdataman.get_item_guid(id,out g1,out g2); WriteInt(data, ref offset, g1); WriteInt(data, ref offset, g2); } else { WriteInt(data, ref offset, 0); WriteInt(data, ref offset, 0); } WriteInt(data, ref offset, ess.price); WriteInt(data, ref offset, 0); // size_t* content_length = (size_t*)buf; buf += sizeof(size_t); //��סbuf��ָ�룬�Ժ����� // char ** item_content = (char **)buf; buf += sizeof(char *); //��סbuf��ָ�룬�Ժ����� // *item_content = buf; // *content_length = (char *)(*data)+size-buf; // Then content_length store the length of the content. // The item_content store the position of the start point of the content. // Skip content_length and item_content pointer. So the remain is the content. // After that we can calculate the content_length and item_content pointer. int content_length = 0; int content_length_ptr = offset; WriteInt(data, ref offset, 0); int item_content = offset; WriteInt(data, ref offset, 0); content_length = (int)(size - offset); WriteInt(data, ref content_length_ptr, content_length); WriteInt(data, ref item_content, offset); // prerequisition // char * require_ptr = buf; // *(short*)buf = ess->require_level; buf += sizeof(short); //prerequisition level // *(short*)buf = ess->character_combo_id&0xFFFF; buf += sizeof(short); //prerequisition race // *(short*)buf = ess->require_strength; buf += sizeof(short); //prerequisition strength // *(short*)buf = ess->require_tili; buf += sizeof(short); //prerequisition val // *(short*)buf = ess->require_agility; buf += sizeof(short); //prerequisition agility // *(short*)buf = ess->require_energy; buf += sizeof(short); //prerequisition energy int require_ptr = offset; WriteShort(data, ref offset, (short)ess.require_level); WriteShort(data, ref offset, (short)(ess.character_combo_id&0xFFFF)); WriteShort(data, ref offset, (short)ess.require_strength); WriteShort(data, ref offset, (short)ess.require_tili); WriteShort(data, ref offset, (short)ess.require_agility); WriteShort(data, ref offset, (short)ess.require_energy); // int temp2 = element_data::RandNormal(ess->durability_min, ess->durability_max, cls,element_data::LOWER_TREND); // int temp; // if(normal_addon != element_data::ADDON_LIST_DROP || ess->proc_type & 0x1000) // { // temp = temp2; // } // else // { // temp = element_data::RandNormal(ess->durability_drop_min, ess->durability_drop_max, cls,element_data::UPPER_TREND); // if(temp > temp2) temp = temp2; // } int temp2 = element_data.RandNormal_NORMAL_LOWER(ess.durability_min, ess.durability_max, NORMAL.NORMAL_RAND, LOWER.LOWER_TREND); int temp = temp2; if(normal_addon != GEN_ADDON_MODE.ADDON_LIST_DROP || (ess.proc_type & 0x1000) != 0) { temp = temp2; } else { temp = element_data.RandNormal_NORMAL_UPPER(ess.durability_drop_min, ess.durability_drop_max, NORMAL.NORMAL_RAND, UPPER.UPPER_TREND); if(temp > temp2) temp = temp2; } // *(int*)buf = temp; buf += sizeof(int); //prerequisition durability // *(int*)buf = temp2; buf += sizeof(int); //prerequisition max_durability WriteInt(data, ref offset, temp); // durability WriteInt(data, ref offset, temp2); // max_durability // //���������߱�ǩע���ǩ���ڱ����С�ͱ�������֮�� // *(short*)buf = sizeof(_weapon_essence); buf += sizeof(short); //װ�������С���ֽڣï¿? // memcpy(buf,tag,tag_size); // buf += tag_size; WriteShort(data, ref offset, (short)Marshal.SizeOf(typeof(_weapon_essence))); WriteTag(data, ref offset, tag); //essence //char ����[]; //ÿ�ֲ�ͬװ���ı���ṹ��Í? // char * essence_ptr = buf; int essence_ptr = offset; // switch(ess->short_range_mode) // { // default: // case 0: *(short*)buf = 1; break; //Զ�� // case 1: *(short*)buf = 0; break; //���� // case 2: *(short*)buf = 2; break; //�̿ͽ��� // } // buf += sizeof(short); //������ï¿? ��Ӧģ����Ľ���Զ�̱�Ö? switch(ess.short_range_mode) { default: case 0: WriteShort(data, ref offset, (short)1); break; case 1: WriteShort(data, ref offset, (short)0); break; case 2: WriteShort(data, ref offset, (short)2); break; } // *(short*)buf = 0; buf += sizeof(short); //���ֵ����ʹ�ï¿? // *(int*)buf = ess->id_major_type; buf += sizeof(int); //�������� ��Ӧģ����Ĵ��ï¿? ���絶�� ������ // *(int*)buf = ess->level; buf += sizeof(int); //�������� ijЩ������Ҫ�������� // *(int*)buf = ess->require_projectile; buf += sizeof(int); //��Ҫ��ҩ������ // *(int*)buf = ess->damage_low; buf += sizeof(int); //����������С��ֵ // *(int*)buf = element_data::RandNormal(ess->damage_high_min, ess->damage_high_max, cls,element_data::LOWER_TREND); buf += sizeof(int); //������������ֵ // *(int*)buf = ess->magic_daage_low; buf += sizeof(int); //ħ���������Ö? // *(int*)buf = element_data::RandNormal(ess->magic_damage_high_min, ess->magic_damage_high_max, cls,element_data::LOWER_TREND); buf += sizeof(int); //ħ������ WriteShort(data, ref offset, (short)0); WriteUInt(data, ref offset, ess.id_major_type); WriteInt(data, ref offset, ess.level); WriteUInt(data, ref offset, ess.require_projectile); WriteInt(data, ref offset, ess.damage_low); WriteInt(data, ref offset, element_data.RandNormal_NORMAL_LOWER(ess.damage_high_min, ess.damage_high_max, NORMAL.NORMAL_RAND, LOWER.LOWER_TREND)); WriteInt(data, ref offset, ess.magic_damage_low); WriteInt(data, ref offset, element_data.RandNormal_NORMAL_LOWER(ess.magic_damage_high_min, ess.magic_damage_high_max, NORMAL.NORMAL_RAND, LOWER.LOWER_TREND)); // WEAPON_SUB_TYPE * subtype = (WEAPON_SUB_TYPE * )get_data_ptr(ess->id_sub_type, ID_SPACE_ESSENCE, datatype); // if(subtype == NULL || datatype != DT_WEAPON_SUB_TYPE) // { // // assert(false); // *(int*)buf = 0; buf += sizeof(int); // } // else // { // unsigned int index = element_data::RandSelect(&(subtype->probability_fastest), sizeof(float), 5, cls,element_data::MIDDLE_TREND); // *(int*)buf = (int)(subtype->attack_speed*20.f + 0.1f) + (index - 2); buf += sizeof(int); //ģ���е���0.05���Ö? // } WEAPON_SUB_TYPE subtype = new WEAPON_SUB_TYPE(); object sub_type_temp = itemdataman._edm.get_data_ptr(ess.id_sub_type, ID_SPACE.ID_SPACE_ESSENCE, ref datatype); if(sub_type_temp == null || datatype != DATA_TYPE.DT_WEAPON_SUB_TYPE) { WriteInt(data, ref offset, 0); } else { subtype = (WEAPON_SUB_TYPE)sub_type_temp; float[] probability_attack_speed = { subtype.probability_fastest, subtype.probability_fast, subtype.probability_normal, subtype.probability_slow, subtype.probability_slowest }; int index = element_data.RandSelect_SPECIFIC_MIDDLE(probability_attack_speed.ToList(), SPECIFIC.SPECIFIC_RAND, MIDDLE.MIDDLE_TREND); WriteInt(data, ref offset, (int)(subtype.attack_speed*20f + 0.1f) + (index - 2)); } // *(float*)buf = ess->attack_range; buf += sizeof(float); // *(float*)buf = subtype->attack_short_range; buf += sizeof(float); // *(short*)buf = hole_num; buf += sizeof(short); //�׶�����Ŀ // *(short*)buf = 0; buf += sizeof(short); //�׶��������������� // for(i=0; i>13)*sizeof(int)+sizeof(int); // } addon_data addon_data = new addon_data(); prerequisition prerequisition = new prerequisition(); for(i = 0; i < addon_num; i++) { int addon_id; ReadInt(addon_buf, ref addon_sld, out addon_id); ReadAddonData(addon_buf, ref addon_sld, out addon_data); ReadPrerequisition(addon_buf, ref require_ptr, out prerequisition); itemdataman.addon_update_ess_data(addon_data, essence_ptr, Marshal.SizeOf(typeof(_weapon_essence)), prerequisition); addon_sld += ((addon_id & 0x6000)>>13)*sizeof(int)+sizeof(int); } // memcpy(buf, addon_buf, addon_size); // set_to_classid(DT_WEAPON_ESSENCE, (item_data*)(*data), -1); itemdataman.update_require_data(prerequisition); WriteAddonData(data, ref offset, addon_data); itemdataman.set_to_classid(DATA_TYPE.DT_WEAPON_ESSENCE, data, -1); return 0; } private static void WriteUInt(byte[] buf, ref int offset, uint value) { Array.Copy(BitConverter.GetBytes(value), 0, buf, offset, 4); offset = offset + 4; } private static void WriteInt(byte[] buf, ref int offset, int value) { Array.Copy(BitConverter.GetBytes(value), 0, buf, offset, 4); offset = offset + 4; } private static void WriteShort(byte[] buf, ref int offset, short value) { Array.Copy(BitConverter.GetBytes(value), 0, buf, offset, 2); offset = offset + 2; } private static void WriteFloat(byte[] buf, ref int offset, float value) { Array.Copy(BitConverter.GetBytes(value), 0, buf, offset, 4); offset = offset + 4; } private static void WriteTag(byte[] buf, ref int offset, item_tag_t tag) { Array.Copy(BitConverter.GetBytes(tag.type), 0, buf, offset, 1); offset = offset + 1; Array.Copy(BitConverter.GetBytes(tag.size), 0, buf, offset, 1); offset = offset + 1; } private static void WriteAddonData(byte[] buf, ref int offset, addon_data value) { WriteInt(buf, ref offset, value.id); for(int i = 0; i < 3; i++) { WriteInt(buf, ref offset, value.arg[i]); } } private static void ReadInt(byte[] buf, ref int offset, out int value) { value = BitConverter.ToInt32(buf, offset); offset = offset + 4; } private static void ReadAddonData(byte[] buf, ref int offset, out addon_data value) { value = new addon_data(); value.id = BitConverter.ToInt32(buf, offset); offset = offset + 4; value.arg = new int[3]; for(int i = 0; i < 3; i++) { value.arg[i] = BitConverter.ToInt32(buf, offset); offset = offset + 4; } } private static void ReadPrerequisition(byte[] buf, ref int offset, out prerequisition value) { value = new prerequisition(); value.level = BitConverter.ToInt16(buf, offset); offset = offset + 2; value.race = BitConverter.ToInt16(buf, offset); offset = offset + 2; value.strength = BitConverter.ToInt16(buf, offset); offset = offset + 2; } }