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.
128 lines
4.2 KiB
128 lines
4.2 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using IVDataFormat;
|
|
using IVServerFormat;
|
|
using System.Numerics;
|
|
using Sirenix.Utilities;
|
|
|
|
[Serializable]
|
|
public class HuntEagleDgData : GameModData, IHasRewards, IAutoProgressable
|
|
{
|
|
HuntEagleDgProp Property => property as HuntEagleDgProp;
|
|
HuntEagleDgPlayProp PlayProperty => playProperty as HuntEagleDgPlayProp;
|
|
|
|
int requestCount = 0;
|
|
Action<IList<nGoods>, bool> onDoneGetResult;
|
|
|
|
public override string NameKey => "dungeon_title_HuntEagle";
|
|
public int OpenStage => (int)Property.openStage;
|
|
|
|
public bool AutoProgress { get; set; }
|
|
|
|
public HuntEagleDgProp.EnemyCreator NormalEnemyCreator => Property.normalEnemyCreator;
|
|
public int WaveCount => Property.waveCount;
|
|
|
|
public float LimitTime => Property.limitTime;
|
|
public uint EnterTicketCount { get => PlayProperty.enterTicketCount; set => PlayProperty.enterTicketCount = value; }
|
|
|
|
public IList<nGoods> DefaultRewards { get; private set; }
|
|
public IList<nGoods> TotalRewards
|
|
{
|
|
get
|
|
{
|
|
//TODO: DefaultReward + BonusReward
|
|
return DefaultRewards;
|
|
}
|
|
}
|
|
|
|
public HuntEagleDgData(HuntEagleDgProp property, HuntEagleDgPlayProp playProperty)
|
|
: base(property, playProperty)
|
|
{
|
|
Property.rewards.Sort((a, b) => a.lvRange.start.CompareTo(b.lvRange.start));
|
|
SetLevel(Level);
|
|
}
|
|
|
|
public override void SetLevel(uint level)
|
|
{
|
|
level = Math.Min(level, MaxLevel);
|
|
DefaultRewards = GetRewardList(level);
|
|
PlayProperty.level = level;
|
|
}
|
|
|
|
public bool IsClear(uint level) => level < Level;
|
|
|
|
public void TryGetReward(Action<IList<nGoods>, bool> onRequestDone)
|
|
{
|
|
if (requestCount > 0) return;
|
|
|
|
requestCount = DefaultRewards.Count;
|
|
onDoneGetResult = onRequestDone;
|
|
|
|
foreach (var reward in TotalRewards)
|
|
{
|
|
SvConnectManager.Instance.RequestSvPost(true, 0, UrlApi.GetUrl(UrlApi.Property), typeof(nGoodsGet), OnGetRewardSuccess, OnGetRewardFail, reward, true);
|
|
}
|
|
|
|
if (requestCount == 0)
|
|
onDoneGetResult?.Invoke(new nGoods[0], true);
|
|
}
|
|
|
|
private void OnGetRewardSuccess(object result, object request)
|
|
{
|
|
if (--requestCount <= 0)
|
|
{
|
|
nGoodsGet data = result as nGoodsGet;
|
|
var totalReward = TotalRewards;
|
|
|
|
DataHandler.AddGoods(totalReward, data.playCurrency, true);
|
|
onDoneGetResult?.Invoke(totalReward, true);
|
|
}
|
|
}
|
|
|
|
private void OnGetRewardFail(SvError error, object request) => onDoneGetResult?.Invoke(new nGoods[0], false);
|
|
|
|
public IList<nGoods> GetRewardList(uint level)
|
|
{
|
|
if (Property.rewards.TryBinarySearch( (v) =>
|
|
{
|
|
if (v.lvRange.InRange(level)) return 0;
|
|
else return v.lvRange.start.CompareTo(level);
|
|
}, out var targetIdx))
|
|
{
|
|
var lvRangeReward = Property.rewards[targetIdx];
|
|
|
|
var result = new List<nGoods>();
|
|
for(int i = 0; i < lvRangeReward.defaultRewards.Length; i++)
|
|
{
|
|
var reward = lvRangeReward.defaultRewards[i];
|
|
|
|
var goods = reward.itemProp.ConvertTo(reward.GetCount(level));
|
|
if(result.TryFind(goods.IsSameGoods, out var exist))
|
|
exist.propertyCount += goods.propertyCount;
|
|
else
|
|
result.Add(goods);
|
|
}
|
|
|
|
//NOTE: this is reward of only once when player clear the dungeon
|
|
if(!IsClear(level))
|
|
{
|
|
for(int i = 0; i < lvRangeReward.initialClearRewards.Length; i++)
|
|
{
|
|
var reward = lvRangeReward.initialClearRewards[i];
|
|
|
|
var goods = reward.itemProp.ConvertTo(reward.GetCount(level));
|
|
if(result.TryFind(goods.IsSameGoods, out var exist))
|
|
exist.propertyCount += goods.propertyCount;
|
|
else
|
|
result.Add(goods);
|
|
}
|
|
}
|
|
|
|
return result.ToArray();
|
|
}
|
|
|
|
return new nGoods[0];
|
|
}
|
|
|
|
public BigInteger GetRecommendBattlePower(uint level) => DataHandler.CalcBattlePower(0, NormalEnemyCreator.GetHp(level));
|
|
}
|