Files
test/Assets/PerfectWorld/Scripts/Common/DataProcess/generate_item_temp.cs
T
2025-12-30 10:19:18 +07:00

380 lines
19 KiB
C#

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<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 = 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;
// 锟斤拷锟絘ddons
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<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, ref 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, 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); //锟斤拷品锟斤拷应锟斤拷锟斤拷锟絀D
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); //锟斤拷品锟斤拷应锟斤拷锟斤拷锟絀D guid
// *(int*)buf = g2; buf += sizeof(int); //锟斤拷品锟斤拷应锟斤拷锟斤拷锟絀D guid
// }
// else{
// *(int*)buf = 0; buf += sizeof(int); //锟斤拷品锟斤拷应锟斤拷锟斤拷锟絀D guid
// *(int*)buf = 0; buf += sizeof(int); //锟斤拷品锟斤拷应锟斤拷锟斤拷锟絀D 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); //锟斤拷锟斤拷锟斤拷锟斤拷 某些锟斤拷锟斤拷锟斤拷要锟斤拷锟斤拷锟斤拷锟斤拷
// *(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<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();
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;
}
}