Rindro-Sqr/Project/AncientheroLuckyBox/AncientheroLuckyBox.nut

525 lines
16 KiB
Plaintext

/*
文件名:AncientheroLuckyBox.nut
路径:Project/AncientheroLuckyBox/AncientheroLuckyBox.nut
创建日期:2025-07-08 18:44
文件用途:圣者遗物箱
*/
class AncientheroLuckyBoxC extends LenheartNewUI_Windows {
//调试模式
// DeBugMode = true;
//不是窗口
// NoWindow = true;
//是否可见
Visible = false;
Img = null;
//遗物箱ID
BoxId = 15;
//盒子数量
BoxCount = 0;
//能量
Energy = 0;
//奖励查询网站
RewardUrl = "https://www.baidu.com";
//打开状态 0未打开 1单抽 10十连抽
OpenFlag = 1;
//抽奖模式按钮集合
OpenBtns = null;
//动画队列
AniQueue = null;
//奖励动画盒子
SmallBoxList = null;
BigBox = null;
constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
Childrens = [];
AniQueue = QuestQueue();;
//注册控件
RegisterWidget();
LenheartNewUI_Windows.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH);
Img = {};
Img["main"] <- Rindro_Image("interface2/event/chn_event_2020/201029_ancientheroluckybox/ancientbox.img");
Img["yosin"] <- Rindro_Image("yosin/db_newani.img");
Img["yosin_bd"] <- Rindro_Image("yosin/db_newani_bd.img");
SmallBoxList = [];
for (local i = 0; i< 20; i++) {
local Buffer = AncientheroLuckyBoxC_Box(this, i);
SmallBoxList.append(Buffer);
}
BigBox = AncientheroLuckyBoxC_BigBox(this, 99);
//配置回包
RegisterPack(20074004, function(Chunk) {
local Jso = Json.Decode(Chunk);
this.Visible = true;
//重置
OpenFlag = 0;
foreach(Obj in SmallBoxList) {
Obj.Reset();
BigBox.Reset();
}
this.BoxId = Jso["BoxId"];
this.BoxCount = Jso["BoxCount"];
this.RewardUrl = Jso["ProbabilityTab"];
this.Energy = Jso["nl"];
}.bindenv(this));
//配置回包
RegisterPack(20094008, function(Chunk) {
local Jso = Json.Decode(Chunk);
this.BoxCount = Jso["BoxCount"];
this.Energy = Jso["nl"];
this.OpenFlag = Jso["itemBuffers"].len();
if (this.OpenFlag == 10) {
foreach(Pos, obj in Jso["itemBuffers"]) {
//因为曾服务端这里发的数组 估计是土罐抄过来的龙盒只有一个道具 只取0号位
local Info = obj;
local RandomScript = GetRewardAniScript(Info.typ);
SmallBoxList[Pos].SetInfo(Info.itemid, Info.num, RandomScript, Info.typ);
}
} else if (this.OpenFlag == 1) {
local Info = Jso["itemBuffers"][0];
BigBox.SetInfo(Info.itemid, Info.num, GetRewardAniScript(Info.typ), Info.typ);
}
}.bindenv(this));
// local monipack = "{\"uid\":1,\"op\":20094008,\"itemBuffers\":[[{\"typ\":1,\"itemid\":3037,\"num\":3}],[{\"typ\":1,\"itemid\":3037,\"num\":2}],[{\"typ\":1,\"itemid\":3037,\"num\":1}],[{\"typ\":1,\"itemid\":3037,\"num\":1}],[{\"typ\":1,\"itemid\":3037,\"num\":1}],[{\"typ\":1,\"itemid\":3037,\"num\":3}],[{\"typ\":1,\"itemid\":3037,\"num\":3}],[{\"typ\":1,\"itemid\":3037,\"num\":3}],[{\"typ\":1,\"itemid\":3037,\"num\":3}],[{\"typ\":2,\"itemid\":3037,\"num\":1}]],\"nl\":80,\"cid\":1,\"BoxCount\":67}";
// local monipack = "{\"BoxCount\":76,\"cid\":1,\"itemBuffers\":[{\"itemid\":3038,\"num\":1,\"typ\":3}],\"nl\":0,\"op\":20094008,\"uid\":1}";
// Pack_Control[20094008](monipack);
}
function GetRewardAniScript(Grade) {
local Middle = "";
switch (Grade) {
case 0: {
Middle = "box_b";
break;
}
case 1: {
switch (sq_getRandom(0, 1)) {
case 0:
Middle = "box_b_a";
break;
case 1:
Middle = "box_a";
break;
}
break;
}
case 2: {
switch (sq_getRandom(0, 2)) {
case 0:
Middle = "box_b_s";
break;
case 1:
Middle = "box_a_s";
break;
case 2:
Middle = "box_s";
break;
}
break;
}
case 3: {
switch (sq_getRandom(0, 3)) {
case 0:
Middle = "box_b_ss";
break;
case 1:
Middle = "box_a_ss";
break;
case 2:
Middle = "box_s_ss";
break;
case 3:
Middle = "box_ss";
break;
}
break;
}
}
return Middle;
}
function RegisterWidget() {
//关闭按钮
local CloseButton = LenheartNewUI_BaseButton(763, 0, 11, 12, "interface/lenheartwindowcommon.img", 276);
CloseButton.OnClick = function() {
this.Visible = false;
}.bindenv(this);
Childrens.append(CloseButton);
OpenBtns = [];
//单抽复选框
local OneOpenBtn = LenheartNewUI_SwitchButtonText(196, 425, " 开启1个");
OneOpenBtn.ImgIndex = 358;
OneOpenBtn.SetTextPos(12, 2);
OneOpenBtn.Width = 130;
OneOpenBtn.Height = 16;
OneOpenBtn.OnClickEx = function(Btn) {
CallOpenAnimation(OpenFlag == 0);
OpenFlag = 1;
OpenBtns[1].State = 0;
Btn.State = 1;
}.bindenv(this);
AddChild(OneOpenBtn);
OpenBtns.append(OneOpenBtn);
//单抽复选框
local TenOpenBtn = LenheartNewUI_SwitchButtonText(458, 425, " 开启10个");
TenOpenBtn.ImgIndex = 358;
TenOpenBtn.SetTextPos(12, 2);
TenOpenBtn.Width = 130;
TenOpenBtn.Height = 16;
TenOpenBtn.OnClickEx = function(Btn) {
CallOpenAnimation(OpenFlag == 0);
OpenFlag = 10;
OpenBtns[0].State = 0;
Btn.State = 1;
}.bindenv(this);
AddChild(TenOpenBtn);
OpenBtns.append(TenOpenBtn);
//抽奖按钮
local UseButton = LenheartNewUI_ButtonText(356, 500, 15, "开 启");
// UseButton.SetFrame(null, 323);
UseButton.SetTextOffset(-3, 1);
UseButton.OnClickEx = function(Btn) {
if (OpenFlag == 0 || AniQueue.Queue.len() != 0) return;
foreach(Obj in SmallBoxList) {
Obj.Reset();
BigBox.Reset();
}
SendPackEx({
op = 20094005,
Num = OpenFlag
});
}.bindenv(this);
AddChild(UseButton);
}
//调用打开界面动画
function CallOpenAnimation(Flag) {
R_Utils.PlaySound("ANCIENTBOX_WHEEL");
//Flag 为true时是第一次进入 盖着盖子的状态 false 需要先盖上再打开
AniQueue.AddQuest("打开界面动画", function(Name, Time, Flag) {
if (Flag) {
local Ani = DrawAniEx(X + 5, Y + 25, "common/ancientheroluckybox/animation/intro.ani");
if (sq_IsEnd(Ani)) {
sq_Rewind(Ani);
AniQueue.RemoveQuest(Name);
}
} else {
local Ani = DrawAniEx(X + 5, Y + 25, "common/ancientheroluckybox/animation/outro.ani");
if (sq_IsEnd(Ani)) {
sq_Rewind(Ani);
AniQueue.RemoveQuest(Name);
CallOpenAnimation(true);
}
}
}.bindenv(this), Flag);
}
//绘制主界面
function DrawMain(obj) {
//绘制背景
Img["yosin"].DrawPng(0, X, Y);
//未打开状态
if (OpenFlag == 0) Img["main"].DrawPng(1, X + 5, Y + 25);
//绘制圣者遗物箱图标
DrawItemBase(X + 377, Y + 394, BoxId, BoxCount);
//绘制圣者遗物箱能量
if (Energy< 100) Img["yosin_bd"].DrawPng(Energy, X + 350, Y + 368);
else {
Img["yosin"].DrawPng(2, X, Y);
local T = Clock() % 2000;
local Alpha = 0;
if (T< 1000) {
Alpha = 150 + 105 * (T.tofloat() / 1000.0);
} else {
Alpha = 255 - 105 * ((T - 1000).tofloat() / 1000.0);
}
Img["yosin_bd"].DrawExPng(100, X + 350, Y + 368, 0, sq_RGBA(255, 255, 255, Alpha.tointeger()), 1.0, 1.0)
}
L_sq_DrawCode(Energy.tostring() + "%", X + 426 - (LenheartTextClass.GetStringLength(Energy.tostring() + "%") / 2), Y + 437, sq_RGBA(179, 169, 135, 255), 0, 1);
if (OpenFlag == 10) {
//绘制奖励动画
for (local i = 0; i< SmallBoxList.len(); i++) {
SmallBoxList[i].Draw(obj, X - 12 + (150 * (i % 5)), Y + 70 + (128 * (i / 5)));
}
} else if (OpenFlag == 1) {
BigBox.Draw(obj, X + 226, Y + 80);
}
}
function Show(obj) {
DrawMain(obj);
AniQueue.Run();
LenheartNewUI_Windows.Show(obj);
}
//逻辑入口
function Proc(obj) {
LenheartNewUI_Windows.SyncPos(X, Y);
}
//重置
function ResetData() {
if (OpenBtns) {
OpenBtns[0].State = 0;
OpenBtns[1].State = 0;
}
OpenFlag = 0;
}
}
function Lenheart_AncientheroLuckyBox_Fun(obj) {
local RootTab = getroottable();
if (!RootTab.rawin("AncientheroLuckyBox_Obj")) {
RootTab.rawset("AncientheroLuckyBox_Obj", true);
LenheartNewUI_CreateWindow(AncientheroLuckyBoxC, "圣者遗物箱窗口", ((getroottable().Rindro_Scr_Width - 782) / 2).tointeger(), 30, 782, 600, 28);
}
}
getroottable()["LenheartFuncTab"].rawset("AncientheroLuckyBoxFuncN", Lenheart_AncientheroLuckyBox_Fun);
L_Windows_List <- [];
getroottable().rawdelete("LenheartPluginsInitFlag");
getroottable().rawdelete("EventList_Obj")
getroottable().rawdelete("AncientheroLuckyBox_Obj");
class AncientheroLuckyBoxC_Box extends Rindro_BaseToolClass {
//父对象
Parent = null;
//标识ID
Idx = null;
//状态 0未设置 1已设置 2播放动画 3播放动画结束
Status = 0;
//道具是否显示
ItemVisFlag = false;
//奖励道具
ItemId = null;
//奖励道具名字
ItemName = null;
//奖励道具名字颜色
ItemNameColor = null;
//奖励道具数量
Count = null;
//奖励动画
Ani = null;
//音效
Sound = null;
//品级
Grade = null;
GradeList = ["b", "a", "s", "ss"];
GradeCorlorList = [sq_RGBA(255, 255, 255, 255), sq_RGBA(104, 213, 237, 255), sq_RGBA(179, 107, 255, 255), sq_RGBA(255, 0, 240, 255), sq_RGBA(255, 177, 0, 255), sq_RGBA(255, 102, 102, 255)];
//标识Flag
Flag = null;
constructor(P, Idx) {
this.Parent = P;
this.Idx = Idx;
}
function Draw(obj, X, Y) {
//如果已设置 可以开始播放
if (Status == 1) {
Status = 2;
Flag = this.Idx + Ani + Clock();
}
if (Status == 2) {
local Ani = DrawAniEx(X, Y, Ani, Flag);
//当Ani播放时间大于百分之90时
if (sq_GetCurrentTime(Ani) > (Ani.getDelaySum(false) * 0.9).tointeger()) {
ItemVisFlag = true;
}
if (sq_IsEnd(Ani)) {
sq_Rewind(Ani);
Status = 3;
}
}
//如果需要显示道具
if (ItemVisFlag) {
X += 10;
DrawAniEx(X + 24, Y + 80, "common/ancientheroluckybox/animation/item_mini_" + this.Grade + "_loop.ani", Flag + "Item");
//绘制道具
Parent.DrawItemBase(X + 27, Y + 83, ItemId, Count);
//绘制道具名字
L_sq_DrawCode(this.ItemName, X + 107 - (LenheartTextClass.GetStringLength(this.ItemName) / 2), Y + 91, ItemNameColor, 0, 1);
DrawAniEx(X + 24 + 25, Y + 80 + 5, "common/ancientheroluckybox/animation/item_mini_" + this.Grade + "_start.ani", Flag + "ItemStart");
}
}
//设置信息
function SetInfo(ItemId, Count, RandomScript, Grade) {
if (Status == 0) {
this.ItemId = ItemId;
local ItemObject = L_sq_GetItem(ItemId);
local NamePointer = L_sq_RA(ItemObject + 0x20);
this.ItemName = NativePointer(L_sq_I2P(NamePointer)).readUnicodeString();
local Rarity = L_sq_RA(ItemObject + 0xF4);
this.ItemNameColor = GradeCorlorList[Rarity];
this.Count = Count;
this.Ani = "common/ancientheroluckybox/animation/mini_" + RandomScript + ".ani";
this.Sound = "ANCIENTBOX_OPEN_" + RandomScript.slice(4);
this.Grade = GradeList[Grade];
R_Utils.PlaySound(this.Sound);
Status = 1;
}
}
//重置
function Reset() {
Status = 0;
ItemId = null;
ItemName = null;
ItemNameColor = null;
Ani = null;
Sound = null;
ItemVisFlag = false;
}
}
class AncientheroLuckyBoxC_BigBox extends Rindro_BaseToolClass {
//父对象
Parent = null;
//标识ID
Idx = null;
//状态 0未设置 1已设置 2播放动画 3播放动画结束
Status = 0;
//道具是否显示
ItemVisFlag = false;
//奖励道具
ItemId = null;
//奖励道具名字
ItemName = null;
//奖励道具名字颜色
ItemNameColor = null;
//奖励道具数量
Count = null;
//奖励动画
Ani = null;
//音效
Sound = null;
//品级
Grade = null;
GradeList = ["b", "a", "s", "ss"];
GradeCorlorList = [sq_RGBA(255, 255, 255, 255), sq_RGBA(104, 213, 237, 255), sq_RGBA(179, 107, 255, 255), sq_RGBA(255, 0, 240, 255), sq_RGBA(255, 177, 0, 255), sq_RGBA(255, 102, 102, 255)];
//标识Flag
Flag = null;
constructor(P, Idx) {
this.Parent = P;
this.Idx = Idx;
}
function Draw(obj, X, Y) {
//如果已设置 可以开始播放
if (Status == 1) {
Status = 2;
Flag = this.Idx + Ani + Clock();
}
if (Status == 2) {
local Ani = DrawAniEx(X, Y, Ani, Flag);
//当Ani播放时间大于百分之90时
if (sq_GetCurrentTime(Ani) > (Ani.getDelaySum(false) * 0.9).tointeger()) {
ItemVisFlag = true;
}
if (sq_IsEnd(Ani)) {
sq_Rewind(Ani);
Status = 3;
}
}
//如果需要显示道具
if (ItemVisFlag) {
X += 74;
Y += 60;
DrawAniEx(X + 24, Y + 80, "common/ancientheroluckybox/animation/item_mini_" + this.Grade + "_loop.ani", Flag + "Item");
//绘制道具
Parent.DrawItemBase(X + 27, Y + 83, ItemId, Count);
//绘制道具名字
L_sq_DrawCode(this.ItemName, X + 107 - (LenheartTextClass.GetStringLength(this.ItemName) / 2), Y + 91, ItemNameColor, 0, 1);
DrawAniEx(X + 24 + 25, Y + 80 + 5, "common/ancientheroluckybox/animation/item_mini_" + this.Grade + "_start.ani", Flag + "ItemStart");
}
}
//设置信息
function SetInfo(ItemId, Count, RandomScript, Grade) {
if (Status == 0) {
this.ItemId = ItemId;
local ItemObject = L_sq_GetItem(ItemId);
local NamePointer = L_sq_RA(ItemObject + 0x20);
this.ItemName = NativePointer(L_sq_I2P(NamePointer)).readUnicodeString();
local Rarity = L_sq_RA(ItemObject + 0xF4);
this.ItemNameColor = GradeCorlorList[Rarity];
this.Count = Count;
this.Ani = "common/ancientheroluckybox/animation/" + RandomScript + ".ani";
this.Sound = "ANCIENTBOX_OPEN_" + RandomScript.slice(4);
this.Grade = GradeList[Grade];
R_Utils.PlaySound(this.Sound);
Status = 1;
}
}
//重置
function Reset() {
Status = 0;
ItemId = null;
ItemName = null;
ItemNameColor = null;
Ani = null;
Sound = null;
ItemVisFlag = false;
}
}