275 lines
9.5 KiB
C#
275 lines
9.5 KiB
C#
using System.Collections;
|
|
using Games.GlobeDefine;
|
|
using GCGame;
|
|
using GCGame.Table;
|
|
using Module.Log;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
namespace Games.LogicObj
|
|
{
|
|
public class Obj_DropItemData : Obj_Init_Data
|
|
{
|
|
public int _IsAutoPick;
|
|
public int m_nItemCount; //物品数量
|
|
public int m_nItemId; //物品Id
|
|
public int m_nType; //掉落类型
|
|
public ulong m_OwnerGuid; //归属者Guild
|
|
|
|
public Obj_DropItemData()
|
|
{
|
|
CleanUp();
|
|
}
|
|
|
|
public override void CleanUp()
|
|
{
|
|
base.CleanUp();
|
|
m_nType = -1;
|
|
m_nItemId = -1;
|
|
m_nItemCount = -1;
|
|
_IsAutoPick = -1;
|
|
m_OwnerGuid = GlobeVar.INVALID_GUID;
|
|
}
|
|
}
|
|
|
|
public class Obj_DropItem : Obj
|
|
{
|
|
public const int coinItemId = 13;
|
|
private int _IsAutoPick;
|
|
private bool bIsSendDrop; //延迟发送
|
|
|
|
public float m_fScaling = 2; //放大陪数
|
|
|
|
public float m_fStop = 0.2f; //停顿时间
|
|
|
|
private float m_fUpdateTimeSecond; //1秒钟执行一次掉落捡取,以防止不停刷背包已满.第一次没有限制
|
|
|
|
protected int m_nItemCount; //物品数量
|
|
|
|
protected ulong m_OwnerGuid; //归属者Guild
|
|
|
|
private Obj_DropHeadUI obj_DropHead;
|
|
|
|
public Obj_DropItem()
|
|
{
|
|
m_ObjType = GameDefine_Globe.OBJ_TYPE.OBJ_DROP_ITEM;
|
|
}
|
|
|
|
public override UIPathData HeadUiPath
|
|
{
|
|
get { return Obj_DropHeadUI.pathData; }
|
|
}
|
|
|
|
public GameDefine_Globe.DROP_TYPE DropType { get; set; }
|
|
public Tab_CommonItem TableData { get; set; }
|
|
|
|
public int ItemCount
|
|
{
|
|
get { return m_nItemCount; }
|
|
set { m_nItemCount = value; }
|
|
}
|
|
|
|
public ulong OwnerGuid
|
|
{
|
|
get { return m_OwnerGuid; }
|
|
set { m_OwnerGuid = value; }
|
|
}
|
|
public AnimationCurve m_Curve;
|
|
private float TimeTotle = 0;
|
|
private float YStart = 0;
|
|
public override bool Init(ObjParent_Init_Data initData1)
|
|
{
|
|
var result = base.Init(initData1);
|
|
if (!result)
|
|
return false;
|
|
var initData = initData1 as Obj_DropItemData;
|
|
if (initData == null)
|
|
return false;
|
|
if (null != GameManager.gameManager.ActiveScene &&
|
|
null != DropBoardManager.Instacne)
|
|
m_ObjTransform.SetParent(DropBoardManager.Instacne.gameObject.transform);
|
|
else
|
|
LogModule.ErrorLog("GameManager.gameManager.ActiveScene.DropItemBoardRoot is null");
|
|
|
|
DropType = (GameDefine_Globe.DROP_TYPE)initData.m_nType;
|
|
TableData = TableManager.GetCommonItemByID(DropType == GameDefine_Globe.DROP_TYPE.DROP_ITEM ? initData.m_nItemId : coinItemId, 0);
|
|
if (TableData == null)
|
|
{
|
|
LogModule.ErrorLog(string.Format("无法找到id={0}的物体数据!", initData.m_nItemId));
|
|
return false;
|
|
}
|
|
ItemCount = initData.m_nItemCount;
|
|
OwnerGuid = initData.m_OwnerGuid;
|
|
_IsAutoPick = initData._IsAutoPick;
|
|
|
|
transform.localRotation = Quaternion.identity;
|
|
transform.localScale = Vector3.one;
|
|
|
|
if(TableData.Quality == 4 || TableData.Quality == 5)
|
|
{
|
|
GameManager.gameManager.SoundManager.PlaySoundEffect(137);
|
|
}
|
|
SetItemModel();
|
|
CreateNameBoard();
|
|
ObjManager.Instance.AddPoolObj(this);
|
|
YStart = transform.localPosition.y;
|
|
TimeTotle = 0;
|
|
return true;
|
|
}
|
|
|
|
public override void InitNameBoard(Obj_HeadUI headUiItem)
|
|
{
|
|
base.InitNameBoard(headUiItem);
|
|
obj_DropHead = (Obj_DropHeadUI)headUiItem;
|
|
string itemName = string.Empty;
|
|
switch (DropType)
|
|
{
|
|
case GameDefine_Globe.DROP_TYPE.DROP_COIN:
|
|
itemName = ItemCount.ToString() + TableData.Name;
|
|
break;
|
|
case GameDefine_Globe.DROP_TYPE.DROP_ITEM:
|
|
itemName = Utils.GetQualityColorInTip(TableData.Quality) + TableData.Name + "</color>";
|
|
break;
|
|
}
|
|
obj_DropHead.SetName(itemName);
|
|
}
|
|
|
|
protected override void CreateModelOver(Hashtable hashParam)
|
|
{
|
|
base.CreateModelOver(hashParam);
|
|
|
|
ModelNode.model.transform.localPosition = Vector3.zero;
|
|
ModelNode.model.transform.localRotation = Quaternion.identity;
|
|
var charModel = TableManager.GetCharModelByID(TableData.DropIcon, 0);
|
|
if (charModel != null)
|
|
{
|
|
ModelNode.model.transform.localScale = Vector3.one * charModel.Scale;
|
|
}
|
|
PlayEffect(TableData.DropEffectId);
|
|
}
|
|
|
|
//更新Obj_DropItem逻辑数据
|
|
private void FixedUpdate()
|
|
{
|
|
if (Time.realtimeSinceStartup - m_fUpdateTimeSecond > m_fStop)
|
|
{
|
|
m_fUpdateTimeSecond = Time.realtimeSinceStartup;
|
|
//更新拾取
|
|
var ownerUser = Singleton<ObjManager>.Instance.MainPlayer;
|
|
if (null != ownerUser && ownerUser.GUID == OwnerGuid && ownerUser.IsDie() == false)
|
|
if (ownerUser.GetAutoCombatState()) // 挂机中自动拾取
|
|
{
|
|
if (DropType == GameDefine_Globe.DROP_TYPE.DROP_ITEM)
|
|
{
|
|
var backPack = GameManager.gameManager.PlayerDataPool.BackPack;
|
|
if (backPack.GetCanContainerSize() <= 0)
|
|
{
|
|
ownerUser.SendNoticMsg(true, "#{1039}");
|
|
return;
|
|
}
|
|
bIsSendDrop = false;
|
|
}
|
|
else if (DropType == GameDefine_Globe.DROP_TYPE.DROP_COIN)
|
|
{
|
|
bIsSendDrop = false;
|
|
}
|
|
}
|
|
}
|
|
if (YStart == 0 || TimeTotle > 1)
|
|
{
|
|
YStart = 0;
|
|
return;
|
|
}
|
|
TimeTotle += Time.deltaTime;
|
|
transform.localPosition = new Vector3(transform.localPosition.x, m_Curve.Evaluate(TimeTotle) + YStart, transform.localPosition.z);
|
|
}
|
|
|
|
private void PickEffect()
|
|
{
|
|
if (obj_DropHead != null)
|
|
obj_DropHead.DoPickUpEffect();
|
|
//播放拾取声音
|
|
if (null != GameManager.gameManager.SoundManager)
|
|
if (DropType == GameDefine_Globe.DROP_TYPE.DROP_COIN)
|
|
{
|
|
GameManager.gameManager.SoundManager.PlaySoundEffect(31); //pickup_coin
|
|
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{8018}", m_nItemCount));
|
|
}
|
|
else if (DropType == GameDefine_Globe.DROP_TYPE.DROP_ITEM)
|
|
{
|
|
GameManager.gameManager.SoundManager.PlaySoundEffect(32); //pickup_goods
|
|
int strId = 67105 + TableData.Quality;
|
|
if(TableData!=null)
|
|
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{" + strId.ToString() + "}",m_nItemCount, TableData.Name));
|
|
}
|
|
}
|
|
|
|
public void OnRemove()
|
|
{
|
|
if (_IsAutoPick <= 0)
|
|
return;
|
|
PickEffect();
|
|
}
|
|
|
|
public void OnPickSuccess()
|
|
{
|
|
if (_IsAutoPick > 0)
|
|
return;
|
|
PickEffect();
|
|
}
|
|
|
|
public void SendDropItem()
|
|
{
|
|
if (bIsSendDrop)
|
|
return;
|
|
bIsSendDrop = true;
|
|
var packet = (CG_ASK_PICKUP_ITEM)PacketDistributed.CreatePacket(MessageID.PACKET_CG_ASK_PICKUP_ITEM);
|
|
packet.SetObjId(ServerID);
|
|
packet.SendPacket();
|
|
}
|
|
|
|
public void SetItemModel()
|
|
{
|
|
if (GameManager.gameManager.SceneLogic != null)
|
|
{
|
|
var charModel = TableManager.GetCharModelByID(TableData.DropIcon, 0);
|
|
if (charModel == null)
|
|
LogModule.ErrorLog(string.Format("无法获得id={0}的掉落物品模型!", TableData.DropIcon));
|
|
else
|
|
{
|
|
m_DeltaHeight = charModel.HeadInfoHeight * ModelScale;
|
|
ModelID = TableData.DropIcon;
|
|
Hashtable table = new Hashtable();
|
|
CreateModel(ModelID);
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void DestroyObj()
|
|
{
|
|
OnRemove();
|
|
base.DestroyObj();
|
|
}
|
|
}
|
|
#region 掉落物品加载器
|
|
public class DropItemLoadData : BaseLoadData<Transform, DropItemLoadData>
|
|
{
|
|
public readonly Tab_CharModel modelData;
|
|
public DropItemLoadData(Transform root, Tab_CharModel modelData, UnityAction<Transform, DropItemLoadData> callback) : base(root, callback)
|
|
{
|
|
this.modelData = modelData;
|
|
}
|
|
}
|
|
|
|
public class DropItemLoadTask : BaseLoadTask<Transform, DropItemLoadData, DropItemLoadTask>
|
|
{
|
|
}
|
|
|
|
public class DropItemPool : AutoLoadPool<Transform, DropItemLoadData, DropItemLoadTask>
|
|
{
|
|
public DropItemPool(Transform root) : base(root, false, null)
|
|
{
|
|
}
|
|
}
|
|
#endregion
|
|
} |