using System;
using Cute;
using Wizard;

public class BattleFinishSendBase
{
	private FinishTaskBase _finishTaskBase;

	private Action<NetworkTask.ResultCode> _onSuccess;

	private NetworkManager _networkManager;

	private BattleManagerBase _battleMgr;

	public BattleFinishSendBase(BattleManagerBase mgr)
	{
		_networkManager = Toolbox.NetworkManager;
		_battleMgr = mgr;
	}

	public void SendMatchingFinish(FinishTaskBase finishTaskBase, Action<NetworkTask.ResultCode> callbackOnSuccess)
	{
		_finishTaskBase = finishTaskBase;
		SettingFinishBattleParameter(finishTaskBase);
		_onSuccess = callbackOnSuccess;
		StartMatchingFinish();
	}

	private void StartMatchingFinish()
	{
		LocalLog.AccumulateLastTraceLog("StartMatchingFinish");
		BattleCoroutine.GetInstance().StartCoroutine(_networkManager.Connect(_finishTaskBase, _onSuccess, CallbackOnFailure, null, encrypt: true, useJson: false, showLoadingIcon: false));
	}

	public void CallbackOnFailure(NetworkTask.ResultCode result)
	{
		LocalLog.AccumulateTraceLog("CallbackOnFailure" + result);
	}

	private void SettingFinishBattleParameter(FinishTaskBase data)
	{
		int cumulativeEvolutionCount = _battleMgr.BattlePlayer._cumulativeEvolutionCount;
		int cumulativeEvolutionCount2 = _battleMgr.BattleEnemy._cumulativeEvolutionCount;
		int battle_result = ((!_battleMgr.BattlePlayer.Class.IsDead) ? 1 : 0);
		int is_retire = (_battleMgr.IsPlayerRetire ? 1 : 0);
		DataMgr dataMgr = GameMgr.GetIns().GetDataMgr();
		data.SettingFinishBattleParameter(dataMgr.GetPlayerClassId(), _battleMgr.BattlePlayer.Turn, cumulativeEvolutionCount, cumulativeEvolutionCount2, battle_result, is_retire);
	}
}
