Rindro-Sqr/Project/WorldBoss/WorldBoss.nut

572 lines
18 KiB
Plaintext
Raw Normal View History

2025-05-27 21:24:22 +08:00
/*
文件名:WorldBoss.nut
路径:Project/WorldBoss/WorldBoss.nut
创建日期:2025-05-01 23:54
文件用途:世界BOSS
*/
class WorldBossC extends LenheartNewUI_Windows {
//调试模式
// DeBugMode = true;
//不是窗口
// NoWindow = true;
//是否可见
Visible = false;
WindowImg = Rindro_Image("hud/worldboss.img");
WindowTimeImg = Rindro_Image("hud/worldboss_time.img");
WindowTimeNumImg = Rindro_Image("hud/worldboss_timenum.img");
2025-08-27 08:45:37 +08:00
WindowLogoImg = Rindro_Image("hud/worldboss_logo.img");
WindowInfoImg = Rindro_Image("hud/worldboss_info.img");
2025-05-27 21:24:22 +08:00
//基础信息
BaseInfo = null;
//Pvf信息
PvfInfo = null;
//伤害列表
RankList = null;
2025-08-27 08:45:37 +08:00
//标题栏
Title = null;
//组队榜单按钮
TeamRankBtn = null;
//个人榜单按钮
PersonalRankBtn = null;
2025-05-27 21:24:22 +08:00
//页面
Page = 0;
2025-08-27 08:45:37 +08:00
//查询排名
CheckType = 0; //0组队 1个人
RankPage = 0; //当前页数
MaxRankPage = 1; //最大页数
//奖励
RewardList = null;
RewardType = 0;
//排行榜
RankObject = null;
MyRankObject = null;
2025-05-27 21:24:22 +08:00
//计时器
TiemrCache = null;
Timer = null;
//累计伤害
TotalDamage = null;
constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
Childrens = [];
//注册控件
RegisterWidget();
LenheartNewUI_Windows.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH);
Pack_Control.rawset(20060002, function(Chunk) {
local Jso = Json.Decode(Chunk);
BaseInfo = Jso;
2025-08-27 08:45:37 +08:00
//临时
for (local i = 0; i< BaseInfo.info.len(); i++) {
if (i == 0) BaseInfo.info[i].boss_name <- "斯卡萨侵袭";
else BaseInfo.info[i].boss_name <- "世界BOSS" + i;
}
RegisterBossPage();
ChangePage(0);
}.bindenv(this));
//获取奖励
Pack_Control.rawset(20060012, function(Chunk) {
local Jso = Json.Decode(Chunk);
RewardList = [];
RewardList.append(Jso.rewards);
RewardList.append(Jso.rewards2);
2025-05-27 21:24:22 +08:00
}.bindenv(this));
Pack_Control.rawset(20060006, function(Chunk) {
local Jso = Json.Decode(Chunk);
2025-08-27 08:45:37 +08:00
MaxRankPage = Jso.maxPage;
RankObject = [];
foreach(Info in Jso.list) {
local T = {
idx = Info.rank,
name = Info.name,
time = "15:20",
damage = Info.damage,
teamid = Info.teamId,
};
local Buffer = WorldBossC_Item(this, T);
RankObject.append(Buffer);
}
if (Jso.rawin("myteam")) {
MyRankObject = WorldBossC_Item(this, {
idx = Jso.myteam.rank,
name = "我的队伍",
time = "15:20",
damage = Jso.myteam.damage,
teamid = Jso.myteam.teamId,
self = true
})
}
}.bindenv(this));
Pack_Control.rawset(20060026, function(Chunk) {
local Jso = Json.Decode(Chunk);
MaxRankPage = Jso.maxPage;
RankObject = [];
foreach(Info in Jso.list) {
local T = {
idx = Info.rank,
name = Info.name,
time = Info.time,
damage = Info.damage,
};
local Buffer = WorldBossC_Item(this, T);
RankObject.append(Buffer);
}
if (Jso.rawin("myteam")) {
MyRankObject = WorldBossC_Item(this, {
idx = Jso.myteam.rank,
name = "我的队伍",
time = Jso.myteam.time,
damage = Jso.myteam.damage,
self = true
})
}
2025-05-27 21:24:22 +08:00
}.bindenv(this));
Pack_Control.rawset(20060014, function(Chunk) {
local Jso = Json.Decode(Chunk);
Timer = Clock();
TiemrCache = Jso.endTime;
}.bindenv(this));
PushDamageFontFuncTab.rawset("DamagePerSecondCFunc", function(ObjAddress, MySelfAddress, Value) {
if (!SendDamagePackFlag) return;
if (ObjAddress == 0 || ObjAddress == MySelfAddress) {
if (!TotalDamage) TotalDamage = longlong(0);
TotalDamage += longlong(Value);
}
}.bindenv(this));
2025-08-27 08:45:37 +08:00
// RankObject = [];
// for (local i = 0; i< 7; i++) {
// local Buffer = WorldBossC_Item(this, {
// idx = i,
// name = "倾泪寒的队伍" + i,
// time = "15:20",
// damage = Clock().tostring(),
// });
// RankObject.append(Buffer);
// }
// MyRankObject = WorldBossC_Item(this, {
// idx = 56,
// name = "我的队伍",
// time = "15:20",
// damage = Clock().tostring(),
// self = true
// });
2025-05-27 21:24:22 +08:00
}
2025-08-27 08:45:37 +08:00
//请求奖励信息
function RequestRewardInformation() {
if (Page == null) return;
local T = {
op = 20060001,
index = Page
}
SendPackEx(T);
2025-05-27 21:24:22 +08:00
}
function ChangePage(ToPage) {
Page = ToPage;
2025-08-27 08:45:37 +08:00
RankPage = 0; //重置页数
CheckRank();
RequestRewardInformation();
2025-05-27 21:24:22 +08:00
}
2025-08-27 08:45:37 +08:00
function CheckRank() {
local T = {
//0查组队 否则查个人
op = (CheckType == 0 ? 20060005 : 20060025),
index = Page,
page = RankPage
}
SendPackEx(T);
}
function RegisterBossPage() {
2025-05-27 21:24:22 +08:00
Title = [];
2025-08-27 08:45:37 +08:00
local LogicFunc = function(Btn) {
foreach(Pos, obj in Title) {
if (obj != Btn) obj.State = 0;
else {
obj.State = 1;
ChangePage(Pos);
}
}
};
//遍历有多少个Boss
foreach(Pos, Info in BaseInfo.info) {
local Tabbars1 = LenheartNewUI_TabbarsText(6 + (Pos * 61), 23, Info.boss_name);
if (Pos == 0) Tabbars1.State = 1;
Tabbars1.SetTextOffset(31 - LenheartTextClass.GetStringLength(Info.boss_name) / 2, 4);
AddChild(Tabbars1);
Tabbars1.OnClickEx = LogicFunc.bindenv(this);
Title.append(Tabbars1);
}
}
2025-05-27 21:24:22 +08:00
2025-08-27 08:45:37 +08:00
function RegisterWidget() {
2025-05-27 21:24:22 +08:00
//关闭按钮
2025-08-27 08:45:37 +08:00
local CloseButton = LenheartNewUI_BaseButton(738, 3, 11, 12, "interface/lenheartwindowcommon.img", 276);
2025-05-27 21:24:22 +08:00
CloseButton.OnClick = function() {
this.Visible = false;
}.bindenv(this);
Childrens.append(CloseButton);
2025-08-27 08:45:37 +08:00
local RankingRewardsButton = LenheartNewUI_ButtonText(42, 472, 40, "排名奖励");
RankingRewardsButton.SetTextOffset(6, 1);
RankingRewardsButton.OnClickEx = function(Btn) {
RewardType = 0;
2025-05-27 21:24:22 +08:00
}.bindenv(this);
2025-08-27 08:45:37 +08:00
AddChild(RankingRewardsButton);
2025-05-27 21:24:22 +08:00
2025-08-27 08:45:37 +08:00
local BasicRewardsButton = LenheartNewUI_ButtonText(170, 472, 40, "基础奖励");
BasicRewardsButton.SetTextOffset(6, 1);
BasicRewardsButton.OnClickEx = function(Btn) {
RewardType = 1;
2025-05-27 21:24:22 +08:00
}.bindenv(this);
2025-08-27 08:45:37 +08:00
AddChild(BasicRewardsButton);
local PurchaseTicketsButton = LenheartNewUI_ButtonText(420, 478, 150, "开始挑战");
PurchaseTicketsButton.SetTextOffset(59, 1);
PurchaseTicketsButton.OnClickEx = function(Btn) {
local T = {
op = 20060007,
index = Page
}
SendPackEx(T);
}.bindenv(this);
AddChild(PurchaseTicketsButton);
TeamRankBtn = LenheartNewUI_TabbarsText(305, 84, "组队榜单");
TeamRankBtn.State = 1;
TeamRankBtn.SetTextOffset(7, 4);
TeamRankBtn.OnClickEx = function(Btn) {
if (Btn.State == 1) return;
PersonalRankBtn.State = 0;
Btn.State = 1;
CheckType = 0;
CheckRank();
}.bindenv(this);
AddChild(TeamRankBtn);
PersonalRankBtn = LenheartNewUI_TabbarsText(366, 84, "个人榜单");
PersonalRankBtn.SetTextOffset(7, 4);
PersonalRankBtn.OnClickEx = function(Btn) {
if (Btn.State == 1) return;
TeamRankBtn.State = 0;
Btn.State = 1;
CheckType = 1;
CheckRank();
}.bindenv(this);
AddChild(PersonalRankBtn);
2025-05-27 21:24:22 +08:00
2025-08-27 08:45:37 +08:00
//左翻页按钮
local LeftButton = LenheartNewUI_BaseButton(480, 416, 15, 15, "interface/lenheartwindowcommon.img", 34);
2025-05-27 21:24:22 +08:00
LeftButton.OnClick = function() {
2025-08-27 08:45:37 +08:00
if (RankPage > 0) {
RankPage--;
CheckRank();
}
2025-05-27 21:24:22 +08:00
}.bindenv(this);
2025-08-27 08:45:37 +08:00
AddChild(LeftButton);
//右翻页按钮
local RightButton = LenheartNewUI_BaseButton(550, 416, 15, 15, "interface/lenheartwindowcommon.img", 38);
2025-05-27 21:24:22 +08:00
RightButton.OnClick = function() {
2025-08-27 08:45:37 +08:00
if (RankPage<(MaxRankPage - 1)) {
RankPage++;
CheckRank();
}
2025-05-27 21:24:22 +08:00
}.bindenv(this);
2025-08-27 08:45:37 +08:00
AddChild(RightButton);
for (local i = 0; i< 8; i++) {
local ButtonBuffer = LenheartNewUI_BaseButton(700, 139 + (i * 40), 25, 25, "interface/lenheartwindowcommon.img", 362);
ButtonBuffer.Data = i;
ButtonBuffer.OnClickEx = function(Btn) {
if (RankObject && Btn.Data< RankObject.len()) {
local T = {
op = 20060003,
index = Page,
teamId = RankObject[Btn.Data].Info.teamid
}
SendPackEx(T);
}
}.bindenv(this);
ButtonBuffer.SetCallBackFunc(function(Btn) {
if (RankObject && Btn.Data< RankObject.len() && CheckType == 0) Btn.Visible = true;
else Btn.Visible = false;
}.bindenv(this));
Childrens.append(ButtonBuffer);
}
2025-05-27 21:24:22 +08:00
}
//悬停层绘制Flag
HoverFlag = null;
//绘制主界面
function DrawMain(obj) {
2025-08-27 08:45:37 +08:00
if (Page != null) {
WindowLogoImg.DrawExPng(Page, X + 1, Y + 19, 0, sq_RGBA(255, 255, 255, 220), 1.0, 1.0);
2025-05-27 21:24:22 +08:00
}
2025-08-27 08:45:37 +08:00
WindowImg.DrawPng(0, X, Y);
if (Page != null) {
WindowInfoImg.DrawExPng(Page, X + 19, Y + 66, 0, sq_RGBA(255, 255, 255, 220), 1.0, 1.0);
}
DrawNineBox(X + 26, Y + 416, 260, 42, "interface/lenheartwindowcommon.img", 213); //背景框
DrawNineBox(X + 308, Y + 106, 433, 26, "interface/lenheartwindowcommon.img", 213); //榜单表头
L_sq_DrawCode("名次", X + 330, Y + 113, sq_RGBA(230, 200, 155, 255), 0, 1);
L_sq_DrawCode(CheckType == 0 ? "队伍名称" : "玩家名称", X + 408, Y + 113, sq_RGBA(230, 200, 155, 255), 0, 1);
L_sq_DrawCode("战斗时长", X + 510, Y + 113, sq_RGBA(230, 200, 155, 255), 0, 1);
L_sq_DrawCode("总伤害", X + 604, Y + 113, sq_RGBA(230, 200, 155, 255), 0, 1);
L_sq_DrawCode("详细", X + 700, Y + 113, sq_RGBA(230, 200, 155, 255), 0, 1);
local RankPageStr = (RankPage + 1) + "/" + MaxRankPage;
L_sq_DrawCode(RankPageStr, X + 524 - LenheartTextClass.GetStringLength(RankPageStr) / 2, Y + 418, sq_RGBA(230, 200, 155, 255), 0, 1);
if (RewardList) {
foreach(Pos, ItemId in RewardList[RewardType]) {
DrawItemEx(X + 34 + (Pos * 36), Y + 423, ItemId, 1);
2025-05-27 21:24:22 +08:00
}
2025-08-27 08:45:37 +08:00
}
2025-05-27 21:24:22 +08:00
2025-08-27 08:45:37 +08:00
if (RankObject) {
foreach(Pos, Object in RankObject) {
Object.Show(X + 309, Y + 132 + (Pos * 40));
}
}
if (MyRankObject) {
MyRankObject.Show(X + 309, Y + 434);
}
}
2025-05-27 21:24:22 +08:00
2025-08-27 08:45:37 +08:00
function TopShow(obj) {
LenheartNewUI_Windows.TopShow(obj);
local MousePos_X = IMouse.GetXPos();
local MousePos_Y = IMouse.GetYPos();
if (RankObject) {
foreach(Pos, Object in RankObject) {
if (sq_IsIntersectRect(MousePos_X, MousePos_Y, 1, 1, X + 309, Y + 131 + (Pos * 39), 433, 39)) {
Object.HoverShow(X + 309, Y + 132 + (Pos * 40));
2025-05-27 21:24:22 +08:00
}
}
}
2025-08-27 08:45:37 +08:00
DrawTime(obj);
2025-05-27 21:24:22 +08:00
}
function DrawTime(obj) {
if (!TiemrCache || !Timer) return;
2025-08-27 08:45:37 +08:00
local CountdownX = 300;
local CountdownY = 0;
local DrawX = CountdownX;
local DrawY = CountdownY;
2025-05-27 21:24:22 +08:00
//背景绘制
WindowTimeImg.DrawPng(1, DrawX, DrawY);
WindowTimeImg.DrawPng(0, DrawX, DrawY + 2);
//时间绘制
local DrawTime = TiemrCache - (Clock() - Timer);
local TotalSeconds = DrawTime / 1000;
local Minutes = (TotalSeconds % 3600) / 60;
local Seconds = (TotalSeconds % 3600) % 60;
local Millisecond = DrawTime % 1000 / 10;
local Offset = 43;
DrawNum(format("%02d", Minutes), Offset);
Offset += 40;
WindowTimeNumImg.DrawPng(10, DrawX + Offset - 5, DrawY + 27);
DrawNum(format("%02d", Seconds), Offset);
Offset += 40;
WindowTimeNumImg.DrawPng(10, DrawX + Offset - 5, DrawY + 27);
DrawNum(format("%02d", Millisecond), Offset);
}
function DrawNum(time, Xoffset) {
2025-08-27 08:45:37 +08:00
if (!TiemrCache || !Timer) return;
local CountdownX = 300;
local CountdownY = 0;
local DrawX = CountdownX;
local DrawY = CountdownY;
2025-05-27 21:24:22 +08:00
for (local i = 0; i< time.len(); i++) {
local DrawNum = time.slice(i, i + 1);
WindowTimeNumImg.DrawPng(DrawNum.tointeger(), DrawX + Xoffset + (i * 15), DrawY + 21);
}
}
function Show(obj) {
DrawMain(obj);
LenheartNewUI_Windows.Show(obj);
}
//进入副本初始化包Flag
EnterMapPackFlag = false;
//发送伤害包Flag
SendDamagePackFlag = false;
//副本逻辑
function DungeonLogic() {
local stage = sq_GetGlobaludpModuleStage();
local mapIndex = sq_GetMapIndex(stage);
2025-08-27 08:45:37 +08:00
if (mapIndex == -1) {
SendDamagePackFlag = false;
EnterMapPackFlag = false;
TiemrCache = null;
Timer = null;
}
2025-05-27 21:24:22 +08:00
local dungeon = sq_GetDungeonByStage(stage);
local dungeonIndex = sq_GetDuegonIndex(dungeon);
2025-08-27 08:45:37 +08:00
if (dungeonIndex == BaseInfo.info[Page].dgn && mapIndex == BaseInfo.info[Page].map) {
2025-05-27 21:24:22 +08:00
if (!EnterMapPackFlag) {
EnterMapPackFlag = true;
SendPackEx({
2025-08-27 08:45:37 +08:00
op = 20060013,
index = Page
2025-05-27 21:24:22 +08:00
})
}
SendDamagePackFlag = true;
} else {
SendDamagePackFlag = false;
2025-08-27 08:45:37 +08:00
EnterMapPackFlag = false;
2025-05-27 21:24:22 +08:00
TiemrCache = null;
Timer = null;
}
}
//发送伤害计时器
SendDamageT = 0;
//逻辑入口
function Proc(obj) {
LenheartNewUI_Windows.SyncPos(X, Y);
if (!BaseInfo) return;
DungeonLogic();
DrawTime(obj);
//在副本中需要发送伤害的时候
if (TotalDamage) {
if (SendDamagePackFlag) {
SendDamageT += Rindro_Duration;
if (SendDamageT > 5000) {
2025-08-27 08:45:37 +08:00
// SendDamageT = 0;
// SendPackEx({
// op = 20060017,
// Damage = TotalDamage.Value
// })
// TotalDamage = null;
2025-05-27 21:24:22 +08:00
}
}
//结束时再发一次
else {
SendPackEx({
op = 20060017,
2025-08-27 08:45:37 +08:00
index = Page,
2025-05-27 21:24:22 +08:00
Damage = TotalDamage.Value
})
2025-08-27 08:45:37 +08:00
// print("发送伤害: " + TotalDamage.Value)
2025-05-27 21:24:22 +08:00
TotalDamage = null;
}
}
}
2025-08-27 08:45:37 +08:00
2025-05-27 21:24:22 +08:00
function OpenCallBack() {
Visible = true;
}
}
function Lenheart_WorldBoss_Fun(obj) {
local RootTab = getroottable();
if (!RootTab.rawin("WorldBoss_Obj")) {
RootTab.rawset("WorldBoss_Obj", true);
2025-08-27 08:45:37 +08:00
local Win = LenheartNewUI_CreateWindow(WorldBossC, "阿拉德守卫战窗口", ((getroottable().Rindro_Scr_Width - 753) / 2).tointeger(), 40, 753, 518, 20);
2025-05-27 21:24:22 +08:00
EventList_Obj.AddEvent("阿拉德守卫战", 1001, Win);
}
}
getroottable()["LenheartFuncTab"].rawset("WorldBossFuncN", Lenheart_WorldBoss_Fun);
2025-08-27 08:45:37 +08:00
L_Windows_List <- [];
getroottable().rawdelete("LenheartPluginsInitFlag");
getroottable().rawdelete("EventList_Obj")
getroottable().rawdelete("WorldBoss_Obj");
class WorldBossC_Item {
//Img
Img = null;
//父对象
Parent = null;
//信息
Info = null;
constructor(Window, Info) {
Parent = Window;
Img = Window.WindowImg;
this.Info = Info;
}
function Show(X, Y) {
if (!Info.rawin("self")) Img.DrawPng(1, X, Y);
else Parent.DrawNineBox(X + 0, Y + 2, 432, 35, "interface/lenheartwindowcommon.img", 204);
local IdxStr = Info.idx.tostring();
L_sq_DrawCode(IdxStr, X + 32 - LenheartTextClass.GetStringLength(IdxStr) / 2, Y + 10, sq_RGBA(230, 200, 155, 255), 2, 1);
L_sq_DrawCode(Info.name, X + 125 - LenheartTextClass.GetStringLength(Info.name) / 2, Y + 14, sq_RGBA(230, 200, 155, 255), 0, 1);
L_sq_DrawCode(Info.time.tostring(), X + 230 - LenheartTextClass.GetStringLength(Info.time.tostring()) / 2, Y + 14, sq_RGBA(230, 200, 155, 255), 0, 1);
L_sq_DrawCode(Info.damage, X + 313 - LenheartTextClass.GetStringLength(Info.damage) / 2, Y + 14, sq_RGBA(230, 200, 155, 255), 0, 1);
}
function HoverShow(X, Y) {
Img.DrawPng(2, X, Y);
}
}
// L_sq_GoDungeon(20501);