Files
test/Assets/PerfectWorld/Scripts/Common/DataProcess/generate_item_temp.cs
T
2026-01-12 15:52:09 +07:00

1234 lines
57 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using BrewMonster.ELEMENT_DATA;
using ModelRenderer.Scripts.GameData;
using BrewMonster;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Linq;
using System;
using BrewMonster.abase;
public static class generate_item_temp
{
public static int generate_weapon<RAND_CLASS>(uint id, ID_SPACE idspace, out byte[] data, out uint size, RAND_CLASS cls,
GEN_ADDON_MODE normal_addon ,item_tag_t tag,List<int> 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 = (uint)element_data.RandSelect<RAND_CLASS, LOWER>(drop_probability_socket.ToList(), cls, 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 = (uint)element_data.RandSelect<RAND_CLASS, LOWER>(make_probability_socket.ToList(), cls, LOWER.LOWER_TREND); //׶Ŀ
}
size += hole_num*sizeof(int); // size hole_numtype
//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 };
//log each probability_addon_num
uint addon_num = (uint)element_data.RandSelect<RAND_CLASS, LOWER>(probability_addon_num.ToList(), cls, LOWER.LOWER_TREND); //ԱĿĿ
uint addon_size = 0;
// if(ess->fixed_props)
// {
// addon_size = generate_equipment_addon_buffer_2(DT_WEAPON_ESSENCE, (int*)&(ess->addons[0]), sizeof(int)+sizeof(float),32, addon_buf,addon_num);
// }
// else
// {
// if(addon_num || normal_addon == element_data::ADDON_LIST_SPEC)
// {
// generate_template_addon(DT_WEAPON_ESSENCE,ess->probability_unique,
// (char*)ess->uniques,(char*)ess->rands,(char*)ess->addons,
// addon_buf,addon_num,addon_size,cls,normal_addon,sa_list);
// }
// else
// {
// if (normal_addon == element_data::ADDON_LIST_SPEC)
// {
// addon_size = generate_spec_addon_buffer(DT_WEAPON_ESSENCE,addon_buf,ELEMENTDATAMAN_MAX_NUM_ADDONS,addon_num,sa_list);
// }
// }
// }
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<int> 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, addon_num);
}
else
{
if(addon_num > 0 || normal_addon == GEN_ADDON_MODE.ADDON_LIST_SPEC)
{
List<int> unique_list = ess.uniques.Select(a => (int)a.id_unique).ToList();
List<int> produce_list = ess.rands.Select(a => (int)a.id_rand).ToList();
List<int> 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, 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<RAND_CLASS, LOWER>(ess.durability_min, ess.durability_max, cls, 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<RAND_CLASS, UPPER>(ess.durability_drop_min, ess.durability_drop_max, cls, 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)));
WriteByte(data, ref offset, tag.type); // MadeFrom
WriteByte(data, ref offset, (byte)tag.size);
//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<RAND_CLASS, LOWER>(ess.damage_high_min, ess.damage_high_max, cls, LOWER.LOWER_TREND));
WriteInt(data, ref offset, ess.magic_damage_low);
WriteInt(data, ref offset, element_data.RandNormal<RAND_CLASS, LOWER>(ess.magic_damage_high_min, ess.magic_damage_high_max, cls, 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<RAND_CLASS, MIDDLE>(probability_attack_speed.ToList(), cls, 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<hole_num; i++)
// {
// *(int*)buf = 0; buf += sizeof(int); //׶Ƕͣûж?0
// }
WriteFloat(data, ref offset, ess.attack_range);
WriteFloat(data, ref offset, subtype.attack_short_range);
WriteShort(data, ref offset, (short)hole_num);
WriteShort(data, ref offset, (short)0);
for(i = 0; i < hole_num; i++)
{
WriteInt(data, ref offset, 0);
}
// addons
// *(int*)buf = addon_num; buf += sizeof(int);
WriteInt(data, ref offset, (int)addon_num);
// char * addon_sld = addon_buf;
int addon_sld = offset;
// for(i=0; i<addon_num; i++)
// {
// int id = *(int*)addon_sld;
// addon_update_ess_data(*(addon_data*)addon_sld, essence_ptr, sizeof(_weapon_essence), (prerequisition*)require_ptr);
// addon_sld += ((id & 0x6000)>>13)*sizeof(int)+sizeof(int);
// }
addon_data addon_data = new addon_data();
prerequisition prerequisition = new prerequisition();
// Read prerequisition from data buffer (where it was written) once before the loop
int require_ptr_copy = require_ptr;
ReadPrerequisition(data, ref require_ptr_copy, out prerequisition);
for(i = 0; i < addon_num; i++)
{
ReadInt(addon_buf, ref addon_sld, out addon_data.id);
ReadAddonData(addon_buf, ref addon_sld, out addon_data);
itemdataman.addon_update_ess_data(addon_data, essence_ptr, Marshal.SizeOf(typeof(_weapon_essence)), prerequisition);
addon_sld += ((addon_data.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(ref prerequisition);
// Write updated prerequisition back to data buffer
int require_ptr_write = require_ptr;
WritePrerequisition(data, ref require_ptr_write, prerequisition);
// Copy the entire addon buffer instead of writing a single addon_data
if(addon_size > 0)
{
Array.Copy(addon_buf, 0, data, offset, (int)addon_size);
offset += (int)addon_size;
}
itemdataman.set_to_classid(DATA_TYPE.DT_WEAPON_ESSENCE, data, -1);
return 0;
}
private static void generate_magic_defense<RAND_CLASS>(int[] res, List<ARMOR_ESSENCE.MagicDefence> res_list , RAND_CLASS cls,
bool b_fixed = false) //
{
float[] count_prop = {0.35f,0.25f,0.20f,0.15f,0.05f,0.051f};
float[] md_adjust = {1.0f,1.1f,1.3f,1.6f,2.0f};
int RE_num = 0;
if(!b_fixed)
{
RE_num = element_data.RandSelect<RAND_CLASS, LOWER>(count_prop.ToList(), cls, LOWER.LOWER_TREND);
}
if(RE_num == 5) return;
// Ensure RE_num is within valid range for md_adjust array (0-4)
if(RE_num < 0 || RE_num >= md_adjust.Length)
{
return;
}
int[] md = {0,1,2,3,4};
for(int i = 0; i < RE_num; i++)
{
int r = abase.Rand(i,4);
int t = md[i];
md[i] = md[r];
md[r] = t;
}
float adj = md_adjust[RE_num];
for(int i = 0; i < 5 - RE_num; i++)
{
int index = md[i];
// Check if res_list has enough elements (need at least index*2+2 elements for low and high)
if(res_list == null || res_list.Count < (index * 2 + 2))
{
// Skip this index if not enough data
continue;
}
int low = res_list[index *2].low;
int high= res_list[index *2+1].high;
res[index] = (int)(element_data.RandNormal<RAND_CLASS, LOWER>(low, high, cls, LOWER.LOWER_TREND) * adj);
}
}
public static int generate_armor<RAND_CLASS>(uint id, ID_SPACE idspace, out byte[] data, out uint size, RAND_CLASS cls,
GEN_ADDON_MODE normal_addon ,item_tag_t tag,List<int> 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_ARMOR_ESSENCE)
{
return -1;
}
ARMOR_ESSENCE ess = (ARMOR_ESSENCE)obj;
size =(uint) (Marshal.SizeOf(typeof(item_data)) + Marshal.SizeOf(typeof(_item_content)) + Marshal.SizeOf(typeof(ARMOR_ESSENCE)));
data = new byte[size];
int offset = 0;
short 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 = (short)element_data.RandSelect<RAND_CLASS, LOWER>(drop_probability_socket.ToList(), cls, 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 = (short)element_data.RandSelect<RAND_CLASS, MIDDLE>(make_probability_socket.ToList(), cls, MIDDLE.MIDDLE_TREND); //׶Ŀ
}
size += (uint)(hole_num*sizeof(int)); // size hole_numtype
size += (uint)Marshal.SizeOf(typeof(item_tag_t));
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 };
uint addon_num = (uint)element_data.RandSelect<RAND_CLASS, LOWER>(probability_addon_num.ToList(), cls, LOWER.LOWER_TREND); //ԱĿĿ
uint addon_size = 0;
if(ess.fixed_props!=0)
{
List<int> addon_list = ess.addons.Select(a => (int)a.id_addon).ToList();
addon_size = itemdataman.generate_equipment_addon_buffer_2(DATA_TYPE.DT_ARMOR_ESSENCE, addon_list, addon_buf,0, addon_num);
}
else
{
if(normal_addon == GEN_ADDON_MODE.ADDON_LIST_DROP)
{
List<int> addon_list = ess.addons.Select(a => (int)a.id_addon).ToList();
addon_size = itemdataman.generate_equipment_addon_buffer(DATA_TYPE.DT_ARMOR_ESSENCE, addon_list, (int)candidate_num, addon_buf,0, addon_num);
}
else if(normal_addon == GEN_ADDON_MODE.ADDON_LIST_PRODUCE)
{
List<int> addon_list = ess.rands.Select(a => (int)a.id_rand).ToList();
addon_size = itemdataman.generate_equipment_addon_buffer(DATA_TYPE.DT_ARMOR_ESSENCE, addon_list, (int)candidate_num, addon_buf,0, addon_num);
}
else if(normal_addon == GEN_ADDON_MODE.ADDON_LIST_SPEC)
{
addon_size = itemdataman.generate_spec_addon_buffer(DATA_TYPE.DT_ARMOR_ESSENCE,addon_buf,0,itemdataman.ELEMENTDATAMAN_MAX_NUM_ADDONS, addon_num,sa_list);
}
else
{
addon_size = 0;
addon_num = 0;
}
}
size += addon_size;
data = new byte[size];
WriteUInt(data, ref offset, id);
WriteUInt(data, ref offset, 1);
WriteInt(data, ref offset, ess.pile_num_max);
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_ARMOR_SUB_TYPE)
{
return -1;
}
else
{
ARMOR_SUB_TYPE sub_type = (ARMOR_SUB_TYPE)sub_type_temp;
WriteUInt(data, ref offset, sub_type.equip_mask|((addon_num > 0)?itemdataman.ELEMENTDATAMAN_EQUIP_MASK_HAS_ADDON:0));
}
WriteUInt(data, ref offset, ess.proc_type);
WriteInt(data, ref offset, (int)DATA_TYPE.DT_ARMOR_ESSENCE);
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);
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);
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<RAND_CLASS, LOWER>(ess.durability_min, ess.durability_max, cls, 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<RAND_CLASS, UPPER>(ess.durability_drop_min, ess.durability_drop_max, cls, UPPER.UPPER_TREND);
if(temp > temp2) temp = temp2;
}
WriteInt(data, ref offset, temp); // durability
WriteInt(data, ref offset, temp2); // max_durability
WriteShort(data, ref offset, (short)Marshal.SizeOf(typeof(ARMOR_ESSENCE)));
WriteByte(data, ref offset, (byte)tag.type); // MadeFrom
WriteByte(data, ref offset, (byte)tag.size);
int essence_ptr = offset;
WriteInt(data, ref offset, element_data.RandNormal<RAND_CLASS, LOWER>(ess.defence_low, ess.defence_high, cls, LOWER.LOWER_TREND));
WriteInt(data, ref offset, element_data.RandNormal<RAND_CLASS, LOWER>(ess.armor_enhance_low, ess.armor_enhance_high, cls, LOWER.LOWER_TREND));
WriteInt(data, ref offset, element_data.RandNormal<RAND_CLASS, LOWER>(ess.mp_enhance_low, ess.mp_enhance_high, cls, LOWER.LOWER_TREND));
WriteInt(data, ref offset, element_data.RandNormal<RAND_CLASS, LOWER>(ess.hp_enhance_low, ess.hp_enhance_high, cls, LOWER.LOWER_TREND));
int[] res = {0,0,0,0,0};
List<ARMOR_ESSENCE.MagicDefence> res_list = ess.magic_defences.ToList();
generate_magic_defense(res, res_list, cls, ess.force_all_magic_defences != 0 || ess.fixed_props!=0);
WriteInt(data, ref offset, res[0]);
WriteInt(data, ref offset, res[1]);
WriteInt(data, ref offset, res[2]);
WriteInt(data, ref offset, res[3]);
WriteInt(data, ref offset, res[4]);
WriteShort(data, ref offset, hole_num);
WriteShort(data, ref offset, 0);
for(i = 0; i < hole_num; i++)
{
WriteInt(data, ref offset, 0);
}
WriteInt(data, ref offset, (int)addon_num);
int addon_sld = offset;
addon_data addon_data = new addon_data();
prerequisition prerequisition = new prerequisition();
// Read prerequisition from data buffer (where it was written) once before the loop
int require_ptr_copy_armor = require_ptr;
ReadPrerequisition(data, ref require_ptr_copy_armor, out prerequisition);
for(i = 0; i < addon_num; i++)
{
ReadInt(addon_buf, ref addon_sld, out addon_data.id);
ReadAddonData(addon_buf, ref addon_sld, out addon_data);
itemdataman.addon_update_ess_data(addon_data, essence_ptr, Marshal.SizeOf(typeof(_weapon_essence)), prerequisition);
addon_sld += ((addon_data.id & 0x6000)>>13)*sizeof(int)+sizeof(int);
}
itemdataman.update_require_data(ref prerequisition);
// Write updated prerequisition back to data buffer
int require_ptr_write_armor = require_ptr;
WritePrerequisition(data, ref require_ptr_write_armor, prerequisition);
if(addon_size > 0)
{
Array.Copy(addon_buf, 0, data, offset, (int)addon_size);
offset += (int)addon_size;
}
itemdataman.set_to_classid(DATA_TYPE.DT_ARMOR_ESSENCE, data, -1);
return 0;
}
public static int generate_tasknormalmatter<RAND_CLASS>(uint id, ID_SPACE idspace, out byte[] data, out uint size, RAND_CLASS cls,
GEN_ADDON_MODE normal_addon ,item_tag_t tag,List<int> sa_list = null)
{
// DATA_TYPE datatype;
DATA_TYPE datatype = DATA_TYPE.DT_INVALID;
data = new byte[0];
size = 0;
int i=0;
// TASKNORMALMATTER_ESSENCE * ess = (TASKNORMALMATTER_ESSENCE *)get_data_ptr(id, idspace, datatype);
object obj = itemdataman._edm.get_data_ptr(id, idspace,ref datatype);
if(obj == null || datatype != DATA_TYPE.DT_TASKNORMALMATTER_ESSENCE)
{
return -1;
}
TASKNORMALMATTER_ESSENCE ess = (TASKNORMALMATTER_ESSENCE)obj;
size =(uint) (Marshal.SizeOf(typeof(item_data)) + Marshal.SizeOf(typeof(TASKNORMALMATTER_ESSENCE)));
data = new byte[size];
int offset = 0;
WriteUInt(data, ref offset, ess.id);
WriteUInt(data, ref offset, 1);
WriteInt(data, ref offset, ess.pile_num_max);
WriteInt(data, ref offset, 0);
WriteUInt(data, ref offset, ess.proc_type);
WriteInt(data, ref offset, (int)DATA_TYPE.DT_TASKNORMALMATTER_ESSENCE);
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);
int content_length;
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);
itemdataman.set_to_classid(DATA_TYPE.DT_TASKNORMALMATTER_ESSENCE, data, -1);
return 0;
}
#region Write Functions
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)
{
buf[offset] = tag.type;
offset = offset + 1;
buf[offset] = tag.size;
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 WriteByte(byte[] buf, ref int offset, byte value)
{
buf[offset] = value;
offset = offset + 1;
}
#endregion
#region Read Functions
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;
value.vitality = BitConverter.ToInt16(buf, offset);
offset = offset + 2;
value.agility = BitConverter.ToInt16(buf, offset);
offset = offset + 2;
value.energy = BitConverter.ToInt16(buf, offset);
offset = offset + 2;
value.durability = BitConverter.ToInt32(buf, offset);
offset = offset + 4;
value.max_durability = BitConverter.ToInt32(buf, offset);
offset = offset + 4;
}
private static void WritePrerequisition(byte[] buf, ref int offset, prerequisition value)
{
WriteShort(buf, ref offset, value.level);
WriteShort(buf, ref offset, value.race);
WriteShort(buf, ref offset, value.strength);
WriteShort(buf, ref offset, value.vitality);
WriteShort(buf, ref offset, value.agility);
WriteShort(buf, ref offset, value.energy);
WriteInt(buf, ref offset, value.durability);
WriteInt(buf, ref offset, value.max_durability);
}
#endregion
private static void PrintData(byte[] buf, int offset, int size)
{
for(int i = offset; i < offset + size; i++)
{
BMLogger.Log("[thn]PrintData: buf[" + i + "]: " + buf[i]);
}
}
private static void PrintPreData(byte[] buf, int offset, int size)
{
for(int i = offset-1; i >= offset - size; i--)
{
BMLogger.Log("[thn]PrintPreData: buf[" + i + "]: " + buf[i]);
}
}
}
#region unimplemented
// template <typename RAND_CLASS>
// int generate_projectile(unsigned int id, ID_SPACE idspace, char ** data, size_t& size, RAND_CLASS cls)
// {
// DATA_TYPE datatype;
// PROJECTILE_ESSENCE * ess = (PROJECTILE_ESSENCE *)get_data_ptr(id, idspace, datatype);
// if(ess == NULL || datatype != DT_PROJECTILE_ESSENCE) return -1;
// size = sizeof(item_data) + sizeof(_item_content) + sizeof(_projectile_essence);
// // ޿׶
// // ̶addons 4
// char addon_buf[ELEMENTDATAMAN_MAX_NUM_ADDONS*sizeof(_addon)];
// unsigned int addon_num = 4; //ԱĿĿ̶ 4
// size_t addon_size = generate_equipment_addon_buffer_2(DT_PROJECTILE_ESSENCE, (int*)&(ess->id_addon0),sizeof(int), 4, addon_buf,addon_num);
// size += addon_size;
// //tag size
// size += sizeof(short);
// // allocate the buffer with exact length
// *data = (char *)abase::fastalloc(size);
// char * buf = *data;
// *(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_PROJECTILE|(addon_num?0x40000000:0); buf += sizeof(int); //ƷĿװ־
// *(int*)buf = ess->proc_type; buf += sizeof(int); //ƷĴʽ
// *(int*)buf = DT_PROJECTILE_ESSENCE; buf += sizeof(int); //ƷӦID
// 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); //ʱ
// size_t* content_length = (size_t*)buf; buf += sizeof(size_t); //סbufָԺ
// char ** item_content = (char **)buf; buf += sizeof(char *); //סbufָԺ
// *content_length = (char*)(*data)+size-buf;
// *item_content = buf;
// // prerequisition
// char * require_ptr = buf;
// //int6
// *(short*)buf = 0; buf += sizeof(short); //prerequisition level
// *(short*)buf = (short)0xFFFF; buf += sizeof(short);
// *(short*)buf = 0; buf += sizeof(short); //prerequisition strength
// *(short*)buf = 0; buf += sizeof(short);
// *(short*)buf = 0; buf += sizeof(short); //prerequisition agility
// *(short*)buf = 0; buf += sizeof(short);
// *(int*)buf = 1; buf += sizeof(int); //prerequisition durability
// *(int*)buf = 1; buf += sizeof(int); //prerequisition max_durability
// *(short*)buf = sizeof(_projectile_essence); buf += sizeof(short); //װСֽڣ
// *(char*)buf = element_data::IMT_NULL;buf += sizeof(char);
// *(char*)buf = 0; buf += sizeof(char);
// // projectile_essence
// char * essence_ptr = buf;
// *(int*)buf = ess->type; buf += sizeof(int); //ҩ
// *(int*)buf = ess->damage_enhance; buf += sizeof(int); //Ĺ
// *(int*)buf = ess->damage_scale_enhance; buf += sizeof(int); //ձӹ
// *(int*)buf = ess->require_weapon_level_min; buf += sizeof(int); //Ҫȼ
// *(int*)buf = ess->require_weapon_level_max; buf += sizeof(int); //Ҫȼ
// // ׶
// *(short*)buf = 0; buf += sizeof(short);
// *(short*)buf = 0; buf += sizeof(short);
// // addon
// *(int*)buf = addon_num; buf += sizeof(int);
// char * addon_sld = addon_buf;
// for(size_t i=0; i<addon_num; i++)
// {
// int id = *(int*)addon_sld;
// addon_update_ess_data(*(addon_data*)addon_sld, essence_ptr, sizeof(_projectile_essence), (prerequisition*)require_ptr);
// addon_sld += ((id & 0x6000)>>13)*sizeof(int)+sizeof(int);
// }
// update_require_data((prerequisition*)require_ptr);
// memcpy(buf, addon_buf, addon_size);
// set_to_classid(DT_PROJECTILE_ESSENCE, (item_data*)(*data), -1);
// return 0;
// }
// template <typename RAND_CLASS>
// int generate_quiver(unsigned int id, ID_SPACE idspace, char ** data, size_t& size, RAND_CLASS cls)
// {
// DATA_TYPE datatype;
// QUIVER_ESSENCE * ess = (QUIVER_ESSENCE *)get_data_ptr(id, ID_SPACE_ESSENCE, datatype);
// if(ess == NULL || datatype != DT_QUIVER_ESSENCE) return -1;
// datatype = DT_PROJECTILE_ESSENCE;
// //dupʽ
// // if(generate_projectile(ess->id_projectile, ID_SPACE_ESSENCE, (char **)data, size, cls) == 0)
// int ret = duplicate_static_item(id, data,size);
// if(ret == 0)
// {
// ASSERT(ess->num_max < (int)((item_data*)(*data))->pile_limit);
// ((item_data*)(*data))->count = element_data::RandNormal(ess->num_min,ess->num_max,cls,element_data::LOWER_TREND);
// return 0;
// }
// else
// return -1;
// /* {
// ASSERT(ess->num_max < (int)((item_data*)(*data))->pile_limit);
// ((item_data*)(*data))->count = element_data::RandNormal<RAND_CLASS,element_data::LOWER>(ess->num_min,ess->num_max,cls);
// return 0;
// }
// else
// return -1;
// */
// }
// template <typename RAND_CLASS>
// int generate_quiver_for_sell(unsigned int id, ID_SPACE idspace, char ** data, size_t& size, RAND_CLASS cls)
// {
// DATA_TYPE datatype;
// QUIVER_ESSENCE * ess = (QUIVER_ESSENCE *)get_data_ptr(id, ID_SPACE_ESSENCE, datatype);
// if(ess == NULL || datatype != DT_QUIVER_ESSENCE) return -1;
// datatype = DT_PROJECTILE_ESSENCE;
// //޷dupΪ
// if(generate_projectile(ess->id_projectile, ID_SPACE_ESSENCE, (char **)data, size, cls) == 0)
// {
// ASSERT(ess->num_max < (int)((item_data*)(*data))->pile_limit);
// ((item_data*)(*data))->count = element_data::RandNormal(ess->num_min,ess->num_max,cls,element_data::LOWER_TREND);
// return 0;
// }
// else
// return -1;
// }
// template <typename RAND_CLASS>
// int generate_decoration(unsigned int id, ID_SPACE idspace, char ** data, size_t& size, RAND_CLASS cls,element_data::GEN_ADDON_MODE normal_addon,const void * tag,size_t tag_size, int * sa_list = NULL)
// {
// DATA_TYPE datatype;
// size_t i=0;
// DECORATION_ESSENCE * ess = (DECORATION_ESSENCE *)get_data_ptr(id, idspace, datatype);
// if(ess == NULL || datatype != DT_DECORATION_ESSENCE) return -1;
// size = sizeof(item_data) + sizeof(_item_content) + sizeof(_decoration_essence);
// // ׶
// unsigned int hole_num = 0; //׶Ŀ
// // addons
// char addon_buf[ELEMENTDATAMAN_MAX_NUM_ADDONS*sizeof(_addon)];
// unsigned int addon_num = element_data::RandSelect(&(ess->probability_addon_num0),sizeof(float), 5,cls,element_data::LOWER_TREND); //ԱĿĿ
// size_t addon_size = 0;
// if(ess->fixed_props)
// {
// addon_size = generate_equipment_addon_buffer_2(DT_DECORATION_ESSENCE, (int*)&(ess->addons[0]), sizeof(int)+sizeof(float),32, addon_buf,addon_num);
// }
// else
// {
// if(normal_addon == element_data::ADDON_LIST_DROP)
// addon_size = generate_equipment_addon_buffer(DT_DECORATION_ESSENCE, (char*)&(ess->addons[0]), 32, addon_buf,addon_num);
// else if(normal_addon == element_data::ADDON_LIST_PRODUCE)
// addon_size = generate_equipment_addon_buffer(DT_DECORATION_ESSENCE, (char*)&(ess->rands[0]), 32, addon_buf,addon_num);
// else if (normal_addon == element_data::ADDON_LIST_SPEC)
// {
// addon_size = generate_spec_addon_buffer(DT_DECORATION_ESSENCE,addon_buf,ELEMENTDATAMAN_MAX_NUM_ADDONS,addon_num,sa_list);
// }
// else
// {
// addon_size = 0;
// addon_num = 0;
// }
// }
// size += addon_size;
// //tag size
// ASSERT(tag_size >= sizeof(short));
// size += tag_size;
// // allocate the buffer with exact length
// *data = (char *)abase::fastalloc(size);
// char * buf = (*data);
// *(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); //ƷĶѵ
// DECORATION_SUB_TYPE* sub_type = (DECORATION_SUB_TYPE*)get_data_ptr(ess->id_sub_type, ID_SPACE_ESSENCE, datatype);
// if(sub_type == NULL || datatype != DT_DECORATION_SUB_TYPE) // error
// return -1;
// *(int*)buf = sub_type->equip_mask|(addon_num?ELEMENTDATAMAN_EQUIP_MASK_HAS_ADDON:0); buf += sizeof(int); //ƷĿװ־
// *(int*)buf = ess->proc_type; buf += sizeof(int); //ƷĴʽ
// *(int*)buf = DT_DECORATION_ESSENCE; buf += sizeof(int); //ƷӦID
// 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); //ʱ
// size_t* content_length = (size_t*)buf; buf += sizeof(size_t); //סbufָԺ
// char ** item_content = (char **)buf; buf += sizeof(char *); //סbufָԺ
// *content_length = (char*)(*data)+size-buf;
// *item_content = buf;
// // 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 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*)buf = temp; buf += sizeof(int); //prerequisition durability
// *(int*)buf = temp2; buf += sizeof(int); //prerequisition max_durability
// //߱ǩעǩڱСͱ֮
// *(short*)buf = sizeof(_decoration_essence); buf += sizeof(short); //װСֽڣ
// memcpy(buf,tag,tag_size);
// buf += tag_size;
// //
// char * essence_ptr = buf;
// *(int*)buf = element_data::RandNormal(ess->damage_low, ess->damage_high, cls,element_data::LOWER_TREND); buf += sizeof(int); //int damage;
// *(int*)buf = element_data::RandNormal(ess->magic_damage_low, ess->magic_damage_high, cls,element_data::LOWER_TREND); buf += sizeof(int); //int magic_damage;
// *(int*)buf = element_data::RandNormal(ess->defence_low, ess->defence_high, cls,element_data::LOWER_TREND); buf += sizeof(int); //int defense;
// *(int*)buf = element_data::RandNormal(ess->armor_enhance_low, ess->armor_enhance_high, cls,element_data::LOWER_TREND); buf += sizeof(int); //int armor;
// //
// int res[5] = {0,0,0,0,0};
// generate_magic_defense(res,(int*)(ess->magic_defences),cls,ess->fixed_props!=0);
// *(int*)buf = res[0]; buf += sizeof(int);
// *(int*)buf = res[1]; buf += sizeof(int);
// *(int*)buf = res[2]; buf += sizeof(int);
// *(int*)buf = res[3]; buf += sizeof(int);
// *(int*)buf = res[4]; buf += sizeof(int);
// // ׶
// *(short*)buf = hole_num; buf += sizeof(short); //׶Ŀ
// *(short*)buf = 0; buf += sizeof(short); //׶
// // addon
// *(int*)buf = addon_num; buf += sizeof(int);
// char * addon_sld = addon_buf;
// for(i=0; i<addon_num; i++)
// {
// int id = *(int*)addon_sld;
// addon_update_ess_data(*(addon_data*)addon_sld, essence_ptr, sizeof(_decoration_essence), (prerequisition*)require_ptr);
// addon_sld += ((id & 0x6000)>>13)*sizeof(int)+sizeof(int);
// }
// update_require_data((prerequisition*)require_ptr);
// memcpy(buf, addon_buf, addon_size);
// set_to_classid(DT_DECORATION_ESSENCE, (item_data*)(*data), -1);
// return 0;
// }
// template <typename RAND_CLASS>
// int generate_stone(unsigned int id, ID_SPACE idspace, char ** data, size_t& size, RAND_CLASS cls)
// {
// DATA_TYPE datatype;
// STONE_ESSENCE * ess = (STONE_ESSENCE *)get_data_ptr(id, idspace, datatype);
// if(ess == NULL || datatype != DT_STONE_ESSENCE) return -1;
// char addon_buf[ELEMENTDATAMAN_MAX_NUM_ADDONS*sizeof(_addon)];
// int *pBuf = (int*)addon_buf;
// *pBuf = 1; //only one weapon addon now
// size_t addon_size = generate_addon_buffer(datatype,ess->id_addon_damage, (char*)(pBuf + 1));
// if(addon_size)
// {
// pBuf = (int*)(((char*)(pBuf+1)) + addon_size);
// }
// else
// {
// ASSERT(false);
// return -1;
// }
// *pBuf = 1; //only one armor addon now
// addon_size = generate_addon_buffer(datatype,ess->id_addon_defence, (char*)(pBuf + 1));
// if(addon_size)
// {
// pBuf = (int*)(((char*)(pBuf+1)) + addon_size);
// }
// else
// {
// ASSERT(false);
// return -1;
// }
// size_t ess_size = ((char*)pBuf) - addon_buf;
// size = sizeof(item_data) + ess_size;
// // allocate the buffer with exact length
// *data = (char *)abase::fastalloc(size);
// char *buf = *data;
// *(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 = 0; buf += sizeof(int); //ƷĿװ־
// *(int*)buf = ess->proc_type; buf += sizeof(int); //ƷĴʽ
// *(int*)buf = DT_STONE_ESSENCE; buf += sizeof(int); //ƷӦID
// *(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); //ʱ
// size_t* content_length = (size_t*)buf; buf += sizeof(size_t); //סbufָԺ
// char ** item_content = (char **)buf; buf += sizeof(char *); //סbufָԺ
// *content_length = size - (buf - (char*)(*data));
// *item_content = buf;
// memcpy(buf, addon_buf, ess_size);
// set_to_classid(DT_STONE_ESSENCE, (item_data*)(*data), -1);
// return 0;
// }
// template <typename RAND_CLASS>
// int generate_medicine(unsigned int id, ID_SPACE idspace, char ** data, size_t& size, RAND_CLASS cls)
// {
// DATA_TYPE datatype;
// MEDICINE_ESSENCE * ess = (MEDICINE_ESSENCE *)get_data_ptr(id, idspace, datatype);
// if(ess == NULL || datatype != DT_MEDICINE_ESSENCE) return -1;
// size = sizeof(item_data);
// switch(ess->id_major_type)
// {
// case 1794: // Ѫ
// case 1802: // ħ
// case 1810: // Ѫħ
// size += sizeof(size_t) + sizeof(int) + sizeof(int) + sizeof(int);
// break;
// case 1815: // ⶾҩ
// case 2038: // ˲ⶾҩ
// size += sizeof(int) + sizeof(int);
// break;
// default:
// return -1;
// }
// // allocate the buffer with exact length
// *data = (char *)abase::fastalloc(size);
// char * buf = (*data);
// *(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 = 0; buf += sizeof(int); //ƷĿװ־
// *(int*)buf = ess->proc_type; buf += sizeof(int); //ƷĴʽ
// *(int*)buf = DT_MEDICINE_ESSENCE; buf += sizeof(int); //ƷӦID
// 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); //ʱ
// size_t* content_length = (size_t*)buf; buf += sizeof(size_t); //סbufָԺ
// char ** item_content = (char **)buf; buf += sizeof(char *); //סbufָԺ
// *content_length = (char*)(*data)+size-buf;
// *item_content = buf;
// switch(ess->id_major_type)
// {
// case 1794: // Ѫ
// if(ess->cool_time < 1000) ess->cool_time *= 100;
// *(int*)buf = ess->hp_add_total; buf += sizeof(int);
// *(int*)buf = ess->hp_add_time; buf += sizeof(int);
// *(int*)buf = ess->cool_time; buf += sizeof(int);
// *(int*)buf = ess->require_level; buf += sizeof(int);
// ASSERT(ess->hp_add_time && ess->hp_add_total);
// ASSERT(ess->hp_add_total/ess->hp_add_time);
// break;
// case 1802: // ħ
// if(ess->cool_time < 1000) ess->cool_time *= 100;
// *(int*)buf = ess->mp_add_total; buf += sizeof(int);
// *(int*)buf = ess->mp_add_time; buf += sizeof(int);
// *(int*)buf = ess->cool_time; buf += sizeof(int);
// *(int*)buf = ess->require_level; buf += sizeof(int);
// ASSERT(ess->mp_add_time && ess->mp_add_total);
// ASSERT(ess->mp_add_total/ess->mp_add_time);
// break;
// case 1810: // Ѫħ
// if(ess->cool_time < 1000) ess->cool_time *= 100;
// *(int*)buf = ess->mp_add_total; buf += sizeof(int);
// *(int*)buf = ess->hp_add_total; buf += sizeof(int);
// *(int*)buf = ess->cool_time; buf += sizeof(int);
// *(int*)buf = ess->require_level; buf += sizeof(int);
// ASSERT(ess->hp_add_time || ess->mp_add_total);
// break;
// case 1815: // ⶾҩ
// case 2038: // ˲ⶾҩ
// if(ess->cool_time < 1000) ess->cool_time *= 100;
// *(int*)buf = ess->cool_time; buf += sizeof(int);
// *(int*)buf = ess->require_level; buf += sizeof(int);
// break;
// default:
// return -1;
// }
// set_to_classid(DT_MEDICINE_ESSENCE, (item_data*)(*data), ess->id_major_type);
// return 0;
// }
// template <typename ESSENCE >
// int generate_material(unsigned int id, ID_SPACE idspace, char ** data, size_t& size, ESSENCE * p, DATA_TYPE DTYPE)
// {
// DATA_TYPE datatype;
// ESSENCE * ess = (ESSENCE *)get_data_ptr(id, idspace, datatype);
// if(ess == NULL || datatype != DTYPE) return -1;
// size = sizeof(item_data) ;
// // allocate the buffer with exact length
// *data = (char *)abase::fastalloc(size);
// char * buf = (*data);
// *(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 = 0; buf += sizeof(int); //ƷĿװ־
// *(int*)buf = ess->proc_type; buf += sizeof(int); //ƷĴʽ
// *(int*)buf = DTYPE; buf += sizeof(int); //ƷӦID
// 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); //ʱ
// size_t* content_length = (size_t*)buf; buf += sizeof(size_t); //סbufָԺ
// char ** item_content = (char **)buf; buf += sizeof(char *); //סbufָԺ
// *content_length = (char*)(*data)+size-buf;
// *item_content = buf;
// set_to_classid(DTYPE, (item_data*)(*data), -1);
// return 0;
// }
// template <typename RAND_CLASS>
// int generate_skilltome(unsigned int id, ID_SPACE idspace, char ** data, size_t& size, RAND_CLASS cls)
// {
// DATA_TYPE datatype;
// SKILLTOME_ESSENCE * ess = (SKILLTOME_ESSENCE *)get_data_ptr(id, idspace, datatype);
// if(ess == NULL || datatype != DT_SKILLTOME_ESSENCE) return -1;
// size = sizeof(item_data);
// // allocate the buffer with exact length
// *data = (char *)abase::fastalloc(size);
// char * buf = (*data);
// *(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 = 0; buf += sizeof(int); //ƷĿװ־
// *(int*)buf = ess->proc_type; buf += sizeof(int); //ƷĴʽ
// *(int*)buf = DT_SKILLTOME_ESSENCE; buf += sizeof(int); //ƷӦID
// 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); //ʱ
// size_t* content_length = (size_t*)buf; buf += sizeof(size_t); //סbufָԺ
// char ** item_content = (char **)buf; buf += sizeof(char *); //סbufָԺ
// *content_length = (char*)(*data)+size-buf;
// *item_content = buf;
// set_to_classid(DT_SKILLTOME_ESSENCE, (item_data*)(*data), -1);
// return 0;
// }
#endregion