256 lines
8.3 KiB
C#
256 lines
8.3 KiB
C#
|
using UnityEngine;
|
|||
|
using System.Collections;
|
|||
|
using Games.Item;
|
|||
|
using GCGame.Table;
|
|||
|
using Games.GlobeDefine;
|
|||
|
using System.Collections.Generic;
|
|||
|
using Module.Log;
|
|||
|
|
|||
|
public class TresureItem :Singleton<TresureItem>
|
|||
|
{
|
|||
|
void OnEnable()
|
|||
|
{
|
|||
|
GameManager.gameManager.PlayerDataPool.InTreasureState = true;
|
|||
|
}
|
|||
|
|
|||
|
void OnDisable()
|
|||
|
{
|
|||
|
GameManager.gameManager.PlayerDataPool.InTreasureState = false;
|
|||
|
}
|
|||
|
|
|||
|
public static float _AnimTime = 2;
|
|||
|
public static float AnimTime
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (_AnimTime < 0)
|
|||
|
{
|
|||
|
_AnimTime = SystemParam.GetSystemParam_FLOAT(24);
|
|||
|
}
|
|||
|
return _AnimTime;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void UseTresureItemInBackPack(GameItem gameItem)
|
|||
|
{
|
|||
|
if (gameItem.GetClass() != (int)ItemClass.TRESURE)
|
|||
|
return;
|
|||
|
|
|||
|
if (gameItem.GetSubClass() == (int)TresureSubClass.PosClearLow
|
|||
|
|| gameItem.GetSubClass() == (int)TresureSubClass.PosClearMid
|
|||
|
|| gameItem.GetSubClass() == (int)TresureSubClass.PosClearHeight
|
|||
|
|| gameItem.GetSubClass() == (int)TresureSubClass.PosClearGold)
|
|||
|
{
|
|||
|
UseDefinedTresure(gameItem);
|
|||
|
}
|
|||
|
else if (gameItem.GetSubClass() == (int)TresureSubClass.PosNotClearLow)
|
|||
|
{
|
|||
|
UseDefinedTresure(gameItem);
|
|||
|
}
|
|||
|
else if (gameItem.GetSubClass() == (int)TresureSubClass.PosNotClearHeight)
|
|||
|
{
|
|||
|
UIManager.CloseUI(UIInfo.BackPackRoot);
|
|||
|
PosNotClearItemMid(gameItem);
|
|||
|
}
|
|||
|
else if (gameItem.GetSubClass() == (int)TresureSubClass.Lottery)
|
|||
|
{
|
|||
|
UseDefinedTresure(gameItem);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void UseDefinedTresure(GameItem gameitem)
|
|||
|
{
|
|||
|
UIManager.CloseUI(UIInfo.BackPackRoot);
|
|||
|
TreasureItemLogic.InitItemInfo(gameitem);
|
|||
|
}
|
|||
|
|
|||
|
public void Update()
|
|||
|
{
|
|||
|
if (_SearchItem == null)
|
|||
|
return;
|
|||
|
|
|||
|
AnimUpdate();
|
|||
|
}
|
|||
|
|
|||
|
#region
|
|||
|
|
|||
|
private GameItem _SearchItem = null;
|
|||
|
public GameItem SearchItem
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return _SearchItem;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void UseTresureInUI(GameItem gameItem)
|
|||
|
{
|
|||
|
if (gameItem.GetSubClass() == (int)TresureSubClass.PosClearLow
|
|||
|
|| gameItem.GetSubClass() == (int)TresureSubClass.PosClearMid
|
|||
|
|| gameItem.GetSubClass() == (int)TresureSubClass.PosClearHeight
|
|||
|
|| gameItem.GetSubClass() == (int)TresureSubClass.PosClearGold)
|
|||
|
{
|
|||
|
PosClearItem(gameItem);
|
|||
|
}
|
|||
|
else if (gameItem.GetSubClass() == (int)TresureSubClass.PosNotClearLow)
|
|||
|
{
|
|||
|
PosNotClearItem(gameItem);
|
|||
|
}
|
|||
|
else if (gameItem.GetSubClass() == (int)TresureSubClass.PosNotClearHeight)
|
|||
|
{
|
|||
|
PosNotClearItemMid(gameItem);
|
|||
|
}
|
|||
|
else if (gameItem.GetSubClass() == (int)TresureSubClass.Lottery)
|
|||
|
{ }
|
|||
|
}
|
|||
|
|
|||
|
private void PosClearItem(GameItem gameItem)
|
|||
|
{
|
|||
|
Tab_TreasureBase treasureTab = TableManager.GetTreasureBaseByID(gameItem.DataID, 0);
|
|||
|
if (treasureTab == null)
|
|||
|
return;
|
|||
|
|
|||
|
_SearchItem = gameItem;
|
|||
|
AutoSearchTreasurePos(treasureTab.ScneneId, new Vector3(treasureTab.GetPosXbyIndex(0), 0, treasureTab.GetPosYbyIndex(0)), gameItem);
|
|||
|
}
|
|||
|
|
|||
|
public void AutoSearchTreasurePos(int sceneID, Vector3 pos, GameItem gameItem)
|
|||
|
{
|
|||
|
Singleton<ObjManager>.GetInstance().MainPlayer.BreakAutoCombatState();
|
|||
|
|
|||
|
// 自动寻路
|
|||
|
AutoSearchPoint point = new AutoSearchPoint(sceneID, pos.x, pos.z);
|
|||
|
if (GameManager.gameManager && GameManager.gameManager.AutoSearch)
|
|||
|
{
|
|||
|
GameManager.gameManager.AutoSearch.BuildPath(point);
|
|||
|
if (null != GameManager.gameManager.AutoSearch.Path)
|
|||
|
{
|
|||
|
GameManager.gameManager.AutoSearch.Path.autoSearchRadius = 1;
|
|||
|
GameManager.gameManager.AutoSearch.Path.AutoSearchTargetID = -1;
|
|||
|
GameManager.gameManager.AutoSearch.Path.finishCallBack = AutoSearchCallBack;
|
|||
|
GameManager.gameManager.AutoSearch.Path.callBackParam = gameItem;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private List<int> treasureActionNameList = new List<int> { 5600, 5601, 5602, 5603 };
|
|||
|
private void AutoSearchCallBack(object param)
|
|||
|
{
|
|||
|
var mainPlayer = Singleton<ObjManager>.GetInstance().MainPlayer;
|
|||
|
if (mainPlayer == null || mainPlayer.IsUsingSkill || Singleton<ObjManager>.GetInstance().MainPlayer.IsHaveNoMoveBuff())
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (GameManager.gameManager.PlayerDataPool.IsInMeditateState)
|
|||
|
mainPlayer.BreakMeditate();
|
|||
|
|
|||
|
mainPlayer.AskUnMount();
|
|||
|
mainPlayer.OnSwithObjAnimState(Games.GlobeDefine.GameDefine_Globe.OBJ_ANIMSTATE.STATE_FINSH);
|
|||
|
mainPlayer.AnimLogic.Play((int)CharacterDefine.CharacterAnimId.COLLECTACTION);
|
|||
|
var strdicId = "#{" + treasureActionNameList[Random.Range(0, 3)] + "}";
|
|||
|
SkillProgressLogic.PlayProcess(SkillProgressLogic.ProgressModel.ORDERMODEL, AnimTime, StrDictionary.GetClientDictionaryString(strdicId));
|
|||
|
_ActingTime = AnimTime;
|
|||
|
}
|
|||
|
|
|||
|
private void BreakAnim()
|
|||
|
{
|
|||
|
SkillProgressLogic.StopProcess(0);
|
|||
|
_SearchItem = null;
|
|||
|
_ActingTime = 0;
|
|||
|
}
|
|||
|
|
|||
|
private float _ActingTime = 0;
|
|||
|
private void AnimUpdate()
|
|||
|
{
|
|||
|
if (_ActingTime <= 0)
|
|||
|
return;
|
|||
|
|
|||
|
_ActingTime -= Time.deltaTime;
|
|||
|
if (Singleton<ObjManager>.GetInstance().MainPlayer.CurObjAnimState != GameDefine_Globe.OBJ_ANIMSTATE.STATE_FINSH)
|
|||
|
{
|
|||
|
BreakAnim();
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (_ActingTime <= 0)
|
|||
|
{
|
|||
|
SendTreasureItem(_SearchItem);
|
|||
|
|
|||
|
Singleton<ObjManager>.GetInstance().MainPlayer.OnSwithObjAnimState(Games.GlobeDefine.GameDefine_Globe.OBJ_ANIMSTATE.STATE_NORMOR);
|
|||
|
//_SearchItem = null;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void SendTreasureItem(GameItem treasureItem)
|
|||
|
{
|
|||
|
LogModule.DebugLog("SendTreasureItem");
|
|||
|
if (treasureItem != null && treasureItem.IsValid())
|
|||
|
{
|
|||
|
if (null != Singleton<ObjManager>.Instance.MainPlayer)
|
|||
|
{
|
|||
|
Singleton<ObjManager>.Instance.MainPlayer.UseItem(treasureItem);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (treasureItem.StackCount > 1)
|
|||
|
{
|
|||
|
TreasureItemLogic.InitItemInfo(treasureItem);
|
|||
|
UseTresureInUI(treasureItem);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
var treasureList = ItemTool.ItemFilter(GameManager.gameManager.PlayerDataPool.BackPack, (int)ItemClass.TRESURE, (int)TresureSubClass.PosClearLow, false);
|
|||
|
treasureList.AddRange(ItemTool.ItemFilter(GameManager.gameManager.PlayerDataPool.BackPack, (int)ItemClass.TRESURE, (int)TresureSubClass.PosClearMid, false));
|
|||
|
treasureList.AddRange(ItemTool.ItemFilter(GameManager.gameManager.PlayerDataPool.BackPack, (int)ItemClass.TRESURE, (int)TresureSubClass.PosClearHeight, false));
|
|||
|
treasureList.AddRange(ItemTool.ItemFilter(GameManager.gameManager.PlayerDataPool.BackPack, (int)ItemClass.TRESURE, (int)TresureSubClass.PosClearGold, false));
|
|||
|
foreach (var treasure in treasureList)
|
|||
|
{
|
|||
|
if (treasure != treasureItem)
|
|||
|
{
|
|||
|
TreasureItemLogic.InitItemInfo(treasure);
|
|||
|
UseTresureInUI(treasure);
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
_SearchItem = null;
|
|||
|
UIManager.CloseUI(UIInfo.TreasureItemRoot);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void PosNotClearItem(GameItem gameItem)
|
|||
|
{
|
|||
|
Tab_TreasureBase treasureTab = TableManager.GetTreasureBaseByID(gameItem.DataID, 0);
|
|||
|
if (treasureTab == null)
|
|||
|
return;
|
|||
|
|
|||
|
if (GameManager.gameManager.ActiveScene.CurSceneServerID != treasureTab.ScneneId)
|
|||
|
{
|
|||
|
GUIData.AddNotifyData( StrDictionary.GetClientDictionaryString("#{5009}"));
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
float distance = Vector2.Distance(new Vector2(Singleton<ObjManager>.Instance.MainPlayer.Position.x, Singleton<ObjManager>.Instance.MainPlayer.Position.z),
|
|||
|
new Vector2(treasureTab.GetPosXbyIndex(0), treasureTab.GetPosYbyIndex(0)));
|
|||
|
|
|||
|
if (distance < 2)
|
|||
|
{
|
|||
|
SendTreasureItem(gameItem);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{5010}"));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void PosNotClearItemMid(GameItem gameItem)
|
|||
|
{
|
|||
|
|
|||
|
TreasureSceneMap.ShowTreasureMap(gameItem);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
}
|