/* 文件名:TreasureGoblin.nut 路径:Project/TreasureGoblin/TreasureGoblin.nut 创建日期:2025-08-06 09:34 文件用途:TreasureGoblin */ class TreasureGoblinC extends LenheartNewUI_Windows { //调试模式 // DeBugMode = true; //不是窗口 NoWindow = true; //是否可见 Visible = false; BaseImg = Rindro_Image("interface2/rindro_reward.img"); MainImg = Rindro_Image("treasuregoblin/main.img"); //窗口名称 WindowTitle = "普通宝藏哥布林的宝箱"; //关闭按钮 CloseButton = null; //搜索时间Flag SearchTimeFlag = 0; //搜索时间品级对应表 SearchTimeGradeTable = [1500, 1500, 2000, 2500, 3000, 3500, 3500, 3500, 3500, 3500, 3500]; //奖励包 RewardPackage = null; //动画队列 AniQueue = null; //哥布林配置表 ID -> 名字 GoldGoblinConfig = null; //当前哥布林ID CurrentGoblinId = 690000226; constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) { Childrens = []; AniQueue = QuestQueue(); //注册控件 RegisterWidget(); //初始化哥布林配置 InitGoldGoblinConfig(); LenheartNewUI_Windows.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH); local RewList = [3037, 3038, 3039, 26058]; // RewardPackage = []; // for (local i = 0; i< sq_getRandom(5, 8); i++) { // local T = {}; // T.ItemId <- RewList[sq_getRandom(0, RewList.len() - 1)]; // T.ItemCount <- sq_getRandom(1, 5); // T.IsSearch <- false; //是否已经搜索 // // T.Grade <- L_sq_RA(L_sq_GetItem(T.ItemId) + 0xF4); //到时候品级由服务端决定下发 // // T.Grade <- L_sq_RA(L_sq_GetItem(T.ItemId) + 0xF4); // T.Grade <- 4; // RewardPackage.append(T); // } // Visible = true; // SetCurrentGoblinId(1); // CloseButton.Visible = false; Pack_Control.rawset(21014002, function (Chunk) { local Jso = Json.Decode(Chunk); RewardPackage = Jso.RewardPackage; foreach (obj in RewardPackage) { obj.IsSearch<- false; } Visible = true; CloseButton.Visible = false; SetCurrentGoblinId(Jso.BoxId); }.bindenv(this)); } function RegisterWidget() { //关闭按钮 CloseButton = LenheartNewUI_BaseButton(303, 6, 11, 12, "interface/lenheartwindowcommon.img", 276); CloseButton.OnClick = function() { this.Visible = false; }.bindenv(this); Childrens.append(CloseButton); } //绘制主界面 function DrawMain(obj) { //绘制标题 DrawWindowTitle(318); //绘制标题名 L_sq_DrawCode(WindowTitle, X + 158 - LenheartTextClass.GetStringLength(WindowTitle) / 2, Y + 7, sq_RGBA(230, 200, 155, 255), 0, 1); //绘制窗口 DrawNineBox(X, Y + 23, 316, 317, "interface/lenheartwindowcommon.img", 213); //背景框 //绘制内嵌窗口 DrawNineBox(X + 8, Y + 32, 299, 299, "interface/lenheartwindowcommon.img", 204); //背景框 //绘制分割线 MainImg.DrawExPng(0, X + 10, Y + 34, 0, sq_RGBA(127, 132, 142, 250), 1.0, 1.0); if (RewardPackage) { foreach(Index, Info in RewardPackage) { local XPos = X + 24 + ((Index % 6) * 47); local YPos = Y + ((Index / 6).tointeger() * 47) + 46; if (Info.IsSearch) { // BaseImg.DrawPng(Info.Grade, XPos, YPos); DrawItemBase(XPos + 3, YPos + 3, Info.ItemId, Info.ItemCount); } else { MainImg.DrawPng(1, XPos + 9, YPos + 9); } } //绘制无道具的遮挡槽 for (local i = 0 ; i< 36; i++) { if (i >= RewardPackage.len()) { MainImg.DrawPng(2, X + 26 + ((i % 6) * 47), Y + ((i / 6).tointeger() * 47) + 48); } } local AllSearchFinish = true; foreach(Index, Info in RewardPackage) { local XPos = 24 + ((Index % 6) * 47); local YPos =((Index / 6).tointeger() * 47) + 46; //如果是没有搜索状态 if (!Info.IsSearch) { AllSearchFinish = false; //还没有开始计时 if (!Info.rawin("SeachTimer")) { Info.SeachTimer <- 0; } if (Duration< 100) Info.SeachTimer += Duration; if (Info.SeachTimer< SearchTimeGradeTable[Info.Grade]) { local T = GetClockwiseCirclePoint(Info.SeachTimer / 1300.0, 0, 0, 6); Rindro_Image_GlobalMap["lenheartui"].DrawPng(159, X + XPos + 12 + T.x, Y + YPos + 12 + T.y); } else { Info.IsSearch = true; local SoundGrade = "ITEM_PICK"; if (Info.Grade == 2 || Info.Grade == 3) SoundGrade = "GoblinBox2"; if (Info.Grade >= 4) SoundGrade = "GoblinBox1"; R_Utils.PlaySound(SoundGrade); SendPackEx({ op = 21014003 }) AniQueue.AddQuest("搜索完成动画" + Info.Grade, function(Name, Time, Grade, XPos, YPos) { local AniPath = "common/item_effect/custom_3option.ani"; if (Grade == 2 || Grade == 3) AniPath = "common/item_effect/custom_4option.ani"; if (Grade >= 4) AniPath = "common/item_effect/custom_honor_4option.ani"; local Ani = DrawAniEx(X + XPos, Y + YPos, AniPath); if (sq_GetAnimationFrameIndex(Ani) == 14) { sq_Rewind(Ani); AniQueue.RemoveQuest(Name); } }.bindenv(this), Info.Grade, XPos + 1, YPos + 1); } break; } } if (AllSearchFinish) { CloseButton.Visible = true; } } } function Show(obj) { DrawMain(obj); AniQueue.Run(); LenheartNewUI_Windows.Show(obj); } //逻辑入口 function Proc(obj) { LenheartNewUI_Windows.SyncPos(X, Y); IsFocus = true; } function GetClockwiseCirclePoint(dt, centerX, centerY, radius) { // 将dt映射到角度(0到2π弧度),并反转方向实现顺时针 local angle = 2 * 3.1415926535 * (1.0 - dt); // 计算相对圆心的偏移量 local offsetX = radius * cos(angle); local offsetY = radius * sin(angle); // 返回包含坐标的表 return { x = centerX + offsetX, y = centerY + offsetY }; } //读取哥布林配置 function InitGoldGoblinConfig() { GoldGoblinConfig = {}; Rindro_Script.GetFileData("etc/rindro/goldgoblin/goldgoblin.lst", function(ConfigTable, Data) { while (!Data.Eof()) { local Index = Data.Get(); local Path = "etc/" + Data.Get(); local GoblinInfo = Rindro_Script.GetFileData(Path, function(InfoTable, InfoData) { while (!InfoData.Eof()) { local Fragment = InfoData.Get(); if (Fragment == "[name]") { InfoTable.Name <- Sq_ConvertWideChar(InfoData.Get(), "big5"); } else if (Fragment == "[trigger]") { InfoTable.TriggerId <- InfoData.Get(); } } }.bindenv(this)); if (GoblinInfo.rawin("TriggerId") && GoblinInfo.rawin("Name")) { GoldGoblinConfig[GoblinInfo.TriggerId] <- GoblinInfo.Name; } } }.bindenv(this)); } //根据ID获取哥布林名字 function GetGoblinNameById(goblinId) { if (GoldGoblinConfig && GoldGoblinConfig.rawin(goblinId)) { return GoldGoblinConfig[goblinId]; } return "宝藏哥布林的宝箱"; } //设置当前哥布林ID并更新窗口标题 function SetCurrentGoblinId(goblinId) { CurrentGoblinId = goblinId; WindowTitle = GetGoblinNameById(goblinId); } } getroottable().rawdelete("TreasureGoblin_Obj"); function Lenheart_TreasureGoblin_Fun(obj) { local RootTab = getroottable(); if (!RootTab.rawin("TreasureGoblin_Obj")) { RootTab.rawset("TreasureGoblin_Obj", true); LenheartNewUI_CreateWindow(TreasureGoblinC, "宝藏哥布林的宝箱窗口", ((getroottable().Rindro_Scr_Width - 317) / 2).tointeger(), 80, 317, 335, 26); } } getroottable()["LenheartFuncTab"].rawset("TreasureGoblinFuncN", Lenheart_TreasureGoblin_Fun); L_Windows_List <- []; getroottable().rawdelete("LenheartPluginsInitFlag"); getroottable().rawdelete("EventList_Obj") getroottable().rawdelete("TreasureGoblin_Obj"); // L_sq_GoDungeon(3709); // local Objss = L_Sq_ObjectAddressToSqrObject(L_sq_RA(0x1AB7CDC), "CNSquirrelPassiveObject", 0); // print(Objss); // print(Objss.isObjectType(OBJECTTYPE_CHARACTER));