using System.Collections.Generic;
using System.Linq;

namespace Wizard;

public class BossRushHiddenBattleStartTask : BaseTask
{
	private DeckData _deck;

	public QuestBossData QuestBossData { get; private set; }

	public List<BossRushSpecialSkill> PlayerSkillList { get; private set; }

	public BossRushHiddenBattleStartTask(DeckData deck, List<BossRushLobbyAbilityData> abilityList)
	{
		base.type = ApiType.Type.BossRushHiddenBattleStart;
		_deck = deck;
		PlayerSkillList = new List<BossRushSpecialSkill>();
		for (int i = 0; i < abilityList.Count; i++)
		{
			BossRushLobbyAbilityData bossRushLobbyAbilityData = abilityList[i];
			BossRushSpecialSkill item = new BossRushSpecialSkill(bossRushLobbyAbilityData.DisplayCardId, bossRushLobbyAbilityData.Name, bossRushLobbyAbilityData.Skill, bossRushLobbyAbilityData.SkillDescText, bossRushLobbyAbilityData.IsFoil);
			PlayerSkillList.Add(item);
		}
	}

	protected override int Parse()
	{
		int num = base.Parse();
		DataMgr dataMgr = GameMgr.GetIns().GetDataMgr();
		dataMgr.ClearSpecialBattleSettingInfo();
		if (num != 1)
		{
			return num;
		}
		GameMgr.GetIns().GetDataMgr().m_BattleType = DataMgr.BattleType.SecretBossQuest;
		Data.CurrentFormat = _deck.Format;
		DeckListUtility.DataMgrSaveLastSelectDeckData(_deck);
		dataMgr.Load();
		CardMaster.SetBattleCardMasterId(FormatBehaviorManager.GetDefaultBehaviour(_deck.Format).CardMasterId);
		QuestBossData = new QuestBossData(base.ResponseData["data"]["hidden_boss_info"]);
		BossRushSpecialSkill enemySkill = new BossRushSpecialSkill(-1, QuestBossData.Name, QuestBossData.Skill, QuestBossData.SkillDescText, isFoil: false);
		BossRushBattleData bossRushBattleData = new BossRushBattleData(QuestBossData, PlayerSkillList, enemySkill);
		dataMgr.SetBossRushBattleData(bossRushBattleData);
		dataMgr.SetEnemyCharaId(dataMgr.BossRushBattleData.CharaId);
		dataMgr.SetStoryBgmID(dataMgr.BossRushBattleData.BgmId);
		dataMgr.SetSoroPlay3DFieldID(dataMgr.BossRushBattleData.Battle3dFieldID);
		dataMgr.SetEnemySleeveId(3000011L);
		int playerMaxLife = GetPlayerMaxLife();
		dataMgr.SetSpecialBattleSetting(null, playerLife: playerMaxLife, playerMaxLife: playerMaxLife, enemyMaxLife: QuestBossData.Life, playerSkill: string.Join(",", PlayerSkillList.Select((BossRushSpecialSkill s) => s.SkillText).ToList()), enemySkill: QuestBossData.Skill, playerPp: 0, enemyPp: 0, idOverrideBattleLogText: "");
		if (base.ResponseData["data"].Keys.Contains("mission_parameter"))
		{
			dataMgr.SetMissionNecessaryInformation(base.ResponseData["data"]["mission_parameter"]);
		}
		return num;
	}

	private int GetPlayerMaxLife()
	{
		int num = 20;
		for (int i = 0; i < PlayerSkillList.Count(); i++)
		{
			if (PlayerSkillList.ElementAt(i).OriginalCardId == 117031020)
			{
				num += 5;
			}
		}
		return num;
	}
}
