using System.Collections.Generic;
using CombatLibrary.CombatLibrary.CombatCore.Utility;
using Common.Utility.CombatEvent;
using Core.Audio;
using Fort23.Core;
using Fort23.Mono;
using Fort23.UTool;
using GameLogic.Bag;
using GameLogic.Combat.CombatTool;
using GameLogic.Combat.CombatType;
using UnityEngine;
using UnityEngine.UI;
using Utility.UITool;
namespace GameUI.Combat
{
///
/// 战斗和mono层的桥接
///
public class CombatMonoBaisc
{
private CombatController combatController;
private ShowItemMoveToTargetPanel _showItemMoveToTargetPanel;
public async CTask Init(CombatController combatController)
{
this.combatController = combatController;
_showItemMoveToTargetPanel = await ShowItemMoveToTargetPanel.OpenShowItemMoveToTargetPanel();
AddEvent();
}
protected void AddEvent()
{
EventManager.Instance.AddEventListener(CustomEventType.Combat_ItemShow, Combat_ItemShow);
CombatEventManager.Instance.AddEventListener(CombatEventType.HeroDieFinish, HeroDie);
}
protected void HeroDie(IEventData iEventData)
{
HeroDieEventData heroDieEventData= iEventData as HeroDieEventData;
if (heroDieEventData.combatHeroEntity.IsEnemy)
{
return;
}
BetterList myHero = combatController.CombatHeroController.GetHeroList(false);
if (myHero.Count <= 0)
{
CombatHeroDiePanel.OpenCombatHeroDiePanel();
}
}
protected void Combat_ItemShow(IEventData iEventData)
{
Vector2 target = _showItemMoveToTargetPanel.moveTarget.GetComponent().anchoredPosition;
CombatItemShowEventData combatItemShowEventData = iEventData as CombatItemShowEventData;
CombatItemShowEventData.ShowType showType = combatItemShowEventData.showType;
if (showType == CombatItemShowEventData.ShowType.LevelExp)
{
MainUIPanel mainUIPanel = UIManager.Instance.GetComponent();
Vector3 pos = mainUIPanel.expPoint.position;
target = _showItemMoveToTargetPanel.transform.worldToLocalMatrix * pos;
}
else if (showType == CombatItemShowEventData.ShowType.HeroExp)
{
MainUIPanel mainUIPanel = UIManager.Instance.GetComponent();
Vector3 pos = mainUIPanel.Icon_HeroExp.transform.position;
target = _showItemMoveToTargetPanel.transform.worldToLocalMatrix * pos;
} else if (showType == CombatItemShowEventData.ShowType.MonsterGold)
{
MainUIPanel mainUIPanel = UIManager.Instance.GetComponent();
Vector3 pos = mainUIPanel.Icon_Coin.transform.position;
target = _showItemMoveToTargetPanel.transform.worldToLocalMatrix * pos;
}
Vector3 p = UIManager.Instance.CurrCustomCameraStack.camera.WorldToScreenPoint(
combatItemShowEventData.startPos_WorldPos);
Vector3 p2 = UIManager.Instance.UICamera.ScreenToWorldPoint(p);
Vector3 startPos = _showItemMoveToTargetPanel.transform.worldToLocalMatrix * p2;
int maxCount = combatItemShowEventData.count;
int addValue = combatItemShowEventData.addValue / maxCount;
int finishVale = combatItemShowEventData.addValue % maxCount;
_showItemMoveToTargetPanel.ShowPanel(startPos, target, maxCount, combatItemShowEventData.showName,
delegate(ImageMove imageMove)
{
MainUIPanel mainUIPanel = UIManager.Instance.GetComponent();
if (mainUIPanel == null)
{
return;
}
int currAddValue = addValue;
if (imageMove.GroupIndex == maxCount - 1)
{
currAddValue += finishVale;
}
if ((CombatItemShowEventData.ShowType)imageMove.data == CombatItemShowEventData.ShowType.LevelExp)
{
if (mainUIPanel != null)
{
ParticleSystemPool particleSystemPool =
GObjectPool.Instance.FetchAsyncForGameObject(mainUIPanel.fx_ui_exp,
"fx_ui_exp");
particleSystemPool.transform.SetParent(mainUIPanel.expPoint.transform);
particleSystemPool.transform.localPosition = Vector3.zero;
particleSystemPool.transform.localScale = Vector3.one;
LevelBattleCombatType levelBattleCombatType =
CombatController.currActiveCombat.CombatTypeBasic as LevelBattleCombatType;
if (levelBattleCombatType != null)
{
levelBattleCombatType.exp += currAddValue;
}
}
}
else if ((CombatItemShowEventData.ShowType)imageMove.data ==
CombatItemShowEventData.ShowType.HeroExp)
{
if (mainUIPanel != null)
{
ParticleSystemPool particleSystemPool =
GObjectPool.Instance.FetchAsyncForGameObject(mainUIPanel.fx_ui_coin,
"fx_ui_coin");
particleSystemPool.transform.SetParent(mainUIPanel.Icon_HeroExp.transform);
particleSystemPool.transform.localPosition = Vector3.zero;
particleSystemPool.transform.localScale = Vector3.one;
BagController.Instance.AddHeroExp(currAddValue);
// particleSystemPool.transform.
}
} else if ((CombatItemShowEventData.ShowType)imageMove.data ==
CombatItemShowEventData.ShowType.MonsterGold)
{
if (mainUIPanel != null)
{
ParticleSystemPool particleSystemPool =
GObjectPool.Instance.FetchAsyncForGameObject(mainUIPanel.fx_ui_coin,
"fx_ui_coin");
particleSystemPool.transform.SetParent(mainUIPanel.Icon_Coin.transform);
particleSystemPool.transform.localPosition = Vector3.zero;
particleSystemPool.transform.localScale = Vector3.one;
BagController.Instance.AddCoin(currAddValue);
// AudioManager.Instance.PlayAudio("jingbi.wav");
// particleSystemPool.transform.
}
}
}, SetTargetPoint, showType);
}
private void SetTargetPoint(ImageMove imageMove)
{
if ((CombatItemShowEventData.ShowType)imageMove.data == CombatItemShowEventData.ShowType.LevelExp)
{
MainUIPanel mainUIPanel = UIManager.Instance.GetComponent();
Vector3 pos = mainUIPanel.expPoint.position;
Vector3 target = _showItemMoveToTargetPanel.transform.worldToLocalMatrix * pos;
CurveInfo curveInfo = imageMove.currAcur.CurveInfos[1];
curveInfo.t = target.x;
curveInfo.v = target.y;
imageMove.currAcur.CurveInfos[1] = curveInfo;
}
}
public void Update(float t)
{
}
}
}