//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Thursday, September 21, 2017
|
//--------------------------------------------------------
|
|
using vnxbqy.UI;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
namespace vnxbqy.UI
|
{
|
|
public class TaskBoxBGMWin : Window
|
{
|
|
[SerializeField] Text _NpcName;//NPC名
|
[SerializeField] Text _TextTaskDescription;//对话内容
|
[SerializeField] Text _TextRewards;//按钮内容
|
[SerializeField] Button _BtnRewards;//领取奖励按钮
|
[SerializeField] Button _Close;//关闭按钮
|
[SerializeField] Transform _Grid;//动态创建节点
|
[SerializeField] Text _TextTaskName;//任务名称
|
[SerializeField] GameObject m_ImageReward;
|
[SerializeField] Text m_AutomaticThreadTask_Text;
|
private int _TaskId = 0;//获取任务ID
|
private int _NpcID = 0;//获取NPCID
|
private int _Gold = 0;//获取流动仙玉
|
private string StrConversa = null;//对话内容接收
|
Dictionary<int, MissionDetailDates> _AllMissionDict;//任务初始化接收字典
|
private List<RewardAnalysis.RewardInfo> rewardList = new List<RewardAnalysis.RewardInfo>();
|
TaskModel m_TaskModel;
|
TaskModel taskmodel { get { return m_TaskModel ?? (m_TaskModel = ModelCenter.Instance.GetModel<TaskModel>()); } }
|
|
PackModel _playerPack;
|
PackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); } }
|
|
VipModel m_Vipmodel;
|
VipModel vipmodel { get { return m_Vipmodel ?? (m_Vipmodel = ModelCenter.Instance.GetModel<VipModel>()); } }
|
|
TreasureModel m_treasureModel;
|
TreasureModel treasureModel { get { return m_treasureModel ?? (m_treasureModel = ModelCenter.Instance.GetModel<TreasureModel>()); } }
|
|
PlayerMainDate m_MainModel;
|
PlayerMainDate mainModel { get { return m_MainModel ?? (m_MainModel = ModelCenter.Instance.GetModel<PlayerMainDate>()); } }
|
private int FabaoId;
|
private int AwaitSecond;
|
private int AwaitSecondNext;
|
private float LatencyTime = 0;//等待时间
|
#region Built-in
|
protected override void BindController()
|
{
|
var config = FuncConfigConfig.Get("TaskContinue");
|
FabaoId = int.Parse(config.Numerical1);
|
AwaitSecond = int.Parse(config.Numerical2);
|
AwaitSecondNext = int.Parse(config.Numerical3);
|
}
|
|
protected override void AddListeners()
|
{
|
_BtnRewards.onClick.AddListener(BtnRewards);
|
_Close.onClick.AddListener(Closee);
|
}
|
|
protected override void OnPreOpen()
|
{
|
LatencyTime = 0;
|
|
_TextTaskDescription.text = "";
|
_Gold = (int)PlayerDatas.Instance.baseData.diamond;
|
_BtnRewards.SetActive(false);
|
_AllMissionDict = taskmodel.allMissionDict;
|
_TaskId = taskmodel._TaskNow;
|
_NpcID = taskmodel.NPCid;
|
if (taskmodel.MainTaskDic.ContainsKey(_TaskId))
|
{
|
m_AutomaticThreadTask_Text.SetActive(true);
|
}
|
else
|
{
|
m_AutomaticThreadTask_Text.SetActive(false);
|
}
|
StrConversa = null;
|
StrConversa = taskmodel._conversation;
|
TypeJudgment();//类型判断
|
ContentAssignment();//内容赋值
|
|
if (!taskmodel.MainTaskDic.ContainsKey(_TaskId))
|
{
|
var npcConfig = NPCConfig.Get(_NpcID);
|
if (npcConfig != null)
|
{
|
if (npcConfig.NPCSpeakID != 0)
|
{
|
SoundPlayer.Instance.PlayNpcAudio(npcConfig.NPCSpeakID);
|
}
|
}
|
}
|
}
|
|
protected override void OnAfterOpen()
|
{
|
StartCoroutine("GetEnumerator");//自动任务
|
}
|
|
protected override void OnPreClose()
|
{
|
if (PlayerDatas.Instance.hero.State != E_ActorState.AutoRun)
|
{
|
MapTransferUtility.Instance.Clear();
|
}
|
StopCoroutine("GetEnumerator");
|
StopCoroutine("LateRelease");
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
|
private void IsOpenMaininterface()
|
{
|
Close();
|
}
|
#endregion
|
IEnumerator GetEnumerator()
|
{
|
yield return WaitingForSecondConst.WaitMS1500;
|
TheAutomaticTask();
|
yield break;
|
}
|
|
void TheAutomaticTask()//自动任务
|
{
|
if (_AllMissionDict.ContainsKey(_TaskId))
|
{
|
|
if (_AllMissionDict[_TaskId].Type == 7 || _AllMissionDict[_TaskId].Type == 12)
|
{
|
if (!ModelCenter.Instance.GetModel<TeamModel>().teamPrepare.isPreparing)
|
{
|
taskmodel.RequestGetTaskAward("OK", _TaskId);
|
WindowCenter.Instance.Close<TaskBoxBGMWin>();
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
}
|
|
}
|
}
|
}
|
void BtnRewards()
|
{
|
int blank = playerPack.GetEmptyGridCount(PackType.Item);
|
if (blank < 1)
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("BackpackReward_Z"));
|
return;
|
}
|
if (!_AllMissionDict.ContainsKey(_TaskId))
|
{
|
Closee();
|
return;
|
}
|
taskmodel.RequestGetTaskAward("OK", _TaskId);
|
mainModel.IsSelfMotionTask = false;
|
SelectionManager.Release(SelectionManager.E_Type.Green);
|
StartCoroutine("LateRelease");
|
}
|
|
IEnumerator LateRelease()
|
{
|
yield return WaitingForSecondConst.WaitMS500;
|
WindowCenter.Instance.Close<TaskBoxBGMWin>();
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
yield break;
|
}
|
|
void Closee()
|
{
|
C080A_tagCCancelEvent _C080A = new C080A_tagCCancelEvent();
|
GameNetSystem.Instance.SendInfo(_C080A);
|
Close();
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
SelectionManager.Release(SelectionManager.E_Type.Green);
|
StopCoroutine("GetEnumerator");
|
StopCoroutine("LateRelease");
|
}
|
|
void ContentAssignment()//内容赋值
|
{
|
NPCConfig Npc = NPCConfig.Get(_NpcID);
|
_NpcName.text = Npc.charName;
|
var config = TASKINFOConfig.Get(_AllMissionDict[_TaskId].Name);
|
if (config == null)
|
{
|
DebugEx.LogError("任务表格配置错误");
|
return;
|
}
|
_TextTaskName.text = config.show_writing;
|
var taskInfoConfig = TASKINFOConfig.Get(StrConversa);
|
if (taskInfoConfig == null)
|
{
|
taskInfoConfig = TASKINFOConfig.Get(StrConversa.ToLower());
|
if(taskInfoConfig == null)
|
{
|
DebugEx.LogError("任务表格配置错误");
|
return;
|
}
|
|
}
|
if (taskmodel.BountyDic.ContainsKey(_TaskId) || taskmodel.FairyAuDic.ContainsKey(_TaskId))
|
{
|
string _taskInfoKey = string.Format("d_{0}_0_1", _NpcID);
|
if (TASKINFOConfig.Get(_taskInfoKey) == null)
|
return;
|
TASKINFOConfig DefaultDialogContent = TASKINFOConfig.Get(_taskInfoKey);
|
_TextTaskDescription.text= DefaultDialogContent.show_writing;
|
}
|
else
|
{
|
_TextTaskDescription.text = taskInfoConfig.show_writing;
|
}
|
|
|
|
var rewardTaskInfoConfig = TASKINFOConfig.Get(_AllMissionDict[_TaskId].RewardList);
|
if (rewardTaskInfoConfig == null)
|
{
|
DebugEx.LogError("任务表格配置错误");
|
return;
|
}
|
string _RewardStr = TaskAllocation.Instance.GetTaskInfo(rewardTaskInfoConfig.show_writing, _TaskId);//获取奖励信息
|
RewardAnalysis.Inst.GetReward(_RewardStr, ref rewardList);
|
RewardInformationDisplay(rewardList);
|
}
|
|
void TypeJudgment()//类型判断
|
{
|
_AllMissionDict = taskmodel.allMissionDict;
|
if (_TaskId == 0 || !_AllMissionDict.ContainsKey(_TaskId))
|
{
|
foreach (int key in _AllMissionDict.Keys)
|
{
|
if (_AllMissionDict[key].LightList.Equals(default(TsakLight)))
|
{
|
continue;
|
}
|
for (int i = 0; i < _AllMissionDict[key].LightList.Count; i++)
|
{
|
if (_AllMissionDict[key].LightList[i].NpcId == _NpcID)
|
{
|
_TaskId = key;
|
}
|
}
|
if (_NpcID == _AllMissionDict[key].NPC_ID)
|
{
|
_TaskId = key;
|
}
|
//if (_NpcID == _AllMissionDict[key].LightList.NpcId)
|
// _TaskId = key;
|
//else if (_NpcID == _AllMissionDict[key].NPC_ID)
|
// _TaskId = key;
|
}
|
}
|
int _TaskType = 0;
|
_TaskType = int.Parse(FuncConfigConfig.Get("MissionType").Numerical1);
|
_BtnRewards.SetActive(true);
|
|
|
if (_AllMissionDict[_TaskId].ColorLV == 2 && _AllMissionDict[_TaskId].MissionState == 1)
|
{
|
_TextRewards.text = Language.Get("EnterACopy_Z");
|
m_ImageReward.SetActive(true);
|
}
|
else if ((_AllMissionDict[_TaskId].Type == 7 || _AllMissionDict[_TaskId].Type == 12) && _AllMissionDict[_TaskId].MissionState == 1)
|
{
|
_TextRewards.text = Language.Get("TaskBoxWin_BtnReward_Text_1");
|
m_ImageReward.SetActive(true);
|
}
|
else
|
{
|
_TextRewards.text = Language.Get("TaskBoxWin_BtnGetReward_Text_1");
|
m_ImageReward.SetActive(true);
|
}
|
if (_AllMissionDict[_TaskId].Type == 13 || _AllMissionDict[_TaskId].Type == 14)
|
{
|
_TextRewards.text = Language.Get("TaskBoxWin_BtnReward_Text_1");
|
m_ImageReward.SetActive(false);
|
}
|
}
|
|
void RewardInformationDisplay(List<RewardAnalysis.RewardInfo> rewardList)//奖励信息
|
{
|
if (_Grid.childCount != 0)
|
{
|
for (int i = 0; i < _Grid.childCount; i++)
|
{
|
DestroyObject(_Grid.GetChild(i).gameObject);
|
}
|
}
|
if (rewardList.Count == 0)
|
return;
|
if ((_AllMissionDict[_TaskId].Type == 7 || _AllMissionDict[_TaskId].Type == 12) && _AllMissionDict[_TaskId].MissionState == 1)
|
return;
|
for (int i = 0; i < rewardList.Count; i++)
|
{
|
GameObject go = GameObject.Instantiate(UILoader.LoadPrefab("ItemCell"));
|
ItemCell itemcell = go.GetComponent<ItemCell>();
|
go.transform.SetParent(_Grid);
|
go.transform.localScale = Vector3.one;
|
Vector3 pos = go.transform.localPosition;
|
go.transform.localPosition = pos.SetZ(0);
|
Button _button = go.transform.GetComponent<Button>();
|
ulong number = 0;
|
if (rewardList[i].expPoint != 0)
|
{
|
number = (ulong)rewardList[i].expPoint * 100000000;
|
number += (ulong)rewardList[i].num;
|
}
|
else
|
{
|
number = (ulong)rewardList[i].num;
|
}
|
ItemCellModel cellModel = new ItemCellModel(rewardList[i].itemCfg.ID, true, (ulong)number);
|
itemcell.Init(cellModel);
|
itemcell.button.RemoveAllListeners();
|
int tab = i;
|
itemcell.button.AddListener(() =>
|
{
|
ItemTipUtility.Show(rewardList[tab].itemCfg.ID);
|
});
|
}
|
}
|
|
protected override void LateUpdate()
|
{
|
base.LateUpdate();
|
if (WindowCenter.Instance.IsOpen("MainInterfaceWin"))
|
{
|
WindowCenter.Instance.Close<TaskBoxBGMWin>();
|
}
|
|
GetMainSelfMotionLaupdate();
|
|
var hero = PlayerDatas.Instance.hero;
|
if (hero != null && hero.LockTarget != null)
|
{
|
var checkDistSqrt = MathUtility.DistanceSqrtXZ(hero.Pos, hero.LockTarget.Pos);
|
if (checkDistSqrt > Mathf.Pow(GeneralDefine.FarawayNpcDist, 2))
|
{
|
WindowCenter.Instance.Close<TaskBoxBGMWin>();
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
hero.LockTarget = null;
|
}
|
}
|
}
|
|
private void GetMainSelfMotionLaupdate()
|
{
|
Treasure treasure = null;
|
if (treasureModel.TryGetTreasure(FabaoId, out treasure))
|
{
|
if (treasure.state == TreasureState.Collected || NewBieCenter.Instance.inGuiding)
|
{
|
if (m_AutomaticThreadTask_Text.gameObject.activeSelf)
|
{
|
m_AutomaticThreadTask_Text.SetActive(false);
|
}
|
return;
|
}
|
}
|
if (taskmodel.MainTaskDic.ContainsKey(_TaskId))
|
{
|
if (!m_AutomaticThreadTask_Text.gameObject.activeSelf)
|
{
|
m_AutomaticThreadTask_Text.SetActive(true);
|
}
|
LatencyTime += Time.deltaTime;
|
if (mainModel.IsSelfMotionTask)
|
{
|
if (AwaitSecondNext >= LatencyTime)
|
{
|
m_AutomaticThreadTask_Text.text = string.Format(Language.Get("TaskContinueCount"), AwaitSecondNext - (int)LatencyTime);
|
}
|
else
|
{
|
m_AutomaticThreadTask_Text.SetActive(false);
|
Autorun();
|
}
|
}
|
else
|
{
|
if (AwaitSecond >= LatencyTime)
|
{
|
m_AutomaticThreadTask_Text.text = string.Format(Language.Get("TaskContinueCount"), AwaitSecond - (int)LatencyTime);
|
}
|
else
|
{
|
m_AutomaticThreadTask_Text.SetActive(false);
|
Autorun();
|
}
|
}
|
}
|
|
}
|
private void Autorun()
|
{
|
int blank = playerPack.GetEmptyGridCount(PackType.Item);
|
if (blank < 1)
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("BackpackReward_Z"));
|
return;
|
}
|
if (!_AllMissionDict.ContainsKey(_TaskId))
|
{
|
Closee();
|
return;
|
}
|
taskmodel.RequestGetTaskAward("OK", _TaskId);
|
mainModel.IsSelfMotionTask = true;
|
SelectionManager.Release(SelectionManager.E_Type.Green);
|
StartCoroutine("LateRelease");
|
}
|
}
|
|
}
|