318 lines
		
	
	
		
			14 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
			
		
		
	
	
			318 lines
		
	
	
		
			14 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
| /*
 | |
| 文件名:AssetManager.nut
 | |
| 路径:User/Asset/AssetManager.nut
 | |
| 创建日期:2024-11-24	08:44
 | |
| 文件用途: 资源管理器
 | |
| */
 | |
| class _AssetManager_ {
 | |
| 
 | |
|     //角色列表
 | |
|     CharacterList = null;
 | |
|     //角色信息表
 | |
|     CharacterInfoList = null;
 | |
|     //地图列表
 | |
|     MapList = null;
 | |
|     //城镇列表
 | |
|     TownList = null;
 | |
|     //装备列表
 | |
|     EquipmentList = null;
 | |
|     //NPC列表
 | |
|     NpcList = null;
 | |
| 
 | |
|     function InitMapList() {
 | |
|         MapList = ScriptData.GetFileData("map/map.lst", function(DataTable, Data) {
 | |
|             while (!Data.Eof()) {
 | |
|                 local Key = Data.Get();
 | |
|                 DataTable.rawset(Key, Data.Get());
 | |
|             }
 | |
|             if (_DEBUG_) print("加载地图List完成, 共" + DataTable.len() + "个");
 | |
|         });
 | |
|     }
 | |
| 
 | |
|     function InitCharacter() {
 | |
|         CharacterList = ScriptData.GetFileData("character/character.lst", function(DataTable, Data) {
 | |
|             local dirpath = DataTable.filepath.slice(0, DataTable.filepath.lastfind("/") + 1);
 | |
|             while (!Data.Eof()) {
 | |
|                 local Index = Data.Get();
 | |
|                 local Path = Data.Get();
 | |
|                 DataTable.rawset(Index, dirpath + Path.tolower());
 | |
|             }
 | |
|             if (_DEBUG_) print("加载角色List完成, 共" + DataTable.len() + "个");
 | |
|         });
 | |
|         CharacterInfoList = [];
 | |
|         foreach(Index, Path in CharacterList) {
 | |
|             if (Index == "filepath") continue;
 | |
|             local Info = ScriptData.GetFileData(Path, function(DataTable, Data) {
 | |
|                 local dirpath = DataTable.filepath.slice(0, DataTable.filepath.lastfind("/") + 1);
 | |
|                 while (!Data.Eof()) {
 | |
|                     local Key = Data.Get();
 | |
|                     if (Key == "[job]") {
 | |
|                         DataTable.job <- Data.Get().slice(1, -1);
 | |
|                     } else if (Key == "[growtype name]") {
 | |
|                         DataTable.growtype <- array(6, {});
 | |
|                         for (local i = 0; i< 5; i++) {
 | |
|                             local name = Data.Get();
 | |
|                             DataTable.growtype[i].name <- name;
 | |
|                         }
 | |
|                     }
 | |
|                     //默认时装
 | |
|                     else if (Key == "[default avatar]") {
 | |
|                         DataTable.default_avatar <- [];
 | |
|                         while (true) {
 | |
|                             local Ret = Data.Get();
 | |
|                             if (Ret == "[/default avatar]") break;
 | |
|                             DataTable.default_avatar.append(Ret);
 | |
|                         }
 | |
|                     }
 | |
|                     //基础属性
 | |
|                     else if (Key == "[HP MAX]]" || Key == "[MP MAX]]" || Key == "[physical attack]]" || Key == "[physical defense]]" || Key == "[magical attack]]" || Key == "[magical defense]]" || Key == "[inventory limit]]" || Key == "[MP regen speed]]" || Key == "[move speed]]" || Key == "[attack speed]]" || Key == "[cast speed]]" || Key == "[hit recovery]]" || Key == "[jump power]]" || Key == "[weight]]" || Key == "[jump speed]]") {
 | |
|                         local RealKey = Key.slice(1, Key.len() - 1);
 | |
|                         DataTable[RealKey] <- Data.Get().tofloat();
 | |
| 
 | |
|                     }
 | |
|                     //基础Ani
 | |
|                     else if (Key == "[waiting motion]" || Key == "[move motion]" || Key == "[sit motion]" || Key == "[damage motion 1]" || Key == "[damage motion 2]" || Key == "[down motion]" || Key == "[overturn motion]" || Key == "[jump motion]" || Key == "[jumpattack motion]" || Key == "[rest motion]" || Key == "[throw motion 1-1]" || Key == "[throw motion 1-2]" || Key == "[throw motion 2-1]" || Key == "[throw motion 2-2]" || Key == "[throw motion 3-1]" || Key == "[throw motion 3-2]" || Key == "[throw motion 4-1]" || Key == "[throw motion 4-2]" || Key == "[dash motion]" || Key == "[dashattack motion]" || Key == "[getitem motion]" || Key == "[buff motion]" || Key == "[simple rest motion]" || Key == "[simple move motion]" || Key == "[back motion]") {
 | |
|                         local RealKey = Key.slice(1, Key.len() - 1);
 | |
|                         DataTable[RealKey] <- dirpath + Data.Get().tolower();
 | |
|                     }
 | |
|                     //普攻Ani
 | |
|                     else if (Key == "[attack motion]") {
 | |
|                         DataTable.attack_motion <- [];
 | |
|                         while (true) {
 | |
|                             local Ret = Data.Get();
 | |
|                             if (Ret == "[/attack motion]") break;
 | |
|                             DataTable.attack_motion.append(dirpath + Ret.tolower());
 | |
|                         }
 | |
|                     }
 | |
|                     //进阶Ani
 | |
|                     else if (Key == "[etc motion]") {
 | |
|                         DataTable.etc_motion <- [];
 | |
|                         while (true) {
 | |
|                             local Ret = Data.Get();
 | |
|                             if (Ret == "[/etc motion]") break;
 | |
|                             DataTable.etc_motion.append(dirpath + Ret.tolower());
 | |
|                         }
 | |
|                     }
 | |
|                     //基础Atk
 | |
|                     else if (Key == "[jumpattack info]" || Key == "[dashattack info]") {
 | |
|                         local RealKey = Key.slice(1, Key.len() - 1);
 | |
|                         DataTable[RealKey] <- (dirpath + Data.Get().tolower());
 | |
|                     }
 | |
|                     //普攻Atk
 | |
|                     else if (Key == "[attack info]") {
 | |
|                         DataTable.attack_info <- [];
 | |
|                         while (true) {
 | |
|                             local Ret = Data.Get();
 | |
|                             if (Ret == "[/attack info]") break;
 | |
|                             DataTable.attack_info.append(dirpath + Ret.tolower());
 | |
|                         }
 | |
|                     }
 | |
|                     //进阶Atk
 | |
|                     else if (Key == "[etc attack info]") {
 | |
|                         DataTable.etc_attack_info <- [];
 | |
|                         while (true) {
 | |
|                             local Ret = Data.Get();
 | |
|                             if (Ret == "[/etc attack info]") break;
 | |
|                             DataTable.etc_attack_info.append(dirpath + Ret.tolower());
 | |
|                         }
 | |
|                     }
 | |
|                 }
 | |
|                 // print(DataTable);
 | |
|                 if (_DEBUG_) print("初始化角色" + DataTable.job);
 | |
|             });
 | |
|             CharacterInfoList.push(Info);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     function InitEquipmentList() {
 | |
|         EquipmentList = ScriptData.GetFileData("equipment/equipment.lst", function(DataTable, Data) {
 | |
|             while (!Data.Eof()) {
 | |
|                 local Key = Data.Get();
 | |
|                 //注册装备列表 路径写入 数据未读取
 | |
|                 DataTable.rawset(Key, {
 | |
|                     Path = Data.Get(),
 | |
|                     Data = null
 | |
|                 });
 | |
|             }
 | |
|             if (_DEBUG_) print("加载装备List完成, 共" + DataTable.len() + "个");
 | |
|         });
 | |
|     }
 | |
| 
 | |
|     function InitNpcList() {
 | |
|         NpcList = ScriptData.GetFileData("npc/npc.lst", function(DataTable, Data) {
 | |
|             while (!Data.Eof()) {
 | |
|                 local Key = Data.Get();
 | |
|                 //注册NPC列表 路径写入 数据未读取
 | |
|                 DataTable.rawset(Key, {
 | |
|                     Path = Data.Get(),
 | |
|                     Data = null
 | |
|                 });
 | |
|             }
 | |
|             if (_DEBUG_) print("加载NPCList完成, 共" + DataTable.len() + "个");
 | |
|         });
 | |
|     }
 | |
| 
 | |
|     function InitTownList() {
 | |
|         TownList = ScriptData.GetFileData("town/town.lst", function(DataTable, Data) {
 | |
|             while (!Data.Eof()) {
 | |
|                 local Key = Data.Get();
 | |
|                 //注册城镇列表 路径写入 数据未读取
 | |
|                 DataTable.rawset(Key, {
 | |
|                     Path = Data.Get(),
 | |
|                     Data = null
 | |
|                 });
 | |
|             }
 | |
|             if (_DEBUG_) print("加载城镇List完成, 共" + DataTable.len() + "个");
 | |
|         });
 | |
|     }
 | |
| 
 | |
|     constructor() {
 | |
|         //初始化城镇列表
 | |
|         InitTownList();
 | |
|         //初始化地图列表
 | |
|         InitMapList();
 | |
|         //初始化角色
 | |
|         InitCharacter();
 | |
|         //初始化装备列表
 | |
|         InitEquipmentList();
 | |
|         //初始化NPC列表
 | |
|         InitNpcList();
 | |
| 
 | |
| 
 | |
|         getroottable().AssetManager <- this;
 | |
|     }
 | |
| 
 | |
| 
 | |
|     //Public::
 | |
| 
 | |
|     //获取装备信息
 | |
|     function GetEquipment(Idx) {
 | |
|         //如果没有这件装备则返回
 | |
|         if (!(EquipmentList.rawin(Idx))) return;
 | |
|         //如果装备数据已经读取过存在了则直接返回
 | |
|         if (EquipmentList[Idx].Data) return EquipmentList[Idx].Data;
 | |
|         local Path = EquipmentList[Idx].Path;
 | |
|         local m_data = ScriptData.GetFileData("equipment/" + Path, function(DataTable, Data) {
 | |
|             DataTable.DirPath <- DataTable.filepath.slice(0, DataTable.filepath.lastfind("/") + 1);
 | |
|             while (!Data.Eof()) {
 | |
|                 local Pack = Data.Get();
 | |
|                 //名称 grade 套装Id
 | |
|                 if (Pack == "[name]" || Pack == "[part set index]" || Pack == "[grade]" || Pack == "[minimum level]") {
 | |
|                     local RealKey = Pack.slice(1, -1);
 | |
|                     DataTable[RealKey] <- Data.Get();
 | |
|                 }
 | |
|                 //适用角色
 | |
|                 else if (Pack == "[usable job]") {
 | |
|                     DataTable.usable_job <- [];
 | |
|                     while (true) {
 | |
|                         local Ret = Data.Get();
 | |
|                         if (Ret == "[/usable job]") break;
 | |
|                         DataTable.usable_job.append(Ret.slice(1, -1).tolower());
 | |
|                     }
 | |
|                 }
 | |
|                 //图标
 | |
|                 else if (Pack == "[icon]") {
 | |
|                     DataTable.icon <- {};
 | |
|                     local Ret = Data.Get();
 | |
|                     DataTable.icon.path <- Ret.tolower();
 | |
|                     Ret = Data.Get();
 | |
|                     DataTable.icon.index <- Ret.tointeger();
 | |
|                 }
 | |
|                 //装备类型
 | |
|                 else if (Pack == "[equipment type]") {
 | |
|                     DataTable.type <- {};
 | |
|                     local Ret = Data.Get();
 | |
|                     DataTable.type.path <- Ret.tolower().slice(1, -1);
 | |
|                     Ret = Data.Get();
 | |
|                     DataTable.type.index <- Ret.tointeger();
 | |
|                 }
 | |
|                 //光环效果
 | |
|                 else if (Pack == "[aurora graphic effects]") {
 | |
|                     DataTable.aurora_effects <- [];
 | |
|                     local Count = Data.Get();
 | |
|                     for (local i = 0; i< Count; i++) {
 | |
|                         local T = {
 | |
|                             type = Data.Get(),
 | |
|                             path = Data.Get().tolower()
 | |
|                         }
 | |
|                         DataTable.aurora_effects.push(T);
 | |
|                     }
 | |
|                 }
 | |
|                 //Ani
 | |
|                 else if (Pack == "[animation job]") {
 | |
|                     local Job = Data.Get().slice(1, -1);
 | |
|                     if (!(DataTable.rawin("Ani"))) DataTable["Ani"] <- {};
 | |
|                     DataTable["Ani"]["Ani_" + Job] <- {};
 | |
|                     Data.Get();
 | |
| 
 | |
|                     local Index1 = Data.Get();
 | |
|                     local Index2 = Data.Get();
 | |
|                     DataTable["Ani"]["Ani_" + Job].variation <- [Index1, Index2];
 | |
|                     DataTable["Ani"]["Ani_" + Job].layer_variation <- [];
 | |
| 
 | |
|                     while (true) {
 | |
|                         local Ret = Data.Get();
 | |
|                         if (Ret == "[animation job]" || (endswith(Ret, "]") && Ret != "[equipment ani script]" && Ret != "[layer variation]")) {
 | |
|                             Data.Pos--;
 | |
|                             break;
 | |
|                         } else if (Ret == "[layer variation]") {
 | |
|                             local InfoBuf = {};
 | |
|                             InfoBuf.Zorder <- Data.Get();
 | |
|                             InfoBuf.Path <- Data.Get();
 | |
|                             DataTable["Ani"]["Ani_" + Job].layer_variation.append(InfoBuf);
 | |
|                         }
 | |
|                     }
 | |
|                 }
 | |
|             }
 | |
|         });
 | |
|         EquipmentList[Idx].Data = m_data;
 | |
|         return m_data;
 | |
|     }
 | |
| 
 | |
| 
 | |
|     //Public::
 | |
| 
 | |
|     //获取NPC信息
 | |
|     function GetNpc(Idx) {
 | |
|         //如果没有这个NPC则返回
 | |
|         if (!(NpcList.rawin(Idx))) return;
 | |
|         //如果NPC数据已经读取过存在了则直接返回
 | |
|         if (NpcList[Idx].Data) return NpcList[Idx].Data;
 | |
|         local Path = NpcList[Idx].Path;
 | |
|         local m_data = ScriptData.GetFileData("npc/" + Path, function(DataTable, Data) {
 | |
|             DataTable.DirPath <- DataTable.filepath.slice(0, DataTable.filepath.lastfind("/") + 1);
 | |
|             while (!Data.Eof()) {
 | |
|                 local Pack = Data.Get();
 | |
|                 //各种头像
 | |
|                 if (Pack == "[small face]" || Pack == "[big face]" || Pack == "[popup face]") {
 | |
|                     local RealKey = Pack.slice(1, Pack.find(" face")) + "_face";
 | |
|                     DataTable[RealKey] <- {
 | |
|                         img = Data.Get().tolower(),
 | |
|                         idx = Data.Get()
 | |
|                     }
 | |
|                 } else if (Pack == "[field animation]") {
 | |
|                     DataTable.field_animation <- DataTable.DirPath + Data.Get().tolower();
 | |
|                 } else if (Pack == "[field wav]") {
 | |
|                     DataTable.field_wav <- Data.Get();
 | |
|                 } else if (Pack == "[popup wav]") {
 | |
|                     DataTable.popup_wav <- [Data.Get(), Data.Get()];
 | |
|                 } else if (Pack == "[name]") {
 | |
|                     DataTable.name <- Data.Get();
 | |
|                 } else if (Pack == "[field name]") {
 | |
|                     DataTable.field_name <- Data.Get();
 | |
|                 }
 | |
|                 //功能
 | |
|                 else if (Pack == "[role]") {
 | |
|                     DataTable.role <- {};
 | |
|                     while (true) {
 | |
|                         local Ret = Data.Get();
 | |
|                         if (Ret == "[/role]") break;
 | |
|                         DataTable.role.rawset(Ret.slice(1, -1).tolower(), Data.Get());
 | |
|                     }
 | |
|                 }
 | |
|             }
 | |
|         });
 | |
|         NpcList[Idx].Data = m_data;
 | |
|         return m_data;
 | |
|     }
 | |
| } |