Sqr/Plugins/NewUpgrade/NewUpgrade.nut

446 lines
14 KiB
Plaintext

/*
文件名:NewUpgrade.nut
路径:Plugins/NewUpgrade/NewUpgrade.nut
创建日期:2023-03-06 13:14
文件用途:新版强化系统
*/
//HudPro按钮类
class UpgradeButtonPro extends BasicsDrawTool // obj -- 按钮名称 -- X坐标 -- Y坐标 -- Ani调用路径 -- 宽度 -- 高度
{
obj = null; //Obj对象
State = 0; //按钮状态
ClickEnble = false; //点击效果
ButtonDynamic = false; //动态按钮效果
BaseFrame = null;
CustomClickEnble = false; //自定义点击效果
CustomClickAnifile = null; //自定义点击效果Ani路径
CustomButtonName = null; //自定义点击效果名称
CustomClickFrame = null; //自定义点击效果Ani编号
CustomClickx = null; //自定义点击效果X坐标
CustomClicky = null; //自定义点击效果Y坐标
RectEnble = false; //悬停效果
RectButtonName = null; //悬停名称
RectBaseAnifile = null; //悬停Ani路径
RectFrame = null; //非动态按钮的悬停调用Ani编号
Rectx = null; //悬停X坐标
Recty = null; //悬停Y坐标
ButtonName = null; //按钮名称
x = null; //X坐标
y = null; //Y坐标
BaseAnifile = null; //调用Ani路径
width = null; //可点击宽度
length = null; //可点击高度
Mobj = null; //鼠标对象
//构造函数
constructor(gObj, gButtonName, gX, gY, gAnifile, gWidth, gLength, gBaseFrame) {
obj = gObj;
ButtonName = gButtonName;
x = gX;
y = gY;
BaseAnifile = gAnifile;
width = gWidth;
length = gLength;
BaseFrame = gBaseFrame;
if (getroottable().rawin("MouseObject")) Mobj = getroottable()["MouseObject"];
}
//绘制按钮
function Show() {
if (ClickEnble) //是否开启点击效果
{
if (isLBDown() && State == 0) //按下左键并且按钮处于弹起状态
{
State = 1; //按键进入按下状态
++y;
}
if (!isLBDown() && State == 1) //按下左键并且按钮处于弹起状态
{
State = 0; //按键进入弹起状态
--y;
}
}
if (CustomClickEnble) //是否开启自定义点击效果
{
if (isLBDown()) //按下左键并且按钮处于弹起状态
{
if (!ButtonDynamic) T_DrawStayAni(obj, CustomClickAnifile, CustomClickx, CustomClicky, CustomClickFrame, CustomButtonName);
else T_DrawDynamicAni(obj, CustomClickAnifile, CustomClickx, CustomClicky, CustomButtonName);
}
}
if (RectEnble) //开启悬停效果时
{
if ((isInRect() && !isLBDown()) || (isInRect() && !CustomClickEnble)) //如果鼠标悬停的时候 并且没有点击的时候
{
//IMouse.SetMouseTask(44);
if (!ButtonDynamic) T_DrawStayAni(obj, RectBaseAnifile, Rectx, Recty, RectFrame, RectButtonName);
else T_DrawDynamicAni(obj, RectBaseAnifile, Rectx, Recty, RectButtonName);
}
}
if (!isInRect()) //如果鼠标没有悬停的时候
{
//IMouse.SetMouseTask(0);
if (!ButtonDynamic) T_DrawStayAni(obj, BaseAnifile, x, y, BaseFrame, ButtonName);
else T_DrawDynamicAni(obj, BaseAnifile, x, y, ButtonName);
}
}
//设置自定义点击效果
function SetCustomClickEnble(bool, gButtonName, gX, gY, gAnifile, gFrame) {
CustomClickEnble = bool; //自定义点击效果
CustomClickAnifile = gAnifile; //自定义点击效果Ani路径
CustomButtonName = gButtonName; //自定义点击效果名称
CustomClickFrame = gFrame; //自定义点击效果Ani编号
CustomClickx = gX; //自定义点击效果X坐标
CustomClicky = gY; //自定义点击效果Y坐标
}
//设置悬停效果
function SetRectEnble(bool, gButtonName, gX, gY, gAnifile, gFrame) {
RectEnble = bool; //悬停效果
RectButtonName = gButtonName; //悬停名称
RectBaseAnifile = gAnifile; //悬停Ani路径
RectFrame = gFrame; //非动态按钮的悬停调用Ani编号
Rectx = gX; //悬停X坐标
Recty = gY; //悬停Y坐标
}
//设置动态按钮
function SetClickEnble(bool) {
ButtonDynamic = bool;
}
//设置点击效果
function SetClickEnble(bool) {
ClickEnble = bool;
}
//悬停状态
function isInRect() {
if (sq_IsIntersectRect(IMouse.GetXPos(), IMouse.GetYPos(), 5, 5, x, y, width, length)) return true;
else return false;
}
//左键按下状态
function isLBDown() {
if (isInRect() && Mobj.Lb == 1) return true;
else return false;
}
//左键弹起状态
function isLBUp() {
if (isInRect() && Mobj.Lb == 0) return true;
else return false;
}
//左键单击状态
function isLBActive() {
if (isInRect() && Mobj.LbEvent) return true;
else return false;
}
}
class UpgradeWindow extends BasicsDrawTool {
//宽度
Width = null;
//高度
Height = null;
//标题高度
TitleH = null;
//X坐标
X = null;
//Y坐标
Y = null;
YMouseSw = true;
constructor(gX, gY, gWidth, gHeight, gTitleH) {
//宽度
Width = gWidth;
//高度
Height = gHeight;
//标题高度
TitleH = gTitleH;
//X坐标
X = gX;
//Y坐标
Y = gY;
}
//设定鼠标逻辑
function LockMouse() {
if (sq_IsIntersectRect(IMouse.GetXPos(), IMouse.GetYPos(), 1, 1, X, Y, Width, Height)) {
IMouse.LockMouseClick();
YMouseSw = false;
} else {
if (YMouseSw == false && sq_IsIntersectRect(IMouse.GetXPos(), IMouse.GetYPos(), 1, 1, 0, 0, 800, 600)) {
IMouse.ReleaseMouseClick();
YMouseSw = true;
}
}
}
function Show(obj) {
//sq_DrawBox(X, Y, Width, Height, 0xffffffff);
//设定鼠标逻辑
LockMouse();
}
}
class UpgradeC extends BasicsDrawTool {
BaseX = 0;
BaseY = 0;
State = false;
Sw = false;
WindowObj = null;
EquObj = null;
//所需材料组
NedItemArr = null;
//幸运值
Lucky_Value = 0;
//幸运值回调
function GetLuckyValue(Chunk) {
local Buffer = Json_STL("UpgradeGetEquInfo");
Buffer.Parse(Chunk, 0, false);
local RootTab = getroottable();
if (RootTab.rawin("UpgradeObj")) {
RootTab["UpgradeObj"].Lucky_Value = Buffer.Get("lucky_value");
}
}
//当前对象信息回调
function GetEquInfo(Chunk) {
local Buffer = Json_STL("UpgradeGetEquInfo");
Buffer.Parse(Chunk, 0, false);
local RootTab = getroottable();
if (RootTab.rawin("UpgradeObj")) {
RootTab["UpgradeObj"].EquObj = null;
RootTab["UpgradeObj"].NedItemArr = [];
if (Buffer.Get("ok")) {
RootTab["UpgradeObj"].EquObj = {
id = Buffer.Get("id"),
name = Buffer.Get("name"),
grade = Buffer.Get("grade"),
upgrade = Buffer.Get("upgrade"),
pos = Buffer.Get("pos"),
}
local Size = Buffer.Get("size");
if (Size && Size > 0) {
for (local i = 0; i < Size; i++) {
local barr = {
name = Buffer.Get("upgradeitem->" + i + "->name"),
id = Buffer.Get("upgradeitem->" + i + "->id"),
count = Buffer.Get("upgradeitem->" + i + "->count"),
rarity = Buffer.Get("upgradeitem->" + i + "->rarity"),
}
RootTab["UpgradeObj"].NedItemArr.append(barr);
}
}
}
}
}
constructor() {
//注册装备信息回调
Pack_Control.rawset(20018006, GetEquInfo);
Pack_Control.rawset(20018008, GetLuckyValue);
NedItemArr = [];
}
//获取汉字偏移
function GetOffserFromLen(char, offset) {
return (char.len() * offset)
}
//获取装备名称颜色
function GetEquColor(rarity) {
switch (rarity) {
case 0:
return 0xFFFFFFFF;
case 1:
return 0xFFEDD568;
case 2:
return 0xFFFF6BB3;
case 3:
return 0xFFF000FF;
case 4:
return 0xFF00B1FF;
}
}
function CallBack(x, y) {
//同步坐标
BaseX = x;
BaseY = y;
//背包打开时才绘制
State = true;
//开关绘制
local obj = sq_GetMyMasterCharacter();
local OpenButton = UpgradeButtonPro(obj, "UpgradeOpenButton", BaseX - 550, BaseY - 300, "common/buffswitching/main.ani", 26, 26, 11);
OpenButton.SetRectEnble(true, "UpgradeOpenButtonr", BaseX - 550 - 4, BaseY - 300 - 4, "common/buffswitching/main.ani", 12);
OpenButton.SetCustomClickEnble(true, "UpgradeOpenButtonc", BaseX - 550 - 4, BaseY - 300 - 4, "common/buffswitching/main.ani", 13);
OpenButton.Show();
//开关按钮
if (OpenButton.isLBActive()) {
if (Sw == false) {
Sw = true;
L_sq_SendPackType(130);
L_sq_SendPackWChar("{\"op\":20018007}");
L_sq_SendPack();
} else {
Sw = false;
}
}
}
function Encode(Table) {
local Size = Table.len();
local Pos = 0;
local Str = "{";
foreach(Key, Value in Table) {
++Pos;
Str += "\"";
Str += Key.tostring();
Str += "\"";
Str += ":";
if (typeof(Value) == "string") {
Str += "\"";
Str += Value;
Str += "\"";
} else Str += Value;
if (Pos != Size) Str += ",";
}
Str += "}";
return Str;
}
function DrawMain(obj) {
local BX = BaseX - 550 - 710;
local BY = BaseY + 86 - 420;
{ //底图层绘制
//窗口
T_DrawStayAni(obj, "common/new_upgrade/main.ani", BX, BY, 0, "UpgradeSystemMain");
//窗口标题
L_sq_DrawCode("强化系统", BX + 200, BY + 3, sq_RGBA(230, 200, 155, 250), 0, 0);
}
{ //装备信息绘制
if (EquObj) {
local CodeColor = GetEquColor(EquObj.grade);
L_Sq_DrawItem(BX + 211, BY + 73, EquObj.id, 1, 0, 0, 0);
L_sq_DrawCode(EquObj.name.tostring(), BX + 224 - GetOffserFromLen(EquObj.name.tostring(), 2), BY + 56, CodeColor, 0, 0);
L_sq_DrawCode("当前等级:" + EquObj.upgrade.tostring(), BX + 196, BY + 107, sq_RGBA(230, 200, 155, 250), 0, 0);
}
if (NedItemArr) {
foreach(Pos, ItemObject in NedItemArr) {
L_Sq_DrawItem(BX + 28 + (230 * (Pos % 2)), BY + 190 + ((35 * (Pos / 2))), ItemObject.id, ItemObject.count, 0, 0, 0);
local ICodeColor = GetEquColor(ItemObject.rarity);
L_sq_DrawCode(ItemObject.name, BX + 62 + (230 * (Pos % 2)), BY + 198 + ((35 * (Pos / 2))), ICodeColor, 0, 0);
//Sout("名称: %L" , ItemObject.name);
}
}
}
{ //幸运值绘制
L_sq_DrawCode("当前幸运值: " + Lucky_Value + " / 100", BX + 170, BY + 370, 0xFF00B1FF, 0, 0);
}
{ //强化按钮
local UpGradeButton = UpgradeButtonPro(obj, "UpGradeButton", BX + 193, BY + 393, "common/new_upgrade/main.ani", 58, 24, 1);
UpGradeButton.SetRectEnble(true, "UpGradeButtonr", BX + 193, BY + 393, "common/new_upgrade/main.ani", 2);
UpGradeButton.SetCustomClickEnble(true, "UpGradeButtonc", BX + 193, BY + 394, "common/new_upgrade/main.ani", 2);
UpGradeButton.Show();
if (UpGradeButton.isLBActive()) {
if (EquObj && NedItemArr) {
local GoUpGradePack = Json_STL("GoUpGradePack");
GoUpGradePack.Put("op", 20018011);
local EquInfo = Encode(EquObj);
GoUpGradePack.Put("EquInfo", EquInfo);
local NedItemInfoPack = Json_STL("NedItemInfoPack");
foreach(Pos, ItemObject in NedItemArr) {
NedItemInfoPack.Put("NedItemInfo" + Pos, Encode(ItemObject));
}
//local NedItemInfo = Json_STL.Encode(NedItemArr);
GoUpGradePack.Put("NedItemInfo", NedItemInfoPack.GetString());
GoUpGradePack.Put("Luckyvalue", Lucky_Value);
NedItemInfoPack.Delete();
local str = GoUpGradePack.GetString();
L_sq_SendPackType(130);
L_sq_SendPackWChar(str);
L_sq_SendPack();
GoUpGradePack.Delete();
}
}
}
}
function Proc(obj) {
//绘制主界面
if (State && Sw) {
if (WindowObj) {
DrawMain(obj);
WindowObj.Show(obj);
} else {
WindowObj = UpgradeWindow(0, 0, 800, 600, 10);
}
} else {
if (WindowObj && WindowObj.YMouseSw == false) {
IMouse.ReleaseMouseClick();
WindowObj.YMouseSw = true;
}
}
}
}
//强化系统
function UpgradeSystem(obj) {
local RootTab = getroottable();
if (!RootTab.rawin("UpgradeObj")) {
local Cobj = UpgradeC();
RootTab.rawset("UpgradeObj", Cobj);
} else {
RootTab["UpgradeObj"].Proc(obj);
RootTab["UpgradeObj"].State = false;
}
}
//回调函数
function Sq_UpgradeCallBack(x, y) {
local RootTab = getroottable();
if (RootTab.rawin("UpgradeObj")) {
RootTab["UpgradeObj"].CallBack(x, y);
}
}