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.
 
 
 
 
 
 

182 lines
5.9 KiB

using System;
using System.Collections.Generic;
using ProtoCSStruct;
using Sog;
namespace Game
{
public static class ChapterHelper
{
public static bool IsEffectiveStage(PlayerOnGame player, int stageIdIndex)
{
if (stageIdIndex == 0)
{
return true;
}
return IsStage(player, ref player.RoleData.ChapterData.EffectiveStage, stageIdIndex);
}
public static void SetEffectiveStage(PlayerOnGame player, int stageIdIndex)
{
if (stageIdIndex == 0)
{
return;
}
ref var effectiveStage = ref player.RoleData.ChapterData.EffectiveStage;
SetStage(player, ref effectiveStage, stageIdIndex);
}
public static bool IsPerfectPass(PlayerOnGame player, int chapterIndex)
{
if (chapterIndex == 0)
{
return true;
}
return IsStage(player, ref player.RoleData.ChapterData.PerfectIds, chapterIndex);
}
public static void SetPerfectPass(PlayerOnGame player, int chapterIndex)
{
if (chapterIndex == 0)
{
return;
}
SetStage(player, ref player.RoleData.ChapterData.PerfectIds, chapterIndex);
}
public static bool IsGainPerfectPassReward(PlayerOnGame player, int chapterIndex)
{
if (chapterIndex == 0)
{
return true;
}
return IsStage(player, ref player.RoleData.ChapterData.PerfectRewardRecord, chapterIndex);
}
public static void SetGainPerfectPassReward(PlayerOnGame player, int chapterIndex)
{
if (chapterIndex == 0)
{
return;
}
SetStage(player, ref player.RoleData.ChapterData.PerfectRewardRecord, chapterIndex);
}
public static void SetGainEffectiveReward(PlayerOnGame player, int stageIdIndex)
{
if (stageIdIndex == 0)
{
return;
}
SetStage(player, ref player.RoleData.ChapterData.EffectiveRewardRecord, stageIdIndex);
}
public static bool IsGainEffectiveReward(PlayerOnGame player, int stageIdIndex)
{
if (stageIdIndex == 0)
{
return true;
}
return IsStage(player, ref player.RoleData.ChapterData.EffectiveRewardRecord, stageIdIndex);
}
private static void SetStage(PlayerOnGame player, ref RepeatedRecord stage, int stageIdIndex)
{
GameServerUtils.GetSequenceCheckIndex(stageIdIndex, out int index1, out int index2, out int bytyIndex);
if (index1 >= stage.Records.Count)
{
player.Trace("ChapterHelper.SetStage set effective stage index overflow stageindex={0}", stageIdIndex);
return;
}
if (index2 >= stage.Records[index1].Record.Count || index2 < 0)
{
player.Trace("ChapterHelper.SetStage set effective stage index overflow stageindex={0}", stageIdIndex);
return;
}
GameServerUtils.SetSequence(bytyIndex, ref stage.Records[index1].Record[index2]);
}
private static bool IsStage(PlayerOnGame player, ref RepeatedRecord stage, int stageIdIndex)
{
GameServerUtils.GetSequenceCheckIndex(stageIdIndex, out int index1, out int index2, out int bytyIndex);
if (index1 >= stage.Records.Count)
{
return true;
}
if (index2 >= stage.Records[index1].Record.Count || index2 < 0)
{
player.Trace("ChapterHelper.IsStage set effective stage index overflow stageindex={0}", stageIdIndex);
return false;
}
return GameServerUtils.CheckInSequence(bytyIndex, stage.Records[index1].Record[index2]);
}
public static List<TypeIDValue32> ConvRewardInternal(PlayerOnGame player, string rewardId, bool apply = false,
bool sendGetMsg = false)
{
var rewards = new List<TypeIDValue32>();
if (string.IsNullOrEmpty(rewardId))
{
return rewards;
}
var list = RewardSvc.Reward(player, rewardId, apply, sendGetMsg);
foreach (var rw in list)
{
var type = (GoodsType)rw.type;
var internalId = 0;
switch (type)
{
case GoodsType.Equipment:
{
var desc = EquipDescMgr.Instance.GetConfig(rw.code);
internalId = desc?.InternalId ?? 0;
}
break;
case GoodsType.Items:
{
var desc = ItemDescMgr.Instance.GetConfig(rw.code);
internalId = desc?.InternalId ?? 0;
}
break;
case GoodsType.EquipSkin:
{
var desc = RoleModelDescMgr.Instance.GetConfig(int.Parse(rw.code));
internalId = desc?.InternalId ?? 0;
}
break;
case GoodsType.ContBattle:
{
internalId = int.Parse(rw.code);
}
break;
}
if (internalId == 0)
{
TraceLog.Error("ChapterHelp.ConvRewardInternal not found desc type={0},id={1}", rw.type, rw.code);
break;
}
var reward = new TypeIDValue32() { Type = rw.type, Value = (int)rw.amount, Id = internalId };
rewards.Add(reward);
}
return rewards;
}
}
}