9c2b5b87f3
# Conflicts: # Assets/NetworkLib/Debug/netstandard2.1/CSNetwork.dll # Packages/manifest.json
296 lines
11 KiB
C#
296 lines
11 KiB
C#
using BrewMonster;
|
|
using ModelRenderer.Scripts.GameData;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public abstract class EC_Player : MonoBehaviour
|
|
{
|
|
private static PLAYER_ACTION[] _default_actions;
|
|
private static PLAYER_ACTION[] _turning_actions;
|
|
PLAYER_ACTION[] m_PlayerActions;
|
|
[SerializeField] internal INFO m_PlayerInfo;
|
|
protected GameObject m_pPlayerModel;
|
|
protected float rotationSpeed = 5;
|
|
internal int m_iMoveMode; // Player's move mode
|
|
internal int m_idSelTarget; // Ñ¡ÖÐÄ¿±êµÄID
|
|
|
|
protected void Awake()
|
|
{
|
|
m_PlayerActions = _default_actions;
|
|
}
|
|
public void SetPlayerInfor(INFO playinfo)
|
|
{
|
|
m_PlayerInfo = playinfo;
|
|
}
|
|
public INFO GetPlayInfo()
|
|
{
|
|
return m_PlayerInfo;
|
|
}
|
|
|
|
public static void InitStaticRes()
|
|
{
|
|
BuildActionList();
|
|
}
|
|
public bool IsValidAction(int iIndex) { return (iIndex >= 0 && iIndex < (int)PLAYER_ACTION_TYPE.ACT_MAX) ? true : false; }
|
|
private static void BuildActionList()
|
|
{
|
|
if (_default_actions == null)
|
|
{
|
|
// thay cho hashtab trong C++
|
|
Dictionary<string, PLAYER_ACTION_INFO_CONFIG> actionMap =
|
|
new Dictionary<string, PLAYER_ACTION_INFO_CONFIG>(100);
|
|
|
|
Dictionary<string, PLAYER_ACTION_INFO_CONFIG> skillActionMap =
|
|
new Dictionary<string, PLAYER_ACTION_INFO_CONFIG>(100);
|
|
|
|
elementdataman dataman = ElementDataManProvider.GetElementDataMan();
|
|
PLAYER_ACTION_INFO_CONFIG data;
|
|
|
|
int count = dataman.get_data_num(ID_SPACE.ID_SPACE_CONFIG);
|
|
|
|
DATA_TYPE dt = default;
|
|
uint id = 0;
|
|
|
|
for (int i = 0; i < count; ++i)
|
|
{
|
|
id = dataman.get_data_id(ID_SPACE.ID_SPACE_CONFIG, i, ref dt);
|
|
if (dt != DATA_TYPE.DT_PLAYER_ACTION_INFO_CONFIG)
|
|
continue;
|
|
|
|
data = (PLAYER_ACTION_INFO_CONFIG)dataman.get_data_ptr(id, ID_SPACE.ID_SPACE_CONFIG, ref dt);
|
|
if (!string.IsNullOrEmpty(data.ActionName) && data.ActionName[0] != '0')
|
|
{
|
|
if (!actionMap.TryAdd(data.ActionName, data))
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
CECStringTab actionNames = new CECStringTab();
|
|
actionNames.Init("actions_player", false);
|
|
|
|
_default_actions = new PLAYER_ACTION[(int)PLAYER_ACTION_TYPE.ACT_MAX];
|
|
|
|
for (int i = 0; i < _default_actions.Length; i++)
|
|
{
|
|
_default_actions[i].type = (PLAYER_ACTION_TYPE)i;
|
|
|
|
string szName = actionNames.GetANSIString(i);
|
|
|
|
if (!string.IsNullOrEmpty(szName))
|
|
{
|
|
if (actionMap.TryGetValue(szName, out var it))
|
|
{
|
|
_default_actions[i].data = it;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public bool PlayAction(int iAction, bool bRestart/* true */, int iTransTime/* 200 */, bool bQueue/* false */)
|
|
{
|
|
return PlayActionWithConfig(iAction, 0, bRestart, iTransTime, bQueue);
|
|
}
|
|
public bool PlayActionWithConfig(int iAction, int actionConfigID, bool bRestart/* =true */, int iTransTime/* =200 */, bool bQueue/* =false */)
|
|
{
|
|
if (iAction < 0 || iAction >= (int)PLAYER_ACTION_TYPE.ACT_MAX)
|
|
{
|
|
return false;
|
|
}
|
|
if (actionConfigID > 0)
|
|
{
|
|
DATA_TYPE dt = DATA_TYPE.DT_INVALID;
|
|
var p = ElementDataManProvider.GetElementDataMan().get_data_ptr((uint)actionConfigID, ID_SPACE.ID_SPACE_CONFIG, ref dt);
|
|
if (dt == DATA_TYPE.DT_PLAYER_ACTION_INFO_CONFIG)
|
|
{
|
|
PLAYER_ACTION actionConfig;
|
|
actionConfig.type = (PLAYER_ACTION_TYPE)iAction;
|
|
actionConfig.data = (PLAYER_ACTION_INFO_CONFIG)p;
|
|
return PlayActionWithConfig(iAction, actionConfig, bRestart, iTransTime, bQueue);
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
}
|
|
return PlayActionWithConfig(iAction, m_PlayerActions[iAction], bRestart, iTransTime, bQueue);
|
|
}
|
|
public bool PlayActionWithConfig(int iAction, in PLAYER_ACTION actionConfig,
|
|
bool bRestart = true, int iTransTime = 200, bool bQueue = false)
|
|
{
|
|
PLAYER_ACTION action = actionConfig;
|
|
|
|
var szAct = EC_Utility.BuildActionName(action, 0);
|
|
EventBus.PublishChannel(m_PlayerInfo.cid, new PlayActionEvent(szAct));
|
|
return true;
|
|
}
|
|
public static void Dispose()
|
|
{
|
|
_default_actions = null;
|
|
_turning_actions = null;
|
|
}
|
|
public struct PLAYER_ACTION
|
|
{
|
|
public PLAYER_ACTION_TYPE type;
|
|
public PLAYER_ACTION_INFO_CONFIG data;
|
|
};
|
|
public enum PLAYER_ACTION_TYPE
|
|
{
|
|
// 0
|
|
ACT_STAND = 0, // Đứng
|
|
ACT_FIGHTSTAND, // Đứng chiến đấu
|
|
ACT_WALK, // Đi bộ
|
|
ACT_RUN, // Chạy
|
|
ACT_JUMP_START, // Bắt đầu nhảy
|
|
|
|
// 5
|
|
ACT_JUMP_LOOP, // Nhảy trên không lặp lại
|
|
ACT_JUMP_LAND, // Nhảy tiếp đất
|
|
ACT_SWIM, // Bơi
|
|
ACT_HANGINWATER, // Lơ lửng trong nước
|
|
ACT_TAKEOFF, // Cất cánh (should be ACT_TAKEOFF_WING)
|
|
|
|
// 10
|
|
ACT_HANGINAIR, // Treo trên không (should be ACT_HANGINAIR_WING)
|
|
ACT_FLY, // Bay (should be ACT_FLY_WING)
|
|
ACT_FLYDOWN, // Bay xuống cao (should be ACT_FLYDOWN_WING_HIGH)
|
|
ACT_FLYDOWN_WING_LOW, // Bay xuống thấp (should be ACT_FLYDOWN_WING_LOW)
|
|
ACT_LANDON, // Hạ cánh (should be ACT_LAND_WING)
|
|
|
|
// 15
|
|
ACT_TAKEOFF_SWORD, // Kiếm bay - cất cánh
|
|
ACT_HANGINAIR_SWORD, // Kiếm bay - treo không trung
|
|
ACT_FLY_SWORD, // Kiếm bay - tiến tới
|
|
ACT_FLYDOWN_SWORD_HIGH, // Kiếm bay - rơi cao
|
|
ACT_FLYDOWN_SWORD_LOW, // Kiếm bay - rơi thấp
|
|
|
|
// 20
|
|
ACT_LANDON_SWORD, // Kiếm bay - hạ cánh
|
|
ACT_SITDOWN, // Ngồi
|
|
ACT_SITDOWN_LOOP, // Ngồi lặp lại
|
|
ACT_STANDUP, // Đứng dậy
|
|
ACT_WOUNDED, // Bị thương
|
|
|
|
// 25
|
|
ACT_GROUNDDIE, // Chết trên mặt đất
|
|
ACT_GROUNDDIE_LOOP, // Chết trên đất (loop)
|
|
ACT_WATERDIE, // Chết trong nước
|
|
ACT_WATERDIE_LOOP, // Chết trong nước (loop)
|
|
ACT_AIRDIE_ST, // Chết trên không (bắt đầu)
|
|
|
|
// 30
|
|
ACT_AIRDIE, // Chết trên không (loop rơi)
|
|
ACT_AIRDIE_ED, // Chết trên không (chạm đất)
|
|
ACT_AIRDIE_LAND_LOOP, // Chết rơi đất (loop)
|
|
ACT_REVIVE, // Hồi sinh
|
|
ACT_CUSTOMIZE, // Động tác tùy chỉnh
|
|
|
|
// 35
|
|
ACT_STRIKEBACK, // Bị đánh lùi
|
|
ACT_STRIKEDOWN, // Bị đánh ngã
|
|
ACT_STRIKEDOWN_LOOP, // Bị đánh ngã (loop)
|
|
ACT_STRIKEDOWN_STANDUP, // Bị đánh ngã rồi đứng dậy
|
|
ACT_PICKUP, // Nhặt đồ
|
|
|
|
// 40
|
|
ACT_PICKUP_LOOP, // Nhặt đồ (loop)
|
|
ACT_PICKUP_STANDUP, // Nhặt đồ đứng dậy
|
|
ACT_PICKUP_MATTER, // Nhặt vật thể
|
|
ACT_GAPE, // Há miệng
|
|
ACT_LOOKAROUND, // Nhìn quanh
|
|
|
|
// 45
|
|
ACT_PLAYWEAPON, // Vung vũ khí
|
|
ACT_EXP_WAVE, // Vẫy tay
|
|
ACT_EXP_NOD, // Gật đầu
|
|
ACT_EXP_SHAKEHEAD, // Lắc đầu
|
|
ACT_EXP_SHRUG, // Nhún vai
|
|
|
|
// 50
|
|
ACT_EXP_LAUGH, // Cười lớn
|
|
ACT_EXP_ANGRY, // Tức giận
|
|
ACT_EXP_STUN, // Choáng
|
|
ACT_EXP_DEPRESSED, // Buồn bã
|
|
ACT_EXP_KISSHAND, // Hôn tay
|
|
|
|
// 55
|
|
ACT_EXP_SHY, // Ngại ngùng
|
|
ACT_EXP_SALUTE, // Chào
|
|
ACT_EXP_SITDOWN, // Ngồi xuống
|
|
ACT_EXP_SITDOWN_LOOP, // Ngồi xuống (loop)
|
|
ACT_EXP_SITDOWN_STANDUP, // Ngồi xuống rồi đứng dậy
|
|
|
|
// 60
|
|
ACT_EXP_ASSAULT, // Tấn công
|
|
ACT_EXP_THINK, // Suy nghĩ
|
|
ACT_EXP_DEFIANCE, // Thách thức
|
|
ACT_EXP_VICTORY, // Chiến thắng
|
|
ACT_EXP_KISS, // Hôn
|
|
|
|
// 65
|
|
ACT_EXP_KISS_LOOP, // Hôn (loop)
|
|
ACT_EXP_KISS_END, // Kết thúc hôn
|
|
ACT_ATTACK_1, // Tấn công 1
|
|
ACT_ATTACK_2, // Tấn công 2
|
|
ACT_ATTACK_3, // Tấn công 3
|
|
|
|
// 70
|
|
ACT_ATTACK_4, // Tấn công 4
|
|
ACT_ATTACK_TOSS, // Ném vũ khí
|
|
ACT_TRICK_RUN, // Chiêu khi chạy
|
|
ACT_TRICK_JUMP, // Chiêu khi nhảy
|
|
ACT_FLY_GLIDE, // Lượn
|
|
|
|
// 75
|
|
ACT_FLY_GLIDE_SWORD, // Kiếm bay - lượn
|
|
ACT_EXP_FIGHT, // Tư thế chiến đấu
|
|
ACT_EXP_ATTACK1, // Tấn công diễn xuất 1
|
|
ACT_EXP_ATTACK2, // Tấn công diễn xuất 2
|
|
ACT_EXP_ATTACK3, // Tấn công diễn xuất 3
|
|
|
|
// 80
|
|
ACT_EXP_ATTACK4, // Tấn công diễn xuất 4
|
|
ACT_EXP_DEFENCE, // Phòng thủ
|
|
ACT_EXP_FALL, // Té ngã
|
|
ACT_EXP_FALLONGROUND, // Ngã xuống đất
|
|
ACT_EXP_LOOKAROUND, // Nhìn quanh
|
|
|
|
// 85
|
|
ACT_EXP_DANCE, // Nhảy múa
|
|
ACT_EXP_FASHIONWEAPON, // Động tác vũ khí thời trang
|
|
ACT_USEITEM, // Dùng item
|
|
ACT_USEITMELOOP, // Dùng item (loop)
|
|
ACT_TWO_KISS, // Hôn đôi
|
|
|
|
// 90
|
|
ACT_USING_TARGET_ITEM, // Dùng đạo cụ
|
|
ACT_SWIM_FOR_MOVESKILL, // Bơi trong lúc dùng skill di chuyển
|
|
|
|
ACT_MAX,
|
|
ACT_CASTSKILL // Chỉ là placeholder cho skill actions
|
|
}
|
|
|
|
}
|
|
public struct PlayActionEvent
|
|
{
|
|
public string AnimationName;
|
|
public PlayActionEvent(string animationName)
|
|
{
|
|
this.AnimationName = animationName;
|
|
}
|
|
}
|
|
[Serializable]
|
|
public struct INFO
|
|
{
|
|
public int cid; // Character ID
|
|
public int crc_c; // customized data crc
|
|
public int crc_e; // Equipment data crc
|
|
public INFO(int cid, int crc_c, int crc_)
|
|
{
|
|
this.cid = cid;
|
|
this.crc_c = crc_c;
|
|
this.crc_e = crc_;
|
|
}
|
|
}; |