Files
JJBB/Assets/Project/Script/GUI/Pet/PetSkillsInfoWnd.cs
2024-08-23 15:49:34 +08:00

629 lines
21 KiB
C#

using System.Collections.Generic;
using Games.LogicObj;
using GCGame;
using GCGame.Table;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using Games.Fellow;
using Games.Events;
public class PetSkillsInfoWnd : MonoBehaviour
{
public UIContainerSelect m_Contains;
public Toggle IsShowHas;
public Toggle IsLow;
public Image skillIcon; //选中的技能的图片
public Text skillname; //选中的技能的名称
public Text skillDescript; //选中的技能的描述
public Image payItemQuility;
public Image payItemIcon; //消耗道具图标
public Text payItemName; //消耗道具名称
public Text PayItemNum; //消耗道具量
public Text PayCost; //消耗货币量
public Text PayHas; //消耗货币拥有量
public Image PayMoneyIcon;
public Image PayMoneyHasIcon;
public Text skillLockNum; //锁定的技能数
public Text currAdd; //当前加成
public Text TipText;
public GameObject[] hadStudySkills = new GameObject[8];
public GameObject skillHaveselect; //选中外框
public GameObject LockSkillBtn;
public GameObject LockSkillOKBtn;
public GameObject UNLockSkillBtn;
public GameObject GetBtnObj;
public GameObject PayTip;
private int m_currSelectSkillId = 0;
private Dictionary<int, GameObject> LockObjs = new Dictionary<int, GameObject>();
private Dictionary<int, Toggle> toggles = new Dictionary<int, Toggle>();
private bool _OpenLockSkill = false;
public bool OpenLockSkill
{
get { return _OpenLockSkill; }
}
public void Awake()
{
Hashtable calbackMoveparam2 = new Hashtable();
calbackMoveparam2["name"] = "LockFellowSkill";
MessageEventCallBack fun2 = LockFellowSkill;
calbackMoveparam2.Add("callFun", fun2);
EventDispatcher.Instance.AddMessageEvent(Games.Events.EventId.LockFellowSkill, calbackMoveparam2);
Hashtable calbackMoveparam3 = new Hashtable();
calbackMoveparam3["name"] = "SkillsInfoPayFresh";
MessageEventCallBack fun3 = PayFresh;
calbackMoveparam3.Add("callFun", fun3);
EventDispatcher.Instance.AddMessageEvent(Games.Events.EventId.FRESHSAMEUSETIP, calbackMoveparam3);
}
public void OnDestroy()
{
EventDispatcher.Instance.RemoveMessage(Games.Events.EventId.StudyFellowSkillSuccess, "StudyFellowSkill");
EventDispatcher.Instance.RemoveMessage(Games.Events.EventId.LockFellowSkill, "LockFellowSkill");
EventDispatcher.Instance.RemoveMessage(Games.Events.EventId.FRESHSAMEUSETIP, "SkillsInfoPayFresh");
}
public void PayFresh(Hashtable addparam, Hashtable sendparam)
{
CountCost(m_currSelectSkillId);
}
public void LockFellowSkill(Hashtable addparam, Hashtable sendparam)
{
if (sendparam == null)
return;
if (sendparam.ContainsKey("fellowId") == false)
return;
ulong guid = (ulong)sendparam["fellowId"];
if (PetMainWnd.CurrentSelectFellowId != guid)
return;
Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (pet == null)
return;
foreach (var lockObj in LockObjs)
{
if (pet.isSkillLocked(lockObj.Key))
{
lockObj.Value.SetActive(true);
}
else
lockObj.Value.SetActive(false);
}
int lockNum = pet.GetlockNum();
int lockNumMax = GetMaxLockNum();
skillLockNum.text = string.Format("{0}/{1}", lockNum, lockNumMax);
OpenLockSkillBtn(true);
}
public void StudyFellowSkill(Hashtable addparam, Hashtable sendparam)
{
if (sendparam == null)
return;
if (sendparam.ContainsKey("fellowId") == false)
return;
ulong guid = (ulong)sendparam["fellowId"];
if (PetMainWnd.CurrentSelectFellowId != guid)
return;
Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (pet == null)
return;
InitHasSkillInfo(pet);
int learnSkill = (int)sendparam["learn"];
int replaceSkill = (int)sendparam["replace"];
UpdateSkillBook(learnSkill, replaceSkill, pet);
OpenLockSkillBtn(true);
CountCost(m_currSelectSkillId);
}
public bool IsHasSkillBook(int fellodSkillId)
{
Tab_FellowLearnSkillCost skilllearnCost = TableManager.GetFellowLearnSkillCostByID(fellodSkillId, 0);
if (skilllearnCost == null)
{
return false;
}
Tab_CommonItem commonItem = null;
for (int i = 0; i < skilllearnCost.getConsumeTypeCount(); i++)
{
if (skilllearnCost.GetConsumeTypebyIndex(i) == (int)CONSUM_TYPE.ITEM)
{
commonItem = TableManager.GetCommonItemByID(skilllearnCost.GetConsumeSubTypebyIndex(i), 0);
}
}
if (commonItem == null)
{
return false;
}
return GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(commonItem.Id) > 0;
}
public void ShowHas(bool Low)
{
Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (pet == null)
return;
var fellowSkills = TableManager.GetFellowLearnSkillCost().Values;
List<int> showList = new List<int>();
List<int> selects = new List<int>();
if(!Low)
{
showList.Insert(0, -3);
showList.Insert(0, -3);
showList.Insert(0, -2);
}
int TypeThree = 0;
foreach (var value in fellowSkills)
{
Tab_FellowSkill skillInfo = TableManager.GetFellowSkillByID(value.Id, 0);
if (skillInfo == null || skillInfo.Type == -1 || skillInfo.IsShow!=1)
continue;
if (IsShowHas.isOn && IsHasSkillBook(skillInfo.Id) == false)
continue;
if (skillInfo.Type == 1 && Low)
{
showList.Add(value.Id);
}
if(!Low)
{
if (skillInfo.Type == 3)
{
showList.Insert(0, value.Id);
TypeThree++;
}
if (skillInfo.Type == 2)
{
showList.Add(value.Id);
}
}
}
if (showList.Count > 0)
selects.Add(showList[0]);
if (!Low)
{
int need = TypeThree % 3;
if(need>0)
{
for (int i = 0; i < 3 - need; i++)
{
showList.Insert(TypeThree + i, -3);
}
}
showList.Insert(0, -3);
showList.Insert(0, -3);
showList.Insert(0, -1);
}
m_Contains.InitSelectContent(showList, selects, OnSelectSkillBook, null);
InitHasSkillInfo(pet);
OpenLockSkillBtn(true);
}
void OnEnable()
{
ShowHas(IsLow.isOn);
TipText.text = StrDictionary.GetClientDictionaryString("#{20171}");
}
public void UpdateSkillBook(int learn,int replace,Fellow pet)
{
Hashtable table = new Hashtable();
table["learn"] = learn;
table["replace"] = replace;
m_Contains.RefreshItems(table);
CountCost(m_currSelectSkillId);
}
int needLearnSkillNum = 0;
public void InitHasSkillInfo(Fellow fellow)
{
LockObjs.Clear();
toggles.Clear();
for (int i = 0; i < hadStudySkills.Length; i++)
{
if (i == 0)
{
AddStudySkill(fellow, fellow.GY_skillid, i);
continue;
}
if (i == 1)
{
AddStudySkill(fellow, fellow.MW_skillid, i);
continue;
}
AddStudySkill(fellow, fellow.GetOwnSkillId(i - 2), i);
}
int lockNumMax = GetMaxLockNum();
if(lockNumMax <= 0)
{
var lockInfos = TableManager.GetFellowSkillLockNum().Values;
foreach(var oneLock in lockInfos)
{
if (oneLock.MaxLockNum > 0)
{
needLearnSkillNum = oneLock.Id;
break;
}
}
}
else
{
needLearnSkillNum = 0;
}
int lockNum = fellow.GetlockNum();
skillLockNum.text = string.Format("{0}/{1}", lockNum, lockNumMax);
Tab_FellowLearnSkillAttr skillAttr = TableManager.GetFellowLearnSkillAttrByID(fellow.GetOwnTotleCount(), 0);
if(skillAttr==null)
{
//currAdd.text = StrDictionary.GetClientDictionaryString("#{20142}",0);
}
else
{
//currAdd.text = StrDictionary.GetClientDictionaryString("#{20142}", skillAttr.AddPercent*1.0f / 100.0f)+"%";
}
UNLockSkillBtn.SetActive(needLearnSkillNum > 0);
}
public void OpenLockSkillBtn(bool state)
{
_OpenLockSkill = state;
LockSkillBtn.SetActive(state);
LockSkillOKBtn.SetActive(!state);
UNLockSkillBtn.SetActive(needLearnSkillNum > 0);
}
public void OnSelectSkillBook(object param)
{
int skillId = (int)param;
m_currSelectSkillId = skillId;
CountCost(skillId);
}
int hasCount = 0;
int commonItem_Cost = 0;
int commonItem_Money = 0;
int commonItem_Money_Cost = 0;
public void CountCost(int bookID)
{
if (m_currSelectSkillId != bookID)
return;
Tab_FellowLearnSkillCost skillBookInfo = TableManager.GetFellowLearnSkillCostByID(m_currSelectSkillId, 0);
if(skillBookInfo==null)
{
return;
}
Tab_FellowSkill skill = TableManager.GetFellowSkillByID(bookID, 0);
if (skill == null || skill.Type == -1)
return;
Tab_CommonItem commonItem = null;
for (int i = 0; i < skillBookInfo.getConsumeTypeCount(); i++)
{
if (skillBookInfo.GetConsumeTypebyIndex(i) == (int)CONSUM_TYPE.ITEM)
{
commonItem = TableManager.GetCommonItemByID(skillBookInfo.GetConsumeSubTypebyIndex(i), 0);
commonItem_Cost = skillBookInfo.GetConsumeNumbyIndex(i);
}
if (skillBookInfo.GetConsumeTypebyIndex(i) == (int)CONSUM_TYPE.MONEY)
{
commonItem_Money = skillBookInfo.GetConsumeSubTypebyIndex(i);
commonItem_Money_Cost = skillBookInfo.GetConsumeNumbyIndex(i);
long count = GameManager.gameManager.PlayerDataPool.Money.GetMoneyByType((MONEYTYPE)commonItem_Money);
PayTip.SetActive(count < commonItem_Money_Cost);
}
}
if (commonItem == null)
return;
LoadAssetBundle.Instance.SetImageSprite(skillIcon, skill.SkillIcon);
skillname.text = skillBookInfo.SkillName;
string strItemDesc = StrDictionary.GetClientString_WithNameSex(skillBookInfo.SkillDesc);
skillDescript.text = strItemDesc;
LoadAssetBundle.Instance.SetImageSprite(payItemQuility, GCGame.Utils.GetItemQualityFrame(commonItem.Quality));
LoadAssetBundle.Instance.SetImageSprite(payItemIcon, commonItem.Icon);
if (commonItem.QualityEffect > 0)
{
CommonItemContainerItem.ShowQualityEffect(true, commonItem.QualityEffect, payItemIcon.transform);
}
else
{
CommonItemContainerItem.ShowQualityEffect(false, commonItem.QualityEffect, payItemIcon.transform);
}
payItemName.text = commonItem.Name;
hasCount = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(commonItem.Id);
if (hasCount < commonItem_Cost)
{
PayItemNum.text = string.Format("<color=#ff0000ff>{0}</color>/{1}", hasCount, commonItem_Cost);
GetBtnObj.SetActive(true);
Button btn = GetBtnObj.GetComponent<Button>();
if (btn != null)
{
btn.onClick.RemoveAllListeners();
btn.onClick.AddListener(delegate ()
{
ItemTooltipsLogic.ShowItemTooltip(commonItem.Id, ItemTooltipsLogic.ShowType.GetPath, btn.transform.position);
});
}
}
else
{
PayItemNum.text = string.Format("<color=#43cd80ff>{0}</color>/{1}", hasCount, commonItem_Cost);
GetBtnObj.SetActive(false);
}
PayHas.text = GameManager.gameManager.PlayerDataPool.Money.GetMoneyByType((MONEYTYPE)commonItem_Money).ToString();
PayCost.text = commonItem_Money_Cost.ToString();
LoadAssetBundle.Instance.SetImageSprite(PayMoneyIcon, UICurrencyItem.GetCurrencySprite((MONEYTYPE)commonItem_Money));
LoadAssetBundle.Instance.SetImageSprite(PayMoneyHasIcon, UICurrencyItem.GetCurrencySprite((MONEYTYPE)commonItem_Money));
m_Contains.RefreshItems();
}
public void AddStudySkill(Fellow fellow,int id,int index)
{
if (index > hadStudySkills.Length)
return;
GameObject skillHas = hadStudySkills[index];
if (skillHas == null)
return;
Transform child = skillHas.transform.Find("Child");
Tab_FellowSkill skillInfo = TableManager.GetFellowSkillByID(id, 0);
if (skillInfo == null)
{
if (child != null)
child.gameObject.SetActive(false);
return;
}
if (fellow.IsHaveSkillId(id) == false)
{
if (child != null)
child.gameObject.SetActive(false);
return;
}
child.gameObject.SetActive(true);
Transform skillIcon = skillHas.transform.Find("Child/skillIcon");
Transform level = skillHas.transform.Find("Child/level");
Transform lockIcon = skillHas.transform.Find("Child/Lock");
Transform toggleTransform = skillHas.transform.Find("Child/Toggle");
if(skillIcon!=null)
{
Image icon = skillIcon.gameObject.GetComponent<Image>();
if(icon!=null)
{
LoadAssetBundle.Instance.SetImageSprite(icon, skillInfo.SkillIcon);
}
}
if(level!=null)
{
Text levelText = level.gameObject.GetComponent<Text>();
if(levelText!=null)
{
levelText.text = "Lv."+ skillInfo.Level.ToString();
}
}
if(lockIcon!=null)
{
LockObjs[id] = lockIcon.gameObject;
lockIcon.gameObject.SetActive(fellow.isSkillLocked(id));
}
if(toggleTransform!=null)
{
Toggle toggle = toggleTransform.gameObject.GetComponent<Toggle>();
toggles[id] = toggle;
toggleTransform.gameObject.SetActive(false);
toggle.onValueChanged.AddListener(delegate (bool result)
{
if (toggle.isOn)
{
int lockNum = Toggle_LockNum();
int lockNumMax = GetMaxLockNum();
if (lockNum > lockNumMax)
{
toggle.isOn = false;
GUIData.AddNotifyData(GCGame.Table.StrDictionary.GetClientDictionaryString("#{20110}", lockNumMax));
}
}
});
}
Button btn = skillHas.GetComponentInChildren<Button>();
if (btn != null)
{
btn.onClick.RemoveAllListeners();
btn.onClick.AddListener(delegate ()
{
FellowSkillTooltip.ShowSkillToolTips(id, btn.transform.position);
});
}
}
public int GetMaxLockNum()
{
Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (pet == null)
{
return 0;
}
int count = pet.GetOwnSkillCount();
Tab_FellowSkillLockNum locknum = TableManager.GetFellowSkillLockNumByID(count, 0);
if (locknum != null)
{
return locknum.MaxLockNum;
}
return 0;
}
public int Toggle_LockNum()
{
int lockNum = 0;
List<int> keys = new List<int>(toggles.Keys);
for(int i=0;i<keys.Count;i++)
{
var toggle = toggles[keys[i]];
if (toggle.isOn)
lockNum++;
}
return lockNum;
}
public void LockSkillTip()
{
MessageHelpLogic.ShowHelpMessage(18);
}
public void BuyFast()
{
JudgeMoneyLogic.ShowSwitchMoneyPanel((MONEYTYPE)commonItem_Money,true);
}
private void LockSkillBox()
{
MessageBoxLogic.OpenOKCancelBox(20161, -1, delegate ()
{
SendLockSkill_Click();
}, null);
}
public void StudySkill_Click()
{
if (m_currSelectSkillId == 0)
return;
Fellow pet = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (pet == null)
{
return;
}
if(!_OpenLockSkill)
{
LockSkillBox();
return;
}
if(pet.IsSkillBookUsed(m_currSelectSkillId) > 0)
{
GUIData.AddNotifyData(GCGame.Table.StrDictionary.GetClientDictionaryString("#{21005}"));
return;
}
if(hasCount < commonItem_Cost)
{
GUIData.AddNotifyData(GCGame.Table.StrDictionary.GetClientDictionaryString("#{20154}"));
return;
}
bool enough = JudgeMoneyLogic.IsMoneyEnough((MONEYTYPE)commonItem_Money, commonItem_Money_Cost);
if (!enough)
return;
CG_ACTIVE_FELLOW_SKILL send = (CG_ACTIVE_FELLOW_SKILL)PacketDistributed.CreatePacket(MessageID.PACKET_CG_ACTIVE_FELLOW_SKILL);
send.FellowGuid = PetMainWnd.CurrentSelectFellowId;
send.SetSkillId(m_currSelectSkillId);
send.SendPacket();
}
public void OnClick_Close()
{
if (!_OpenLockSkill)
{
LockSkillBox();
return;
}
UIManager.CloseUI(UIInfo.PetSkillsWndPath);
UIManager.ShowUI(UIInfo.PetMainWndPath, delegate (bool bSuccess, object param)
{
if (bSuccess && PetMainWnd.Instance != null)
{
PetMainWnd.Instance.ShowPage(2, PetMainWnd.CurrentSelectFellowId);
}
});
}
public void AskLockSkill_Click()
{
if(GetMaxLockNum() <= 0)
{
GUIData.AddNotifyData(GCGame.Table.StrDictionary.GetClientDictionaryString("#{20144}", needLearnSkillNum));
return;
}
Fellow fellow = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (fellow == null)
return;
bool isHasToggle = false;
foreach(var toggle in toggles)
{
toggle.Value.gameObject.SetActive(true);
Tab_FellowSkill skillInfo = TableManager.GetFellowSkillByID(toggle.Key, 0);
if (skillInfo == null || skillInfo.Type == -1)
continue;
toggle.Value.isOn = fellow.isSkillLocked(toggle.Key);
isHasToggle = true;
}
if (isHasToggle == false)
return;
OpenLockSkillBtn(false);
foreach (var lockObj in LockObjs)
{
lockObj.Value.SetActive(false);
}
}
public void SendLockSkill_Click()
{
OpenLockSkillBtn(true);
Fellow fellow = GameManager.gameManager.PlayerDataPool.FellowContainer.GetFellowByGuid(PetMainWnd.CurrentSelectFellowId);
if (fellow == null)
return;
foreach (var lockObj in LockObjs)
{
Tab_FellowSkill skillInfo = TableManager.GetFellowSkillByID(lockObj.Key, 0);
if (skillInfo == null)
continue;
lockObj.Value.SetActive(fellow.isSkillLocked(lockObj.Key));
}
CG_LOCK_FELLOW_SKILL send = (CG_LOCK_FELLOW_SKILL)PacketDistributed.CreatePacket(MessageID.PACKET_CG_LOCK_FELLOW_SKILL);
send.SetGuid(fellow.Guid);
foreach (var toggle in toggles)
{
if (toggle.Value.isOn)
{
send.AddSkillId(toggle.Key);
}
toggle.Value.gameObject.SetActive(false);
}
send.SendPacket();
}
public void Click_ShowLow(bool isOn)
{
if(isOn)
ShowHas(true);
}
public void Click_ShowHigh(bool isOn)
{
if(isOn)
ShowHas(false);
}
public void OnToggleValueChange(bool IsOn)
{
ShowHas(IsLow.isOn);
}
}