Files
Main/Assets/Code/Logic/_Required/Entity/Object/Collection.cs

232 lines
7.5 KiB
C#
Raw Normal View History

2025-01-25 04:38:09 +08:00
using Thousandto.Core.Asset;
using Thousandto.Core.Base;
using Thousandto.Plugins.Common.UniScene;
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using Thousandto.Cfg.Data;
using Thousandto.Code.Global;
using Thousandto.Code.Center;
using Thousandto.Core.Support;
using Thousandto.Plugins.Common;
using Thousandto.Code.Logic.LocalPlayerBT;
namespace Thousandto.Code.Logic
{
//采集物
public class Collection : Character
{
#region//私有变量
private float _offsetTime = 1f;
//属性模块
private CollectionPropterty _propMoudleEx = null;
private uint _taskSymbolVfxID = 0;
//配置
private DeclareGather _cfg = null;
#endregion
#region//属性信息
public new CollectionPropterty PropMoudle
{
get
{
if (_propMoudleEx == null)
{
_propMoudleEx = base.PropMoudle as CollectionPropterty;
}
return _propMoudleEx;
}
}
#endregion
#region//构造函数
public Collection()
{
GameCenter.RegFixEventHandle(LogicEventDefine.EID_EVENT_TASKINIT, OnTaskChanged);
GameCenter.RegFixEventHandle(LogicEventDefine.EID_EVENT_TASKFINISH, OnTaskChanged);
}
#endregion
#region//头顶符号效果 -- 用于任务处理
//添加问号
private void AddSymbol()
{
if (_taskSymbolVfxID != 0)
{
//VfxPlayer.Stop(_taskSymbolVfxID);
}
//_taskSymbolVfxID = VfxPlayer.Play(SceneVFXUtils.TaskSymbolPath_Collection, true, null, null, -1, 1f, 1f, SceneVFXUtils.SymbolOffset);
}
//关闭任务符号
private void CloseSymbol()
{
if (_taskSymbolVfxID != 0)
{
//VfxPlayer.Stop(_taskSymbolVfxID);
_taskSymbolVfxID = 0;
}
}
#endregion
#region//初始化,加载Skin,卸载处理
protected override FSkinBase OnSetupSkin()
{
FSkinModel skin = GameCenter.LuaSystem.Adaptor.CreateFSkinModel(FSkinTypeCode.Custom);
skin.SetLayer(LayerUtils.Monster);
skin.SetMipmapLevel(0.5f);
skin.SetOnSkinPartChangedHandler((x, y) => { OnTaskChanged(null); });
return skin;
}
protected override bool OnInitializeAfter(EntityInitInfo baseInfo)
{
var initInfo = baseInfo as CollectionInitInfo;
base.OnInitializeAfter(baseInfo);
SyncInfo(initInfo);
OnTaskChanged(null);
return true;
}
public void SyncInfo(CollectionInitInfo initInfo)
{
_cfg = DeclareGather.Get((int)initInfo.CfgID);
_propMoudle = _propMoudleEx = new CollectionPropterty(this, _cfg);
BodyScale = _cfg.SizeScale / 100f;
SetDirection(initInfo.GetDirection(), false);
int specialModel = -1;
//if(GameCenter.MapLogicSystem.ActiveLogic != null)
//{
// specialModel = GameCenter.MapLogicSystem.ActiveLogic.GetSpecialCollectionModel(this);
//}
if(specialModel > 0)
{
Skin.SetSkinPartFromCfgID(FSkinPartCode.Body, specialModel);
}
else
{
Skin.SetSkinPartFromCfgID(FSkinPartCode.Body, _cfg.Res);
}
if (_cfg.ShowName != 0)
{
ShowHUD();
}
}
public void LoadSpecialModel(int modelID)
{
if(modelID > 0)
{
Skin.SetSkinPartFromCfgID(FSkinPartCode.Body, modelID);
}
}
protected override void OnUninitializeBefore()
{
GameCenter.UnRegFixEventHandle(LogicEventDefine.EID_EVENT_TASKINIT, OnTaskChanged);
GameCenter.UnRegFixEventHandle(LogicEventDefine.EID_EVENT_TASKFINISH, OnTaskChanged);
CloseSymbol();
HideHUD();
base.OnUninitializeBefore();
}
//选择
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);
//SceneVFXUtils.DestorySelectVFX();
}
protected override void OnUpdate(float elapsedTime)
{
base.OnUpdate(elapsedTime);
LocalPlayer lp = GameCenter.GameSceneSystem.GetLocalPlayer();
if (lp == null)
return;
if (lp.IsXState(EntityStateID.Collect))
{
_offsetTime = 1f;
}
if (!lp.IsXState(EntityStateID.Collect))
{
if (_offsetTime > 0f)
{
_offsetTime -= elapsedTime;
}
else
{
_offsetTime = 0f;
}
}
bool isShow = false;
float sprDis = Vector2.SqrMagnitude(Position2d - lp.Position2d);
if (sprDis <= 16f && _propMoudleEx.Cfg.ShowButton == 1 && !PlayerBT.IsState(PlayerBDState.CollectState) && !lp.IsXState(EntityStateID.Collect))
{
isShow = true;
}
if (isShow && !GameCenter.GatherTishiSystem.IsOpen && _offsetTime == 0f)
{
//判断当前地图是否是仙盟战副本
if (GameCenter.GameSceneSystem.GetActivedScene().Cfg.MapLogicType == 33)
{
if (GameCenter.LuaSystem.Adaptor.GetXmFightCamp() == 1)
{
//如果是防守方
GameCenter.PushFixEvent(UIEventDefine.UIGaterTishiForm_OPEN, ID);
}
}
else
{
GameCenter.PushFixEvent(UIEventDefine.UIGaterTishiForm_OPEN, ID);
}
//if (!GameCenter.ElementSystem.FightFlagCanBeCollect(ID))
}
if (GameCenter.GatherTishiSystem.IsOpen)
{
if (lp.IsXState(EntityStateID.Collect) || lp.IsXState(EntityStateID.FlyTeleport))
{
GameCenter.PushFixEvent(UIEventDefine.UIGaterTishiForm_CLOSE);
}
}
}
#endregion
#region//私有方法
//任务改变处理
private void OnTaskChanged(object obj, object sender = null)
{
//if (PropMoudle.Cfg.Type != (int)CollectionType.Task)
// return;
//TaskTargetType t = 0;
//int id = 0;
//bool isFinsh = false;
//if (GameCenter.RoleTaskSystem.GetMainTaskTargetInfo(ref t,ref id, ref isFinsh))
//{
// if (t == TaskTargetType.TARGETTYPE_COLLECT && id == PropMoudle.CfgID && isFinsh == false)
// {
// AddSymbol();
// }
// else
// {
// CloseSymbol();
// }
//}
}
#endregion
}
}