308 lines
9.6 KiB
C#
308 lines
9.6 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using GCGame.Table;
|
|||
|
using Module.Log;
|
|||
|
|
|||
|
public class PrivilegeVipItem : MonoBehaviour {
|
|||
|
|
|||
|
public PrivilegeVipRoot.PRIVILEGE_VIP_TYPE _CurType;
|
|||
|
public List<PrivilegeVipRewItem> rewItemList;
|
|||
|
public UICameraTexture _CamerTexture;
|
|||
|
//public GameObject _ActiveIcon;
|
|||
|
//public GameObject _HasntActiveIcon;
|
|||
|
public Text _RemainDayText;
|
|||
|
public Text _ConsumeText;
|
|||
|
public Image _MoneyIcon;
|
|||
|
public UIImgText _CombatVal;
|
|||
|
|
|||
|
public GameObject consumeObj;
|
|||
|
public Text btnDesc;
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
StartCoroutine(InitItem());
|
|||
|
}
|
|||
|
|
|||
|
private void OnEnable()
|
|||
|
{
|
|||
|
StartCoroutine(InitShowModel());
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
private Tab_PrivilegeVip privilegeTab = null;
|
|||
|
IEnumerator InitItem()
|
|||
|
{
|
|||
|
yield return new WaitForEndOfFrame();
|
|||
|
|
|||
|
var privilegeDic = TableManager.GetPrivilegeVip().Values;
|
|||
|
foreach (var info in privilegeDic)
|
|||
|
{
|
|||
|
if (info.VipType == (int)_CurType)
|
|||
|
{
|
|||
|
privilegeTab = info;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (privilegeTab == null)
|
|||
|
{
|
|||
|
LogModule.ErrorLog("CAN'T FINF TYPE : " + _CurType);
|
|||
|
yield break;
|
|||
|
}
|
|||
|
_CombatVal.text = privilegeTab.CombatVal.ToString();
|
|||
|
InitConsume();
|
|||
|
InitRewItem();
|
|||
|
|
|||
|
yield break;
|
|||
|
}
|
|||
|
|
|||
|
IEnumerator InitShowModel()
|
|||
|
{
|
|||
|
yield return new WaitForEndOfFrame();
|
|||
|
var CharModel = TableManager.GetCharModelByID(GetShowModelId(privilegeTab.ModelID), 0);
|
|||
|
if (CharModel == null)
|
|||
|
yield break;
|
|||
|
|
|||
|
if (!_CamerTexture.gameObject.activeInHierarchy)
|
|||
|
_CamerTexture.gameObject.SetActive(true);
|
|||
|
_CamerTexture.isPreview = true;
|
|||
|
_CamerTexture._CanDrag = false;
|
|||
|
_CamerTexture.InitModelPath(CharModel.ResPath, CharModel, LoadAssetBundle.BUNDLE_PATH_MODEL, true);
|
|||
|
|
|||
|
yield break;
|
|||
|
}
|
|||
|
|
|||
|
public int GetShowModelId(string modelStr)
|
|||
|
{
|
|||
|
if(!modelStr.Contains("|"))
|
|||
|
{
|
|||
|
return int.Parse(modelStr);
|
|||
|
}else
|
|||
|
{
|
|||
|
var modelIdStr = modelStr.Split('|');
|
|||
|
return int.Parse(modelIdStr[GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Profession]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void InitRewItem()
|
|||
|
{
|
|||
|
for (int index = 0; index < privilegeTab.getRewShowCount(); index++)
|
|||
|
{
|
|||
|
if (privilegeTab.GetRewShowbyIndex(index) != -1)
|
|||
|
{
|
|||
|
rewItemList[index].gameObject.SetActive(true);
|
|||
|
rewItemList[index].InitItem(privilegeTab.GetRewShowbyIndex(index), privilegeTab.GetRewShowNumbyIndex(index));
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
rewItemList[index].gameObject.SetActive(false);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void InitConsume()
|
|||
|
{
|
|||
|
_ConsumeText.text = privilegeTab.MoneyNum.ToString();
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(_MoneyIcon,
|
|||
|
UICurrencyItem.GetCurrencySprite((MONEYTYPE)privilegeTab.MoneyType));
|
|||
|
}
|
|||
|
|
|||
|
public void OnPacket(PrivilegeVip info)
|
|||
|
{
|
|||
|
//Debug.LogError("Type : " + info._PrivilegeType + " , State : " + info._Activate + " , deadLineTime : " + info._Deadline);
|
|||
|
InitActiveState(info._Activate);
|
|||
|
InitRemainTime(info._Deadline);
|
|||
|
}
|
|||
|
|
|||
|
private int _RemainTime = 0;
|
|||
|
private void InitRemainTime(int remainTime)
|
|||
|
{
|
|||
|
StopAllCoroutines();
|
|||
|
_IsForeverActive = (remainTime == -1);
|
|||
|
_RemainTime = remainTime - GlobalData.ServerAnsiTime;
|
|||
|
if (_RemainTime > 0)
|
|||
|
{
|
|||
|
_RemainDayText.gameObject.SetActive(false);
|
|||
|
consumeObj.SetActive(false);
|
|||
|
|
|||
|
SetRemainTimeDesc();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_RemainDayText.gameObject.SetActive(false);
|
|||
|
if (!_IsForeverActive)
|
|||
|
{
|
|||
|
consumeObj.SetActive(true);
|
|||
|
switch (_CurType)
|
|||
|
{
|
|||
|
case PrivilegeVipRoot.PRIVILEGE_VIP_TYPE.Sliver:
|
|||
|
btnDesc.text = StrDictionary.GetClientDictionaryString("#{67015}");
|
|||
|
break;
|
|||
|
case PrivilegeVipRoot.PRIVILEGE_VIP_TYPE.Gloden:
|
|||
|
btnDesc.text = StrDictionary.GetClientDictionaryString("#{67016}");
|
|||
|
break;
|
|||
|
case PrivilegeVipRoot.PRIVILEGE_VIP_TYPE.Diamond:
|
|||
|
btnDesc.text = StrDictionary.GetClientDictionaryString("#{67017}");
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
consumeObj.SetActive(false);
|
|||
|
btnDesc.text = StrDictionary.GetClientDictionaryString("#{67014}");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void SetRemainTimeDesc()
|
|||
|
{
|
|||
|
StartCoroutine(CountRemainTime());
|
|||
|
}
|
|||
|
|
|||
|
IEnumerator CountRemainTime()
|
|||
|
{
|
|||
|
while(true)
|
|||
|
{
|
|||
|
yield return new WaitForSeconds(1.0f);
|
|||
|
_RemainTime--;
|
|||
|
if(_RemainTime > 0)
|
|||
|
{
|
|||
|
int day = _RemainTime / (3600 * 24);
|
|||
|
int hour = (_RemainTime - day * 3600 * 24) / 3600;
|
|||
|
int minute = (_RemainTime - day * 3600 * 24 - hour * 3600) / 60;
|
|||
|
int sec = _RemainTime - day * 3600 * 24 - hour * 3600 - minute * 60;
|
|||
|
_RemainDayText.text = StrDictionary.GetClientDictionaryString("#{67001}", day, hour, minute, sec); //不足一天算一天
|
|||
|
btnDesc.text = StrDictionary.GetClientDictionaryString("#{67018}", _RemainDayText.text);
|
|||
|
}else
|
|||
|
{
|
|||
|
InitRemainTime(_RemainTime);
|
|||
|
yield break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private bool _IsActive = false;
|
|||
|
private bool _IsLocalActive = false;
|
|||
|
private bool _IsForeverActive = false;
|
|||
|
private void InitActiveState(int _IsAcvite)
|
|||
|
{
|
|||
|
this._IsActive = _IsAcvite == 1;
|
|||
|
_IsLocalActive = _IsAcvite == 2;
|
|||
|
|
|||
|
//_ActiveIcon.SetActive(_IsAcvite);
|
|||
|
//_HasntActiveIcon.SetActive(!_IsAcvite);
|
|||
|
}
|
|||
|
|
|||
|
public void OnBtnClikc()
|
|||
|
{
|
|||
|
//白钻特殊处理
|
|||
|
if(_CurType == PrivilegeVipRoot.PRIVILEGE_VIP_TYPE.Sliver && !_IsForeverActive)
|
|||
|
{
|
|||
|
if (JudgeMoneyLogic.IsMoneyEnough((MONEYTYPE)privilegeTab.MoneyType, privilegeTab.MoneyNum))
|
|||
|
{
|
|||
|
MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{67024}",
|
|||
|
privilegeTab.MoneyNum, GetPrivilegeTypeDesc()),
|
|||
|
"", PerchaseOption, CloseMessageBox);
|
|||
|
}
|
|||
|
|
|||
|
return;
|
|||
|
}
|
|||
|
if(_IsLocalActive)
|
|||
|
{
|
|||
|
UseItem();
|
|||
|
}
|
|||
|
else if(_IsActive)
|
|||
|
{
|
|||
|
//是否已永久激活
|
|||
|
if(_IsForeverActive)
|
|||
|
{
|
|||
|
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{67007}"));
|
|||
|
return;
|
|||
|
}else
|
|||
|
{
|
|||
|
//判断背包是否有对应道具
|
|||
|
MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{67006}", GetPrivilegeTypeDesc(), GetPrivilegeTypeDesc())
|
|||
|
, "", UseItem, CloseMessageBox);
|
|||
|
}
|
|||
|
}else
|
|||
|
{
|
|||
|
if(privilegeTab.Time == -1) //永久
|
|||
|
{
|
|||
|
MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{67010}",
|
|||
|
privilegeTab.MoneyNum, GetPrivilegeTypeDesc()),"", PerchaseOption, CloseMessageBox);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (JudgeMoneyLogic.IsMoneyEnough((MONEYTYPE)privilegeTab.MoneyType, privilegeTab.MoneyNum))
|
|||
|
{
|
|||
|
MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{67002}",
|
|||
|
privilegeTab.MoneyNum, GetPrivilegeTypeDesc(), privilegeTab.Time, GetPrivilegeTypeDesc()),
|
|||
|
"", PerchaseOption, CloseMessageBox);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void PerchaseOption()
|
|||
|
{
|
|||
|
ReqActivePrivilege();
|
|||
|
CloseMessageBox();
|
|||
|
}
|
|||
|
|
|||
|
public void CloseMessageBox()
|
|||
|
{
|
|||
|
UIManager.CloseUI(UIInfo.MessageBox);
|
|||
|
}
|
|||
|
|
|||
|
public void UseItem()
|
|||
|
{
|
|||
|
CloseMessageBox();
|
|||
|
var _BackPack = GameManager.gameManager.PlayerDataPool.BackPack;
|
|||
|
if(_BackPack == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
if (_BackPack != null)
|
|||
|
{
|
|||
|
if (_BackPack.GetItemCountByDataId(privilegeTab.LevelUpItem) > 0)
|
|||
|
{
|
|||
|
if (Singleton<ObjManager>.Instance != null && Singleton<ObjManager>.Instance.MainPlayer)
|
|||
|
Singleton<ObjManager>.Instance.MainPlayer.UseItem(_BackPack.GetItemByDataID(privilegeTab.LevelUpItem));
|
|||
|
}else
|
|||
|
{
|
|||
|
//没有该道具
|
|||
|
GUIData.AddNotifyData("#{42701}");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//永久特权类型描述 //白金 黄金 钻石
|
|||
|
public string GetPrivilegeTypeDesc()
|
|||
|
{
|
|||
|
var desc = "";
|
|||
|
switch(_CurType)
|
|||
|
{
|
|||
|
case PrivilegeVipRoot.PRIVILEGE_VIP_TYPE.Diamond:
|
|||
|
desc = StrDictionary.GetClientDictionaryString("#{67004}");
|
|||
|
break;
|
|||
|
case PrivilegeVipRoot.PRIVILEGE_VIP_TYPE.Gloden:
|
|||
|
desc = StrDictionary.GetClientDictionaryString("#{67005}");
|
|||
|
break;
|
|||
|
case PrivilegeVipRoot.PRIVILEGE_VIP_TYPE.Sliver:
|
|||
|
desc = StrDictionary.GetClientDictionaryString("#{67003}");
|
|||
|
break;
|
|||
|
}
|
|||
|
return desc;
|
|||
|
}
|
|||
|
|
|||
|
private void ReqActivePrivilege()
|
|||
|
{
|
|||
|
ReqActivatePrivilegeVip req = new ReqActivatePrivilegeVip();
|
|||
|
req._PrivilegeType = (int)_CurType;
|
|||
|
req.SendMsg();
|
|||
|
}
|
|||
|
}
|