Rindro-Sqr/Project/DamagePerSecond/DamagePerSecond.nut

195 lines
6.0 KiB
Plaintext
Raw Normal View History

2024-09-16 17:09:36 +08:00
/*
文件名:DamagePerSecond.nut
路径:Project/DamagePerSecond/DamagePerSecond.nut
创建日期:2024-08-31 10:32
文件用途:秒伤统计
*/
//大数字
class longlong {
Value = null;
//构造函数 不管是不是string类型都要转成string类型
constructor(StrValue) {
Value = StrValue.tostring();
}
function _add(other) {
return longlong(L_sq_LongLongOperation(this.Value, other.Value, "+"));
}
function _sub(other) {
return longlong(L_sq_LongLongOperation(this.Value, other.Value, "-"));
}
function _mul(other) {
return longlong(L_sq_LongLongOperation(this.Value, other.Value, "*"));
}
function _div(other) {
return L_sq_LongLongOperation(this.Value, other.Value, "/");
}
function _unm() {
return longlong(L_sq_LongLongOperation(longlong("0"), this.Value, "-"));
}
function _modulo(other) {
return longlong(L_sq_LongLongOperation(this.Value, other.Value, "%"));
}
function GetFormat(FType) {
local Buf = L_sq_LongLongOperation(this.Value, FType, "format");
local Value = Buf.slice(0, -1);
local Unit = Buf.slice(-1);
local RetStr = format(FType + Unit, Value.tofloat());
return RetStr;
}
}
class DamagePerSecondC extends LenheartNewUI_Windows {
//调试模式
// DeBugMode = true;
//不是窗口
NoWindow = true;
//是否可见
// Visible = false;
//伤害统计集合
DamagePerSecondList = null;
//总伤害统计
TotalDamage = longlong(0);
function Sq_PushDamageData(ObjAddress, MySelfAddress, Value) {
local Object = null;
//我自己的伤害
if (ObjAddress == 0 || ObjAddress == MySelfAddress) {
Object = MySelfAddress;
} else {
//先判断是否是角色
if (L_Sq_GetObjectIsCharacter(ObjAddress)) {
Object = ObjAddress;
}
}
if (Object) {
if (DamagePerSecondList.rawin(Object)) {
//如果存在就相加
DamagePerSecondList[Object].Damage = DamagePerSecondList[Object].Damage + longlong(Value);
} else {
//不存在就创建
DamagePerSecondList.rawset(Object, {
Damage = longlong(Value),
Name = L_Sq_GetObjectNameByAddress(Object)
});
}
TotalDamage += longlong(Value);
}
}
constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
Childrens = [];
DamagePerSecondList = {};
// DamagePerSecondList.rawset(0, {
// Name = "测试1",
// Damage = longlong("3002132000321100000")
// });
// DamagePerSecondList.rawset(1, {
// Name = "测试2",
// Damage = longlong("2002313000012310000")
// });
// DamagePerSecondList.rawset(2, {
// Name = "测试3",
// Damage = longlong("10000012121300000")
// });
// DamagePerSecondList.rawset(3, {
// Name = "测试4",
// Damage = longlong("1500012313000000")
// });
// foreach(Oii in DamagePerSecondList) {
// TotalDamage += Oii.Damage;
// }
//注册控件
RegisterWidget();
LenheartNewUI_Windows.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH);
PushDamageFontFuncTab.rawset("DamagePerSecondCFunc", Sq_PushDamageData.bindenv(this));
}
function RegisterWidget() {
// //关闭按钮
// local CloseButton = LenheartNewUI_BaseButton(278, 0, 11, 12, "interface/lenheartwindowcommon.img", 276);
// CloseButton.OnClick = function() {
// this.Visible = false;
// }.bindenv(this);
// Childrens.append(CloseButton);
}
function DrawDamageBar(Pos, DamageObj) {
local Rate = DamageObj.Damage / TotalDamage;
local DamageStr = DamageObj.Damage.GetFormat("%0.2f");
local ShowStr = DamageStr + ", " + format("%.2f", Rate.tofloat() * 100) + "%";
//绘制底
L_sq_DrawImg("hud/dps.img", 3, X + 8, Y + 20 + (Pos * 22));
setClip(X + 8, Y + 20 + (Pos * 22), X + 8 + (160.0 * Rate.tofloat()).tointeger(), Y + 20 + (Pos * 22) + 18);
L_sq_DrawImg("hud/dps.img", 4 + (Pos % 4), X + 8, Y + 20 + (Pos * 22));
releaseClip(); //裁切结束
L_sq_DrawCode(DamageObj.Name, X + 12, Y + 23 + (Pos * 22), sq_RGBA(230, 200, 155, 255), 0, 1);
L_sq_DrawCode(ShowStr, X + 168 - LenheartTextClass.GetStringLength(ShowStr), Y + 23 + (Pos * 22), sq_RGBA(230, 200, 155, 255), 0, 1);
}
//绘制主界面
function DrawMain(obj) {
if (DamagePerSecondList.len() == 0) return;
L_sq_DrawImg("hud/dps.img", 0, X, Y);
for (local i = 0; i<(DamagePerSecondList.len() - 1); i++) {
L_sq_DrawImg("hud/dps.img", 2, X, Y + 41 + (22 * i));
}
L_sq_DrawImg("hud/dps.img", 1, X, Y + 41 + (22 * (DamagePerSecondList.len() - 1)));
local i = 0;
foreach(Object, DamageObj in DamagePerSecondList) {
DrawDamageBar(i, DamageObj);
i++;
}
}
function Show(obj) {
DrawMain(obj);
LenheartNewUI_Windows.Show(obj);
}
//逻辑入口
function Proc(obj) {
LenheartNewUI_Windows.SyncPos(X, Y);
Height = 41 + (22 * (DamagePerSecondList.len() - 1)) + 7;
TitleH = Height;
if (sq_GetCurrentModuleType() == 1 || sq_GetCurrentModuleType() == 2) {
DamagePerSecondList = {};
TotalDamage = longlong(0);
}
}
}
getroottable().rawdelete("DamagePerSecond_Obj");
function Lenheart_DamagePerSecond_Fun(obj) {
local RootTab = getroottable();
if (!RootTab.rawin("DamagePerSecond_Obj")) {
RootTab.rawset("DamagePerSecond_Obj", true);
LenheartNewUI_CreateWindow(DamagePerSecondC, "秒伤统计窗口", 0, 160, 178, 150, 28);
}
}
getroottable()["LenheartFuncTab"].rawset("DamagePerSecondFuncN", Lenheart_DamagePerSecond_Fun);