| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using LuaInterface;
- using Mono.Xml;
- public class BattleMgr : SingletonMono<BattleMgr>
- {
- public delegate void DoSomethingCallback(object arg);
- public static int c_updateFPS = 30;
- public static float c_targetFrameTime = 1.0f / (float)c_updateFPS;
- public static float speed_up_rate = 1f;
- public static Vector3 s_reward_pos = Vector3.zero;
- private bool m_bIsShutDown = false;
- private Dictionary<int, BattleStatistics> mBattleStatisticDic = new Dictionary<int, BattleStatistics>();
- private Dictionary<long, string> mBattleRecordList = new Dictionary<long, string>();
- #region fields
- public bool IsCameraDoingStart
- {
- get { return BattleCamera.Instance != null && BattleCamera.Instance.IsDoingSpecialCamera; }
- }
- private bool mInFighting = false;
- public bool InFighting { get { return mInFighting; } }
- private bool bShowBossIntroEnd = false;
- public bool ShowBossIntroEnd
- {
- get { return bShowBossIntroEnd; }
- set { bShowBossIntroEnd = value; }
- }
- BaseBattle mBattle;
- public BaseBattle Battle { get { return mBattle; } }
- [HideInInspector]
- public LuaTable LuaBattleMgr
- {
- set { mLuaBattleMgr = value; }
- get { return mLuaBattleMgr; }
- }
- private LuaTable mLuaVersusMgr;
- public LuaTable LuaTowerMgr
- {
- get { return mLuaVersusMgr; }
- set { mLuaVersusMgr = value; }
- }
- private LuaTable mLuaBossBattleMgr;
- public LuaTable LuaBossBattleMgr
- {
- get { return mLuaBossBattleMgr; }
- set { mLuaBossBattleMgr = value; }
- }
- private LuaTable mLuaTimeBattleMgr;
- public LuaTable LuaTimeBattleMgr
- {
- get { return mLuaTimeBattleMgr; }
- set { mLuaTimeBattleMgr = value; }
- }
- private LevelItem mCurrentLevelItem;
- private LuaTable mLuaBattleMgr = null;
- public int CurExp
- {
- get { return (mCurrentLevelItem != null) ? mCurrentLevelItem.Exp : 0; }
- }
- public int CurParnterExp
- {
- get { return (mCurrentLevelItem != null) ? mCurrentLevelItem.PartnerExp : 0; }
- }
- public int CurZeny
- {
- get { return (mCurrentLevelItem != null) ? mCurrentLevelItem.Zeny : 0; }
- }
- public int CurCruise
- {
- get { return (mCurrentLevelItem != null) ? mCurrentLevelItem.CruiseVal : 0; }
- }
- public int CurGold
- {
- get { return (mCurrentLevelItem != null) ? mCurrentLevelItem.Gold : 0; }
- }
- public int CurEvil
- {
- get { return (mCurrentLevelItem != null) ? mCurrentLevelItem.Evil : 0; }
- }
- public int ChallengeLevel
- {
- get { return (mCurrentLevelItem != null) ? mCurrentLevelItem.ChallengeLv : 0; }
- }
- public bool IsKillBoss
- {
- get { return mBattle != null && mBattle.CurBattleField != null && mBattle.CurBattleField.killBoss; }
- }
- public float FightingTime
- {
- get { return (mBattle != null && mBattle.CurBattleField != null) ? mBattle.CurBattleField.FightingTime : 0; }
- }
- public override void InitMgr()
- {
- base.InitMgr();
- }
- public bool IsRotatingCam
- {
- get; private set;
- }
- private List<int> mCommonEffectIds = new List<int>();
- public List<int> CommonEffectIds
- {
- get { return mCommonEffectIds; }
- }
- public bool SkillDirty
- {
- get { return skillDirty; }
- }
- public bool TeamDirty
- {
- get { return teamDataDirty; }
- }
- protected override void Dispose()
- {
- EventMgr.RemoveEventListener<ValType[]>(ECoreEventType.EID_Click_Challenge, OnChallengeBoss);
- EventMgr.RemoveEventListener<Fighter>(ECoreEventType.EID_BOSS_SPAWNED, OnBossSpawned);
- EventMgr.RemoveEventListener<Fighter>(ECoreEventType.EID_CLONE_NEW_BOSS, OnCloneNewBoss);
- EventMgr.RemoveEventListener<string>(ECoreEventType.EID_BATTLE_NEW_NEXT_WAVE, OnBattleNewWave);
- EventMgr.RemoveEventListener<bool>(ECoreEventType.EID_BATTLE_CONTINUE_WAVE, OnContinueBattle);
- EventMgr.RemoveEventListener<bool>(ECoreEventType.EID_BEGIN_BOSS_RAGE_TIME, OnShowBossRage);
- EventMgr.RemoveEventListener<int>(ECoreEventType.EID_SHOW_BOSS_RAGE_LEFTTIME, OnShowBossRageLeftTime);
- EventMgr.RemoveEventListener<bool>(ECoreEventType.EID_BOSS_IN_RAGE, OnBossInRage);
- //EventMgr.RemoveEventListener<string>(ECoreEventType.EID_SHOW_SCENE_GO, OnSwitchScene);
- //EventMgr.RemoveEventListener<bool>(ECoreEventType.EID_RESTORE_SCENE, OnRestoreScene);
- EventMgr.RemoveEventListener<bool>(ECoreEventType.EID_FIGHTERS_LOAD_OK, OnLoadTeam);
- EventMgr.RemoveEventListener<bool>(ECoreEventType.EID_PREPARE_LOAD_OK, OnPrepareLoadOk);
- EventMgr.RemoveEventListener<bool>(ECoreEventType.EID_LOAD_BEGIN, OnLoadBegin);
- EventMgr.RemoveEventListener<bool>(ECoreEventType.EID_LOAD_COMPLETE, OnLoadComplete);
- EventMgr.RemoveEventListener<float>(ECoreEventType.EID_LOAD_PROGRESS, OnLoadProgress);
- EventMgr.RemoveEventListener<UIEventParamFighterHurt>(ECoreEventType.EID_FIGHTER_HURT, OnFighterHurt);
- EventMgr.RemoveEventListener<CastSkillData>(ECoreEventType.EID_Refresh_Skill, OnFighterCastSkill);
- EventMgr.RemoveEventListener<Fighter>(ECoreEventType.EID_FIGHTER_LIFE_CHANGED, OnFighterLifeChanged);
- EventMgr.RemoveEventListener<Fighter>(ECoreEventType.EID_FIGHTER_ENERGY_CHAGNED, OnFighterEnergyChanged);
- EventMgr.RemoveEventListener<stBuffParam>(ECoreEventType.EID_SHOW_BUFF_ICON, OnShowBossBuffIcon);
- //EventMgr.RemoveEventListener<string>(ECoreEventType.EID_SHOW_DEBUFF_ICON, OnShowBossDebuffIcon);
- EventMgr.RemoveEventListener<stBuffParam>(ECoreEventType.EID_REMOVE_BUFF_ICON, OnRemoveBuffIcon);
- EventMgr.RemoveEventListener<SkillCDParam>(ECoreEventType.EID_REFRESH_SKILL_CD, OnFighterSkillCDChanged);
- EventMgr.RemoveEventListener<Fighter>(ECoreEventType.EID_SHOW_FIGHTER, OnShowFighter);
- EventMgr.RemoveEventListener<string>(ECoreEventType.EID_PLAY_SKILL_PREFAB, OnShowSkillPrefab);
- EventMgr.RemoveEventListener<string>(ECoreEventType.EID_CLOSE_SKILL_PREFAB, OnCloseSkillPrefab);
- EventMgr.RemoveEventListener<bool>(ECoreEventType.EID_BattleUI_Visible, OnBattleUIVis);
- EventMgr.RemoveEventListener<Vector2>(ECoreEventType.EID_START_MOVE_MOUSE, OnStartMoveMouse);
- //EventMgr.RemoveEventListener<Vector2>(ECoreEventType.EID_MOUSE_DELTA, OnMouseMove);
- EventMgr.RemoveEventListener<Vector2>(ECoreEventType.EID_END_MOVE_MOUSE, OnEndMoveMouse);
- EventMgr.RemoveEventListener<bool>(ECoreEventType.EID_REPLAY_BATTLE_LOADOK, OnReplayBattleLoadedOk);
- base.Dispose();
- }
- protected override void OnApplicationQuit()
- {
- base.OnApplicationQuit();
- }
- #endregion
- void Start()
- {
- EventMgr.AddEventListener<ValType[]>(ECoreEventType.EID_Click_Challenge, OnChallengeBoss);
- EventMgr.AddEventListener<Fighter>(ECoreEventType.EID_BOSS_SPAWNED, OnBossSpawned);
- EventMgr.AddEventListener<Fighter>(ECoreEventType.EID_CLONE_NEW_BOSS, OnCloneNewBoss);
- EventMgr.AddEventListener<string>(ECoreEventType.EID_BATTLE_NEW_NEXT_WAVE, OnBattleNewWave);
- EventMgr.AddEventListener<bool>(ECoreEventType.EID_BATTLE_CONTINUE_WAVE, OnContinueBattle);
- EventMgr.AddEventListener<bool>(ECoreEventType.EID_BEGIN_BOSS_RAGE_TIME, OnShowBossRage);
- EventMgr.AddEventListener<int>(ECoreEventType.EID_SHOW_BOSS_RAGE_LEFTTIME, OnShowBossRageLeftTime);
- EventMgr.AddEventListener<bool>(ECoreEventType.EID_BOSS_IN_RAGE, OnBossInRage);
- //EventMgr.AddEventListener<string>(ECoreEventType.EID_SHOW_SCENE_GO, OnSwitchScene);
- //EventMgr.AddEventListener<bool>(ECoreEventType.EID_RESTORE_SCENE, OnRestoreScene);
- EventMgr.AddEventListener<bool>(ECoreEventType.EID_FIGHTERS_LOAD_OK, OnLoadTeam);
- EventMgr.AddEventListener<bool>(ECoreEventType.EID_PREPARE_LOAD_OK, OnPrepareLoadOk);
- EventMgr.AddEventListener<bool>(ECoreEventType.EID_LOAD_BEGIN, OnLoadBegin);
- EventMgr.AddEventListener<bool>(ECoreEventType.EID_LOAD_COMPLETE, OnLoadComplete);
- EventMgr.AddEventListener<float>(ECoreEventType.EID_LOAD_PROGRESS, OnLoadProgress);
- EventMgr.AddEventListener<UIEventParamFighterHurt>(ECoreEventType.EID_FIGHTER_HURT, OnFighterHurt);
- EventMgr.AddEventListener<CastSkillData>(ECoreEventType.EID_Refresh_Skill, OnFighterCastSkill);
- EventMgr.AddEventListener<Fighter>(ECoreEventType.EID_FIGHTER_LIFE_CHANGED, OnFighterLifeChanged);
- EventMgr.AddEventListener<Fighter>(ECoreEventType.EID_FIGHTER_ENERGY_CHAGNED, OnFighterEnergyChanged);
- EventMgr.AddEventListener<stBuffParam>(ECoreEventType.EID_SHOW_BUFF_ICON, OnShowBossBuffIcon);
- //EventMgr.AddEventListener<string>(ECoreEventType.EID_SHOW_DEBUFF_ICON, OnShowBossDebuffIcon);
- EventMgr.AddEventListener<stBuffParam>(ECoreEventType.EID_REMOVE_BUFF_ICON, OnRemoveBuffIcon);
- EventMgr.AddEventListener<SkillCDParam>(ECoreEventType.EID_REFRESH_SKILL_CD, OnFighterSkillCDChanged);
- EventMgr.AddEventListener<Fighter>(ECoreEventType.EID_SHOW_FIGHTER, OnShowFighter);
- EventMgr.AddEventListener<string>(ECoreEventType.EID_PLAY_SKILL_PREFAB, OnShowSkillPrefab);
- EventMgr.AddEventListener<string>(ECoreEventType.EID_CLOSE_SKILL_PREFAB, OnCloseSkillPrefab);
- EventMgr.AddEventListener<bool>(ECoreEventType.EID_BattleUI_Visible, OnBattleUIVis);
- EventMgr.AddEventListener<Vector2>(ECoreEventType.EID_START_MOVE_MOUSE, OnStartMoveMouse);
- //EventMgr.AddEventListener<Vector2>(ECoreEventType.EID_MOUSE_DELTA, OnMouseMove);
- EventMgr.AddEventListener<Vector2>(ECoreEventType.EID_END_MOVE_MOUSE, OnEndMoveMouse);
- EventMgr.AddEventListener<bool>(ECoreEventType.EID_REPLAY_BATTLE_LOADOK, OnReplayBattleLoadedOk);
- Time.timeScale = speed_up_rate;
- Init();
- }
- void Init()
- {
- BattleFlyWordMgr.Instance.InitMgr();
- mRecordTime2 = Time.realtimeSinceStartup;
- }
- void Update()
- {
- if (null == mBattle)
- return;
- if (mBattle.IsShutDown)
- return;
- UpdateLogic();
- UpdateTrigger();
- UpdateElse();
- }
- float mNextActionTime;
- float mRecordTime2 = 0;
- float passedTime = 0;
- void UpdateLogic()
- {
- if (mBattle != null)
- {
- if (mNextActionTime > 0f)
- {
- mNextActionTime -= Time.deltaTime;
- passedTime += Time.deltaTime;
- }
- if (mNextActionTime > 0f)
- return;
- #if PROFILE
- UnityEngine.Profiling.Profiler.BeginSample("LogicBattle Update");
- #endif
- mBattle.Update(passedTime);
- EffectManager.Instance.Update(passedTime);
- #if PROFILE
- UnityEngine.Profiling.Profiler.EndSample();
- #endif
- mNextActionTime = c_targetFrameTime;
- passedTime = 0;
- }
- else
- {
- passedTime = 0;
- }
- }
- void UpdateTrigger()
- {
- if (mBattle != null && mBattle.globalTrigger != null)
- {
- mBattle.globalTrigger.UpdateLogic(Time.deltaTime);
- }
- }
- void UpdateElse()
- {
- if (mBattle != null)
- {
- #if PROFILE
- UnityEngine.Profiling.Profiler.BeginSample("BattleDropMgr Update");
- #endif
- BattleDropMgr.Instance.Update(Time.deltaTime);
- #if PROFILE
- UnityEngine.Profiling.Profiler.EndSample();
- #endif
- #if PROFILE
- UnityEngine.Profiling.Profiler.BeginSample("ScaleTimeInfo Update");
- #endif
- //ScaleTimeInfo.Instance.Update(Time.deltaTime);
- #if PROFILE
- UnityEngine.Profiling.Profiler.EndSample();
- #endif
- #if PROFILE
- UnityEngine.Profiling.Profiler.BeginSample("EffectManager Update");
- #endif
- //EffectManager.Instance.Update(Time.deltaTime);
- #if PROFILE
- UnityEngine.Profiling.Profiler.EndSample();
- #endif
- }
- }
- public BattleStatistics GetBattleStatistics(BattleMode mode, BattleSubMode subMode)
- {
- int type = ((int)mode) * 100 + ((int)subMode);
- BattleStatistics data;
- mBattleStatisticDic.TryGetValue(type, out data);
- return data;
- }
- public bool HasBattleStatistics(BattleMode mode, BattleSubMode subMode)
- {
- var data = GetBattleStatistics(mode, subMode);
- if (data == null) return false;
- return data.Exist;
- }
- public void SetSpeedUp(float speedUp)
- {
- if (speed_up_rate != speedUp)
- {
- speed_up_rate = speedUp;
- Time.timeScale = speed_up_rate;
- }
- }
- private void LateUpdate()
- {
- if (mBattle != null)
- {
- BattleCamera.Instance.Update(Time.deltaTime);
- }
- }
- public float GetLeftFightingTime()
- {
- if (mBattle == null) return 0;
- if (mBattle.IsTimeBattle)
- {
- return mBattle.CurBattleField.MaxFightingTime - mBattle.CurBattleField.FightingTime;
- }
- return 0;
- }
- public void SetMapLevelId(int mapId, int levelId)
- {
- if (mBattle != null && mBattle.CurLevelItem != null && mBattle is LogicBattle)
- {
- //(mBattle as LogicBattle)?.StartInfo.Reset(mapId,levelId);
- //LogicBattleStartInfo startInfo = new LogicBattleStartInfo(mapId, levelId);
- //Debug.Log($"============PreloadBattle=========={mapId} --- {levelId}");
- //ShutDownCurrentBattle();
- //StartBattle(startInfo);
- }
- }
- public void StartBattle(LogicBattleStartInfo startInfo)
- {
- try
- {
- List<BattleEndCondition> endConds = new List<BattleEndCondition>();
- BattleEndCondition con = new BattleEndCondition(Constants.EndBattle_By_UndeadCount, Constants.ResultType_Normal);
- endConds.Add(con);
- mCommonEffectIds.Clear();
- mBattle = new LogicBattle(startInfo, false, endConds);
- mBattle.Start();
- mCurrentLevelItem = mBattle.CurLevelItem;
-
- Debug.Log($"==============StartBattle== Bossid={mCurrentLevelItem.bossId}====={mCurrentLevelItem.MapId} --- {mCurrentLevelItem.LevelId}");
- SaveBattleStat();
- }
- catch (System.Exception e)
- {
- DebugHelper.LogError(e.StackTrace);
- }
- }
- public void StartVersusBattle(BattleSubMode mode, ActorData[] teamActors, ActorData[] enemyActors, string sceneName, float maxBattlingTime, BattleEndCondition[] endConds,
- GvGMark[] OurMarks, GvGMark[] EnemyMarks,bool IsPresspoint,int nPresspoint)
- {
- mCommonEffectIds.Clear();
- if (teamActors == null || enemyActors == null || string.IsNullOrEmpty(sceneName)) return;
- if (endConds == null || endConds.Length == 0) return;
- try
- {
- List<BattleEndCondition> conds = new List<BattleEndCondition>();
- conds.AddRange(endConds);
- ForceSyncSkill();
- TowerBattleInfo bi = TowerBattleCfgMgr.Instance.GetTowerBattleInfo();
- mBattle = new VersusBattle(mode, bi, teamActors, enemyActors, sceneName, maxBattlingTime, conds, OurMarks,EnemyMarks,IsPresspoint, nPresspoint);
- mBattle.Start();
- SaveBattleStat();
- }
- catch (System.Exception e)
- {
- DebugHelper.LogError(e.StackTrace);
- }
- }
- public void StartBossBattle(ActorData[] actors, int bossId, int sceneId, BattleEndCondition[] endConds)
- {
- mCommonEffectIds.Clear();
- if (actors == null || actors.Length == 0)
- {
- DebugHelper.LogError("传入的玩家信息为空");
- return;
- }
- if (bossId == 0)
- {
- DebugHelper.LogError("挑战的bossid不能为0");
- return;
- }
- if (sceneId == 0)
- {
- DebugHelper.LogError("挑战boss的boss场景id不能为0");
- return;
- }
- ForceSyncSkill();
- ActorData bossActor = ActorData.CreateNpcPlayerActor(bossId, bossId, 1);
- bossActor.IsBoss = true;
- if (!bossActor.valid)
- {
- DebugHelper.LogError(string.Format("挑战{0}boss配置正确,请查看npc配表", bossId));
- return;
- }
- if (endConds == null || endConds.Length == 0)
- {
- Debugger.LogError("战斗结束条件不能配置为空");
- return;
- }
- try
- {
- List<BattleEndCondition> conds = new List<BattleEndCondition>();
- conds.AddRange(endConds);
- mBattle = new BossBattle(actors, bossActor, sceneId, BattleSubMode.WorldBoss, conds);
- mBattle.Start();
- SaveBattleStat();
- }
- catch (System.Exception e)
- {
- DebugHelper.LogError(e.StackTrace);
- }
- }
- public bool StartTimeBattle(LuaTable luaTbl,
- BattleSubMode mode, float maxFightingTime, string sceneName, string bgmMusic,
- ActorData[] ourActors, ActorData[] enemyActors, ServerFighterParam[] fighterParams,
- BattleEndCondition[] endConds, ValType[] factors,int nRestoreSp, GvGMark[] OurMarks,
- GvGMark[] EnemyMarks)
- {
- if (mode == BattleSubMode.None) return false;
- if (string.IsNullOrEmpty(sceneName)) return false;
- if (ourActors == null || enemyActors == null || ourActors.Length == 0 || enemyActors.Length == 0) return false;
- if (mBattle != null && mBattle.IsTimeBattle) return false;
- if (endConds == null || endConds.Length == 0)
- {
- Debugger.LogError("战斗结束条件不能配置为空");
- return false;
- }
- try
- {
- List<BattleEndCondition> conds = new List<BattleEndCondition>();
- conds.AddRange(endConds);
- ShutDownCurrentBattle();
- ForceSyncSkill();
- mLuaTimeBattleMgr = luaTbl;
- mBattle = new TimeBattle(mode, ourActors, enemyActors, sceneName, maxFightingTime, bgmMusic, fighterParams, conds, nRestoreSp, OurMarks, EnemyMarks);
- mBattle.Start(0, factors);
- SaveBattleStat();
- return true;
- }
- catch (System.Exception e)
- {
- DebugHelper.LogError(e.StackTrace);
- return false;
- }
- }
- public bool ReplayTimeBattle(LuaTable luaTbl, BattleSubMode mode, float maxFightingTime, string sceneName, string bgmMusic, string battleRecordStr)
- {
- if (mode == BattleSubMode.None) return false;
- if (string.IsNullOrEmpty(sceneName)) return false;
- if (string.IsNullOrEmpty(battleRecordStr)) return false;
- if (mBattle != null && mBattle.IsTimeBattle) return false;
- if (mBattle != null && mBattle.IsPlayRecord) return false;
- ShutDownCurrentBattle();
- mLuaTimeBattleMgr = luaTbl;
- JSONObject json = JSONObject.Create(CompressionUtil.UnCompress(battleRecordStr));
- BattleRecorder battleRecord = new BattleRecorder(json);
- List<BattleEndCondition> endConds = new List<BattleEndCondition>();
- BattleEndCondition con = new BattleEndCondition(Constants.EndBattle_By_UndeadCount, Constants.ResultType_Normal);
- endConds.Add(con);
- mBattle = new TimeBattle(mode, sceneName, maxFightingTime, bgmMusic, battleRecord, endConds);
- mBattle.Start();
- SaveBattleStat();
- return true;
- }
- public void SaveBattleStat()
- {
- if (mBattle.IsNormalBattle ||
- mBattle.IsVersusBattle ||
- mBattle.IsTimeBattle)
- {
- if (mBattle.BattleStatistics != null)
- {
- int type = ((int)mBattle.Mode) * 100 + ((int)mBattle.SubBattleMode);
- if (mBattleStatisticDic.ContainsKey(type))
- {
- mBattleStatisticDic[type] = mBattle.BattleStatistics;
- }
- else
- {
- mBattleStatisticDic.Add(type, mBattle.BattleStatistics);
- }
- }
- }
- }
- public List<ActorData> StartNewbieBossBattle(int sceneId, int sex)
- {
- mCommonEffectIds.Clear();
- if (sceneId == 0)
- {
- DebugHelper.LogError("挑战boss的boss场景id不能为0");
- return null;
- }
- string ta = ConfigMgr.Instance.GetXmlCfg("Newbie_Design");
- if (ta == null)
- {
- DebugHelper.LogError("新手训练没有配置全局触发器文件");
- return null;
- }
- SecurityParser doc = new SecurityParser();
- try
- {
- doc.LoadXml(ta);
- }
- catch (System.Exception e)
- {
- DebugHelper.Assert(false, "exception = {0}", e.Message);
- return null;
- }
- List<ActorData> fellows = new List<ActorData>();
- ActorData bossActor = null;
- System.Security.SecurityElement root = doc.SelectSingleNode("GlobalTrigger");
- if (root == null || root.Children == null) return null;
- for (int idx = 0; idx < root.Children.Count; idx++)
- {
- var node = root.Children[idx] as System.Security.SecurityElement;
- if (node.Tag.CompareTo("TriggerSpawnGroup") == 0)
- {
- for (int jdx = 0; jdx < node.Children.Count; jdx++)
- {
- var spawnNode = node.Children[jdx] as System.Security.SecurityElement;
- if (spawnNode.Tag.CompareTo("Spawn") == 0)
- {
- int id = 0, type;
- int.TryParse(spawnNode.Attribute("id"), out id);
- int.TryParse(spawnNode.Attribute("actorType"), out type);
- if (id > 0)
- {
- ActorType aType = (ActorType)type;
- if (aType == ActorType.Hero)
- {
- int newId = id;
- if (sex == (int)Role_Gender.Female)
- {
- newId = newId + 1;
- }
- ActorData fellow = ActorData.CreateFellowActor(sceneId * 1000 + 100 + jdx, newId, 1, null);
- fellows.Add(fellow);
- fellow.BaseId = id;
- fellow.Gender = sex;
- }
- else if (aType == ActorType.Fellow)
- {
- ActorData fellow = ActorData.CreateFellowActor(sceneId * 1000 + 100 + jdx, id, 1, null);
- fellows.Add(fellow);
- }
- else if (aType == ActorType.Monster)
- {
- bossActor = ActorData.CreateNpcPlayerActor(sceneId * 1000 + 110, id, 1);
- bossActor.IsBoss = true;
- bossActor.PositionValue = 2;
- }
- }
- }
- }
- }
- else if (node.Tag.CompareTo("EffectGroup") == 0)
- {
- for (int jdx = 0; jdx < node.Children.Count; jdx++)
- {
- var effectNode = node.Children[jdx] as System.Security.SecurityElement;
- if (effectNode.Tag.CompareTo("Effect") == 0)
- {
- int effectId = 0;
- int.TryParse(effectNode.Attribute("id"), out effectId);
- if (effectId > 0 && !mCommonEffectIds.Contains(effectId))
- {
- mCommonEffectIds.Add(effectId);
- }
- }
- }
- }
- }
- if (fellows.Count == 0 || bossActor == null)
- {
- DebugHelper.LogError("新手训练营没有配置伙伴或者boss");
- return null;
- }
- List<BattleEndCondition> endConds = new List<BattleEndCondition>();
- BattleEndCondition con = new BattleEndCondition(Constants.EndBattle_By_UndeadCount, Constants.ResultType_Normal);
- endConds.Add(con);
- mBattle = new BossBattle(fellows.ToArray(), bossActor, sceneId, BattleSubMode.NewbieBoss, endConds);
- mBattle.Start();
- return fellows;
- }
- public void EnterNextBattle()
- {
- if (mBattle == null) return;
- if (mBattle.IsNormalBattle)
- {
- if (mBattle.CurBattleField.IsIdleState)
- {
- mBattle.EnterNextBattle();
- }
- else
- {
- mBattle.ServerAckOk = true;
- }
- }
- }
- public void DoPauseFighting(bool pause)
- {
- if (mBattle != null && mBattle.CurBattleField != null)
- {
- mBattle.CurBattleField.DoPauseFight(pause);
- }
- }
- public void AddActorToBossBattle(ActorData actor)
- {
- if (mBattle == null || actor == null) return;
- mBattle.AddActor(actor);
- }
- public void SetActorDead(long actorId)
- {
- if (mBattle == null) return;
- mBattle.SyncActorLife(actorId, 0);
- }
- public void RemoveActorFromBossBattle(long actorId)
- {
- if (mBattle == null) return;
- mBattle.RemoveActor(actorId);
- }
- public void SyncBossLife(int life)
- {
- if (mBattle == null) return;
- mBattle.SyncBossLife(life);
- }
- public void SetVersusActors(ActorData[] teamActors, ActorData[] enemyActors, float maxBattlingTime)
- {
- if (teamActors == null || enemyActors == null || mBattle == null || teamActors.Length == 0 || enemyActors.Length == 0)
- {
- DebugHelper.LogError("对战数据不能为空");
- return;
- }
- if (mBattle.Mode != BattleMode.Versus) return;
- VersusBattle tb = mBattle as VersusBattle;
- tb.SetVersusActors(teamActors, enemyActors, maxBattlingTime);
- }
- public void BeginVersus()
- {
- if (mBattle == null) return;
- if (mBattle.Mode != BattleMode.Versus) return;
- VersusBattle tb = mBattle as VersusBattle;
- tb.StartVersus();
- }
- public void StartStoryScript()
- {
- if (mBattle == null) return;
- mBattle.StartStoryScript();
- if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr == null) return;
- mLuaBossBattleMgr.CallCS2Lua("OpenNewbieBattleUI");
- }
- }
- private List<ActorData> ParseTeamActors(ActorParam[] paramList)
- {
- if (paramList == null) return null;
- List<ActorData> actors = new List<ActorData>();
- for (int idx = 0; idx < paramList.Length; idx++)
- {
- ActorParam param = paramList[idx];
- ActorData ad = null;
- if (param.isRole)
- {
- ad = ActorData.CreatePlayerActor(param);
- }
- else
- {
- ad = ActorData.CreateFellowActor(param);
- }
- ad.IsMainRole = param.isMainRole;
- if (ad.valid)
- actors.Add(ad);
- }
- return actors;
- }
- public void DisposeCurrentBattle()
- {
- if (mSkillPrefabs != null && mSkillPrefabs.Count > 0)
- {
- foreach (var p in mSkillPrefabs)
- {
- ResourceMgr.Instance.RecycleGO(Constants.UIPath, p.Key, p.Value);
- }
- mSkillPrefabs.Clear();
- }
- if (mBattle != null)
- {
- mBattle.Dispose();
- mBattle = null;
- }
- }
- public void ShutDownCurrentBattle(bool bIsDispose = true)
- {
- if (mBattle != null)
- {
- mBattle.ShutDown();
- }
- if (bIsDispose)
- DisposeCurrentBattle();
- mLuaBattleMgr = null;
- mLuaBossBattleMgr = null;
- mLuaVersusMgr = null;
- mLuaTimeBattleMgr = null;
- bHasLoadedRole = false;
- bRoleModelDirty = false;
- mRoleModelGo = null;
- bLoadingRoleModel = false;
- //ScaleTimeInfo.Instance.Stop();
- EffectManager.Instance.Clear();
- if (BattleFlyWordMgr.HasInstance())
- BattleFlyWordMgr.Instance.Clear();
- if (MusicMgr.HasInstance())
- MusicMgr.Instance.CleanBeforeChangeScene();
- }
- public void Replay(BattleRecorder recorder)
- {
- if (mBattle == null)
- return;
- if (mBattle.IsNormalBattle)
- {
- mBattle.CurBattleField.PeaceEnd();
- mBattle.ReplayRecords(recorder);
- }
- }
- public void ClearBattleLog()
- {
- if (mBattle == null)
- return;
- mBattle.BattleOut.Clean();//清空本场战斗
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr == null) return;
- mLuaBattleMgr.CallCS2Lua("ClearBattleLog");//清空历史所有
- }
- }
- public void ForceStopBattle()
- {
- if (mBattle == null)
- return;
- mBattle.CurBattleField.PeaceEnd();
- }
- public void ShowStartFighting()
- {
- EventMgr.DispatchEvent<bool>(new CoreEvent<bool>(ECoreEventType.EID_BATTLE_NEW_START_FIGHTING, true));
- }
- public void SetBattleCamera()
- {
- if (BattleCamera.Instance != null)
- {
- EnableBattleCamera();
- }
- }
- public void DisableBattleCamera()
- {
- if (BattleCamera.Instance != null)
- {
- BattleCamera.Instance.DisableBattleCam();
- }
- }
- int mCurrentBattlePageId = 0;
- public void HideBattleUI()
- {
- mCurrentBattlePageId = UIMgr.Instance.GetCurrentBattlePageId();
- if (mCurrentBattlePageId > 0)
- UIMgr.Instance.Hide(mCurrentBattlePageId);
- }
- public void ShowBattleUI()
- {
- if (mCurrentBattlePageId > 0)
- {
- UIMgr.Instance.Show(mCurrentBattlePageId);
- }
- }
- public void EnableBattleCamera()
- {
- if (BattleCamera.Instance != null && UIMgr.Instance.HasBattleMainPage() && !IsPlayingComingCamera())
- {
- BattleCamera.Instance.EnableBattleCam();
- }
- }
- public void SetBossBattleCamera()
- {
- if (BattleCamera.Instance != null)
- {
- EnableBattleCamera();
- BattleCamera.Instance.SetCameraPosAndRot(mBattle.BattleBossCamPos, mBattle.BattleBossCamRot, 0, mBattle.BattleCamFar);
- }
- }
- public void SetFollowCamera(Vector3 forward, bool immediate = false)
- {
- if (BattleCamera.Instance != null)
- {
- EnableBattleCamera();
- if(0 < mBattle.FighterMgr.TeamFighters.Count)
- BattleCamera.Instance.LockFighter(mBattle.FighterMgr.TeamFighters[0], BattleCamera.Instance.CamCfg.followCamOffset, forward, BattleCamera.Instance.CamCfg.followCameraFov, BattleCamera.Instance.CamCfg.followDist, immediate);
- }
- }
- public void LookAtBattleFieldCenter()
- {
- if (mBattle.IsKillingBoss) return;
- Vector3 focusForward = mBattle.CurBattleField.FighterForward;
- Vector3 toFocus = mBattle.CurBattleField.FieldFocus;
- Vector3 toPosition = BattleCamera.Instance.CamPosition + BattleCamera.Instance.CamCfg.batttleCamOffset;
- BattleCamera.Instance.SetCameraWithFocus(toPosition, toFocus, BattleCamera.Instance.CamCfg.battleCameraFov);
- }
- public void PerformStartCamera(List<MapCameraConfig> cfgs, bool tweenTo)
- {
- EnableBattleCamera();
- BattleCamera.Instance.PerformStartCamera(cfgs, tweenTo);
- }
- public void EnterBossIntro()
- {
- ShowBossIntroEnd = false;
- BattleFlyWordMgr.Instance.SetHudVisible(false);
- UIMgr.Instance.Hide(UIPageIDs.PAGE_ID_BATTLE);
- BattleCamera.Instance.EnterBossIntroCam();
- }
- public void ExitBossIntro()
- {
- BattleFlyWordMgr.Instance.SetHudVisible(true);
- UIMgr.Instance.Show(UIPageIDs.PAGE_ID_BATTLE);
- UIMgr.Instance.Close(UIPageIDs.PAGE_ID_BOSS_INTRO);
- BattleCamera.Instance.ExitBossIntroCam();
- }
- public void ShowComingCamera()
- {
- if (BattleCamera.Instance.ComingCameraGo != null)
- {
- BattleCamera.Instance.ComingCameraGo.SetActive(true);
- }
- }
- public void PlayComingCameraAnim(string goName, string anim)
- {
- if (string.IsNullOrEmpty(anim) || string.IsNullOrEmpty(goName)) return;
- GameObject animGo = GameObject.Find(goName);
- if (animGo != null)
- {
- Animator animator = animGo.GetComponent<Animator>();
- if (animator != null)
- animator.Play(anim);
- }
- }
- public void HideComingCamera()
- {
- if (BattleCamera.Instance.ComingCameraGo != null)
- {
- BattleCamera.Instance.ComingCameraGo.SetActive(false);
- }
- }
- public bool IsPlayingComingCamera()
- {
- if (BattleCamera.Instance.ComingCameraGo != null)
- {
- return BattleCamera.Instance.ComingCameraGo.activeInHierarchy;
- }
- return false;
- }
- public void ActiveSceneAnim(string goName, string animName, bool active)
- {
- if (string.IsNullOrEmpty(goName))
- return;
- GameObject go = GameObject.Find(goName);
- if (go != null)
- {
- if (active)
- PocHelper.PlayGoAnim(go, animName);
- else
- PocHelper.StopGoAnim(go);
- }
- }
- public void ActiveSceneGo(string goName, bool active)
- {
- GameObject go = GameObject.Find(goName);
- if (go != null)
- go.SetActive(active);
- }
- public void SetUINodeVis(string nodePath)
- {
- if (string.IsNullOrEmpty(nodePath)) return;
- if (mBattle == null) return;
- if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr == null) return;
- mLuaBossBattleMgr.CallCS2Lua("SetUINodeVis", nodePath);
- }
- }
- public void OnRefreshBattleOutput()
- {
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr == null) return;
- mLuaBattleMgr.CallCS2Lua("OnRefreshBattleOutput");
- }
- }
- public void OnFightingStart()
- {
- mInFighting = true;
- BattleCamera.Instance.MoveSpeed = BattleCamera.Instance.CamCfg.CamMoveSpeed;
- UIMgr.Instance.RestoreBattleUIVisible();
- BattleFlyWordMgr.Instance.SetHudVisible(true);
- EventMgr.DispatchEvent<bool>(new CoreEvent<bool>(ECoreEventType.EID_BATTLE_NEW_FIGHTING_START, true));
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr == null) return;
- mLuaBattleMgr.CallCS2Lua("OnFightingStart", IsKillBoss);
- }
- else if (mBattle.IsTimeBattle)
- {
- if (mLuaTimeBattleMgr == null) return;
- mLuaTimeBattleMgr.CallCS2Lua("OnFightingStart");
- }
- else if (mBattle.IsVersusBattle)
- {
- if (mLuaVersusMgr != null)
- mLuaVersusMgr.CallCS2Lua("OnFightingStart");
- }
- }
- bool teamDataDirty = false;
- public bool TeamDataDirty { get { return teamDataDirty; } }
- List<ActorData> needChangeActors = new List<ActorData>();
- public void SyncTeams(bool bIsForce)
- {
- if (mBattle == null) return;
- teamDataDirty = true;
- if (mInFighting)
- {
- if(bIsForce)// 强制结束战斗 同步属性(巡游战斗中)
- {
- ForceStopBattle();
- ClearBattleLog();
- }
- else
- {
- return; //下场战斗开始 同步
- }
- }
- BattleMgr.Instance.SyncTeamData(); //同步数据
- }
- public void ClearSkillDirty()
- {
- dirtySkills.Clear();
- skillDirty = false;
- }
- Dictionary<int, List<SkillParam>> dirtySkills = new Dictionary<int, List<SkillParam>>();
- bool skillDirty = false;
- public void UpdateTeamSkills(LuaTable heroSkills)
- {
- if (heroSkills == null) return;
- dirtySkills.Clear();
- for (int i = heroSkills.Length; i >= 1; i--)
- {
- int uid = 0;
- LuaTable ltt = (LuaTable)heroSkills[i];
- int.TryParse(ltt["uid"].ToString(), out uid);
- if (uid == 0) continue;
- if (ltt["skills"] == null) continue;
- List<SkillParam> skillParams = ActorData.ParseSkillParam((LuaTable)ltt["skills"]);
- dirtySkills.Add(uid, skillParams);
- }
- if (mInFighting)
- {
- //skillDirty = true;
- //return;
- ForceStopBattle();
- ClearBattleLog();
- }
- skillDirty = true;
- CheckSkill();
- }
- public void UpdateTeamSkills(int uid, List<SkillParam> skillParams)
- {
- if (skillParams == null) return;
- bool bIsFind = dirtySkills.ContainsKey(uid);
- if(bIsFind)
- {
- dirtySkills[uid] = skillParams;
- }
- else
- {
- dirtySkills.Add(uid, skillParams);
- }
- if (mInFighting)
- {
- //skillDirty = true;
- //return;
- ForceStopBattle();
- ClearBattleLog();
- }
- skillDirty = true;
- CheckSkill();
- }
- bool professionDirty = false;
- int mCacheJobId = 0;
- public void SetProfessionDirty(bool dirty, int jobId)
- {
- professionDirty = dirty;
- mCacheJobId = jobId;
- }
- public void SetTeamData()
- {
- if (teamDataDirty)
- {
- //var teamActors = GameMgr.Instance.CharacterInfo.NormleBattleTeamActors;
- var teamActors = GameMgr.Instance.CharacterInfo.TeamActors;
- bool ret = mBattle.AddNewActors(teamActors);
- teamDataDirty = false;
- for (int idx = 0; idx < teamActors.Count; idx++)
- {
- ActorDataMgr.Instance.RefreshFellowActorData(teamActors[idx].ID, teamActors[idx].BaseId);
- }
- }
- }
- private void OnChallengeBoss(CoreEvent<ValType[]> ce)
- {
- if (mBattle == null) return;
- mBattle.ChallengeBoss = true;
- mBattle.Factors = ce.Data;
- if (mBattle.CurBattleField != null)
- {
- if (mBattle.CurBattleField.CanKillBoss)
- {
- mBattle.CurBattleField.killBoss = true;
- }
- }
- }
- public void ReplayBattle(string recordStr)
- {
- if (string.IsNullOrEmpty(recordStr)) return;
- if (mBattle == null) return;
- if (mBattle.IsPlayRecord) return;
- if (mBattle.IsKillingBoss) return;
- string recordContent = CompressionUtil.UnCompress(recordStr);
- JSONObject json = JSONObject.Create(recordContent);
- BattleRecorder battleRecord = new BattleRecorder(json);
- Replay(battleRecord);
- }
- private void OnCloneNewBoss(CoreEvent<Fighter> ce)
- {
- Fighter f = ce.Data;
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr == null) return;
- mLuaBattleMgr.CallCS2Lua("OnCloneNewBoss", f.Name, (float)f.Life, (float)f.MaxLife, f.CastSkill);
- }
- }
- private void OnBossSpawned(CoreEvent<Fighter> ce)
- {
- Fighter f = ce.Data;
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr == null) return;
- SetDifModeBossAttr(f);
- //Debug.Log("--------------OnBossSpawned-----Level-" + f.Actor.Level);
- //f.Actor.SetLevel(1200);
- mLuaBattleMgr.CallCS2Lua("OnBossSpawned", f.Actor, f.Name, (float)f.Life, (float)f.MaxLife, f.CastSkill, mBattle.IsPlayRecord);
- }
- else if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr == null) return;
- mLuaBossBattleMgr.CallCS2Lua("OnBossSpawned", f.Name, (float)f.Life, (float)f.MaxLife, f.CastSkill);
- }
- }
- private void SetDifModeBossAttr(Fighter f)
- {
- Dictionary<int, int> attrs = GameMgr.Instance.GetDifAttrs();
- NpcActorData npc = null;
- if (f.IsNpc)
- {
- npc = f.Actor as NpcActorData;
- }
- if (npc == null) return;
- npc.NpcDifRateData.Reset();
- NpcBaseData data = npc.NpcData;
- //attrs.Add(-156, 1200);
- if (attrs.ContainsKey(-156))
- {
- int newLv = attrs[-156];
- f.Actor.SetLevel(newLv);
- //f.Actor.ShowLevel = newLv;
- foreach (var item in attrs)
- {
- if (item.Key == -156) continue;
- float val = item.Value;// * 0.01f;
- val = val < 0 ? 0 : val;
- npc.NpcDifRateData.SetAttr(item.Key, val);
- }
- int size = NpcDifRateAttr.AttKeys.Count - 1;
- for (int i = 0; i < size; i++)
- {
- f.SetAttr(NpcDifRateAttr.AttKeys[i]);
- }
- }
- else
- {
- foreach (var item in attrs)
- {
- float val = item.Value;// * 0.01f;
- val = val < 0 ? 0 : val;
- //Debug.Log($"--------------[key = {item.Key}---value = { item.Value}]-");
- npc.NpcDifRateData.SetAttr(item.Key, val);
- f.SetAttr(item.Key);
- }
- }
-
- }
- public void OnReplayEnd()
- {
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr == null) return;
- mLuaBattleMgr.CallCS2Lua("OnReplayEnd");
- }
- else if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr == null) return;
- mLuaBossBattleMgr.CallCS2Lua("OnReplayEnd");
- }
- else if (mBattle.IsVersusBattle)
- {
- if (mLuaVersusMgr == null) return;
- mLuaVersusMgr.CallCS2Lua("OnReplayEnd");
- }
- else if (mBattle.IsTimeBattle)
- {
- if (mLuaTimeBattleMgr == null) return;
- mLuaTimeBattleMgr.CallCS2Lua("OnReplayEnd");
- }
- }
- public void OnBattleEnd(int flag = 0, BattleEndInfo pEndInfo = null)
- {
- mInFighting = false;
- BattleFlyWordMgr.Instance.SetHudVisible(false);
- ActorDataMgr.Instance.ResetData();
- if (mBattle.IsNormalBattle)
- {
- if (mBattle.CurBattleField.killBoss)
- {
- mBattle.ChallengeBoss = false;
- }
- StopCameraRelieveEffect();
- CheckRoleModel();
- if (mLuaBattleMgr == null) return;
- bool bIsRecord = mBattle.CurBattleField.IsPlayingRecorder;
- if (null != pEndInfo)
- bIsRecord = pEndInfo.IsPlayRecord;
- mLuaBattleMgr.CallCS2Lua("OnBattleEnd", mBattle.CurBattleField.killBoss, FightingTime, mBattle.CurBattleField.IsWin, bIsRecord);
- }
- else if (mBattle.IsVersusBattle)
- {
- if (mLuaVersusMgr != null)
- {
- mLuaVersusMgr.CallCS2Lua("OnBattleEnd");
- }
- }
- else if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr != null)
- {
- mLuaBossBattleMgr.CallCS2Lua("OnBattleEnd", flag);
- }
- }
- else if (mBattle.IsTimeBattle)
- {
- if (mLuaTimeBattleMgr != null)
- {
- mLuaTimeBattleMgr.CallCS2Lua("OnBattleEnd", mBattle.CurBattleField.IsPlayingRecorder);
- }
- }
- }
-
- public void OnBattleForceStop(bool bossBattle)
- {
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr == null) return;
- mLuaBattleMgr.CallCS2Lua("OnForceBattleFailed", bossBattle, mBattle.IsPlayRecord);
- }
- else if(mBattle.IsTimeBattle)
- {
- mLuaTimeBattleMgr.CallCS2Lua("OnForceBattleFailed");
- }
- }
- public void OnBattleWin(bool bossBattle)
- {
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr == null) return;
- long timeStamp = DateTimeUtil.GetCurrentTimeStamp();
- string recordStr = mBattle.Recorder != null ? mBattle.Recorder.RecordStr : null;
- if (!string.IsNullOrEmpty(recordStr))
- {
- mBattleRecordList.Add(timeStamp, recordStr);
- }
- int mapId = 0;
- int levelId = 0;
- if (mBattle.CurLevelItem != null)
- {
- mapId = mBattle.CurLevelItem.MapId;
- levelId = mBattle.CurLevelItem.LevelId;
- }
- mLuaBattleMgr.CallCS2Lua("OnBattleWin", bossBattle, FightingTime, mapId, levelId, mBattle.IsPlayRecord, timeStamp);
- }
- else if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr == null) return;
- mLuaBossBattleMgr.CallCS2Lua("OnBattleWin");
- }
- else if (mBattle.IsVersusBattle)
- {
- if (mLuaVersusMgr == null) return;
- mLuaVersusMgr.CallCS2Lua("OnBattleWin");
- }
- else if (mBattle.IsTimeBattle)
- {
- if (mLuaTimeBattleMgr == null) return;
- long timeStamp = DateTimeUtil.GetCurrentTimeStamp();
- if (!string.IsNullOrEmpty(mBattle.RecorderStr))
- {
- mBattleRecordList.Add(timeStamp, mBattle.RecorderStr);
- }
- List<ServerFighterParam> fighterParams = new List<ServerFighterParam>();
- for (int idx = 0; idx < mBattle.CurBattleField.TeamFighters.Count; idx++)
- {
- var f = mBattle.CurBattleField.TeamFighters[idx];
- if (f.IsPlayer)
- {
- TimeBattle pTimeBattle = mBattle as TimeBattle;
- float fRestorSp = 0.0f;
- if(null != pTimeBattle)
- {
- fRestorSp = pTimeBattle.GetRestoreSp();//远征之门 战斗胜利后的 回蓝
- }
- float fhpPercent = (f.Life * 1.0f) / f.MaxLife;
- float fspPercent = f.Sp / f.MaxSp + fRestorSp;
- MathUtil.ConverFloatRound(ref fhpPercent);
- MathUtil.ConverFloatRound(ref fspPercent);
- fhpPercent = Mathf.Min(fhpPercent, 1.0f);
- fspPercent = Mathf.Min(fspPercent, 1.0f);
- fighterParams.Add(new ServerFighterParam(f.Actor.ID, 0, 0, fhpPercent, fspPercent));
- }
- }
- mLuaTimeBattleMgr.CallCS2Lua("OnBattleWin", mBattle.CurBattleField.BattleFrame / Constants.frame_to_time, mBattle.IsPlayRecord, timeStamp, fighterParams);
- }
- }
- public void OnBattleFailed(bool bossBattle, int bossLife = 0, int bossSp = 0,bool bIsShowFailedUi = true)
- {
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr == null) return;
-
- mLuaBattleMgr.CallCS2Lua("OnBattleFailed", bossBattle, mBattle.IsPlayRecord);
-
- }
- else if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr == null) return;
- mLuaBossBattleMgr.CallCS2Lua("OnBattleFailed");
- }
- else if (mBattle.IsVersusBattle)
- {
- if (mLuaVersusMgr == null) return;
- mLuaVersusMgr.CallCS2Lua("OnBattleFailed");
- }
- else if (mBattle.IsTimeBattle)
- {
- if (mLuaTimeBattleMgr == null) return;
- List<ServerFighterParam> fighterParams = new List<ServerFighterParam>();
- for (int idx = 0; idx < mBattle.CurBattleField.TeamFighters.Count; idx++)
- {
- var f = mBattle.CurBattleField.TeamFighters[idx];
- if (f.IsPlayer)
- {
- float fhpPercent = (f.Life * 1.0f) / f.MaxLife;
- float fspPercent = f.Sp / f.MaxSp;
- MathUtil.ConverFloatRound(ref fhpPercent);
- MathUtil.ConverFloatRound(ref fspPercent);//防止丢之精度 2位后有值 向前进一位
- fhpPercent = Mathf.Min(fhpPercent, 1.0f);
- fspPercent = Mathf.Min(fspPercent, 1.0f);
- fighterParams.Add(new ServerFighterParam(f.Actor.ID, 0,0, fhpPercent, fspPercent));
- }
- }
-
- mLuaTimeBattleMgr.CallCS2Lua("OnBattleFailed", mBattle.CurBattleField.BattleFrame / Constants.frame_to_time, fighterParams, bossLife, bossSp);
-
-
- }
- }
- private void OnBattleNewWave(CoreEvent<string> ce)
- {
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr == null) return;
- mCurrentLevelItem = mBattle.CurBattleField.BattleInfo;
- mLuaBattleMgr.CallCS2Lua("OnBattleNewWave", ce.Data);
- }
- }
- private void OnContinueBattle(CoreEvent<bool> ce)
- {
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr == null) return;
- mLuaBattleMgr.CallCS2Lua("OnContinueBattle");
- }
- }
- private void OnShowBossRage(CoreEvent<bool> ce)
- {
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr == null) return;
- mLuaBattleMgr.CallCS2Lua("OnShowBossRage", ce.Data, mBattle.IsPlayRecord);
- }
- }
- private void OnShowBossRageLeftTime(CoreEvent<int> ce)
- {
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr == null) return;
- mLuaBattleMgr.CallCS2Lua("OnShowBossRageLeftTime", ce.Data, mBattle.IsPlayRecord);
- }
- else if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr == null) return;
- mLuaBossBattleMgr.CallCS2Lua("OnShowBossRageLeftTime", ce.Data);
- }
- }
- private void OnBossInRage(CoreEvent<bool> ce)
- {
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr == null) return;
- mLuaBattleMgr.CallCS2Lua("OnBossInRage", mBattle.IsPlayRecord);
- }
- else if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr == null) return;
- mLuaBossBattleMgr.CallCS2Lua("OnBossInRage");
- }
- }
- private void OnFighterHurt(CoreEvent<UIEventParamFighterHurt> ce)
- {
- if (mBattle != null)
- {
- if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr == null) return;
- UIEventParamFighterHurt hurtParam = ce.Data;
- Fighter target = hurtParam.mTarget;
- if (target.IsBoss)
- {
- mLuaBossBattleMgr.CallCS2Lua("OnSyncBossDamage", hurtParam.mHurtVal, mBattle.IsPlayRecord);
- }
- }
- else if (mBattle.IsTimeBattle &&( mBattle.SubBattleMode == BattleSubMode.Guild || mBattle.SubBattleMode == BattleSubMode.GuildEx) )
- {
- if (mLuaTimeBattleMgr == null) return;
- UIEventParamFighterHurt hurtParam = ce.Data;
- Fighter target = hurtParam.mTarget;
- if (target.TeamSide == eTeamType.Enemy)
- {
- mLuaTimeBattleMgr.CallCS2Lua("OnFighterHurt", hurtParam.mHurtVal);
- }
- }
- }
- }
- private void OnFighterCastSkill(CoreEvent<CastSkillData> ce)
- {
- CastSkillData skillParam = ce.Data;
- if (mBattle != null)
- {
- if (mBattle.IsNormalBattle && IsKillBoss && mLuaBattleMgr != null)
- {
- mLuaBattleMgr.CallCS2Lua("OnFighterCastSkill", skillParam, mBattle.IsPlayRecord);
- }
- else if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr != null)
- mLuaBossBattleMgr.CallCS2Lua("OnFighterCastSkill", skillParam);
- }
- else if (mBattle.IsVersusBattle)
- {
- if (mLuaVersusMgr != null)
- {
- mLuaVersusMgr.CallCS2Lua("OnFighterCastSkill", skillParam);
- }
- }
- else if (mBattle.IsTimeBattle)
- {
- if (mLuaTimeBattleMgr != null)
- {
- mLuaTimeBattleMgr.CallCS2Lua("OnFighterCastSkill", skillParam);
- }
- }
- }
- }
- private void OnShowBossBuffIcon(CoreEvent<stBuffParam> ce)
- {
- stBuffParam param = ce.Data;
- if (mBattle != null)
- {
- if (mBattle.IsNormalBattle && IsKillBoss && mLuaBattleMgr != null)
- {
- mLuaBattleMgr.CallCS2Lua("OnShowBossBuff", param.actorId, param.isBoss, param.buffIcon, param.pointNum, mBattle.IsPlayRecord);
- }
- else if (mBattle.IsVersusBattle)
- {
- if (mLuaVersusMgr != null)
- mLuaVersusMgr.CallCS2Lua("OnShowBossBuff", param.teamSide, param.actorId, param.isBoss, param.buffIcon, param.pointNum);
- }
- else if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr != null)
- mLuaBossBattleMgr.CallCS2Lua("OnShowBossBuff", param.actorId, param.isBoss, param.buffIcon, param.pointNum);
- }
- else if (mBattle.IsTimeBattle)
- {
- if (mLuaTimeBattleMgr != null)
- mLuaTimeBattleMgr.CallCS2Lua("OnShowBossBuff", param.teamSide, param.actorId, param.isBoss, param.buffIcon, param.pointNum);
- }
- }
- }
- private void OnRemoveBuffIcon(CoreEvent<stBuffParam> ce)
- {
- stBuffParam param = ce.Data;
- if (mBattle != null)
- {
- if (mBattle.IsNormalBattle && IsKillBoss && mLuaBattleMgr != null)
- {
- mLuaBattleMgr.CallCS2Lua("OnRemoveBossBuff", param.actorId, param.isBoss, param.buffIcon, mBattle.IsPlayRecord);
- }
- else if (mBattle.IsVersusBattle)
- {
- if (mLuaVersusMgr != null)
- mLuaVersusMgr.CallCS2Lua("OnRemoveBossBuff", param.teamSide, param.actorId, param.isBoss, param.buffIcon);
- }
- else if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr != null)
- mLuaBossBattleMgr.CallCS2Lua("OnRemoveBossBuff", param.actorId, param.isBoss, param.buffIcon);
- }
- else if (mBattle.IsTimeBattle)
- {
- if (mLuaTimeBattleMgr != null)
- mLuaTimeBattleMgr.CallCS2Lua("OnRemoveBossBuff", param.teamSide, param.actorId, param.isBoss, param.buffIcon);
- }
- }
- }
- private void OnFighterLifeChanged(CoreEvent<Fighter> ce)
- {
- if (mBattle == null) return;
- Fighter f = ce.Data;
- if (mBattle.IsNormalBattle)
- {
- if (IsKillBoss)
- {
- if (mLuaBattleMgr != null && (f.IsPlayer || f.IsBoss))
- mLuaBattleMgr.CallCS2Lua("OnFighterLifeChanged", f.IsBoss, f.Actor.ID, (float)f.Life, (float)f.MaxLife);
- }
- }
- else if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr != null && (f.IsPlayer || f.IsBoss))
- mLuaBossBattleMgr.CallCS2Lua("OnFighterLifeChanged", f.IsBoss, f.Actor.ID, (float)f.Life, (float)f.MaxLife);
- }
- else if (mBattle.IsVersusBattle)
- {
- if (mLuaVersusMgr != null && f.IsPlayer)
- mLuaVersusMgr.CallCS2Lua("OnFighterLifeChanged", f.IsBoss, f.Actor.ID, (float)f.Life, (float)f.MaxLife, (int)f.TeamSide);
- }
- else if (mBattle.IsTimeBattle)
- {
- if (mLuaTimeBattleMgr != null)
- {
- if (f.IsPlayer || f.IsBoss)
- {
- mLuaTimeBattleMgr.CallCS2Lua("OnFighterLifeChanged", f.IsBoss,
- f.Actor.ID,
- (float)f.Life,
- (float)f.MaxLife,
- (int)f.Sp,
- (int)f.MaxSp);
- }
- }
- }
- }
- private void OnFighterEnergyChanged(CoreEvent<Fighter> ce)
- {
- Fighter f = ce.Data;
- if (mBattle != null)
- {
- if (mBattle.IsNormalBattle)
- {
- if (IsKillBoss && mLuaBattleMgr != null && f.IsPlayer)
- mLuaBattleMgr.CallCS2Lua("OnFighterEnergyChanged", f.Actor.ID, (int)f.Sp, (int)f.MaxSp, mBattle.IsPlayRecord);
- }
- else if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr != null && f.IsPlayer)
- mLuaBossBattleMgr.CallCS2Lua("OnFighterEnergyChanged", f.Actor.ID, (int)f.Sp, (int)f.MaxSp);
- }
- else if (mBattle.IsVersusBattle)
- {
- if (mLuaVersusMgr != null && f.IsPlayer)
- {
- mLuaVersusMgr.CallCS2Lua("OnFighterEnergyChanged", f.Actor.ID, (int)f.Sp, (int)f.MaxSp, (int)f.TeamSide);
- }
- }
- else if (mBattle.IsTimeBattle)
- {
- if (mLuaTimeBattleMgr != null && (f.IsPlayer || f.IsBoss))
- {
- mLuaTimeBattleMgr.CallCS2Lua("OnFighterEnergyChanged", f.IsBoss,
- f.Actor.ID,
- (float)f.Life,
- (float)f.MaxLife,
- (int)f.Sp,
- (int)f.MaxSp);
- }
- }
- }
- }
- private void OnFighterSkillCDChanged(CoreEvent<SkillCDParam> ce)
- {
- if (mBattle != null && IsKillBoss)
- {
- SkillCDParam cdParam = ce.Data;
- if (mLuaBattleMgr != null)
- mLuaBattleMgr.CallCS2Lua("OnRefreshSkillCD", cdParam.isBoss, cdParam.actorId, cdParam.leftCD, cdParam.totalCD, mBattle.IsPlayRecord);
- }
- }
- private void OnShowFighter(CoreEvent<Fighter> ce)
- {
- Fighter f = ce.Data;
- if (mBattle != null)
- {
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr != null)
- mLuaBattleMgr.CallCS2Lua("OnShowFighter", f.Id, mBattle.IsPlayRecord);
- }
- else if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr != null)
- mLuaBossBattleMgr.CallCS2Lua("OnShowFighter", f.Id);
- }
- }
- }
- Dictionary<string, GameObject> mSkillPrefabs = new Dictionary<string, GameObject>();
- private void OnShowSkillPrefab(CoreEvent<string> ce)
- {
- string prefabName = ce.Data;
- if (string.IsNullOrEmpty(prefabName)) return;
- GameObject skillPrefab = ResourceMgr.Instance.GetGoFromPool(Constants.UIPath, prefabName);
- if (skillPrefab != null)
- {
- Transform hudPanel = BattleFlyWordMgr.Instance.HudRootTrans;
- if (hudPanel != null)
- {
- skillPrefab.transform.SetParent(hudPanel, true);
- skillPrefab.transform.localScale = Vector3.one;
- skillPrefab.transform.localRotation = Quaternion.identity;
- }
- RectTransform rt = skillPrefab.GetComponent<RectTransform>();
- rt.anchorMin = Vector2.zero;
- rt.anchorMax = Vector2.one;
- rt.anchoredPosition3D = Vector3.zero;
- rt.offsetMin = rt.offsetMax = Vector2.zero;
- mSkillPrefabs.Add(prefabName, skillPrefab);
- }
- }
- private void OnCloseSkillPrefab(CoreEvent<string> ce)
- {
- string prefabName = ce.Data;
- if (string.IsNullOrEmpty(prefabName)) return;
- if (mSkillPrefabs.ContainsKey(prefabName))
- {
- GameObject go = mSkillPrefabs[prefabName];
- mSkillPrefabs.Remove(prefabName);
- ResourceMgr.Instance.RecycleGO(Constants.UIPath, prefabName, go);
- }
- }
- private void OnBattleUIVis(CoreEvent<bool> ce)
- {
- if (mBattle != null)
- {
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr != null)
- mLuaBattleMgr.CallCS2Lua("OnBattleUIVis", ce.Data);
- if (BattleFlyWordMgr.Instance.HudRoot != null)
- BattleFlyWordMgr.Instance.HudRoot.SetActive(ce.Data);
- }
- }
- }
- public void ShowBossWarning()
- {
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr == null) return;
- if (!mBattle.IsPlayRecord)
- mLuaBattleMgr.CallCS2Lua("OnShowBossWarning");
- }
- else if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr == null) return;
- mLuaBossBattleMgr.CallCS2Lua("OnShowBossWarning");
- }
- }
- public void ShowPVPPressPoint()
- {
- if (mLuaVersusMgr == null) return;
- mLuaVersusMgr.CallCS2Lua("OnShowPvpPressPoint");
- }
-
- //显示战斗结束转场
- public void ShowBattleEndInterlude()
- {
- if (mLuaVersusMgr != null)
- {
- mLuaVersusMgr.CallCS2Lua("ShowBattleEndInterlude");
- }
- }
- //开始巡游
- public void OnBeginSearch()
- {
- mBattle.TeamIntoBattlField();
- SetFollowCamera(Vector3.zero);
- }
- //更新队伍数据 技能等级
- public void SyncTeamData()
- {
- bool bIsProcessLoad = false;//是否有更新加载
- if (!mBattle.IsPlayRecord)
- {
- SetTeamData();
- CheckSkill();
- bIsProcessLoad = CheckProfession();
- SyncTeamName();
- }
- if (bIsProcessLoad || bRoleModelDirty) //是否需要刷新形象
- {
- NotifyRefreshRoleView(); //刷新形象
- CheckRoleModel();
- }
- }
- public void SyncTeamName()
- {
- //HeroActorData hero = GameMgr.Instance.CharacterInfo.Actor;
- //HeroActorData Battlehero = GameMgr.Instance.CharacterInfo.mBattleActor;
- //if(null != hero && null != Battlehero)
- //{
- // Battlehero.Name = hero.Name;//战斗数据同步 源数据
- //}
- }
- public void CheckSkill()
- {
- //同步主属性
- bool needLoad = false;
- foreach (var p in dirtySkills)
- {
- ActorData ad = ActorDataMgr.Instance.GetActorsById(p.Key);
- if (ad != null)
- {
- needLoad = ad.SkillMgr.SetSkillLevels(p.Value);
- ad.ResetFirstSkill();
- }
- }
- if (null == mBattle)
- return;
- //同步战斗属性
- if (skillDirty)
- {
- foreach (var p in dirtySkills)
- {
- Fighter f = mBattle.FighterMgr.GetTeamMemberById(p.Key);
- if (f != null)
- {
- bool ret = f.Actor.SkillMgr.SetSkillLevels(p.Value);
- needLoad |= ret;
- f.Actor.ResetFirstSkill();
- }
- }
- if (needLoad)
- {
- BattlePrepareManager.Instance.StartLoad();
- }
- skillDirty = false;
- }
- }
- public bool CheckProfession()
- {
- if (professionDirty)
- {
- HeroActorData hero = GameMgr.Instance.CharacterInfo.Actor; //更新源数据
- //HeroActorData Battlehero = GameMgr.Instance.CharacterInfo.mBattleActor;//更新备份战斗数据
- //Battlehero.SetProfessionId(mCacheJobId, true);
- hero.SetProfessionId(mCacheJobId, true);
- BattlePrepareManager.Instance.StartLoad();
- if (IsLoadingBattleAssets)
- {
- for (int idx = 0; idx < mBattle.FighterMgr.TeamFighters.Count; idx++)
- {
- mBattle.FighterMgr.TeamFighters[idx].Ctrl.EnableNavAgent(false);
- }
- }
- professionDirty = false;
- //通知lua 主角转职正式完成
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr != null)
- mLuaBattleMgr.CallCS2Lua("HeroChangeProfessionSuccess");
- }
- else if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr != null)
- mLuaBossBattleMgr.CallCS2Lua("HeroChangeProfessionSuccess");
- }
- return true;
- }
- return false;
- }
- public void ForceSyncSkill()
- {
- if (skillDirty)
- {
- foreach (var p in dirtySkills)
- {
- ActorData actor = ActorDataMgr.Instance.GetActorsById(p.Key);
- if (actor != null && p.Value != null)
- {
- actor.RefreshSkills(p.Value.ToArray());
- }
- }
- skillDirty = false;
- }
- }
- public void RefreshStatistics()
- {
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr != null)
- mLuaBattleMgr.CallCS2Lua("RefreshStatistics");
- }
- else if (mBattle.IsTimeBattle)
- {
- if (mLuaTimeBattleMgr != null)
- mLuaTimeBattleMgr.CallCS2Lua("RefreshStatistics");
- }
- else if (mBattle.IsVersusBattle)
- {
- if (mLuaVersusMgr != null)
- mLuaVersusMgr.CallCS2Lua("RefreshStatistics");
- }
- }
-
- int notifiedStatus = -1;
- public void NotifyLoadingStatus(int status)
- {
- if (mBattle != null)
- {
- if (mLuaBattleMgr != null)
- mLuaBattleMgr.CallCS2Lua("NotifyLoadingStatus", status);
- }
- }
- public void NotifyLoadingStatusEnd()
- {
- if (mBattle != null)
- {
- if (mLuaBattleMgr != null)
- mLuaBattleMgr.CallCS2Lua("NotifyLoadingStatusEnd", notifiedStatus);
- }
- }
- public void StartingFight()
- {
- if (mBattle != null)
- {
- if (mLuaVersusMgr != null)
- mLuaVersusMgr.CallCS2Lua("OnStartingFight");
- }
- }
- public void Skip()
- {
- if (mBattle.IsPlayRecord)
- mBattle.Recorder.Skip();
- }
- public const int m_angle_effect_id_cfgid = 32;
- int cameraRelieveEffectIstanceId = 0;
- public void PlayCameraReliveEffect()
- {
- if (cameraRelieveEffectIstanceId > 0) return;
- int effectId = GlobalConfig.Instance.GetConfigIntValue(m_angle_effect_id_cfgid);
- if (effectId > 0)
- {
- cameraRelieveEffectIstanceId = EffectManager.Instance.PlayEffect(effectId);
- }
- }
- public void StopCameraRelieveEffect()
- {
- if (cameraRelieveEffectIstanceId > 0)
- {
- cameraRelieveEffectIstanceId = 0;
- }
- }
- void WorldPos2MinimapPos(Vector3 pos, int mapSizeX, int mapSizeZ, int miniMapSizeX, int miniMapSizeZ, ref float x, ref float z)
- {
- float xRate = pos.x / mapSizeX;
- float zRate = pos.z / mapSizeZ;
- x = miniMapSizeX * xRate;
- z = miniMapSizeZ * zRate;
- }
- public void RefreshMinimap(Vector3 center, int mapSizeX, int mapSizeZ, int miniMapSizeX, int miniMapSizeZ, GameObject hero, params RectTransform[] goes)
- {
- GetFightersPos();
- int cnt = mFightersPos.Count;
- if (cnt < 2 || goes.Length < 1 || hero == null) return;
- //设置主角的位置
- RectTransform miniMapGO = goes[0];
- float mapX = 0, mapZ = 0;
- WorldPos2MinimapPos(mFightersPos[0], mapSizeX, mapSizeZ, miniMapSizeX, miniMapSizeZ, ref mapX, ref mapZ);
- Vector3 pos = miniMapGO.anchoredPosition;
- pos.x = miniMapSizeX * ((float)center.x / mapSizeX) - mapX;
- pos.y = miniMapSizeZ * ((float)center.z / mapSizeZ) - mapZ;
- miniMapGO.anchoredPosition = pos;
- //设置主角的朝向
- Vector3 rot = mFightersPos[1];
- rot.x = 0; rot.z = -rot.y; rot.y = 0;
- hero.transform.localRotation = Quaternion.Euler(rot);
- //设置怪物的位置
- for (int idx = 1; idx < goes.Length; idx++)
- {
- if (idx + 1 >= cnt)
- {
- goes[idx].gameObject.SetActive(false);
- }
- else
- {
- goes[idx].gameObject.SetActive(true);
- Vector3 deltaPos = mFightersPos[idx + 1] - mFightersPos[0];
- float enemyX = 0, enemyZ = 0;
- WorldPos2MinimapPos(deltaPos, mapSizeX, mapSizeZ, miniMapSizeX, miniMapSizeZ, ref enemyX, ref enemyZ);
- var p = goes[idx].anchoredPosition;
- p.x = enemyX;
- p.y = enemyZ;
- goes[idx].anchoredPosition = p;
- }
- }
- }
- List<Vector3> mFightersPos = new List<Vector3>();
- public List<Vector3> GetFightersPos()
- {
- mFightersPos.Clear();
- if (mBattle == null || mBattle.CurBattleField == null || !mBattle.IsNormalBattle) return mFightersPos;
- if (mBattle.CurBattleField.TeamFighters.Count > 0)
- {
- mFightersPos.Add(mBattle.CurBattleField.TeamFighters[0].Position);
- mFightersPos.Add(mBattle.CurBattleField.TeamFighters[0].Ctrl.transform.rotation.eulerAngles);
- }
- for (int idx = 0; idx < mBattle.CurBattleField.EnemyFighters.Count; idx++)
- {
- mFightersPos.Add(mBattle.CurBattleField.EnemyFighters[idx].Position);
- }
- return mFightersPos;
- }
- void OnStartMoveMouse(CoreEvent<Vector2> ce)
- {
- if (mBattle == null) return;
- if (!mBattle.IsNormalBattle) return;
- if (mBattle.IsKillingBoss) return;
- IsRotatingCam = true;
- BattleCamera.Instance.BeginCamRotate();
- }
- void OnEndMoveMouse(CoreEvent<Vector2> ce)
- {
- if (mBattle == null) return;
- if (!mBattle.IsNormalBattle) return;
- if (mBattle.IsKillingBoss) return;
- IsRotatingCam = false;
- BattleCamera.Instance.RestoreCamRotate();
- }
- //bool newScene = false;
- //void OnSwitchScene(CoreEvent<string> ce)
- //{
- // newScene = true;
- //}
- //void OnRestoreScene(CoreEvent<bool> ce)
- //{
- // newScene = false;
- //}
- void OnLoadTeam(CoreEvent<bool> ce)
- {
- if (mBattle.IsLoadingActor)
- {
- NotifyLoadingStatus(1);
- for (int idx = 0; idx < mBattle.FighterMgr.TeamFighters.Count; idx++)
- {
- mBattle.FighterMgr.TeamFighters[idx].Ctrl.EnableNavAgent(false);
- }
- }
- else
- {
- if (!IsLoadingBattleAssets)
- {
- mBattle.MoveToNextBattleField(false);
- }
- NotifyLoadingStatusEnd();
- }
- }
- void OnPrepareLoadOk(CoreEvent<bool> ce)
- {
- if (mBattle == null) return;
- if (mBattle.Mode != BattleMode.Normal) return;
- if (!IsLoadingBattleAssets)
- {
- NotifyLoadingStatusEnd();
- }
- }
- void OnReplayBattleLoadedOk(CoreEvent<bool> ce)
- {
- if (mBattle == null) return;
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr == null) return;
- mLuaBattleMgr.CallCS2Lua("OnLoadComplete");
- }
- else if (mBattle.IsVersusBattle)
- {
- if (mLuaVersusMgr == null) return;
- mLuaVersusMgr.CallCS2Lua("OnLoadComplete");
- }
- else if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr == null) return;
- mLuaBossBattleMgr.CallCS2Lua("OnLoadComplete");
- }
- else if (mBattle.IsTimeBattle)
- {
- if (mLuaTimeBattleMgr == null) return;
- mLuaTimeBattleMgr.CallCS2Lua("OnLoadComplete");
- }
- }
- public bool IsLoadingBattleAssets
- {
- get { return (mBattle != null && mBattle.IsLoadingActor) || BattlePrepareManager.Instance.IsLoading; }
- }
- public void CheckRoleModel()
- {
- if (!bRoleModelDirty) return;
- mLuaBattleMgr.CallCS2Lua("RefreshRoleView");
- bRoleModelDirty = false;
- }
- private bool bHasLoadedRole = false;
- private bool bLoadingRoleModel = false;
- private GameObject mRoleModelGo = null;
- private bool bRoleModelDirty = false;
- public bool LoadingRoleModel
- {
- get { return bLoadingRoleModel; }
- }
- public GameObject RoleModelGo
- {
- get
- {
- return mRoleModelGo;
- }
- }
- public void LoadRole()
- {
- if (bHasLoadedRole) return;
- bLoadingRoleModel = true;
- mLuaBattleMgr.CallCS2Lua("CreateRoleView");
- }
- public void OnLoadRoleCompleted(GameObject go, bool bRefresh, bool isNew,int roleId = 1)
- {
- bLoadingRoleModel = false;
- bHasLoadedRole = true;
- mRoleModelGo = go;
- if (bRefresh && isNew && mBattle != null)
- {
- var f = mBattle.FighterMgr.GetTeamMemberById(roleId);
- if (f.Ctrl != null)
- f.Ctrl.RebindAvatarGo(go);
- mBattle.MoveToNextBattleField(false);
- f.Ctrl.Animator.Play(FighterAnimatorHash.StateRun);
- }
- //for (int i =2; i < 7; i++)
- //{
- // GameObject ngo = Instantiate<GameObject>(go);
- // var f = mBattle.FighterMgr.GetTeamMemberById(i);
- // if (f.Ctrl != null)
- // f.Ctrl.RebindAvatarGo(ngo);
- // mBattle.MoveToNextBattleField(false);
- // f.Ctrl.Animator.Play(FighterAnimatorHash.StateRun);
- //}
- }
- public void NotifyRefreshRoleView()
- {
- bRoleModelDirty = true;
- }
- public string PopBattleRecord(long timeStamp)
- {
- if (mBattleRecordList.ContainsKey(timeStamp))
- {
- string recordStr = mBattleRecordList[timeStamp];
- mBattleRecordList.Remove(timeStamp);
- return recordStr;
- }
- return null;
- }
- public void ShowSkipBattle()
- {
- if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr == null) return;
- mLuaBossBattleMgr.CallCS2Lua("ShowSkipBattle");
- }
- }
- void OnLoadBegin(CoreEvent<bool> ce)
- {
- if (mBattle == null) return;
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr == null) return;
- mLuaBattleMgr.CallCS2Lua("OnLoadBegin");
- }
- else if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr == null) return;
- mLuaBossBattleMgr.CallCS2Lua("OnLoadBegin");
- }
- else if (mBattle.IsVersusBattle)
- {
- if (mLuaVersusMgr == null) return;
- mLuaVersusMgr.CallCS2Lua("OnLoadBegin");
- }
- else if (mBattle.IsTimeBattle)
- {
- if (mLuaTimeBattleMgr == null) return;
- mLuaTimeBattleMgr.CallCS2Lua("OnLoadBegin");
- }
- }
- void OnLoadComplete(CoreEvent<bool> ce)
- {
- if (mBattle == null) return;
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr == null) return;
- mLuaBattleMgr.CallCS2Lua("OnLoadComplete");
- }
- else if (mBattle.IsVersusBattle)
- {
- if (mLuaVersusMgr == null) return;
- mLuaVersusMgr.CallCS2Lua("OnLoadComplete");
- }
- else if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr == null) return;
- mLuaBossBattleMgr.CallCS2Lua("OnLoadComplete");
- }
- else if (mBattle.IsTimeBattle)
- {
- if (mLuaTimeBattleMgr == null) return;
- mLuaTimeBattleMgr.CallCS2Lua("OnLoadComplete");
- }
- }
- void OnLoadProgress(CoreEvent<float> ce)
- {
- if (mBattle == null) return;
- if (mBattle.IsNormalBattle)
- {
- if (mLuaBattleMgr == null) return;
- mLuaBattleMgr.CallCS2Lua("OnLoadProgress", ce.Data);
- }
- else if (mBattle.IsVersusBattle)
- {
- if (mLuaVersusMgr == null) return;
- mLuaVersusMgr.CallCS2Lua("OnLoadProgress", ce.Data);
- }
- else if (mBattle.IsBossBattle)
- {
- if (mLuaBossBattleMgr == null) return;
- mLuaBossBattleMgr.CallCS2Lua("OnLoadProgress", ce.Data);
- }
- else if (mBattle.IsTimeBattle)
- {
- if (mLuaTimeBattleMgr == null) return;
- mLuaTimeBattleMgr.CallCS2Lua("OnLoadProgress", ce.Data);
- }
- }
- }
|