| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  | using System.Collections; | 
					
						
							|  |  |  |  | using System.Collections.Generic; | 
					
						
							|  |  |  |  | using UnityEngine; | 
					
						
							|  |  |  |  | using DG.Tweening; | 
					
						
							|  |  |  |  | using URandom = UnityEngine.Random; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | public class GameLogic : MonoBehaviour | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     [SerializeField] Camera mGameCam; | 
					
						
							|  |  |  |  |     [SerializeField] Vector3 mBattlePos; | 
					
						
							|  |  |  |  |     [SerializeField] Vector3 mBattleRot; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     [SerializeField] Transform mCtnStage; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     [SerializeField] Transform mTsfWinFx; | 
					
						
							|  |  |  |  |     [SerializeField] GameObject mPfbWinFx; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     [SerializeField] BlockManager mPlayerBlockMgr; | 
					
						
							|  |  |  |  |     [SerializeField] BlockManager mEnemyBlockMgr; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     [SerializeField] GroupManager mPlayerGroupMgr; | 
					
						
							|  |  |  |  |     [SerializeField] GroupManager mEnemyGroupMgr; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |     [SerializeField] GameObject[] mGuideTips; | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     private PanelMain mUIMain; | 
					
						
							|  |  |  |  |     private PanelGame mUIGame; | 
					
						
							|  |  |  |  |     private bool mIsOver; | 
					
						
							|  |  |  |  |     private TimerUnit mOverTimer; | 
					
						
							|  |  |  |  |     private bool mIsWin; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void Start() | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |         AdjustCamera(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         //debug | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         GameManager.Instance.CurrentPlayerBlockMgr = mPlayerBlockMgr; | 
					
						
							|  |  |  |  |         GameManager.Instance.CurrentEnemyBlockMgr = mEnemyBlockMgr; | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |         GameManager.Instance.PlayerGroupMgr = mPlayerGroupMgr; | 
					
						
							|  |  |  |  |         GameManager.Instance.EnemyGroupMgr = mEnemyGroupMgr; | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         GameManager.Instance.CurrentGameCam = mGameCam; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         TKGSDKManager.Instance.LogEvent(Const.AdsEvent.LevelEnter, Const.AdsKey.Level, PlayerData.Instance.CurrentLevel.ToString()); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |         int tStageID = ((PlayerData.Instance.CurrentLevel - 1) / 10) % GameConfig.Instance.SceneCount + 1; | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         Instantiate(ResourceManager.Instance.LoadRes<GameObject>(Const.Path.GetStage(tStageID)), mCtnStage); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         UIManager.Instance.OpenUI<PanelTopBar>(); | 
					
						
							|  |  |  |  |         mUIMain = UIManager.Instance.OpenUI<PanelMain>(); | 
					
						
							|  |  |  |  |         mUIMain.DelFocus = OnMainFocus; | 
					
						
							|  |  |  |  |         mUIMain.DelStart = MoveBattleCam; | 
					
						
							|  |  |  |  |         mUIMain.DelHuman = mPlayerBlockMgr.CreateBaseHumanBlock; | 
					
						
							|  |  |  |  |         mUIMain.DelMonster = mPlayerBlockMgr.CreateBaseMonsterBlock; | 
					
						
							| 
									
										
										
										
											2022-06-08 13:23:44 +00:00
										 |  |  |  |         mUIMain.DelAutoMergeAdd = mPlayerBlockMgr.CheckAutoMerge; | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         mPlayerGroupMgr.DelSoldierClear = Lose; | 
					
						
							|  |  |  |  |         mEnemyGroupMgr.DelSoldierClear = Win; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         mPlayerBlockMgr.CreateBlocksByData(PlayerData.Instance.ArmyStr); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |         GenerteLevel(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         FloorManager.Instance.SetFloor(PlayerData.Instance.CurrentFloorID); | 
					
						
							|  |  |  |  |         PetManager.Instance.SetPet(PlayerData.Instance.CurrentPetID); | 
					
						
							|  |  |  |  |         if (PlayerData.Instance.CurrentLevel % TKGSDKManager.Instance.GetConfigInt(TKGParamKey.ExtraLevelDelta.ToString()) == 0) | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |             ExtraManager.Instance.RestartAvatar(); | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         mOverTimer = TimerManager.Instance.CreateTimerUnit(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         mPlayerBlockMgr.EnableInteraction(false); | 
					
						
							|  |  |  |  |         MMOModule.Instance.StartGame(CheckGuide, PlayerData.Instance.IsMMOUser, PlayerData.Instance.Diamond, PlayerData.Instance.CurrentLevel); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void OnDestroy() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         if (mOverTimer != null) | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |             mOverTimer.Destroy(); | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |     private void AdjustCamera() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         Camera tCam = Camera.main; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         float tScreenRatio = Screen.height / (float)Screen.width; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if (tScreenRatio > 2)//39 : 18 | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |             tCam.fieldOfView = 70; | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |         else if (tScreenRatio > 1.65f)//16 : 9 | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |             tCam.fieldOfView = 60; | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |         else if (tScreenRatio > 1.55f)//16 : 10 | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |             tCam.fieldOfView = 60; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         else if (tScreenRatio > 1.45f)//3 : 2 | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             tCam.fieldOfView = 55; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         else//4 : 3 and smaller | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             tCam.fieldOfView = 55; | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |     private void CheckGuide() | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |         mPlayerBlockMgr.EnableInteraction(true); | 
					
						
							|  |  |  |  |         if (!PlayerData.Instance.CheckGuide(0)) | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |             mPlayerBlockMgr.EnableInteraction(false); | 
					
						
							|  |  |  |  |             GuideManager.Instance.StartGuide(0, new Dictionary<int, System.Action>() { | 
					
						
							|  |  |  |  |                 { 0, () => { mPlayerBlockMgr.CreateBlock(13, BlockType.Human, 1); AudioManager.Instance.PlaySound(AudioClipType.BuyUnit); PlayerData.Instance.BuyHuman(); mUIMain.RefreshButtons(); mPlayerBlockMgr.EnableInteraction(true); mPlayerBlockMgr.SetForbidden(true, new List<int>(){12, 13}); ShowGuideTip(0); } }, | 
					
						
							|  |  |  |  |                 { 1, () => { ShowGuideTip(-1); mPlayerBlockMgr.EnableInteraction(false); mPlayerBlockMgr.SetForbidden(false); } }, | 
					
						
							|  |  |  |  |                 { 2, () => { UIManager.Instance.CloseUI<PanelNewCard>(); mPlayerBlockMgr.EnableInteraction(false); } }, | 
					
						
							|  |  |  |  |                 { 3, MoveBattleCam }}); | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         //if (!PlayerData.Instance.CheckGuide(0)) | 
					
						
							|  |  |  |  |         //{ | 
					
						
							|  |  |  |  |         //    mPlayerBlockMgr.EnableInteraction(false); | 
					
						
							|  |  |  |  |         //    GuideManager.Instance.StartGuide(0, new Dictionary<int, System.Action>() { { 0, MoveBattleCam } }); | 
					
						
							|  |  |  |  |         //} | 
					
						
							|  |  |  |  |         //else if (!PlayerData.Instance.CheckGuide(1)) | 
					
						
							|  |  |  |  |         //{ | 
					
						
							|  |  |  |  |         //    mPlayerBlockMgr.EnableInteraction(false); | 
					
						
							|  |  |  |  |         //    GuideManager.Instance.StartGuide(1, new Dictionary<int, System.Action>() { | 
					
						
							|  |  |  |  |         //        { 0, () => { mPlayerBlockMgr.CreateBlock(11, BlockType.Human, 1); AudioManager.Instance.PlaySound(AudioClipType.BuyUnit); PlayerData.Instance.BuyHuman(); mUIMain.RefreshButtons(); mPlayerBlockMgr.EnableInteraction(true); mPlayerBlockMgr.SetForbidden(true, new List<int>(){2, 12}); ShowGuideTip(0); } }, | 
					
						
							|  |  |  |  |         //        { 1, () => { ShowGuideTip(-1); mPlayerBlockMgr.EnableInteraction(false); mPlayerBlockMgr.SetForbidden(false); } }, | 
					
						
							|  |  |  |  |         //        { 2, MoveBattleCam }}); | 
					
						
							|  |  |  |  |         //} | 
					
						
							|  |  |  |  |         //else if (!PlayerData.Instance.CheckGuide(2)) | 
					
						
							|  |  |  |  |         //{ | 
					
						
							|  |  |  |  |         //    mPlayerBlockMgr.EnableInteraction(false); | 
					
						
							|  |  |  |  |         //    GuideManager.Instance.StartGuide(2, new Dictionary<int, System.Action>() { | 
					
						
							|  |  |  |  |         //        { 0, () => { mPlayerBlockMgr.CreateBlock(3, BlockType.Monster, 1); AudioManager.Instance.PlaySound(AudioClipType.BuyUnit); PlayerData.Instance.BuyMonster(); mUIMain.RefreshButtons(); mPlayerBlockMgr.EnableInteraction(true); mPlayerBlockMgr.SetForbidden(true, new List<int>(){2, 3}); ShowGuideTip(1); } }, | 
					
						
							|  |  |  |  |         //        { 1, () => { ShowGuideTip(-1); mPlayerBlockMgr.SetForbidden(false);} } }); | 
					
						
							|  |  |  |  |         //} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         mOverTimer.StartTimer(ShowBanner, 1f); | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-08 13:23:44 +00:00
										 |  |  |  |     private void ShowBanner() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         TKGSDKManager.Instance.ShowBanner(2); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |     private void OnMainFocus(bool pFocus) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         mPlayerBlockMgr.EnableInteraction(pFocus); | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |         ExtraManager.Instance.EnableInteraction(pFocus); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     #region Level | 
					
						
							|  |  |  |  |     private void GenerteLevel() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         if (PlayerData.Instance.CurrentLevel <= TableLevel.Instance.Count) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             if (GameConfig.Instance.IsAutoLevel) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 string tLevelStr = PlayerData.Instance.GetAutoLevel(); | 
					
						
							|  |  |  |  |                 if (string.IsNullOrEmpty(tLevelStr)) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     CreateAutoLevel(); | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 else | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     mEnemyBlockMgr.CreateBlocksByData(tLevelStr); | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             else | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 string tOnlineLevelJson = TKGSDKManager.Instance.GetConfigStr(TKGParamKey.LevelList.ToString()); | 
					
						
							|  |  |  |  |                 LevelOnlineData tOnlineData = string.IsNullOrEmpty(tOnlineLevelJson) ? null : LevelOnlineData.JsonToData(tOnlineLevelJson); | 
					
						
							|  |  |  |  |                 if (tOnlineData != null) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     TKGSDKManager.Instance.LogEvent(TKGParamKey.LevelList.ToString() + "_" + tOnlineData.Version); | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                 string tFormation = ""; | 
					
						
							|  |  |  |  |                 if (tOnlineData != null && tOnlineData.Formations != null && PlayerData.Instance.CurrentLevel <= tOnlineData.Formations.Count) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     tFormation = tOnlineData.Formations[PlayerData.Instance.CurrentLevel - 1]; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 else if (PlayerData.Instance.CurrentLevelData != null) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     tFormation = PlayerData.Instance.CurrentLevelData.Formation; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                 if (!string.IsNullOrEmpty(tFormation)) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     mEnemyBlockMgr.CreateBlocksByData(tFormation); | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 else | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     RandomEnemy(); | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         else | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             RandomEnemy(); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if (PlayerData.Instance.CurrentLevelData != null && PlayerData.Instance.CurrentLevelData.IsBoss) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mEnemyBlockMgr.SetAsBoss(); | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-08 13:23:44 +00:00
										 |  |  |  |     private void CreateAutoLevel() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         int tMaxLv = PlayerData.Instance.CurrentLevelData.MaxLevel; | 
					
						
							|  |  |  |  |         int tMinLv = Mathf.Max(1, tMaxLv / 2); | 
					
						
							|  |  |  |  |         int tTotalUnitCount = PlayerData.Instance.CurrentLevelData.UnitNum; | 
					
						
							|  |  |  |  |         if (PlayerData.Instance.CurrentLevel >= 4 && PlayerData.Instance.CurrentLevel <= 20) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             tTotalUnitCount -= 1; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         else if (PlayerData.Instance.CurrentLevel > 20) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             tTotalUnitCount -= 2; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         List<int> tLevelList = new List<int>(); | 
					
						
							|  |  |  |  |         int tLevel = tMaxLv; | 
					
						
							|  |  |  |  |         int tCostUnitCount = 0; | 
					
						
							|  |  |  |  |         while (true) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             tCostUnitCount = (int)Mathf.Pow(2, tLevel - 1); | 
					
						
							|  |  |  |  |             if (tTotalUnitCount >= tCostUnitCount) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 tTotalUnitCount -= tCostUnitCount; | 
					
						
							|  |  |  |  |                 tLevelList.Add(tLevel); | 
					
						
							|  |  |  |  |                 //Debug.Log("Level :" + tLevel); | 
					
						
							|  |  |  |  |                 //Debug.Log("Left Unit Count :" + tTotalUnitCount); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             else | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 tLevel--; | 
					
						
							|  |  |  |  |                 if (tLevel < tMinLv) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     break; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             if (tTotalUnitCount <= 0 || tLevelList.Count >= 15) | 
					
						
							|  |  |  |  |                 break; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         BlockType tBType = BlockType.Monster; | 
					
						
							|  |  |  |  |         List<int> tNearIndexes = new List<int>() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; | 
					
						
							|  |  |  |  |         List<int> tFarIndexes = new List<int>() { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; | 
					
						
							|  |  |  |  |         int tPosIndex = 0; | 
					
						
							|  |  |  |  |         for (int i = 0; i < tLevelList.Count; i++) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             if (tBType == BlockType.Monster) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 tPosIndex = tNearIndexes[URandom.Range(0, tNearIndexes.Count)]; | 
					
						
							|  |  |  |  |                 tNearIndexes.Remove(tPosIndex); | 
					
						
							|  |  |  |  |                 if (tFarIndexes.Contains(tPosIndex)) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     tFarIndexes.Remove(tPosIndex); | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             else if(tBType == BlockType.Human) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 tPosIndex = tFarIndexes[URandom.Range(0, tFarIndexes.Count)]; | 
					
						
							|  |  |  |  |                 tFarIndexes.Remove(tPosIndex); | 
					
						
							|  |  |  |  |                 if (tNearIndexes.Contains(tPosIndex)) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     tNearIndexes.Remove(tPosIndex); | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             mEnemyBlockMgr.CreateBlock(tPosIndex, tBType, tLevelList[i]); | 
					
						
							|  |  |  |  |             tBType = tBType == BlockType.Monster ? BlockType.Human : BlockType.Monster; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         PlayerData.Instance.SaveAutoLevel(mEnemyBlockMgr.GetFormationStr()); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |     private void RandomEnemy() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         List<int> tPosIndexes = new List<int>() { 0, 1, 2, 3, 4 }; | 
					
						
							|  |  |  |  |         int tCount = URandom.Range(1, 5); | 
					
						
							|  |  |  |  |         for (int i = 0; i < tCount; i++) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             int tPosIndex = tPosIndexes[URandom.Range(0, tPosIndexes.Count)]; | 
					
						
							|  |  |  |  |             tPosIndexes.Remove(tPosIndex); | 
					
						
							| 
									
										
										
										
											2022-06-08 13:23:44 +00:00
										 |  |  |  |             mEnemyBlockMgr.CreateBlock(tPosIndex, BlockType.Monster, URandom.Range(6, 11)); | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  |         tPosIndexes = new List<int>() { 5, 6, 7, 8, 9 }; | 
					
						
							|  |  |  |  |         tCount = URandom.Range(1, 5); | 
					
						
							|  |  |  |  |         for (int i = 0; i < tCount; i++) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             int tPosIndex = tPosIndexes[URandom.Range(0, tPosIndexes.Count)]; | 
					
						
							|  |  |  |  |             tPosIndexes.Remove(tPosIndex); | 
					
						
							| 
									
										
										
										
											2022-06-08 13:23:44 +00:00
										 |  |  |  |             mEnemyBlockMgr.CreateBlock(tPosIndex, (BlockType)URandom.Range(0, 2), URandom.Range(7, 10)); | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  |         tPosIndexes = new List<int>() { 10, 11, 12, 13, 14 }; | 
					
						
							|  |  |  |  |         tCount = URandom.Range(1, 5); | 
					
						
							|  |  |  |  |         for (int i = 0; i < tCount; i++) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             int tPosIndex = tPosIndexes[URandom.Range(0, tPosIndexes.Count)]; | 
					
						
							|  |  |  |  |             tPosIndexes.Remove(tPosIndex); | 
					
						
							| 
									
										
										
										
											2022-06-08 13:23:44 +00:00
										 |  |  |  |             mEnemyBlockMgr.CreateBlock(tPosIndex, BlockType.Human, URandom.Range(7, 11)); | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |     #endregion | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void MoveBattleCam() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         if (string.IsNullOrEmpty(PlayerData.Instance.ArmyStr)) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             UIUtils.ShowTips(LanguageConfig.Instance.GetText("ArmyEmpty")); | 
					
						
							|  |  |  |  |             return; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         mUIMain.Close(); | 
					
						
							|  |  |  |  |         VibrateManager.Instance.Vibrate(VibrateType.Medium); | 
					
						
							|  |  |  |  |         mPlayerBlockMgr.EnableInteraction(false); | 
					
						
							|  |  |  |  |         mPlayerBlockMgr.ShowFloor(false); | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |         FloorManager.Instance.FloorDisappear(); | 
					
						
							|  |  |  |  |         ExtraManager.Instance.StopMoving(); | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         Transform tCamTrans = mGameCam.transform; | 
					
						
							|  |  |  |  |         tCamTrans.DOMove(mBattlePos, 1).SetEase(Ease.OutCubic); | 
					
						
							|  |  |  |  |         tCamTrans.DORotate(mBattleRot, 1).SetEase(Ease.OutCubic); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         GameStart(); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void GameStart() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         TKGSDKManager.Instance.NotifyGameStart(PlayerData.Instance.CurrentLevel); | 
					
						
							|  |  |  |  |         mUIGame = UIManager.Instance.OpenUI<PanelGame>(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |         PetManager.Instance.Courage(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         List<SoldierUnit> tSoldiers = mPlayerBlockMgr.GetAllSoldier(); | 
					
						
							|  |  |  |  |         for (int i = 0; i < tSoldiers.Count; i++) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mPlayerGroupMgr.AddSoldier(tSoldiers[i], mEnemyGroupMgr); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         mPlayerGroupMgr.ActiveAllSoldier(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         tSoldiers = mEnemyBlockMgr.GetAllSoldier(); | 
					
						
							|  |  |  |  |         for (int i = 0; i < tSoldiers.Count; i++) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mEnemyGroupMgr.AddSoldier(tSoldiers[i], mPlayerGroupMgr); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         mEnemyGroupMgr.ActiveAllSoldier(); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void Win() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         mIsWin = true;//win is overridable | 
					
						
							|  |  |  |  |         if (mIsOver) | 
					
						
							|  |  |  |  |             return; | 
					
						
							|  |  |  |  |         mIsOver = true; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         mUIGame.Close(); | 
					
						
							|  |  |  |  |         mOverTimer.StartTimer(GameOver, 0.5f); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void Lose() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         if (mIsOver) | 
					
						
							|  |  |  |  |             return; | 
					
						
							|  |  |  |  |         mIsOver = true; | 
					
						
							|  |  |  |  |         mIsWin = false; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         mUIGame.Close(); | 
					
						
							|  |  |  |  |         mOverTimer.StartTimer(GameOver, 0.5f); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void GameOver() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         TKGSDKManager.Instance.NotifyGameEnd(PlayerData.Instance.CurrentLevel, mIsWin); | 
					
						
							|  |  |  |  |         if (mIsWin) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             Instantiate(mPfbWinFx, mTsfWinFx); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |             PetManager.Instance.Win(); | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |             mPlayerGroupMgr.Win(); | 
					
						
							|  |  |  |  |             AudioManager.Instance.PlaySound(AudioClipType.GameWin); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         else | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mEnemyGroupMgr.Win(); | 
					
						
							|  |  |  |  |             AudioManager.Instance.PlaySound(AudioClipType.GameLose); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |          | 
					
						
							|  |  |  |  |         mOverTimer.StartTimer(() => | 
					
						
							|  |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-06-21 04:29:58 +00:00
										 |  |  |  |             AdsUtils.PlayInterstitial(mIsWin ? Const.AdsValue.GameSuccess : Const.AdsValue.GameFailure, mIsWin, () => | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |             { | 
					
						
							| 
									
										
										
										
											2022-06-21 04:29:58 +00:00
										 |  |  |  |                 PanelResult tUIResult = UIManager.Instance.OpenUI<PanelResult>(); | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |                 tUIResult.InitResult(mIsWin, mEnemyGroupMgr.TotalDamage, TKGSDKManager.Instance.GetConfigBool(TKGParamKey.NativeSwitch.ToString()) && TKGSDKManager.Instance.IsNativeReady()); | 
					
						
							| 
									
										
										
										
											2022-06-21 04:29:58 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |                 if (mIsWin) | 
					
						
							|  |  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |                     MMOModule.Instance.PassLevel(); | 
					
						
							| 
									
										
										
										
											2022-06-21 04:29:58 +00:00
										 |  |  |  |                     PlayerData.Instance.CurrentLevel++; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         }, 1.5f); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |     private void ShowGuideTip(int pIndex) | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |         for (int i = 0; i < mGuideTips.Length; i++) | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |             mGuideTips[i].SetActive(i == pIndex); | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } |