using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using System;
namespace YLBattle
{
///
/// 战斗管理者
///
public partial class FightingManager : MonoSingleton
{
#region 战斗结果
///
/// 参展己方ID
///
private List mHeros = new List();
///
/// 星级
///
private int mStar = 0;
///
///
///
private int mBattleForever_leaveState = 0;
#endregion
#region 关卡变量(pve)
///
/// 战斗关卡
///
private int mGateId = 0;
///
/// 波次总数
///
private int mLevelTotal = 0;
///
/// 当前波次
///
private int mLevelState = 0;
///
/// 当前关卡难度
///
private int mLevelDif = 0;
///
/// 购买buff需要的金钱
///
private int mBuyBuffGold = 0;
///
/// 关卡名称
///
private string mLevelName = string.Empty;
///
/// 关卡模式 [0=普通关卡 1=无穷尽 2=pvp 3=test 4=guide]
///
private int mLevelMode = 0;
///
/// 副本ID
///
private int mCarbonId = 0;
#endregion
#region 关卡变量(pvp)
///
///
///
private string mPvpPlayerUID = string.Empty;
///
///
///
private string mPvpType = string.Empty;
#endregion
#region 变量
///
/// 战斗者列表
///
private Dictionary mFighterList = new Dictionary();
///
/// 战斗者ID对应的TID
///
private Dictionary mFighterTIDs = new Dictionary();
///
/// 战斗者ID对应的IID
///
private Dictionary mFighterIIDs = new Dictionary();
///
/// 援军IID
///
private Dictionary mFriendIIDs = new Dictionary();
///
/// UFF 资源对象表
///
private Dictionary mBuffEffTemplate = new Dictionary();
///
/// 战斗外部数据接口
///
private IBattleGlobalOper mBFM = null;
///
/// 是否更新
///
private bool mUpdate = false;
///
/// 是否暂停
///
private bool mGetFocus = false;
///
/// 是否开启连击模式
///
private bool mOpenAombos = false;
///
/// 上次连击操作点击时间
///
private float mLastClick = 0f;
#endregion
#region 属性(对外)
///
/// 是否暂停
///
private bool isPause = false;
///
/// 战斗结束
///
private bool isGameOver = false;
#endregion
///
/// 实例
///
static FightingManager mInstance;
///
/// 获取单键
///
/// 单键实例
public static FightingManager Instance
{
get
{
if (mInstance == null)
{
GameObject obj = GameObject.Find("FightingManager");
if (obj != null)
{
mInstance = obj.AddComponent();
obj.AddComponent();
}
}
return mInstance;
}
}
///
/// 设置暂停
///
///
public void SetGameOver(bool _over)
{
this.isGameOver = _over;
}
///
/// 设置暂停
///
///
public void SetPause(bool _pause)
{
this.isPause = _pause;
if (this.isPause)
{
this.FightingPause();
}
else
{
this.FightingContinue();
}
}
///
/// 战斗暂停
///
public void FightingPause()
{
//TimeScale.Instance().Pause();
//if (this.mBFM != null)
//{
// this.mBFM.Pause();
//}
}
///
/// 战斗继续
///
public void FightingContinue()
{
//if (this.isPause && this.isGameOver == false)
//{
// return;
//}
//TimeScale.Instance().PauseOver();
//if (this.mBFM != null)
//{
// this.mBFM.Continue();
//}
}
///
/// 更新
///
void Update()
{
#region 总开关
if (!mUpdate)
{
return;
}
GameBattleManager.Instance().Update();
#endregion
if (InApplication.Instance.Focus != this.mGetFocus)
{
this.mGetFocus = InApplication.Instance.Focus;
if (this.mGetFocus)
{
this.FightingContinue();
}
else
{
this.FightingPause();
}
}
#region //是否打开连击模式
if (this.mOpenAombos == false)
{
return;
}
//如果左键按下
if (Input.GetMouseButtonDown(0))
{
//从主这相机到鼠标点发射一条射线
Ray ray = CameraManager.Instance.SenceCamara.ScreenPointToRay(Input.mousePosition);
//接受射线返回的碰撞信息
RaycastHit hitInfo;
//如果射线碰撞到东西
if (Physics.Raycast(ray, out hitInfo))
{
// if (hitInfo.collider.gameObject.tag == "BattleMonster")
if (hitInfo.collider.gameObject.CompareTag("BattleMonster"))
{
Fighter fighter = hitInfo.collider.gameObject.GetComponent();
if (fighter != null && fighter.IsDead == false)
{
fighter.SetLianjiEffect(true);
this.mLastClick = Time.realtimeSinceStartup;
SkillControl.Instance.createPosEffect(fighter.mID, "UI_SKILL_dianji", fighter.mBodyCenterPos, 2, 1.0f);
this.mBFM.ConfirmUIClickCritical(hitInfo.collider.gameObject.GetComponent().mID);
}
}
}
}
bool _showEffect = Time.realtimeSinceStartup - this.mLastClick > BattleConst.BattleLianjiSpanTime;
//fighter的特效更新
foreach (Fighter f in this.mFighterList.Values)
{
if (f.IsDead == false && f.mTeam == EBattleTeam.REDTEAM)
{
f.SetLianjiEffect(_showEffect);
}
}
#endregion
}
#region 战场动态
///
/// 获取战斗操作接口
///
/// IBattlingOpr 对象
public IBattleGlobalOper FiledBattlingHandler()
{
return this.mBFM;
}
///
/// BattleManager=>设置本次战斗信息(波次初始化)
///
/// 对象管理器
/// 地图
internal void SetLevelInfo(IBattleGlobalOper op, string scene, string bg, int mode)
{
this.mLevelMode = mode;
this.isGameOver = false;
this.ClearAllFighter();
///清空技能数据和实例
LogHelper.Log("清空技能数据和实例");
if (SkillControl.Instance)
{
SkillControl.Instance.ClearAllSkill();
}
mBFM = op;
SkillControl.Instance.SetOp(mBFM);
if (this.mLevelState == 0)
{
FightingMap.Instance.SetMapMode(mode);
///初始化状态需要去加载地图
FightingMap.Instance.GetState().ChangeState(EMapState.Loading, new List() { bg, scene });
}
}
///
/// 设置更新状态
///
/// 状态
public void SetUpdateState(bool _bolState)
{
mUpdate = _bolState;
}
///
/// 设置是否开启必杀状态
///
///
internal void SetCriticalState(bool _bol)
{
this.mOpenAombos = _bol;
this.mLastClick = 0f;
if (this.mOpenAombos == false)
{
foreach (Fighter f in this.mFighterList.Values)
{
if (f.IsDead == false && f.mTeam == EBattleTeam.REDTEAM)
{
f.SetLianjiEffect(false);
}
}
}
}
///
/// Arrival.Enter=>设置关卡信息
///
///
internal void SetFightingLevelInfo(int _gateID, int _status, int total, int dif,
string _gateName, int _buybuffgold, int _levelmode)
{
LogHelper.Log("........准备开始........:::波次::" + _status);
this.mGateId = _gateID;
this.mLevelState = _status;
this.mLevelTotal = total;
this.mLevelDif = dif;
this.mLevelName = _gateName;
this.mBuyBuffGold = _buybuffgold;
this.mLevelMode = _levelmode;
if (_status == 0)
{
//PlayerGuideManager.Instance.OnOutTrigger(EGuideEventType.EnterSence, new Dictionary() { { "senceName", "Battle" } });
UI_LoadingWindow.Instance().Hide();
}
}
///
/// Arrival.Enter=>设置关卡信息
///
///
internal void SetPVPLevelInfo(int levelID, string pvpPlayerID, string pvpType)
{
LogHelper.Log("........准备开始........");
this.mGateId = levelID;
this.mPvpPlayerUID = pvpPlayerID;
this.mPvpType = pvpType;
this.mLevelMode = 2;
UI_LoadingWindow.Instance().Hide();
}
///
/// Arrival=>战斗开始
///
/// 进度
internal void FightingStart(int _status)
{
LogHelper.Log("战斗开始,刷新界面数据......");
this.OnShowBattleUI();
BUI_TopUIWindow.Instance.SetData(this.mLevelState + 1, this.mLevelTotal, this.mLevelMode);
BUI_BattleControl.Instance.SetBattleMode(this.mLevelMode);
BUI_ButtomUIWindow.Instance.SetData(this.mLevelMode);
BUI_FighterUIWindow.Instance.SetSlotData(this.mLevelMode);
BUI_FighterUIWindow.Instance.SetLockedState(false);
BUI_ButtomUIWindow.Instance.SetActive();
BUI_BattleInfoBar.Instance.SetAcive();
}
///
/// 战斗计时刷新
///
/// 剩余毫秒数
internal void BattleTime(long leftMil)
{
BUI_ButtomUIWindow.Instance.SetBattleTime((int)leftMil);
}
///
/// Leave=>下一场战斗
///
internal void BattleLeave()
{
LogHelper.Log("------战场离开------");
BUI_FighterUIWindow.Instance.SetLockedState(true);
}
///
/// 清除战斗资源
///
public void ClearBattleBundle()
{
LogHelper.Log("------清除战斗资源------");
///战斗结果窗体
BUI_MainWindow.Instance.UnloadAllBUIBundle();
///清理bundle,放在此,主要是为了避免战斗中有些技能或者其他效果未播放完毕,就被清理~~~(特效播放有延迟)
ResourceHelper.Instance.UnloadAssetBundle("DragonBone_Mon");
ResourceHelper.Instance.UnloadAssetBundle("DragonBone_Role");
ResourceHelper.Instance.UnloadAssetBundle("UI_carbon_605021_siwang"); //死亡
ResourceHelper.Instance.UnloadAssetBundle("SKILL_604001_Arrival"); //出场动画
ResourceHelper.Instance.UnloadAssetBundle("UI_SKILL_kaishizhandou"); //开战动画
ResourceHelper.Instance.UnloadAssetBundle("UI_SKILL_LianjiFiger");
ResourceHelper.Instance.UnloadAssetBundle("UI_SKILL_dianji");
//ResourceHelper.Instance.UnloadAssetBundle(IconPrefixConst.Battle_BossIcon);
ResourceHelper.Instance.UnloadAssetBundle(IconPrefixConst.LianJi0_Icon);
ResourceHelper.Instance.UnloadAssetBundle(IconPrefixConst.LianJi1_Icon);
ResourceHelper.Instance.UnloadAssetBundle(IconPrefixConst.SkillNameIcon);
ResourceHelper.Instance.UnloadAssetBundle(IconPrefixConst.Battle_BossIcon);
this.ClearBuffBundle();
FightingMap.Instance.UnloadMapBundle();
foreach (string sID in this.mLoadedMonsterDragons)
{
FightingResManager.Instance.UnloadDragonBone(sID);
}
FightingResManager.Instance.Clear();
this.mLoadedMonsterDragons.Clear();
/// 清除延迟调用的函数
//CancelInvoke("LateShowSuccessAniWindow");
//CancelInvoke("LateShowFailAniWindow");
CancelInvoke("LateShowBattleSuccessWindow");
CancelInvoke("LateShowBattleFailWindow");
//CancelInvoke("LateShowBattleForeverSuccessWindow");
//CancelInvoke("LateShowBattleForeverFailWindow");
CancelInvoke("LateShowBattlePVPSuccessWindow");
CancelInvoke("LateShowBattlePVPFailWindow");
}
///
/// 清理战场(龙骨,UI隐藏,角色数据,地图归位
///
public void ClearBattleData()
{
BUI_BattleInfoBar.Instance.Clear();
this.ClearAllFighter();
if (SkillControl.Instance)
{
SkillControl.Instance.ClearAllSkill();
SkillControl.Instance.UnLoadAllBundle();
}
this.SetUpdateState(false);
}
#endregion
#region 战斗结果
///
/// 战斗失败
///
/// 本次战斗关卡id
/// 伤害统计
public void BattleFailed(int levelid)
{
this.mGateId = levelid;
this.isGameOver = true;
AudioManager.Instance.PlayUISoundEffect(AudioManager.BattleSepcial_LoseSound);
if (this.mLevelMode == 4) //引导
{
Invoke("LateShowGuideBattleWindow", 1.5f);
}
if (this.mLevelMode == 0)
{
//Invoke("LateShowFailAniWindow", 1.0f);
Invoke("LateShowBattleFailWindow", 1.0f);
}
if (this.mLevelMode == 1)
{
if (this.mLevelState == 0)
{
Invoke("LateShowBattleForeverFailWindow", 1.0f);
}
else
{
Invoke("LateShowBattleForeverSuccessWindow", 1.0f);
}
}
if (this.mLevelMode == 2)
{
Invoke("LateShowBattlePVPFailWindow", 1.0f);
}
if (this.mLevelMode == 3)
{
Invoke("LateShowFailAniWindow", 1.0f);
}
}
///
/// 战斗胜利
///
/// 战斗结果信息
public void BattleVictory(IBattleResult result)
{
return;
this.isGameOver = true;
if (this.mLevelMode == 4)
{
Invoke("LateShowGuideBattleWindow", 1.5f);
}
mHeros = new List();
for (int i = 0; i < result.BlueTeamFighter().Count; ++i)
{
mHeros.Add(result.BlueTeamFighter()[i].IID());
}
this.mStar = result.Star();
this.mLevelDif = result.Diflv();
this.mGateId = result.LevelID();
this.mCarbonId = result.CarbonID();
this.mBattleForever_leaveState = result.BattleForever_leaveState();
AudioManager.Instance.PlayUISoundEffect(AudioManager.BattleSepcial_WinSound);
if (this.mLevelMode == 0)
{
//Invoke("LateShowSuccessAniWindow", 1.0f);
// Invoke("LateShowBattleSuccessWindow", 1.0f);
}
if (this.mLevelMode == 1)
{
Invoke("LateShowBattleForeverSuccessWindow", 1.0f);
}
if (this.mLevelMode == 2)
{
Invoke("LateShowBattlePVPSuccessWindow", 1.0f);
}
//if (this.mLevelMode == 3)
//{
// Invoke("LateShowSuccessAniWindow", 1.0f);
//}
}
///
/// 战斗超时
///
/// 本次战斗关卡id
/// 伤害统计
public void BattleTimeOut(int levelid)
{
this.isGameOver = true;
this.mGateId = levelid;
//Invoke("LateShowFailAniWindow", 1.0f);
Invoke("LateShowBattleFailWindow", 2.5f);
}
#endregion
#region Map
///
/// 技能触发的地图被攻击动作(Bomb阶段)
///
///
public void SetMapDraging(int shakeType)
{
FightingMap.Instance.GetState().ChangeState(EMapState.Drag, shakeType);
}
///
/// 技能触发的地图被攻击动作(Bomb阶段)
///
///
public void SetMapShaking(int shakeType)
{
FightingMap.Instance.SetShaking(shakeType);
}
///
/// 地图行为
///
///
public void SetMapMove(string who)
{
if (FightingMap.Instance.Locked)
{
return;
}
if (mFighterList.ContainsKey(who))
{
if (mFighterList[who].mTeam == EBattleTeam.REDTEAM)
{
#region old 角色在地图转动时的隐藏效果
//int hideSeat = -1;
//if (mFighterList[who].mSeat == 1)
//{
// hideSeat = 2;
//}
//if (mFighterList[who].mSeat == 2)
//{
// hideSeat = 1;
//}
//foreach (Fighter f in mFighterList.Values)
//{
// if (f.mTeam != EBattleTeam.REDTEAM || f.IsDead == true)
// {
// continue;
// }
// if (f.mSeat != hideSeat)
// {
// BUI_BattleInfoBar.Instance.SetFade(false, f.mID);
// f.SetLight();
// }
// else
// {
// BUI_BattleInfoBar.Instance.SetFade(true, f.mID);
// f.SetDark();
// }
//}
#endregion
FightingMap.Instance.GetState().ChangeState(EMapState.Move, mFighterList[who].mSeat);
}
}
else
{
FightingMap.Instance.GetState().ChangeState(EMapState.Move, 0);
//foreach (Fighter f in mFighterList.Values)
//{
// if (f.mTeam != EBattleTeam.REDTEAM || f.IsDead == true)
// {
// continue;
// }
// BUI_BattleInfoBar.Instance.SetFade(false, f.mID);
// f.SetLight();
//}
}
}
///
/// 锁定地图状态
///
///
internal void SetMapLock(bool _bol)
{
FightingMap.Instance.SetLock(_bol);
}
///
/// Arrival.Enter=>设置地图平板的状态
///
///
internal void SetMapPlatState(int _status, string _aniName)
{
FightingMap.Instance.GetState().ChangeState((EMapState)_status, _aniName);
}
///
/// Arrival.IsComplete=>转盘是否处于指定状态
///
///
internal bool CheckMapState(EMapState state)
{
return FightingMap.Instance.GetState().GetCurrentState().Type() == state;
}
#endregion
#region Fighter操作
///
/// 进入攻击状态
///
/// 攻击者
/// 技能ID
/// 攻击动作
public void FighterAttack(string _who, string _strSkill, int _atkactiontype)
{
if (mFighterList.ContainsKey(_who))
{
mFighterList[_who].SetAttack(_strSkill, _atkactiontype);
}
}
///
/// 目标受伤
///
///
public void BattleFighterBeHit(string who, int _atkactiontype = 0)
{
if (mFighterList.ContainsKey(who))
{
AudioManager.Instance.PlayHeroSound(this.mFighterList[who].mTID, this.mFighterList[who].mBeattackSound, ESoundType.HERO_SOUND_BEATTACK);
if (mFighterList[who].mTeam == EBattleTeam.BLUETEAM)
{
BUI_FighterUIWindow.Instance.GetFighterSlot(who).SetHit();
}
else
{
mFighterList[who].SetHit();
/**
* 增加地图配合动画(向后拉)
*/
FightingMap.Instance.GetState().ChangeState(EMapState.BeHit, null);
}
}
}
///
/// 目标被选择
///
///
public void BattleFighterBeSelect(string who, bool isSelect = false)
{
if (mFighterList.ContainsKey(who))
{
Fighter fighter = mFighterList[who];
if (fighter.mTeam == EBattleTeam.BLUETEAM)
{
if (isSelect)
{
BUI_FighterUIWindow.Instance.GetFighterSlot(who).SetBeSelect();
}
else
{
BUI_FighterUIWindow.Instance.GetFighterSlot(who).SetBeForget();
}
}
else
{
if (isSelect)
{
SkillControl.Instance.createPosEffect(mFighterList[who].mID, "UI_SKILL_beijitishi", Vector3.zero, 1, 1.20f);
//fighter.SetBeSelect();
}
else
{
fighter.SetBeForget();
}
}
}
}
///
/// 目标死亡
///
///
public void BattleFighterBeDead(string who)
{
if (mFighterList.ContainsKey(who))
{
mFighterList[who].SetDead();
BUI_BattleInfoBar.Instance.SetDead(who);
///己方,通知管理是否有队友支援
if (mFighterList[who].mTeam == EBattleTeam.BLUETEAM)
{
this.mBFM.SetFriendHelp(mFighterList[who].mSeat);
}
///敌方,播放死亡动画
if (mFighterList[who].mTeam == EBattleTeam.REDTEAM)
{
SkillControl.Instance.createPosEffect(mFighterList[who].mID, "UI_carbon_605021_siwang", Vector3.zero, 1, 1.0f);
}
}
else
{
LogHelper.LogError("someOne is not exist...." + who);
}
// ------------------------ 新手引导 ----------------------------------------
//GuideStepAdapter adp = PlayerGuideServer.Instance.GetCurtNoviceNodeType(EGuideEventType.FighterDead);
//if (adp != null && adp.TriggerEventType == EGuideEventType.FighterDead)
//{
// adp.mNoviceEvent(gameObject, mFighterList[who].mTID);
//}
// ------------------------ 新手引导 ----------------------------------------
}
///
/// 目标等待
///
///
public void BattleFighterDisapper(string who)
{
if (mFighterList.ContainsKey(who))
{
if (mFighterList[who].mTeam == EBattleTeam.REDTEAM)
{
mFighterList[who].SetDisapper();
}
}
}
public void BattleFighterLight(string who)
{
if (mFighterList.ContainsKey(who))
{
BUI_BattleInfoBar.Instance.SetFade(false, mFighterList[who].mID);
mFighterList[who].SetLight();
}
}
public void BattleFigherDark(string who)
{
if (mFighterList.ContainsKey(who))
{
BUI_BattleInfoBar.Instance.SetFade(true, mFighterList[who].mID);
mFighterList[who].SetDark();
}
}
///
/// 目标隐藏
///
///
public void BattleFighterHidden(string who)
{
if (mFighterList.ContainsKey(who))
{
mFighterList[who].SetHidden();
}
}
///
/// 目标显示及出场
///
///
public void BattleFighterArrival(string who, bool boleffect)
{
if (mFighterList.ContainsKey(who))
{
mFighterList[who].SetArrival();
}
if (boleffect)
{
SkillControl.Instance.createPosEffect(mFighterList[who].mID, "SKILL_604001_Arrival", Vector3.zero, 0, 2.6f);
}
}
///
/// 进入静止状态
///
/// who
/// 是否强制执行静止状态
public void BattleFighterIdle(string who, bool _force)
{
if (mFighterList.ContainsKey(who))
{
mFighterList[who].SetIdle(_force);
}
}
///
/// 进入特定动画状态
///
/// who
/// 动画名字
/// 回调
public void BattleSpecialAni(string who, string _strAniName = "", Action ac = null)
{
if (mFighterList.ContainsKey(who))
{
if (_strAniName.Length <= 0)
{
//Debug.LogError("re false");
mFighterList[who].SetActiveBodyTexture(false);
}
else
{
mFighterList[who].SetActiveBodyTexture(true, "Attack", () =>
{
if (ac != null)
{
ac.Invoke();
}
});
}
}
}
#endregion
#region Buff
///
/// 添加一个BUFF 缓存
///
///
public void AddOneBuffCache(string name)
{
ResourceHelper.Instance.LoadAssetBundle(name, ab =>
{
if (ab != null && !mBuffEffTemplate.ContainsKey(name))
{
//LogHelper.LogError("###加载buff资源" + name);
GameObject buffEff = ab.LoadAsset(name);
mBuffEffTemplate.Add(name, buffEff);
}
});
}
///
/// 增加icon
///
///
public void AddNewBuffRes(string who, int iid, string res)
{
if (!mFighterList.ContainsKey(who))
{
return;
}
SkillControl.Instance.createPosEffect(who, res, Vector3.zero, 0);
}
///
/// 增加icon
///
///
public void AddNewBuffIcon(string who, int iid, string tid, string icon)
{
if (mFighterList.ContainsKey(who))
{
GameObject buffObj = null;
if (!this.mBuffEffTemplate.ContainsKey(icon))
{
return;
}
else
{
buffObj = this.mBuffEffTemplate[icon];
}
if (mFighterList[who].mTeam == EBattleTeam.REDTEAM)
{
BUI_BattleUIMovedInfoBar A = BUI_BattleInfoBar.Instance.GetFighterBar(who);
if (A != null)
{
A.AddBuff(tid, iid, buffObj);
}
else
{
//Debug.LogError("血条Null id=" + who);
}
}
else
{
BUI_FighterUIWindow.Instance.GetFighterSlot(who).AddBuff(tid, iid, buffObj);
}
}
}
///
/// 删除icon
///
///
///
public void RemoveBuffIcon(string who, int iid)
{
if (mFighterList.ContainsKey(who))
{
if (mFighterList[who].mTeam == EBattleTeam.REDTEAM)
{
BUI_BattleUIMovedInfoBar bar = BUI_BattleInfoBar.Instance.GetFighterBar(who);
if (bar != null)
{
bar.DelBuff(iid);
}
}
else
{
BUI_FighterUIWindow.Instance.GetFighterSlot(who).DelBuff(iid);
}
}
}
///
/// 清除所有buff的bundle
///
public void ClearBuffBundle()
{
foreach (KeyValuePair keyvalue in this.mBuffEffTemplate)
{
ResourceHelper.Instance.UnloadAssetBundle(keyvalue.Key);
}
this.mBuffEffTemplate.Clear();
}
#endregion
}
}