142 lines
5.7 KiB
C#
142 lines
5.7 KiB
C#
using BrewMonster.Scripts;
|
||
using System.Threading.Tasks;
|
||
using UnityEngine;
|
||
using CSNetwork.GPDataType;
|
||
namespace BrewMonster
|
||
{
|
||
public class CECClonePlayer : CECPlayer
|
||
{
|
||
protected bool m_bShowCustomize; // ��ʾ���Ի�
|
||
protected bool m_bUseHintModel; // ʹ��˵��ģ��
|
||
|
||
public CECClonePlayer(){
|
||
m_iCID = (int)Class_ID.OCID_CLONED_PLAYER;
|
||
m_bCastShadow = true;
|
||
m_bShowCustomize= true;
|
||
//Todo: add cofig feature to game
|
||
//m_bUseHintModel = GetConfigs().GetVideoSettings().bModelLimit;
|
||
}
|
||
public bool CanClone(CECPlayer player)
|
||
{
|
||
return player != null
|
||
&& (player.IsHostPlayer() || player.IsElsePlayer());
|
||
}
|
||
public async Task<bool> Clone(CECPlayer player, bool atOnce){
|
||
if (!player){
|
||
return false;
|
||
}
|
||
if (player.IsHostPlayer()){
|
||
if (await LoadFrom((CECHostPlayer)player, atOnce)){
|
||
return true;
|
||
}
|
||
}
|
||
if (player.IsElsePlayer()){
|
||
if (await LoadFrom((EC_ElsePlayer)player, atOnce)){
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
protected async Task<bool> LoadFrom(CECHostPlayer player, bool atOnce)
|
||
{
|
||
int i = 0;
|
||
EC_IvtrItem[] aEquipItems = new EC_IvtrItem[InventoryConst.SIZE_ALL_EQUIPIVTR];
|
||
|
||
// Create equipments
|
||
for (i=0; i < player.GetEquipment().GetSize(); i++){
|
||
if (!ShouldLoadEquipment(i)){
|
||
continue;
|
||
}
|
||
EC_IvtrItem Equip = player.GetEquipment().GetItem(i);
|
||
aEquipItems[i] = Equip;
|
||
}
|
||
|
||
// // Todo: Create goblin
|
||
// if( aEquipItems[EQUIPIVTR_GOBLIN] )
|
||
// {
|
||
// m_pGoblin = new CECGoblin();
|
||
// CECIvtrGoblin* pIvtrGoblin = (CECIvtrGoblin*)aEquipItems[EQUIPIVTR_GOBLIN];
|
||
// m_pGoblin->Init(pIvtrGoblin->GetTemplateID(), pIvtrGoblin, this);
|
||
// }
|
||
|
||
// Build new equipments id array (must match SIZE_ALL_EQUIPIVTR — LoadPlayerSkeleton iterates full range)
|
||
int[] aNewEquips = new int[InventoryConst.SIZE_ALL_EQUIPIVTR];
|
||
|
||
for (i=0; i < InventoryConst.IVTRSIZE_EQUIPPACK; i++) {
|
||
EC_IvtrItem pItem = aEquipItems[i];
|
||
if (pItem != null) {
|
||
aNewEquips[i] = pItem.GetTemplateID();
|
||
if( ((i >= InventoryConst.EQUIPIVTR_FASHION_BODY && i <= InventoryConst.EQUIPIVTR_FASHION_WRIST)
|
||
|| i == InventoryConst.EQUIPIVTR_FASHION_HEAD ) &&
|
||
pItem.GetClassID() == (int)EC_IvtrEquip.EQUIP_CLASS_ID.ICID_FASHION ) {
|
||
EC_IvtrFashion pFashionItem = (EC_IvtrFashion)pItem;
|
||
aNewEquips[i] |= (pFashionItem.GetWordColor() << 16) & 0x7fffffff;
|
||
}
|
||
else {
|
||
EC_IvtrEquip pEquip = (EC_IvtrEquip) pItem;
|
||
ushort stoneStatus = pEquip != null ? pEquip.GetStoneMask() : (ushort)0;
|
||
aNewEquips[i] |= (stoneStatus << 16) & 0x7fffffff;
|
||
}
|
||
}
|
||
else{
|
||
aNewEquips[i] = 0;
|
||
}
|
||
}
|
||
|
||
m_aEquips = aNewEquips;
|
||
|
||
return await Load(player, atOnce);
|
||
}
|
||
protected async Task<bool> LoadFrom(EC_ElsePlayer player, bool atOnce){
|
||
// Create equipments
|
||
for (int i=0; i < InventoryConst.SIZE_ALL_EQUIPIVTR; i++){
|
||
if (!ShouldLoadEquipment(i)){
|
||
continue;
|
||
}
|
||
m_aEquips[i] = player.GetEquipment(i);
|
||
}
|
||
return await Load(player, atOnce);
|
||
}
|
||
public override void SetDirAndUp(A3DVECTOR3 vDir, A3DVECTOR3 vUp){
|
||
base.SetDirAndUp(vDir, vUp);
|
||
if(m_pPlayerCECModel != null)
|
||
{
|
||
Vector3 dir = new Vector3(vDir.x, vDir.y, vDir.z);
|
||
Vector3 up = new Vector3(vUp.x, vUp.y, vUp.z);
|
||
if (dir.magnitude > 0.01f)
|
||
{
|
||
Quaternion lookRot = Quaternion.LookRotation(dir, up);
|
||
m_pPlayerCECModel.m_pPlayerModel.transform.rotation = lookRot;
|
||
}
|
||
m_bAdjustOrient = false;
|
||
}
|
||
//m_pPlayerCECModel.SetDirAndUp(vDir,vUp);
|
||
}
|
||
protected async Task<bool> Load(CECPlayer player, bool atOnce){
|
||
player.CloneSimplePropertyTo(this);
|
||
OnCloneSimpleProperty();
|
||
if (!await LoadPlayerSkeleton(atOnce)){
|
||
BMLogger.LogError("CECCloneElsePlayer::Load, Failed to load skeleton.");
|
||
return false;
|
||
}
|
||
SetNewExtendStates(0, m_aExtStates, OBJECT_EXT_STATE_COUNT);
|
||
if (player.GetOriginalShapeID() != 0){
|
||
await TransformShape(player.GetShapeMask(), true);
|
||
}
|
||
return true;
|
||
}
|
||
protected virtual bool ShouldLoadEquipment(int index)
|
||
{
|
||
return true;
|
||
}
|
||
protected virtual void OnCloneSimpleProperty(){}
|
||
public virtual CECModel GetRenderModel(){
|
||
return m_pPlayerCECModel; //m_pPetModel ? m_pPetModel : m_pPlayerModel;
|
||
//Todo: add pet model when implement pet? system
|
||
}
|
||
public void PlayActionByName(string szActName){
|
||
m_pActionController.PlayNonSkillActionWithName((int)PLAYER_ACTION_TYPE.ACT_MAX, szActName);
|
||
}
|
||
}
|
||
|
||
} |