You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

432 lines
15 KiB

using TMPro;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using IVDataFormat;
using System.Numerics;
public class EScrGoldEnchance : EScrCell
{
GameObject unlockSet;
GameObject lockSet;
Image icon;
TextMeshProUGUI txtLevel;
TextMeshProUGUI txtName;
TextMeshProUGUI txtCur;
Button btnLvUp;
GameObject goBtnLvUpObj;
GameObject goBtnLvMax;
TextMeshProUGUI txtMaxLevel;
TextMeshProUGUI txtMaxLevelMax;
TextMeshProUGUI txtPrice;
TextMeshProUGUI unlockConditionText;
nIdEnhance dataEnhance = null;
ParticleSystem partUpEffect;
int iupgradeMulti = 1;
BigInteger iprice = new BigInteger();
int inextValue = 0;
int iresetValue = 0;
int iMaxLv = 100;
int iLoading = 0;
bool bClicking = false;
BigInteger calcmultiply = 0;
BigInteger calcdivide = 0;
[SerializeField] Color effectValueColor = Color.white;
public override void InitCell()
{
unlockSet = transform.Find("Unlock").gameObject;
lockSet = transform.Find("Lock").gameObject;
icon = unlockSet.transform.Find("icon").GetComponent<Image>();
txtLevel = unlockSet.transform.Find("txtLevel").GetComponent<TextMeshProUGUI>();
txtName = unlockSet.transform.Find("txtName").GetComponent<TextMeshProUGUI>();
txtCur = unlockSet.transform.Find("txtCur").GetComponent<TextMeshProUGUI>();
btnLvUp = unlockSet.transform.Find("btnlvup").GetComponent<Button>();
goBtnLvUpObj = unlockSet.transform.Find("btnlvup").gameObject;
goBtnLvMax = unlockSet.transform.Find("btnMaxLv").gameObject;
txtMaxLevel = btnLvUp.transform.Find("txtMaxLevel").GetComponent<TextMeshProUGUI>();
txtMaxLevelMax= goBtnLvMax.transform.Find("txtMaxLevel").GetComponent<TextMeshProUGUI>();
txtPrice = btnLvUp.transform.Find("txtPrice").GetComponent<TextMeshProUGUI>();
unlockConditionText = lockSet.transform.Find("UnlockCondition").GetComponent<TextMeshProUGUI>();
partUpEffect = unlockSet.transform.Find("StrengthenLevel").GetComponent<ParticleSystem>();
}
public override void SetData(int itemid)
{
itemID = itemid;
dCharStat charData = DataHandler.GetCharStat(itemid);
iupgradeMulti = EnhanceMgr.GetMultifulGoldEnhance();//강화 횟수
switch (itemid)
{
case 1:
case 2:
icon.sprite = AddressableMgr.GetEnhanceIcon(itemid);
break;
default:
icon.sprite = AddressableMgr.GetEnhanceIcon(3);
break;
}
//iprice = EnhanceMgr.GetGoldPrice(itemID);
int abilityValue = 0;
int abilityValueInc = 1;
BigInteger buyingCnt = 0L;
int buyingCntInc = 1;
int level = 1;
bool isUnlock = false;
abilityValue = charData.abilityValue;
abilityValueInc = charData.abilityValueInc;
buyingCnt = charData.buyingCount;
buyingCntInc = charData.buyingCntInc;
iMaxLv = charData.maxLv;
level = charData.level;
if (charData.level + iupgradeMulti > iMaxLv)
{
iupgradeMulti = iMaxLv - level;//만렙 제한
}
/*
// 현재레벨 + 강화횟수가 만렙보다 높으면
//calcmultiply = BigInteger.Pow(buyingCntInc, level);
//calcdivide = BigInteger.Pow(dConst.RateMaxBi, level);
//Debug.Log(calcmultiply / calcdivide);
// 가격 = 현재 가격 * (증가율^레벨)
//iprice = buyingCnt * calcmultiply / calcdivide;
//// 증가 스탯 계산
int icurValue = abilityValue + (abilityValueInc * level);
//// 다음 증가 스탯 계산
//inextValue = abilityValue + (abilityValueInc * (level + 1));
//시작금액 계산식.
//float eja = (dConst.RateMaxFloat + (float)(buyingCntInc - dConst.RateMax)) / dConst.RateMax;
//eja = Mathf.Pow(eja, iupgradeMulti);
//iprice = buyingCnt * (BigInteger)(eja * dConst.RateMax) / dConst.RateMax;
//정확한 값이 필요하면 사용해서 연산할 것.
// 여러번 강화할때 계산
//if (iupgradeMulti > 1)
//{
// iprice = 0L;
// for (int i = 0; i < iupgradeMulti; i++)
// {
// iprice += buyingCnt * BigInteger.Pow(buyingCntInc, level + i) / BigInteger.Pow(dConst.RateMaxBi, level + i);
// }
// inextValue = abilityValue + (abilityValueInc * (level + iupgradeMulti));
//}
//if (itemid == 1 || itemid == 2)
// Debug.Log(FormatString.StringFormat("반복 {0}", FormatString.BigIntString1(iprice)));
iprice = 0L;
if (iupgradeMulti == 1)
{
//iprice = buyingCnt * BigInteger.Pow(buyingCntInc, level) / BigInteger.Pow(dConst.RateMaxBi, level);
iprice = CalcCharLvUpPriceAccum1(level % 1000, iupgradeMulti, (double)buyingCntInc / dConst.RateMax, DataHandler.GetGoldLevelInterval(level));
}
else
{
if (itemid == 1)
{
iprice = CalcCharLvUpPriceAccum1(level % 1000, iupgradeMulti, (double)buyingCntInc / dConst.RateMax, DataHandler.GetGoldLevelInterval(level));
}
else if (itemid == 2)
{
iprice = CalcCharLvUpPriceAccum1(level % 1000, iupgradeMulti, (double)buyingCntInc / dConst.RateMax, DataHandler.GetHpLevelInterval(level));
}
else
{
iprice = CalcCharLvUpPriceAccum1(level, iupgradeMulti, (double)buyingCntInc / dConst.RateMax, buyingCnt);
}
}
//if (itemid == 1 || itemid == 2)
// Debug.Log(FormatString.StringFormat("심연 {0}", FormatString.BigIntString1(iprice)));
inextValue = abilityValue + (abilityValueInc * (level + iupgradeMulti));
//강화수치가 실제 값과 일치하는지 확인하는 용도
//Debug.Log(FormatString.StringFormat("반복 {0} / 심연 {1}", FormatString.BigIntString1(iprice),FormatString.BigIntString1(CalcCharLvUpPriceAccum1(level, iupgradeMulti, (double)buyingCntInc / dConst.RateMax, buyingCnt))));
iresetValue = abilityValue + (abilityValueInc * level);
*/
iprice = EnhanceMgr.SSingleRecalcGoldPrice(itemid);
int icurValue = abilityValue + (abilityValueInc * level);
// UI
//imgIcon.sprite = AddressableMgr.GetSkillIcon(itemid);
txtLevel.text = FormatString.TextLv(charData.level);
if(charData.abilityType == eEffectType.CrtRate)
{
txtName.text = FormatString.StringFormat(LocalizationText.GetText("stat_kind_bottom3"), abilityValue / dConst.RateMax + 2);
}
else
txtName.text = LocalizationText.GetText(FormatString.CombineAllString("enhancegold", itemid.ToString()));
#if false
if (charData.abilityType == eEffectType.AtkBase || charData.abilityType == eEffectType.HpBase)
txtCur.text = FormatString.StringFormat("<color=#FFEA73>{0}</color>", FormatString.TextEffectValue(charData.abilityType, icurValue, false, false));
else
txtCur.text = FormatString.StringFormat("<color=#FFEA73>{0}</color>", FormatString.TextEffectValue(charData.abilityType, (icurValue % dConst.RateMax) <= 0 ? dConst.RateMax : icurValue % dConst.RateMax));
#else
if (charData.abilityType == eEffectType.AtkBase || charData.abilityType == eEffectType.HpBase)
txtCur.text = Utility.GetMergeStringWithColor(effectValueColor, FormatString.TextEffectValue(charData.abilityType, icurValue, false, false));
else
txtCur.text = Utility.GetMergeStringWithColor(effectValueColor, FormatString.TextEffectValue(charData.abilityType, (icurValue % dConst.RateMax) <= 0 ? dConst.RateMax : icurValue % dConst.RateMax));
#endif
txtMaxLevel.text = FormatString.CombineAllString("Max Lv.", iMaxLv.ToString());
txtPrice.text = FormatString.BigIntString1(iprice);
goBtnLvMax.SetActive(false);
goBtnLvUpObj.SetActive(true);
btnLvUp.interactable = iprice <= DataHandler.Goods.gold;
if (charData.level >= charData.maxLv)
{
txtPrice.text = "Max";
goBtnLvUpObj.SetActive(false);
goBtnLvMax.SetActive(true);
txtMaxLevelMax.text = FormatString.CombineAllString("Max Lv.", charData.maxLv.ToString());
}
if (charData.condType == 0 || DataHandler.GetCharStatLevel(charData.condType) >= charData.condValue)
{
if (isUnlock == false)
{
unlockSet.SetActive(true);
lockSet.SetActive(false);
BuffMgr.Instance.ChangeCharStat(DataHandler.GetCharStat(itemID).abilityType, abilityValue + (abilityValueInc * level), true);
isUnlock = true;
}
}
else
{
UnlockConditionDesc(charData.condType, charData.condValue);
unlockSet.SetActive(false);
lockSet.SetActive(true);
}
}
public BigInteger CalcCharLvUpPriceAccum1(int curlevel, int addlevel, double buyingCntInc, BigInteger buyingCnt)
{
if (/*curlevel < 1 ||*/ addlevel < 1)
return buyingCnt;
double ftargetlv = curlevel + addlevel - 1d;
ftargetlv = System.Math.Pow(buyingCntInc, ftargetlv) - 1d;
double fcurlv = curlevel - 1d;
fcurlv = System.Math.Pow(buyingCntInc, fcurlv) - 1d;
ftargetlv -= fcurlv;
ftargetlv *= buyingCntInc;
ftargetlv /= (buyingCntInc - 1d);
return buyingCnt * (BigInteger)(ftargetlv * 100) / 100;
}
void UnlockConditionDesc(int condid, int unlockLevel)
{
if (condid == 0)
return;
dCharStat stat = DataHandler.GetCharStat(condid);
if (stat.abilityType == eEffectType.CrtRate)
{
string strtext = FormatString.StringFormat(LocalizationText.GetText("stat_kind_bottom3"), stat.abilityValue/dConst.RateMax + 2);
unlockConditionText.text = FormatString.CombineAllString(strtext, FormatString.StringFormat(LocalizationText.GetText("enhance_unlock_condition"), unlockLevel));
}
else
{
string strtext = FormatString.StringFormat(LocalizationText.GetText("enhance_unlock_condition"), unlockLevel.ToString());
unlockConditionText.text = FormatString.CombineAllString(LocalizationText.GetText(FormatString.CombineAllString("enhancegold", condid.ToString())), strtext);
}
}
public override void RefreshCellView()
{
base.RefreshCellView();
SetData(itemID);
}
public void OnBtnLvEnhanceDown()
{
if (iLoading > 0)
{
return;
}
if (bClicking)
return;
iLoading++;
if(iprice <= DataHandler.Goods.gold)
{
bClicking = true;
dataEnhance = new nIdEnhance(itemID, DataHandler.GetCharStat(itemID).level);
StartCoroutine(CGoldLevelUp());
}
else
{
iLoading--;
}
}
int delayTimer = 0;
private IEnumerator CGoldLevelUp()
{
if (iprice > DataHandler.Goods.gold || dataEnhance.aftLv >= iMaxLv)
{
OnBtnLvEnhanceUp();
yield break;
}
//upEffect.AnimationState.SetAnimation(0, "idle", false);
partUpEffect.Play();
dataEnhance.aftLv += iupgradeMulti;
dataEnhance.tryCount += iupgradeMulti;
//dataEnhance.useGoods += iprice;//이 정보를 아래쪽 포스트 요청에 보내서 서버에 적용한다. 맨 끝에서 두번째에 있다.
//DataHandler.SubGold(iprice);
EnhanceMgr.SLevelUpCharStatServer(itemID, iupgradeMulti, iprice, inextValue);
//EnhanceMgr.CheckBedge();
//asLvUp.Play();
SoundMgr.PlaySfx(SoundName.BtnPress,SoundName.ReinforceSuccess);
//EnhanceMgr.SSingleRecalcGoldPrice(itemID);
//iprice = EnhanceMgr.GetGoldPrice(itemID);
RefreshCellView();
while (bClicking)
{
if (delayTimer > 3)
{
//int iprice = (dataEnhance.aftLv - 1) * gear.buyingCountInc + gear.buyingCount;
if (iprice > DataHandler.Goods.gold || dataEnhance.aftLv >= iMaxLv)
{
OnBtnLvEnhanceUp();
yield break;
}
//upEffect.AnimationState.SetAnimation(0, "idle", false);
partUpEffect.Play();
dataEnhance.aftLv += iupgradeMulti;
dataEnhance.tryCount += iupgradeMulti;
//dataEnhance.useGoods += iprice;//이 정보를 아래쪽 포스트 요청에 보내서 서버에 적용한다. 맨 끝에서 두번째에 있다.
//DataHandler.SubGold(iprice);
EnhanceMgr.SLevelUpCharStatServer(itemID, iupgradeMulti, iprice, inextValue);
//asLvUp.Play();
SoundMgr.PlaySfx(SoundName.BtnPress, SoundName.ReinforceSuccess);
//EnhanceMgr.SSingleRecalcGoldPrice(itemID);
//iprice = EnhanceMgr.GetGoldPrice(itemID);
//EnhanceMgr.CheckBedge();
RefreshCellView();
}
else
{
delayTimer++;
}
yield return YieldInstructionCache.WaitForSeconds(0.1f);
}
}
int cover = 0;
public void OnBtnLvEnhanceUp()
{
if (!bClicking)
return;
CoverCamera.Hold();
cover++;
delayTimer = 0;
StopCoroutine(nameof(CGoldLevelUp));
bClicking = false;
//EnhanceMgr.TryGoldEnhance(dataEnhance);
SvConnectManager.Instance.RequestSvPost(true, 0, IVServerFormat.UrlApi.GetUrl(IVServerFormat.UrlApi.GoldEnhance), typeof(nCharEnhanceGoldReturn), AGoldEnhanceSucc, AGoldEnhanceFail, dataEnhance, true);
}
//골드 강화 통신 실패
private void AGoldEnhanceFail(IVServerFormat.SvError error, object request)
{
CoverCamera.Release();
DataHandler.AddGold(dataEnhance.useGoods);
EnhanceMgr.SLevelUpCharStatServer(itemID, -(dataEnhance.aftLv - dataEnhance.befLv), iprice, iresetValue);
RefreshCellView();
dataEnhance = null;
iLoading--;
}
// 골드 강화 통신 성공.
private void AGoldEnhanceSucc(object result, object request)
{
nCharEnhanceGoldReturn data = result as nCharEnhanceGoldReturn;
if (data == null)
{
AGoldEnhanceFail(new IVServerFormat.SvError(IVServerFormat.eErrorCode.NULL_OR_EMPTY), request);
return;
}
//if (dataEnhance.sid == 2)
// Debug.Log( " hp per : " + BuffMgr.Instance.getHpPer());
nIdLv datalv;
datalv = data.playCharEnhanceGold;
//System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
//
//watch.Start();
EnhanceMgr.SCalcMyInfoStat();
//watch.Stop();
//UnityEngine.Debug.Log(watch.ElapsedMilliseconds + " ms");
EnhanceMgr.CheckBedge();
EnhanceMgr.RefreshGoldAll();
BattleMgr.StatRecalc();
RefreshCellView();
DataHandler.Goods.Save(DataHandler.PlayData.server);
BattleMgr.EnhanceHeal((dataEnhance.aftLv - dataEnhance.befLv) * DataHandler.GetCharStats()[2].abilityValueInc);
dataEnhance = null;
while (cover > 0)
{
CoverCamera.Release();
cover--;
}
iLoading--;
}
public void UpdateCell()
{
}
}