2023-01-05 18:32:58 +08:00
|
|
|
|
using Axibug.Resources;
|
|
|
|
|
using Axibug.Runtime;
|
|
|
|
|
using Codice.CM.WorkspaceServer.DataStore;
|
|
|
|
|
using Game.Config;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace Game
|
|
|
|
|
{
|
|
|
|
|
public class RoleMgrComponent : GameComponent
|
|
|
|
|
{
|
|
|
|
|
private Queue<RoleBase> temp_RemoveUser = new Queue<RoleBase>();//<2F><>Ҫ<EFBFBD>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
|
|
|
|
|
private Queue<Int32> temp_RemoveRequest = new Queue<Int32>();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
|
|
|
|
|
private Dictionary<long, RoleBase> dictAllRole = new Dictionary<long, RoleBase>();
|
|
|
|
|
private Dictionary<E_NODE_TYPE, Dictionary<long, RoleBase>> dictRoleList = new Dictionary<E_NODE_TYPE, Dictionary<long, RoleBase>>();
|
|
|
|
|
|
|
|
|
|
//key:ְҵ+<2B>Ա<EFBFBD> <20><><EFBFBD>磺ss_w
|
|
|
|
|
private Dictionary<string, Queue<GameObject>> userPool = new Dictionary<string, Queue<GameObject>>();
|
|
|
|
|
|
|
|
|
|
private float temp_CheckTime = 0;
|
|
|
|
|
private float temp_RequestTime = 0;
|
|
|
|
|
|
|
|
|
|
private long mRoleIdSeed = 0;
|
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
//AppEntry.Event.Subscribe(UserMoveEventArgs.EventId, OnUserMoveEvent);
|
|
|
|
|
//AppEntry.Event.Subscribe(UserPlayerSkillEventArgs.EventId, OnUserPlayerSkill);
|
|
|
|
|
//AppEntry.Event.Subscribe(RoleDeadEventArgs.EventId, OnRoleDead);
|
|
|
|
|
//AppEntry.Event.Subscribe(RoleReviveEventArgs.EventId, OnRoleRevive);
|
|
|
|
|
//AppEntry.Event.Subscribe(RoleLevelupEventArgs.EventId, OnRoleLevelUp);
|
|
|
|
|
//AppEntry.Event.Subscribe(AddRoleBufferEvent.EventId, AddBuffer);
|
|
|
|
|
//AppEntry.Event.Subscribe(RemoveRoleBufferEvent.EventId, RemoveBuffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long GetNewRoleId()
|
|
|
|
|
{
|
|
|
|
|
return ++mRoleIdSeed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region <EFBFBD><EFBFBD>ɫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
public void AddRole(RoleBase role)
|
|
|
|
|
{
|
|
|
|
|
if (!dictAllRole.ContainsKey(role.RoleID))
|
|
|
|
|
{
|
|
|
|
|
dictAllRole[role.RoleID] = role;
|
|
|
|
|
|
|
|
|
|
Dictionary<long, RoleBase> roleList;
|
|
|
|
|
if (!dictRoleList.ContainsKey(role.RoleType))
|
|
|
|
|
roleList = dictRoleList[role.RoleType] = new Dictionary<long, RoleBase>();
|
|
|
|
|
else
|
|
|
|
|
roleList = dictRoleList[role.RoleType];
|
|
|
|
|
roleList[role.RoleID] = role;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void RemoveRole(RoleBase role)
|
|
|
|
|
{
|
|
|
|
|
if (dictAllRole.ContainsKey(role.RoleID))
|
|
|
|
|
{
|
|
|
|
|
dictAllRole.Remove(role.RoleID);
|
|
|
|
|
|
|
|
|
|
Dictionary<long, RoleBase> roleList;
|
|
|
|
|
if (!dictRoleList.ContainsKey(role.RoleType))
|
|
|
|
|
roleList = dictRoleList[role.RoleType] = new Dictionary<long, RoleBase>();
|
|
|
|
|
else
|
|
|
|
|
roleList = dictRoleList[role.RoleType];
|
|
|
|
|
roleList.Remove(role.RoleID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public MainRole CreateMainRole()
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
S_ROLE_SELF data = new S_ROLE_SELF();
|
|
|
|
|
|
|
|
|
|
data.innate.roleid = GetNewRoleId();
|
|
|
|
|
data.innate.job = 0;//TODO
|
|
|
|
|
data.innate.nick = "";//<2F>dz<EFBFBD>
|
|
|
|
|
data.innate.sex = 0;//<2F>Ա<EFBFBD>
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
data.exp.exp = 0;
|
|
|
|
|
data.exp.level = 1;
|
|
|
|
|
|
|
|
|
|
//״̬<D7B4><CCAC>
|
|
|
|
|
data.status.state = CharacterState.Living;
|
|
|
|
|
data.status.pos = GamePlayEntry.Map.SpawnPos;
|
|
|
|
|
data.status.mapid = 0;//TODO
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ħ<EFBFBD><C4A7><EFBFBD><EFBFBD>
|
|
|
|
|
data.life.maxMP = 100;
|
|
|
|
|
data.life.curMP = 100;
|
|
|
|
|
data.life.maxMP = 100;
|
|
|
|
|
data.life.curMP = 100;
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
data.econ.gold = 0;
|
|
|
|
|
|
|
|
|
|
string ModelName = "Warrior";//ģ<><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
//ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
GameObject playergo = CloneRole(ModelName, GamePlayEntry.MainPlayer.transform);
|
|
|
|
|
playergo.transform.localPosition = Vector3.zero;
|
|
|
|
|
GamePlayEntry.MainPlayer.transform.position = data.status.pos;
|
|
|
|
|
|
2023-01-06 00:14:59 +08:00
|
|
|
|
SetRigibody(playergo.transform);
|
2023-01-05 18:32:58 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2023-01-06 00:14:59 +08:00
|
|
|
|
MainRole role = playergo.gameObject.AddComponent<MainRole>();
|
|
|
|
|
role.Init(data);
|
2023-01-05 18:32:58 +08:00
|
|
|
|
|
|
|
|
|
AddRole(role);
|
|
|
|
|
|
|
|
|
|
return role;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private GameObject CloneRole(string RoleName,Transform parent)
|
|
|
|
|
{
|
|
|
|
|
string rootPath = "Assets/GameAssets";
|
|
|
|
|
string MapName = $"Assets/GameAssets/Prefabs/Role/{RoleName}/{RoleName}.prefab";
|
|
|
|
|
string tmp = MapName.Remove(0, rootPath.Length + 1);
|
|
|
|
|
int idx = tmp.LastIndexOf('/');
|
|
|
|
|
string bundleName = tmp.Substring(0, idx);
|
|
|
|
|
|
|
|
|
|
UnityEngine.Object asset = null;
|
|
|
|
|
if (AppEntry.Base.EditorResourceMode)
|
|
|
|
|
{
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
asset = AssetDatabase.LoadAssetAtPath<GameObject>(MapName);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int id = MapName.GetHashCode();
|
|
|
|
|
asset = PrefabManager.LoadPrefab<UnityEngine.Object>(bundleName.ToLower(), MapName, id, parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (asset == null)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError($"asset<65><74><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>path={MapName}");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GameObject go = Instantiate(asset, parent) as GameObject;
|
|
|
|
|
if (go == null)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("LoadPrefabByEditor2. go == null. asset:" + asset);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return go;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetRigibody(Transform trans)
|
|
|
|
|
{
|
|
|
|
|
Rigidbody mRigidbody = trans.gameObject.AddComponent<Rigidbody>();
|
|
|
|
|
mRigidbody.isKinematic = false;
|
|
|
|
|
mRigidbody.useGravity = true;
|
2023-01-06 00:14:59 +08:00
|
|
|
|
|
|
|
|
|
mRigidbody.constraints = RigidbodyConstraints.FreezeRotation;
|
2023-01-05 18:32:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|