| 
									
										
										
										
											2024-12-25 11:36:05 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 文件名:TownObject.nut | 
					
						
							|  |  |  | 路径:User/Object/Map/TownObject.nut | 
					
						
							|  |  |  | 创建日期:2024-12-24	14:49 | 
					
						
							|  |  |  | 文件用途:城镇对象 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | if (!getroottable().rawin("GlobalTownManager")) { | 
					
						
							|  |  |  |     GlobalTownManager <- {}; | 
					
						
							|  |  |  |     GlobalTownManager.TownList <- {}; | 
					
						
							| 
									
										
										
										
											2025-01-05 00:48:35 +08:00
										 |  |  |     //全局当前所在城镇地图 | 
					
						
							|  |  |  |     GlobalTownManager.CurrentMap <- null; | 
					
						
							| 
									
										
										
										
											2024-12-25 11:36:05 +08:00
										 |  |  | } | 
					
						
							|  |  |  | class Town { | 
					
						
							|  |  |  |     //城镇编号 | 
					
						
							|  |  |  |     TownID = 0; | 
					
						
							|  |  |  |     //数据 | 
					
						
							|  |  |  |     t_data = null; | 
					
						
							|  |  |  |     //地图管理器 | 
					
						
							|  |  |  |     map = null; | 
					
						
							|  |  |  |     //赛丽亚房间编号 | 
					
						
							|  |  |  |     SariaRoomID = 0; | 
					
						
							|  |  |  |     //赛利亚房间进入时的坐标 | 
					
						
							|  |  |  |     SariaRoomPos = null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //初始化城镇数据 | 
					
						
							|  |  |  |     function InitData(Path) { | 
					
						
							|  |  |  |         Path = "town/" + Path; | 
					
						
							|  |  |  |         t_data = ScriptData.GetFileData(Path, function(DataTable, Data) { | 
					
						
							|  |  |  |             //在这里添加一些初始化的默认值 | 
					
						
							|  |  |  |             DataTable.area <- {}; | 
					
						
							|  |  |  |             while (!Data.Eof()) { | 
					
						
							|  |  |  |                 local str = Data.Get(); | 
					
						
							|  |  |  |                 //进入城镇时的标题动画 | 
					
						
							|  |  |  |                 if (str == "[entering title]") { | 
					
						
							|  |  |  |                     DataTable.entering_title <- (Data.Get()); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 //进入城镇时的过场标题图像 | 
					
						
							|  |  |  |                 else if (str == "[cutscene image]") { | 
					
						
							|  |  |  |                     DataTable.cutscene_image <- {}; | 
					
						
							|  |  |  |                     DataTable.cutscene_image.path <- Data.Get().tolower(); | 
					
						
							|  |  |  |                     DataTable.cutscene_image.idx <- Data.Get(); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 //进入城镇的前置副本 | 
					
						
							|  |  |  |                 else if (str == "[dungeon what must be cleared]") { | 
					
						
							|  |  |  |                     DataTable.dungeon_what_must_be_cleared <- Data.Get(); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 //城镇区域 | 
					
						
							|  |  |  |                 else if (str == "[area]") { | 
					
						
							|  |  |  |                     local DataT = {}; | 
					
						
							|  |  |  |                     local MapId = Data.Get(); | 
					
						
							|  |  |  |                     DataT.path <- Data.Get().tolower(); | 
					
						
							|  |  |  |                     DataT.type <- Data.Get(); | 
					
						
							|  |  |  |                     //赛利亚房间 | 
					
						
							|  |  |  |                     if (DataT.type == "[gate]") { | 
					
						
							|  |  |  |                         SariaRoomID = MapId; | 
					
						
							|  |  |  |                         SariaRoomPos = { | 
					
						
							|  |  |  |                             x = Data.Get(), | 
					
						
							|  |  |  |                             y = Data.Get(), | 
					
						
							|  |  |  |                             z = 0 | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                     } else if (DataT.type == "[dungeon gate]") { | 
					
						
							|  |  |  |                         DataT.dungeon_gate <- Data.Get(); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     DataTable.area[MapId] <- DataT; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 //城镇名称 | 
					
						
							|  |  |  |                 else if (str == "[name]") { | 
					
						
							|  |  |  |                     DataTable.name <- (Data.Get()); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 //城镇可进入最低等级 | 
					
						
							|  |  |  |                 else if (str == "[limit level]") { | 
					
						
							|  |  |  |                     DataTable.limit_level <- Data.Get(); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }.bindenv(this)); | 
					
						
							|  |  |  |         t_data.path <- Path; | 
					
						
							|  |  |  |         t_data.dirpath <- Path.slice(0, Path.lastfind("/") + 1); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //构造地图 | 
					
						
							|  |  |  |     function InitMap() { | 
					
						
							|  |  |  |         map = {}; | 
					
						
							|  |  |  |         foreach(pos, info in t_data.area) { | 
					
						
							|  |  |  |             local MapObj = Map("map/" + info.path); | 
					
						
							|  |  |  |             MapObj.m_town = TownID; | 
					
						
							|  |  |  |             MapObj.m_mapId = pos; | 
					
						
							|  |  |  |             map[pos] <- MapObj; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //添加角色对象 (注意 这里是第一次上线 或者是使用瞬间移动药剂走的逻辑 因为会默认在赛丽亚房间) | 
					
						
							|  |  |  |     function AddObject(obj, IsPlayer = false) { | 
					
						
							|  |  |  |         //获取当前场景 | 
					
						
							|  |  |  |         local Stage = sq_GetCurrentStage(); | 
					
						
							| 
									
										
										
										
											2025-01-05 00:48:35 +08:00
										 |  |  |         if (GlobalTownManager.CurrentMap) { | 
					
						
							|  |  |  |             Stage.Removechild(GlobalTownManager.CurrentMap); | 
					
						
							| 
									
										
										
										
											2024-12-25 11:36:05 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |         local SariaRoomMap = map[SariaRoomID]; | 
					
						
							|  |  |  |         Stage.Addchild(SariaRoomMap); | 
					
						
							|  |  |  |         //添加全局 | 
					
						
							| 
									
										
										
										
											2025-01-05 00:48:35 +08:00
										 |  |  |         GlobalTownManager.CurrentMap = SariaRoomMap.weakref(); | 
					
						
							| 
									
										
										
										
											2024-12-25 11:36:05 +08:00
										 |  |  |         SariaRoomMap.AddObject(obj, IsPlayer); | 
					
						
							|  |  |  |         obj.SetPosition(SariaRoomPos); | 
					
						
							|  |  |  |         obj.SetAnimation("RestAni"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     constructor(Index) { | 
					
						
							|  |  |  |         TownID = Index; | 
					
						
							|  |  |  |         local TownPath = AssetManager.TownList[Index].Path; | 
					
						
							|  |  |  |         //初始化数据 | 
					
						
							|  |  |  |         InitData(TownPath); | 
					
						
							|  |  |  |         //构造地图 | 
					
						
							|  |  |  |         InitMap(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //加入全局 | 
					
						
							|  |  |  |         GlobalTownManager.TownList[Index] <- this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |