284 lines
9.0 KiB
C#
284 lines
9.0 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using GCGame.Table;
|
|
using UnityEngine.UI;
|
|
using System.Collections.Generic;
|
|
|
|
public class MarryCopyPanelCtr : MonoBehaviour {
|
|
public static MarryCopyPanelCtr Instance;
|
|
private void Awake()
|
|
{
|
|
InitRewardPanel();
|
|
Instance = this;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
Instance = null;
|
|
}
|
|
|
|
public Text remainTimes;
|
|
public GameObject itemPrefab;
|
|
public Transform itemPrefabParent;
|
|
|
|
private void OnEnable()
|
|
{
|
|
AskForCopySceneInfo();
|
|
}
|
|
|
|
private int curFubenId = -1;
|
|
public void AskForCopySceneInfo()
|
|
{
|
|
Tab_MarryBase marryBase = TableManager.GetMarryBaseByID(1, 0);
|
|
if (marryBase != null)
|
|
{
|
|
CG_REQ_PROF_PASS_LAYER req = (CG_REQ_PROF_PASS_LAYER)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_PROF_PASS_LAYER);
|
|
req.SetType(1);
|
|
req.SetParam(marryBase.FubenId);
|
|
req.SendPacket();
|
|
}
|
|
}
|
|
|
|
public void SetRemainTimes(GC_PROF_PASS_LAYER_FB packet)
|
|
{
|
|
for (int index = 0; index < packet.fbinfoCount; index++)
|
|
{
|
|
if(packet.GetFbinfo(index).Id == curFubenId)
|
|
{
|
|
|
|
if(totalCanChallengeTimes == -1)
|
|
{
|
|
todayRemainTimes = -1;
|
|
remainTimes.text = StrDictionary.GetClientDictionaryString("#{43036}");
|
|
}
|
|
else
|
|
{
|
|
remainTimes.text = (totalCanChallengeTimes - packet.GetFbinfo(index).Count > 0 ? totalCanChallengeTimes - packet.GetFbinfo(index).Count : 0).ToString();
|
|
todayRemainTimes = totalCanChallengeTimes - packet.GetFbinfo(index).Count > 0 ? totalCanChallengeTimes - packet.GetFbinfo(index).Count : 0;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private List<GameObject> itemPrefabList;
|
|
private int totalCanChallengeTimes = 0;
|
|
private int todayRemainTimes = 0;
|
|
public void GetDayMaxTimes()
|
|
{
|
|
Tab_Fuben fuben = TableManager.GetFubenByID(curFubenId, 0);
|
|
if(fuben == null)
|
|
{
|
|
return;
|
|
}
|
|
totalCanChallengeTimes = fuben.ChallengeTimes;
|
|
}
|
|
|
|
public void InitRewardPanel()
|
|
{
|
|
Tab_MarryBase marryBase = TableManager.GetMarryBaseByID(1, 0);
|
|
if (marryBase != null)
|
|
{
|
|
curFubenId = marryBase.FubenId;
|
|
}else
|
|
{
|
|
curFubenId = -1;
|
|
}
|
|
|
|
if(curFubenId == -1)
|
|
{
|
|
return;
|
|
}
|
|
|
|
GetDayMaxTimes();
|
|
|
|
Tab_NewCopyBase copyBase = TableManager.GetNewCopyBaseByID(curFubenId, 0);
|
|
if(copyBase == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Tab_CopySceneReward copySceneReward = TableManager.GetCopySceneRewardByID(copyBase.NormalPassRewardId, 0);
|
|
if(copySceneReward == null)
|
|
{
|
|
return;
|
|
}
|
|
itemPrefabList = new List<GameObject>();
|
|
for (int index = 0; index < copySceneReward.getRewardItemIDCount(); index++)
|
|
{
|
|
if (copySceneReward.GetRewardItemIDbyIndex(index) != -1)
|
|
{
|
|
GameObject item = GameObject.Instantiate(itemPrefab);
|
|
|
|
item.transform.SetParent(itemPrefabParent);
|
|
item.transform.localPosition = Vector3.zero;
|
|
item.transform.localRotation = Quaternion.Euler(Vector3.zero);
|
|
item.transform.localScale = Vector3.one;
|
|
|
|
item.GetComponent<MarryCopyRewareItem>().InitItem(copySceneReward.GetRewardItemIDbyIndex(index));
|
|
itemPrefabList.Add(item);
|
|
}else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public void OnChallengeBtnClick()
|
|
{
|
|
int lowLevel = 0;
|
|
Tab_Fuben fuben = TableManager.GetFubenByID(curFubenId, 0);
|
|
if (fuben != null)
|
|
{
|
|
lowLevel = fuben.PlayerLevelMin;
|
|
}
|
|
|
|
//没有结婚
|
|
if (!GameManager.gameManager.PlayerDataPool.IsMarried)
|
|
{
|
|
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{47012}"));
|
|
return;
|
|
}
|
|
//不是队长
|
|
if (!GameManager.gameManager.PlayerDataPool.TeamInfo.IsCaptain())
|
|
{
|
|
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{47013}"));
|
|
return;
|
|
}
|
|
//人数不是2
|
|
if (GameManager.gameManager.PlayerDataPool.TeamInfo.GetTeamMemberCount() != 2)
|
|
{
|
|
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{47014}"));
|
|
return;
|
|
}
|
|
|
|
//没带老婆
|
|
if (GameManager.gameManager.PlayerDataPool.TeamInfo.GetTeamMember(1).IsValid() &&
|
|
!GameManager.gameManager.PlayerDataPool.MyRingInfoData.loverName.Equals(
|
|
GameManager.gameManager.PlayerDataPool.TeamInfo.GetTeamMember(1).MemberName))
|
|
{
|
|
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{47014}"));
|
|
return;
|
|
}
|
|
//
|
|
|
|
//次数限制
|
|
//if (todayRemainTimes < 1 && todayRemainTimes != -1)
|
|
//{
|
|
// GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{47015}"));
|
|
// return;
|
|
//}
|
|
|
|
//等级限制
|
|
if (!IsLevelEnough(GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Level))
|
|
{
|
|
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{47016}", lowLevel));
|
|
return;
|
|
}
|
|
|
|
//爱人等级不足
|
|
if (!IsLevelEnough(GameManager.gameManager.PlayerDataPool.TeamInfo.GetTeamMember(1).Level))
|
|
{
|
|
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{47019}", lowLevel));
|
|
return;
|
|
}
|
|
|
|
CG_REQ_ENTER_COPY req = (CG_REQ_ENTER_COPY)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_ENTER_COPY);
|
|
req.SetCopyid(curFubenId);
|
|
req.SendPacket();
|
|
|
|
UIManager.CloseUI(UIInfo.MarryRoot);
|
|
}
|
|
|
|
public bool IsLevelEnough(int level)
|
|
{
|
|
Tab_Fuben fuben = TableManager.GetFubenByID(curFubenId, 0);
|
|
if(fuben != null)
|
|
{
|
|
return level >= fuben.PlayerLevelMin;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void PreInit()
|
|
{
|
|
Tab_MarryBase marryBase = TableManager.GetMarryBaseByID(1, 0);
|
|
CG_REQ_PROF_PASS_LAYER req = (CG_REQ_PROF_PASS_LAYER)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_PROF_PASS_LAYER);
|
|
req.SetType(1);
|
|
req.SetParam(marryBase.FubenId);
|
|
req.SendPacket();
|
|
}
|
|
|
|
//只刷新一次
|
|
public static void HasRedPoint()
|
|
{
|
|
if(!GameManager.gameManager.PlayerDataPool.IsMarried)
|
|
{
|
|
MarryRoot.RefreshRedTip(false);
|
|
if (MarryRoot.Instance)
|
|
MarryRoot.Instance.UpdateRedTips(MarryRoot.RedTipType.Copy, false);
|
|
}else
|
|
{
|
|
if(_RemainTimes == -1 || _RemainTimes == 0)
|
|
{
|
|
Tab_MarryBase marryBase = TableManager.GetMarryBaseByID(1, 0);
|
|
if (marryBase != null)
|
|
{
|
|
CG_REQ_PROF_PASS_LAYER req = (CG_REQ_PROF_PASS_LAYER)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_PROF_PASS_LAYER);
|
|
req.SetType(1);
|
|
req.SetParam(marryBase.FubenId);
|
|
req.SendPacket();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MarryRoot.RefreshRedTip(true);
|
|
if (MarryRoot.Instance)
|
|
MarryRoot.Instance.UpdateRedTips(MarryRoot.RedTipType.Copy, true);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
private static int _RemainTimes = -1;
|
|
public static void OnPacket(GC_PROF_PASS_LAYER_FB packet)
|
|
{
|
|
Tab_MarryBase marryBase = TableManager.GetMarryBaseByID(1, 0);
|
|
if (marryBase == null)
|
|
{
|
|
MarryRoot.RefreshRedTip(false);
|
|
if (MarryRoot.Instance)
|
|
MarryRoot.Instance.UpdateRedTips(MarryRoot.RedTipType.Copy, false);
|
|
}
|
|
var curFubenId = marryBase.FubenId;
|
|
Tab_Fuben fuben = TableManager.GetFubenByID(curFubenId, 0);
|
|
if (fuben == null)
|
|
{
|
|
return;
|
|
}
|
|
var _totalCount = fuben.ChallengeTimes;
|
|
|
|
for (int index = 0; index < packet.fbinfoCount; index++)
|
|
{
|
|
if (packet.GetFbinfo(index).Id == curFubenId)
|
|
{
|
|
if(_totalCount - packet.GetFbinfo(index).Count > 0)
|
|
{
|
|
MarryRoot.RefreshRedTip(true);
|
|
if(MarryRoot.Instance)
|
|
MarryRoot.Instance.UpdateRedTips(MarryRoot.RedTipType.Copy, true);
|
|
}
|
|
else
|
|
{
|
|
MarryRoot.RefreshRedTip(false);
|
|
if(MarryRoot.Instance)
|
|
MarryRoot.Instance.UpdateRedTips(MarryRoot.RedTipType.Copy, false);
|
|
_RemainTimes = _totalCount - packet.GetFbinfo(index).Count > 0 ? _totalCount - packet.GetFbinfo(index).Count : 0;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|