341 lines
11 KiB
C#
341 lines
11 KiB
C#
|
using Thousandto.Cfg.Data;
|
|||
|
using Thousandto.Code.Center;
|
|||
|
using Thousandto.Code.Global;
|
|||
|
using Thousandto.Core.Asset;
|
|||
|
|
|||
|
using Thousandto.Core.Base;
|
|||
|
using Thousandto.Core.PostEffect;
|
|||
|
using Thousandto.Plugins.Common;
|
|||
|
using Thousandto.Plugins.Common.UniScene;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
|
|||
|
using System.Text;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace Thousandto.Code.Logic
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// NPC逻辑处理
|
|||
|
/// </summary>
|
|||
|
public class Npc : Character
|
|||
|
{
|
|||
|
#region 私有变量
|
|||
|
//NPC模型ID
|
|||
|
//当前特效的ID
|
|||
|
private uint m_questTagVFXId = 0;
|
|||
|
private NpcProperty _propMoudleEx = null;
|
|||
|
//默认朝向
|
|||
|
private Vector2 _normalDir = Vector2.zero;
|
|||
|
//转身倒计时
|
|||
|
private float _rotateTimer = 0f;
|
|||
|
//高度
|
|||
|
private float _offsetHeight = 0f;
|
|||
|
#endregion
|
|||
|
|
|||
|
#region//属性信息
|
|||
|
//属性模块
|
|||
|
public new NpcProperty PropMoudle
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (_propMoudleEx == null)
|
|||
|
{
|
|||
|
_propMoudleEx = base.PropMoudle as NpcProperty;
|
|||
|
}
|
|||
|
return _propMoudleEx;
|
|||
|
}
|
|||
|
}
|
|||
|
//默认动作
|
|||
|
public string NormalAnim { get; private set; }
|
|||
|
#endregion
|
|||
|
|
|||
|
#region//构造函数
|
|||
|
public Npc()
|
|||
|
{
|
|||
|
GameCenter.RegFixEventHandle(LogicEventDefine.EID_EVENT_TASKINIT, OnTaskChanged);
|
|||
|
GameCenter.RegFixEventHandle(LogicEventDefine.EID_EVENT_TASKCHANG, OnTaskChanged);
|
|||
|
GameCenter.RegFixEventHandle(LogicEventDefine.EID_EVENT_PLAYER_BASE_ATTR_CHANGED, OnPlayerBaseAttrChanged);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region//初始化,卸载,以及刷新数据 -- EntityInitInfo=>NpcInitInfo
|
|||
|
|
|||
|
//加载皮肤 --- 重载
|
|||
|
protected override FSkinBase OnSetupSkin()
|
|||
|
{
|
|||
|
FSkinModel skin = GameCenter.LuaSystem.Adaptor.CreateFSkinModel(FSkinTypeCode.NPC);
|
|||
|
skin.SetLayer(LayerUtils.Monster);
|
|||
|
skin.SetOnSkinPartChangedHandler((x,y)=> {
|
|||
|
if(y == FSkinPartCode.Body)
|
|||
|
{
|
|||
|
var body = Skin.GetSkinPart(FSkinPartCode.Body) as FGameObjectBody;
|
|||
|
body.BrightWeapon = true;
|
|||
|
}
|
|||
|
OnTaskChanged(null);
|
|||
|
});
|
|||
|
skin.SetMipmapLevel(0.5f);
|
|||
|
skin.SetActiveChangedCallBack(OnActiveChanged);
|
|||
|
return skin;
|
|||
|
}
|
|||
|
|
|||
|
protected override bool OnSetupFSMBefore()
|
|||
|
{
|
|||
|
ResetDirection();
|
|||
|
return base.OnSetupFSMBefore();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//安装状态机
|
|||
|
protected override bool OnSetupFSM()
|
|||
|
{
|
|||
|
Fsm = new EntityFSM(this);
|
|||
|
Fsm.AddState(new NpcFSM.Idle());
|
|||
|
Fsm.SetDefaultStateId(EntityStateID.Idle);
|
|||
|
Fsm.Init(this);
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
//初始化处理
|
|||
|
protected override bool OnInitializeAfter(EntityInitInfo baseInfo)
|
|||
|
{
|
|||
|
|
|||
|
var initInfo = baseInfo as NpcInitInfo;
|
|||
|
base.OnInitializeAfter(baseInfo);
|
|||
|
SyncInfo(initInfo);
|
|||
|
|
|||
|
if(Scene.Cfg.ShowNpcHud != 0)
|
|||
|
{
|
|||
|
ShowHUD();
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
//重新刷新信息
|
|||
|
public void SyncInfo(EntityInitInfo info)
|
|||
|
{
|
|||
|
var initInfo = info as NpcInitInfo;
|
|||
|
ModelTransform.position = Scene.GetTerrainPosition(initInfo.X, initInfo.Z);
|
|||
|
float angleToZ = initInfo.QuatW * Mathf.Deg2Rad;
|
|||
|
SetDirection(new Vector3(Mathf.Sin(angleToZ), 0, Mathf.Cos(angleToZ)), false);
|
|||
|
_propMoudle = _propMoudleEx = new NpcProperty(this, initInfo.Cfg);
|
|||
|
_propMoudleEx.Level = (uint)initInfo.Cfg.Level;
|
|||
|
_normalDir = GetFacingDirection2d();
|
|||
|
_offsetHeight = initInfo.Cfg.HeightAdd / 100f;
|
|||
|
RayCastToGround(Position);
|
|||
|
|
|||
|
|
|||
|
if (initInfo.Cfg.PlayerModel != 0 && !String.IsNullOrEmpty(initInfo.Cfg.PlayerModelRes))
|
|||
|
{
|
|||
|
Skin.SkinTypeCode = FSkinTypeCode.Player;
|
|||
|
String[] modelsparam = initInfo.Cfg.PlayerModelRes.Split('_');
|
|||
|
int body = 0;
|
|||
|
int weaponId = 0;
|
|||
|
int zhenId = 0;
|
|||
|
int huanId = 0;
|
|||
|
int mountId = 0;
|
|||
|
int hunjiaId = 0;
|
|||
|
if (modelsparam.Length > 0)
|
|||
|
{
|
|||
|
int.TryParse(modelsparam[0], out body);
|
|||
|
}
|
|||
|
|
|||
|
if (modelsparam.Length > 1)
|
|||
|
{
|
|||
|
int.TryParse(modelsparam[1], out weaponId);
|
|||
|
}
|
|||
|
if (modelsparam.Length > 2)
|
|||
|
{
|
|||
|
int.TryParse(modelsparam[2], out zhenId);
|
|||
|
}
|
|||
|
if (modelsparam.Length > 3)
|
|||
|
{
|
|||
|
int.TryParse(modelsparam[3], out huanId);
|
|||
|
}
|
|||
|
if (modelsparam.Length > 4)
|
|||
|
{
|
|||
|
int.TryParse(modelsparam[4], out mountId);
|
|||
|
}
|
|||
|
if (modelsparam.Length > 5)
|
|||
|
{
|
|||
|
int.TryParse(modelsparam[5], out hunjiaId);
|
|||
|
}
|
|||
|
Dictionary<string, bool> _animDic = null;
|
|||
|
if (mountId > 0)
|
|||
|
{
|
|||
|
//有坐骑时,许愿加载玩家骑乘动作
|
|||
|
NormalAnim = AnimClipNameDefine.NormalIdle;
|
|||
|
_animDic = FPlayerAnimRelation.UIMountAnims;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
NormalAnim = AnimClipNameDefine.FightIdle;
|
|||
|
}
|
|||
|
Skin.SetSkinPartFromCfgID(FSkinPartCode.Body, body, _animDic, false);
|
|||
|
Skin.SetSkinPartFromCfgID(FSkinPartCode.GodWeaponHead, weaponId);
|
|||
|
Skin.SetSkinPartFromCfgID(FSkinPartCode.XianjiaZhen, zhenId);
|
|||
|
Skin.SetSkinPartFromCfgID(FSkinPartCode.XianjiaHuan, huanId);
|
|||
|
Skin.SetSkinPartFromCfgID(FSkinPartCode.Mount, mountId);
|
|||
|
Skin.SetSkinPartFromCfgID(FSkinPartCode.Wing, hunjiaId);
|
|||
|
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Skin.SkinTypeCode = FSkinTypeCode.NPC;
|
|||
|
Skin.SetSkinPartFromCfgID(FSkinPartCode.Body, initInfo.Cfg.Res);
|
|||
|
NormalAnim = AnimClipNameDefine.NormalIdle;
|
|||
|
}
|
|||
|
BodyScale = initInfo.Cfg.SizeScale / 100f;
|
|||
|
}
|
|||
|
|
|||
|
//卸载处理
|
|||
|
protected override void OnUninitializeBefore()
|
|||
|
{
|
|||
|
HideHUD();
|
|||
|
GameCenter.UnRegFixEventHandle(LogicEventDefine.EID_EVENT_TASKINIT, OnTaskChanged);
|
|||
|
GameCenter.UnRegFixEventHandle(LogicEventDefine.EID_EVENT_TASKCHANG, OnTaskChanged);
|
|||
|
GameCenter.UnRegFixEventHandle(LogicEventDefine.EID_EVENT_PLAYER_BASE_ATTR_CHANGED, OnPlayerBaseAttrChanged);
|
|||
|
CloseMissionSymbol();
|
|||
|
base.OnUninitializeBefore();
|
|||
|
}
|
|||
|
|
|||
|
protected override void OnUpdate(float elapsedTime)
|
|||
|
{
|
|||
|
if(_rotateTimer > 0f)
|
|||
|
{
|
|||
|
_rotateTimer -= elapsedTime;
|
|||
|
if(_rotateTimer <= 0f)
|
|||
|
{
|
|||
|
SetDirection2d(_normalDir);
|
|||
|
}
|
|||
|
}
|
|||
|
base.OnUpdate(elapsedTime);
|
|||
|
}
|
|||
|
public override Vector3 GetTerrainPosition(float x, float z)
|
|||
|
{
|
|||
|
var pos = Scene.GetTerrainPosition(x, z);
|
|||
|
pos.y += _offsetHeight;
|
|||
|
return pos;
|
|||
|
}
|
|||
|
public override bool GetHeightOnTerrain(float x, float z, out float height)
|
|||
|
{
|
|||
|
var result = Scene.GetHeightOnTerrain(x, z, out height);
|
|||
|
height += _offsetHeight;
|
|||
|
return result;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
|
|||
|
#region//头顶符号效果 -- 用于任务处理
|
|||
|
//添加问号
|
|||
|
public void AddQuestionSymbol()
|
|||
|
{
|
|||
|
//Skin.SetSkinPart(FSkinPartCode.HeadPromptVfx, ModelTypeCode.OtherVFX, 10, false, null, null, null, SlotNameDefine.Head);
|
|||
|
}
|
|||
|
|
|||
|
//添加感叹号
|
|||
|
public void AddExcalmatorySymbol()
|
|||
|
{
|
|||
|
//Skin.SetSkinPart(FSkinPartCode.HeadPromptVfx, ModelTypeCode.OtherVFX, 11, false, null, null, null, SlotNameDefine.Head);
|
|||
|
}
|
|||
|
|
|||
|
//关闭任务符号
|
|||
|
public void CloseMissionSymbol()
|
|||
|
{
|
|||
|
Skin.RemoveSkinPart(FSkinPartCode.HeadPromptVfx);
|
|||
|
}
|
|||
|
|
|||
|
//朝向玩家
|
|||
|
public void LookAtPosition(Vector2 pos)
|
|||
|
{
|
|||
|
if(PropMoudle.Cfg.Turn != 0)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
_rotateTimer = 5f;
|
|||
|
SetDirection2d(pos - Position2d);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region//选择处理
|
|||
|
//选择
|
|||
|
protected override void OnSelect()
|
|||
|
{
|
|||
|
//Skin.SetSkinPart(FSkinPartCode.SelectedVfx, ModelTypeCode.OtherVFX, 2, false, null, null, null, SlotNameDefine.Origin);
|
|||
|
//设置选择圈的大小
|
|||
|
//Skin.GetSkinPart(FSkinPartCode.SelectedVfx).SetLocalScale(new Vector3(PropMoudle.LogicBodyRadius / BodyScale, 1, PropMoudle.LogicBodyRadius / BodyScale));
|
|||
|
}
|
|||
|
|
|||
|
//取消选择
|
|||
|
protected override void OnDeselect()
|
|||
|
{
|
|||
|
//Skin.RemoveSkinPart(FSkinPartCode.SelectedVfx);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region//私有方法
|
|||
|
|
|||
|
//玩家基础实行改变
|
|||
|
private void OnPlayerBaseAttrChanged(object obj, object sender = null)
|
|||
|
{
|
|||
|
//var roleComponent = data as LocalPlayerProperty;
|
|||
|
//if (roleComponent != null)
|
|||
|
//{
|
|||
|
// var baseType = roleComponent.CurrentChangeBasePropType;
|
|||
|
// if (baseType == RoleBaseAttribute.OverallLevel)
|
|||
|
// {
|
|||
|
// var inst = GameCenter.RoleTaskSystem.MainTask.GetInstanceData();
|
|||
|
// if (inst != null && inst._Type == TaskTargetType.TARGETTYPE_UPLEVLE && inst.IsReach())
|
|||
|
// {
|
|||
|
// OnTaskChanged(null);
|
|||
|
// }
|
|||
|
// }
|
|||
|
//}
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 任务改变
|
|||
|
/// </summary>
|
|||
|
/// <param name="o"></param>
|
|||
|
private void OnTaskChanged(object o,object sender = null)
|
|||
|
{
|
|||
|
var state = GameCenter.TaskManager.GetNpcTaskState(_propMoudleEx.CfgID);
|
|||
|
switch (state)
|
|||
|
{
|
|||
|
//case NpcTaskStatus.DEFAULT:
|
|||
|
// CloseMissionSymbol();
|
|||
|
// break;
|
|||
|
//case NpcTaskStatus.CANSUBMIT:
|
|||
|
// AddExcalmatorySymbol();
|
|||
|
// break;
|
|||
|
//case NpcTaskStatus.HAVETASK:
|
|||
|
// AddQuestionSymbol();
|
|||
|
// break;
|
|||
|
case -1:
|
|||
|
{
|
|||
|
CloseMissionSymbol();
|
|||
|
}
|
|||
|
break;
|
|||
|
case 0:
|
|||
|
{
|
|||
|
}
|
|||
|
break;
|
|||
|
case 1:
|
|||
|
{
|
|||
|
}
|
|||
|
break;
|
|||
|
case 2:
|
|||
|
{
|
|||
|
bool haveTask = GameCenter.TaskManager.HaveNpcTask(_propMoudleEx.CfgID);
|
|||
|
if (haveTask)
|
|||
|
{
|
|||
|
AddExcalmatorySymbol();
|
|||
|
}
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
}
|
|||
|
}
|