* 胜率查看
* 录像录制与保存功能(未实装,等完成播放后)
This commit is contained in:
notify 2023-06-27 16:50:24 +08:00 committed by GitHub
parent 2f93f7d59c
commit 3522ea81b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 156 additions and 9 deletions

1
.gitignore vendored
View File

@ -19,6 +19,7 @@
/FreeKill
/FreeKill.exe
/mymod
/recording
freekill-wrap.cxx
/server/users.db
/server/rsa

View File

@ -265,6 +265,7 @@ Item {
function enterRoom(roomId, playerNum, capacity, pw) {
if (playerNum < capacity) {
config.observing = false;
Backend.callLuaFunction("SetObserving", [false]);
mainWindow.busy = true;
ClientInstance.notifyServer(
"EnterRoom",
@ -272,6 +273,7 @@ Item {
);
} else {
config.observing = true;
Backend.callLuaFunction("SetObserving", [true]);
mainWindow.busy = true;
ClientInstance.notifyServer(
"ObserveRoom",

View File

@ -944,8 +944,8 @@ Item {
roomScene.isOwner = d.isOwner;
} else {
Backend.callLuaFunction("ResetAddPlayer", [JSON.stringify([d.id, d.name, d.avatar, d.ready])]);
Backend.callLuaFunction("SetPlayerGameData", [d.id, d.gameData]);
}
Backend.callLuaFunction("SetPlayerGameData", [d.id, d.gameData]);
Logic.getPhotoModel(d.id).isOwner = d.isOwner;
});
}

View File

@ -1291,6 +1291,20 @@ callbacks["UpdateRoundNum"] = (j) => {
roomScene.miscStatus.roundNum = data;
}
callbacks["UpdateGameData"] = (j) => {
const data = JSON.parse(j);
const id = data[0];
const total = data[1];
const win = data[2];
const run = data[3];
const photo = getPhoto(id);
if (photo) {
photo.totalGame = total;
photo.winGame = win;
photo.runGame = run;
}
}
// 神貂蝉
callbacks["StartChangeSelf"] = (j) => {

View File

@ -31,6 +31,10 @@ Item {
property int drank: 0
property bool isOwner: false
property bool ready: false
property int winGame: 0
property int runGame: 0
property int totalGame: 0
property int distance: -1
property string status: "normal"
property int maxCard: 0
@ -246,10 +250,43 @@ Item {
opacity: 0.4 + Math.log(root.drank) * 0.12
}
Image {
Rectangle {
id: winRateRect
width: 138; x: 31
anchors.bottom: parent.bottom
anchors.bottomMargin: 6
height: childrenRect.height + 8
color: "#CC3C3229"
radius: 8
border.color: "white"
border.width: 1
visible: screenName != "" && !roomScene.isStarted
Text {
y: 4
anchors.horizontalCenter: parent.horizontalCenter
font.pixelSize: 20
font.family: fontLibian.name
color: (totalGame > 0 && runGame / totalGame > 0.2) ? "red" : "white"
style: Text.Outline
text: {
if (totalGame === 0) {
return Backend.translate("Newbie");
}
const winRate = (winGame / totalGame) * 100;
const runRate = (runGame / totalGame) * 100;
return Backend.translate("Win=%1\nRun=%2\nTotal=%3")
.arg(winRate.toFixed(2))
.arg(runRate.toFixed(2))
.arg(totalGame);
}
}
}
Image {
anchors.bottom: winRateRect.top
anchors.right: parent.right
anchors.bottomMargin: 8
anchors.bottomMargin: -8
anchors.rightMargin: 4
source: SkinBank.PHOTO_DIR + (isOwner ? "owner" : (ready ? "ready" : "notready"))
visible: screenName != "" && !roomScene.isStarted

View File

@ -8,6 +8,7 @@
---@field public current ClientPlayer
---@field public discard_pile integer[]
---@field public status_skills Skill[]
---@field public observing boolean
Client = class('Client')
-- load client classes
@ -28,7 +29,11 @@ function Client:initialize()
self.notifyUI = function(self, command, jsonData)
fk.Backend:emitNotifyUI(command, jsonData)
end
self.client.callback = function(_self, command, jsonData)
self.client.callback = function(_self, command, jsonData, isRequest)
if self.recording and not self.observing then
table.insert(self.record, {os.getms() / 1000, isRequest, command, jsonData})
end
local cb = fk.client_callback[command]
if table.contains(pattern_refresh_commands, command) then
@ -57,6 +62,8 @@ function Client:initialize()
self.filtered_cards = {}
self.disabled_packs = {}
self.disabled_generals = {}
self.recording = false
end
---@param id integer
@ -780,6 +787,64 @@ fk.client_callback["UpdateGameData"] = function(jsonData)
if player then
player.player:setGameData(total, win, run)
end
ClientInstance:notifyUI("UpdateGameData", jsonData)
end
fk.client_callback["StartGame"] = function(jsonData)
local c = ClientInstance
c.record = { fk.FK_VER, os.date("%Y%m%d%H%M%S") }
for _, p in ipairs(c.players) do
if p.id ~= Self.id then
table.insert(c.record, {
os.getms() / 100,
false,
"AddPlayer",
json.encode {
p.player:getId(),
p.player:getScreenName(),
p.player:getAvatar(),
true,
},
})
end
end
c.recording = true
c:notifyUI("StartGame", jsonData)
end
fk.client_callback["GameOver"] = function(jsonData)
local c = ClientInstance
if c.recording and not c.observing then
c.recording = false
c.record[2] = table.concat({
c.record[2],
Self.player:getScreenName(),
c.room_settings.gameMode,
Self.general,
Self.role,
jsonData,
}, ".")
-- c.client:saveRecord(json.encode(c.record), c.record[2])
end
c:notifyUI("GameOver", jsonData)
end
fk.client_callback["EnterLobby"] = function(jsonData)
local c = ClientInstance
if c.recording and not c.observing then
c.recording = false
c.record[2] = table.concat({
c.record[2],
Self.player:getScreenName(),
c.room_settings.gameMode,
Self.general,
Self.role,
"",
}, ".")
-- c.client:saveRecord(json.encode(c.record), c.record[2])
end
c:notifyUI("EnterLobby", jsonData)
end
-- Create ClientInstance (used by Lua)

View File

@ -612,10 +612,16 @@ function SetPlayerGameData(pid, data)
local c = ClientInstance
local p = c:getPlayerById(pid)
p.player:setGameData(table.unpack(data))
table.insert(data, 1, pid)
ClientInstance:notifyUI("UpdateGameData", json.encode(data))
end
function FilterMyHandcards()
Self:filterHandcards()
end
function SetObserving(o)
ClientInstance.observing = o
end
dofile "lua/client/i18n/init.lua"

View File

@ -57,6 +57,7 @@ Fk:loadTranslationTable{
["Kick From Room"] = "踢出房间",
["Newbie"] = "新手保护ing",
["Win=%1 Run=%2 Total=%3"] = "胜率%1% 逃率%2% 总场次%3",
["Win=%1\nRun=%2\nTotal=%3"] = "胜率: %1%\n逃率: %2%\n总场次: %3",
["$OnlineInfo"] = "大厅人数:%1总在线人数%2",

View File

@ -2860,6 +2860,9 @@ local function shouldUpdateWinRate(room)
if room.settings.gameMode == "aaa_role_mode" and #room.players < 5 then
return false
end
if room.settings.enableFreeAssign then
return false
end
for _, p in ipairs(room.players) do
if p.id < 0 then return false end
end

View File

@ -79,3 +79,13 @@ void Client::changeSelf(int id) {
lua_State *Client::getLuaState() { return L; }
void Client::installAESKey(const QByteArray &key) { router->installAESKey(key); }
void Client::saveRecord(const QString &json, const QString &fname) {
if (!QDir("recording").exists()) {
QDir(".").mkdir("recording");
}
QFile c("recording/" + fname + ".fk.rep");
c.open(QIODevice::WriteOnly);
c.write(qCompress(json.toUtf8()));
c.close();
}

View File

@ -21,7 +21,7 @@ public:
Q_INVOKABLE void replyToServer(const QString &command, const QString &jsonData);
Q_INVOKABLE void notifyServer(const QString &command, const QString &jsonData);
Q_INVOKABLE void callLua(const QString &command, const QString &jsonData);
Q_INVOKABLE void callLua(const QString &command, const QString &jsonData, bool isRequest = false);
LuaFunction callback;
ClientPlayer *addPlayer(int id, const QString &name, const QString &avatar);
@ -32,6 +32,7 @@ public:
lua_State *getLuaState();
void installAESKey(const QByteArray &key);
void saveRecord(const QString &json, const QString &fname);
signals:
void error_message(const QString &msg);

View File

@ -258,7 +258,7 @@ void Router::handlePacket(const QByteArray &rawPacket) {
if (type & TYPE_NOTIFICATION) {
if (type & DEST_CLIENT) {
#ifndef FK_SERVER_ONLY
ClientInstance->callLua(command, jsonData);
ClientInstance->callLua(command, jsonData, false);
#endif
}
#ifndef FK_CLIENT_ONLY
@ -301,7 +301,7 @@ void Router::handlePacket(const QByteArray &rawPacket) {
if (type & DEST_CLIENT) {
#ifndef FK_SERVER_ONLY
qobject_cast<Client *>(parent())->callLua(command, jsonData);
qobject_cast<Client *>(parent())->callLua(command, jsonData, true);
#endif
} else {
// requesting server is not allowed

View File

@ -27,12 +27,14 @@ public:
ClientPlayer *addPlayer(int id, const QString &name, const QString &avatar);
void removePlayer(int id);
void changeSelf(int id);
void saveRecord(const QString &json, const QString &fname);
};
extern Client *ClientInstance;
%{
void Client::callLua(const QString& command, const QString& json_data)
void Client::callLua(const QString& command, const QString& json_data, bool isRequest)
{
Q_ASSERT(callback);
@ -44,8 +46,9 @@ void Client::callLua(const QString& command, const QString& json_data)
SWIG_NewPointerObj(L, this, SWIGTYPE_p_Client, 0);
lua_pushstring(L, command.toUtf8());
lua_pushstring(L, json_data.toUtf8());
lua_pushboolean(L, isRequest);
int error = lua_pcall(L, 3, 0, -5);
int error = lua_pcall(L, 4, 0, -6);
if (error) {
const char *error_msg = lua_tostring(L, -1);

View File

@ -11,6 +11,8 @@
#include "roomthread.h"
#include "qmlbackend.h"
#include "util.h"
const char *FK_VER = FK_VERSION;
%}
%include "naturalvar.i"
@ -18,3 +20,5 @@
%include "player.i"
%include "client.i"
%include "server.i"
extern char *FK_VER;