429 lines
13 KiB
C#
429 lines
13 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using UnityEngine.UI;
|
|
using GCGame.Table;
|
|
using Games.Mission;
|
|
using System.Collections.Generic;
|
|
|
|
//可以挑战的对手信息
|
|
public class RoleInfo
|
|
{
|
|
public string name;
|
|
public int carrer;
|
|
public int combat;
|
|
public int rank;
|
|
public int level;
|
|
public ulong guid;
|
|
public RoleInfo(string _Name, int _Carrer, int _Combat, int _Rank, int _Level, ulong _Guid)
|
|
{
|
|
name = _Name;
|
|
carrer = _Carrer;
|
|
combat = _Combat;
|
|
rank = _Rank;
|
|
level = _Level;
|
|
guid = _Guid;
|
|
}
|
|
}
|
|
|
|
|
|
public class FactionChallengeCtr : MonoBehaviour {
|
|
|
|
public enum Toggle_Type
|
|
{
|
|
Reward = 0,
|
|
SCORESHOP,
|
|
RANK,
|
|
FIGHTRECORD,
|
|
}
|
|
|
|
#region 拖拽UI控件
|
|
//排名 战斗力
|
|
public Text MyRankText;
|
|
public Text MyFightNumberText;
|
|
//public Text ThirteenRankText;
|
|
//public Text NighteenRankText;
|
|
//public Text TwentyThreeRankText;
|
|
|
|
//剩余挑战次数 时间
|
|
public Text TodayRemainChallengeTimes;
|
|
public Text NextChallengeTimes;
|
|
|
|
//金钱消耗 拥有 加钱
|
|
public Text BeginCostMoneyText;
|
|
//public Text CurrentOwnMoneyText;
|
|
//public Button AddMoneyButton;
|
|
public GameObject cdTimePanel;
|
|
|
|
//重置 快速开始 换一批
|
|
public Button ResetChallengeButtton;
|
|
public Text ResetAndQuickStartText;
|
|
public Button ChnageOtherButton;
|
|
|
|
//切换界面Toggle
|
|
// public List<GameObject> _MarkIconList;
|
|
|
|
//对手信息item、父节点
|
|
public GameObject RoleInfoItem;
|
|
public Transform RoleInfoItem_Parent;
|
|
|
|
//对手信息展示
|
|
public RoleInfoItem[] roleInfoItem;
|
|
|
|
private const int todayTotalChallengTimes = 5;//每天可以免费挑战5次
|
|
|
|
//Model
|
|
//public UICameraTexture _UICameraTexture;
|
|
|
|
#endregion
|
|
|
|
private void OnEnable()
|
|
{
|
|
GetActivityBase();
|
|
//请求面板信息协议
|
|
AskChallgeneInfo();
|
|
//请求可以挑战的挑战者信息协议(跟换一批的协议一样)
|
|
OnChangeOtherBtnClick();
|
|
SetCurFactionValue();
|
|
}
|
|
|
|
public Text _FactionValue;
|
|
public void SetCurFactionValue()
|
|
{
|
|
_FactionValue.text = GameManager.gameManager.PlayerDataPool.Money.GetMoneyByType(
|
|
MONEYTYPE.MONEYTYPE_USERCHALLENGE).ToString();
|
|
}
|
|
|
|
private Tab_ActivityBase activityBase = null;
|
|
public void GetActivityBase()
|
|
{
|
|
activityBase = ActivityDataManager.Instance.GetActivityTabByServerType(ActivityDataManager.Activity_Type.ACTIVITY_FACTIONCHALLENGE);
|
|
}
|
|
|
|
public static FactionChallengeCtr Instace;
|
|
private void Awake()
|
|
{
|
|
Instace = this;
|
|
GUIData.delMoneyChanged += RefreshOwnMoneyValue;
|
|
GetMaxCanBuyCount(); //获取最大购买次数
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
Instace = null;
|
|
GUIData.delMoneyChanged -= RefreshOwnMoneyValue;
|
|
}
|
|
|
|
|
|
void AskChallgeneInfo() //请求当前挑战信息
|
|
{
|
|
CG_REQ_USER_CHALLENGE_INFO ask = (CG_REQ_USER_CHALLENGE_INFO)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_USER_CHALLENGE_INFO);
|
|
ask.SetFlag(1);
|
|
ask.SendPacket();
|
|
}
|
|
|
|
public void OnRuleBtnClick()
|
|
{
|
|
MessageHelpLogic.ShowHelpMessage(24);
|
|
}
|
|
public List<GameObject> _MarkIconList;
|
|
public void OnToggleClick(int index)
|
|
{
|
|
for(int _Index = 0; _Index < _MarkIconList.Count; _Index++)
|
|
{
|
|
_MarkIconList[_Index].SetActive(index == _Index);
|
|
}
|
|
|
|
switch (index)
|
|
{
|
|
case (int)Toggle_Type.Reward: //奖励
|
|
UIManager.ShowUI(UIInfo.FactionRankRewPanel, delegate(bool bSucess, object param) {
|
|
if(bSucess)
|
|
{
|
|
FactionRankRewPanel.Instance.InitRank(m_TotalRank);
|
|
}
|
|
});
|
|
break;
|
|
case (int)Toggle_Type.RANK: //打开职业排行版面板
|
|
UIManager.ShowUI(UIInfo.FactionRankPanel);
|
|
break;
|
|
case (int)Toggle_Type.FIGHTRECORD: //打开对战记录面板
|
|
UIManager.ShowUI(UIInfo.BattleInfoRecordPanel, delegate (bool bSucess, object param) {
|
|
if (bSucess)
|
|
{
|
|
CG_REQ_USER_CHALLENGE_LOG ask = (CG_REQ_USER_CHALLENGE_LOG)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_USER_CHALLENGE_LOG);
|
|
ask.SetBteFlag(1);
|
|
ask.SendPacket();
|
|
}
|
|
});
|
|
break;
|
|
//case (int)Toggle_Type.CHANGESKILL: //打开更换技能面板
|
|
// UIManager.ShowUI(UIInfo.FactionSkillChangeRoot);
|
|
// break;
|
|
case (int)Toggle_Type.SCORESHOP: //打开积分商店面板
|
|
{
|
|
YuanBaoShopLogic.OpenShopForJiFenItem(4, -1);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void OnCloseBtnClick()
|
|
{
|
|
UIManager.CloseUI(UIInfo.SportsPanel);
|
|
}
|
|
|
|
//增加金钱btn
|
|
public void OnAddMoneyItemClick()
|
|
{
|
|
JudgeMoneyLogic.ShowSwitchMoneyPanel(MONEYTYPE.MONEYTYPE_YUANBAO_BIND, true);
|
|
}
|
|
|
|
//重置次数Btn
|
|
public void OnQuickStartOrAddTimesClick()
|
|
{
|
|
if (isInCDTime)
|
|
{
|
|
MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{26003}", curCostValue), null, OnOkBtnClick, OnCancelBtnClick);
|
|
}else
|
|
{
|
|
MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{26004}", curCostValue), null, OnOkBtnClick, OnCancelBtnClick);
|
|
}
|
|
|
|
}
|
|
|
|
void OnOkBtnClick()
|
|
{
|
|
//判断当前金钱是否满足
|
|
if(JudgeMoneyLogic.IsMoneyEnough(MONEYTYPE.MONEYTYPE_YUANBAO_BIND, int.Parse(BeginCostMoneyText.text)))
|
|
{
|
|
//增加挑战次数 重置挑战时间 服务器会自行判断
|
|
CG_USER_CHALLENGE_RESET_CHALLENGE_NUM packet = (CG_USER_CHALLENGE_RESET_CHALLENGE_NUM)PacketDistributed.CreatePacket(MessageID.PACKET_CG_USER_CHALLENGE_RESET_CHALLENGE_NUM);
|
|
packet.SetFlag(1);
|
|
packet.SendPacket();
|
|
}
|
|
}
|
|
|
|
void OnCancelBtnClick()
|
|
{
|
|
UIManager.CloseUI(UIInfo.MessageBox);
|
|
}
|
|
|
|
//换一批
|
|
public void OnChangeOtherBtnClick()
|
|
{
|
|
CG_USER_CHALLENGE_UPDATE_USER packet = (CG_USER_CHALLENGE_UPDATE_USER)PacketDistributed.CreatePacket(MessageID.PACKET_CG_USER_CHALLENGE_UPDATE_USER);
|
|
packet.SetFlag(1);
|
|
packet.SendPacket();
|
|
}
|
|
|
|
public int m_TotalRank = 0;
|
|
private int resetNum = 0;
|
|
public int remainTimes = 0; //剩余挑战次数
|
|
public bool isInCDTime = false;
|
|
private bool canClick = true; // 是否可以点击购买 重置Item
|
|
|
|
private int buyTimes = 0; //已经购买的次数
|
|
//初始化挑战面板
|
|
public List<int> curSkillIdx = new List<int>();
|
|
public void InitMyChallengePanel(GC_RET_USER_CHALLENGE_RANK_INFO packet)
|
|
{
|
|
isInCDTime = false;
|
|
buyTimes = packet.BuyChallengeNum;
|
|
//记录当前服务器发过来的ID
|
|
curSkillIdx.Clear();
|
|
for (int index = 0; index < packet.skillListCount; index++)
|
|
{
|
|
curSkillIdx.Add(packet.GetSkillList(index));
|
|
}
|
|
|
|
//当前人物排名
|
|
if (packet.CurRank != -1)
|
|
{
|
|
MyRankText.text = (packet.CurRank + 1).ToString();
|
|
m_TotalRank = packet.CurRank + 1; //记录总榜排名
|
|
if(FactionRankRewPanel.Instance)
|
|
FactionRankRewPanel.Instance.InitRank(m_TotalRank);
|
|
}
|
|
else
|
|
{
|
|
MyRankText.text = "0";
|
|
}
|
|
MyFightNumberText.text = GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.CombatValue.ToString();
|
|
//整点排名
|
|
//if (packet.OneRank != -1)
|
|
//{
|
|
// ThirteenRankText.text = (packet.OneRank + 1).ToString();
|
|
//}
|
|
//if(packet.TwoRank != -1)
|
|
//{
|
|
// NighteenRankText.text = (packet.TwoRank + 1).ToString();
|
|
//}
|
|
//if(packet.ThreddRank != -1)
|
|
//{
|
|
// TwentyThreeRankText.text = (packet.ThreddRank + 1).ToString();
|
|
//}
|
|
|
|
//剩余挑战次数 从活动中取0);
|
|
if (activityBase != null)
|
|
{
|
|
remainTimes = packet.BuyChallengeNum + todayTotalChallengTimes - packet.ChallengeNum;
|
|
}
|
|
resetNum = packet.Resetnum;
|
|
|
|
TodayRemainChallengeTimes.text = remainTimes.ToString() + "/" + todayTotalChallengTimes;
|
|
|
|
if(packet.LeftTm > 0)
|
|
{
|
|
isInCDTime = true;
|
|
}else
|
|
{
|
|
isInCDTime = false;
|
|
}
|
|
|
|
if (isInCDTime)
|
|
{
|
|
//计算时间
|
|
CountCanChallengeTime(packet.LeftTm);
|
|
if (!cdTimePanel.activeInHierarchy)
|
|
{
|
|
cdTimePanel.SetActive(true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(cdTimePanel.activeInHierarchy)
|
|
{
|
|
cdTimePanel.SetActive(false);
|
|
}
|
|
}
|
|
//设置当前的快速开始消耗金钱 当前拥有金钱
|
|
RefreshMyOwnMoneyAndCostMoney();
|
|
SetBeginFightButton(); //设置增加次数 快速开始
|
|
}
|
|
|
|
private float totalCountTime = 0.0f;
|
|
public int remainTime = 0;
|
|
void CountCanChallengeTime(int endTime)
|
|
{
|
|
NextChallengeTimes.text = endTime.ToString();
|
|
remainTime = endTime;
|
|
isInCDTime = true;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if(isInCDTime && remainTime > 0)
|
|
{
|
|
totalCountTime += Time.deltaTime;
|
|
if(totalCountTime >= 1.0f)
|
|
{
|
|
--remainTime;
|
|
if (remainTime > 0)
|
|
{
|
|
NextChallengeTimes.text = remainTime.ToString();
|
|
}
|
|
totalCountTime = (1 - totalCountTime) + Time.deltaTime;
|
|
if(remainTime <= 0)
|
|
{
|
|
isInCDTime = false;
|
|
NextChallengeTimes.text = "0";
|
|
if(cdTimePanel.gameObject.activeInHierarchy)
|
|
{
|
|
cdTimePanel.gameObject.SetActive(false);
|
|
}
|
|
SetBeginFightButton(); //设置增加次数 快速开始
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
isInCDTime = false;
|
|
if (cdTimePanel.gameObject.activeInHierarchy)
|
|
{
|
|
cdTimePanel.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetCanChallengeRoleInfo(GC_RET_USER_CHALLENGE_USER_INFO packet) //设置可以挑战的人物信息
|
|
{
|
|
for(int index = 0; index < packet.usersCount; index++)
|
|
{
|
|
//初始化Item信息
|
|
RoleInfo roleInfo = new RoleInfo(packet.GetUsers(index).Name,
|
|
packet.GetUsers(index).Career,
|
|
packet.GetUsers(index).Combat,
|
|
packet.GetUsers(index).Rank,
|
|
packet.GetUsers(index).Level,
|
|
packet.GetUsers(index).Guid);
|
|
|
|
roleInfoItem[index].gameObject.SetActive(true);
|
|
roleInfoItem[index].InitMyRoleInfoItem(roleInfo, index);
|
|
}
|
|
|
|
//隐藏多余的显示
|
|
for(int index = packet.usersCount; index < 3; index++)
|
|
{
|
|
roleInfoItem[index].gameObject.SetActive(false);
|
|
}
|
|
|
|
//是否显示叠影背景
|
|
//HideInHideBgs.SetActive(packet.usersCount < 3 ? false : true);
|
|
}
|
|
|
|
private int maxBuyCount = 0; //最大购买次数
|
|
public void GetMaxCanBuyCount()
|
|
{
|
|
var tab = TableManager.GetUserChallengeBuyNum();
|
|
maxBuyCount = tab.Count;
|
|
}
|
|
|
|
private int curCostValue = 0; //记录当前需要的消耗
|
|
void RefreshMyOwnMoneyAndCostMoney()
|
|
{
|
|
Tab_UserChallengeBuyNum buyNum = null;
|
|
if (resetNum >= maxBuyCount)
|
|
{
|
|
resetNum = maxBuyCount;
|
|
buyNum = TableManager.GetUserChallengeBuyNumByID(resetNum, 0);
|
|
}
|
|
else
|
|
{
|
|
//当前需要消耗的金钱
|
|
buyNum = TableManager.GetUserChallengeBuyNumByID(resetNum + 1, 0);
|
|
}
|
|
|
|
if(buyNum != null)
|
|
{
|
|
BeginCostMoneyText.text = buyNum.Num.ToString();
|
|
curCostValue = buyNum.Num;
|
|
}
|
|
//当前拥有的金子
|
|
//CurrentOwnMoneyText.text = GameManager.gameManager.PlayerDataPool.GetLongPropty((int)CONSUM_TYPE.MONEY, (int)MONEYTYPE.MONEYTYPE_YUANBAO_BIND).ToString();
|
|
}
|
|
|
|
public void RefreshOwnMoneyValue()
|
|
{
|
|
//当前拥有的金子
|
|
//CurrentOwnMoneyText.text = GameManager.gameManager.PlayerDataPool.GetLongPropty((int)CONSUM_TYPE.MONEY, (int)MONEYTYPE.MONEYTYPE_YUANBAO_BIND).ToString();
|
|
}
|
|
|
|
|
|
//判断剩余的挑战次数 设置挑战Button的状态(CD时间大于0 快速开始 消耗金币 CD时间为0 增加次数)
|
|
void SetBeginFightButton()
|
|
{
|
|
if (!isInCDTime)
|
|
{
|
|
ResetAndQuickStartText.text = StrDictionary.GetClientDictionaryString("#{42659}");// "增加次数";
|
|
cdTimePanel.gameObject.SetActive(false);
|
|
if(NextChallengeTimes.gameObject.activeInHierarchy)
|
|
NextChallengeTimes.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
ResetChallengeButtton.interactable = true;
|
|
ResetAndQuickStartText.text = StrDictionary.GetClientDictionaryString("#{42660}");// "快速开始";
|
|
cdTimePanel.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
}
|