📄 m2character.cpp
字号:
texIndex = texFile.ReadInt32(index, CSV_HAND, -1);
if(texIndex != -1)
pTexGroup->AddTexture("Picture\\Hand.amf", texIndex, CR_HAND, layer);
texIndex = texFile.ReadInt32(index, CSV_TORSO_UPPER, -1);
if(texIndex != -1)
pTexGroup->AddTexture("Picture\\TorsoUpper.amf", texIndex, CR_TORSO_UPPER, layer);
texIndex = texFile.ReadInt32(index, CSV_TORSO_LOWER, -1);
if(texIndex != -1)
pTexGroup->AddTexture("Picture\\TorsoLower.amf", texIndex, CR_TORSO_LOWER, layer);
texIndex = texFile.ReadInt32(index, CSV_LEG_UPPER, -1);
if(texIndex != -1)
pTexGroup->AddTexture("Picture\\LegUpper.amf", texIndex, CR_LEG_UPPER, layer);
texIndex = texFile.ReadInt32(index, CSV_LEG_LOWER, -1);
if(texIndex != -1)
pTexGroup->AddTexture("Picture\\LegLower.amf", texIndex, CR_LEG_LOWER, layer);
texIndex = texFile.ReadInt32(index, CSV_FOOT, -1);
if(texIndex != -1)
pTexGroup->AddTexture("Picture\\Foot.amf", texIndex, CR_FOOT, layer);
if(slot == ES_CHEST)
{
texIndex = texFile.ReadInt32(index, CSV_GEOSET_A, -1);
if(texIndex != 0)
m_Geoset[0] = 800+1+texIndex;
else
m_Geoset[0] = 0;
texIndex = texFile.ReadInt32(index, CSV_GEOSET_B, -1);
if(texIndex != 0)
m_Geoset[1] = 1300+1+texIndex;
else
m_Geoset[1] = 0;
}
if(slot == ES_SHIRT)
{
texIndex = texFile.ReadInt32(index, CSV_GEOSET_A, -1);
if(texIndex != 0)
m_Geoset[0] = 800+1+texIndex;
else
m_Geoset[0] = 0;
}
if(slot == ES_PANTS)
{
texIndex = texFile.ReadInt32(index, CSV_GEOSET_B, -1);
if(texIndex != 0)
m_Geoset[1] = 1300+1+texIndex;
else
m_Geoset[1] = 0;
}
if(slot == ES_GLOVES)
{
texIndex = texFile.ReadInt32(index, CSV_GEOSET_C, -1);
if(texIndex != 0)
m_Geoset[2] = 400+1+texIndex;
else
m_Geoset[2] = 0;
}
if(slot == ES_BOOTS)
{
texIndex = texFile.ReadInt32(index, CSV_GEOSET_B, -1);
if(texIndex != 0)
m_Geoset[3] = 500+1+texIndex;
else
m_Geoset[3] = 0;
}
if(slot == ES_CAPE)
{
texIndex = texFile.ReadInt32(index, CSV_GEOSET_A, -1);
if(texIndex != -1)
{
ReleaseTexture(m_hCape);
m_hCape = g_pTextureManager->LoadAMFTexture("Picture\\Cape.amf", texIndex, MM_KEEPINMEMORY, 0);
}
texIndex = texFile.ReadInt32(index, CSV_GEOSET_B, -1);
if(texIndex != 0)
{
m_Geoset[4] = 1500+1+texIndex;
}
else
m_Geoset[4] = 0;
}
}
else
{
if(slot == ES_GLOVES) m_Geoset[2] = 0;
if(slot == ES_BOOTS) m_Geoset[3] = 0;
if(slot == ES_CAPE) m_Geoset[4] = 0;
}
}
//--------------------------------------------------
// Create Texture
//--------------------------------------------------
void M2Character::CreateTexture(void)
{
//--------------------------------------------------
// Reset All Character Sub Meshes
//--------------------------------------------------
for(size_t i=0; i<m_pCharacter->m_SubMesh.size(); i++)
{
m_pCharacter->m_bShowSubMesh[i] = (m_pCharacter->m_SubMesh[i].id)%100<2;
}
m_pCharacter->m_bShowSubMesh[12] = false; // Ears
m_pCharacter->m_bShowSubMesh[13] = false; // Bald Head
m_pCharacter->m_bShowSubMesh[12] = true; // Ears
// m_pCharacter->m_bShowSubMesh[20] = true; // Hair
//----------------------------------------------------
// texture
TextureGroup texgroup;
texgroup.AddTexture("Picture\\BaseSkin.amf", m_EquipmentIndex[ES_SKINCOLOR], CR_BASE, 0);
texgroup.AddTexture("Picture\\TorsoSkin.amf", m_EquipmentIndex[ES_SKINCOLOR], CR_TORSO_UPPER, 1);
texgroup.AddTexture("Picture\\PelvisSkin.amf", m_EquipmentIndex[ES_SKINCOLOR], CR_PELVIS_UPPER, 1);
texgroup.AddTexture("Picture\\FaceUpper.amf", m_EquipmentIndex[ES_SKINCOLOR]+m_EquipmentMax[ES_SKINCOLOR]*m_EquipmentIndex[ES_FACESTYLE], CR_FACE_UPPER, 1);
texgroup.AddTexture("Picture\\FaceLower.amf", m_EquipmentIndex[ES_SKINCOLOR]+m_EquipmentMax[ES_SKINCOLOR]*m_EquipmentIndex[ES_FACESTYLE], CR_FACE_LOWER, 1);
int texIndex = -1;
bool hasRobe = false;
// check if we have a robe on
if(m_EquipmentIndex[ES_CHEST] != 0)
{
CSVFile texFile("Picture\\Item.csv");
texIndex = texFile.ReadInt32(m_EquipmentIndex[ES_CHEST], CSV_GEOSET_B, 0);
if(texIndex == 1)
{
hasRobe = true;
m_pCharacter->m_bShowSubMesh[47] = false;
m_pCharacter->m_bShowSubMesh[50] = false;
}
}
if(m_EquipmentIndex[ES_PANTS] != 0)
{
CSVFile texFile("Picture\\Item.csv");
texIndex = texFile.ReadInt32(m_EquipmentIndex[ES_CHEST], CSV_GEOSET_B, 0);
if(texIndex == 1)
{
hasRobe = true;
m_pCharacter->m_bShowSubMesh[47] = false;
m_pCharacter->m_bShowSubMesh[50] = false;
}
}
// check the order of robe/gloves
SlotOrderWithRobe[7] = ES_CHEST;
SlotOrderWithRobe[8] = ES_GLOVES;
if(m_EquipmentIndex[ES_CHEST] && m_EquipmentIndex[ES_GLOVES])
{
CSVFile texFile("Picture\\Item.csv");
texIndex = texFile.ReadInt32(m_EquipmentIndex[ES_GLOVES], CSV_GEOSET_C, 0);
if(texIndex == 0)
{
SlotOrderWithRobe[7] = ES_GLOVES;
SlotOrderWithRobe[8] = ES_CHEST;
}
}
if(m_EquipmentIndex[ES_CHEST]==0 && m_EquipmentIndex[ES_SHIRT]==0)
{
m_Geoset[0] = 0;
}
if(hasRobe==false)
{
m_Geoset[1] = 0;
}
for(int i=ES_EQUITBASE; i<ES_EQUITBASE+NUM_CHAR_SLOTS; i++)
{
int slot = hasRobe ? SlotOrderWithRobe[i-ES_EQUITBASE] : SlotOrder[i-ES_EQUITBASE];
if(!IsSlotHasModel(slot))
AddEquipment(slot, &texgroup, 10+i);
}
m_hChar = texgroup.Compose(m_hChar);
m_pCharacter->m_ReplaceTexture[1] = m_hChar;
m_pCharacter->m_ReplaceTexture[2] = m_hCape;
m_pCharacter->m_ReplaceTexture[6] = m_hHair;
//--------------------------------------------------
// 问题:
// 1, 非ROBE情况下,手套护腕显示在袖子外, 注意改进
// 2. 换装时有时会一闪(有model情况)
//--------------------------------------------------
//--------------------------------------------------
// INFO: Geoset[0] 表示袖子
// Geoset[1] 表示裤子类型
// Geoset[2] 表示手套MESH
// Geoset[3] 表示靴子MESH
// Geoset[4] 表示披风
//--------------------------------------------------
if(m_Geoset[2]>0) m_Geoset[0] = 0;
if(m_Geoset[1]>0) m_Geoset[3] = 0;
if(m_Geoset[4])
m_pCharacter->m_bShowSubMesh[43] = false;
else
m_pCharacter->m_bShowSubMesh[43] = true;
for(uint32 j=0; j<m_pCharacter->m_SubMesh.size(); j++)
{
int id = m_pCharacter->m_SubMesh[j].id;
for(int i=0; i<5; i++)
{
if(id == m_Geoset[i] && id)
{
m_pCharacter->m_bShowSubMesh[j] = true;
break;
}
}
}
ChangeHairStyle();
ChangeFacialStyle();
}
void M2Character::SetAnimationIndex(int index)
{
m_pCurModel->SetAnimationByIndex(0, 0, index);
}
CM2Loader* M2Character::GetCurModel(void)
{
return m_pCurModel;
}
CM2Loader* M2Character::GetChar(void)
{
return m_pCharacter;
}
bool M2Character::IsSlotHasModel(int slot)
{
return (slot==ES_HEAD || slot==ES_SHOULDER ||
slot==ES_HAND_LEFT || slot==ES_HAND_RIGHT ||
slot==ES_QUIVER);
}
void M2Character::SetEquipmentValue(int index, int value)
{
if(index>=0 && index<32)
{
m_EquipmentIndex[index] = value;
switch(index)
{
case ES_FACESTYLE:
case ES_SKINCOLOR: CreateTexture(); break;
case ES_HAIRCOLOR: ChangeHairColor(); break;
case ES_HAIRSTYLE: ChangeHairStyle(); break;
case ES_FACIALSTYLE: ChangeFacialStyle(); break;
case ES_HEAD:
case ES_NECK:
case ES_SHOULDER:
case ES_BOOTS:
case ES_BELT:
case ES_SHIRT:
case ES_PANTS:
case ES_CHEST:
case ES_BRACERS:
case ES_GLOVES:
case ES_HAND_RIGHT:
case ES_HAND_LEFT:
case ES_CAPE:
case ES_TABARD:
case ES_QUIVER:
{
if(value==0)
{
m_EquipmentIndex[index] = 0;
}
else
{
m_EquipmentIndex[index] = m_EquipmentBase[index]-1+value;
}
for(int i=ES_EQUITBASE; i<ES_EQUITBASE+NUM_CHAR_SLOTS; i++)
{
if(IsSlotHasModel(i)) LoadItem(i);
}
CreateTexture();
}
break;
}
}
}
int M2Character::GetEquipmentValue(int index)
{
if(index>=0 && index<32)
{
if(index<ES_EQUITBASE)
return m_EquipmentIndex[index];
else
{
if(m_EquipmentIndex[index] == 0)
return 0;
else
return m_EquipmentIndex[index]-m_EquipmentBase[index]+1;
}
}
return 0;
}
int M2Character::GetEquipmentMax(int index)
{
if(index>=0 && index<32)
{
return m_EquipmentMax[index];
}
return 0;
}
void M2Character::SaveEquipment(void)
{
CIniFile equip("Config\\Equipment.ini");
char szItemName[32];
for(int i=ES_UNUSED; i<ES_TOTALNUM; i++)
{
sprintf(szItemName, "Equip_%d", i);
equip.WriteInt("Save", szItemName, m_EquipmentIndex[i]);
}
equip.Save(NULL);
}
void M2Character::LoadEquipment(bool bDefault /* = false */)
{
CIniFile equip("Config\\Equipment.ini");
char szIndexName[32];
char szItemName[32];
if(bDefault) sprintf(szIndexName, "Default");
else sprintf(szIndexName, "Save");
for(int i=ES_UNUSED; i<ES_TOTALNUM; i++)
{
sprintf(szItemName, "Equip_%d", i);
m_EquipmentIndex[i] = equip.ReadInt(szIndexName, szItemName, 0);
}
for(int i=ES_EQUITBASE; i<ES_EQUITBASE+NUM_CHAR_SLOTS; i++)
{
if(IsSlotHasModel(i)) LoadItem(i);
}
CreateTexture();
ChangeHairColor();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -