Rindro-Sqr/Project/HorseGuessing/HorseGuessing.nut

622 lines
19 KiB
Plaintext

/*
文件名:HorseGuessing.nut
路径:Project/HorseGuessing/HorseGuessing.nut
创建日期:2024-09-25 20:30
文件用途:骑士马战
*/
// dofile("sqr/Project/HorseGuessing/HorseGuessing_Guide.nut"); //骑士马战指引
// dofile("sqr/Project/HorseGuessing/HorseGuessing_KnightInfo.nut"); //骑士马战资料
// dofile("sqr/Project/HorseGuessing/HorseGuessing_PastRecord.nut"); //骑士马战过往战绩
class HorseGuessingBaseButton extends LenheartNewUI_BaseButton {
//是否翻转
IsFlip = false;
//ovverride
//鼠标事件回调
function OnMouseProc(Flag, MousePos_X, MousePos_Y) {
if (!IsFlip) {
if (sq_IsIntersectRect(MousePos_X, MousePos_Y, 1, 1, X, Y, Width, Height)) isInRect = true;
else isInRect = false;
} else {
if (sq_IsIntersectRect(MousePos_X, MousePos_Y, 1, 1, X - Width, Y, Width, Height)) isInRect = true;
else isInRect = false;
}
}
//ovverride
//鼠标左键按下回调
function OnMouseLbDown(MousePos_X, MousePos_Y) {
if (!IsFlip) {
if (sq_IsIntersectRect(MousePos_X, MousePos_Y, 1, 1, X, Y, Width, Height)) {
isLBDown = true;
if (!OnClickSound) {
R_Utils.PlaySound("CLICK_BUTTON1");
} else {
R_Utils.PlaySound(OnClickSound);
}
}
} else {
if (sq_IsIntersectRect(MousePos_X, MousePos_Y, 1, 1, X - Width, Y, Width, Height)) {
isLBDown = true;
if (!OnClickSound) {
R_Utils.PlaySound("CLICK_BUTTON1");
} else {
R_Utils.PlaySound(OnClickSound);
}
}
}
}
//ovverride
function Show(obj) {
local XRate = 1.0;
if (IsFlip) XRate = -1.0;
//不可用
if (State == 8) {
L_sq_DrawImg(Path, Idx + 3, X, Y + 1, 1, sq_RGBA(255, 255, 255, 250), XRate, 1.0);
} else {
//按下
if (isLBDown) {
L_sq_DrawImg(Path, Idx + 2, X, Y + 1, 1, sq_RGBA(255, 255, 255, 250), XRate, 1.0);
}
//悬停
else if (isInRect) {
L_sq_DrawImg(Path, Idx + 1, X, Y, 1, sq_RGBA(255, 255, 255, 250), XRate, 1.0);
}
//普通
else {
L_sq_DrawImg(Path, Idx, X, Y, 1, sq_RGBA(255, 255, 255, 250), XRate, 1.0);
}
}
}
}
class HorseGuessingC extends LenheartNewUI_Windows {
//调试模式
//DeBugMode = true;
//不是窗口
// NoWindow = true;
//是否可见
Visible = false;
//标题栏
Title = null;
//当前页面
Page = 0;
//页面选择器
PageSelectM = 0;
//指引页面
GuidePage = null;
//骑士资料页面
KnightInfoPage = null;
//过往战绩页面
PastRecordPage = null;
//骑手名称
RiderName = null;
//当前选择骑手
NowSelectRider = 0;
//下注
BetItem = 0;
//剩余可下注数量
ResidueCoin = 10000;
//骑手信息
RiderInfo = null;
//往期战绩
InfoContestLog = null;
//状态
MyState = 0;
//初始化名字包
function InitRiderNameCallBack(Chunk) {
local Jso = Json.Decode(Chunk);
RiderName = Jso.name;
ResidueCoin = Jso.Max;
BetItem = Jso.itemId;
}
//获取基础配置信息
function GetBaseConfig() {
local T = {
op = 20055001,
}
SendPackEx(T);
}
//获取基础配置信息回调
function GetBaseConfigCallBack(Chunk) {
local Jso = Json.Decode(Chunk);
if (!("Top8" in Jso.Rank)) return;
//同步状态
MyState = Jso.state;
//初始化骑手信息
RiderInfo = [];
RiderInfo = Jso.Rank.Top8;
//写入骑手下注信息
for (local i = 0; i< RiderInfo.len(); i++) {
RiderInfo[i].codeItem <- Jso.codeItem[i];
}
//重置骑手按钮
//构造骑手按钮
InitKnightButton();
//刷新剩余可下注数量
ResidueCoin = Jso.ResidueCoin;
//请求骑士个人信息
this.GetRiderInfo();
}
//获取过往战绩
function GetPastRecord() {
local T = {
op = 20055009,
}
SendPackEx(T);
}
//获取过往战绩回调
function GetPastRecordCallBack(Chunk) {
local Jso = Json.Decode(Chunk);
InfoContestLog = Jso.knights;
}
//获取选手具体信息
function GetRiderInfo() {
local T = {
op = 20055003,
code = NowSelectRider,
}
SendPackEx(T);
}
//获取选手具体信息回调包
function GetRiderInfoCallBack(Chunk) {
local Jso = Json.Decode(Chunk);
RiderInfo[NowSelectRider].outcome <- Jso.outcome;
}
//通知刷新信息包
function NotifyRefreshInfoCallBack(Chunk) {
GetBaseConfig();
}
//动画脚本状态
AnimationAct = 0;
//绘制动画包
function DrawAniInfoCallBack(Chunk) {
local Jso = Json.Decode(Chunk);
AnimationAct = Jso.state;
if (AnimationAct == 2) {
if (CompetitionStartAnimotion) sq_Rewind(CompetitionStartAnimotion);
}
}
//战斗信息
FightInfo = null;
WinnerEffectTimer = null;
//战斗信息包
function FightInfoCallBack(Chunk) {
local Jso = Json.Decode(Chunk);
MyState = Jso.state;
FightInfo = Jso;
if (MyState >= 30) {
WinnerEffectTimer = Clock();
}
}
//获胜者动画
NotiState = false; //公告状态
NotiStr = null; //公告内容
NotiTime = null; //公告时间
function WinnerAniCallBack(Chunk) {
local Jso = Json.Decode(Chunk);
NotiState = true; //公告状态
NotiStr = Jso.Str; //公告内容
NotiTime = Clock();
}
constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
Childrens = [];
Title = [];
RiderInfo = [];
RiderName = [
"伊撒尔",
"理查德",
"席恩",
"吉尔特",
"爱德华",
"罗兰",
"莱奥",
"贝奥武夫",
];
// //读取配置文件
// local Config = R_Utils.ReadScriptConfig("etc/rindro/horseguessing/horseguessing.dat", 1024, "utf8");
// RiderName = Config.RiderInfo;
// BetItem = Config.ItemId;
// //把big的名字 转成 utf8
// for (local i = 0; i< RiderName.len(); i++) {
// RiderName[i] = Sq_ConvertWideChar(RiderName[i], "big5");
// }
//注册控件
RegisterWidget();
Pack_Control.rawset(20055058, InitRiderNameCallBack.bindenv(this));
Pack_Control.rawset(20055002, GetBaseConfigCallBack.bindenv(this));
Pack_Control.rawset(20055010, GetPastRecordCallBack.bindenv(this));
Pack_Control.rawset(20055004, GetRiderInfoCallBack.bindenv(this));
Pack_Control.rawset(20055018, NotifyRefreshInfoCallBack.bindenv(this));
Pack_Control.rawset(20055020, DrawAniInfoCallBack.bindenv(this));
Pack_Control.rawset(20055012, FightInfoCallBack.bindenv(this));
Pack_Control.rawset(20055078, WinnerAniCallBack.bindenv(this));
//获取基础配置
GetBaseConfig();
//获取历史战绩
GetPastRecord();
LenheartNewUI_Windows.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH);
GuidePage = HorseGuessing_GuideC("骑士马战_指引窗口", X + 7, Y + 50, 214, 480, 0);
KnightInfoPage = HorseGuessing_KnightInfoC("骑士马战_资料窗口", X + 7, Y + 50, 214, 480, 0);
PastRecordPage = HorseGuessing_PastRecordC("骑士马战_战绩窗口", X + 7, Y + 50, 214, 480, 0);
//默认构造时切换到0页
ChangePage(0);
}
function ChangePage(ToPage) {
foreach(ButtonObj in Title) {
ButtonObj.State = 0;
}
Page = ToPage;
Title[ToPage].State = 1;
RemoveChild("骑士马战_指引窗口");
RemoveChild("骑士马战_资料窗口");
RemoveChild("骑士马战_战绩窗口");
PageSelectM = ToPage;
switch (ToPage) {
case 0: {
AddChild(GuidePage);
break;
}
case 1: {
AddChild(KnightInfoPage);
break;
}
case 2:
AddChild(PastRecordPage);
break;
}
}
//初始化骑士按钮
function InitKnightButton() {
foreach(pos, v in RiderInfo) {
local KnightButton = HorseGuessingBaseButton(269 + ((pos / 2) * 121) + ((pos % 2) * 59), 398, 36, 42, "interface2/event/chn_event_2016/160927_joustmatches/joustmatches_cha_btn.img", pos * 4);
//如果是偶数需要翻转骑士
if (pos % 2 == 1) {
KnightButton.IsFlip = true;
KnightButton.Localtion_X += 36;
}
KnightButton.Data = v;
KnightButton.OnClickEx = function(Button) {
this.NowSelectRider = Button.Data.code;
ChangePage(1);
//请求骑士个人信息
this.GetRiderInfo();
}.bindenv(this);
KnightButton.SetCallBackFunc(function(Button) {
//是否翻转的偏移
local FlipXOffset = ((Button.IsFlip == true) ? -35 : 0);
local horseKey = ((Button.IsFlip == true) ? "right" : "left");
//绘制旗帜
L_sq_DrawImg("interface2/event/chn_event_2016/160927_joustmatches/joustmatches_ui.img", 11 + Button.Data.code, Button.X - 6 + FlipXOffset, Button.Y + 46);
//绘制赔率信息
local OddsStr = format("%.2f", Button.Data.Odds.tofloat());
L_sq_DrawCode(OddsStr, Button.X + 18 + FlipXOffset - LenheartTextClass.GetStringLength(OddsStr) / 2, Button.Y + 53);
//绘制已投币数量
local codeItem = Button.Data.codeItem.tostring();
L_sq_DrawCode(codeItem, Button.X + 18 + FlipXOffset - LenheartTextClass.GetStringLength(codeItem) / 2, Button.Y + 68);
//绘制框
if (FlipXOffset == -35) FlipXOffset = -37; //傻逼国服美工这个偏移和那个翻转的偏移不一样
L_sq_DrawImg("interface2/event/chn_event_2016/160927_joustmatches/joustmatches_horse_" + horseKey + "_effect.img", Button.Data.code * 2, Button.X + FlipXOffset - 11, Button.Y - 54);
}.bindenv(this));
Childrens.append(KnightButton);
}
}
function RegisterWidget() {
//关闭按钮
local CloseButton = LenheartNewUI_BaseButton(750, 0, 11, 12, "interface/lenheartwindowcommon.img", 276);
CloseButton.OnClick = function() {
this.Visible = false;
}.bindenv(this);
Childrens.append(CloseButton);
local Tabbars1 = LenheartNewUI_TabbarsText(12, 27, "指引");
Tabbars1.State = 1;
AddChild(Tabbars1);
Tabbars1.OnClick = function() {
ChangePage(0);
}.bindenv(this);
Title.append(Tabbars1);
local Tabbars2 = LenheartNewUI_TabbarsText(74, 27, "骑士资料");
AddChild(Tabbars2);
Tabbars2.OnClick = function() {
ChangePage(1);
}.bindenv(this);
Tabbars2.SetTextOffset(7, 3);
Title.append(Tabbars2);
local Tabbars3 = LenheartNewUI_TabbarsText(136, 27, "过往战绩");
AddChild(Tabbars3);
Tabbars3.OnClick = function() {
ChangePage(2);
}.bindenv(this);
Tabbars3.SetTextOffset(7, 3);
Title.append(Tabbars3);
}
function DrawInfo(obj) {
}
//绘制主界面
function DrawMain(obj) {
//绘制窗口
L_sq_DrawImg("interface2/event/chn_event_2016/160927_joustmatches/joustmatches_ui.img", 33, X, Y);
//绘制左边底槽窗口
L_sq_DrawWindow(X + 2, Y + 46, 210, 435, "interface/lenheartwindowcommon.img", 97, 11, 12, 11, 13);
//绘制详情页
DrawInfo(obj);
//BackGround
L_sq_DrawImg("interface2/event/chn_event_2016/160927_joustmatches/joustmatches_ui.img", 0, X + 227, Y + 26);
// L_sq_DrawCode(L_sq_StringBinById(271069), X + 400, Y + 386, sq_RGBA(255, 255, 255, 250), 0, 1);
}
//开始动画
CompetitionStartAnimotion = null;
//绘制动画
function DrawAnimation(obj) {
//绘制321开始
if (AnimationAct == 1) {
CompetitionStartAnimotion = T_DrawDynamicAni(obj, "common/horseguessing/countdown.ani", X + 9 + 287 - 14 + 202, Y + 45 + 237 + 64 - 144, "HorseGuessingCompetitionState8");
}
//绘制战斗
else if (AnimationAct == 2) {
local T = {
count = 4,
x = 282,
y = 346,
x2 = 282,
y2 = 346,
x3 = 282,
y3 = 346,
offset = 122,
}
// if(MyState < 10)
if (MyState >= 10 && MyState< 20) {
T.count = 2;
T.x = 344;
T.y = 222;
T.x2 = 310;
T.y2 = 232;
T.x3 = 380;
T.y3 = 232;
T.offset = 244;
} else if (MyState >= 20) {
T.count = 1;
T.x = 465;
T.y = 54;
T.x2 = 370;
T.y2 = 120;
T.x3 = 560;
T.y3 = 120;
T.offset = 244;
}
for (local i = 0; i< T.count; i++) {
T_DrawDynamicAni(obj, "common/horseguessing/battle.ani", X + T.x + (i * T.offset), Y + T.y, "骑士马战战斗动画文字");
T_DrawDynamicAni(obj, "common/horseguessing/battleleffect.ani", X + T.x2 + (i * T.offset), Y + T.y2, "骑士马战战斗动画左");
T_DrawDynamicAni(obj, "common/horseguessing/battlereffect.ani", X + T.x3 + (i * T.offset), Y + T.y3, "骑士马战战斗动画右");
}
}
//结束绘制
else if (AnimationAct == 3) {
}
}
//绘制骑士和生命值
function DrawKnightAndHpDrawFunction(T, Key) {
foreach(i, value in FightInfo[Key]) {
local DrawX = X + T.x + ((i / 2) * T.offset1) + ((i % 2) * T.offset2);
local DrawY = Y + T.y;
local XRate = (i % 2 == 0 ? 1.0 : -1.0);
local Xoffset = (i % 2 == 0 ? 0 : 36);
L_sq_DrawImg("interface2/event/chn_event_2016/160927_joustmatches/joustmatches_cha_btn.img", value.code * 4, DrawX + Xoffset, DrawY, 1, sq_RGBA(255, 255, 255, 250), XRate, 1.0);
//绘制血条
setClip(DrawX + 2, DrawY - 4, DrawX + 2 + (34.0 * (value.hp.tofloat() / 100.0)).tointeger(), DrawY - 4 + 2);
L_sq_DrawImg("interface2/event/chn_event_2016/160927_joustmatches/joustmatches_ui.img", 2, DrawX + 2, DrawY - 4);
releaseClip();
//绘制胜利线
if (value.win > 0) {
local XXoffset = (i % 2 == 0 ? 0 : -2);
L_sq_DrawImg("interface2/event/chn_event_2016/160927_joustmatches/joustmatches_ui.img", 20 + T.imgoffset, DrawX + XXoffset + T.Xx, DrawY - 65 + T.Xy, 1, sq_RGBA(255, 255, 255, 250), XRate, 1.0);
}
}
}
function DrawKnightAndHp(obj) {
if (!FightInfo) return;
if (MyState > 0) {
local T = {
x = 268,
y = 398,
offset1 = 121,
offset2 = 59,
imgoffset = 0,
Xx = 20,
Xy = 0
}
DrawKnightAndHpDrawFunction(T, "top8");
}
if (MyState >= 10) {
local T = {
x = 298,
y = 287,
offset1 = 242,
offset2 = 122,
imgoffset = 1,
Xx = 19,
Xy = 0
};
DrawKnightAndHpDrawFunction(T, "top4");
}
if (MyState >= 20) {
local T = {
x = 358,
y = 176,
offset1 = 400,
offset2 = 244,
imgoffset = 2,
Xx = 19,
Xy = 7
};
DrawKnightAndHpDrawFunction(T, "top2");
}
if (MyState >= 30) {
local T = {
x = 482,
y = 88,
offset1 = 121,
offset2 = 59,
imgoffset = 1,
Xx = 19,
Xy = 0
};
T_DrawDynamicAni(obj, "common/horseguessing/winnereffect_back.ani", X + T.x, Y + T.y, "骑士马战冠军背景");
DrawKnightAndHpDrawFunction(T, "top1");
T_DrawDynamicAni(obj, "common/horseguessing/winnereffect_front.ani", X + T.x - 15, Y + T.y - 10, "骑士马战冠军特效" + WinnerEffectTimer);
}
}
//绘制公告
function DrawNoti(obj) {
//NotiStr
if (NotiState) {
// print(Clock() - NotiTime);
local A = 0;
if (Clock() - NotiTime< 2000) {
A = sq_GetUniformVelocity(0, 250, Clock() - NotiTime, 2000);
}
if (Clock() - NotiTime >= 2000 && Clock() - NotiTime< 3000) A = 250;
if (Clock() - NotiTime >= 3000) {
A = sq_GetUniformVelocity(250, 0, Clock() - NotiTime, 6000);
}
local Xpos = ((getroottable().Rindro_Scr_Width - 647) / 2).tointeger();
L_sq_DrawImg("interface2/event/chn_event_2016/160927_joustmatches/joustmatches_ui.img", 26, Xpos, 160, 0, sq_RGBA(255, 255, 255, A), 1.0, 1.0);
L_sq_DrawCode(NotiStr, Xpos + 366 - LenheartTextClass.GetStringLength(NotiStr), 160 + 44, sq_RGBA(255, 255, 255, A), 2, 1);
if (Clock() - NotiTime >= 6000) {
NotiState = false;
}
// NotiTime
}
}
function Show(obj) {
DrawMain(obj);
LenheartNewUI_Windows.Show(obj);
DrawAnimation(obj);
DrawKnightAndHp(obj);
}
//逻辑入口
function Proc(obj) {
LenheartNewUI_Windows.SyncPos(X, Y);
//主动调用子对象窗口的Proc
foreach(Object in Childrens) {
if (Object instanceof LenheartNewUI_Windows)
Object.Proc(obj);
}
}
function TopShow(obj) {
DrawNoti(obj);
}
function OpenCallBack() {
this.Visible = true;
ResetFocus();
//获取基础配置
GetBaseConfig();
//获取历史战绩
GetPastRecord();
}
}
getroottable().rawdelete("HorseGuessing_Obj");
function Lenheart_HorseGuessing_Fun(obj) {
local RootTab = getroottable();
if (!RootTab.rawin("HorseGuessing_Obj")) {
RootTab.rawset("HorseGuessing_Obj", true);
local Winobj = LenheartNewUI_CreateWindow(HorseGuessingC, "骑士马战窗口", ((getroottable().Rindro_Scr_Width - 772) / 2).tointeger(), 30, 772, 539, 28);
EventList_Obj.AddEvent("骑士马战", 106, Winobj, "interface2/yosin/eventsystemlist2.img");
}
}
getroottable()["LenheartFuncTab"].rawset("HorseGuessingFuncN", Lenheart_HorseGuessing_Fun);