Files
2024-08-23 15:49:34 +08:00

740 lines
23 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using GCGame;
using GCGame.Table;
using UnityEngine;
using UnityEngine.UI;
public class KungfuSoul : MonoBehaviour
{
public UIImgText _Power;
public Text Bless;
public GameObject BlessEffect;
public Image BlessFill;
public GameObject UpSuccessEffect;
public GameObject FailedEffect2;
public ObjectTween FailedEffect1;
//public GameObject curBtnRedPoint; // 当前显示窗口的红点
public GameObject learnBtnRedPoint; // 修炼按钮上的红点
public GameObject MaxLevelLearnBtn; // 到达满级出现的灰色按钮
public GameObject ChildWnd;
private readonly float endPos = 20;
public UIContainerBase m_AddAttrs;
public UIContainerSelect m_LeftLists;
public UICameraTexture m_CameraTexture;
private RenderLine _renderLine;
private int m_CurrHeavenID = -1;
private int m_CurrSoulID = -1;
public Text DeBlockText;
public Text LinkText;
public SoulTipChild m_DeBlockWnd;
public SoulTipChild m_LinkWnd;
public Text NameAndAttr;
public Text NeedLevel;
public Text PayNum;
public Text Star;
public GameObject[] SignImages;
//public GameObject[] btnRedPoints; // 按钮上的红点
private int m_SoulStars = 0;
private int m_SoulAllStars = 0;
public GameObject EffectQipaoParent;
private readonly float startPos = -120;
public Text SuccRate;
public Toggle AutoPay;
public GameObject LastBtnObj;
public GameObject NextBtnObj;
private bool ForceSwitch = false;
int PayEnough = 0;
private List<int> SoulHeavens = new List<int>();
int FreshStep = -1;
public void OnClose()
{
m_CurrSoulID = -1;
m_CurrHeavenID = -1;
}
public void CloseTipChild()
{
ChildWnd.SetActive(false);
m_LinkWnd.gameObject.SetActive(false);
m_DeBlockWnd.gameObject.SetActive(false);
}
private void Awake()
{
_renderLine = new RenderLine(m_CameraTexture);
/*
LoadAssetBundle.Instance.LoadGameObject(LoadAssetBundle.BUNDLE_PATH_EFFECT, "TX_whq_qipao",
(modelName, resObj, hashParam) =>
{
// 直接使用resObj作为Prefab源
if (EffectQipaoParent != null && resObj != null)
{
var qiPaoOBj = Object.Instantiate(resObj);
qiPaoOBj.transform.SetParent(EffectQipaoParent.transform);
qiPaoOBj.transform.localPosition = Vector3.zero;
qiPaoOBj.transform.rotation = Quaternion.identity;
qiPaoOBj.gameObject.layer = gameObject.layer;
}
},
null);
*/
var soulClasss = TableManager.GetSoulHeavenAttr();
SoulHeavens.AddRange(soulClasss.Keys);
}
private void LateUpdate()
{
_renderLine.LateUpdate();
}
private void Update()
{
if (FreshStep >= 0)
{
switch (FreshStep)
{
case 0: FreshShow1(); FreshStep = 1; return;
case 1: CountAllAttrAndPower(); FreshStep = -1; return;
}
}
if (DataDuty < 0)
{
return;
}
if (DataDuty == 0)
{
Show();
}
DataDuty--;
}
int DataDuty = -1;
public void SetDataDuty()
{
DataDuty = 5;
}
public void Show()
{
if(m_CurrSoulID == -1 || m_CurrHeavenID == -1)
{
int[] selectInfo = MeridiaSoulData.Instance.GetAllHighSoul();
m_CurrHeavenID = selectInfo[0];
m_CurrSoulID = selectInfo[1];
}
FreshShow(m_CurrHeavenID);
m_OldWishNum = MeridiaSoulData.Instance.GetWishNum();
SetWish();
NextBtnObj.SetActive(m_CurrHeavenID < SoulHeavens[SoulHeavens.Count - 1]);
LastBtnObj.SetActive(m_CurrHeavenID > SoulHeavens[0]);
}
private int m_OldWishNum = 0;
// 刷新祝福值
public void SetWish()
{
var wish = MeridiaSoulData.Instance.GetWishNum();
Bless.text = wish.ToString();
var soulbase = TableManager.GetSoulBaseByID(1, 0);
if (soulbase == null)
return;
var rate = wish * 1.0f / soulbase.WishNumMax;
rate = Mathf.Clamp(rate, 0, 1);
BlessFill.fillAmount = rate;
var pos = startPos + (endPos - startPos) * rate;
BlessEffect.transform.localPosition = new Vector3(0, pos, 0);
if(m_OldWishNum > 0 && m_OldWishNum < wish)
{
FailedEffect2.SetActive(true);
FailedEffect1.gameObject.SetActive(true);
}
m_OldWishNum = wish;
}
public void UpGrade()
{
SetWish();
ForceSwitch = true;
FreshShow(m_CurrHeavenID);
UpSuccessEffect.SetActive(true);
}
// 计算所有的属性加成
private void CountAllAttrAndPower()
{
var m_powerAll = 0;
var attrValue = new Dictionary<int, int>();
var soulAttrs = TableManager.GetSoulGeneralAttr().Values;
m_SoulAllStars = 0;
m_SoulStars = 100;
foreach (var soul in soulAttrs)
{
if (soul.HeavenID != m_CurrHeavenID)
continue;
var soulID = soul.Id;
soulID = soulID * 1000;
int star = 0;
var kungfuData = MeridiaSoulData.Instance.GetKungfuData(soul.Id, soul.HeavenID);
if (kungfuData != null)
{
soulID += kungfuData.star;
star = kungfuData.star;
m_SoulAllStars += star;
}
if (star <= m_SoulStars)
m_SoulStars = star;
var soulInfo = TableManager.GetSoulGeneralStarByID(soulID, 0);
if (soulInfo == null)
continue;
m_powerAll += soulInfo.AttrPower;
for (var j = 0; j < soulInfo.getAttrIdCount(); j++)
{
var proID = soulInfo.GetAttrIdbyIndex(j);
if (proID == -1)
continue;
if (attrValue.ContainsKey(soulInfo.GetAttrIdbyIndex(j)))
{
var newVal = attrValue[soulInfo.GetAttrIdbyIndex(j)] + soulInfo.GetAttrValuebyIndex(j);
attrValue[soulInfo.GetAttrIdbyIndex(j)] = newVal;
}
else
{
attrValue[soulInfo.GetAttrIdbyIndex(j)] = soulInfo.GetAttrValuebyIndex(j);
}
}
}
if (m_SoulStars == 100)
m_SoulStars = 0;
m_powerAll += GetLinkData(m_SoulStars, m_CurrHeavenID, attrValue);
m_powerAll += GetDeBlockData(m_SoulAllStars, m_CurrHeavenID, attrValue);
_Power.text = m_powerAll.ToString();
var showLists = new List<MeridiaSoul.BloodVeinAttrData>();
var proIDs = new List<int>(attrValue.Keys);
for (var i = 0; i < proIDs.Count; i++)
{
var data = new MeridiaSoul.BloodVeinAttrData();
data.ProId = proIDs[i];
if (data.ProId == -1)
continue;
data.ProVal = attrValue[proIDs[i]];
showLists.Add(data);
}
if (m_AddAttrs.GetValueCnt() <= 0)
{
m_AddAttrs.SetShowItemFinishCallFun(NeedFreshAdd);
m_AddAttrs.InitContentItem(showLists);
}
else
{
m_AddAttrs.InitContentItem(showLists, null);
}
}
public void NeedFreshAdd()
{
FreshShowInfo(m_CurrSoulID, m_CurrHeavenID, false);
}
public void AutoPayChange(bool ison)
{
FreshShow1();
}
public void FreshShow1()
{
int HeavenID = -1;
var souls = TableManager.GetSoulGeneralAttr().Values;
var showlists = new List<SoulItem.SoulItemData>();
foreach (var item in souls)
{
var soul = new SoulItem.SoulItemData();
soul.attrName = item.Name;
soul.icon = item.Icon;
soul.SoulID = item.Id;
soul.HeavenID = item.HeavenID;
soul.CaUp = MeridiaSoulData.Instance.SoulCanUp(soul.HeavenID, soul.SoulID, AutoPay.isOn);
soul.isMaxLevel = MeridiaSoulData.Instance.IsSoulMaxLevel(soul.HeavenID, soul.SoulID);
if (soul.CaUp && (HeavenID == -1 || soul.HeavenID == m_CurrHeavenID))
{
HeavenID = soul.HeavenID;
}
showlists.Add(soul);
}
if (ForceSwitch && HeavenID!=-1)
m_CurrHeavenID = HeavenID;
else
HeavenID = m_CurrHeavenID;
if(HeavenID==-1)
HeavenID = m_CurrHeavenID;
List<SoulItem.SoulItemData> lists = new List<SoulItem.SoulItemData>(showlists);
showlists.Clear();
SoulItem.SoulItemData selectSoul = null;
for (int i=0;i< lists.Count;i++)
{
var soul = lists[i];
if(soul.HeavenID == HeavenID)
{
showlists.Add(soul);
if(selectSoul==null || selectSoul.SoulID!=m_CurrSoulID || selectSoul.CaUp ==false)
{
if (soul.SoulID == m_CurrSoulID && soul.CaUp)
selectSoul = soul;
else
{
if (selectSoul == null)
selectSoul = soul;
else
{
if (soul.isMaxLevel)
continue;
if (selectSoul.isMaxLevel || (selectSoul.CaUp == false && soul.CaUp))
{
selectSoul = soul;
}else if (selectSoul.CaUp == false && soul.CaUp == false)
{
if (MeridiaSoulData.Instance.Compare(selectSoul, soul) == false)
selectSoul = soul;
}
}
}
}
}
}
var selects = new List<SoulItem.SoulItemData>();
ForceSwitch = false;
if (selectSoul != null)
selects.Add(selectSoul);
else if(showlists.Count>0)
selects.Add(showlists[0]);
m_LeftLists.InitSelectContent(showlists, selects, SoulItemClick);
}
private int GetLinkData(int learnNum,int HeavenID,Dictionary<int, int> AttrValus)
{
var links = TableManager.GetSoulGeneralLink().Values;
foreach (var link in links)
{
if (link.HeavenID != HeavenID)
continue;
if (link.StarMin <= learnNum && link.StarMax >= learnNum)
{
for (int j = 0; j < link.getAttrIdCount(); j++)
{
int value = link.GetAttrValuebyIndex(j);
if (AttrValus.ContainsKey(link.GetAttrIdbyIndex(j)))
{
value += AttrValus[link.GetAttrIdbyIndex(j)];
}
AttrValus[link.GetAttrIdbyIndex(j)] = value;
}
return link.AttrPower;
}
}
return 0;
}
private int GetDeBlockData(int learnNum,int HeavenID, Dictionary<int, int> AttrValus)
{
var links = TableManager.GetSoulHeavenUnlock().Values;
foreach (var link in links)
{
if (link.HeavenID != HeavenID)
continue;
Tab_SoulHeavenAttr soulHeaven = TableManager.GetSoulHeavenAttrByID(link.HeavenID, 0);
if (soulHeaven == null)
continue;
if (link.StarTotalMin <= learnNum && link.StarTotalMax >= learnNum)
{
for (int j = 0; j < link.getAttrIdCount(); j++)
{
int value = link.GetAttrValuebyIndex(j);
if (AttrValus.ContainsKey(link.GetAttrIdbyIndex(j)))
{
value += AttrValus[link.GetAttrIdbyIndex(j)];
}
AttrValus[link.GetAttrIdbyIndex(j)] = value;
}
return link.AttrPower;
}
}
return 0;
}
public void FreshOther()
{
for(int i=0;i<SoulHeavens.Count;i++)
{
if (SignImages.Length <= i)
continue;
if (m_CurrHeavenID == SoulHeavens[i])
SignImages[i].SetActive(true);
else
{
SignImages[i].SetActive(false);
}
}
Tab_SoulHeavenAttr soul = TableManager.GetSoulHeavenAttrByID(m_CurrHeavenID, 0);
if(soul != null)
{
LinkText.text = string.Format("{0}•{1}", soul.Name, StrDictionary.GetClientDictionaryString("#{45999}"));
DeBlockText.text = string.Format("{0}•{1}", soul.Name, StrDictionary.GetClientDictionaryString("#{45998}"));
}
}
// 显示 / 刷新左侧武魂 Icon
public void FreshShow(int HeavenID)
{
m_CurrHeavenID = HeavenID;
FreshOther();
FreshStep = 0;
}
public void ContentReFresh()
{
SetDataDuty();
}
public void Click_ShowNext()
{
if (m_CurrHeavenID == -1)
{
FreshShow(SoulHeavens[0]);
return;
}
var index = 0;
for (index = 0; index < SoulHeavens.Count; index++)
if (m_CurrHeavenID == SoulHeavens[index])
break;
index++;
if (index < SoulHeavens.Count)
FreshShow(SoulHeavens[index]);
if (index >= SoulHeavens.Count - 1)
{
NextBtnObj.SetActive(false);
}
LastBtnObj.SetActive(true);
}
public void Click_ShowLast()
{
if (m_CurrHeavenID == -1)
{
FreshShow(SoulHeavens[0]);
return;
}
var index = SoulHeavens.Count - 1;
for (; index >= 0; index--)
if (m_CurrHeavenID == SoulHeavens[index])
break;
index--;
if (index >= 0)
{
FreshShow(SoulHeavens[index]);
}
if(index<=0)
{
LastBtnObj.SetActive(false);
}
NextBtnObj.SetActive(true);
}
private void GetPayEnough()
{
if(m_CurrHeavenID==-1 || m_CurrSoulID == -1)
{
PayEnough = 0;
return;
}
var star = 0;
var kungfuData = MeridiaSoulData.Instance.GetKungfuData(m_CurrSoulID, m_CurrHeavenID);
if (kungfuData != null) star = kungfuData.star;
var id = m_CurrSoulID * 1000 + star;
var soul = TableManager.GetSoulGeneralStarByID(id, 0);
if (soul == null)
return;
if (soul.OpenLevel <= GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Level)
NeedLevel.text = string.Format("<color=#156c17ff>{0}</color>", soul.OpenLevel);
else
NeedLevel.text = string.Format("<color=#a80e0eff>{0}</color>", soul.OpenLevel);
SuccRate.text = soul.SucceedRate / 100 + "%";
var hasCount0 = Utils.GetConstHas(soul.ConsumeType, soul.ConsumeSubType);
if (hasCount0 >= soul.ConsumeValue)
{
PayEnough = 0;
PayNum.text = string.Format("<color=#156c17ff>{0}</color>", soul.ConsumeValue);
}
else
{
PayEnough = soul.ConsumeValue - (int)hasCount0;
PayNum.text = string.Format("<color=#a80e0eff>{0}</color>", soul.ConsumeValue);
}
}
// 刷新并显示某一具体武魂的信息
public void FreshShowInfo(int SoulID, int HeavenID, bool isMaxLevel)
{
var star = 0;
var kungfuData = MeridiaSoulData.Instance.GetKungfuData(SoulID, HeavenID);
if (kungfuData != null) star = kungfuData.star;
var id = SoulID * 1000 + star;
var soul = TableManager.GetSoulGeneralStarByID(id, 0);
if (soul == null)
return;
_renderLine.LockUpdate();
_renderLine.SetActivePointCount(soul.Star);
if (soul.OpenLevel <= GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Level)
NeedLevel.text = string.Format("<color=#156c17ff>{0}</color>", soul.OpenLevel);
else
NeedLevel.text = string.Format("<color=#a80e0eff>{0}</color>", soul.OpenLevel);
SuccRate.text = soul.SucceedRate / 100 + "%";
var hasCount0 = Utils.GetConstHas(soul.ConsumeType, soul.ConsumeSubType);
if (hasCount0 >= soul.ConsumeValue)
{
PayEnough = 0;
PayNum.text = string.Format("<color=#156c17ff>{0}</color>", soul.ConsumeValue);
}
else
{
PayEnough = soul.ConsumeValue - (int)hasCount0;
PayNum.text = string.Format("<color=#a80e0eff>{0}</color>", soul.ConsumeValue);
}
var soulAttr = TableManager.GetSoulGeneralAttrByID(SoulID, 0);
if (soulAttr != null)
{
var charModel = TableManager.GetCharModelByID(soulAttr.CharModel, 0);
bool result = m_CameraTexture.InitModelPath(string.Empty, charModel, LoadAssetBundle.BUNDLE_PATH_MODEL, false);
if(!result)
_renderLine.UnLockUpdate();
}
MaxLevelLearnBtn.SetActive(false);
var soulNext = TableManager.GetSoulGeneralStarByID(id + 1, 0);
if (soulNext == null)
{
soulNext = soul;
MaxLevelLearnBtn.SetActive(true);
}
var attrStr = "";
m_AddAttrs.RefreshItems();
for (var i = 0; i < soulNext.getAttrIdCount(); i++)
{
int attID = soulNext.GetAttrIdbyIndex(i);
if (attID == -1)
continue;
var attrname = PropID.GetAttrName((PropID.PropertyID)attID);
if (attrname == "" || attrname.Contains("ClientDictionary ERROR0"))
continue;
if (attrStr != "")
attrStr += ",";
attrStr += string.Format("{0} +{1}", attrname, soulNext.GetAttrValuebyIndex(i));
var data = new MeridiaSoul.BloodVeinAttrData();
data.ProId = soulNext.GetAttrIdbyIndex(i);
data.ProVal = soulNext.GetAttrValuebyIndex(i) - soul.GetAttrValuebyIndex(i);
var addAttr = new Hashtable();
addAttr["InitObj"] = data;
m_AddAttrs.RefreshItems(addAttr);
}
NameAndAttr.text = attrStr;
Star.text = StrDictionary.GetClientDictionaryString("#{45997}", NumToChina(star));
m_CurrSoulID = SoulID;
m_CurrHeavenID = HeavenID;
var SoulDatas = MeridiaSoulData.Instance.GetKungfus(HeavenID);
if (learnBtnRedPoint != null)
{
bool isShow = IsCanUP(m_CurrSoulID, m_CurrHeavenID);
if (learnBtnRedPoint.activeSelf != isShow)
{
learnBtnRedPoint.SetActive(isShow);
}
}
}
//100内的数字转汉字
public string NumToChina(int Num)
{
string NumStr = "";
if (Num == 0)
return Utils.NumStr(0);
if (Num < 100)
{
int data = Num / 10;
if(data > 1)
{
NumStr += Utils.NumStr(data);
NumStr += Utils.NumStr(10);
}
else if(data==1)
{
NumStr += Utils.NumStr(10);
}
data = Num % 10;
if(data != 0)
NumStr += Utils.NumStr(data);
}
return NumStr;
}
public void SoulItemClick(object initInfo)
{
if (Singleton<ObjManager>.Instance.MainPlayer == null)
return;
var soulData = initInfo as SoulItem.SoulItemData;
if (soulData == null)
return;
MessageBoxLogic.CloseBox();
FreshShowInfo(soulData.SoulID, soulData.HeavenID,soulData.isMaxLevel);
}
public void Bless_Click()
{
var cmd = new ReqGetMoney();
cmd.flag = 1;
cmd.SendMsg();
}
public void MaxLevelLearn_Click()
{
GUIData.AddNotifyData(GCGame.Table.StrDictionary.GetClientDictionaryString("#{25096}"));
}
public void UpSoulFailed()
{
GetPayEnough();
if(AutoPay.isOn == false && PayEnough > 0)
{
MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{46009}", PayEnough), null, delegate ()
{
Learn(1);
}, null);
}
}
public void Learn_Click()
{
GetPayEnough();
if (PayEnough > 0 && AutoPay.isOn == false)
{
MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{46009}",PayEnough), null, delegate()
{
Learn(1);
}, null);
return;
}
Learn(AutoPay.isOn ? 1 : 0);
}
void Learn(int autoUse)
{
var cmd = new ReqUpgradeSoul();
cmd.generalId = m_CurrSoulID;
cmd.isAutoUse = autoUse;
cmd.SendMsg();
}
public void Deblock_Click()
{
if (m_CurrHeavenID == -1)
return;
ChildWnd.SetActive(true);
m_DeBlockWnd.gameObject.SetActive(true);
m_DeBlockWnd.InitInfo(0, m_SoulAllStars, m_CurrHeavenID);
}
public void LinkAge_Click()
{
if (m_CurrHeavenID == -1)
return;
ChildWnd.SetActive(true);
m_LinkWnd.gameObject.SetActive(true);
m_LinkWnd.InitInfo(1, m_SoulStars, m_CurrHeavenID);
}
public struct SoulItemData
{
public int soulID;
public int HeavenID;
public int star;
}
#region
/// <summary>
/// 是否可升级检测
/// </summary>
/// <param name="soulID">SoulGeneralAttr表的id</param>
/// <param name="HeavenID">SoulGeneralAttr表的HeavenID</param>
/// <returns>true为可升级false为不可升级</returns>
public bool IsCanUP(int soulID, int HeavenID)
{
MeridiaSoulData.KungfuSoulData data = MeridiaSoulData.Instance.GetKungfuData(soulID, HeavenID);
soulID *= 1000;
if (data != null)
{
soulID += data.star;
}
Tab_SoulGeneralStar soulStar = TableManager.GetSoulGeneralStarByID(soulID, 0);
Tab_SoulGeneralStar soulStarNext = TableManager.GetSoulGeneralStarByID(soulID + 1, 0);
if (soulStar == null || soulStarNext == null)
{
return false;
}
if (GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Level < soulStar.OpenLevel)
{
return false;
}
long hasCount0 = Utils.GetConstHas(soulStar.ConsumeType, soulStar.ConsumeSubType);
if (hasCount0 < soulStar.ConsumeValue)
{
return false;
}
return true;
}
#endregion
}