mirror of
https://github.com/Qsgs-Fans/FreeKill.git
synced 2024-11-16 11:42:45 +08:00
Compare commits
7 Commits
495c08cb0f
...
271001c562
Author | SHA1 | Date | |
---|---|---|---|
|
271001c562 | ||
|
d5832b824b | ||
|
d11bf58cb4 | ||
|
d94b483f66 | ||
|
5090bdba77 | ||
|
4235bf6237 | ||
|
ebc5675ead |
5
.github/workflows/build-android.yml
vendored
5
.github/workflows/build-android.yml
vendored
|
@ -85,7 +85,10 @@ jobs:
|
|||
cd assets/res
|
||||
cp -r /etc/ssl/certs .
|
||||
cp /usr/share/ca-certificates/mozilla/* certs/
|
||||
echo ${FKVER%)} > fk_ver
|
||||
cd ../..
|
||||
echo ${FKVER%)} > ../fk_ver
|
||||
../genfkver.sh
|
||||
cp ../fk_ver assets/res
|
||||
|
||||
- name: Configure CMake Project
|
||||
working-directory: ${{github.workspace}}
|
||||
|
|
1
.github/workflows/build-windows.yml
vendored
1
.github/workflows/build-windows.yml
vendored
|
@ -77,6 +77,7 @@ jobs:
|
|||
cp lib/win/* FreeKill-release
|
||||
cp build/zh_CN.qm FreeKill-release
|
||||
cp build/en_US.qm FreeKill-release
|
||||
cp fk_ver FreeKill-release
|
||||
cp ../Qt/6.5.3/mingw_64/bin/li*.dll FreeKill-release
|
||||
cp ../Qt/Tools/OpenSSLv3/Win_x64/bin/libcrypto-3-x64.dll FreeKill-release
|
||||
7z a -t7z FreeKill-release.7z FreeKill-release -r -mx=9 -m0=LZMA2 -ms=10m -mf=on -mhc=on -mmt=on
|
||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -15,6 +15,7 @@
|
|||
/*.kdev4
|
||||
/.cache/
|
||||
/tags
|
||||
/.luarc.json
|
||||
|
||||
# file produced by game
|
||||
/FreeKill
|
||||
|
|
33
CHANGELOG.md
33
CHANGELOG.md
|
@ -1,5 +1,38 @@
|
|||
# ChangeLog
|
||||
|
||||
## v0.4.16 & v0.4.17
|
||||
|
||||
在引入freekill-core之后的第一次版本更新,甚至无法保证这次更新是否正常
|
||||
|
||||
UI是半成品,0.4.17修复各种爆炸以及半成品UI稍微人性化一点
|
||||
|
||||
1. 改进processPrompt,支持双将和暗将
|
||||
2. 副将长名旋转
|
||||
3. 国战体力上限优化,包括一览和选将框
|
||||
4. 空格添加结束出牌阶段,Escape键呼出菜单
|
||||
5. 武将一览左栏文本换行
|
||||
6. 同名替换影响已选择的武将
|
||||
7. 再次排序手牌时按照点数排序
|
||||
8. Logic.js翻译
|
||||
9. 进入房间翻译删去句号,跟房间内其他toast风格统一
|
||||
10. 常见疑问最后一张“下一条”改为“OK!”
|
||||
11. 录像回放“从文件打开”翻译
|
||||
12. interaction自动弹出和关闭,comboBox补技能名
|
||||
13. 卡牌音效添加装备效果音效和使用音效,小小重构
|
||||
14. activeSkill的prompt的selected_targets实装
|
||||
15. 禁用扩展包文本ui限制长度
|
||||
16. 右键技能呼出气泡
|
||||
17. 搬运了ArrangeCards。
|
||||
18. 优化了GuanxingBox的操作
|
||||
19. 修复了不能及时更新技能prompt的bug
|
||||
20. 取消目标后会刷新目标选择
|
||||
21. 完备了借刀的牌名
|
||||
22. CPP代码进行大的重构,配有少量文档
|
||||
23. (底层)调度机制大改
|
||||
24. 大厅UI开始调整,但是仍未完工
|
||||
|
||||
___
|
||||
|
||||
## v0.4.13 & 14 & 15
|
||||
|
||||
- 优化重连逻辑
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(FreeKill VERSION 0.4.15)
|
||||
project(FreeKill VERSION 0.4.17)
|
||||
add_definitions(-DFK_VERSION=\"${CMAKE_PROJECT_VERSION}\")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS
|
||||
|
@ -39,11 +39,6 @@ include_directories(include/lua)
|
|||
include_directories(include)
|
||||
include_directories(include/libgit2)
|
||||
include_directories(src)
|
||||
include_directories(src/client)
|
||||
include_directories(src/core)
|
||||
include_directories(src/network)
|
||||
include_directories(src/server)
|
||||
include_directories(src/ui)
|
||||
|
||||
file(GLOB SWIG_FILES "${PROJECT_SOURCE_DIR}/src/swig/*.i")
|
||||
if (DEFINED FK_SERVER_ONLY)
|
||||
|
@ -78,6 +73,7 @@ add_custom_command(
|
|||
POST_BUILD
|
||||
COMMENT "Generating version file fk_ver"
|
||||
COMMAND echo ${CMAKE_PROJECT_VERSION} > ${PROJECT_SOURCE_DIR}/fk_ver
|
||||
COMMAND ${PROJECT_SOURCE_DIR}/genfkver.sh
|
||||
)
|
||||
|
||||
add_subdirectory(src)
|
||||
|
|
|
@ -40,8 +40,13 @@ Flickable {
|
|||
|
||||
extra_data.generals.forEach((g) => {
|
||||
const data = lcall("GetGeneralDetail", g);
|
||||
skillDesc.append(luatr(data.kingdom) + " " + luatr(g) + " " + data.hp +
|
||||
"/" + data.maxHp);
|
||||
skillDesc.append(luatr(data.kingdom) + " " + luatr(g) + " " + (data.hp === data.maxHp
|
||||
? ((g.startsWith('hs__') || g.startsWith('ld__') || g.includes('heg__'))
|
||||
? ((data.mainMaxHp != 0 || data.deputyMaxHp != 0)
|
||||
? ((data.hp + data.mainMaxHp) / 2 + '/' + (data.hp + data.deputyMaxHp) / 2)
|
||||
: data.hp / 2)
|
||||
: data.hp)
|
||||
: data.hp + "/" + data.maxHp));
|
||||
if (data.companions.length > 0){
|
||||
let ret = '';
|
||||
ret +="<font color=\"slategrey\"><b>" + luatr("Companions") + "</b>: ";
|
||||
|
|
|
@ -50,6 +50,16 @@ Item {
|
|||
if (idx < extra_data.cards.count) {
|
||||
extra_data.cards.set(idx, { name: modelData });
|
||||
}
|
||||
|
||||
idx = 0;
|
||||
extra_data.choices.forEach( s => {
|
||||
if (s === gname) {
|
||||
extra_data.choices[idx] = modelData;
|
||||
return;
|
||||
}
|
||||
idx++;
|
||||
});
|
||||
|
||||
root.finish();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,8 @@ QtObject {
|
|||
property string password: ""
|
||||
property string cipherText
|
||||
property string aeskey
|
||||
// string => { roomId => config }
|
||||
property var roomConfigCache: ({})
|
||||
|
||||
// Client data
|
||||
property string serverMotd: ""
|
||||
|
|
|
@ -184,6 +184,12 @@ Item {
|
|||
return ret;
|
||||
}
|
||||
delegate: Text {
|
||||
width: parent.width / 2
|
||||
wrapMode: Text.WordWrap
|
||||
fontSizeMode: Text.HorizontalFit
|
||||
minimumPixelSize: 14
|
||||
elide: Text.ElideRight
|
||||
height: 24
|
||||
text: luatr(modelData)
|
||||
font.pixelSize: 16
|
||||
}
|
||||
|
|
19
Fk/Logic.js
19
Fk/Logic.js
|
@ -81,6 +81,25 @@ callbacks["ErrorMsg"] = (jsonData) => {
|
|||
}
|
||||
}
|
||||
|
||||
callbacks["ErrorDlg"] = (jsonData) => {
|
||||
let log;
|
||||
try {
|
||||
const a = JSON.parse(jsonData);
|
||||
log = qsTr(a[0]).arg(a[1]);
|
||||
} catch (e) {
|
||||
log = qsTr(jsonData);
|
||||
}
|
||||
|
||||
console.log("ERROR: " + log);
|
||||
Backend.showDialog("warning", log, jsonData);
|
||||
mainWindow.busy = false;
|
||||
if (sheduled_download !== "") {
|
||||
mainWindow.busy = true;
|
||||
Pacman.loadSummary(JSON.stringify(sheduled_download), true);
|
||||
sheduled_download = "";
|
||||
}
|
||||
}
|
||||
|
||||
callbacks["UpdatePackage"] = (jsonData) => sheduled_download = jsonData;
|
||||
|
||||
callbacks["UpdateBusyText"] = (jsonData) => {
|
||||
|
|
|
@ -289,18 +289,29 @@ Item {
|
|||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: {
|
||||
if (gender === "male") {
|
||||
if (audioType === "male") {
|
||||
return luatr("Male Audio");
|
||||
} else {
|
||||
} else if (audioType === "female") {
|
||||
return luatr("Female Audio");
|
||||
} else if (audioType === "equip_effect") {
|
||||
return luatr("Equip Effect Audio");
|
||||
} {
|
||||
return luatr("Equip Use Audio");
|
||||
}
|
||||
}
|
||||
font.pixelSize: 14
|
||||
}
|
||||
onClicked: {
|
||||
const data = lcall("GetCardData", cardDetail.cid);
|
||||
Backend.playSound("./packages/" + extension + "/audio/card/"
|
||||
+ gender + "/" + data.name);
|
||||
if (audioType === "male" || audioType === "female") {
|
||||
Backend.playSound("./packages/" + extension + "/audio/card/"
|
||||
+ audioType + "/" + data.name);
|
||||
} else if (audioType === "equip_effect") {
|
||||
Backend.playSound("./packages/" + extension + "/audio/card/"
|
||||
+ "/" + data.name);
|
||||
} else {
|
||||
Backend.playSound("./audio/card/common/" + extension);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -317,27 +328,41 @@ Item {
|
|||
}
|
||||
}
|
||||
|
||||
function loadAudio(cardName, type, extension, orig_extension) {
|
||||
const prefix = AppPath + "/packages/";
|
||||
const suffix = cardName + ".mp3";
|
||||
let midfix = type + "/";
|
||||
if (type === "equip_effect") {
|
||||
midfix = "";
|
||||
}
|
||||
let fname = prefix + extension + "/audio/card/" + midfix + suffix;
|
||||
if (Backend.exists(fname)) {
|
||||
audioRow.append( { audioType: type, extension: extension } );
|
||||
} else {
|
||||
fname = prefix + orig_extension + "/audio/card/" + midfix + suffix;
|
||||
if (Backend.exists(fname)) {
|
||||
audioRow.append( { audioType: type, extension: orig_extension} );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addCardAudio(card) {
|
||||
const extension = card.extension;
|
||||
const orig_extension = lcall("GetCardExtensionByName", card.name);
|
||||
const prefix = AppPath + "/packages/";
|
||||
const suffix = card.name + ".mp3";
|
||||
let fname = prefix + extension + "/audio/card/male/" + suffix;
|
||||
if (Backend.exists(fname)) {
|
||||
audioRow.append( { gender: "male", extension: extension } );
|
||||
} else {
|
||||
fname = prefix + orig_extension + "/audio/card/male/" + suffix;
|
||||
if (Backend.exists(fname)) {
|
||||
audioRow.append( {gender: "male", extension: orig_extension} );
|
||||
}
|
||||
}
|
||||
fname = prefix + extension + "/audio/card/female/" + suffix;
|
||||
if (Backend.exists(fname)) {
|
||||
audioRow.append( { gender: "female", extension: extension } );
|
||||
}else {
|
||||
fname = prefix + orig_extension + "/audio/card/female/" + suffix;
|
||||
if (Backend.exists(fname)) {
|
||||
audioRow.append( { gender: "female", extension: orig_extension } );
|
||||
loadAudio(card.name, "male", extension, orig_extension);
|
||||
loadAudio(card.name, "female", extension, orig_extension);
|
||||
if (audioRow.count === 0 && card.type === 3) {
|
||||
loadAudio(card.name, "equip_effect", extension, orig_extension);
|
||||
if (audioRow.count === 0) {
|
||||
let subType = "";
|
||||
if (card.subtype === "defensive_horse" || card.subtype === "offensive_horse") {
|
||||
subType = "horse";
|
||||
} else if (card.subtype === "weapon") {
|
||||
subType = "weapon";
|
||||
} else {
|
||||
subType = "armor";
|
||||
}
|
||||
audioRow.append( { audioType: "equip_use", extension: subType } );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -503,6 +503,8 @@ Item {
|
|||
|
||||
Item {
|
||||
id: generalInfo
|
||||
x: 5
|
||||
y: 10
|
||||
width: 150
|
||||
ColumnLayout {
|
||||
width: parent.width
|
||||
|
@ -516,6 +518,7 @@ Item {
|
|||
|
||||
Text {
|
||||
Layout.fillWidth: true
|
||||
wrapMode: Text.WordWrap
|
||||
textFormat: TextEdit.RichText
|
||||
font.pixelSize: 16
|
||||
function trans(str) {
|
||||
|
|
|
@ -107,6 +107,7 @@ Item {
|
|||
}
|
||||
|
||||
Text {
|
||||
id: faqTxt
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.rightMargin: 8
|
||||
|
@ -123,6 +124,24 @@ Item {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.right: faqTxt.left
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.rightMargin: 8
|
||||
anchors.bottomMargin: 8
|
||||
text: qsTr("ResFix")
|
||||
color: "blue"
|
||||
font.pixelSize: 24
|
||||
font.underline: true
|
||||
visible: OS === "Android"
|
||||
|
||||
TapHandler {
|
||||
onTapped: {
|
||||
Backend.askFixResource();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -183,17 +202,6 @@ Item {
|
|||
}
|
||||
}
|
||||
|
||||
// Temp
|
||||
Button {
|
||||
text: qsTr("Making Mod")
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
visible: Debugging
|
||||
onClicked: {
|
||||
mainStack.push(modMaker);
|
||||
}
|
||||
}
|
||||
|
||||
function downloadComplete() {
|
||||
toast.show(qsTr("updated packages for md5"));
|
||||
}
|
||||
|
|
|
@ -11,112 +11,151 @@ import "Logic.js" as Logic
|
|||
Item {
|
||||
id: root
|
||||
property alias roomModel: roomModel
|
||||
property var roomInfoCache: ({})
|
||||
|
||||
property string password
|
||||
|
||||
Rectangle {
|
||||
width: parent.width / 2 - roomListLayout.width / 2 - 50
|
||||
height: parent.height * 0.7
|
||||
anchors.top: exitButton.bottom
|
||||
anchors.bottom: createRoomButton.top
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 20
|
||||
color: "#88EEEEEE"
|
||||
radius: 6
|
||||
Component {
|
||||
id: roomDelegate
|
||||
|
||||
Flickable {
|
||||
id: flickableContainer
|
||||
ScrollBar.vertical: ScrollBar {}
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: 10
|
||||
flickableDirection: Flickable.VerticalFlick
|
||||
width: parent.width - 10
|
||||
height: parent.height - 10
|
||||
contentHeight: bulletin_info.height
|
||||
clip: true
|
||||
Rectangle {
|
||||
radius: 8
|
||||
height: 124 - 8
|
||||
width: 124 - 8
|
||||
color: outdated ? "#E2E2E2" : "#DDDDDDDD"
|
||||
|
||||
Text {
|
||||
id: bulletin_info
|
||||
width: parent.width
|
||||
wrapMode: TextEdit.WordWrap
|
||||
textFormat: Text.MarkdownText
|
||||
text: config.serverMotd + "\n___\n" + luatr('Bulletin Info')
|
||||
onLinkActivated: Qt.openUrlExternally(link);
|
||||
id: roomNameText
|
||||
horizontalAlignment: Text.AlignLeft
|
||||
width: parent.width - 16
|
||||
height: contentHeight
|
||||
maximumLineCount: 2
|
||||
wrapMode: Text.WrapAnywhere
|
||||
textFormat: Text.PlainText
|
||||
text: roomName
|
||||
// color: outdated ? "gray" : "black"
|
||||
font.pixelSize: 16
|
||||
// elide: Label.ElideRight
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
anchors.margins: 8
|
||||
}
|
||||
|
||||
Text {
|
||||
id: roomIdText
|
||||
text: luatr(gameMode) + ' #' + roomId
|
||||
anchors.top: roomNameText.bottom
|
||||
anchors.left: roomNameText.left
|
||||
}
|
||||
|
||||
Image {
|
||||
source: AppPath + "/image/button/skill/locked.png"
|
||||
visible: hasPassword
|
||||
scale: 0.8
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.margins: -4
|
||||
}
|
||||
|
||||
Text {
|
||||
color: (playerNum == capacity) ? "red" : "black"
|
||||
text: playerNum + "/" + capacity
|
||||
font.pixelSize: 18
|
||||
font.bold: true
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: 8
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 8
|
||||
}
|
||||
|
||||
TapHandler {
|
||||
gesturePolicy: TapHandler.WithinBounds
|
||||
enabled: !opTimer.running && !outdated
|
||||
|
||||
onTapped: {
|
||||
lobby_dialog.sourceComponent = roomDetailDialog;
|
||||
lobby_dialog.item.roomData = {
|
||||
roomId, roomName, gameMode, playerNum, capacity,
|
||||
hasPassword, outdated,
|
||||
};
|
||||
lobby_dialog.item.roomConfig = config.roomConfigCache?.[config.serverAddr]?.[roomId]
|
||||
lobby_drawer.open();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: roomDelegate
|
||||
id: roomDetailDialog
|
||||
ColumnLayout {
|
||||
property var roomData: ({
|
||||
roomName: "",
|
||||
hasPassword: true,
|
||||
})
|
||||
property var roomConfig: undefined
|
||||
signal finished()
|
||||
anchors.fill: parent
|
||||
anchors.margins: 16
|
||||
|
||||
Item {
|
||||
height: 48
|
||||
width: roomList.width
|
||||
Text {
|
||||
text: roomData.roomName
|
||||
font.pixelSize: 18
|
||||
}
|
||||
|
||||
Text {
|
||||
font.pixelSize: 18
|
||||
text: {
|
||||
let ret = luatr(roomData.gameMode);
|
||||
ret += (' #' + roomData.roomId);
|
||||
ret += (' ' + roomData.playerNum + '/' + roomData.capacity);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
Item { Layout.fillHeight: true }
|
||||
|
||||
// Dummy
|
||||
Text {
|
||||
text: "在未来的版本中这一块区域将增加更多实用的功能,<br>"+
|
||||
"例如直接查看房间的各种配置信息<br>"+
|
||||
"以及更多与禁将有关的实用功能!"+
|
||||
"<font color='gray'>注:绿色按钮为试做型UI 后面优化</font>"
|
||||
font.pixelSize: 18
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
anchors.fill: parent
|
||||
spacing: 16
|
||||
Layout.fillWidth: true
|
||||
Text {
|
||||
text: roomId
|
||||
color: "grey"
|
||||
visible: roomData.hasPassword
|
||||
text: luatr("Please input room's password")
|
||||
}
|
||||
|
||||
Text {
|
||||
horizontalAlignment: Text.AlignLeft
|
||||
TextField {
|
||||
id: passwordEdit
|
||||
visible: roomData.hasPassword
|
||||
Layout.fillWidth: true
|
||||
text: {
|
||||
let ret = roomName;
|
||||
if (outdated) {
|
||||
ret = '<font color="grey"><del>' + ret + '</del></font>';
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
font.pixelSize: 20
|
||||
elide: Label.ElideRight
|
||||
onTextChanged: root.password = text;
|
||||
}
|
||||
|
||||
Item {
|
||||
Layout.preferredWidth: 16
|
||||
Image {
|
||||
source: AppPath + "/image/button/skill/locked.png"
|
||||
visible: hasPassword
|
||||
anchors.centerIn: parent
|
||||
scale: 0.8
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
text: luatr(gameMode)
|
||||
}
|
||||
|
||||
Text {
|
||||
color: (playerNum == capacity) ? "red" : "black"
|
||||
text: playerNum + "/" + capacity
|
||||
font.pixelSize: 20
|
||||
font.bold: true
|
||||
visible: !roomData.hasPassword
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
Button {
|
||||
text: (playerNum < capacity) ? luatr("Enter") :
|
||||
luatr("Observe")
|
||||
|
||||
enabled: !opTimer.running && !outdated
|
||||
|
||||
// text: "OK"
|
||||
text: (roomData.playerNum < roomData.capacity) ? luatr("Enter") : luatr("Observe")
|
||||
onClicked: {
|
||||
opTimer.start();
|
||||
if (hasPassword) {
|
||||
lobby_dialog.sourceComponent = enterPassword;
|
||||
lobby_dialog.item.roomId = roomId;
|
||||
lobby_dialog.item.playerNum = playerNum;
|
||||
lobby_dialog.item.capacity = capacity;
|
||||
lobby_drawer.open();
|
||||
} else {
|
||||
enterRoom(roomId, playerNum, capacity, "");
|
||||
}
|
||||
enterRoom(roomData.roomId, roomData.playerNum, roomData.capacity,
|
||||
roomData.hasPassword ? root.password : "");
|
||||
lobby_dialog.item.finished();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
passwordEdit.text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,8 +163,7 @@ Item {
|
|||
id: roomModel
|
||||
}
|
||||
|
||||
PersonalSettings {
|
||||
}
|
||||
PersonalSettings {}
|
||||
|
||||
Timer {
|
||||
id: opTimer
|
||||
|
@ -134,69 +172,132 @@ Item {
|
|||
|
||||
ColumnLayout {
|
||||
id: roomListLayout
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: 10
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
width: root.width * 0.48
|
||||
height: root.height - 80
|
||||
Button {
|
||||
Layout.alignment: Qt.AlignRight
|
||||
text: luatr("Refresh Room List")
|
||||
enabled: !opTimer.running
|
||||
onClicked: {
|
||||
opTimer.start();
|
||||
ClientInstance.notifyServer("RefreshRoomList", "");
|
||||
height: root.height - 72
|
||||
y: 16
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: root.width * 0.03 + root.width * 0.94 * 0.8 % 128 / 2
|
||||
width: {
|
||||
let ret = root.width * 0.94 * 0.8;
|
||||
ret -= ret % 128;
|
||||
return ret;
|
||||
}
|
||||
clip: true
|
||||
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
Item { Layout.fillWidth: true }
|
||||
Button {
|
||||
Layout.alignment: Qt.AlignRight
|
||||
text: luatr("Refresh Room List").arg(roomModel.count)
|
||||
enabled: !opTimer.running
|
||||
onClicked: {
|
||||
opTimer.start();
|
||||
ClientInstance.notifyServer("RefreshRoomList", "");
|
||||
}
|
||||
}
|
||||
Button {
|
||||
text: luatr("Create Room")
|
||||
onClicked: {
|
||||
lobby_dialog.sourceComponent =
|
||||
Qt.createComponent("../LobbyElement/CreateRoom.qml");
|
||||
lobby_drawer.open();
|
||||
config.observing = false;
|
||||
config.replaying = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
|
||||
GridView {
|
||||
id: roomList
|
||||
cellWidth: 128
|
||||
cellHeight: 128
|
||||
Layout.fillHeight: true
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
anchors.centerIn: parent
|
||||
color: "#88EEEEEE"
|
||||
radius: 16
|
||||
Text {
|
||||
width: parent.width
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: luatr("Room List").arg(roomModel.count)
|
||||
}
|
||||
ListView {
|
||||
id: roomList
|
||||
height: parent.height * 0.9
|
||||
width: parent.width * 0.95
|
||||
contentHeight: roomDelegate.height * count
|
||||
ScrollBar.vertical: ScrollBar {}
|
||||
anchors.centerIn: parent
|
||||
delegate: roomDelegate
|
||||
clip: true
|
||||
model: roomModel
|
||||
}
|
||||
}
|
||||
Layout.fillWidth: true
|
||||
ScrollBar.vertical: ScrollBar {}
|
||||
delegate: roomDelegate
|
||||
clip: true
|
||||
model: roomModel
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
id: createRoomButton
|
||||
anchors.bottom: buttonRow.top
|
||||
Rectangle {
|
||||
id: serverInfoLayout
|
||||
height: root.height - 112
|
||||
y: 56
|
||||
width: root.width * 0.94 * 0.2
|
||||
anchors.right: parent.right
|
||||
width: 120
|
||||
display: AbstractButton.TextUnderIcon
|
||||
icon.name: "media-playback-start"
|
||||
text: luatr("Create Room")
|
||||
onClicked: {
|
||||
lobby_dialog.sourceComponent =
|
||||
Qt.createComponent("../LobbyElement/CreateRoom.qml");
|
||||
lobby_drawer.open();
|
||||
config.observing = false;
|
||||
config.replaying = false;
|
||||
anchors.rightMargin: root.width * 0.03
|
||||
// anchors.horizontalCenter: parent.horizontalCenter
|
||||
color: "#88EEEEEE"
|
||||
property bool chatShown: true
|
||||
|
||||
Flickable {
|
||||
ScrollBar.vertical: ScrollBar {}
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: 10
|
||||
flickableDirection: Flickable.VerticalFlick
|
||||
width: parent.width - 10
|
||||
height: parent.height - 10 - (parent.chatShown ? 200 : 0)
|
||||
contentHeight: bulletin_info.height
|
||||
clip: true
|
||||
|
||||
Text {
|
||||
id: bulletin_info
|
||||
width: parent.width
|
||||
wrapMode: TextEdit.WordWrap
|
||||
textFormat: Text.MarkdownText
|
||||
text: config.serverMotd + "\n\n___\n\n" + luatr('Bulletin Info')
|
||||
onLinkActivated: Qt.openUrlExternally(link);
|
||||
}
|
||||
}
|
||||
|
||||
MetroButton {
|
||||
text: "🗨️" + (parent.chatShown ? "➖" : "➕")
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.bottom: lobbyChat.top
|
||||
onClicked: {
|
||||
parent.chatShown = !parent.chatShown
|
||||
}
|
||||
}
|
||||
|
||||
ChatBox {
|
||||
id: lobbyChat
|
||||
width: parent.width
|
||||
height: parent.chatShown ? 200 : 0
|
||||
Behavior on height { NumberAnimation { duration: 200 } }
|
||||
anchors.bottom: parent.bottom
|
||||
isLobby: true
|
||||
color: "#88EEEEEE"
|
||||
clip: true
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
id: buttonRow
|
||||
anchors.right: parent.right
|
||||
anchors.left: parent.left
|
||||
anchors.bottom: parent.bottom
|
||||
width: parent.width
|
||||
|
||||
Rectangle {
|
||||
Layout.fillHeight: true
|
||||
Layout.preferredWidth: childrenRect.width + 72
|
||||
|
||||
gradient: Gradient {
|
||||
orientation: Gradient.Horizontal
|
||||
GradientStop { position: 0.8; color: "white" }
|
||||
GradientStop { position: 1.0; color: "transparent" }
|
||||
}
|
||||
Text {
|
||||
x: 16; y: 4
|
||||
font.pixelSize: 16
|
||||
text: luatr("$OnlineInfo")
|
||||
.arg(lobbyPlayerNum).arg(serverPlayerNum) + "\n"
|
||||
+ "Powered by FreeKill " + FkVersion
|
||||
}
|
||||
}
|
||||
|
||||
Item { Layout.fillWidth: true }
|
||||
Button {
|
||||
text: luatr("Generals Overview")
|
||||
onClicked: {
|
||||
|
@ -276,39 +377,6 @@ Item {
|
|||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: enterPassword
|
||||
ColumnLayout {
|
||||
property int roomId
|
||||
property int playerNum
|
||||
property int capacity
|
||||
signal finished()
|
||||
anchors.fill: parent
|
||||
anchors.margins: 16
|
||||
|
||||
Text {
|
||||
text: luatr("Please input room's password")
|
||||
}
|
||||
|
||||
TextField {
|
||||
id: passwordEdit
|
||||
onTextChanged: root.password = text;
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "OK"
|
||||
onClicked: {
|
||||
enterRoom(roomId, playerNum, capacity, root.password);
|
||||
parent.finished();
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
passwordEdit.text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function enterRoom(roomId, playerNum, capacity, pw) {
|
||||
config.replaying = false;
|
||||
if (playerNum < capacity) {
|
||||
|
@ -333,40 +401,15 @@ Item {
|
|||
property int lobbyPlayerNum: 0
|
||||
property int serverPlayerNum: 0
|
||||
|
||||
/*
|
||||
function updateOnlineInfo() {
|
||||
}
|
||||
|
||||
onLobbyPlayerNumChanged: updateOnlineInfo();
|
||||
onServerPlayerNumChanged: updateOnlineInfo();
|
||||
|
||||
Rectangle {
|
||||
id: info
|
||||
color: "#88EEEEEE"
|
||||
width: root.width * 0.23 // childrenRect.width + 8
|
||||
height: childrenRect.height + 4
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
radius: 4
|
||||
|
||||
Text {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
x: 4; y: 2
|
||||
font.pixelSize: 16
|
||||
text: luatr("$OnlineInfo")
|
||||
.arg(lobbyPlayerNum).arg(serverPlayerNum) + "\n"
|
||||
+ "Powered by FreeKill " + FkVersion
|
||||
}
|
||||
}
|
||||
|
||||
ChatBox {
|
||||
id: lobbyChat
|
||||
anchors.bottom: info.top
|
||||
width: info.width
|
||||
height: root.height * 0.6
|
||||
isLobby: true
|
||||
color: "#88EEEEEE"
|
||||
radius: 4
|
||||
}
|
||||
/*
|
||||
*/
|
||||
|
||||
Danmaku {
|
||||
id: danmaku
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
callbacks["UpdateAvatar"] = (jsonData) => {
|
||||
mainWindow.busy = false;
|
||||
Self.avatar = jsonData;
|
||||
toast.show("Update avatar done.");
|
||||
toast.show(luatr("Update avatar done."));
|
||||
}
|
||||
|
||||
callbacks["UpdatePassword"] = (jsonData) => {
|
||||
mainWindow.busy = false;
|
||||
if (jsonData === "1")
|
||||
toast.show("Update password done.");
|
||||
toast.show(luatr("Update password done."));
|
||||
else
|
||||
toast.show("Old password wrong!", 5000);
|
||||
toast.show(luatr("Old password wrong!"), 5000);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ Item {
|
|||
id: menu
|
||||
y: bar.height
|
||||
MenuItem {
|
||||
text: qsTr("Replay from file")
|
||||
text: luatr("Replay from File")
|
||||
onTriggered: {
|
||||
fdialog.open();
|
||||
}
|
||||
|
|
|
@ -810,7 +810,7 @@ Item {
|
|||
skillInteraction.item.choices = data.choices;
|
||||
skillInteraction.item.detailed = data.detailed;
|
||||
skillInteraction.item.all_choices = data.all_choices;
|
||||
// skillInteraction.item.clicked();
|
||||
skillInteraction.item.clicked();
|
||||
break;
|
||||
case "spin":
|
||||
skillInteraction.sourceComponent =
|
||||
|
@ -818,12 +818,14 @@ Item {
|
|||
skillInteraction.item.skill = skill_name;
|
||||
skillInteraction.item.from = data.from;
|
||||
skillInteraction.item.to = data.to;
|
||||
skillInteraction.item.clicked();
|
||||
break;
|
||||
case "custom":
|
||||
skillInteraction.sourceComponent =
|
||||
Qt.createComponent(AppPath + "/" + data.qml_path + ".qml");
|
||||
skillInteraction.item.skill = skill_name;
|
||||
skillInteraction.item.extra_data = data;
|
||||
skillInteraction.item.clicked();
|
||||
break;
|
||||
default:
|
||||
skillInteraction.sourceComponent = undefined;
|
||||
|
@ -837,6 +839,8 @@ Item {
|
|||
cancelButton.enabled = true;
|
||||
} else {
|
||||
skillInteraction.sourceComponent = undefined;
|
||||
if (roomScene.popupBox.item)
|
||||
roomScene.popupBox.item.close();
|
||||
Logic.doCancelButton();
|
||||
}
|
||||
}
|
||||
|
@ -1060,8 +1064,17 @@ Item {
|
|||
|
||||
Shortcut {
|
||||
sequence: "Space"
|
||||
enabled: cancelButton.enabled
|
||||
onActivated: Logic.doCancelButton();
|
||||
enabled: cancelButton.enabled || endPhaseButton.visible;
|
||||
onActivated: if (cancelButton.enabled) {
|
||||
Logic.doCancelButton();
|
||||
} else {
|
||||
Logic.replyToServer("");
|
||||
}
|
||||
}
|
||||
|
||||
Shortcut {
|
||||
sequence: "Escape"
|
||||
onActivated: menuContainer.open();
|
||||
}
|
||||
|
||||
function getCurrentCardUseMethod() {
|
||||
|
|
|
@ -314,6 +314,10 @@ function resortHandcards() {
|
|||
["treasure"]: Card.SubtypeTreasure,
|
||||
}
|
||||
|
||||
const hand = dashboard.handcardArea.cards.map(c => {
|
||||
return c.cid;
|
||||
})
|
||||
|
||||
dashboard.handcardArea.cards.sort((prev, next) => {
|
||||
if (prev.footnote === next.footnote) {
|
||||
if (prev.type === next.type) {
|
||||
|
@ -341,6 +345,34 @@ function resortHandcards() {
|
|||
}
|
||||
});
|
||||
|
||||
let i = 0;
|
||||
let resort = true;
|
||||
dashboard.handcardArea.cards.forEach(c => {
|
||||
if (hand[i] !== c.cid) {
|
||||
resort = false;
|
||||
return;
|
||||
}
|
||||
i++;
|
||||
})
|
||||
|
||||
if (resort) {
|
||||
dashboard.handcardArea.cards.sort((prev, next) => {
|
||||
if (prev.footnote === next.footnote) {
|
||||
if (prev.number === next.number) { // 按点数排
|
||||
if (prev.suit === next.suit) {
|
||||
return prev.cid - next.cid;
|
||||
} else {
|
||||
return prev.suit - next.suit;
|
||||
}
|
||||
} else {
|
||||
return prev.number - next.number;
|
||||
}
|
||||
} else {
|
||||
return prev.footnote > next.footnote ? 1 : -1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dashboard.handcardArea.updateCardPosition(true);
|
||||
}
|
||||
|
||||
|
@ -488,19 +520,37 @@ function doIndicate(from, tos) {
|
|||
line.running = true;
|
||||
}
|
||||
|
||||
function getPlayerStr(playerid) {
|
||||
const photo = getPhoto(playerid);
|
||||
if (photo.general === "anjiang" && (photo.deputyGeneral === "anjiang" || !p.deputyGeneral)) {
|
||||
return luatr("seat#" + photo.seatNumber);
|
||||
}
|
||||
|
||||
let ret = photo.general;
|
||||
ret = luatr(ret);
|
||||
if (photo.deputyGeneral && photo.deputyGeneral !== "") {
|
||||
ret = ret + "/" + luatr(photo.deputyGeneral);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
function processPrompt(prompt) {
|
||||
const data = prompt.split(":");
|
||||
let raw = luatr(data[0]);
|
||||
const src = parseInt(data[1]);
|
||||
const dest = parseInt(data[2]);
|
||||
if (raw.match("%src"))
|
||||
raw = raw.replace(/%src/g, luatr(getPhoto(src).general));
|
||||
raw = raw.replace(/%src/g, getPlayerStr(src));
|
||||
if (raw.match("%dest"))
|
||||
raw = raw.replace(/%dest/g, luatr(getPhoto(dest).general));
|
||||
if (raw.match("%arg2"))
|
||||
raw = raw.replace(/%arg2/g, luatr(data[4]));
|
||||
if (raw.match("%arg"))
|
||||
raw = raw.replace(/%arg/g, luatr(data[3]));
|
||||
|
||||
if (data.length > 3) {
|
||||
for (let i = data.length - 1; i > 3; i--) {
|
||||
raw = raw.replace(new RegExp("%arg" + (i - 2), "g"), luatr(data[i]));
|
||||
}
|
||||
|
||||
raw = raw.replace(new RegExp("%arg", "g"), luatr(data[3]));
|
||||
}
|
||||
return raw;
|
||||
}
|
||||
|
||||
|
@ -672,6 +722,49 @@ function updateSelectedTargets(playerid, selected) {
|
|||
}
|
||||
|
||||
if (candidate) {
|
||||
if (!selected) {
|
||||
const remain_targets = [];
|
||||
selected_targets.forEach(id => {
|
||||
const photo = getPhoto(id);
|
||||
const ret = lcall("CanUseCardToTarget", card, id, remain_targets,
|
||||
JSON.stringify(roomScene.extra_data));
|
||||
let bool = ret;
|
||||
if (roomScene.extra_data instanceof Object) {
|
||||
const must = roomScene.extra_data.must_targets;
|
||||
const included = roomScene.extra_data.include_targets;
|
||||
const exclusive = roomScene.extra_data.exclusive_targets;
|
||||
if (exclusive instanceof Array) {
|
||||
if (exclusive.indexOf(id) === -1) bool = false;
|
||||
}
|
||||
if (must instanceof Array) {
|
||||
if (must.filter((val) => {
|
||||
return remain_targets.indexOf(val) === -1;
|
||||
}).length !== 0 && must.indexOf(id) === -1) bool = false;
|
||||
}
|
||||
if (included instanceof Array) {
|
||||
if (included.filter((val) => {
|
||||
return remain_targets.indexOf(val) !== -1;
|
||||
}).length === 0 && included.indexOf(id) === -1) bool = false;
|
||||
}
|
||||
}
|
||||
if (bool) {
|
||||
remain_targets.push(id);
|
||||
} else {
|
||||
photo.selected = false;
|
||||
}
|
||||
})
|
||||
selected_targets = remain_targets;
|
||||
}
|
||||
|
||||
roomScene.resetPrompt(); // update prompt due to selected_targets
|
||||
const prompt = lcall("ActiveSkillPrompt",
|
||||
dashboard.pending_skill !== "" ? dashboard.pending_skill: lcall("GetCardSkill", card),
|
||||
dashboard.pending_skill !== "" ? dashboard.pendings : [card],
|
||||
selected_targets);
|
||||
if (prompt !== "") {
|
||||
roomScene.setPrompt(Util.processPrompt(prompt));
|
||||
}
|
||||
|
||||
all_photos.forEach(photo => {
|
||||
if (photo.selected) return;
|
||||
const id = photo.playerid;
|
||||
|
@ -959,8 +1052,31 @@ callbacks["AskForSkillInvoke"] = (data) => {
|
|||
roomScene.cancelButton.enabled = true;
|
||||
}
|
||||
|
||||
callbacks["AskForArrangeCards"] = (data) => {
|
||||
roomScene.state = "replying";
|
||||
roomScene.popupBox.sourceComponent =
|
||||
Qt.createComponent("../RoomElement/ArrangeCardsBox.qml");
|
||||
const box = roomScene.popupBox.item;
|
||||
const cards = data.cards;
|
||||
box.cards = cards.reduce((newArray, elem) => {
|
||||
return newArray.concat(elem.map(cid => lcall("GetCardData", cid)));
|
||||
}, []);
|
||||
box.org_cards = cards;
|
||||
box.prompt = data.prompt;
|
||||
box.size = data.size;
|
||||
box.areaCapacities = data.capacities;
|
||||
box.areaLimits = data.limits;
|
||||
box.free_arrange = data.is_free;
|
||||
box.areaNames = data.names;
|
||||
box.pattern = data.pattern;
|
||||
box.poxi_type = data.poxi_type;
|
||||
box.cancelable = data.cancelable;
|
||||
|
||||
box.initializeCards();
|
||||
}
|
||||
|
||||
callbacks["AskForGuanxing"] = (data) => {
|
||||
const cards = [];
|
||||
const cards = data.cards;
|
||||
const min_top_cards = data.min_top_cards;
|
||||
const max_top_cards = data.max_top_cards;
|
||||
const min_bottom_cards = data.min_bottom_cards;
|
||||
|
@ -971,9 +1087,9 @@ callbacks["AskForGuanxing"] = (data) => {
|
|||
roomScene.state = "replying";
|
||||
roomScene.popupBox.sourceComponent =
|
||||
Qt.createComponent("../RoomElement/GuanxingBox.qml");
|
||||
data.cards.forEach(id => cards.push(lcall("GetCardData", id)));
|
||||
const box = roomScene.popupBox.item;
|
||||
box.prompt = prompt;
|
||||
box.free_arrange = data.is_free;
|
||||
if (max_top_cards === 0) {
|
||||
box.areaCapacities = [max_bottom_cards];
|
||||
box.areaLimits = [min_bottom_cards];
|
||||
|
@ -989,8 +1105,11 @@ callbacks["AskForGuanxing"] = (data) => {
|
|||
box.areaNames = [luatr(top_area_name), luatr(bottom_area_name)];
|
||||
}
|
||||
}
|
||||
box.cards = cards;
|
||||
box.arrangeCards();
|
||||
box.org_cards = cards;
|
||||
box.cards = cards.reduce((newArray, elem) => {
|
||||
return newArray.concat(elem.map(cid => lcall("GetCardData", cid)));
|
||||
}, []);
|
||||
box.initializeCards();
|
||||
box.accepted.connect(() => {
|
||||
replyToServer(JSON.stringify(box.getResult()));
|
||||
});
|
||||
|
@ -1006,6 +1125,7 @@ callbacks["AskForExchange"] = (data) => {
|
|||
Qt.createComponent("../RoomElement/GuanxingBox.qml");
|
||||
let for_i = 0;
|
||||
const box = roomScene.popupBox.item;
|
||||
box.org_cards = data.piles;
|
||||
data.piles.forEach(ids => {
|
||||
if (ids.length > 0) {
|
||||
ids.forEach(id => cards.push(lcall("GetCardData", id)));
|
||||
|
@ -1015,11 +1135,11 @@ callbacks["AskForExchange"] = (data) => {
|
|||
for_i ++;
|
||||
}
|
||||
});
|
||||
box.cards = cards;
|
||||
box.areaCapacities = capacities
|
||||
box.areaLimits = limits
|
||||
box.areaNames = cards_name
|
||||
box.cards = cards;
|
||||
box.arrangeCards();
|
||||
box.initializeCards();
|
||||
box.accepted.connect(() => {
|
||||
replyToServer(JSON.stringify(box.getResult()));
|
||||
});
|
||||
|
|
423
Fk/RoomElement/ArrangeCardsBox.qml
Normal file
423
Fk/RoomElement/ArrangeCardsBox.qml
Normal file
|
@ -0,0 +1,423 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Fk
|
||||
import Fk.Pages
|
||||
import Fk.RoomElement
|
||||
|
||||
GraphicsBox {
|
||||
id: root
|
||||
property string prompt
|
||||
property var cards: []
|
||||
property var org_cards: []
|
||||
property var result: []
|
||||
property var areaCapacities: []
|
||||
property var areaLimits: []
|
||||
property var areaNames: []
|
||||
property var dragging_card: ""
|
||||
property var movepos: []
|
||||
property bool free_arrange: true
|
||||
property bool cancelable: false
|
||||
property string poxi_type: ""
|
||||
property string pattern: "."
|
||||
property int size: 0
|
||||
property int padding: 25
|
||||
|
||||
title.text: Backend.translate(prompt !== "" ? Util.processPrompt(prompt) : "Please arrange cards")
|
||||
width: body.width + padding * 2
|
||||
height: title.height + body.height + padding * 2
|
||||
|
||||
ColumnLayout {
|
||||
id: body
|
||||
x: padding
|
||||
y: parent.height - padding - height
|
||||
spacing: 10
|
||||
|
||||
Repeater {
|
||||
id: areaRepeater
|
||||
model: areaCapacities
|
||||
|
||||
Row {
|
||||
spacing: 7
|
||||
|
||||
property int areaCapacity: modelData
|
||||
property string areaName: index < areaNames.length ? qsTr(Backend.translate(areaNames[index])) : ""
|
||||
|
||||
Rectangle {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
color: "#6B5D42"
|
||||
width: 20
|
||||
height: 100
|
||||
radius: 5
|
||||
|
||||
Text {
|
||||
anchors.fill: parent
|
||||
width: 20
|
||||
height: 100
|
||||
text: areaName
|
||||
color: "white"
|
||||
font.family: fontLibian.name
|
||||
font.pixelSize: 18
|
||||
style: Text.Outline
|
||||
wrapMode: Text.WordWrap
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
}
|
||||
|
||||
Repeater {
|
||||
id: cardRepeater
|
||||
model: (size === 0) ? areaCapacity : 1
|
||||
|
||||
Rectangle {
|
||||
color: "#1D1E19"
|
||||
width: (size === 0) ? 93 : size * 100 - 7
|
||||
height: 130
|
||||
|
||||
}
|
||||
}
|
||||
property alias cardRepeater: cardRepeater
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
spacing: 32
|
||||
|
||||
MetroButton {
|
||||
width: 120
|
||||
height: 35
|
||||
id: buttonConfirm
|
||||
text: luatr("OK")
|
||||
onClicked: {
|
||||
close();
|
||||
roomScene.state = "notactive";
|
||||
const reply = JSON.stringify(getResult());
|
||||
ClientInstance.replyToServer("", reply);
|
||||
}
|
||||
}
|
||||
|
||||
MetroButton {
|
||||
width: 120
|
||||
height: 35
|
||||
text: luatr("Cancel")
|
||||
visible: root.cancelable
|
||||
onClicked: {
|
||||
close();
|
||||
roomScene.state = "notactive";
|
||||
const ret = [];
|
||||
let i;
|
||||
for (i = 0; i < result.length; i++) {
|
||||
ret.push([]);
|
||||
}
|
||||
const reply = JSON.stringify(ret);
|
||||
ClientInstance.replyToServer("", reply);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Repeater {
|
||||
id: cardItem
|
||||
model: cards
|
||||
|
||||
CardItem {
|
||||
x: index
|
||||
y: -1
|
||||
cid: modelData.cid
|
||||
name: modelData.name
|
||||
suit: modelData.suit
|
||||
number: modelData.number
|
||||
draggable: true
|
||||
onReleased: updateCardReleased(this);
|
||||
onDraggingChanged: {
|
||||
if (!dragging) return;
|
||||
dragging_card = this;
|
||||
let i, card
|
||||
for (i = 0; i < cardItem.count; i++) {
|
||||
card = cardItem.itemAt(i);
|
||||
if (card !== this)
|
||||
card.draggable = false;
|
||||
}
|
||||
}
|
||||
onXChanged : updateCardDragging(this);
|
||||
onYChanged : updateCardDragging(this);
|
||||
onSelectedChanged : updateCardSelected(this);
|
||||
}
|
||||
}
|
||||
|
||||
function updateCardDragging(_card) {
|
||||
if (!_card.dragging) return;
|
||||
_card.goBackAnim.stop();
|
||||
_card.opacity = 0.5
|
||||
let i, j
|
||||
let box, pos, pile;
|
||||
movepos = [];
|
||||
for (j = 0; j <= result.length; j++) {
|
||||
if (j >= result.length) {
|
||||
arrangeCards();
|
||||
return;
|
||||
}
|
||||
pile = areaRepeater.itemAt(j);
|
||||
if (pile.y === 0) {
|
||||
pile.y = j * 140
|
||||
}
|
||||
box = pile.cardRepeater.itemAt(0);
|
||||
pos = mapFromItem(pile, box.x, box.y);
|
||||
if (Math.abs(pos.y - _card.y) < 130 / 2) break;
|
||||
}
|
||||
if (result[j].includes(_card)) {
|
||||
if (j === 0 && !free_arrange) {
|
||||
arrangeCards();
|
||||
return;
|
||||
}
|
||||
} else if (!_card.selectable) {
|
||||
arrangeCards();
|
||||
return;
|
||||
}
|
||||
|
||||
let card;
|
||||
let index = result[j].indexOf(_card);
|
||||
if (index === -1 && result[j].length === areaCapacities[j]) {
|
||||
for (i = result[j].length; i > 0; i--) {
|
||||
card = result[j][i-1];
|
||||
if (card === _card) continue;
|
||||
if (Math.abs(card.x - _card.x) <= card.width / 2 && card.selectable) {
|
||||
movepos = [j, i-1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < result[j].length; i++) {
|
||||
card = result[j][i];
|
||||
if (card.dragging) continue;
|
||||
|
||||
if (card.x > _card.x) {
|
||||
movepos = [j, i - ((index !==-1 && index < i) ? 1 : 0)];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (movepos.length === 0)
|
||||
movepos = [j, result[j].length - ((index === -1) ? 0 : 1)];
|
||||
|
||||
if (!free_arrange && j === 0 && org_cards[0].includes(_card.cid)) {
|
||||
let a = 0, b = -1, c = -1;
|
||||
i = 0;
|
||||
while (i < result[j].length && a < org_cards[0].length) {
|
||||
if (result[j][i].cid === org_cards[0][a]) {
|
||||
if (b !==c) {
|
||||
c = i;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
a++;
|
||||
} else {
|
||||
if (b === -1)
|
||||
b = i;
|
||||
if (org_cards[0].includes(result[j][i].cid)) {
|
||||
a++;
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (b === -1) b = result[j].length;
|
||||
if (c === -1) c = result[j].length;
|
||||
|
||||
if (b === c)
|
||||
movepos = [j, b];
|
||||
else if (movepos[1] < b || (movepos[1] > c && c !==-1))
|
||||
movepos = [];
|
||||
}
|
||||
}
|
||||
arrangeCards();
|
||||
}
|
||||
|
||||
function updateCardReleased(_card) {
|
||||
let i, j;
|
||||
if (movepos.length === 2) {
|
||||
for (j = 0; j < result.length; j++) {
|
||||
i = result[j].indexOf(_card);
|
||||
if (i !==-1) {
|
||||
if (j !==movepos[0] && result[movepos[0]].length === areaCapacities[movepos[0]]) {
|
||||
result[j][i] = result[movepos[0]][movepos[1]];
|
||||
result[movepos[0]][movepos[1]] = _card;
|
||||
if (!free_arrange && result[0].length < areaCapacities[0])
|
||||
result[0].sort((a, b) => org_cards[0].indexOf(a.cid) - org_cards[0].indexOf(b.cid));
|
||||
} else {
|
||||
result[j].splice(i, 1);
|
||||
result[movepos[0]].splice(movepos[1], 0, _card);
|
||||
}
|
||||
movepos = [];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
dragging_card = "";
|
||||
arrangeCards();
|
||||
}
|
||||
|
||||
function updateCardSelected(_card) {
|
||||
let i = result[0].indexOf(_card);
|
||||
let j;
|
||||
if (i === -1) {
|
||||
if (result[0].length < areaCapacities[0]) {
|
||||
if (free_arrange || !org_cards[0].includes(_card.cid)) {
|
||||
for (j = 1; j < result.length; j++) {
|
||||
i = result[j].indexOf(_card);
|
||||
if (i !==-1) {
|
||||
result[j].splice(i, 1);
|
||||
result[0].push(_card);
|
||||
arrangeCards();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (i < result[0].length && j < org_cards[0].length) {
|
||||
if (org_cards[0][j] === _card.cid) break;
|
||||
if (result[0][i].cid === org_cards[0][j]) {
|
||||
i++;
|
||||
j++;
|
||||
} else {
|
||||
if (org_cards[0].includes(result[0][i].cid))
|
||||
j++;
|
||||
else
|
||||
i++;
|
||||
}
|
||||
}
|
||||
let index;
|
||||
for (j = 1; j < result.length; j++) {
|
||||
index = result[j].indexOf(_card);
|
||||
if (index !== -1) {
|
||||
result[j].splice(index, 1);
|
||||
result[0].splice(i, 0, _card);
|
||||
arrangeCards();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (j = 1; j < result.length; j++) {
|
||||
if (result[j].length < areaCapacities[j]) {
|
||||
result[0].splice(i, 1);
|
||||
result[j].push(_card);
|
||||
arrangeCards();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function arrangeCards() {
|
||||
let i, j, a, b;
|
||||
let card, box, pos, pile;
|
||||
let spacing;
|
||||
let same_row;
|
||||
let c_result = getResult();
|
||||
let is_exchange = (movepos.length === 2 && !result[movepos[0]].includes(dragging_card) && result[movepos[0]].length === areaCapacities[movepos[0]])
|
||||
for (j = 0; j < result.length; j++) {
|
||||
pile = areaRepeater.itemAt(j);
|
||||
box = pile.cardRepeater.itemAt(0);
|
||||
if (pile.y === 0) {
|
||||
pile.y = j * 140
|
||||
}
|
||||
a = result[j].length;
|
||||
if (movepos.length === 2) {
|
||||
if (movepos[0] === j && !result[j].includes(dragging_card) && result[j].length < areaCapacities[j]) {
|
||||
a++;
|
||||
} else if (movepos[0] !== j && result[j].includes(dragging_card)) {
|
||||
a--;
|
||||
}
|
||||
}
|
||||
spacing = (size > 0 && a > size) ? ((size - 1) * 100 / (a - 1)) : 100;
|
||||
b = 0;
|
||||
for (i = 0; i < result[j].length; i++) {
|
||||
card = result[j][i];
|
||||
if (card.dragging) {
|
||||
if (movepos.length !== 2 || movepos[0] !== j)
|
||||
b++;
|
||||
continue;
|
||||
}
|
||||
if (movepos.length === 2 && movepos[0] === j && b === movepos[1] && !is_exchange)
|
||||
b++;
|
||||
pos = mapFromItem(pile, box.x, box.y);
|
||||
card.glow.visible = false;
|
||||
card.chosenInBox = (movepos.length === 2 && result[j].length === areaCapacities[j] && movepos[0] === j && movepos[1] === b);
|
||||
card.origX = (movepos.length === 2 && movepos[0] === j && b > (movepos[1] - (is_exchange ? 0 : 1))) ? (pos.x + (b - 1) * spacing + 100) : (pos.x + b * spacing);
|
||||
card.origY = pos.y;
|
||||
card.opacity = 1;
|
||||
card.z = i + 1;
|
||||
card.initialZ = i + 1;
|
||||
card.maxZ = cardItem.count;
|
||||
|
||||
if (poxi_type !== "")
|
||||
card.selectable = lcall("PoxiFilter", poxi_type, card.cid, [dragging_card.cid], c_result, org_cards);
|
||||
else if (pattern !== ".")
|
||||
card.selectable = lcall("CardFitPattern", card.cid, pattern);
|
||||
else {
|
||||
if (free_arrange || dragging_card === "")
|
||||
card.selectable = true;
|
||||
else if (result[j].length < areaCapacities[j] + (result[j].includes(dragging_card) ? 1 : 0))
|
||||
card.selectable = (j !== 0);
|
||||
else {
|
||||
if (j === 0)
|
||||
card.selectable = !org_cards[0].includes(dragging_card.cid) || i === org_cards[0].indexOf(dragging_card.cid);
|
||||
else {
|
||||
if (result[0].includes(dragging_card))
|
||||
card.selectable = result[0].length < areaCapacities[0] || !org_cards[0].includes(card.cid) || card.cid === org_cards[0][result[0].indexOf(dragging_card)]
|
||||
else
|
||||
card.selectable = org_cards[0].includes(dragging_card.cid) || card.cid === org_cards[0][result[0].indexOf(dragging_card)]
|
||||
}
|
||||
}
|
||||
}
|
||||
card.draggable = (dragging_card === "") && (free_arrange || j > 0 || card.selectable);
|
||||
card.goBack(true);
|
||||
b++;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < areaRepeater.count; i++) {
|
||||
if (result[i].length < areaLimits[i]) {
|
||||
buttonConfirm.enabled = false;
|
||||
break;
|
||||
}
|
||||
buttonConfirm.enabled = poxi_type ? lcall("PoxiFeasible", poxi_type, [], c_result, org_cards) : true;
|
||||
}
|
||||
}
|
||||
|
||||
function initializeCards() {
|
||||
result = new Array(areaCapacities.length);
|
||||
let i, j;
|
||||
let k = 0;
|
||||
for (i = 0; i < result.length; i++){
|
||||
result[i] = [];
|
||||
}
|
||||
|
||||
let card;
|
||||
|
||||
for (j = 0; j < org_cards.length; j++){
|
||||
for (i = 0; i < org_cards[j].length; i++){
|
||||
result[j].push(cardItem.itemAt(k));
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
arrangeCards();
|
||||
}
|
||||
|
||||
function getResult() {
|
||||
const ret = [];
|
||||
result.forEach(t => {
|
||||
const t2 = [];
|
||||
t.forEach(v => t2.push(v.cid));
|
||||
ret.push(t2);
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
}
|
|
@ -112,7 +112,7 @@ GraphicsBox {
|
|||
visible: !convertDisabled
|
||||
text: luatr("Same General Convert")
|
||||
onClicked: {
|
||||
roomScene.startCheat("SameConvert", { cards: generalList });
|
||||
roomScene.startCheat("SameConvert", { cards: generalList, choices: choices });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -263,6 +263,7 @@ GraphicsBox {
|
|||
item.selectable = hegemony ? isHegPair(selectedItem[0], item)
|
||||
: true;
|
||||
if (hegemony) {
|
||||
item.inPosition = 0;
|
||||
if (selectedItem[0]) {
|
||||
if (selectedItem[1]) {
|
||||
if (selectedItem[0] === item) {
|
||||
|
@ -299,6 +300,23 @@ GraphicsBox {
|
|||
}
|
||||
}
|
||||
|
||||
if (hegemony) {
|
||||
if (selectedItem[0]) {
|
||||
if (selectedItem[0].mainMaxHp < 0) {
|
||||
selectedItem[0].inPosition = 1;
|
||||
} else if (selectedItem[0].deputyMaxHp < 0) {
|
||||
selectedItem[0].inPosition = -1;
|
||||
}
|
||||
if (selectedItem[1]) {
|
||||
if (selectedItem[1].mainMaxHp < 0) {
|
||||
selectedItem[1].inPosition = -1;
|
||||
} else if (selectedItem[1].deputyMaxHp < 0) {
|
||||
selectedItem[1].inPosition = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < generalList.count; i++) {
|
||||
if (lcall("GetSameGenerals", generalList.get(i).name).length > 0) {
|
||||
convertBtn.enabled = true;
|
||||
|
|
|
@ -322,11 +322,6 @@ RowLayout {
|
|||
|
||||
const enabled_cards = [];
|
||||
const targets = roomScene.selected_targets;
|
||||
const prompt = lcall("ActiveSkillPrompt", pending_skill, pendings,
|
||||
targets);
|
||||
if (prompt !== "") {
|
||||
roomScene.setPrompt(Util.processPrompt(prompt));
|
||||
}
|
||||
|
||||
handcardAreaItem.cards.forEach((card) => {
|
||||
if (card.selected || lcall("ActiveCardFilter", pending_skill, card.cid,
|
||||
|
@ -373,6 +368,11 @@ RowLayout {
|
|||
pending_card = -1;
|
||||
cardSelected(pending_card);
|
||||
}
|
||||
const prompt = lcall("ActiveSkillPrompt", pending_skill, pendings,
|
||||
targets);
|
||||
if (prompt !== "") {
|
||||
roomScene.setPrompt(Util.processPrompt(prompt));
|
||||
}
|
||||
}
|
||||
|
||||
function startPending(skill_name) {
|
||||
|
|
|
@ -22,6 +22,9 @@ CardItem {
|
|||
property int hp
|
||||
property int maxHp
|
||||
property int shieldNum
|
||||
property int mainMaxHp
|
||||
property int deputyMaxHp
|
||||
property int inPosition: 0
|
||||
property string pkgName: ""
|
||||
property bool detailed: true
|
||||
property alias hasCompanions: companions.visible
|
||||
|
@ -119,12 +122,15 @@ CardItem {
|
|||
width: childrenRect.width
|
||||
height: childrenRect.height
|
||||
Image {
|
||||
opacity: ((mainMaxHp < 0 || deputyMaxHp < 0) && (index * 2 + 1 === hp) && inPosition !== -1)
|
||||
? (inPosition === 0 ? 0.5 : 0) :1
|
||||
height: 12; fillMode: Image.PreserveAspectFit
|
||||
source: SkinBank.getGeneralCardDir(kingdom) + kingdom + "-magatama-l"
|
||||
}
|
||||
Image {
|
||||
x: 4.4
|
||||
opacity: (index + 1) * 2 <= hp ? 1 : 0
|
||||
opacity: (index + 1) * 2 <= hp ? (((mainMaxHp < 0 || deputyMaxHp < 0) && inPosition !== -1 && ((index + 1) * 2 === hp))
|
||||
? (inPosition === 0 ? 0.5 : 0) : 1) : 0
|
||||
height: 12; fillMode: Image.PreserveAspectFit
|
||||
source: {
|
||||
const k = subkingdom ? subkingdom : kingdom;
|
||||
|
@ -227,6 +233,8 @@ CardItem {
|
|||
hp = data.hp;
|
||||
maxHp = data.maxHp;
|
||||
shieldNum = data.shield;
|
||||
mainMaxHp = data.mainMaxHpAdjustedValue;
|
||||
deputyMaxHp = data.deputyMaxHpAdjustedValue;
|
||||
|
||||
const splited = name.split("__");
|
||||
if (splited.length > 1) {
|
||||
|
|
|
@ -8,10 +8,14 @@ GraphicsBox {
|
|||
id: root
|
||||
property string prompt
|
||||
property var cards: []
|
||||
property var org_cards: []
|
||||
property var movepos: []
|
||||
property var dragging_card: ""
|
||||
property var result: []
|
||||
property var areaCapacities: []
|
||||
property var areaLimits: []
|
||||
property var areaNames: []
|
||||
property bool free_arrange: true
|
||||
property int padding: 25
|
||||
|
||||
title.text: luatr(prompt !== "" ? prompt : "Please arrange cards")
|
||||
|
@ -103,59 +107,191 @@ GraphicsBox {
|
|||
number: modelData.number
|
||||
mark: modelData.mark
|
||||
draggable: true
|
||||
onReleased: arrangeCards();
|
||||
onDraggingChanged: {
|
||||
if (!dragging) return;
|
||||
dragging_card = this;
|
||||
let i, card
|
||||
for (i = 0; i < cardItem.count; i++) {
|
||||
card = cardItem.itemAt(i);
|
||||
if (card !== this)
|
||||
card.draggable = false;
|
||||
}
|
||||
}
|
||||
onReleased: updateCardReleased(this);
|
||||
onXChanged : updateCardDragging(this);
|
||||
onYChanged : updateCardDragging(this);
|
||||
}
|
||||
}
|
||||
|
||||
function arrangeCards() {
|
||||
result = new Array(areaCapacities.length);
|
||||
let i;
|
||||
for (i = 0; i < result.length; i++){
|
||||
result[i] = [];
|
||||
function updateCardDragging(_card) {
|
||||
if (!_card.dragging) return;
|
||||
_card.goBackAnim.stop();
|
||||
_card.opacity = 0.5
|
||||
let i, j
|
||||
let box, pos, pile;
|
||||
movepos = [];
|
||||
for (j = 0; j <= result.length; j++) {
|
||||
if (j >= result.length) {
|
||||
arrangeCards();
|
||||
return;
|
||||
}
|
||||
pile = areaRepeater.itemAt(j);
|
||||
if (pile.y === 0) {
|
||||
pile.y = j * 150
|
||||
}
|
||||
box = pile.cardRepeater.itemAt(0);
|
||||
pos = mapFromItem(pile, box.x, box.y);
|
||||
if (Math.abs(pos.y - _card.y) < 130 / 2) break;
|
||||
}
|
||||
if (result[j].includes(_card)) {
|
||||
if (j === 0 && !free_arrange) {
|
||||
arrangeCards();
|
||||
return;
|
||||
}
|
||||
} else if (!_card.selectable) {
|
||||
arrangeCards();
|
||||
return;
|
||||
}
|
||||
|
||||
let card, j, area, cards, stay;
|
||||
for (i = 0; i < cardItem.count; i++) {
|
||||
card = cardItem.itemAt(i);
|
||||
|
||||
stay = true;
|
||||
for (j = areaRepeater.count - 1; j >= 0; j--) {
|
||||
area = areaRepeater.itemAt(j);
|
||||
cards = result[j];
|
||||
if (cards.length < areaCapacities[j] && card.y >= area.y) {
|
||||
cards.push(card);
|
||||
stay = false;
|
||||
let card;
|
||||
let index = result[j].indexOf(_card);
|
||||
if (index === -1 && result[j].length === areaCapacities[j]) {
|
||||
for (i = result[j].length; i > 0; i--) {
|
||||
card = result[j][i-1];
|
||||
if (card === _card) continue;
|
||||
if (Math.abs(card.x - _card.x) <= card.width / 2 && card.selectable) {
|
||||
movepos = [j, i-1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < result[j].length; i++) {
|
||||
card = result[j][i];
|
||||
if (card.dragging) continue;
|
||||
|
||||
if (stay) {
|
||||
for (j = 0; j < areaRepeater.count; j++) {
|
||||
if (result[j].length < areaCapacities[j]) {
|
||||
result[j].push(card);
|
||||
break;
|
||||
if (card.x > _card.x) {
|
||||
movepos = [j, i - ((index !==-1 && index < i) ? 1 : 0)];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (movepos.length === 0)
|
||||
movepos = [j, result[j].length - ((index === -1) ? 0 : 1)];
|
||||
|
||||
if (!free_arrange && j === 0 && org_cards[0].includes(_card.cid)) {
|
||||
let a = 0, b = -1, c = -1;
|
||||
i = 0;
|
||||
while (i < result[j].length && a < org_cards[0].length) {
|
||||
if (result[j][i].cid === org_cards[0][a]) {
|
||||
if (b !==c) {
|
||||
c = i;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
a++;
|
||||
} else {
|
||||
if (b === -1)
|
||||
b = i;
|
||||
if (org_cards[0].includes(result[j][i].cid)) {
|
||||
a++;
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (b === -1) b = result[j].length;
|
||||
if (c === -1) c = result[j].length;
|
||||
|
||||
if (b === c)
|
||||
movepos = [j, b];
|
||||
else if (movepos[1] < b || (movepos[1] > c && c !==-1))
|
||||
movepos = [];
|
||||
}
|
||||
}
|
||||
arrangeCards();
|
||||
}
|
||||
|
||||
function updateCardReleased(_card) {
|
||||
let i, j;
|
||||
if (movepos.length === 2) {
|
||||
for (j = 0; j < result.length; j++) {
|
||||
i = result[j].indexOf(_card);
|
||||
if (i !==-1) {
|
||||
if (j !==movepos[0] && result[movepos[0]].length === areaCapacities[movepos[0]]) {
|
||||
result[j][i] = result[movepos[0]][movepos[1]];
|
||||
result[movepos[0]][movepos[1]] = _card;
|
||||
if (!free_arrange && result[0].length < areaCapacities[0])
|
||||
result[0].sort((a, b) => org_cards[0].indexOf(a.cid) - org_cards[0].indexOf(b.cid));
|
||||
} else {
|
||||
result[j].splice(i, 1);
|
||||
result[movepos[0]].splice(movepos[1], 0, _card);
|
||||
}
|
||||
movepos = [];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(i = 0; i < result.length; i++)
|
||||
result[i].sort((a, b) => a.x - b.x);
|
||||
dragging_card = "";
|
||||
arrangeCards();
|
||||
}
|
||||
|
||||
|
||||
|
||||
let box, pos, pile;
|
||||
for (j = 0; j < areaRepeater.count; j++) {
|
||||
function arrangeCards() {
|
||||
let i, j, a, b;
|
||||
let card, box, pos, pile;
|
||||
let spacing;
|
||||
let same_row;
|
||||
let c_result = getResult();
|
||||
let is_exchange = (movepos.length === 2 && !result[movepos[0]].includes(dragging_card) && result[movepos[0]].length === areaCapacities[movepos[0]])
|
||||
for (j = 0; j < result.length; j++) {
|
||||
pile = areaRepeater.itemAt(j);
|
||||
if (pile.y === 0){
|
||||
box = pile.cardRepeater.itemAt(0);
|
||||
if (pile.y === 0) {
|
||||
pile.y = j * 150
|
||||
}
|
||||
a = result[j].length;
|
||||
if (movepos.length === 2) {
|
||||
if (movepos[0] === j && !result[j].includes(dragging_card) && result[j].length < areaCapacities[j]) {
|
||||
a++;
|
||||
} else if (movepos[0] !== j && result[j].includes(dragging_card)) {
|
||||
a--;
|
||||
}
|
||||
}
|
||||
spacing = 100;
|
||||
b = 0;
|
||||
for (i = 0; i < result[j].length; i++) {
|
||||
box = pile.cardRepeater.itemAt(i);
|
||||
pos = mapFromItem(pile, box.x, box.y);
|
||||
card = result[j][i];
|
||||
card.origX = pos.x;
|
||||
if (card.dragging) {
|
||||
if (movepos.length !== 2 || movepos[0] !== j)
|
||||
b++;
|
||||
continue;
|
||||
}
|
||||
if (movepos.length === 2 && movepos[0] === j && b === movepos[1] && !is_exchange)
|
||||
b++;
|
||||
pos = mapFromItem(pile, box.x, box.y);
|
||||
card.glow.visible = false;
|
||||
card.origX = (movepos.length === 2 && movepos[0] === j && b > (movepos[1] - (is_exchange ? 0 : 1))) ? (pos.x + (b - 1) * spacing + 100) : (pos.x + b * spacing);
|
||||
card.origY = pos.y;
|
||||
card.opacity = 1;
|
||||
card.z = i + 1;
|
||||
card.initialZ = i + 1;
|
||||
card.maxZ = cardItem.count;
|
||||
|
||||
if (free_arrange || dragging_card === "")
|
||||
card.selectable = true;
|
||||
else if (result[j].length < areaCapacities[j] + (result[j].includes(dragging_card) ? 1 : 0))
|
||||
card.selectable = (j !== 0);
|
||||
else {
|
||||
if (j === 0)
|
||||
card.selectable = !org_cards[0].includes(dragging_card.cid) || i === org_cards[0].indexOf(dragging_card.cid);
|
||||
else {
|
||||
if (result[0].includes(dragging_card))
|
||||
card.selectable = result[0].length < areaCapacities[0] || !org_cards[0].includes(card.cid) || card.cid === org_cards[0][result[0].indexOf(dragging_card)]
|
||||
else
|
||||
card.selectable = org_cards[0].includes(dragging_card.cid) || card.cid === org_cards[0][result[0].indexOf(dragging_card)]
|
||||
}
|
||||
}
|
||||
card.draggable = (dragging_card === "") && (free_arrange || j > 0 || card.selectable);
|
||||
card.goBack(true);
|
||||
b++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,6 +304,26 @@ GraphicsBox {
|
|||
}
|
||||
}
|
||||
|
||||
function initializeCards() {
|
||||
result = new Array(areaCapacities.length);
|
||||
let i, j;
|
||||
let k = 0;
|
||||
for (i = 0; i < result.length; i++){
|
||||
result[i] = [];
|
||||
}
|
||||
|
||||
let card;
|
||||
|
||||
for (j = 0; j < org_cards.length; j++){
|
||||
for (i = 0; i < org_cards[j].length; i++){
|
||||
result[j].push(cardItem.itemAt(k));
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
arrangeCards();
|
||||
}
|
||||
|
||||
function getResult() {
|
||||
const ret = [];
|
||||
result.forEach(t => {
|
||||
|
|
|
@ -234,7 +234,26 @@ Item {
|
|||
color: "white"
|
||||
width: 24
|
||||
wrapMode: Text.WrapAnywhere
|
||||
text: luatr(deputyGeneral)
|
||||
text: ""
|
||||
style: Text.Outline
|
||||
}
|
||||
|
||||
Text {
|
||||
id: longDeputyGeneralName
|
||||
anchors.left: generalImage.right
|
||||
anchors.leftMargin: -14
|
||||
y: 23
|
||||
font.family: fontLibian.name
|
||||
font.pixelSize: 22
|
||||
rotation: 90
|
||||
transformOrigin: Item.BottomLeft
|
||||
opacity: 0.9
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
lineHeight: 18
|
||||
lineHeightMode: Text.FixedHeight
|
||||
color: "white"
|
||||
width: 24
|
||||
text: ""
|
||||
style: Text.Outline
|
||||
}
|
||||
}
|
||||
|
@ -740,6 +759,18 @@ Item {
|
|||
}
|
||||
}
|
||||
|
||||
onDeputyGeneralChanged: {
|
||||
if (!roomScene.isStarted) return;
|
||||
const text = luatr(deputyGeneral);
|
||||
if (text.length > 6) {
|
||||
deputyGeneralName.text = "";
|
||||
longDeputyGeneralName.text = text;
|
||||
} else {
|
||||
deputyGeneralName.text = text;
|
||||
longDeputyGeneralName.text = "";
|
||||
}
|
||||
}
|
||||
|
||||
function chat(msg) {
|
||||
chat.text = msg;
|
||||
chat.visible = true;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import QtQuick
|
||||
import Qt5Compat.GraphicalEffects
|
||||
import QtQuick.Controls
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
@ -86,7 +87,40 @@ Item {
|
|||
}
|
||||
|
||||
TapHandler {
|
||||
enabled: root.type !== "notactive" && root.enabled
|
||||
onTapped: parent.pressed = !parent.pressed;
|
||||
acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.NoButton
|
||||
onTapped: (p, btn) => {
|
||||
if ((btn === Qt.LeftButton || btn === Qt.NoButton) && root.type !== "notactive" && root.enabled) {
|
||||
parent.pressed = !parent.pressed;
|
||||
} else if (btn === Qt.RightButton) {
|
||||
skillDetail.open();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Popup {
|
||||
id: skillDetail
|
||||
x: Math.round((parent.width - width) / 2)
|
||||
y: Math.round((parent.height - height) / 2)
|
||||
property string text: ""
|
||||
width: Math.min(contentWidth, realMainWin.width * 0.4)
|
||||
height: Math.min(contentHeight + 24, realMainWin.height * 0.9)
|
||||
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
|
||||
padding: 12
|
||||
background: Rectangle {
|
||||
color: "#EEEEEEEE"
|
||||
radius: 5
|
||||
border.color: "#A6967A"
|
||||
border.width: 1
|
||||
}
|
||||
contentItem: Text {
|
||||
text: "<b>" + luatr(orig) + "</b>: " + luatr(":" + orig)
|
||||
font.pixelSize: 20
|
||||
wrapMode: Text.WordWrap
|
||||
textFormat: TextEdit.RichText
|
||||
|
||||
TapHandler {
|
||||
onTapped: skillDetail.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ MetroButton {
|
|||
const box = roomScene.popupBox.item;
|
||||
box.options = choices;
|
||||
box.all_options = all_choices;
|
||||
box.skill_name = skill;
|
||||
box.accepted.connect(() => {
|
||||
answer = all_choices[box.result];
|
||||
});
|
||||
|
|
|
@ -64,9 +64,15 @@ Rectangle {
|
|||
}
|
||||
|
||||
Button {
|
||||
text: qsTr("Next")
|
||||
enabled: view.currentIndex + 1 < total
|
||||
onClicked: view.currentIndex++
|
||||
text: view.currentIndex + 1 == total ? qsTr("OK!") : qsTr("Next")
|
||||
enabled: view.currentIndex + 1 <= total
|
||||
onClicked: {
|
||||
if (view.currentIndex + 1 == total) {
|
||||
mainStack.pop();
|
||||
} else {
|
||||
view.currentIndex++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,6 @@ Window {
|
|||
|
||||
Component { id: init; Init {} }
|
||||
Component { id: packageManage; PackageManage {} }
|
||||
Component { id: modMaker; ModMaker {} }
|
||||
Component { id: lobby; Lobby {} }
|
||||
Component { id: generalsOverview; GeneralsOverview {} }
|
||||
Component { id: cardsOverview; CardsOverview {} }
|
||||
|
|
28
Fk/util.js
28
Fk/util.js
|
@ -12,19 +12,37 @@ function convertNumber(number) {
|
|||
return "";
|
||||
}
|
||||
|
||||
function getPlayerStr(playerid) {
|
||||
const photo = getPhoto(playerid);
|
||||
if (photo.general === "anjiang" && (photo.deputyGeneral === "anjiang" || !p.deputyGeneral)) {
|
||||
return luatr("seat#" + photo.seatNumber);
|
||||
}
|
||||
|
||||
let ret = photo.general;
|
||||
ret = luatr(ret);
|
||||
if (photo.deputyGeneral && photo.deputyGeneral !== "") {
|
||||
ret = ret + "/" + luatr(photo.deputyGeneral);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
function processPrompt(prompt) {
|
||||
const data = prompt.split(":");
|
||||
let raw = luatr(data[0]);
|
||||
const src = parseInt(data[1]);
|
||||
const dest = parseInt(data[2]);
|
||||
if (raw.match("%src"))
|
||||
raw = raw.replace(/%src/g, luatr(getPhoto(src).general));
|
||||
raw = raw.replace(/%src/g, getPlayerStr(src));
|
||||
if (raw.match("%dest"))
|
||||
raw = raw.replace(/%dest/g, luatr(getPhoto(dest).general));
|
||||
if (raw.match("%arg2"))
|
||||
raw = raw.replace(/%arg2/g, luatr(data[4]));
|
||||
if (raw.match("%arg"))
|
||||
raw = raw.replace(/%arg/g, luatr(data[3]));
|
||||
|
||||
if (data.length > 3) {
|
||||
for (let i = 4; i < data.length; i++) {
|
||||
raw = raw.replace(new RegExp("%arg" + (i - 2), "g"), data[i]);
|
||||
}
|
||||
|
||||
raw = raw.replace(new RegExp("%arg", "g"), data[3]);
|
||||
}
|
||||
return raw;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.notify.FreeKill"
|
||||
android:installLocation="preferExternal"
|
||||
android:versionCode="415"
|
||||
android:versionName="0.4.15">
|
||||
android:versionCode="417"
|
||||
android:versionName="0.4.17">
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
|
|
21
genfkver.sh
Executable file
21
genfkver.sh
Executable file
|
@ -0,0 +1,21 @@
|
|||
#!/bin/sh
|
||||
|
||||
# 为fk_ver文件追加编译时相关文件列表
|
||||
# 类似其他项目中flist.txt的功能
|
||||
|
||||
cd $(dirname $0)
|
||||
sed -i '2,$d' ./fk_ver
|
||||
|
||||
fn() {
|
||||
for f in $(ls -1 $1 | sort); do
|
||||
if [ -d $1/$f ]; then
|
||||
fn $1/$f
|
||||
else
|
||||
echo $1/$f >> ./fk_ver
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
fn lua
|
||||
fn Fk
|
||||
cd -
|
|
@ -109,7 +109,51 @@
|
|||
</message>
|
||||
<message>
|
||||
<source>packages/%1: some error occured.</source>
|
||||
<translation>拓展包 %1 出了点问题,尝试在管理拓展包中删除之再试试</translation>
|
||||
<translation>拓展包 %1 出了点问题,可以尝试:进入“管理拓展包”,找到 %1,删除,然后再尝试</translation>
|
||||
</message>
|
||||
</context>
|
||||
|
||||
<context>
|
||||
<name>QmlBackend</name>
|
||||
<message>
|
||||
<source>FreeKill</source>
|
||||
<translation>新月杀</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>help: others logged in again with this name</source>
|
||||
<translation>提示:请检查密码是否泄漏</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>help: unknown password error</source>
|
||||
<translation>提示:请使用“编辑服务器”删除该服务器,然后重新添加服务器并重新输入用户名和密码;若为单机启动则在“加入服务器”中选中服务器127.0.0.1,编辑服务器->删除,然后再单机启动</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>help: you have been banned!</source>
|
||||
<translation>提示:此为永久封禁,请联系管理员说明</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>help: you have been temporarily banned!</source>
|
||||
<translation>提示:此为暂时封禁,一般在约二十分钟后自动解禁</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>help: user name not in whitelist</source>
|
||||
<translation>提示:请联系服主解决</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>help: username or password error</source>
|
||||
<translation>提示:可能该用户名已被占用,或者密码错误,如果你是初次注册的话考虑用另一个用户名密码进行登入;若为单机启动则在“加入服务器”中选中服务器127.0.0.1,编辑服务器->删除,然后再单机启动</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>help: md5 fail</source>
|
||||
<translation>检测到MD5错误且未发生拓展包变动,若该情况多次发生请考虑点击主界面“资源修复”蓝色文字</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>fix resource</source>
|
||||
<translation>修复资源文件</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>help: fix resource</source>
|
||||
<translation>点击“确定”将立刻关闭游戏,下次启动时重新复制资源文件,适用于进入服务器多次提示MD5失败,是否继续?</translation>
|
||||
</message>
|
||||
</context>
|
||||
|
||||
|
@ -147,6 +191,10 @@
|
|||
<source>FAQ</source>
|
||||
<translation>常见疑问</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ResFix</source>
|
||||
<translation>资源修复</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>$LoginFAQ</source>
|
||||
<translation>
|
||||
|
@ -286,13 +334,25 @@
|
|||
<source>MD5 check failed!</source>
|
||||
<translation>MD5检测失败!请与服务端保持一致后再登入</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>md5 fail</source>
|
||||
<translation>资源文件错误</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>others logged in with this name</source>
|
||||
<translation>已经有人用这个名字登入了</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>others logged in again with this name</source>
|
||||
<translation>其他人用你的用户名和密码登陆到了服务器,请检查密码是否泄漏</translation>
|
||||
<translation>其他人用你的用户名和密码登陆到了服务器</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>unknown password error</source>
|
||||
<translation>服务端解密密码时出现未知错误</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>user name not in whitelist</source>
|
||||
<translation>你不在该服务器的白名单中!</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>invalid user name</source>
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
---@field public discard_pile integer[] @ 弃牌堆
|
||||
---@field public observing boolean
|
||||
---@field public record any
|
||||
---@field public last_update_ui integer @ 上次刷新状态技UI的时间
|
||||
Client = AbstractRoom:subclass('Client')
|
||||
|
||||
-- load client classes
|
||||
|
@ -65,6 +66,23 @@ function Client:initialize()
|
|||
else
|
||||
self:notifyUI(command, data)
|
||||
end
|
||||
|
||||
if self.recording and command == "GameLog" then
|
||||
--and os.getms() - self.last_update_ui > 60000 then
|
||||
-- self.last_update_ui = os.getms()
|
||||
-- TODO: create a function
|
||||
-- 刷所有人手牌上限
|
||||
for _, p in ipairs(self.alive_players) do
|
||||
self:notifyUI("MaxCard", {
|
||||
pcardMax = p:getMaxCards(),
|
||||
id = p.id,
|
||||
})
|
||||
end
|
||||
-- 刷自己的手牌
|
||||
for _, cid in ipairs(Self:getCardIds("h")) do
|
||||
self:notifyUI("UpdateCard", cid)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self.discard_pile = {}
|
||||
|
@ -72,6 +90,7 @@ function Client:initialize()
|
|||
|
||||
self.disabled_packs = {}
|
||||
self.disabled_generals = {}
|
||||
-- self.last_update_ui = os.getms()
|
||||
|
||||
self.recording = false
|
||||
end
|
||||
|
@ -114,10 +133,6 @@ function Client:moveCards(moves)
|
|||
for _, move in ipairs(moves) do
|
||||
if move.from and move.fromArea then
|
||||
local from = self:getPlayerById(move.from)
|
||||
self:notifyUI("MaxCard", {
|
||||
pcardMax = from:getMaxCards(),
|
||||
id = move.from,
|
||||
})
|
||||
if move.fromArea == Card.PlayerHand and not Self:isBuddy(self:getPlayerById(move.from)) then
|
||||
for _ = 1, #move.ids do
|
||||
table.remove(from.player_cards[Player.Hand])
|
||||
|
@ -133,13 +148,11 @@ function Client:moveCards(moves)
|
|||
|
||||
if move.to and move.toArea then
|
||||
local ids = move.ids
|
||||
self:notifyUI("MaxCard", {
|
||||
pcardMax = self:getPlayerById(move.to):getMaxCards(),
|
||||
id = move.to,
|
||||
})
|
||||
if (not Self:isBuddy(self:getPlayerById(move.to)) and move.toArea == Card.PlayerHand) or table.contains(ids, -1) then
|
||||
ids = table.map(ids, function() return -1 end)
|
||||
if (move.toArea == Card.PlayerHand and not Self:isBuddy(self:getPlayerById(move.to))) or
|
||||
(move.toArea == Card.PlayerSpecial and not move.moveVisible) then
|
||||
ids = {-1}
|
||||
end
|
||||
|
||||
self:getPlayerById(move.to):addCards(move.toArea, ids, move.specialName)
|
||||
elseif move.toArea == Card.DiscardPile then
|
||||
table.insert(self.discard_pile, move.ids[1])
|
||||
|
@ -340,6 +353,7 @@ fk.client_callback["AddObserver"] = function(data)
|
|||
}
|
||||
local p = ClientPlayer:new(player)
|
||||
table.insert(ClientInstance.observers, p)
|
||||
-- ClientInstance:notifyUI("ServerMessage", string.format(Fk:translate("$AddObserver"), name))
|
||||
end
|
||||
|
||||
fk.client_callback["RemoveObserver"] = function(data)
|
||||
|
@ -347,6 +361,7 @@ fk.client_callback["RemoveObserver"] = function(data)
|
|||
for _, p in ipairs(ClientInstance.observers) do
|
||||
if p.player:getId() == id then
|
||||
table.removeOne(ClientInstance.observers, p)
|
||||
-- ClientInstance:notifyUI("ServerMessage", string.format(Fk:translate("$RemoveObserver"), p.player:getScreenName()))
|
||||
break
|
||||
end
|
||||
end
|
||||
|
@ -387,10 +402,6 @@ fk.client_callback["PropertyUpdate"] = function(data)
|
|||
end
|
||||
|
||||
ClientInstance:notifyUI("PropertyUpdate", data)
|
||||
ClientInstance:notifyUI("MaxCard", {
|
||||
pcardMax = ClientInstance:getPlayerById(id):getMaxCards(),
|
||||
id = id,
|
||||
})
|
||||
end
|
||||
|
||||
fk.client_callback["AskForCardChosen"] = function(data)
|
||||
|
@ -474,7 +485,38 @@ end
|
|||
---@param moves CardsMoveStruct[]
|
||||
local function separateMoves(moves)
|
||||
local ret = {} ---@type CardsMoveInfo[]
|
||||
|
||||
local function containArea(area, relevant, defaultVisible) --处理区的处理?
|
||||
local areas = relevant
|
||||
and {Card.PlayerEquip, Card.PlayerJudge, Card.PlayerHand}
|
||||
or {Card.PlayerEquip, Card.PlayerJudge}
|
||||
return table.contains(areas, area) or (defaultVisible and table.contains({Card.Processing, Card.DiscardPile}, area))
|
||||
end
|
||||
|
||||
for _, move in ipairs(moves) do
|
||||
local singleVisible = move.moveVisible
|
||||
if not singleVisible then
|
||||
if move.visiblePlayers then
|
||||
local visiblePlayers = move.visiblePlayers
|
||||
if type(visiblePlayers) == "number" then
|
||||
if Self:isBuddy(visiblePlayers) then
|
||||
singleVisible = true
|
||||
end
|
||||
elseif type(visiblePlayers) == "table" then
|
||||
if table.find(visiblePlayers, function(pid) return Self:isBuddy(pid) end) then
|
||||
singleVisible = true
|
||||
end
|
||||
end
|
||||
else
|
||||
if move.to and move.toArea == Card.PlayerSpecial and Self:isBuddy(move.to) then
|
||||
singleVisible = true
|
||||
end
|
||||
end
|
||||
end
|
||||
if not singleVisible then
|
||||
singleVisible = containArea(move.toArea, move.to and Self:isBuddy(move.to), move.moveVisible == nil)
|
||||
end
|
||||
|
||||
for _, info in ipairs(move.moveInfo) do
|
||||
table.insert(ret, {
|
||||
ids = {info.cardId},
|
||||
|
@ -486,6 +528,7 @@ local function separateMoves(moves)
|
|||
specialName = move.specialName,
|
||||
fromSpecialName = info.fromSpecialName,
|
||||
proposer = move.proposer,
|
||||
moveVisible = singleVisible or containArea(info.fromArea, move.from and Self:isBuddy(move.from), move.moveVisible == nil)
|
||||
})
|
||||
end
|
||||
end
|
||||
|
@ -513,7 +556,7 @@ local function mergeMoves(moves)
|
|||
proposer = move.proposer,
|
||||
}
|
||||
end
|
||||
table.insert(temp[info].ids, move.ids[1])
|
||||
table.insert(temp[info].ids, move.moveVisible and move.ids[1] or -1)
|
||||
end
|
||||
for _, v in pairs(temp) do
|
||||
table.insert(ret, v)
|
||||
|
@ -609,8 +652,27 @@ local function sendMoveCardLog(move)
|
|||
from = move.from,
|
||||
card = move.ids,
|
||||
}
|
||||
-- elseif move.toArea == Card.Processing then
|
||||
-- nop
|
||||
elseif move.toArea == Card.Processing then
|
||||
if move.fromArea == Card.DrawPile and (move.moveReason == fk.ReasonPut or move.moveReason == fk.ReasonJustMove) then
|
||||
if hidden then
|
||||
client:appendLog{
|
||||
type = "$ViewCardFromDrawPile",
|
||||
from = move.proposer,
|
||||
arg = #move.ids,
|
||||
}
|
||||
else
|
||||
client:appendLog{
|
||||
type = "$TurnOverCardFromDrawPile",
|
||||
from = move.proposer,
|
||||
card = move.ids,
|
||||
arg = #move.ids,
|
||||
}
|
||||
client:setCardNote(move.ids, {
|
||||
type = "$$TurnOverCard",
|
||||
from = move.proposer,
|
||||
})
|
||||
end
|
||||
end
|
||||
elseif move.from and move.toArea == Card.DrawPile then
|
||||
msgtype = hidden and "$PutCard" or "$PutKnownCard"
|
||||
client:appendLog{
|
||||
|
@ -1029,7 +1091,7 @@ 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({
|
||||
|
@ -1120,7 +1182,7 @@ local function loadPlayerSummary(pdata)
|
|||
to = id,
|
||||
toArea = Card.PlayerSpecial,
|
||||
specialName = k,
|
||||
specialVisible = Self.id == id,
|
||||
moveVisible = true,
|
||||
}
|
||||
table.insert(card_moves, move)
|
||||
end
|
||||
|
|
|
@ -16,6 +16,8 @@ function GetGeneralData(name)
|
|||
subkingdom = general.subkingdom,
|
||||
hp = general.hp,
|
||||
maxHp = general.maxHp,
|
||||
mainMaxHpAdjustedValue = general.mainMaxHpAdjustedValue,
|
||||
deputyMaxHpAdjustedValue = general.deputyMaxHpAdjustedValue,
|
||||
shield = general.shield,
|
||||
hidden = general.hidden,
|
||||
total_hidden = general.total_hidden,
|
||||
|
@ -31,6 +33,8 @@ function GetGeneralDetail(name)
|
|||
kingdom = general.kingdom,
|
||||
hp = general.hp,
|
||||
maxHp = general.maxHp,
|
||||
mainMaxHp = general.mainMaxHpAdjustedValue,
|
||||
deputyMaxHp = general.deputyMaxHpAdjustedValue,
|
||||
gender = general.gender,
|
||||
skill = {},
|
||||
related_skill = {},
|
||||
|
@ -382,6 +386,22 @@ function CardFeasible(card, selected_targets)
|
|||
return ret
|
||||
end
|
||||
|
||||
---@param card string | integer
|
||||
---@param selected_targets integer[] @ ids of selected players
|
||||
function CardPrompt(card, selected_targets)
|
||||
local c ---@type Card
|
||||
local selected_cards
|
||||
if type(card) == "number" then
|
||||
c = Fk:getCardById(card)
|
||||
selected_cards = {card}
|
||||
else
|
||||
local t = json.decode(card)
|
||||
return ActiveSkillPrompt(t.skill, t.subcards, selected_targets)
|
||||
end
|
||||
|
||||
return ActiveSkillPrompt(c.skill, selected_cards, selected_targets)
|
||||
end
|
||||
|
||||
-- Handle skills
|
||||
|
||||
function GetSkillData(skill_name)
|
||||
|
@ -621,6 +641,7 @@ end
|
|||
function GetInteractionOfSkill(skill_name)
|
||||
local skill = Fk.skills[skill_name]
|
||||
if skill and skill.interaction then
|
||||
skill.interaction.data = nil
|
||||
return skill:interaction()
|
||||
end
|
||||
return nil
|
||||
|
@ -738,10 +759,9 @@ function GetCardProhibitReason(cid, method, pattern)
|
|||
local skillName = s.name
|
||||
local ret = Fk:translate(skillName)
|
||||
if ret ~= skillName then
|
||||
-- TODO: translate
|
||||
return ret .. "禁" .. (method == "use" and "使用" or "打出")
|
||||
return ret .. Fk:translate("prohibit") .. Fk:translate(method == "use" and "method_use" or "method_response_play")
|
||||
elseif skillName:endsWith("_prohibit") and skillName:startsWith("#") then
|
||||
return Fk:translate(skillName:sub(2, -10)) .. "禁" .. (method == "use" and "使用" or "打出")
|
||||
return Fk:translate(skillName:sub(2, -10)) .. Fk:translate("prohibit") .. Fk:translate(method == "use" and "method_use" or "method_response_play")
|
||||
else
|
||||
return ret
|
||||
end
|
||||
|
|
|
@ -12,7 +12,10 @@ Fk:loadTranslationTable({
|
|||
-- ["Old Password"] = "旧密码",
|
||||
-- ["New Password"] = "新密码",
|
||||
-- ["Update Avatar"] = "更新头像",
|
||||
-- ["Update avatar done."] = "头像已更新",
|
||||
-- ["Update Password"] = "更新密码",
|
||||
-- ["Update password done."] = "密码已更新",
|
||||
-- ["Old password wrong!"] = "旧密码错误!",
|
||||
-- ["Lobby BG"] = "大厅壁纸",
|
||||
-- ["Room BG"] = "房间背景",
|
||||
-- ["Game BGM"] = "游戏BGM",
|
||||
|
@ -90,9 +93,14 @@ Fk:loadTranslationTable({
|
|||
["Cards Overview"] = "Cards",
|
||||
["Special card skills:"] = "<b>Special use method:</b>",
|
||||
["Every suit & number:"] = "<b>All suit and number:</b>",
|
||||
-- ["Male Audio"] = "男性音效",
|
||||
-- ["Female Audio"] = "女性音效",
|
||||
-- ["Equip Effect Audio"] = "效果音效",
|
||||
-- ["Equip Use Audio"] = "使用音效",
|
||||
["Scenarios Overview"] = "Game modes",
|
||||
-- ["Replay"] = "录像",
|
||||
-- ["Replay Manager"] = "来欣赏潇洒的录像吧!",
|
||||
-- ["Replay from File"] = "从文件打开",
|
||||
["Game Win"] = "Win",
|
||||
["Game Lose"] = "Lose",
|
||||
["Play the Replay"] = "Play",
|
||||
|
@ -156,7 +164,7 @@ Fk:loadTranslationTable({
|
|||
["IncludeDeputy"] = "<font color=\"red\">Deputy character enabled</font>",
|
||||
|
||||
-- Room
|
||||
["$EnterRoom"] = "Successfully entered the room.",
|
||||
["$EnterRoom"] = "Successfully entered the room",
|
||||
["#currentRoundNum"] = "Round #%1",
|
||||
["$Choice"] = "%1: Please choose",
|
||||
["$ChooseGeneral"] = "Please choose %1 character(s)",
|
||||
|
@ -347,7 +355,7 @@ Fk:loadTranslationTable({
|
|||
|
||||
-- get/lose skill
|
||||
["#AcquireSkill"] = '%from acquired the skill "%arg"',
|
||||
["#LoseSkill"] = '%from lost the skill "%arg"',
|
||||
["#LoseSkill"] = '%from lost the skill "%arg"',
|
||||
|
||||
-- moveCards (they are sent by notifyMoveCards)
|
||||
["$PutCard"] = "%arg card(s) of %from were put into draw pile",
|
||||
|
@ -405,8 +413,8 @@ Fk:loadTranslationTable({
|
|||
|
||||
-- turnOver
|
||||
["#TurnOver"] = "%from turned over character card, now his status is %arg",
|
||||
["face_up"] = "face up",
|
||||
["face_down"] = "face down",
|
||||
["face_up"] = "face up",
|
||||
["face_down"] = "face down",
|
||||
|
||||
-- damage, heal and lose HP
|
||||
["#Damage"] = "%to dealt %arg %arg2 DMG to %from",
|
||||
|
@ -443,4 +451,6 @@ Fk:loadTranslationTable({
|
|||
["##ResponsePlayCard"] = "%from plays",
|
||||
["##ShowCard"] = "%from shows",
|
||||
["##JudgeCard"] = "%arg judge",
|
||||
["##PindianCard"] = "%from point fights",
|
||||
["##RecastCard"] = "%from recasts",
|
||||
}, "en_US")
|
||||
|
|
|
@ -12,7 +12,10 @@ Fk:loadTranslationTable{
|
|||
["Old Password"] = "旧密码",
|
||||
["New Password"] = "新密码",
|
||||
["Update Avatar"] = "更新头像",
|
||||
["Update avatar done."] = "头像已更新",
|
||||
["Update Password"] = "更新密码",
|
||||
["Update password done."] = "密码已更新",
|
||||
["Old password wrong!"] = "旧密码错误!",
|
||||
["Lobby BG"] = "大厅壁纸",
|
||||
["Room BG"] = "房间背景",
|
||||
["Game BGM"] = "游戏BGM",
|
||||
|
@ -31,7 +34,7 @@ Fk:loadTranslationTable{
|
|||
["Search"] = "搜索",
|
||||
["Back"] = "返回",
|
||||
|
||||
["Refresh Room List"] = "刷新房间列表",
|
||||
["Refresh Room List"] = "刷新房间列表 (%1个房间)",
|
||||
|
||||
["Disable Extension"] = "禁用Lua拓展 (重启后生效)",
|
||||
["Create Room"] = "创建房间",
|
||||
|
@ -100,9 +103,12 @@ Fk:loadTranslationTable{
|
|||
["Every suit & number:"] = "<b>所有的花色和点数:</b>",
|
||||
["Male Audio"] = "男性音效",
|
||||
["Female Audio"] = "女性音效",
|
||||
["Equip Effect Audio"] = "效果音效",
|
||||
["Equip Use Audio"] = "使用音效",
|
||||
["Scenarios Overview"] = "玩法一览",
|
||||
["Replay"] = "录像",
|
||||
["Replay Manager"] = "来欣赏潇洒的录像吧!",
|
||||
["Replay from File"] = "从文件打开",
|
||||
["Game Win"] = "胜利",
|
||||
["Game Lose"] = "失败",
|
||||
["Play the Replay"] = "重放",
|
||||
|
@ -212,7 +218,7 @@ FreeKill使用的是libgit2的C API,与此同时使用Git完成拓展包的下
|
|||
["IncludeDeputy"] = "<font color=\"red\">启用副将机制</font>",
|
||||
|
||||
-- Room
|
||||
["$EnterRoom"] = "成功加入房间。",
|
||||
["$EnterRoom"] = "成功加入房间",
|
||||
["#currentRoundNum"] = "第 %1 轮",
|
||||
["$Choice"] = "%1:请选择",
|
||||
["$ChooseGeneral"] = "请选择 %1 名武将",
|
||||
|
@ -222,7 +228,7 @@ FreeKill使用的是libgit2的C API,与此同时使用Git完成拓展包的下
|
|||
|
||||
["#PlayCard"] = "出牌阶段,请使用一张牌",
|
||||
["#AskForGeneral"] = "请选择 1 名武将",
|
||||
["#AskForSkillInvoke"] = "你想发动技能“%1”吗?",
|
||||
["#AskForSkillInvoke"] = "你想发动〖%1〗吗?",
|
||||
["#AskForLuckCard"] = "你想使用手气卡吗?还可以使用 %1 次,剩余手气卡∞张",
|
||||
["AskForLuckCard"] = "手气卡",
|
||||
["#AskForChoice"] = "%1:请选择",
|
||||
|
@ -254,13 +260,13 @@ FreeKill使用的是libgit2的C API,与此同时使用Git完成拓展包的下
|
|||
["$Equip"] = "装备区",
|
||||
["$Judge"] = "判定区",
|
||||
['$Selected'] = "已选择",
|
||||
["#AskForUseActiveSkill"] = "请使用技能 %1",
|
||||
["#AskForUseCard"] = "请使用卡牌 %1",
|
||||
["#AskForResponseCard"] = "请打出卡牌 %1",
|
||||
["#AskForNullification"] = "是否为目标为 %dest 的 %arg 使用无懈可击?",
|
||||
["#AskForNullificationWithoutTo"] = "是否对 %src 使用的 %arg 使用无懈可击?",
|
||||
["#AskForPeaches"] = "%src 生命危急,需要 %arg 个桃",
|
||||
["#AskForPeachesSelf"] = "你生命危急,需要 %arg 个桃或酒",
|
||||
["#AskForUseActiveSkill"] = "请发动〖%1〗",
|
||||
["#AskForUseCard"] = "请使用【%1】",
|
||||
["#AskForResponseCard"] = "请打出【%1】",
|
||||
["#AskForNullification"] = "是否为目标为 %dest 的【%arg】使用【无懈可击】?",
|
||||
["#AskForNullificationWithoutTo"] = "是否对 %src 使用的【%arg】使用【无懈可击】?",
|
||||
["#AskForPeaches"] = "%src 生命危急,需要 %arg 个【桃】",
|
||||
["#AskForPeachesSelf"] = "你生命危急,需要 %arg 个【桃】或【酒】",
|
||||
|
||||
["#AskForDiscard"] = "请弃置 %arg 张牌,最少 %arg2 张",
|
||||
["#AskForCard"] = "请选择 %arg 张牌,最少 %arg2 张",
|
||||
|
@ -322,6 +328,9 @@ FreeKill使用的是libgit2的C API,与此同时使用Git完成拓展包的下
|
|||
["Back To Lobby"] = "返回大厅",
|
||||
["Save Replay"] = "保存录像",
|
||||
|
||||
["$AddObserver"] = '玩家 <b>%s</b> 开始旁观',
|
||||
["$RemoveObserver"] = '旁观者 <b>%s</b> 离开了房间',
|
||||
|
||||
["Speed Resume"] = "匀速",
|
||||
["Speed Up"] = "加速",
|
||||
["Speed Down"] = "减速",
|
||||
|
@ -373,6 +382,7 @@ Fk:loadTranslationTable{
|
|||
["pile_discard"] = "弃牌堆",
|
||||
["processing_area"] = "处理区",
|
||||
["Pile"] = "牌堆",
|
||||
["toObtain"] = "获得的牌",
|
||||
["Top"] = "牌堆顶",
|
||||
["Bottom"] = "牌堆底",
|
||||
["Shuffle"] = "洗牌",
|
||||
|
@ -408,8 +418,8 @@ Fk:loadTranslationTable{
|
|||
["$GameEnd"] = "== 游戏结束 ==",
|
||||
|
||||
-- get/lose skill
|
||||
["#AcquireSkill"] = "%from 获得了技能 “%arg”",
|
||||
["#LoseSkill"] = "%from 失去了技能 “%arg”",
|
||||
["#AcquireSkill"] = "%from 获得了〖%arg〗",
|
||||
["#LoseSkill"] = "%from 失去了〖%arg〗",
|
||||
|
||||
-- moveCards (they are sent by notifyMoveCards)
|
||||
["$GetCardsFromPile"] = "%from 从 %arg 中获得了 %arg2 张牌 %card",
|
||||
|
@ -432,6 +442,8 @@ Fk:loadTranslationTable{
|
|||
["$DiscardCards"] = "%from 弃置了 %arg 张牌 %card",
|
||||
["$DiscardOther"] = "%to 弃置了 %from 的 %arg 张牌 %card",
|
||||
["$PutToDiscard"] = "%arg 张牌 %card 被置入弃牌堆",
|
||||
["$ViewCardFromDrawPile"] = "%from 观看了 %arg 张牌",
|
||||
["$TurnOverCardFromDrawPile"] = "%from 亮出了 %arg 张牌 %card",
|
||||
|
||||
["#AbortArea"] = "%from 的 %arg 被废除",
|
||||
["#ResumeArea"] = "%from 的 %arg 被恢复",
|
||||
|
@ -464,30 +476,30 @@ Fk:loadTranslationTable{
|
|||
["#FilterCard"] = "由于 %arg 的效果,与 %from 相关的 %arg2 被视为了 %arg3",
|
||||
|
||||
-- skill
|
||||
["#InvokeSkill"] = "%from 发动了 “%arg”",
|
||||
["#InvokeSkill"] = "%from 发动了〖%arg〗",
|
||||
|
||||
-- judge
|
||||
["#StartJudgeReason"] = "%from 开始了 %arg 的判定",
|
||||
["#InitialJudge"] = "%from 的判定牌为 %arg",
|
||||
["#ChangedJudge"] = "%from 发动“%arg”把 %to 的判定牌改为 %arg2",
|
||||
["#ChangedJudge"] = "%from 发动了〖%arg〗把 %to 的判定牌改为 %arg2",
|
||||
["#JudgeResult"] = "%from 的判定结果为 %arg",
|
||||
|
||||
-- turnOver
|
||||
["#TurnOver"] = "%from 将武将牌翻面,现在是 %arg",
|
||||
["face_up"] = "正面朝上",
|
||||
["face_down"] = "背面朝上",
|
||||
["face_up"] = "正面朝上",
|
||||
["face_down"] = "背面朝上",
|
||||
|
||||
-- damage, heal and lose HP
|
||||
["#Damage"] = "%to 对 %from 造成了 %arg 点 %arg2 伤害",
|
||||
["#DamageWithNoFrom"] = "%from 受到了 %arg 点 %arg2 伤害",
|
||||
["#LoseHP"] = "%from 失去了 %arg 点体力",
|
||||
["#HealHP"] = "%from 回复了 %arg 点体力",
|
||||
["#ShowHPAndMaxHP"] = "%from 现在的体力值为 %arg,体力上限为 %arg2",
|
||||
["#ShowHPAndMaxHP"] = "%from 的体力值为 %arg,体力上限为 %arg2",
|
||||
["#LoseMaxHP"] = "%from 减了 %arg 点体力上限",
|
||||
["#HealMaxHP"] = "%from 加了 %arg 点体力上限",
|
||||
|
||||
-- dying and death
|
||||
["#EnterDying"] = "%from 进入了濒死阶段",
|
||||
["#EnterDying"] = "%from 进入了濒死状态",
|
||||
["#KillPlayer"] = "%from [%arg] 阵亡,凶手是 %to",
|
||||
["#KillPlayerWithNoKiller"] = "%from [%arg] 阵亡,无伤害来源",
|
||||
["#Revive"] = "%from 竟然复活了",
|
||||
|
@ -499,7 +511,7 @@ Fk:loadTranslationTable{
|
|||
["#GuanxingResult"] = "%from 的观星结果为 %arg 上 %arg2 下",
|
||||
["#ChainStateChange"] = "%from %arg 了武将牌",
|
||||
["#ChainDamage"] = "%from 处于连环状态,将受到传导的伤害",
|
||||
["#ChangeKingdom"] = "%from 的国籍从 %arg 变成了 %arg2",
|
||||
["#ChangeKingdom"] = "%from 的势力从 %arg 变成了 %arg2",
|
||||
["#RoomOutdated"] = "服务器更新完毕!该房间已过期,将无法再次游玩",
|
||||
}
|
||||
|
||||
|
@ -507,10 +519,13 @@ Fk:loadTranslationTable{
|
|||
Fk:loadTranslationTable{
|
||||
["$$DiscardCards"] = "%from弃置",
|
||||
["$$PutCard"] = "%from置于",
|
||||
["$$TurnOverCard"] = "%from亮出",
|
||||
|
||||
["##UseCard"] = "%from使用",
|
||||
["##UseCardTo"] = "%from对%to",
|
||||
["##ResponsePlayCard"] = "%from打出",
|
||||
["##ShowCard"] = "%from展示",
|
||||
["##JudgeCard"] = "%arg判定",
|
||||
["##PindianCard"] = "%from拼点",
|
||||
["##RecastCard"] = "%from重铸",
|
||||
}
|
||||
|
|
|
@ -2,33 +2,80 @@
|
|||
|
||||
---@class EquipCard : Card
|
||||
---@field public equip_skill Skill
|
||||
---@field public equip_skills Skill[]
|
||||
---@field public dynamicEquipSkills fun(player: Player): Skill[]
|
||||
local EquipCard = Card:subclass("EquipCard")
|
||||
|
||||
function EquipCard:initialize(name, suit, number)
|
||||
Card.initialize(self, name, suit, number)
|
||||
self.type = Card.TypeEquip
|
||||
self.equip_skill = nil
|
||||
self.equip_skills = nil
|
||||
self.dynamicEquipSkills = nil
|
||||
end
|
||||
|
||||
---@param room Room
|
||||
---@param player Player
|
||||
function EquipCard:onInstall(room, player)
|
||||
if self.equip_skill then
|
||||
room:handleAddLoseSkills(player, self.equip_skill.name, nil, false, true)
|
||||
local equipSkills = self:getEquipSkills(player)
|
||||
if #equipSkills > 0 then
|
||||
local noTrigger = table.filter(equipSkills, function(skill) return skill.attached_equip end)
|
||||
if #noTrigger > 0 then
|
||||
noTrigger = table.map(noTrigger, function(skill) return skill.name end)
|
||||
room:handleAddLoseSkills(player, table.concat(noTrigger, "|"), nil, false, true)
|
||||
end
|
||||
|
||||
local toTrigger = table.filter(equipSkills, function(skill) return not skill.attached_equip end)
|
||||
if #toTrigger > 0 then
|
||||
toTrigger = table.map(toTrigger, function(skill) return skill.name end)
|
||||
room:handleAddLoseSkills(player, table.concat(toTrigger, "|"), nil, false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param room Room
|
||||
---@param player Player
|
||||
function EquipCard:onUninstall(room, player)
|
||||
if self.equip_skill then
|
||||
room:handleAddLoseSkills(player, "-" .. self.equip_skill.name, nil, false, true)
|
||||
local equipSkills = self:getEquipSkills(player)
|
||||
if #equipSkills > 0 then
|
||||
local noTrigger = table.filter(equipSkills, function(skill) return skill.attached_equip end)
|
||||
if #noTrigger > 0 then
|
||||
noTrigger = table.map(noTrigger, function(skill) return '-' .. skill.name end)
|
||||
room:handleAddLoseSkills(player, table.concat(noTrigger, "|"), nil, false, true)
|
||||
end
|
||||
|
||||
local toTrigger = table.filter(equipSkills, function(skill) return not skill.attached_equip end)
|
||||
if #toTrigger > 0 then
|
||||
toTrigger = table.map(toTrigger, function(skill) return '-' .. skill.name end)
|
||||
room:handleAddLoseSkills(player, table.concat(toTrigger, "|"), nil, false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param player Player
|
||||
---@return Skill[]
|
||||
function EquipCard:getEquipSkills(player)
|
||||
if self.dynamicEquipSkills then
|
||||
local equipSkills = self:dynamicEquipSkills(player)
|
||||
if equipSkills and #equipSkills > 0 then
|
||||
return equipSkills
|
||||
end
|
||||
end
|
||||
|
||||
if self.equip_skills then
|
||||
return self.equip_skills
|
||||
elseif self.equip_skill then
|
||||
return { self.equip_skill }
|
||||
end
|
||||
|
||||
return {}
|
||||
end
|
||||
|
||||
function EquipCard:clone(suit, number)
|
||||
local ret = Card.clone(self, suit, number)
|
||||
ret.equip_skill = self.equip_skill
|
||||
ret.equip_skills = self.equip_skills
|
||||
ret.dynamicEquipSkills = self.dynamicEquipSkills
|
||||
ret.onInstall = self.onInstall
|
||||
ret.onUninstall = self.onUninstall
|
||||
return ret
|
||||
|
@ -36,6 +83,7 @@ end
|
|||
|
||||
---@class Weapon : EquipCard
|
||||
---@field public attack_range integer
|
||||
---@field public dynamicAttackRange? fun(player: Player): int
|
||||
local Weapon = EquipCard:subclass("Weapon")
|
||||
|
||||
function Weapon:initialize(name, suit, number, attackRange)
|
||||
|
@ -47,9 +95,21 @@ end
|
|||
function Weapon:clone(suit, number)
|
||||
local ret = EquipCard.clone(self, suit, number)
|
||||
ret.attack_range = self.attack_range
|
||||
ret.dynamicAttackRange = self.dynamicAttackRange
|
||||
return ret
|
||||
end
|
||||
|
||||
function Weapon:getAttackRange(player)
|
||||
if type(self.dynamicAttackRange) == "function" then
|
||||
local currentAttackRange = self:dynamicAttackRange(player)
|
||||
if currentAttackRange then
|
||||
return currentAttackRange
|
||||
end
|
||||
end
|
||||
|
||||
return self.attack_range
|
||||
end
|
||||
|
||||
---@class Armor : EquipCard
|
||||
local Armor = EquipCard:subclass("armor")
|
||||
|
||||
|
|
|
@ -676,9 +676,10 @@ end
|
|||
---
|
||||
--- 其实就是翻译了 ":" .. name 罢了
|
||||
---@param name string @ 要获得描述的名字
|
||||
---@param lang? string @ 要使用的语言,默认读取config
|
||||
---@return string @ 描述
|
||||
function Engine:getDescription(name)
|
||||
return self:translate(":" .. name)
|
||||
function Engine:getDescription(name, lang)
|
||||
return self:translate(":" .. name, lang)
|
||||
end
|
||||
|
||||
return Engine
|
||||
|
|
|
@ -71,4 +71,16 @@ function GameMode:countInFunc(room)
|
|||
return true
|
||||
end
|
||||
|
||||
-- 修改角色的属性
|
||||
---@param player ServerPlayer
|
||||
---@return table @ 返回表,键为调整的角色属性,值为调整后的属性
|
||||
function GameMode:getAdjustedProperty (player)
|
||||
local list = {}
|
||||
if player.role == "lord" and player.role_shown and #player.room.players > 4 then
|
||||
list.hp = player.hp + 1
|
||||
list.maxHp = player.maxHp + 1
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
return GameMode
|
||||
|
|
|
@ -260,13 +260,7 @@ function Player:removeCards(playerArea, cardIds, specialName)
|
|||
if #fromAreaIds == 0 then
|
||||
break
|
||||
end
|
||||
|
||||
if table.contains(fromAreaIds, id) then
|
||||
table.removeOne(fromAreaIds, id)
|
||||
-- FIXME: 为客户端移动id为-1的牌考虑,但总感觉有地方需要商讨啊!
|
||||
elseif table.every(fromAreaIds, function(e) return e == -1 end) then
|
||||
table.remove(fromAreaIds, 1)
|
||||
elseif id == -1 then
|
||||
if not table.removeOne(fromAreaIds, id) and not table.removeOne(fromAreaIds, -1) then
|
||||
table.remove(fromAreaIds, 1)
|
||||
end
|
||||
end
|
||||
|
@ -455,7 +449,7 @@ function Player:getAttackRange()
|
|||
baseValue = 0
|
||||
for _, id in ipairs(weapons) do
|
||||
local weapon = Fk:getCardById(id)
|
||||
baseValue = math.max(baseValue, weapon.attack_range or 1)
|
||||
baseValue = math.max(baseValue, weapon:getAttackRange(self) or 1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -563,7 +557,7 @@ end
|
|||
--- 比较距离
|
||||
---@param other Player @ 终点角色
|
||||
---@param num integer @ 比较基准
|
||||
---@param operator string @ 运算符,有 ``"<"`` ``">"`` ``"<="`` ``">="`` ``"=="`` ``"~="``
|
||||
---@param operator "<"|">"|"<="|">="|"=="|"~=" @ 运算符
|
||||
---@return boolean @ 返回比较结果,不计入距离结果永远为false
|
||||
function Player:compareDistance(other, num, operator)
|
||||
local distance = self:distanceTo(other)
|
||||
|
@ -596,6 +590,11 @@ function Player:inMyAttackRange(other, fixLimit)
|
|||
fixLimit = fixLimit or 0
|
||||
|
||||
local status_skills = Fk:currentRoom().status_skills[AttackRangeSkill] or Util.DummyTable
|
||||
for _, skill in ipairs(status_skills) do
|
||||
if skill:withoutAttackRange(self, other) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
for _, skill in ipairs(status_skills) do
|
||||
if skill:withinAttackRange(self, other) then
|
||||
return true
|
||||
|
@ -609,7 +608,8 @@ end
|
|||
--- 获取下家。
|
||||
---@param ignoreRemoved? boolean @ 忽略被移除
|
||||
---@param num? integer @ 第几个,默认1
|
||||
---@return ServerPlayer
|
||||
---@param ignoreRest? boolean @ 是否忽略休整
|
||||
---@return Player
|
||||
function Player:getNextAlive(ignoreRemoved, num, ignoreRest)
|
||||
if #Fk:currentRoom().alive_players == 0 then
|
||||
return self.rest > 0 and self.next.rest > 0 and self.next or self
|
||||
|
@ -631,9 +631,9 @@ function Player:getNextAlive(ignoreRemoved, num, ignoreRest)
|
|||
end
|
||||
|
||||
--- 获取上家。
|
||||
---@param ignoreRemoved boolean @ 忽略被移除
|
||||
---@param ignoreRemoved? boolean @ 忽略被移除
|
||||
---@param num? integer @ 第几个,默认1
|
||||
---@return ServerPlayer
|
||||
---@return Player
|
||||
function Player:getLastAlive(ignoreRemoved, num)
|
||||
num = num or 1
|
||||
local index = (ignoreRemoved and #Fk:currentRoom().alive_players or #table.filter(Fk:currentRoom().alive_players, function(p) return not p:isRemoved() end)) - num
|
||||
|
@ -1019,9 +1019,11 @@ function Player:prohibitReveal(isDeputy)
|
|||
return false
|
||||
end
|
||||
|
||||
---@param to Player
|
||||
---@param ignoreFromKong? boolean
|
||||
---@param ignoreToKong? boolean
|
||||
--- 判断能否拼点
|
||||
---@param to Player @ 拼点对象
|
||||
---@param ignoreFromKong? boolean @ 忽略发起者没有手牌
|
||||
---@param ignoreToKong? boolean @ 忽略对象没有手牌
|
||||
---@return boolean
|
||||
function Player:canPindian(to, ignoreFromKong, ignoreToKong)
|
||||
if self == to then return false end
|
||||
|
||||
|
@ -1073,6 +1075,10 @@ function Player:getSwitchSkillState(skillName, afterUse, inWord)
|
|||
end
|
||||
end
|
||||
|
||||
--- 是否能移动特定牌至特定角色
|
||||
---@param to Player @ 移动至的角色
|
||||
---@param id integer @ 移动的牌
|
||||
---@return boolean
|
||||
function Player:canMoveCardInBoardTo(to, id)
|
||||
if self == to then
|
||||
return false
|
||||
|
@ -1094,6 +1100,11 @@ function Player:canMoveCardInBoardTo(to, id)
|
|||
end
|
||||
end
|
||||
|
||||
--- 是否能移动特定牌至特定角色
|
||||
--- @param to Player @ 移动至的角色
|
||||
--- @param flag? string @ 移动的区域,`e`为装备区,`j`为判定区,`nil`为装备区和判定区
|
||||
--- @param excludeIds? integer[] @ 排除的牌
|
||||
---@return boolean
|
||||
function Player:canMoveCardsInBoardTo(to, flag, excludeIds)
|
||||
if self == to then
|
||||
return false
|
||||
|
@ -1120,6 +1131,9 @@ function Player:canMoveCardsInBoardTo(to, flag, excludeIds)
|
|||
return false
|
||||
end
|
||||
|
||||
--- 获取使命技状态
|
||||
---@param skillName string
|
||||
---@return string? @ 存在返回`failed` or `succeed`,不存在返回`nil`
|
||||
function Player:getQuestSkillState(skillName)
|
||||
local questSkillState = self:getMark(MarkEnum.QuestSkillPreName .. skillName)
|
||||
return type(questSkillState) == "string" and questSkillState or nil
|
||||
|
|
|
@ -90,8 +90,19 @@ function Skill:addRelatedSkill(skill)
|
|||
end
|
||||
|
||||
--- 确认本技能是否为装备技能。
|
||||
---@param player Player
|
||||
---@return boolean
|
||||
function Skill:isEquipmentSkill()
|
||||
function Skill:isEquipmentSkill(player)
|
||||
if player then
|
||||
local filterSkills = Fk:currentRoom().status_skills[FilterSkill]
|
||||
for _, filter in ipairs(filterSkills) do
|
||||
local result = filter:equipSkillFilter(self, player)
|
||||
if result then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return self.attached_equip and type(self.attached_equip) == 'string' and self.attached_equip ~= ""
|
||||
end
|
||||
|
||||
|
@ -126,4 +137,11 @@ function Skill:isSwitchSkill()
|
|||
return self.switchSkillName and type(self.switchSkillName) == 'string' and self.switchSkillName ~= ""
|
||||
end
|
||||
|
||||
--判断技能是否为角色技能
|
||||
---@param player Player
|
||||
---@return boolean
|
||||
function Skill:isPlayerSkill(player)
|
||||
return not (self:isEquipmentSkill(player) or self.name:endsWith("&"))
|
||||
end
|
||||
|
||||
return Skill
|
||||
|
|
|
@ -21,47 +21,51 @@ function ActiveSkill:initialize(name, frequency)
|
|||
end
|
||||
|
||||
---------
|
||||
-- Note: these functions are used both client and ai
|
||||
-- 注:客户端函数,AI也会调用以作主动技判断
|
||||
------- {
|
||||
|
||||
--- Determine whether the skill can be used in playing phase
|
||||
---@param player Player
|
||||
---@param card Card @ helper
|
||||
-- 判断该技能是否可主动发动
|
||||
---@param player Player @ 使用者
|
||||
---@param card Card @ 牌
|
||||
---@param extra_data UseExtraData @ 额外数据
|
||||
---@return bool
|
||||
function ActiveSkill:canUse(player, card, extra_data)
|
||||
return self:isEffectable(player)
|
||||
end
|
||||
|
||||
--- Determine whether a card can be selected by this skill
|
||||
--- only used in skill of players
|
||||
---@param to_select integer @ id of a card not selected
|
||||
---@param selected integer[] @ ids of selected cards
|
||||
---@param selected_targets integer[] @ ids of selected players
|
||||
-- 判断一张牌是否可被此技能选中
|
||||
---@param to_select integer @ 待选牌
|
||||
---@param selected integer[] @ 已选牌
|
||||
---@param selected_targets integer[] @ 已选目标
|
||||
---@return bool
|
||||
function ActiveSkill:cardFilter(to_select, selected, selected_targets)
|
||||
return true
|
||||
end
|
||||
|
||||
--- Determine whether a target can be selected by this skill
|
||||
--- only used in skill of players
|
||||
---@param to_select integer @ id of the target
|
||||
---@param selected integer[] @ ids of selected targets
|
||||
---@param selected_cards integer[] @ ids of selected cards
|
||||
---@param card Card @ helper
|
||||
---@param extra_data? any @ extra_data
|
||||
-- 判断一名角色是否可被此技能选中
|
||||
---@param to_select integer @ 待选目标
|
||||
---@param selected integer[] @ 已选目标
|
||||
---@param selected_cards integer[] @ 已选牌
|
||||
---@param card Card @ 牌
|
||||
---@param extra_data UseExtraData @ 额外数据
|
||||
---@return bool
|
||||
function ActiveSkill:targetFilter(to_select, selected, selected_cards, card, extra_data)
|
||||
return false
|
||||
end
|
||||
|
||||
--- Determine whether a target can be selected by this skill(in modifying targets)
|
||||
--- only used in skill of players
|
||||
---@param to_select integer @ id of the target
|
||||
---@param selected? integer[] @ ids of selected targets
|
||||
---@param user? integer @ id of the userdata
|
||||
---@param card? Card @ helper
|
||||
---@param distance_limited? boolean @ is limited by distance
|
||||
-- 判断一名角色是否可成为此技能的目标
|
||||
---@param to_select integer @ 待选目标
|
||||
---@param selected integer[] @ 已选目标
|
||||
---@param user? integer @ 使用者
|
||||
---@param card? Card @ 牌
|
||||
---@param distance_limited? boolean @ 是否受距离限制
|
||||
---@return bool
|
||||
function ActiveSkill:modTargetFilter(to_select, selected, user, card, distance_limited)
|
||||
return false
|
||||
end
|
||||
|
||||
-- 获得技能的最小目标数
|
||||
---@return number @ 最小目标数
|
||||
function ActiveSkill:getMinTargetNum()
|
||||
local ret
|
||||
if self.target_num then ret = self.target_num
|
||||
|
@ -78,6 +82,10 @@ function ActiveSkill:getMinTargetNum()
|
|||
end
|
||||
end
|
||||
|
||||
-- 获得技能的最大目标数
|
||||
---@param player Player @ 使用者
|
||||
---@param card Card @ 牌
|
||||
---@return number @ 最大目标数
|
||||
function ActiveSkill:getMaxTargetNum(player, card)
|
||||
local ret
|
||||
if self.target_num then ret = self.target_num
|
||||
|
@ -100,6 +108,8 @@ function ActiveSkill:getMaxTargetNum(player, card)
|
|||
return ret
|
||||
end
|
||||
|
||||
-- 获得技能的最小卡牌数
|
||||
---@return number @ 最小卡牌数
|
||||
function ActiveSkill:getMinCardNum()
|
||||
local ret
|
||||
if self.card_num then ret = self.card_num
|
||||
|
@ -116,6 +126,8 @@ function ActiveSkill:getMinCardNum()
|
|||
end
|
||||
end
|
||||
|
||||
-- 获得技能的最大卡牌数
|
||||
---@return number @ 最大卡牌数
|
||||
function ActiveSkill:getMaxCardNum()
|
||||
local ret
|
||||
if self.card_num then ret = self.card_num
|
||||
|
@ -132,6 +144,11 @@ function ActiveSkill:getMaxCardNum()
|
|||
end
|
||||
end
|
||||
|
||||
-- 获得技能的距离限制
|
||||
---@param player Player @ 使用者
|
||||
---@param card Card @ 使用卡牌
|
||||
---@param to Player @ 目标
|
||||
---@return number @ 距离限制
|
||||
function ActiveSkill:getDistanceLimit(player, card, to)
|
||||
local ret = self.distance_limit or 0
|
||||
local status_skills = Fk:currentRoom().status_skills[TargetModSkill] or Util.DummyTable
|
||||
|
@ -143,8 +160,14 @@ function ActiveSkill:getDistanceLimit(player, card, to)
|
|||
return ret
|
||||
end
|
||||
|
||||
-- 判断一个角色是否在技能的距离限制内
|
||||
---@param player Player @ 使用者
|
||||
---@param isattack bool @ 是否使用攻击距离
|
||||
---@param card Card @ 使用卡牌
|
||||
---@param to Player @ 目标
|
||||
---@return bool
|
||||
function ActiveSkill:withinDistanceLimit(player, isattack, card, to)
|
||||
if to and to.dead then return false end
|
||||
if not to or player:distanceTo(to) < 1 then return false end
|
||||
local status_skills = Fk:currentRoom().status_skills[TargetModSkill] or Util.DummyTable
|
||||
if not card and self.name:endsWith("_skill") then
|
||||
card = Fk:cloneCard(self.name:sub(1, #self.name - 6))
|
||||
|
@ -174,7 +197,7 @@ function ActiveSkill:withinDistanceLimit(player, isattack, card, to)
|
|||
end
|
||||
|
||||
return (isattack and player:inMyAttackRange(to)) or
|
||||
(player:distanceTo(to) > 0 and player:distanceTo(to) <= self:getDistanceLimit(player, card, to)) or
|
||||
(player:distanceTo(to) <= self:getDistanceLimit(player, card, to)) or
|
||||
hasMark(card, MarkEnum.BypassDistancesLimit, card_temp_suf) or
|
||||
hasMark(player, MarkEnum.BypassDistancesLimit, temp_suf) or
|
||||
hasMark(to, MarkEnum.BypassDistancesLimitTo, temp_suf)
|
||||
|
@ -189,26 +212,32 @@ function ActiveSkill:withinDistanceLimit(player, isattack, card, to)
|
|||
-- end)))
|
||||
end
|
||||
|
||||
--- Determine if selected cards and targets are valid for this skill
|
||||
--- If returns true, the OK button should be enabled
|
||||
--- only used in skill of players
|
||||
|
||||
-- NOTE: don't reclaim it
|
||||
---@param selected integer[] @ ids of selected players
|
||||
---@param selected_cards integer[] @ ids of selected cards
|
||||
-- 判断一个技能是否可发动(也就是确认键是否可点击)
|
||||
-- 警告:没啥事别改
|
||||
---@param selected integer[] @ 已选目标
|
||||
---@param selected_cards integer[] @ 已选牌
|
||||
---@param player Player @ 使用者
|
||||
---@param card Card @ 牌
|
||||
---@return bool
|
||||
function ActiveSkill:feasible(selected, selected_cards, player, card)
|
||||
return #selected >= self:getMinTargetNum() and #selected <= self:getMaxTargetNum(player, card)
|
||||
and #selected_cards >= self:getMinCardNum() and #selected_cards <= self:getMaxCardNum()
|
||||
end
|
||||
|
||||
-- 使用技能时默认的烧条提示(一般会在主动使用时出现)
|
||||
---@param selected_cards integer[] @ 已选牌
|
||||
---@param selected_targets integer[] @ 已选目标
|
||||
---@return string?
|
||||
function ActiveSkill:prompt(selected_cards, selected_targets) return "" end
|
||||
|
||||
------- }
|
||||
|
||||
---@param room Room
|
||||
---@param cardUseEvent CardUseStruct
|
||||
---@param cardUseEvent CardUseStruct | SkillEffectEvent
|
||||
function ActiveSkill:onUse(room, cardUseEvent) end
|
||||
|
||||
---@param room Room
|
||||
---@param cardUseEvent CardUseStruct
|
||||
---@param cardUseEvent CardUseStruct | SkillEffectEvent
|
||||
---@param finished? bool
|
||||
function ActiveSkill:onAction(room, cardUseEvent, finished) end
|
||||
|
||||
|
@ -225,8 +254,4 @@ function ActiveSkill:onEffect(room, cardEffectEvent) end
|
|||
---@param cardEffectEvent CardEffectEvent | SkillEffectEvent
|
||||
function ActiveSkill:onNullified(room, cardEffectEvent) end
|
||||
|
||||
---@param selected_cards integer[] @ ids of selected cards
|
||||
---@param selected_targets integer[] @ ids of selected players
|
||||
function ActiveSkill:prompt(selected_cards, selected_targets) return "" end
|
||||
|
||||
return ActiveSkill
|
||||
|
|
|
@ -15,8 +15,18 @@ function AttackRangeSkill:getFixed(from)
|
|||
return nil
|
||||
end
|
||||
|
||||
---@param from Player
|
||||
---@param to Player
|
||||
---@return boolean
|
||||
function AttackRangeSkill:withinAttackRange(from, to)
|
||||
return false
|
||||
end
|
||||
|
||||
---@param from Player
|
||||
---@param to Player
|
||||
---@return boolean
|
||||
function AttackRangeSkill:withoutAttackRange(from, to)
|
||||
return false
|
||||
end
|
||||
|
||||
return AttackRangeSkill
|
||||
|
|
|
@ -17,4 +17,11 @@ function FilterSkill:viewAs(card, player)
|
|||
return nil
|
||||
end
|
||||
|
||||
---@param skill Skill
|
||||
---@param player Player
|
||||
---@return string
|
||||
function FilterSkill:equipSkillFilter(skill, player)
|
||||
return nil
|
||||
end
|
||||
|
||||
return FilterSkill
|
||||
|
|
|
@ -14,6 +14,12 @@ function UsableSkill:initialize(name, frequency)
|
|||
self.max_use_time = {9999, 9999, 9999, 9999}
|
||||
end
|
||||
|
||||
-- 获得技能的最大使用次数
|
||||
---@param player Player @ 使用者
|
||||
---@param scope integer @ 考察时机(默认为回合)
|
||||
---@param card Card @ 卡牌
|
||||
---@param to Player @ 目标
|
||||
---@return number @ 最大使用次数
|
||||
function UsableSkill:getMaxUseTime(player, scope, card, to)
|
||||
scope = scope or Player.HistoryTurn
|
||||
local ret = self.max_use_time[scope]
|
||||
|
@ -26,18 +32,31 @@ function UsableSkill:getMaxUseTime(player, scope, card, to)
|
|||
return ret
|
||||
end
|
||||
|
||||
-- 判断一个角色是否在技能的次数限制内
|
||||
---@param player Player @ 使用者
|
||||
---@param scope integer @ 考察时机(默认为回合)
|
||||
---@param card? Card @ 牌,若没有牌,则尝试制造一张虚拟牌
|
||||
---@param card_name? string @ 牌名
|
||||
---@param to any @ 目标
|
||||
---@return bool
|
||||
function UsableSkill:withinTimesLimit(player, scope, card, card_name, to)
|
||||
if to and to.dead then return false end
|
||||
scope = scope or Player.HistoryTurn
|
||||
local status_skills = Fk:currentRoom().status_skills[TargetModSkill] or Util.DummyTable
|
||||
if not card and self.name:endsWith("_skill") then
|
||||
card = Fk:cloneCard(self.name:sub(1, #self.name - 6))
|
||||
if not card then
|
||||
if card_name then
|
||||
card = Fk:cloneCard(card_name)
|
||||
elseif self.name:endsWith("_skill") then
|
||||
card = Fk:cloneCard(self.name:sub(1, #self.name - 6))
|
||||
end
|
||||
end
|
||||
if not card_name and card then
|
||||
card_name = card.trueName
|
||||
end
|
||||
for _, skill in ipairs(status_skills) do
|
||||
if skill:bypassTimesCheck(player, self, scope, card, to) then return true end
|
||||
end
|
||||
|
||||
card_name = card_name or card.trueName
|
||||
local temp_suf = table.simpleClone(MarkEnum.TempMarkSuffix)
|
||||
local card_temp_suf = table.simpleClone(MarkEnum.CardTempMarkSuffix)
|
||||
|
||||
|
|
|
@ -180,11 +180,11 @@ end
|
|||
---@field public card_filter? fun(self: ActiveSkill, to_select: integer, selected: integer[], selected_targets: integer[]): boolean?
|
||||
---@field public target_filter? fun(self: ActiveSkill, to_select: integer, selected: integer[], selected_cards: integer[], card: Card, extra_data: any): boolean?
|
||||
---@field public feasible? fun(self: ActiveSkill, selected: integer[], selected_cards: integer[]): boolean?
|
||||
---@field public on_use? fun(self: ActiveSkill, room: Room, cardUseEvent: CardUseStruct): boolean?
|
||||
---@field public on_action? fun(self: ActiveSkill, room: Room, cardUseEvent: CardUseStruct, finished: boolean): boolean?
|
||||
---@field public about_to_effect? fun(self: ActiveSkill, room: Room, cardEffectEvent: CardEffectEvent): boolean?
|
||||
---@field public on_effect? fun(self: ActiveSkill, room: Room, cardEffectEvent: CardEffectEvent): boolean?
|
||||
---@field public on_nullified? fun(self: ActiveSkill, room: Room, cardEffectEvent: CardEffectEvent): boolean?
|
||||
---@field public on_use? fun(self: ActiveSkill, room: Room, cardUseEvent: CardUseStruct | SkillEffectEvent): boolean?
|
||||
---@field public on_action? fun(self: ActiveSkill, room: Room, cardUseEvent: CardUseStruct | SkillEffectEvent, finished: boolean): boolean?
|
||||
---@field public about_to_effect? fun(self: ActiveSkill, room: Room, cardEffectEvent: CardEffectEvent | SkillEffectEvent): boolean?
|
||||
---@field public on_effect? fun(self: ActiveSkill, room: Room, cardEffectEvent: CardEffectEvent | SkillEffectEvent): boolean?
|
||||
---@field public on_nullified? fun(self: ActiveSkill, room: Room, cardEffectEvent: CardEffectEvent | SkillEffectEvent): boolean?
|
||||
---@field public mod_target_filter? fun(self: ActiveSkill, to_select: integer, selected: integer[], user: integer, card: Card, distance_limited: boolean): boolean?
|
||||
---@field public prompt? string|fun(self: ActiveSkill, selected_cards: integer[], selected_targets: integer[]): string
|
||||
---@field public interaction any
|
||||
|
@ -335,12 +335,14 @@ end
|
|||
---@field public correct_func? fun(self: AttackRangeSkill, from: Player, to: Player): number?
|
||||
---@field public fixed_func? fun(self: AttackRangeSkill, player: Player): number?
|
||||
---@field public within_func? fun(self: AttackRangeSkill, from: Player, to: Player): boolean?
|
||||
---@field public without_func? fun(self: AttackRangeSkill, from: Player, to: Player): boolean?
|
||||
|
||||
---@param spec AttackRangeSpec
|
||||
---@return AttackRangeSkill
|
||||
function fk.CreateAttackRangeSkill(spec)
|
||||
assert(type(spec.name) == "string")
|
||||
assert(type(spec.correct_func) == "function" or type(spec.fixed_func) == "function" or type(spec.within_func) == "function")
|
||||
assert(type(spec.correct_func) == "function" or type(spec.fixed_func) == "function" or
|
||||
type(spec.within_func) == "function" or type(spec.without_func) == "function")
|
||||
|
||||
local skill = AttackRangeSkill:new(spec.name)
|
||||
readStatusSpecToSkill(skill, spec)
|
||||
|
@ -353,6 +355,9 @@ function fk.CreateAttackRangeSkill(spec)
|
|||
if spec.within_func then
|
||||
skill.withinAttackRange = spec.within_func
|
||||
end
|
||||
if spec.without_func then
|
||||
skill.withoutAttackRange = spec.without_func
|
||||
end
|
||||
|
||||
return skill
|
||||
end
|
||||
|
@ -417,6 +422,7 @@ end
|
|||
---@class FilterSpec: StatusSkillSpec
|
||||
---@field public card_filter? fun(self: FilterSkill, card: Card, player: Player, isJudgeEvent: boolean): boolean?
|
||||
---@field public view_as? fun(self: FilterSkill, card: Card, player: Player): Card?
|
||||
---@field public equip_skill_filter? fun(self: FilterSkill, skill: Skill, player: Player): string?
|
||||
|
||||
---@param spec FilterSpec
|
||||
---@return FilterSkill
|
||||
|
@ -427,6 +433,7 @@ function fk.CreateFilterSkill(spec)
|
|||
readStatusSpecToSkill(skill, spec)
|
||||
skill.cardFilter = spec.card_filter
|
||||
skill.viewAs = spec.view_as
|
||||
skill.equipSkillFilter = spec.equip_skill_filter
|
||||
|
||||
return skill
|
||||
end
|
||||
|
@ -526,7 +533,20 @@ function fk.CreateDelayedTrickCard(spec)
|
|||
end
|
||||
|
||||
local function readCardSpecToEquip(card, spec)
|
||||
card.equip_skill = spec.equip_skill
|
||||
if spec.equip_skill then
|
||||
if spec.equip_skill.class and spec.equip_skill:isInstanceOf(Skill) then
|
||||
card.equip_skill = spec.equip_skill
|
||||
card.equip_skills = { spec.equip_skill }
|
||||
else
|
||||
card.equip_skill = spec.equip_skill[1]
|
||||
card.equip_skills = spec.equip_skill
|
||||
end
|
||||
end
|
||||
|
||||
if spec.dynamic_equip_skills then
|
||||
assert(type(spec.dynamic_equip_skills) == "function")
|
||||
card.dynamicEquipSkills = spec.dynamic_equip_skills
|
||||
end
|
||||
|
||||
if spec.on_install then card.onInstall = spec.on_install end
|
||||
if spec.on_uninstall then card.onUninstall = spec.on_uninstall end
|
||||
|
@ -543,6 +563,11 @@ function fk.CreateWeapon(spec)
|
|||
local card = Weapon:new(spec.name, spec.suit, spec.number, spec.attack_range)
|
||||
readCardSpecToCard(card, spec)
|
||||
readCardSpecToEquip(card, spec)
|
||||
if spec.dynamic_attack_range then
|
||||
assert(type(spec.dynamic_attack_range) == "function")
|
||||
card.dynamicAttackRange = spec.dynamic_attack_range
|
||||
end
|
||||
|
||||
return card
|
||||
end
|
||||
|
||||
|
@ -610,6 +635,10 @@ function fk.CreateGameMode(spec)
|
|||
assert(type(spec.is_counted) == "function")
|
||||
ret.countInFunc = spec.is_counted
|
||||
end
|
||||
if spec.get_adjusted then
|
||||
assert(type(spec.get_adjusted) == "function")
|
||||
ret.getAdjustedProperty = spec.get_adjusted
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
-- 向Lua虚拟机中加载库、游戏中的类,以及加载Mod等等。
|
||||
|
||||
-- 加载第三方库
|
||||
package.path = package.path .. ";./lua/lib/?.lua"
|
||||
.. ";./lua/?.lua"
|
||||
package.path = "./?.lua;./?/init.lua;./lua/lib/?.lua;./lua/?.lua"
|
||||
|
||||
-- middleclass: 轻量级的面向对象库
|
||||
class = require "middleclass"
|
||||
|
@ -62,7 +61,9 @@ UI = require "ui-util"
|
|||
-- 读取配置文件。
|
||||
-- 因为io马上就要被禁用了,所以赶紧先在这里读取配置文件。
|
||||
local function loadConf()
|
||||
local cfg = io.open("freekill.client.config.json")
|
||||
local new_core = FileIO.pwd():endsWith("packages/freekill-core")
|
||||
|
||||
local cfg = io.open((new_core and "../../" or "") .. "freekill.client.config.json")
|
||||
local ret
|
||||
if cfg == nil then
|
||||
ret = {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
-- SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
GameEvent.functions[GameEvent.Dying] = function(self)
|
||||
---@class GameEvent.Dying : GameEvent
|
||||
local Dying = GameEvent:subclass("GameEvent.Dying")
|
||||
function Dying:main()
|
||||
local dyingStruct = table.unpack(self.data)
|
||||
local room = self.room
|
||||
local logic = room.logic
|
||||
|
@ -27,7 +29,7 @@ GameEvent.functions[GameEvent.Dying] = function(self)
|
|||
end
|
||||
end
|
||||
|
||||
GameEvent.exit_funcs[GameEvent.Dying] = function(self)
|
||||
function Dying:exit()
|
||||
local room = self.room
|
||||
local logic = room.logic
|
||||
local dyingStruct = self.data[1]
|
||||
|
@ -41,7 +43,9 @@ GameEvent.exit_funcs[GameEvent.Dying] = function(self)
|
|||
logic:trigger(fk.AfterDying, dyingPlayer, dyingStruct, self.interrupted)
|
||||
end
|
||||
|
||||
GameEvent.prepare_funcs[GameEvent.Death] = function(self)
|
||||
---@class GameEvent.Death : GameEvent
|
||||
local Death = GameEvent:subclass("GameEvent.Death")
|
||||
function Death:prepare()
|
||||
local deathStruct = table.unpack(self.data)
|
||||
local room = self.room
|
||||
local victim = room:getPlayerById(deathStruct.who)
|
||||
|
@ -50,7 +54,7 @@ GameEvent.prepare_funcs[GameEvent.Death] = function(self)
|
|||
end
|
||||
end
|
||||
|
||||
GameEvent.functions[GameEvent.Death] = function(self)
|
||||
function Death:main()
|
||||
local deathStruct = table.unpack(self.data)
|
||||
local room = self.room
|
||||
local victim = room:getPlayerById(deathStruct.who)
|
||||
|
@ -99,7 +103,9 @@ GameEvent.functions[GameEvent.Death] = function(self)
|
|||
logic:trigger(fk.Deathed, victim, deathStruct)
|
||||
end
|
||||
|
||||
GameEvent.functions[GameEvent.Revive] = function(self)
|
||||
---@class GameEvent.Revive : GameEvent
|
||||
local Revive = GameEvent:subclass("GameEvent.Revive")
|
||||
function Revive:main()
|
||||
local room = self.room
|
||||
local player, sendLog, reason = table.unpack(self.data)
|
||||
|
||||
|
@ -118,3 +124,5 @@ GameEvent.functions[GameEvent.Revive] = function(self)
|
|||
reason = reason or ""
|
||||
room.logic:trigger(fk.AfterPlayerRevived, player, { reason = reason })
|
||||
end
|
||||
|
||||
return { Dying, Death, Revive }
|
||||
|
|
|
@ -47,7 +47,9 @@ local function discardInit(room, player)
|
|||
end
|
||||
end
|
||||
|
||||
GameEvent.functions[GameEvent.DrawInitial] = function(self)
|
||||
---@class GameEvent.DrawInitial : GameEvent
|
||||
local DrawInitial = GameEvent:subclass("GameEvent.DrawInitial")
|
||||
function DrawInitial:main()
|
||||
local room = self.room
|
||||
|
||||
local luck_data = {
|
||||
|
@ -81,6 +83,7 @@ GameEvent.functions[GameEvent.DrawInitial] = function(self)
|
|||
room:setTag("LuckCardData", luck_data)
|
||||
room:notifyMoveFocus(room.alive_players, "AskForLuckCard")
|
||||
room:doBroadcastNotify("AskForLuckCard", room.settings.luckTime or 4)
|
||||
room.room:setRequestTimer(room.timeout * 1000 + 1000)
|
||||
|
||||
local remainTime = room.timeout + 1
|
||||
local currentTime = os.time()
|
||||
|
@ -123,6 +126,8 @@ GameEvent.functions[GameEvent.DrawInitial] = function(self)
|
|||
coroutine.yield("__handleRequest", (remainTime - elapsed) * 1000)
|
||||
end
|
||||
|
||||
room.room:destroyRequestTimer()
|
||||
|
||||
for _, player in ipairs(room.alive_players) do
|
||||
local draw_data = luck_data[player.id]
|
||||
draw_data.luckTime = nil
|
||||
|
@ -132,10 +137,23 @@ GameEvent.functions[GameEvent.DrawInitial] = function(self)
|
|||
room:removeTag("LuckCardData")
|
||||
end
|
||||
|
||||
GameEvent.functions[GameEvent.Round] = function(self)
|
||||
---@class GameEvent.Round : GameEvent
|
||||
local Round = GameEvent:subclass("GameEvent.Round")
|
||||
|
||||
function Round:action()
|
||||
local room = self.room
|
||||
local p
|
||||
repeat
|
||||
p = room.current
|
||||
GameEvent.Turn:create(p):exec()
|
||||
if room.game_finished then break end
|
||||
room.current = room.current:getNextAlive(true, nil, true)
|
||||
until p.seat >= p:getNextAlive(true, nil, true).seat
|
||||
end
|
||||
|
||||
function Round:main()
|
||||
local room = self.room
|
||||
local logic = room.logic
|
||||
local p
|
||||
|
||||
local isFirstRound = room:getTag("FirstRound")
|
||||
if isFirstRound then
|
||||
|
@ -160,18 +178,11 @@ GameEvent.functions[GameEvent.Round] = function(self)
|
|||
end
|
||||
|
||||
logic:trigger(fk.RoundStart, room.current)
|
||||
|
||||
repeat
|
||||
p = room.current
|
||||
GameEvent(GameEvent.Turn, p):exec()
|
||||
if room.game_finished then break end
|
||||
room.current = room.current:getNextAlive(true, nil, true)
|
||||
until p.seat >= p:getNextAlive(true, nil, true).seat
|
||||
|
||||
self:action()
|
||||
logic:trigger(fk.RoundEnd, p)
|
||||
end
|
||||
|
||||
GameEvent.cleaners[GameEvent.Round] = function(self)
|
||||
function Round:clear()
|
||||
local room = self.room
|
||||
|
||||
for _, p in ipairs(room.players) do
|
||||
|
@ -198,7 +209,9 @@ GameEvent.cleaners[GameEvent.Round] = function(self)
|
|||
end
|
||||
end
|
||||
|
||||
GameEvent.prepare_funcs[GameEvent.Turn] = function(self)
|
||||
---@class GameEvent.Turn : GameEvent
|
||||
local Turn = GameEvent:subclass("GameEvent.Turn")
|
||||
function Turn:prepare()
|
||||
local room = self.room
|
||||
local logic = room.logic
|
||||
local player = room.current
|
||||
|
@ -224,7 +237,7 @@ GameEvent.prepare_funcs[GameEvent.Turn] = function(self)
|
|||
return logic:trigger(fk.BeforeTurnStart, player)
|
||||
end
|
||||
|
||||
GameEvent.functions[GameEvent.Turn] = function(self)
|
||||
function Turn:main()
|
||||
local room = self.room
|
||||
room.current.phase = Player.PhaseNone
|
||||
room.logic:trigger(fk.TurnStart, room.current)
|
||||
|
@ -232,7 +245,7 @@ GameEvent.functions[GameEvent.Turn] = function(self)
|
|||
room.current:play()
|
||||
end
|
||||
|
||||
GameEvent.cleaners[GameEvent.Turn] = function(self)
|
||||
function Turn:clear()
|
||||
local room = self.room
|
||||
|
||||
local current = room.current
|
||||
|
@ -280,7 +293,9 @@ GameEvent.cleaners[GameEvent.Turn] = function(self)
|
|||
end
|
||||
end
|
||||
|
||||
GameEvent.functions[GameEvent.Phase] = function(self)
|
||||
---@class GameEvent.Phase : GameEvent
|
||||
local Phase = GameEvent:subclass("GameEvent.Phase")
|
||||
function Phase:main()
|
||||
local room = self.room
|
||||
local logic = room.logic
|
||||
|
||||
|
@ -373,7 +388,7 @@ GameEvent.functions[GameEvent.Phase] = function(self)
|
|||
end
|
||||
end
|
||||
|
||||
GameEvent.cleaners[GameEvent.Phase] = function(self)
|
||||
function Phase:clear()
|
||||
local room = self.room
|
||||
local player = self.data[1]
|
||||
local logic = room.logic
|
||||
|
@ -408,3 +423,5 @@ GameEvent.cleaners[GameEvent.Phase] = function(self)
|
|||
room:broadcastProperty(p, "MaxCards")
|
||||
end
|
||||
end
|
||||
|
||||
return { DrawInitial, Round, Turn, Phase }
|
||||
|
|
|
@ -31,7 +31,9 @@ local function sendDamageLog(room, damageStruct)
|
|||
})
|
||||
end
|
||||
|
||||
GameEvent.functions[GameEvent.ChangeHp] = function(self)
|
||||
---@class GameEvent.ChangeHp : GameEvent
|
||||
local ChangeHp = GameEvent:subclass("GameEvent.ChangeHp")
|
||||
function ChangeHp:main()
|
||||
local player, num, reason, skillName, damageStruct = table.unpack(self.data)
|
||||
local room = self.room
|
||||
local logic = room.logic
|
||||
|
@ -112,17 +114,21 @@ GameEvent.functions[GameEvent.ChangeHp] = function(self)
|
|||
return true
|
||||
end
|
||||
|
||||
GameEvent.functions[GameEvent.Damage] = function(self)
|
||||
---@class GameEvent.Damage : GameEvent
|
||||
local Damage = GameEvent:subclass("GameEvent.Damage")
|
||||
function Damage:main()
|
||||
local damageStruct = table.unpack(self.data)
|
||||
local room = self.room
|
||||
local logic = room.logic
|
||||
|
||||
if not damageStruct.chain and logic:damageByCardEffect(not not damageStruct.from) then
|
||||
if not damageStruct.chain and logic:damageByCardEffect(false) then
|
||||
local cardEffectData = logic:getCurrentEvent():findParent(GameEvent.CardEffect)
|
||||
if cardEffectData then
|
||||
local cardEffectEvent = cardEffectData.data[1]
|
||||
damageStruct.damage = damageStruct.damage + (cardEffectEvent.additionalDamage or 0)
|
||||
damageStruct.by_user = true
|
||||
if damageStruct.from and cardEffectEvent.from == damageStruct.from.id then
|
||||
damageStruct.by_user = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -137,12 +143,14 @@ GameEvent.functions[GameEvent.Damage] = function(self)
|
|||
|
||||
assert(damageStruct.to:isInstanceOf(ServerPlayer))
|
||||
|
||||
local stages = {
|
||||
{fk.PreDamage, "from"},
|
||||
}
|
||||
local stages = {}
|
||||
|
||||
if not damageStruct.isVirtualDMG then
|
||||
table.insertTable(stages, { { fk.DamageCaused, "from" }, { fk.DamageInflicted, "to" } })
|
||||
stages = {
|
||||
{ fk.PreDamage, "from"},
|
||||
{ fk.DamageCaused, "from" },
|
||||
{ fk.DamageInflicted, "to" },
|
||||
}
|
||||
end
|
||||
|
||||
for _, struct in ipairs(stages) do
|
||||
|
@ -198,7 +206,7 @@ GameEvent.functions[GameEvent.Damage] = function(self)
|
|||
return true
|
||||
end
|
||||
|
||||
GameEvent.exit_funcs[GameEvent.Damage] = function(self)
|
||||
function Damage:exit()
|
||||
local room = self.room
|
||||
local logic = room.logic
|
||||
local damageStruct = self.data[1]
|
||||
|
@ -230,7 +238,9 @@ GameEvent.exit_funcs[GameEvent.Damage] = function(self)
|
|||
end
|
||||
end
|
||||
|
||||
GameEvent.functions[GameEvent.LoseHp] = function(self)
|
||||
---@class GameEvent.LoseHp : GameEvent
|
||||
local LoseHp = GameEvent:subclass("GameEvent.LoseHp")
|
||||
function LoseHp:main()
|
||||
local player, num, skillName = table.unpack(self.data)
|
||||
local room = self.room
|
||||
local logic = room.logic
|
||||
|
@ -258,7 +268,9 @@ GameEvent.functions[GameEvent.LoseHp] = function(self)
|
|||
return true
|
||||
end
|
||||
|
||||
GameEvent.functions[GameEvent.Recover] = function(self)
|
||||
---@class GameEvent.Recover : GameEvent
|
||||
local Recover = GameEvent:subclass("GameEvent.Recover")
|
||||
function Recover:main()
|
||||
local recoverStruct = table.unpack(self.data)
|
||||
local room = self.room
|
||||
local logic = room.logic
|
||||
|
@ -289,7 +301,9 @@ GameEvent.functions[GameEvent.Recover] = function(self)
|
|||
return true
|
||||
end
|
||||
|
||||
GameEvent.functions[GameEvent.ChangeMaxHp] = function(self)
|
||||
---@class GameEvent.ChangeMaxHp : GameEvent
|
||||
local ChangeMaxHp = GameEvent:subclass("GameEvent.ChangeMaxHp")
|
||||
function ChangeMaxHp:main()
|
||||
local player, num = table.unpack(self.data)
|
||||
local room = self.room
|
||||
|
||||
|
@ -344,3 +358,5 @@ GameEvent.functions[GameEvent.ChangeMaxHp] = function(self)
|
|||
room.logic:trigger(fk.MaxHpChanged, player, { num = num })
|
||||
return true
|
||||
end
|
||||
|
||||
return { ChangeHp, Damage, LoseHp, Recover, ChangeMaxHp }
|
||||
|
|
|
@ -5,51 +5,46 @@
|
|||
-- 某类事件对应的结束事件,其id刚好就是那个事件的相反数
|
||||
-- GameEvent.EventFinish = -1
|
||||
|
||||
GameEvent.Game = 0
|
||||
local tmp
|
||||
tmp = require "server.events.misc"
|
||||
GameEvent.Game = tmp[1]
|
||||
GameEvent.ChangeProperty = tmp[2]
|
||||
GameEvent.ClearEvent = tmp[3]
|
||||
|
||||
GameEvent.ChangeHp = 1
|
||||
GameEvent.Damage = 2
|
||||
GameEvent.LoseHp = 3
|
||||
GameEvent.Recover = 4
|
||||
GameEvent.ChangeMaxHp = 5
|
||||
dofile "lua/server/events/hp.lua"
|
||||
tmp = require "server.events.hp"
|
||||
GameEvent.ChangeHp = tmp[1]
|
||||
GameEvent.Damage = tmp[2]
|
||||
GameEvent.LoseHp = tmp[3]
|
||||
GameEvent.Recover = tmp[4]
|
||||
GameEvent.ChangeMaxHp = tmp[5]
|
||||
|
||||
GameEvent.Dying = 6
|
||||
GameEvent.Death = 7
|
||||
GameEvent.Revive = 22
|
||||
dofile "lua/server/events/death.lua"
|
||||
tmp = require "server.events.death"
|
||||
GameEvent.Dying = tmp[1]
|
||||
GameEvent.Death = tmp[2]
|
||||
GameEvent.Revive = tmp[3]
|
||||
|
||||
GameEvent.MoveCards = 8
|
||||
dofile "lua/server/events/movecard.lua"
|
||||
tmp = require "server.events.movecard"
|
||||
GameEvent.MoveCards = tmp
|
||||
|
||||
GameEvent.UseCard = 9
|
||||
GameEvent.RespondCard = 10
|
||||
GameEvent.CardEffect = 20
|
||||
dofile "lua/server/events/usecard.lua"
|
||||
tmp = require "server.events.usecard"
|
||||
GameEvent.UseCard = tmp[1]
|
||||
GameEvent.RespondCard = tmp[2]
|
||||
GameEvent.CardEffect = tmp[3]
|
||||
|
||||
GameEvent.SkillEffect = 11
|
||||
-- GameEvent.AddSkill = 12
|
||||
-- GameEvent.LoseSkill = 13
|
||||
dofile "lua/server/events/skill.lua"
|
||||
tmp = require "server.events.skill"
|
||||
GameEvent.SkillEffect = tmp
|
||||
|
||||
GameEvent.Judge = 14
|
||||
dofile "lua/server/events/judge.lua"
|
||||
tmp = require "server.events.judge"
|
||||
GameEvent.Judge = tmp
|
||||
|
||||
GameEvent.DrawInitial = 15
|
||||
GameEvent.Round = 16
|
||||
GameEvent.Turn = 17
|
||||
GameEvent.Phase = 18
|
||||
dofile "lua/server/events/gameflow.lua"
|
||||
tmp = require "server.events.gameflow"
|
||||
GameEvent.DrawInitial = tmp[1]
|
||||
GameEvent.Round = tmp[2]
|
||||
GameEvent.Turn = tmp[3]
|
||||
GameEvent.Phase = tmp[4]
|
||||
|
||||
GameEvent.Pindian = 19
|
||||
dofile "lua/server/events/pindian.lua"
|
||||
|
||||
-- 20 = CardEffect
|
||||
GameEvent.ChangeProperty = 21
|
||||
|
||||
-- 新的clear函数专用
|
||||
GameEvent.ClearEvent = 9999
|
||||
dofile "lua/server/events/misc.lua"
|
||||
tmp = require "server.events.pindian"
|
||||
GameEvent.Pindian = tmp
|
||||
|
||||
for _, l in ipairs(Fk._custom_events) do
|
||||
local name, p, m, c, e = l.name, l.p, l.m, l.c, l.e
|
||||
|
@ -58,37 +53,3 @@ for _, l in ipairs(Fk._custom_events) do
|
|||
GameEvent.cleaners[name] = c
|
||||
GameEvent.exit_funcs[name] = e
|
||||
end
|
||||
|
||||
local eventTranslations = {
|
||||
[GameEvent.Game] = "GameEvent.Game",
|
||||
|
||||
[GameEvent.ChangeHp] = "GameEvent.ChangeHp",
|
||||
[GameEvent.Damage] = "GameEvent.Damage",
|
||||
[GameEvent.LoseHp] = "GameEvent.LoseHp",
|
||||
[GameEvent.Recover] = "GameEvent.Recover",
|
||||
[GameEvent.ChangeMaxHp] = "GameEvent.ChangeMaxHp",
|
||||
[GameEvent.Dying] = "GameEvent.Dying",
|
||||
[GameEvent.Death] = "GameEvent.Death",
|
||||
[GameEvent.Revive] = "GameEvent.Revive",
|
||||
[GameEvent.MoveCards] = "GameEvent.MoveCards",
|
||||
[GameEvent.UseCard] = "GameEvent.UseCard",
|
||||
[GameEvent.RespondCard] = "GameEvent.RespondCard",
|
||||
[GameEvent.CardEffect] = "GameEvent.CardEffect",
|
||||
[GameEvent.SkillEffect] = "GameEvent.SkillEffect",
|
||||
[GameEvent.Judge] = "GameEvent.Judge",
|
||||
[GameEvent.DrawInitial] = "GameEvent.DrawInitial",
|
||||
[GameEvent.Round] = "GameEvent.Round",
|
||||
[GameEvent.Turn] = "GameEvent.Turn",
|
||||
[GameEvent.Phase] = "GameEvent.Phase",
|
||||
[GameEvent.Pindian] = "GameEvent.Pindian",
|
||||
|
||||
[GameEvent.ChangeProperty] = "GameEvent.ChangeProperty",
|
||||
|
||||
[GameEvent.ClearEvent] = "GameEvent.ClearEvent",
|
||||
}
|
||||
|
||||
function GameEvent.static:translate(id)
|
||||
local ret = eventTranslations[id]
|
||||
if not ret then ret = id end
|
||||
return ret
|
||||
end
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
-- SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
GameEvent.functions[GameEvent.Judge] = function(self)
|
||||
---@class GameEvent.Judge : GameEvent
|
||||
local Judge = GameEvent:subclass("GameEvent.Judge")
|
||||
function Judge:main()
|
||||
local data = table.unpack(self.data)
|
||||
local room = self.room
|
||||
local logic = room.logic
|
||||
|
@ -53,7 +55,7 @@ GameEvent.functions[GameEvent.Judge] = function(self)
|
|||
end
|
||||
end
|
||||
|
||||
GameEvent.cleaners[GameEvent.Judge] = function(self)
|
||||
function Judge:clear()
|
||||
local data = table.unpack(self.data)
|
||||
local room = self.room
|
||||
if (self.interrupted or not data.skipDrop) and room:getCardArea(data.card.id) == Card.Processing then
|
||||
|
@ -71,3 +73,5 @@ GameEvent.cleaners[GameEvent.Judge] = function(self)
|
|||
end
|
||||
})
|
||||
end
|
||||
|
||||
return Judge
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
-- SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
GameEvent.functions[GameEvent.Game] = function(self)
|
||||
---@class GameEvent.Game : GameEvent
|
||||
local Game = GameEvent:subclass("GameEvent.Game")
|
||||
function Game:main()
|
||||
self.room.logic:run()
|
||||
end
|
||||
|
||||
GameEvent.functions[GameEvent.ChangeProperty] = function(self)
|
||||
---@class GameEvent.ChangeProperty : GameEvent
|
||||
local ChangeProperty = GameEvent:subclass("GameEvent.Game")
|
||||
function ChangeProperty:main()
|
||||
local data = table.unpack(self.data)
|
||||
local room = self.room
|
||||
local player = data.from
|
||||
|
@ -125,12 +129,14 @@ GameEvent.functions[GameEvent.ChangeProperty] = function(self)
|
|||
logic:trigger(fk.AfterPropertyChange, player, data)
|
||||
end
|
||||
|
||||
GameEvent.functions[GameEvent.ClearEvent] = function(self)
|
||||
---@class GameEvent.ClearEvent : GameEvent
|
||||
local ClearEvent = GameEvent:subclass("GameEvent.ClearEvent")
|
||||
function ClearEvent:main()
|
||||
local event = self.data[1]
|
||||
local logic = self.room.logic
|
||||
-- 不可中断
|
||||
Pcall(event.clear_func, event)
|
||||
for _, f in ipairs(event.extra_clear_funcs) do
|
||||
Pcall(event.clear, event)
|
||||
for _, f in ipairs(event.extra_clear) do
|
||||
if type(f) == "function" then Pcall(f, event) end
|
||||
end
|
||||
|
||||
|
@ -147,3 +153,5 @@ GameEvent.functions[GameEvent.ClearEvent] = function(self)
|
|||
logic.game_event_stack:pop()
|
||||
logic.cleaner_stack:pop()
|
||||
end
|
||||
|
||||
return { Game, ChangeProperty, ClearEvent }
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
-- SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
GameEvent.functions[GameEvent.MoveCards] = function(self)
|
||||
---@class GameEvent.MoveCards : GameEvent
|
||||
local MoveCards = GameEvent:subclass("GameEvent.MoveCards")
|
||||
function MoveCards:main()
|
||||
local args = self.data
|
||||
local room = self.room
|
||||
---@type CardsMoveStruct[]
|
||||
|
@ -57,6 +59,7 @@ GameEvent.functions[GameEvent.MoveCards] = function(self)
|
|||
specialVisible = cardsMoveInfo.specialVisible,
|
||||
drawPilePosition = cardsMoveInfo.drawPilePosition,
|
||||
moveMark = cardsMoveInfo.moveMark,
|
||||
visiblePlayers = cardsMoveInfo.visiblePlayers,
|
||||
}
|
||||
|
||||
table.insert(cardsMoveStructs, cardsMoveStruct)
|
||||
|
@ -69,10 +72,11 @@ GameEvent.functions[GameEvent.MoveCards] = function(self)
|
|||
from = cardsMoveInfo.from,
|
||||
toArea = Card.DiscardPile,
|
||||
moveReason = fk.ReasonPutIntoDiscardPile,
|
||||
specialName = cardsMoveInfo.specialName,
|
||||
specialVisible = cardsMoveInfo.specialVisible,
|
||||
drawPilePosition = cardsMoveInfo.drawPilePosition,
|
||||
moveMark = cardsMoveInfo.moveMark,
|
||||
moveVisible = true,
|
||||
--specialName = cardsMoveInfo.specialName,
|
||||
--specialVisible = cardsMoveInfo.specialVisible,
|
||||
--drawPilePosition = cardsMoveInfo.drawPilePosition,
|
||||
--moveMark = cardsMoveInfo.moveMark,
|
||||
}
|
||||
|
||||
table.insert(cardsMoveStructs, cardsMoveStruct)
|
||||
|
@ -159,7 +163,7 @@ GameEvent.functions[GameEvent.MoveCards] = function(self)
|
|||
realFromArea == Player.Equip and
|
||||
beforeCard.type == Card.TypeEquip and
|
||||
data.from ~= nil and
|
||||
beforeCard.equip_skill
|
||||
#beforeCard:getEquipSkills(room:getPlayerById(data.from)) > 0
|
||||
then
|
||||
beforeCard:onUninstall(room, room:getPlayerById(data.from))
|
||||
end
|
||||
|
@ -183,15 +187,20 @@ GameEvent.functions[GameEvent.MoveCards] = function(self)
|
|||
end
|
||||
end
|
||||
if data.moveMark then
|
||||
local mark = table.clone(data.moveMark) or {"", 0}
|
||||
room:setCardMark(currentCard, mark[1], mark[2])
|
||||
local mark = data.moveMark
|
||||
if type(mark) == "string" then
|
||||
room:setCardMark(currentCard, mark, 1)
|
||||
elseif type(mark) == "table" then
|
||||
mark = table.clone(data.moveMark) or {"", 0}
|
||||
room:setCardMark(currentCard, mark[1], mark[2])
|
||||
end
|
||||
end
|
||||
if
|
||||
data.toArea == Player.Equip and
|
||||
currentCard.type == Card.TypeEquip and
|
||||
data.to ~= nil and
|
||||
room:getPlayerById(data.to):isAlive() and
|
||||
currentCard.equip_skill
|
||||
#currentCard:getEquipSkills(room:getPlayerById(data.to)) > 0
|
||||
then
|
||||
currentCard:onInstall(room, room:getPlayerById(data.to))
|
||||
end
|
||||
|
@ -202,3 +211,5 @@ GameEvent.functions[GameEvent.MoveCards] = function(self)
|
|||
room.logic:trigger(fk.AfterCardsMove, nil, cardsMoveStructs)
|
||||
return true
|
||||
end
|
||||
|
||||
return MoveCards
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
-- SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
GameEvent.functions[GameEvent.Pindian] = function(self)
|
||||
---@class GameEvent.Pindian : GameEvent
|
||||
local Pindian = GameEvent:subclass("GameEvent.Pindian")
|
||||
function Pindian:main()
|
||||
local pindianData = table.unpack(self.data)
|
||||
local room = self.room
|
||||
local logic = room.logic
|
||||
|
@ -35,6 +37,7 @@ GameEvent.functions[GameEvent.Pindian] = function(self)
|
|||
pindianCard:addSubcard(_pindianCard.id)
|
||||
|
||||
pindianData.fromCard = pindianCard
|
||||
pindianData._fromCard = _pindianCard
|
||||
|
||||
table.insert(moveInfos, {
|
||||
ids = { _pindianCard.id },
|
||||
|
@ -53,6 +56,7 @@ GameEvent.functions[GameEvent.Pindian] = function(self)
|
|||
pindianCard:addSubcard(_pindianCard.id)
|
||||
|
||||
pindianData.results[to.id].toCard = pindianCard
|
||||
pindianData.results[to.id]._toCard = _pindianCard
|
||||
|
||||
table.insert(moveInfos, {
|
||||
ids = { _pindianCard.id },
|
||||
|
@ -86,9 +90,11 @@ GameEvent.functions[GameEvent.Pindian] = function(self)
|
|||
|
||||
if p == pindianData.from then
|
||||
pindianData.fromCard = pindianCard
|
||||
pindianData._fromCard = _pindianCard
|
||||
else
|
||||
pindianData.results[p.id] = pindianData.results[p.id] or {}
|
||||
pindianData.results[p.id].toCard = pindianCard
|
||||
pindianData.results[p.id]._toCard = _pindianCard
|
||||
end
|
||||
|
||||
table.insert(moveInfos, {
|
||||
|
@ -109,10 +115,21 @@ GameEvent.functions[GameEvent.Pindian] = function(self)
|
|||
|
||||
room:moveCards(table.unpack(moveInfos))
|
||||
|
||||
room:sendFootnote({ pindianData._fromCard.id }, {
|
||||
type = "##PindianCard",
|
||||
from = pindianData.from.id,
|
||||
})
|
||||
for _, to in ipairs(pindianData.tos) do
|
||||
room:sendFootnote({ pindianData.results[to.id]._toCard.id }, {
|
||||
type = "##PindianCard",
|
||||
from = to.id,
|
||||
})
|
||||
end
|
||||
|
||||
logic:trigger(fk.PindianCardsDisplayed, nil, pindianData)
|
||||
|
||||
for toId, result in pairs(pindianData.results) do
|
||||
local to = room:getPlayerById(toId)
|
||||
for _, to in ipairs(pindianData.tos) do
|
||||
local result = pindianData.results[to.id]
|
||||
if pindianData.fromCard.number > result.toCard.number then
|
||||
result.winner = pindianData.from
|
||||
elseif pindianData.fromCard.number < result.toCard.number then
|
||||
|
@ -131,9 +148,13 @@ GameEvent.functions[GameEvent.Pindian] = function(self)
|
|||
room:sendLog{
|
||||
type = "#ShowPindianResult",
|
||||
from = pindianData.from.id,
|
||||
to = { toId },
|
||||
to = { to.id },
|
||||
arg = result.winner == pindianData.from and "pindianwin" or "pindiannotwin"
|
||||
}
|
||||
|
||||
-- room:setCardEmotion(pindianData._fromCard.id, result.winner == pindianData.from and "pindianwin" or "pindiannotwin")
|
||||
-- room:setCardEmotion(pindianData.results[to.id]._toCard.id, result.winner == to and "pindianwin" or "pindiannotwin")
|
||||
|
||||
logic:trigger(fk.PindianResultConfirmed, nil, singlePindianData)
|
||||
end
|
||||
|
||||
|
@ -142,7 +163,7 @@ GameEvent.functions[GameEvent.Pindian] = function(self)
|
|||
end
|
||||
end
|
||||
|
||||
GameEvent.cleaners[GameEvent.Pindian] = function(self)
|
||||
function Pindian:clear()
|
||||
local pindianData = table.unpack(self.data)
|
||||
local room = self.room
|
||||
|
||||
|
@ -168,3 +189,5 @@ GameEvent.cleaners[GameEvent.Pindian] = function(self)
|
|||
end
|
||||
if not self.interrupted then return end
|
||||
end
|
||||
|
||||
return Pindian
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
-- SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
GameEvent.functions[GameEvent.SkillEffect] = function(self)
|
||||
---@class GameEvent.SkillEffect : GameEvent
|
||||
local SkillEffect = GameEvent:subclass("GameEvent.SkillEffect")
|
||||
function SkillEffect:main()
|
||||
local effect_cb, player, _skill = table.unpack(self.data)
|
||||
local room = self.room
|
||||
local logic = room.logic
|
||||
|
@ -19,3 +21,5 @@ GameEvent.functions[GameEvent.SkillEffect] = function(self)
|
|||
logic:trigger(fk.AfterSkillEffect, player, skill)
|
||||
return ret
|
||||
end
|
||||
|
||||
return SkillEffect
|
||||
|
|
|
@ -162,7 +162,9 @@ local sendCardEmotionAndLog = function(room, cardUseEvent)
|
|||
return _card
|
||||
end
|
||||
|
||||
GameEvent.functions[GameEvent.UseCard] = function(self)
|
||||
---@class GameEvent.UseCard : GameEvent
|
||||
local UseCard = GameEvent:subclass("GameEvent.UseCard")
|
||||
function UseCard:main()
|
||||
local cardUseEvent = table.unpack(self.data)
|
||||
local room = self.room
|
||||
local logic = room.logic
|
||||
|
@ -185,6 +187,27 @@ GameEvent.functions[GameEvent.UseCard] = function(self)
|
|||
cardUseEvent.card.skill:onUse(room, cardUseEvent)
|
||||
end
|
||||
|
||||
if cardUseEvent.card.type == Card.TypeEquip then
|
||||
local targets = TargetGroup:getRealTargets(cardUseEvent.tos)
|
||||
if #targets == 1 then
|
||||
local target = room:getPlayerById(targets[1])
|
||||
local subType = cardUseEvent.card.sub_type
|
||||
local equipsExist = target:getEquipments(subType)
|
||||
|
||||
if #equipsExist > 0 and not target:hasEmptyEquipSlot(subType) then
|
||||
local choices = table.map(
|
||||
equipsExist,
|
||||
function(id, index)
|
||||
return "#EquipmentChoice:" .. index .. "::" .. Fk:translate(Fk:getCardById(id).name) end
|
||||
)
|
||||
if target:hasEmptyEquipSlot(subType) then
|
||||
table.insert(choices, target:getAvailableEquipSlots(subType)[1])
|
||||
end
|
||||
cardUseEvent.toPutSlot = room:askForChoice(target, choices, "replace_equip", "#GameRuleReplaceEquipment")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if logic:trigger(fk.PreCardUse, room:getPlayerById(cardUseEvent.from), cardUseEvent) then
|
||||
logic:breakEvent()
|
||||
end
|
||||
|
@ -238,7 +261,7 @@ GameEvent.functions[GameEvent.UseCard] = function(self)
|
|||
end
|
||||
end
|
||||
|
||||
GameEvent.cleaners[GameEvent.UseCard] = function(self)
|
||||
function UseCard:clear()
|
||||
local cardUseEvent = table.unpack(self.data)
|
||||
local room = self.room
|
||||
|
||||
|
@ -254,7 +277,9 @@ GameEvent.cleaners[GameEvent.UseCard] = function(self)
|
|||
end
|
||||
end
|
||||
|
||||
GameEvent.functions[GameEvent.RespondCard] = function(self)
|
||||
---@class GameEvent.RespondCard : GameEvent
|
||||
local RespondCard = GameEvent:subclass("GameEvent.RespondCard")
|
||||
function RespondCard:main()
|
||||
local cardResponseEvent = table.unpack(self.data)
|
||||
local room = self.room
|
||||
local logic = room.logic
|
||||
|
@ -306,7 +331,7 @@ GameEvent.functions[GameEvent.RespondCard] = function(self)
|
|||
logic:trigger(fk.CardResponding, room:getPlayerById(cardResponseEvent.from), cardResponseEvent)
|
||||
end
|
||||
|
||||
GameEvent.cleaners[GameEvent.RespondCard] = function(self)
|
||||
function RespondCard:clear()
|
||||
local cardResponseEvent = table.unpack(self.data)
|
||||
local room = self.room
|
||||
|
||||
|
@ -322,7 +347,9 @@ GameEvent.cleaners[GameEvent.RespondCard] = function(self)
|
|||
end
|
||||
end
|
||||
|
||||
GameEvent.functions[GameEvent.CardEffect] = function(self)
|
||||
---@class GameEvent.CardEffect : GameEvent
|
||||
local CardEffect = GameEvent:subclass("GameEvent.CardEffect")
|
||||
function CardEffect:main()
|
||||
local cardEffectEvent = table.unpack(self.data)
|
||||
local room = self.room
|
||||
local logic = room.logic
|
||||
|
@ -359,13 +386,16 @@ GameEvent.functions[GameEvent.CardEffect] = function(self)
|
|||
end
|
||||
logic:breakEvent()
|
||||
end
|
||||
elseif cardEffectEvent.to and logic:trigger(event, room:getPlayerById(cardEffectEvent.to), cardEffectEvent) then
|
||||
cardEffectEvent.nullifiedTargets = cardEffectEvent.nullifiedTargets or {}
|
||||
table.insert(cardEffectEvent.nullifiedTargets, cardEffectEvent.to)
|
||||
|
||||
elseif logic:trigger(event, room:getPlayerById(cardEffectEvent.to), cardEffectEvent) then
|
||||
if cardEffectEvent.to then
|
||||
cardEffectEvent.nullifiedTargets = cardEffectEvent.nullifiedTargets or {}
|
||||
table.insert(cardEffectEvent.nullifiedTargets, cardEffectEvent.to)
|
||||
end
|
||||
logic:breakEvent()
|
||||
end
|
||||
|
||||
room:handleCardEffect(event, cardEffectEvent)
|
||||
end
|
||||
end
|
||||
|
||||
return { UseCard, RespondCard, CardEffect }
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
---@field public id integer @ 事件的id,随着时间推移自动增加并分配给新事件
|
||||
---@field public end_id integer @ 事件的对应结束id,如果整个事件中未插入事件,那么end_id就是自己的id
|
||||
---@field public room Room @ room实例
|
||||
---@field public event integer @ 该事件对应的EventType
|
||||
---@field public event GameEvent @ 该事件对应的EventType,现已改为对应的class
|
||||
---@field public data any @ 事件的附加数据,视类型而定
|
||||
---@field public parent GameEvent @ 事件的父事件(栈中的上一层事件)
|
||||
---@field public prepare_func fun(self: GameEvent) @ 事件即将开始时执行的函数
|
||||
---@field public main_func fun(self: GameEvent) @ 事件的主函数
|
||||
---@field public clear_func fun(self: GameEvent) @ 事件结束时执行的函数
|
||||
---@field public extra_clear_funcs fun(self:GameEvent)[] @ 事件结束时执行的自定义函数列表
|
||||
---@field public exit_func fun(self: GameEvent) @ 事件结束后执行的函数
|
||||
---@field public extra_exit_funcs fun(self:GameEvent)[] @ 事件结束后执行的自定义函数
|
||||
---@field public extra_clear fun(self:GameEvent)[] @ 事件结束时执行的自定义函数列表
|
||||
---@field public extra_exit fun(self:GameEvent)[] @ 事件结束后执行的自定义函数
|
||||
---@field public exec_ret boolean? @ exec函数的返回值,可能不存在
|
||||
---@field public status string @ ready, running, exiting, dead
|
||||
---@field public interrupted boolean @ 事件是否是因为被中断而结束的,可能是防止事件或者被杀
|
||||
|
@ -31,61 +27,96 @@ GameEvent.cleaners = {}
|
|||
---@type (fun(self: GameEvent): bool)[]
|
||||
GameEvent.exit_funcs = {}
|
||||
|
||||
local function wrapCoFunc(f, ...)
|
||||
if not f then return nil end
|
||||
local args = {...}
|
||||
return function() return f(table.unpack(args)) end
|
||||
end
|
||||
local dummyFunc = Util.DummyFunc
|
||||
|
||||
function GameEvent:initialize(event, ...)
|
||||
self.id = -1
|
||||
self.end_id = -1
|
||||
self.room = RoomInstance
|
||||
-- for compat
|
||||
self.event = event
|
||||
---@diagnostic disable-next-line
|
||||
-- self.event = self.class
|
||||
self.data = { ... }
|
||||
self.prepare_func = GameEvent.prepare_funcs[event] or dummyFunc
|
||||
self.main_func = wrapCoFunc(GameEvent.functions[event], self) or dummyFunc
|
||||
self.clear_func = GameEvent.cleaners[event] or dummyFunc
|
||||
self.extra_clear_funcs = Util.DummyTable
|
||||
self.exit_func = GameEvent.exit_funcs[event] or dummyFunc
|
||||
self.extra_exit_funcs = Util.DummyTable
|
||||
self.status = "ready"
|
||||
self.interrupted = false
|
||||
|
||||
self.extra_clear = Util.DummyTable
|
||||
self.extra_exit = Util.DummyTable
|
||||
end
|
||||
|
||||
-- 静态函数,实际定义在events/init.lua
|
||||
function GameEvent:translate(id)
|
||||
error('static')
|
||||
---@generic T
|
||||
---@param self T
|
||||
---@return T
|
||||
function GameEvent.create(self, ...)
|
||||
if self.class then error('cannot use "create()" by event instances') end
|
||||
return self:new(self, ...)
|
||||
end
|
||||
|
||||
-- 获取最接近GameEvent的基类
|
||||
---@return GameEvent
|
||||
function GameEvent.getBaseClass(self, ...)
|
||||
if self.class then error('cannot use "getBaseClass()" by event instances') end
|
||||
if self.super == GameEvent or self == GameEvent then
|
||||
return self
|
||||
end
|
||||
return self.super:getBaseClass()
|
||||
end
|
||||
|
||||
function GameEvent.static:subclassed(subclass)
|
||||
local mt = getmetatable(subclass)
|
||||
-- 适配老代码event == GameEvent.Turn之类的奇技淫巧,危险性待评估
|
||||
-- 这样若某个模式启用派生类修改逻辑,那么findParent之类的基于父类也能找
|
||||
mt.__eq = function(a, b)
|
||||
if not a.super or not b.super then return false end
|
||||
return rawequal(a, b) or a:isSubclassOf(b) or b:isSubclassOf(a)
|
||||
end
|
||||
end
|
||||
|
||||
function GameEvent:__tostring()
|
||||
return string.format("<%s #%d>", GameEvent:translate(self.event), self.id)
|
||||
return string.format("<%s #%d>",
|
||||
type(self.event == "string") and self.event or self.class.name, self.id)
|
||||
end
|
||||
|
||||
function GameEvent:prepare()
|
||||
return (GameEvent.prepare_funcs[self.event] or dummyFunc)(self)
|
||||
end
|
||||
|
||||
function GameEvent:main()
|
||||
return (GameEvent.functions[self.event] or dummyFunc)(self)
|
||||
end
|
||||
|
||||
function GameEvent:clear()
|
||||
return (GameEvent.cleaners[self.event] or dummyFunc)(self)
|
||||
end
|
||||
|
||||
function GameEvent:exit()
|
||||
return (GameEvent.exit_funcs[self.event] or dummyFunc)(self)
|
||||
end
|
||||
|
||||
function GameEvent:addCleaner(f)
|
||||
if self.extra_clear_funcs == Util.DummyTable then
|
||||
self.extra_clear_funcs = {}
|
||||
if self.extra_clear == Util.DummyTable then
|
||||
self.extra_clear= {}
|
||||
end
|
||||
table.insert(self.extra_clear_funcs, f)
|
||||
table.insert(self.extra_clear, f)
|
||||
end
|
||||
|
||||
function GameEvent:addExitFunc(f)
|
||||
if self.extra_exit_funcs == Util.DummyTable then
|
||||
self.extra_exit_funcs = {}
|
||||
if self.extra_exit== Util.DummyTable then
|
||||
self.extra_exit= {}
|
||||
end
|
||||
table.insert(self.extra_exit_funcs, f)
|
||||
table.insert(self.extra_exit, f)
|
||||
end
|
||||
|
||||
function GameEvent:prependExitFunc(f)
|
||||
if self.extra_exit_funcs == Util.DummyTable then
|
||||
self.extra_exit_funcs = {}
|
||||
if self.extra_exit== Util.DummyTable then
|
||||
self.extra_exit= {}
|
||||
end
|
||||
table.insert(self.extra_exit_funcs, 1, f)
|
||||
table.insert(self.extra_exit, 1, f)
|
||||
end
|
||||
|
||||
-- 找第一个与当前事件有继承关系的特定事件
|
||||
---@param eventType integer @ 事件类型
|
||||
---@param eventType GameEvent @ 事件类型
|
||||
---@param includeSelf bool @ 是否包括本事件
|
||||
---@param depth? integer @ 搜索深度
|
||||
---@return GameEvent?
|
||||
|
@ -187,18 +218,18 @@ function GameEvent:exec()
|
|||
|
||||
self.parent = logic:getCurrentEvent()
|
||||
|
||||
if self:prepare_func() then return true end
|
||||
if self:prepare() then return true end
|
||||
|
||||
logic:pushEvent(self)
|
||||
|
||||
local co = coroutine.create(self.main_func)
|
||||
local co = coroutine.create(function() return self:main() end)
|
||||
self._co = co
|
||||
self.status = "running"
|
||||
|
||||
coroutine.yield(self, "__newEvent")
|
||||
|
||||
Pcall(self.exit_func, self)
|
||||
for _, f in ipairs(self.extra_exit_funcs) do
|
||||
Pcall(self.exit, self)
|
||||
for _, f in ipairs(self.extra_exit) do
|
||||
if type(f) == "function" then
|
||||
Pcall(f, self)
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
---@field public cleaner_stack Stack
|
||||
---@field public role_table string[][]
|
||||
---@field public all_game_events GameEvent[]
|
||||
---@field public event_recorder table<integer, GameEvent>
|
||||
---@field public event_recorder table<GameEvent, GameEvent>
|
||||
---@field public current_event_id integer
|
||||
local GameLogic = class("GameLogic")
|
||||
|
||||
|
@ -23,7 +23,21 @@ function GameLogic:initialize(room)
|
|||
self.game_event_stack = Stack:new()
|
||||
self.cleaner_stack = Stack:new()
|
||||
self.all_game_events = {}
|
||||
self.event_recorder = {}
|
||||
self.event_recorder = setmetatable({}, {
|
||||
-- 对派生事件而言 共用一个键 键取决于最接近GameEvent类的基类
|
||||
__newindex = function(t, k, v)
|
||||
if type(k) == "table" and k:isSubclassOf(GameEvent) then
|
||||
k = k:getBaseClass()
|
||||
end
|
||||
rawset(t, k, v)
|
||||
end,
|
||||
__index = function(t, k)
|
||||
if type(k) == "table" and k:isSubclassOf(GameEvent) then
|
||||
k = k:getBaseClass()
|
||||
end
|
||||
return rawget(t, k)
|
||||
end,
|
||||
})
|
||||
self.current_event_id = 0
|
||||
self.specific_events_id = {
|
||||
[GameEvent.Damage] = 1,
|
||||
|
@ -65,13 +79,13 @@ function GameLogic:run()
|
|||
self:action()
|
||||
end
|
||||
|
||||
local function execGameEvent(type, ...)
|
||||
local event = GameEvent:new(type, ...)
|
||||
---@return boolean
|
||||
local function execGameEvent(tp, ...)
|
||||
local event = tp:create(...)
|
||||
local _, ret = event:exec()
|
||||
return ret
|
||||
end
|
||||
|
||||
|
||||
function GameLogic:assignRoles()
|
||||
local room = self.room
|
||||
local n = #room.players
|
||||
|
@ -113,17 +127,13 @@ function GameLogic:chooseGenerals()
|
|||
generals = table.filter(generals, function(g) return not table.contains(lord_generals, g) end)
|
||||
room:returnToGeneralPile(generals)
|
||||
|
||||
room:setPlayerGeneral(lord, lord_general, true)
|
||||
room:prepareGeneral(lord, lord_general, deputy, true)
|
||||
|
||||
room:askForChooseKingdom({lord})
|
||||
room:broadcastProperty(lord, "general")
|
||||
room:broadcastProperty(lord, "kingdom")
|
||||
room:setDeputyGeneral(lord, deputy)
|
||||
room:broadcastProperty(lord, "deputyGeneral")
|
||||
end
|
||||
|
||||
local nonlord = room:getOtherPlayers(lord, true)
|
||||
local generals = room:getNGenerals(#nonlord * generalNum)
|
||||
table.shuffle(generals)
|
||||
local generals = table.random(room.general_pile, #nonlord * generalNum)
|
||||
for i, p in ipairs(nonlord) do
|
||||
local arg = table.slice(generals, (i - 1) * generalNum + 1, i * generalNum + 1)
|
||||
p.request_data = json.encode{ arg, n }
|
||||
|
@ -133,25 +143,22 @@ function GameLogic:chooseGenerals()
|
|||
room:notifyMoveFocus(nonlord, "AskForGeneral")
|
||||
room:doBroadcastRequest("AskForGeneral", nonlord)
|
||||
|
||||
local selected = {}
|
||||
for _, p in ipairs(nonlord) do
|
||||
local general, deputy
|
||||
if p.general == "" and p.reply_ready then
|
||||
local general_ret = json.decode(p.client_reply)
|
||||
local general = general_ret[1]
|
||||
local deputy = general_ret[2]
|
||||
table.insertTableIfNeed(selected, general_ret)
|
||||
room:setPlayerGeneral(p, general, true, true)
|
||||
room:setDeputyGeneral(p, deputy)
|
||||
general = general_ret[1]
|
||||
deputy = general_ret[2]
|
||||
else
|
||||
room:setPlayerGeneral(p, p.default_reply[1], true, true)
|
||||
room:setDeputyGeneral(p, p.default_reply[2])
|
||||
general = p.default_reply[1]
|
||||
deputy = p.default_reply[2]
|
||||
end
|
||||
room:findGeneral(general)
|
||||
room:findGeneral(deputy)
|
||||
room:prepareGeneral(p, general, deputy)
|
||||
p.default_reply = ""
|
||||
end
|
||||
|
||||
generals = table.filter(generals, function(g) return not table.contains(selected, g) end)
|
||||
room:returnToGeneralPile(generals)
|
||||
|
||||
room:askForChooseKingdom(nonlord)
|
||||
end
|
||||
|
||||
|
@ -178,14 +185,25 @@ function GameLogic:broadcastGeneral()
|
|||
p.shield = math.min(general.shield + (deputy and deputy.shield or 0), 5)
|
||||
-- TODO: setup AI here
|
||||
|
||||
if p.role ~= "lord" then
|
||||
room:broadcastProperty(p, "general")
|
||||
room:broadcastProperty(p, "kingdom")
|
||||
room:broadcastProperty(p, "deputyGeneral")
|
||||
elseif #players >= 5 then
|
||||
p.maxHp = p.maxHp + 1
|
||||
p.hp = p.hp + 1
|
||||
local changer = Fk.game_modes[room.settings.gameMode]:getAdjustedProperty(p)
|
||||
if changer then
|
||||
for key, value in pairs(changer) do
|
||||
p[key] = value
|
||||
end
|
||||
end
|
||||
local fixMaxHp = Fk.generals[p.general].fixMaxHp
|
||||
local deputyFix = Fk.generals[p.deputyGeneral] and Fk.generals[p.deputyGeneral].fixMaxHp
|
||||
if deputyFix then
|
||||
fixMaxHp = fixMaxHp and math.min(fixMaxHp, deputyFix) or deputyFix
|
||||
end
|
||||
if fixMaxHp then
|
||||
p.maxHp = fixMaxHp
|
||||
end
|
||||
p.hp = math.min(p.maxHp, p.hp)
|
||||
|
||||
room:broadcastProperty(p, "general")
|
||||
room:broadcastProperty(p, "deputyGeneral")
|
||||
room:broadcastProperty(p, "kingdom")
|
||||
room:broadcastProperty(p, "maxHp")
|
||||
room:broadcastProperty(p, "hp")
|
||||
room:broadcastProperty(p, "shield")
|
||||
|
@ -416,7 +434,7 @@ end
|
|||
|
||||
-- 此为启动事件管理器并启动第一个事件的初始函数
|
||||
function GameLogic:start()
|
||||
local root_event = GameEvent:new(GameEvent.Game)
|
||||
local root_event = GameEvent.Game:create()
|
||||
|
||||
self:pushEvent(root_event)
|
||||
|
||||
|
@ -424,25 +442,20 @@ function GameLogic:start()
|
|||
-- 事件管理器协程,同时也是Game事件
|
||||
-- 当新事件想要exec时,就切回此处,由这里负责调度协程
|
||||
-- 一个事件结束后也切回此处,然后resume
|
||||
local co = coroutine.create(root_event.main_func)
|
||||
local co = coroutine.create(function() return root_event:main() end)
|
||||
root_event._co = co
|
||||
|
||||
local jump_to -- shutdown函数用
|
||||
|
||||
while true do
|
||||
-- 对于cleaner和正常事件,处理更后面来的
|
||||
local ne = self:getCurrentEvent()
|
||||
local ce = self:getCurrentCleaner()
|
||||
local e = ce and (ce.id >= ne.id and ce or ne) or ne
|
||||
|
||||
-- 如果正在jump的话,判断是否需要继续clean,否则正常继续
|
||||
if e == ne and jump_to ~= nil then
|
||||
if e == ne and e.killed then
|
||||
e.interrupted = true
|
||||
e.killed = e ~= jump_to
|
||||
self:clearEvent(e)
|
||||
coroutine.close(e._co)
|
||||
e.status = "dead"
|
||||
if e == jump_to then jump_to = nil end -- shutdown结束了
|
||||
e = self:getCurrentCleaner()
|
||||
end
|
||||
|
||||
|
@ -467,11 +480,12 @@ function GameLogic:start()
|
|||
coroutine.close(e._co)
|
||||
e.status = "dead"
|
||||
elseif ret == true then
|
||||
-- 跳到越早发生的事件越好
|
||||
if not jump_to then
|
||||
jump_to = evt
|
||||
else
|
||||
jump_to = jump_to.id < evt.id and jump_to or evt
|
||||
-- 遍历栈,将shutdown图中的事件全标记上killed
|
||||
-- 被标记killed的事件之后会自动结束并清理
|
||||
for i = self.game_event_stack.p, 1, -1 do
|
||||
local event = self.game_event_stack.t[i]
|
||||
event.killed = true
|
||||
if event == evt then break end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -551,9 +565,9 @@ function GameLogic:clearEvent(event)
|
|||
if event.event == GameEvent.ClearEvent then return end
|
||||
if event.status == "exiting" then return end
|
||||
event.status = "exiting"
|
||||
local ce = GameEvent(GameEvent.ClearEvent, event)
|
||||
local ce = GameEvent.ClearEvent:create(event)
|
||||
ce.id = self.current_event_id
|
||||
local co = coroutine.create(ce.main_func)
|
||||
local co = coroutine.create(function() return ce:main() end)
|
||||
ce._co = co
|
||||
self.cleaner_stack:push(ce)
|
||||
end
|
||||
|
@ -563,7 +577,7 @@ function GameLogic:getCurrentEvent()
|
|||
return self.game_event_stack.t[self.game_event_stack.p]
|
||||
end
|
||||
|
||||
---@param eventType integer
|
||||
---@param eventType GameEvent
|
||||
function GameLogic:getMostRecentEvent(eventType)
|
||||
return self:getCurrentEvent():findParent(eventType, true)
|
||||
end
|
||||
|
@ -581,7 +595,7 @@ function GameLogic:getCurrentSkillName()
|
|||
end
|
||||
|
||||
-- 在指定历史范围中找至多n个符合条件的事件
|
||||
---@param eventType integer @ 要查找的事件类型
|
||||
---@param eventType GameEvent @ 要查找的事件类型
|
||||
---@param n integer @ 最多找多少个
|
||||
---@param func fun(e: GameEvent): boolean @ 过滤用的函数
|
||||
---@param scope integer @ 查询历史范围,只能是当前阶段/回合/轮次
|
||||
|
|
|
@ -2,9 +2,13 @@
|
|||
|
||||
local function tellRoomToObserver(self, player)
|
||||
local observee = self.players[1]
|
||||
local start_time = os.getms()
|
||||
local summary = self:getSummary(observee, true)
|
||||
player:doNotify("Observe", json.encode(summary))
|
||||
|
||||
fk.qInfo(string.format("[Observe] %d, %s, in %.3fms",
|
||||
self.id, player:getScreenName(), (os.getms() - start_time) / 1000))
|
||||
|
||||
table.insert(self.observers, {observee.id, player, player:getId()})
|
||||
end
|
||||
|
||||
|
@ -76,6 +80,7 @@ request_handlers["luckcard"] = function(room, id, reqlist)
|
|||
p:doNotify("AskForLuckCard", pdata.luckTime)
|
||||
else
|
||||
p.serverplayer:setThinking(false)
|
||||
ResumeRoom(room.id)
|
||||
end
|
||||
|
||||
room:setTag("LuckCardData", luck_data)
|
||||
|
@ -111,6 +116,7 @@ request_handlers["surrender"] = function(room, id, reqlist)
|
|||
room.hasSurrendered = true
|
||||
player.surrendered = true
|
||||
room:doBroadcastNotify("CancelRequest", "")
|
||||
ResumeRoom(room.id)
|
||||
end
|
||||
|
||||
request_handlers["updatemini"] = function(room, pid, reqlist)
|
||||
|
@ -127,6 +133,7 @@ end
|
|||
|
||||
request_handlers["newroom"] = function(s, id)
|
||||
s:registerRoom(id)
|
||||
ResumeRoom(id)
|
||||
end
|
||||
|
||||
request_handlers["reloadpackage"] = function(_, _, reqlist)
|
||||
|
@ -135,31 +142,16 @@ request_handlers["reloadpackage"] = function(_, _, reqlist)
|
|||
Fk:reloadPackage(path)
|
||||
end
|
||||
|
||||
-- 处理异步请求的协程,本身也是个死循环就是了。
|
||||
-- 为了适应调度器,目前又暂且将请求分为“耗时请求”和不耗时请求。
|
||||
-- 耗时请求处理后会立刻挂起。不耗时的请求则会不断处理直到请求队列空后再挂起。
|
||||
local function requestLoop(self)
|
||||
while true do
|
||||
local ret = false
|
||||
local request = self.thread:fetchRequest()
|
||||
if request ~= "" then
|
||||
ret = true
|
||||
local reqlist = request:split(",")
|
||||
local roomId = tonumber(table.remove(reqlist, 1))
|
||||
local room = self:getRoom(roomId)
|
||||
return function(self, request)
|
||||
local reqlist = request:split(",")
|
||||
local roomId = tonumber(table.remove(reqlist, 1))
|
||||
local room = self:getRoom(roomId)
|
||||
|
||||
if room then
|
||||
RoomInstance = room
|
||||
local id = tonumber(reqlist[1])
|
||||
local command = reqlist[2]
|
||||
Pcall(request_handlers[command], room, id, reqlist)
|
||||
RoomInstance = nil
|
||||
end
|
||||
end
|
||||
if not ret then
|
||||
coroutine.yield()
|
||||
end
|
||||
if room then
|
||||
RoomInstance = room
|
||||
local id = tonumber(reqlist[1])
|
||||
local command = reqlist[2]
|
||||
Pcall(request_handlers[command], room, id, reqlist)
|
||||
RoomInstance = nil
|
||||
end
|
||||
end
|
||||
|
||||
return requestLoop
|
||||
|
|
|
@ -84,6 +84,11 @@ function Room:initialize(_room)
|
|||
self.request_queue = {}
|
||||
self.request_self = {}
|
||||
|
||||
-- doNotify过载保护,每次获得控制权时置为0
|
||||
-- 若在yield之前执行了max次doNotify则强制让出
|
||||
self.notify_count = 0
|
||||
self.notify_max = 500
|
||||
|
||||
self.settings = json.decode(self.room:settings())
|
||||
self.disabled_packs = self.settings.disabledPack
|
||||
if not Fk.game_modes[self.settings.gameMode] then
|
||||
|
@ -108,10 +113,11 @@ function Room:resume()
|
|||
local main_co = self.main_co
|
||||
|
||||
if self:checkNoHuman() then
|
||||
return true
|
||||
goto GAME_OVER
|
||||
end
|
||||
|
||||
if not self.game_finished then
|
||||
self.notify_count = 0
|
||||
ret, err_msg, rest_time = coroutine.resume(main_co, err_msg)
|
||||
|
||||
-- handle error
|
||||
|
@ -162,17 +168,6 @@ function Room:isReady()
|
|||
return true
|
||||
end
|
||||
|
||||
-- 因为delay函数而延时:判断延时是否已经结束。
|
||||
-- 注意整个delay函数的实现都搬到这来了,delay本身只负责挂起协程了。
|
||||
if self.in_delay then
|
||||
local rest = self.delay_duration - (os.getms() - self.delay_start) / 1000
|
||||
if rest <= 0 then
|
||||
self.in_delay = false
|
||||
return true
|
||||
end
|
||||
return false, rest
|
||||
end
|
||||
|
||||
-- 剩下的就是因为等待应答而未就绪了
|
||||
-- 检查所有正在等回答的玩家,如果已经过了烧条时间
|
||||
-- 那么就不认为他还需要时间就绪了
|
||||
|
@ -182,13 +177,14 @@ function Room:isReady()
|
|||
for _, p in ipairs(self.players) do
|
||||
-- 这里判断的话需要用_splayer了,不然一控多的情况下会导致重复判断
|
||||
if p._splayer:thinking() then
|
||||
ret = false
|
||||
-- 烧条烧光了的话就把thinking设为false
|
||||
rest = p.request_timeout * 1000 - (os.getms() -
|
||||
p.request_start) / 1000
|
||||
|
||||
if rest <= 0 or p.serverplayer:getState() ~= fk.Player_Online then
|
||||
p._splayer:setThinking(false)
|
||||
else
|
||||
ret = false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -244,7 +240,6 @@ function Room:run()
|
|||
local logic = (mode.logic and mode.logic() or GameLogic):new(self)
|
||||
self.logic = logic
|
||||
if mode.rule then logic:addTriggerSkill(mode.rule) end
|
||||
-- GameEvent(GameEvent.Game):exec()
|
||||
logic:start()
|
||||
end
|
||||
|
||||
|
@ -337,7 +332,7 @@ end
|
|||
--- 获得当前房间中的所有玩家。
|
||||
---
|
||||
--- 返回的数组的第一个元素是当前回合玩家,并且按行动顺序进行排序。
|
||||
---@param sortBySeat? boolean @ 是否无视按座位排序直接返回
|
||||
---@param sortBySeat? boolean @ 是否按座位排序,默认是
|
||||
---@return ServerPlayer[] @ 房间中玩家的数组
|
||||
function Room:getAllPlayers(sortBySeat)
|
||||
if not self.game_started then
|
||||
|
@ -359,7 +354,7 @@ function Room:getAllPlayers(sortBySeat)
|
|||
end
|
||||
|
||||
--- 获得所有存活玩家,参看getAllPlayers
|
||||
---@param sortBySeat? boolean
|
||||
---@param sortBySeat? boolean @ 是否按座位排序,默认是
|
||||
---@return ServerPlayer[]
|
||||
function Room:getAlivePlayers(sortBySeat)
|
||||
if sortBySeat == nil or sortBySeat then
|
||||
|
@ -370,7 +365,7 @@ function Room:getAlivePlayers(sortBySeat)
|
|||
if temp == nil then
|
||||
return { table.unpack(self.players) }
|
||||
end
|
||||
local ret = {current}
|
||||
local ret = current.dead and {} or {current}
|
||||
while temp ~= current do
|
||||
if not temp.dead then
|
||||
table.insert(ret, temp)
|
||||
|
@ -386,7 +381,7 @@ end
|
|||
|
||||
--- 获得除一名玩家外的其他玩家。
|
||||
---@param player ServerPlayer @ 要排除的玩家
|
||||
---@param sortBySeat? boolean @ 是否要按座位排序?
|
||||
---@param sortBySeat? boolean @ 是否按座位排序,默认是
|
||||
---@param include_dead? boolean @ 是否要把死人也算进去?
|
||||
---@return ServerPlayer[] @ 其他玩家列表
|
||||
function Room:getOtherPlayers(player, sortBySeat, include_dead)
|
||||
|
@ -565,8 +560,8 @@ function Room:setBanner(name, value)
|
|||
end
|
||||
|
||||
---@return boolean
|
||||
local function execGameEvent(type, ...)
|
||||
local event = GameEvent:new(type, ...)
|
||||
local function execGameEvent(tp, ...)
|
||||
local event = tp:create(...)
|
||||
local _, ret = event:exec()
|
||||
return ret
|
||||
end
|
||||
|
@ -600,6 +595,41 @@ function Room:setDeputyGeneral(player, general)
|
|||
self:notifyProperty(player, player, "deputyGeneral")
|
||||
end
|
||||
|
||||
---@param player ServerPlayer
|
||||
---@param general string
|
||||
---@param deputy string
|
||||
---@param broadcast boolean|nil
|
||||
function Room:prepareGeneral(player, general, deputy, broadcast)
|
||||
self:findGeneral(general)
|
||||
self:findGeneral(deputy)
|
||||
local skills = Fk.generals[general]:getSkillNameList()
|
||||
if Fk.generals[deputy] then
|
||||
table.insertTable(skills, Fk.generals[deputy]:getSkillNameList())
|
||||
end
|
||||
if table.find(skills, function (s) return Fk.skills[s].isHiddenSkill end) then
|
||||
self:setPlayerMark(player, "__hidden_general", general)
|
||||
if Fk.generals[deputy] then
|
||||
self:setPlayerMark(player, "__hidden_deputy", deputy)
|
||||
deputy = ""
|
||||
end
|
||||
general = "hiddenone"
|
||||
end
|
||||
player.general = general
|
||||
player.gender = Fk.generals[general].gender
|
||||
self:broadcastProperty(player, "gender")
|
||||
if Fk.generals[deputy] then
|
||||
player.deputyGeneral = deputy
|
||||
end
|
||||
player.kingdom = Fk.generals[general].kingdom
|
||||
for _, property in ipairs({"general","deputyGeneral","kingdom"}) do
|
||||
if broadcast then
|
||||
self:broadcastProperty(player, property)
|
||||
else
|
||||
self:notifyProperty(player, player, property)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param player ServerPlayer @ 要换将的玩家
|
||||
---@param new_general string @ 要变更的武将,若不存在则变身为孙策,孙策不存在变身为士兵
|
||||
---@param full? boolean @ 是否血量满状态变身
|
||||
|
@ -757,6 +787,10 @@ local function surrenderCheck(room)
|
|||
room.hasSurrendered = false
|
||||
end
|
||||
|
||||
local function setRequestTimer(room)
|
||||
room.room:setRequestTimer(room.timeout * 1000 + 500)
|
||||
end
|
||||
|
||||
--- 向某个玩家发起一次Request。
|
||||
---@param player ServerPlayer @ 发出这个请求的目标玩家
|
||||
---@param command string @ 请求的类型
|
||||
|
@ -770,9 +804,11 @@ function Room:doRequest(player, command, jsonData, wait)
|
|||
player:doRequest(command, jsonData, self.timeout)
|
||||
|
||||
if wait then
|
||||
setRequestTimer(self)
|
||||
local ret = player:waitForReply(self.timeout)
|
||||
player.serverplayer:setBusy(false)
|
||||
player.serverplayer:setThinking(false)
|
||||
self.room:destroyRequestTimer()
|
||||
surrenderCheck(self)
|
||||
return ret
|
||||
end
|
||||
|
@ -786,6 +822,7 @@ function Room:doBroadcastRequest(command, players, jsonData)
|
|||
players = players or self.players
|
||||
self.request_queue = {}
|
||||
self.race_request_list = nil
|
||||
setRequestTimer(self)
|
||||
for _, p in ipairs(players) do
|
||||
p:doRequest(command, jsonData or p.request_data)
|
||||
end
|
||||
|
@ -803,6 +840,7 @@ function Room:doBroadcastRequest(command, players, jsonData)
|
|||
p.serverplayer:setThinking(false)
|
||||
end
|
||||
|
||||
self.room:destroyRequestTimer()
|
||||
surrenderCheck(self)
|
||||
end
|
||||
|
||||
|
@ -819,6 +857,7 @@ function Room:doRaceRequest(command, players, jsonData)
|
|||
players = players or self.players
|
||||
players = table.simpleClone(players)
|
||||
local player_len = #players
|
||||
setRequestTimer(self)
|
||||
-- self:notifyMoveFocus(players, command)
|
||||
self.request_queue = {}
|
||||
self.race_request_list = players
|
||||
|
@ -837,7 +876,8 @@ function Room:doRaceRequest(command, players, jsonData)
|
|||
if remainTime - elapsed <= 0 then
|
||||
break
|
||||
end
|
||||
for _, p in ipairs(players) do
|
||||
for i = #players, 1, -1 do
|
||||
local p = players[i]
|
||||
p:waitForReply(0)
|
||||
if p.reply_ready == true then
|
||||
winner = p
|
||||
|
@ -845,7 +885,7 @@ function Room:doRaceRequest(command, players, jsonData)
|
|||
end
|
||||
|
||||
if p.reply_cancel then
|
||||
table.removeOne(players, p)
|
||||
table.remove(players, i)
|
||||
table.insertIfNeed(canceled_players, p)
|
||||
elseif p.id > 0 then
|
||||
-- 骗过调度器让他以为自己尚未就绪
|
||||
|
@ -871,20 +911,16 @@ function Room:doRaceRequest(command, players, jsonData)
|
|||
p.serverplayer:setThinking(false)
|
||||
end
|
||||
|
||||
self.room:destroyRequestTimer()
|
||||
surrenderCheck(self)
|
||||
return ret
|
||||
end
|
||||
|
||||
|
||||
--- 延迟一段时间。
|
||||
---
|
||||
--- 这个函数不应该在请求处理协程中使用。
|
||||
---@param ms integer @ 要延迟的毫秒数
|
||||
function Room:delay(ms)
|
||||
local start = os.getms()
|
||||
self.delay_start = start
|
||||
self.delay_duration = ms
|
||||
self.in_delay = true
|
||||
self.room:delay(ms)
|
||||
coroutine.yield("__handleRequest", ms)
|
||||
end
|
||||
|
||||
|
@ -913,24 +949,6 @@ function Room:notifyMoveCards(players, card_moves, forceVisible)
|
|||
end
|
||||
end
|
||||
|
||||
local function containArea(area, relevant) --处理区的处理?
|
||||
local areas = relevant
|
||||
and {Card.PlayerEquip, Card.PlayerJudge, Card.DiscardPile, Card.Processing, Card.PlayerHand, Card.PlayerSpecial}
|
||||
or {Card.PlayerEquip, Card.PlayerJudge, Card.DiscardPile, Card.Processing}
|
||||
return table.contains(areas, area)
|
||||
end
|
||||
|
||||
-- forceVisible make the move visible
|
||||
-- if move is relevant to player's hands or equips, it should be open
|
||||
-- cards move from/to equip/judge/discard/processing should be open
|
||||
|
||||
if not (move.moveVisible or forceVisible or containArea(move.toArea, move.to and p.isBuddy and p:isBuddy(move.to))) then
|
||||
for _, info in ipairs(move.moveInfo) do
|
||||
if not containArea(info.fromArea, move.from and p.isBuddy and p:isBuddy(move.from)) then
|
||||
info.cardId = -1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
p:doNotify("MoveCards", json.encode(arg))
|
||||
end
|
||||
|
@ -1058,7 +1076,7 @@ end
|
|||
--- 与此同时,在战报里面发一条“xxx发动了xxx”
|
||||
---@param player ServerPlayer @ 发动技能的那个玩家
|
||||
---@param skill_name string @ 技能名
|
||||
---@param skill_type? string @ 技能的动画效果,默认是那个技能的anim_type
|
||||
---@param skill_type? string | AnimationType @ 技能的动画效果,默认是那个技能的anim_type
|
||||
function Room:notifySkillInvoked(player, skill_name, skill_type)
|
||||
local bigAnim = false
|
||||
if not skill_type then
|
||||
|
@ -1842,7 +1860,13 @@ function Room:askForChoice(player, choices, skill_name, prompt, detailed, all_ch
|
|||
local result = self:doRequest(player, command, json.encode{
|
||||
choices, all_choices, skill_name, prompt, detailed
|
||||
})
|
||||
if result == "" then result = choices[1] end
|
||||
if result == "" then
|
||||
if table.contains(choices, "Cancel") then
|
||||
result = "Cancel"
|
||||
else
|
||||
result = choices[1]
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
|
@ -1970,6 +1994,93 @@ function Room:askForAddTarget(player, targets, num, can_minus, distance_limited,
|
|||
return {}
|
||||
end
|
||||
|
||||
--- 询问玩家在自定义大小的框中排列卡牌(观星、交换、拖拽选牌)
|
||||
---@param player ServerPlayer @ 要询问的玩家
|
||||
---@param skillname string @ 烧条技能名
|
||||
---@param cardMap any @ { "牌堆1卡表", "牌堆2卡表", …… }
|
||||
---@param prompt? string @ 操作提示
|
||||
---@param box_size? integer @ 数值对应卡牌平铺张数的最大值,为0则有单个卡位,每张卡占100单位长度,默认为7
|
||||
---@param max_limit? integer[] @ 每一行牌上限 { 第一行, 第二行,…… },不填写则不限
|
||||
---@param min_limit? integer[] @ 每一行牌下限 { 第一行, 第二行,…… },不填写则不限
|
||||
---@param free_arrange? boolean @ 是否允许自由排列第一行卡的位置,默认不能
|
||||
---@param pattern? string @ 控制第一行卡牌是否可以操作,不填写默认均可操作
|
||||
---@param poxi_type? string @ 控制每张卡牌是否可以操作、确定键是否可以点击,不填写默认均可操作
|
||||
---@param default_choice? table[] @ 超时的默认响应值,在带poxi_type时需要填写
|
||||
---@return table[]
|
||||
function Room:askForArrangeCards(player, skillname, cardMap, prompt, free_arrange, box_size, max_limit, min_limit, pattern, poxi_type, default_choice)
|
||||
prompt = prompt or ""
|
||||
local areaNames = {}
|
||||
if type(cardMap[1]) == "number" then
|
||||
cardMap = {cardMap}
|
||||
else
|
||||
for i = #cardMap, 1, -1 do
|
||||
if type(cardMap[i]) == "string" then
|
||||
table.insert(areaNames, 1, cardMap[i])
|
||||
table.remove(cardMap, i)
|
||||
end
|
||||
end
|
||||
end
|
||||
if #areaNames == 0 then
|
||||
areaNames = {skillname, "toObtain"}
|
||||
end
|
||||
box_size = box_size or 7
|
||||
max_limit = max_limit or {#cardMap[1], #cardMap > 1 and #cardMap[2] or #cardMap[1]}
|
||||
min_limit = min_limit or {0, 0}
|
||||
for _ = #cardMap + 1, #min_limit, 1 do
|
||||
table.insert(cardMap, {})
|
||||
end
|
||||
pattern = pattern or "."
|
||||
poxi_type = poxi_type or ""
|
||||
local command = "AskForArrangeCards"
|
||||
local data = {
|
||||
cards = cardMap,
|
||||
names = areaNames,
|
||||
prompt = prompt,
|
||||
size = box_size,
|
||||
capacities = max_limit,
|
||||
limits = min_limit,
|
||||
is_free = free_arrange or false,
|
||||
pattern = pattern or ".",
|
||||
poxi_type = poxi_type or "",
|
||||
cancelable = ((pattern ~= "." or poxi_type ~= "") and (default_choice == nil))
|
||||
}
|
||||
local result = self:doRequest(player, command, json.encode(data))
|
||||
-- local result = player.room:askForCustomDialog(player, skillname,
|
||||
-- "RoomElement/ArrangeCardsBox.qml", {
|
||||
-- cardMap, prompt, box_size, max_limit, min_limit, free_arrange or false, areaNames,
|
||||
-- pattern or ".", poxi_type or "", ((pattern ~= "." or poxi_type ~= "") and (default_choice == nil))
|
||||
-- })
|
||||
if result == "" then
|
||||
if default_choice then return default_choice end
|
||||
for j = 1, #min_limit, 1 do
|
||||
if #cardMap[j] < min_limit[j] then
|
||||
local cards = {table.connect(table.unpack(cardMap))}
|
||||
if #min_limit > 1 then
|
||||
for i = 2, #min_limit, 1 do
|
||||
table.insert(cards, {})
|
||||
if #cards[i] < min_limit[i] then
|
||||
for _ = 1, min_limit[i] - #cards[i], 1 do
|
||||
table.insert(cards[i], table.remove(cards[1], #cards[1] + #cards[i] - min_limit[i] + 1))
|
||||
end
|
||||
end
|
||||
end
|
||||
if #cards[1] > max_limit[1] then
|
||||
for i = 2, #max_limit, 1 do
|
||||
while #cards[i] < max_limit[i] do
|
||||
table.insert(cards[i], table.remove(cards[1], max_limit[1] + 1))
|
||||
if #cards[1] == max_limit[1] then return cards end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return cards
|
||||
end
|
||||
end
|
||||
return cardMap
|
||||
end
|
||||
return json.decode(result)
|
||||
end
|
||||
|
||||
-- TODO: guanxing type
|
||||
--- 询问玩家对若干牌进行观星。
|
||||
---
|
||||
|
@ -2003,9 +2114,15 @@ function Room:askForGuanxing(player, cards, top_limit, bottom_limit, customNotif
|
|||
end
|
||||
local command = "AskForGuanxing"
|
||||
self:notifyMoveFocus(player, customNotify or command)
|
||||
local max_top = top_limit and top_limit[2] or #cards
|
||||
local card_map = {table.slice(cards, 1, max_top + 1)}
|
||||
if max_top < #cards then
|
||||
table.insert(card_map, table.slice(cards, max_top))
|
||||
end
|
||||
local data = {
|
||||
prompt = "",
|
||||
cards = cards,
|
||||
is_free = true,
|
||||
cards = card_map,
|
||||
min_top_cards = top_limit and top_limit[1] or 0,
|
||||
max_top_cards = top_limit and top_limit[2] or #cards,
|
||||
min_bottom_cards = bottom_limit and bottom_limit[1] or 0,
|
||||
|
@ -2034,7 +2151,7 @@ function Room:askForGuanxing(player, cards, top_limit, bottom_limit, customNotif
|
|||
for i = #top, 1, -1 do
|
||||
table.insert(self.draw_pile, 1, top[i])
|
||||
end
|
||||
for i = 1, #bottom, -1 do
|
||||
for i = 1, #bottom, 1 do
|
||||
table.insert(self.draw_pile, bottom[i])
|
||||
end
|
||||
|
||||
|
@ -2062,7 +2179,7 @@ function Room:askForExchange(player, piles, piles_name, customNotify)
|
|||
if #piles_name ~= #piles then
|
||||
piles_name = {}
|
||||
for i, _ in ipairs(piles) do
|
||||
table.insert(piles_name, "Pile" .. i)
|
||||
table.insert(piles_name, Fk:translate("Pile") .. i)
|
||||
end
|
||||
end
|
||||
self:notifyMoveFocus(player, customNotify or command)
|
||||
|
@ -2420,6 +2537,7 @@ end
|
|||
-- Show a qml dialog and return qml's ClientInstance.replyToServer
|
||||
-- Do anything you like through this function
|
||||
|
||||
-- 调用一个自定义对话框,须自备loadData方法
|
||||
---@param player ServerPlayer
|
||||
---@param focustxt string
|
||||
---@param qmlPath string
|
||||
|
@ -2434,6 +2552,7 @@ function Room:askForCustomDialog(player, focustxt, qmlPath, extra_data)
|
|||
})
|
||||
end
|
||||
|
||||
--- 询问移动场上的一张牌
|
||||
---@param player ServerPlayer @ 移动的操作
|
||||
---@param targetOne ServerPlayer @ 移动的目标1玩家
|
||||
---@param targetTwo ServerPlayer @ 移动的目标2玩家
|
||||
|
@ -2731,15 +2850,16 @@ function Room:doCardUseEffect(cardUseEvent)
|
|||
return
|
||||
end
|
||||
|
||||
if self:getPlayerById(TargetGroup:getRealTargets(cardUseEvent.tos)[1]).dead then
|
||||
self:moveCards({
|
||||
ids = realCardIds,
|
||||
toArea = Card.DiscardPile,
|
||||
moveReason = fk.ReasonPutIntoDiscardPile,
|
||||
})
|
||||
else
|
||||
local target = TargetGroup:getRealTargets(cardUseEvent.tos)[1]
|
||||
local existingEquipId = self:getPlayerById(target):getEquipment(cardUseEvent.card.sub_type)
|
||||
local target = TargetGroup:getRealTargets(cardUseEvent.tos)[1]
|
||||
if not (self:getPlayerById(target).dead or table.contains((cardUseEvent.nullifiedTargets or Util.DummyTable), target)) then
|
||||
local existingEquipId
|
||||
if cardUseEvent.toPutSlot and cardUseEvent.toPutSlot:startsWith("#EquipmentChoice") then
|
||||
local index = cardUseEvent.toPutSlot:split(":")[2]
|
||||
existingEquipId = self:getPlayerById(target):getEquipments(cardUseEvent.card.sub_type)[tonumber(index)]
|
||||
elseif not self:getPlayerById(target):hasEmptyEquipSlot(cardUseEvent.card.sub_type) then
|
||||
existingEquipId = self:getPlayerById(target):getEquipment(cardUseEvent.card.sub_type)
|
||||
end
|
||||
|
||||
if existingEquipId then
|
||||
self:moveCards(
|
||||
{
|
||||
|
@ -2772,7 +2892,7 @@ function Room:doCardUseEffect(cardUseEvent)
|
|||
end
|
||||
|
||||
local target = TargetGroup:getRealTargets(cardUseEvent.tos)[1]
|
||||
if not self:getPlayerById(target).dead then
|
||||
if not (self:getPlayerById(target).dead or table.contains((cardUseEvent.nullifiedTargets or Util.DummyTable), target)) then
|
||||
local findSameCard = false
|
||||
for _, cardId in ipairs(self:getPlayerById(target):getCardIds(Player.Judge)) do
|
||||
if Fk:getCardById(cardId).trueName == cardUseEvent.card.trueName then
|
||||
|
@ -2783,6 +2903,13 @@ function Room:doCardUseEffect(cardUseEvent)
|
|||
if not findSameCard then
|
||||
if cardUseEvent.card:isVirtual() then
|
||||
self:getPlayerById(target):addVirtualEquip(cardUseEvent.card)
|
||||
elseif cardUseEvent.card.name ~= Fk:getCardById(cardUseEvent.card.id, true).name then
|
||||
local card = Fk:cloneCard(cardUseEvent.card.name)
|
||||
card.skillNames = cardUseEvent.card.skillNames
|
||||
card:addSubcard(cardUseEvent.card.id)
|
||||
self:getPlayerById(target):addVirtualEquip(card)
|
||||
else
|
||||
self:getPlayerById(target):removeVirtualEquip(cardUseEvent.card.id)
|
||||
end
|
||||
|
||||
self:moveCards({
|
||||
|
@ -2796,12 +2923,6 @@ function Room:doCardUseEffect(cardUseEvent)
|
|||
end
|
||||
end
|
||||
|
||||
self:moveCards({
|
||||
ids = realCardIds,
|
||||
toArea = Card.DiscardPile,
|
||||
moveReason = fk.ReasonPutIntoDiscardPile,
|
||||
})
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -3091,34 +3212,16 @@ end
|
|||
|
||||
--- 让一名玩家获得一张牌
|
||||
---@param player integer|ServerPlayer @ 要拿牌的玩家
|
||||
---@param cid integer|Card|integer[] @ 要拿到的卡牌
|
||||
---@param card integer|integer[]|Card|Card[] @ 要拿到的卡牌
|
||||
---@param unhide? boolean @ 是否明着拿
|
||||
---@param reason? CardMoveReason @ 卡牌移动的原因
|
||||
---@param proposer? integer @ 移动操作者的id
|
||||
function Room:obtainCard(player, cid, unhide, reason, proposer)
|
||||
if type(cid) ~= "number" then
|
||||
assert(cid and type(cid) == "table")
|
||||
if cid[1] == nil then
|
||||
cid = cid:isVirtual() and cid.subcards or {cid.id}
|
||||
end
|
||||
else
|
||||
cid = {cid}
|
||||
end
|
||||
if #cid == 0 then return end
|
||||
|
||||
if type(player) == "table" then
|
||||
player = player.id
|
||||
end
|
||||
|
||||
self:moveCards({
|
||||
ids = cid,
|
||||
from = self.owner_map[cid[1]],
|
||||
to = player,
|
||||
toArea = Card.PlayerHand,
|
||||
moveReason = reason or fk.ReasonJustMove,
|
||||
proposer = proposer or player,
|
||||
moveVisible = unhide or false,
|
||||
})
|
||||
---@param skill_name? string @ 技能名
|
||||
---@param moveMark? table|string @ 移动后自动赋予标记,格式:{标记名(支持-inarea后缀,移出值代表区域后清除), 值}
|
||||
---@param visiblePlayers? integer|integer[] @ 控制移动对特定角色可见(在moveVisible为false时生效)
|
||||
function Room:obtainCard(player, card, unhide, reason, proposer, skill_name, moveMark, visiblePlayers)
|
||||
local pid = type(player) == "number" and player or player.id
|
||||
self:moveCardTo(card, Card.PlayerHand, player, reason, skill_name, nil, unhide, proposer or pid, moveMark, visiblePlayers)
|
||||
end
|
||||
|
||||
--- 让玩家摸牌
|
||||
|
@ -3126,8 +3229,9 @@ end
|
|||
---@param num integer @ 摸牌数
|
||||
---@param skillName? string @ 技能名
|
||||
---@param fromPlace? string @ 摸牌的位置,"top" 或者 "bottom"
|
||||
---@param moveMark? table|string @ 移动后自动赋予标记,格式:{标记名(支持-inarea后缀,移出值代表区域后清除), 值}
|
||||
---@return integer[] @ 摸到的牌
|
||||
function Room:drawCards(player, num, skillName, fromPlace)
|
||||
function Room:drawCards(player, num, skillName, fromPlace, moveMark)
|
||||
local drawData = {
|
||||
who = player,
|
||||
num = num,
|
||||
|
@ -3150,6 +3254,7 @@ function Room:drawCards(player, num, skillName, fromPlace)
|
|||
moveReason = fk.ReasonDraw,
|
||||
proposer = player.id,
|
||||
skillName = skillName,
|
||||
moveMark = moveMark,
|
||||
})
|
||||
|
||||
return { table.unpack(topCards) }
|
||||
|
@ -3158,13 +3263,15 @@ end
|
|||
--- 将一张或多张牌移动到某处
|
||||
---@param card integer | integer[] | Card | Card[] @ 要移动的牌
|
||||
---@param to_place integer @ 移动的目标位置
|
||||
---@param target? ServerPlayer @ 移动的目标角色
|
||||
---@param target? ServerPlayer|integer @ 移动的目标角色
|
||||
---@param reason? integer @ 移动时使用的移牌原因
|
||||
---@param skill_name? string @ 技能名
|
||||
---@param special_name? string @ 私人牌堆名
|
||||
---@param visible? boolean @ 是否明置
|
||||
---@param proposer? integer @ 移动操作者的id
|
||||
function Room:moveCardTo(card, to_place, target, reason, skill_name, special_name, visible, proposer)
|
||||
---@param moveMark? table|string @ 移动后自动赋予标记,格式:{标记名(支持-inarea后缀,移出值代表区域后清除), 值}
|
||||
---@param visiblePlayers? integer|integer[] @ 控制移动对特定角色可见(在moveVisible为false时生效)
|
||||
function Room:moveCardTo(card, to_place, target, reason, skill_name, special_name, visible, proposer, moveMark, visiblePlayers)
|
||||
reason = reason or fk.ReasonJustMove
|
||||
skill_name = skill_name or ""
|
||||
special_name = special_name or ""
|
||||
|
@ -3174,7 +3281,12 @@ function Room:moveCardTo(card, to_place, target, reason, skill_name, special_nam
|
|||
if table.contains(
|
||||
{Card.PlayerEquip, Card.PlayerHand,
|
||||
Card.PlayerJudge, Card.PlayerSpecial}, to_place) then
|
||||
to = target.id
|
||||
assert(target)
|
||||
if type(target) == "number" then
|
||||
to = target
|
||||
else
|
||||
to = target.id
|
||||
end
|
||||
end
|
||||
|
||||
local movesSplitedByOwner = {}
|
||||
|
@ -3196,6 +3308,8 @@ function Room:moveCardTo(card, to_place, target, reason, skill_name, special_nam
|
|||
specialName = special_name,
|
||||
moveVisible = visible,
|
||||
proposer = proposer,
|
||||
moveMark = moveMark,
|
||||
visiblePlayers = visiblePlayers,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
@ -3559,6 +3673,10 @@ function Room:recastCard(card_ids, who, skillName)
|
|||
moveReason = fk.ReasonRecast,
|
||||
proposer = who.id
|
||||
})
|
||||
self:sendFootnote(card_ids, {
|
||||
type = "##RecastCard",
|
||||
from = who.id,
|
||||
})
|
||||
self:broadcastPlaySound("./audio/system/recast")
|
||||
self:sendLog{
|
||||
type = skillName == "recast" and "#Recast" or "#RecastBySkill",
|
||||
|
@ -3712,6 +3830,7 @@ end
|
|||
---@param winner string @ 获胜的身份,空字符串表示平局
|
||||
function Room:gameOver(winner)
|
||||
if not self.game_started then return end
|
||||
self.room:destroyRequestTimer()
|
||||
|
||||
if table.contains(
|
||||
{ "running", "normal" },
|
||||
|
@ -3727,6 +3846,7 @@ function Room:gameOver(winner)
|
|||
self:broadcastProperty(p, "role")
|
||||
end
|
||||
self:doBroadcastNotify("GameOver", winner)
|
||||
fk.qInfo(string.format("[GameOver] %d, %s, %s, in %ds", self.id, self.settings.gameMode, winner, os.time() - self.start_time))
|
||||
|
||||
if shouldUpdateWinRate(self) then
|
||||
for _, p in ipairs(self.players) do
|
||||
|
@ -3990,6 +4110,52 @@ function Room:resumePlayerArea(player, playerSlots)
|
|||
end
|
||||
end
|
||||
|
||||
---@param player ServerPlayer
|
||||
---@param playerSlots string | string[]
|
||||
function Room:addPlayerEquipSlots(player, playerSlots)
|
||||
assert(type(playerSlots) == "string" or type(playerSlots) == "table")
|
||||
|
||||
if type(playerSlots) == "string" then
|
||||
playerSlots = { playerSlots }
|
||||
end
|
||||
|
||||
for _, slot in ipairs(playerSlots) do
|
||||
local slotIndex = table.indexOf(player.equipSlots, slot)
|
||||
if slotIndex > -1 then
|
||||
table.insert(player.equipSlots, slotIndex, slot)
|
||||
else
|
||||
table.insert(player.equipSlots, slot)
|
||||
end
|
||||
end
|
||||
|
||||
self:broadcastProperty(player, "equipSlots")
|
||||
end
|
||||
|
||||
---@param player ServerPlayer
|
||||
---@param playerSlots string | string[]
|
||||
function Room:removePlayerEquipSlots(player, playerSlots)
|
||||
assert(type(playerSlots) == "string" or type(playerSlots) == "table")
|
||||
|
||||
if type(playerSlots) == "string" then
|
||||
playerSlots = { playerSlots }
|
||||
end
|
||||
|
||||
for _, slot in ipairs(playerSlots) do
|
||||
table.removeOne(player.equipSlots, slot)
|
||||
end
|
||||
|
||||
self:broadcastProperty(player, "equipSlots")
|
||||
end
|
||||
|
||||
---@param player ServerPlayer
|
||||
---@param playerSlots string[]
|
||||
function Room:setPlayerEquipSlots(player, playerSlots)
|
||||
assert(type(playerSlots) == "table")
|
||||
player.equipSlots = playerSlots
|
||||
|
||||
self:broadcastProperty(player, "equipSlots")
|
||||
end
|
||||
|
||||
--- 设置休整
|
||||
---@param player ServerPlayer
|
||||
---@param roundNum integer
|
||||
|
|
|
@ -2,49 +2,19 @@
|
|||
|
||||
local Room = require "server.room"
|
||||
|
||||
--[[
|
||||
local verbose = function(...)
|
||||
printf(...)
|
||||
end
|
||||
--]]
|
||||
|
||||
-- 所有当前正在运行的房间(即游戏尚未结束的房间)
|
||||
---@type table<integer, Room>
|
||||
local runningRooms = {}
|
||||
|
||||
-- 所有处于就绪态的房间,以及request协程(如果就绪的话)
|
||||
---@type Room[]
|
||||
local readyRooms = {}
|
||||
|
||||
local requestCo = coroutine.create(function(room)
|
||||
require "server.request"(room)
|
||||
end)
|
||||
|
||||
-- 仿照Room接口编写的request协程处理器
|
||||
local requestRoom = setmetatable({
|
||||
id = -1,
|
||||
runningRooms = runningRooms,
|
||||
|
||||
-- minDelayTime 是当没有任何就绪房间时,可以睡眠的时间。
|
||||
-- 因为这个时间是所有房间预期就绪用时的最小值,故称为minDelayTime。
|
||||
minDelayTime = -1,
|
||||
|
||||
getRoom = function(_, roomId)
|
||||
return runningRooms[roomId]
|
||||
end,
|
||||
|
||||
resume = function(self)
|
||||
local err, msg = coroutine.resume(requestCo, self)
|
||||
if err == false then
|
||||
fk.qCritical(msg .. "\n" .. debug.traceback(requestCo))
|
||||
end
|
||||
return nil, 0
|
||||
end,
|
||||
|
||||
isReady = function(self)
|
||||
return self.thread:hasRequest()
|
||||
end,
|
||||
|
||||
registerRoom = function(self, id)
|
||||
local cRoom = self.thread:getRoom(id)
|
||||
local room = Room:new(cRoom)
|
||||
|
@ -59,116 +29,44 @@ local requestRoom = setmetatable({
|
|||
|
||||
runningRooms[-1] = requestRoom
|
||||
|
||||
-- 从所有运行中房间中挑出就绪的房间。
|
||||
-- 方法暂时就是最简单的遍历。
|
||||
local function refreshReadyRooms()
|
||||
-- verbose '[+] Refreshing ready queue...'
|
||||
for k, v in pairs(runningRooms) do
|
||||
local ready, rest = v:isReady()
|
||||
if ready then
|
||||
table.insertIfNeed(readyRooms, v)
|
||||
elseif rest and rest >= 0 then
|
||||
local time = requestRoom.minDelayTime
|
||||
time = math.min((time <= 0 and 9999999 or time), rest)
|
||||
requestRoom.minDelayTime = math.ceil(time)
|
||||
end
|
||||
end
|
||||
-- verbose('[+] now have %d ready rooms...', #readyRooms)
|
||||
end
|
||||
|
||||
-- 主循环。只要线程没有被杀掉,就一直循环下去。
|
||||
-- 函数每轮循环会从队列中取一个元素并交给控制权,
|
||||
-- 如果没有,则尝试刷新队列,无法刷新则开始睡眠。
|
||||
local function mainLoop()
|
||||
-- request协程的专用特判变量。因为处理request不应当重置睡眠时长
|
||||
local rest_sleep_time
|
||||
|
||||
while not requestRoom.thread:isTerminated() do
|
||||
local room = table.remove(readyRooms, 1)
|
||||
if room then
|
||||
-- verbose '============= LOOP =============='
|
||||
-- verbose('[*] Switching to %s...', tostring(room))
|
||||
|
||||
RoomInstance = (room ~= requestRoom and room or nil)
|
||||
local over, rest = room:resume()
|
||||
RoomInstance = nil
|
||||
|
||||
if over then
|
||||
-- verbose('[#] %s is finished, removing ...', tostring(room))
|
||||
for _, e in ipairs(room.logic.game_event_stack.t) do
|
||||
coroutine.close(e._co)
|
||||
end
|
||||
for _, e in ipairs(room.logic.cleaner_stack.t) do
|
||||
coroutine.close(e._co)
|
||||
end
|
||||
room.logic = nil
|
||||
runningRooms[room.id] = nil
|
||||
else
|
||||
local time = requestRoom.minDelayTime
|
||||
if room == requestRoom then
|
||||
rest = rest_sleep_time
|
||||
end
|
||||
|
||||
if rest and rest >= 0 then
|
||||
time = math.min((time <= 0 and 9999999 or time), rest)
|
||||
else
|
||||
time = -1
|
||||
end
|
||||
requestRoom.minDelayTime = math.ceil(time)
|
||||
-- verbose("[+] minDelay is %d ms...", requestRoom.minDelayTime)
|
||||
-- verbose('[-] %s successfully yielded, %d ready rooms left...',
|
||||
-- tostring(room), #readyRooms)
|
||||
end
|
||||
else
|
||||
refreshReadyRooms()
|
||||
if #readyRooms == 0 then
|
||||
refreshReadyRooms()
|
||||
if #readyRooms == 0 then
|
||||
local time = requestRoom.minDelayTime
|
||||
-- verbose('[.] Sleeping for %d ms...', time)
|
||||
local cur = os.getms()
|
||||
|
||||
time = math.min((time <= 0 and 9999999 or time), 200)
|
||||
|
||||
-- 调用RoomThread的trySleep函数开始真正的睡眠。会被wakeUp(c++)唤醒。
|
||||
requestRoom.thread:trySleep(time)
|
||||
local runningRoomsCount = -1 -- 必有requestRoom,从-1开始算
|
||||
for _ in pairs(runningRooms) do
|
||||
runningRoomsCount = runningRoomsCount + 1
|
||||
if runningRoomsCount > 0 then break end
|
||||
end
|
||||
if runningRoomsCount == 0 and requestRoom.thread:isOutdated() then
|
||||
break
|
||||
end
|
||||
|
||||
-- verbose('[!] Waked up after %f ms...', (os.getms() - cur) / 1000)
|
||||
|
||||
if time > 0 then
|
||||
rest_sleep_time = math.floor(time - (os.getms() - cur) / 1000)
|
||||
else
|
||||
rest_sleep_time = -1
|
||||
end
|
||||
|
||||
requestRoom.minDelayTime = -1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- verbose '=========== LOOP END ============'
|
||||
-- verbose '[:)] Goodbye!'
|
||||
end
|
||||
|
||||
-- 当Cpp侧的RoomThread运行时,以下这个函数就是这个线程的主函数。
|
||||
-- 而这个函数里面又调用了上面的mainLoop。
|
||||
function InitScheduler(_thread)
|
||||
requestRoom.thread = _thread
|
||||
Pcall(mainLoop)
|
||||
-- Pcall(mainLoop)
|
||||
end
|
||||
|
||||
function IsConsoleStart()
|
||||
return requestRoom.thread:isConsoleStart()
|
||||
end
|
||||
|
||||
local Req = require "server.request"
|
||||
function HandleRequest(req)
|
||||
Req(requestRoom, req)
|
||||
return true
|
||||
end
|
||||
|
||||
function ResumeRoom(roomId)
|
||||
local room = requestRoom:getRoom(roomId)
|
||||
if not room then return false end
|
||||
if not room:isReady() then return false end
|
||||
RoomInstance = (room ~= requestRoom and room or nil)
|
||||
local over = room:resume()
|
||||
RoomInstance = nil
|
||||
|
||||
if over then
|
||||
for _, e in ipairs(room.logic.game_event_stack.t) do
|
||||
coroutine.close(e._co)
|
||||
end
|
||||
for _, e in ipairs(room.logic.cleaner_stack.t) do
|
||||
coroutine.close(e._co)
|
||||
end
|
||||
room.logic = nil
|
||||
runningRooms[room.id] = nil
|
||||
end
|
||||
return over
|
||||
end
|
||||
|
||||
if FileIO.pwd():endsWith("packages/freekill-core") then
|
||||
FileIO.cd("../..")
|
||||
end
|
||||
|
|
|
@ -53,17 +53,25 @@ end
|
|||
---@param command string
|
||||
---@param jsonData string
|
||||
function ServerPlayer:doNotify(command, jsonData)
|
||||
local room = self.room
|
||||
for _, p in ipairs(self._observers) do
|
||||
if p:getState() ~= fk.Player_Robot then
|
||||
room.notify_count = room.notify_count + 1
|
||||
end
|
||||
p:doNotify(command, jsonData)
|
||||
end
|
||||
|
||||
local room = self.room
|
||||
for _, t in ipairs(room.observers) do
|
||||
local id, p = table.unpack(t)
|
||||
if id == self.id and room.room:hasObserver(p) then
|
||||
p:doNotify(command, jsonData)
|
||||
end
|
||||
end
|
||||
|
||||
if room.notify_count >= room.notify_max and
|
||||
coroutine.status(room.main_co) == "normal" then
|
||||
room:delay(100)
|
||||
end
|
||||
end
|
||||
|
||||
--- Send a request to client, and allow client to reply within *timeout* seconds.
|
||||
|
@ -155,6 +163,16 @@ local function _waitForReply(player, timeout)
|
|||
end
|
||||
end
|
||||
|
||||
--- 发送一句聊天
|
||||
---@param msg string
|
||||
function ServerPlayer:chat(msg)
|
||||
self.room:doBroadcastNotify("Chat", json.encode {
|
||||
type = 2,
|
||||
sender = self.id,
|
||||
msg = msg,
|
||||
})
|
||||
end
|
||||
|
||||
--- Wait for at most *timeout* seconds for reply from client.
|
||||
---
|
||||
--- If *timeout* is negative or **nil**, the function will wait forever until get reply.
|
||||
|
@ -369,7 +387,7 @@ function ServerPlayer:changePhase(from_phase, to_phase)
|
|||
table.remove(self.phases, 1)
|
||||
end
|
||||
|
||||
GameEvent(GameEvent.Phase, self, self.phase):exec()
|
||||
GameEvent.Phase:create(self, self.phase):exec()
|
||||
|
||||
return false
|
||||
end
|
||||
|
@ -412,7 +430,7 @@ function ServerPlayer:gainAnExtraPhase(phase, delay)
|
|||
arg = phase_name_table[phase],
|
||||
}
|
||||
|
||||
GameEvent(GameEvent.Phase, self, self.phase):exec()
|
||||
GameEvent.Phase:create(self, self.phase):exec()
|
||||
|
||||
phase_change = {
|
||||
from = phase,
|
||||
|
@ -491,7 +509,7 @@ function ServerPlayer:play(phase_table)
|
|||
end
|
||||
|
||||
if (not skip) or (cancel_skip) then
|
||||
GameEvent(GameEvent.Phase, self, self.phase):exec()
|
||||
GameEvent.Phase:create(self, self.phase):exec()
|
||||
else
|
||||
room:sendLog{
|
||||
type = "#PhaseSkipped",
|
||||
|
@ -554,7 +572,7 @@ function ServerPlayer:gainAnExtraTurn(delay, skillName)
|
|||
local ex_tag = self.tag["_extra_turn_count"]
|
||||
table.insert(ex_tag, skillName)
|
||||
|
||||
GameEvent(GameEvent.Turn, self):exec()
|
||||
GameEvent.Turn:create(self):exec()
|
||||
|
||||
table.remove(ex_tag)
|
||||
|
||||
|
@ -581,18 +599,21 @@ end
|
|||
---@param num integer @ 摸牌数
|
||||
---@param skillName? string @ 技能名
|
||||
---@param fromPlace? string @ 摸牌的位置,"top" 或者 "bottom"
|
||||
---@param moveMark? table|string @ 移动后自动赋予标记,格式:{标记名(支持-inarea后缀,移出值代表区域后清除), 值}
|
||||
---@return integer[] @ 摸到的牌
|
||||
function ServerPlayer:drawCards(num, skillName, fromPlace)
|
||||
return self.room:drawCards(self, num, skillName, fromPlace)
|
||||
function ServerPlayer:drawCards(num, skillName, fromPlace, moveMark)
|
||||
return self.room:drawCards(self, num, skillName, fromPlace, moveMark)
|
||||
end
|
||||
|
||||
---@param pile_name string
|
||||
---@param card integer|Card
|
||||
---@param card integer | integer[] | Card | Card[]
|
||||
---@param visible? boolean
|
||||
---@param skillName? string
|
||||
function ServerPlayer:addToPile(pile_name, card, visible, skillName)
|
||||
local room = self.room
|
||||
room:moveCardTo(card, Card.PlayerSpecial, self, fk.ReasonJustMove, skillName, pile_name, visible)
|
||||
---@param proposer? integer
|
||||
---@param visiblePlayers? integer | integer[] @ 为nil时默认对自己可见
|
||||
function ServerPlayer:addToPile(pile_name, card, visible, skillName, proposer, visiblePlayers)
|
||||
self.room:moveCardTo(card, Card.PlayerSpecial, self, fk.ReasonJustMove, skillName, pile_name, visible,
|
||||
proposer or self.id, nil, visiblePlayers)
|
||||
end
|
||||
|
||||
function ServerPlayer:bury()
|
||||
|
@ -637,6 +658,7 @@ function ServerPlayer:clearPiles()
|
|||
end
|
||||
|
||||
function ServerPlayer:addVirtualEquip(card)
|
||||
self:removeVirtualEquip(card:getEffectiveId())
|
||||
Player.addVirtualEquip(self, card)
|
||||
self.room:doBroadcastNotify("AddVirtualEquip", json.encode{
|
||||
player = self.id,
|
||||
|
@ -647,10 +669,12 @@ end
|
|||
|
||||
function ServerPlayer:removeVirtualEquip(cid)
|
||||
local ret = Player.removeVirtualEquip(self, cid)
|
||||
self.room:doBroadcastNotify("RemoveVirtualEquip", json.encode{
|
||||
player = self.id,
|
||||
id = cid,
|
||||
})
|
||||
if ret then
|
||||
self.room:doBroadcastNotify("RemoveVirtualEquip", json.encode{
|
||||
player = self.id,
|
||||
id = cid,
|
||||
})
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
---@field public specialName? string @ 若终点区域为PlayerSpecial,则存至对应私人牌堆内
|
||||
---@field public specialVisible? boolean @ 控制上述创建私人牌堆后是否令其可见
|
||||
---@field public drawPilePosition? integer @ 移至牌堆的索引位置,值为-1代表置入牌堆底,或者牌堆牌数+1也为牌堆底
|
||||
---@field public moveMark? table @ 移动后自动赋予标记,格式:{标记名(支持-inarea后缀,移出值代表区域后清除), 值}
|
||||
---@field public moveMark? table|string @ 移动后自动赋予标记,格式:{标记名(支持-inarea后缀,移出值代表区域后清除), 值}
|
||||
---@field public visiblePlayers? integer|integer[] @ 控制移动对特定角色可见(在moveVisible为false时生效)
|
||||
|
||||
--- MoveInfo 一张牌的来源信息
|
||||
---@class MoveInfo
|
||||
|
@ -36,7 +37,8 @@
|
|||
---@field public specialName? string @ 若终点区域为PlayerSpecial,则存至对应私人牌堆内
|
||||
---@field public specialVisible? boolean @ 控制上述创建私人牌堆后是否令其可见
|
||||
---@field public drawPilePosition? integer @ 移至牌堆的索引位置,值为-1代表置入牌堆底,或者牌堆牌数+1也为牌堆底
|
||||
---@field public moveMark? table @ 移动后自动赋予标记,格式:{标记名(支持-inarea后缀,移出值代表区域后清除), 值}
|
||||
---@field public moveMark? table|string @ 移动后自动赋予标记,格式:{标记名(支持-inarea后缀,移出值代表区域后清除), 值}
|
||||
---@field public visiblePlayers? integer|integer[] @ 控制移动对特定角色可见(在moveVisible为false时生效)
|
||||
|
||||
--- PindianResult 拼点结果
|
||||
---@class PindianResult
|
||||
|
|
|
@ -2,21 +2,21 @@ return {
|
|||
["maneuvering"] = "Maneuvering",
|
||||
|
||||
["thunder__slash"] = "Thunder Slash",
|
||||
[":thunder__slash"] = "Thunder Slash (basic card)<br /><b>Phase</b>: Action phase<br /><b>Target</b>: Another player within your ATK range<br /><b>Effect</b>: Deal 1 Thunder DMG to the targets.<br/><b>Note</b>: You can only use 1 Slash per action phase.",
|
||||
[":thunder__slash"] = "Thunder Slash (basic card)<br /><b>Phase</b>: Action phase<br /><b>Target</b>: Another player within your ATK range<br /><b>Effect</b>: Deal 1 Thunder DMG to the targets.<br/><b>Note</b>: You can only use 1 Slash per action phase.",
|
||||
["#thunder__slash_skill"] = "Choose 1 player within your ATK range, deal 1 Thunder DMG to him",
|
||||
["#thunder__slash_skill_multi"] = "Choose up to %arg players within your ATK range. Deal 1 Thunder DMG to them",
|
||||
|
||||
["fire__slash"] = "Fire Slash",
|
||||
[":fire__slash"] = "Fire Slash (basic card)<br /><b>Phase</b>: Action phase<br /><b>Target</b>: Another player within your ATK range<br /><b>Effect</b>: Deal 1 Fire DMG to the targets.<br/><b>Note</b>: You can only use 1 Slash per action phase.",
|
||||
[":fire__slash"] = "Fire Slash (basic card)<br /><b>Phase</b>: Action phase<br /><b>Target</b>: Another player within your ATK range<br /><b>Effect</b>: Deal 1 Fire DMG to the targets.<br/><b>Note</b>: You can only use 1 Slash per action phase.",
|
||||
["#fire__slash_skill"] = "Choose 1 player within your ATK range, deal 1 Fire DMG to him",
|
||||
["#fire__slash_skill_multi"] = "Choose up to %arg players within your ATK range. Deal 1 Fire DMG to them",
|
||||
|
||||
["analeptic"] = "Alcohol",
|
||||
[":analeptic"] = "Alcohol (basic card)<br /><b>Phase</b>: 1. Action phase 2. When you are dying<br /><b>Target</b>: Yourself<br /><b>Effect</b>: 1. the DMG of the next Slash you use this turn is increased by +1. (This effect can only be used once per turn) 2. You heal 1 HP.",
|
||||
[":analeptic"] = "Alcohol (basic card)<br /><b>Phase</b>: 1. Action phase 2. When you are dying<br /><b>Target</b>: Yourself<br /><b>Effect</b>: 1. the DMG of the next Slash you use this turn is increased by +1. (This effect can only be used once per turn) 2. You heal 1 HP.",
|
||||
["#analeptic_skill"] = "the DMG of the next Slash you use this turn is increased by +1",
|
||||
|
||||
["iron_chain"] = "Iron Chain",
|
||||
[":iron_chain"] = "Iron Chain (trick card)<br /><b>Phase</b>: Action phase<br /><b>Target</b>: 1~2 players<br /><b>Effect</b>: Change chain state of the targets.",
|
||||
[":iron_chain"] = "Iron Chain (trick card)<br /><b>Phase</b>: Action phase<br /><b>Target</b>: 1~2 players<br /><b>Effect</b>: Change chain state of the targets.",
|
||||
["#iron_chain_skill"] = "Choose 1~2 players. Change their chain states",
|
||||
["_normal_use"] = "Normally use",
|
||||
["recast"] = "Recast",
|
||||
|
@ -25,29 +25,29 @@ return {
|
|||
|
||||
["fire_attack"] = "Fire Attack",
|
||||
["fire_attack_skill"] = "Fire Attack",
|
||||
[":fire_attack"] = "Fire Attack (trick card)<br /><b>Phase</b>: Action phase<br /><b>Target</b>: A player with hand cards<br /><b>Effect</b>: The target player shows 1 hand card; then, if you discard 1 card with the same suit, you deal 1 Fire DMG to him.",
|
||||
[":fire_attack"] = "Fire Attack (trick card)<br /><b>Phase</b>: Action phase<br /><b>Target</b>: A player with hand cards<br /><b>Effect</b>: The target player shows 1 hand card; then, if you discard 1 card with the same suit, you deal 1 Fire DMG to him.",
|
||||
["#fire_attack-show"] = "%src used Fire Attack to you, please show 1 hand card",
|
||||
["#fire_attack-discard"] = "You can discard 1 %arg hand card, then deal 1 Fire DMG to %src",
|
||||
["#fire_attack_skill"] = "Choose a player with hand cards. He shows 1 hand card;<br />then, if you discard 1 card with the same suit, you deal 1 Fire DMG to him",
|
||||
|
||||
["supply_shortage"] = "Supply Shortage",
|
||||
[":supply_shortage"] = "Supply Shortage (delayed trick card)<br /><b>Phase</b>: Action phase<br /><b>Target</b>: Another player at distance 1<br /><b>Effect</b>: Place this card in target's judgement area. He performs a judgement in his judge phase: if result is not ♣, he skips his draw phase.",
|
||||
[":supply_shortage"] = "Supply Shortage (delayed trick card)<br /><b>Phase</b>: Action phase<br /><b>Target</b>: Another player at distance 1<br /><b>Effect</b>: Place this card in target's judgement area. He performs a judgement in his judge phase: if result is not ♣, he skips his draw phase.",
|
||||
["#supply_shortage_skill"] = "Place this card in another player's judgement area. He performs a judgement in his judge phase:<br />If result is not ♣, he skips his draw phase",
|
||||
|
||||
["guding_blade"] = "Ancient Scimitar",
|
||||
[":guding_blade"] = "Ancient Scimitar (equip card, weapon)<br /><b>ATK range</b>: 2<br /><b>Weapon skill</b>: When your used Slash is about to cause DMG, if the target player has no hand cards: the DMG is increased by +1.",
|
||||
[":guding_blade"] = "Ancient Scimitar (equip card, weapon)<br /><b>ATK range</b>: 2<br /><b>Weapon skill</b>: When your used Slash is about to cause DMG, if the target player has no hand cards: the DMG is increased by +1.",
|
||||
["#guding_blade_skill"] = "Ancient Scimitar",
|
||||
|
||||
["fan"] = "Fan",
|
||||
[":fan"] = "Fan (equip card, weapon)<br /><b>ATK range</b>: 4<br /><b>Weapon skill</b>: You can use any basic Slash as Fire Slash.",
|
||||
[":fan"] = "Fan (equip card, weapon)<br /><b>ATK range</b>: 4<br /><b>Weapon skill</b>: You can use any basic Slash as Fire Slash.",
|
||||
["#fan_skill"] = "Fan",
|
||||
|
||||
["vine"] = "Vine",
|
||||
[":vine"] = "Vine (equip card, armor)<br /><b>Armor skill</b>: Savage Assault, Archery Attack and basic Slash have no effect on you. When you are about to suffer Fire DMG, the DMG is increased by +1.",
|
||||
[":vine"] = "Vine (equip card, armor)<br /><b>Armor skill</b>: Savage Assault, Archery Attack and basic Slash have no effect on you. When you are about to suffer Fire DMG, the DMG is increased by +1.",
|
||||
["#vine_skill"] = "Vine",
|
||||
|
||||
["silver_lion"] = "Sliver Lion",
|
||||
[":silver_lion"] = "Sliver Lion (equip card, armor)<br /><b>Armor skill</b>: When you are about to suffer DMG: that DMG is reduced to 1. When you lose this card in your equipment area: you heal 1 HP.",
|
||||
[":silver_lion"] = "Sliver Lion (equip card, armor)<br /><b>Armor skill</b>: When you are about to suffer DMG: that DMG is reduced to 1. When you lose this card in your equipment area: you heal 1 HP.",
|
||||
["#silver_lion_skill"] = "Sliver Lion",
|
||||
|
||||
["hualiu"] = "Hua Liu",
|
||||
|
|
|
@ -136,7 +136,7 @@ local analepticSkill = fk.CreateActiveSkill{
|
|||
card = effect.card,
|
||||
})
|
||||
else
|
||||
to.drank = to.drank + 1
|
||||
to.drank = to.drank + 1 + ((effect.extra_data or {}).additionalDrank or 0)
|
||||
room:broadcastProperty(to, "drank")
|
||||
end
|
||||
end
|
||||
|
@ -497,21 +497,21 @@ Fk:loadTranslationTable{
|
|||
["maneuvering"] = "军争",
|
||||
|
||||
["thunder__slash"] = "雷杀",
|
||||
[":thunder__slash"] = "基本牌<br /><b>时机</b>:出牌阶段<br /><b>目标</b>:攻击范围内的一名角色<br /><b>效果</b>:对目标角色造成1点雷电伤害。",
|
||||
[":thunder__slash"] = "基本牌<br /><b>时机</b>:出牌阶段<br /><b>目标</b>:攻击范围内的一名角色<br /><b>效果</b>:对目标角色造成1点雷电伤害。",
|
||||
["#thunder__slash_skill"] = "选择攻击范围内的一名角色,对其造成1点雷电伤害",
|
||||
["#thunder__slash_skill_multi"] = "选择攻击范围内的至多%arg名角色,对这些角色各造成1点雷电伤害",
|
||||
|
||||
["fire__slash"] = "火杀",
|
||||
[":fire__slash"] = "基本牌<br /><b>时机</b>:出牌阶段<br /><b>目标</b>:攻击范围内的一名角色<br /><b>效果</b>:对目标角色造成1点火焰伤害。",
|
||||
[":fire__slash"] = "基本牌<br /><b>时机</b>:出牌阶段<br /><b>目标</b>:攻击范围内的一名角色<br /><b>效果</b>:对目标角色造成1点火焰伤害。",
|
||||
["#fire__slash_skill"] = "选择攻击范围内的一名角色,对其造成1点火焰伤害",
|
||||
["#fire__slash_skill_multi"] = "选择攻击范围内的至多%arg名角色,对这些角色各造成1点火焰伤害",
|
||||
|
||||
["analeptic"] = "酒",
|
||||
[":analeptic"] = "基本牌<br /><b>时机</b>:出牌阶段/你处于濒死状态时<br /><b>目标</b>:你<br /><b>效果</b>:目标角色本回合使用的下一张【杀】将要造成的伤害+1/目标角色回复1点体力。",
|
||||
[":analeptic"] = "基本牌<br /><b>时机</b>:出牌阶段/你处于濒死状态时<br /><b>目标</b>:你<br /><b>效果</b>:目标角色本回合使用的下一张【杀】将要造成的伤害+1/目标角色回复1点体力。",
|
||||
["#analeptic_skill"] = "你于此回合内使用的下一张【杀】的伤害值基数+1",
|
||||
|
||||
["iron_chain"] = "铁锁连环",
|
||||
[":iron_chain"] = "锦囊牌<br /><b>时机</b>:出牌阶段<br /><b>目标</b>:一至两名角色<br /><b>效果</b>:横置或重置目标角色的武将牌。",
|
||||
[":iron_chain"] = "锦囊牌<br /><b>时机</b>:出牌阶段<br /><b>目标</b>:一至两名角色<br /><b>效果</b>:横置或重置目标角色的武将牌。",
|
||||
["#iron_chain_skill"] = "选择一至两名角色,这些角色横置或重置",
|
||||
["_normal_use"] = "正常使用",
|
||||
["recast"] = "重铸",
|
||||
|
@ -520,29 +520,29 @@ Fk:loadTranslationTable{
|
|||
|
||||
["fire_attack"] = "火攻",
|
||||
["fire_attack_skill"] = "火攻",
|
||||
[":fire_attack"] = "锦囊牌<br /><b>时机</b>:出牌阶段<br /><b>目标</b>:一名有手牌的角色<br /><b>效果</b>:目标角色展示一张手牌,然后你可以弃置一张与此牌花色相同的手牌对其造成1点火焰伤害。",
|
||||
[":fire_attack"] = "锦囊牌<br /><b>时机</b>:出牌阶段<br /><b>目标</b>:一名有手牌的角色<br /><b>效果</b>:目标角色展示一张手牌,然后你可以弃置一张与此牌花色相同的手牌对其造成1点火焰伤害。",
|
||||
["#fire_attack-show"] = "%src 对你使用了火攻,请展示一张手牌",
|
||||
["#fire_attack-discard"] = "你可弃置一张 %arg 手牌,对 %src 造成1点火属性伤害",
|
||||
["#fire_attack_skill"] = "选择一名有手牌的角色,令其展示一张手牌,<br />然后你可以弃置一张与此牌花色相同的手牌对其造成1点火焰伤害",
|
||||
|
||||
["supply_shortage"] = "兵粮寸断",
|
||||
[":supply_shortage"] = "延时锦囊牌<br /><b>时机</b>:出牌阶段<br /><b>目标</b>:距离1的一名其他角色<br /><b>效果</b>:将此牌置于目标角色判定区内。其判定阶段进行判定:若结果不为♣,其跳过摸牌阶段。然后将【兵粮寸断】置入弃牌堆。",
|
||||
[":supply_shortage"] = "延时锦囊牌<br /><b>时机</b>:出牌阶段<br /><b>目标</b>:距离1的一名其他角色<br /><b>效果</b>:将此牌置于目标角色判定区内。其判定阶段进行判定:若结果不为♣,其跳过摸牌阶段。然后将【兵粮寸断】置入弃牌堆。",
|
||||
["#supply_shortage_skill"] = "选择距离1的一名角色,将此牌置于其判定区内。其判定阶段判定:<br />若结果不为♣,其跳过摸牌阶段",
|
||||
|
||||
["guding_blade"] = "古锭刀",
|
||||
[":guding_blade"] = "装备牌·武器<br /><b>攻击范围</b>:2<br /><b>武器技能</b>:锁定技。每当你使用【杀】对目标角色造成伤害时,若该角色没有手牌,此伤害+1。",
|
||||
[":guding_blade"] = "装备牌·武器<br /><b>攻击范围</b>:2<br /><b>武器技能</b>:锁定技。每当你使用【杀】对目标角色造成伤害时,若该角色没有手牌,此伤害+1。",
|
||||
["#guding_blade_skill"] = "古锭刀",
|
||||
|
||||
["fan"] = "朱雀羽扇",
|
||||
[":fan"] = "装备牌·武器<br /><b>攻击范围</b>:4<br /><b>武器技能</b>:当你声明使用普【杀】后,你可以将此【杀】改为火【杀】。",
|
||||
[":fan"] = "装备牌·武器<br /><b>攻击范围</b>:4<br /><b>武器技能</b>:当你声明使用普【杀】后,你可以将此【杀】改为火【杀】。",
|
||||
["#fan_skill"] = "朱雀羽扇",
|
||||
|
||||
["vine"] = "藤甲",
|
||||
[":vine"] = "装备牌·防具<br /><b>防具技能</b>:锁定技。【南蛮入侵】、【万箭齐发】和普通【杀】对你无效。每当你受到火焰伤害时,此伤害+1。",
|
||||
[":vine"] = "装备牌·防具<br /><b>防具技能</b>:锁定技。【南蛮入侵】、【万箭齐发】和普通【杀】对你无效。每当你受到火焰伤害时,此伤害+1。",
|
||||
["#vine_skill"] = "藤甲",
|
||||
|
||||
["silver_lion"] = "白银狮子",
|
||||
[":silver_lion"] = "装备牌·防具<br /><b>防具技能</b>:锁定技。每当你受到伤害时,若此伤害大于1点,防止多余的伤害。每当你失去装备区里的【白银狮子】后,你回复1点体力。",
|
||||
[":silver_lion"] = "装备牌·防具<br /><b>防具技能</b>:锁定技。每当你受到伤害时,若此伤害大于1点,防止多余的伤害。每当你失去装备区里的【白银狮子】后,你回复1点体力。",
|
||||
["#silver_lion_skill"] = "白银狮子",
|
||||
|
||||
["hualiu"] = "骅骝",
|
||||
|
|
|
@ -213,7 +213,7 @@ local uncompulsoryInvalidity = fk.CreateInvaliditySkill {
|
|||
end
|
||||
return
|
||||
(skill.frequency ~= Skill.Compulsory and skill.frequency ~= Skill.Wake) and
|
||||
not (skill:isEquipmentSkill() or skill.name:endsWith("&")) and
|
||||
skill:isPlayerSkill(from) and
|
||||
hasMark(from, MarkEnum.UncompulsoryInvalidity, MarkEnum.TempMarkSuffix)
|
||||
-- (
|
||||
-- from:getMark(MarkEnum.UncompulsoryInvalidity) ~= 0 or
|
||||
|
|
|
@ -53,7 +53,14 @@ GameRule = fk.CreateTriggerSkill{
|
|||
end)
|
||||
if #cardNames == 0 then return end
|
||||
|
||||
local peach_use = room:askForUseCard(player, "peach", table.concat(cardNames, ",") , prompt, true, {analepticRecover = true})
|
||||
local peach_use = room:askForUseCard(
|
||||
player,
|
||||
"peach",
|
||||
table.concat(cardNames, ","),
|
||||
prompt,
|
||||
true,
|
||||
{analepticRecover = true, must_targets = { dyingPlayer.id }}
|
||||
)
|
||||
if not peach_use then break end
|
||||
peach_use.tos = { {dyingPlayer.id} }
|
||||
if peach_use.card.trueName == "analeptic" then
|
||||
|
|
|
@ -52,6 +52,7 @@ Fk:loadTranslationTable({
|
|||
["liubei"] = "Liu Bei",
|
||||
["rende"] = "Benevolence",
|
||||
[":rende"] = "In your Action Phase: you can give any # of hand cards to other players; then, if you have given a total of 2 or more cards, you heal 1 HP (only once).",
|
||||
["#rende-active"] = "Use Benevolence, give any # of hand cards to other players;<br >then, if you have given a total of 2 or more cards, you heal 1 HP (only once)",
|
||||
["jijiang"] = "Rouse",
|
||||
[":jijiang"] = "(lord) When you need to use/play Slash: you can ask other Shu characters to play Slash, which is regard as you use/play that.",
|
||||
["#jijiang-ask"] = "Rouse: you can play a Slash, which is regarded as %src uses/plays",
|
||||
|
@ -89,6 +90,7 @@ Fk:loadTranslationTable({
|
|||
["sunquan"] = "Sun Quan",
|
||||
["zhiheng"] = "Balance of Power",
|
||||
[":zhiheng"] = "Once per Action Phase: you can discard any # of cards; then, draw the same # of cards.",
|
||||
["#zhiheng-active"] = "Use Balance of Power, discard any # of cards; then, draw the same # of cards",
|
||||
["jiuyuan"] = "Rescued",
|
||||
[":jiuyuan"] = "(lord, forced) When another Wu character uses Peach to you, you heal +1 HP.",
|
||||
|
||||
|
@ -103,18 +105,20 @@ Fk:loadTranslationTable({
|
|||
["huanggai"] = "Huang Gai",
|
||||
["kurou"] = "Trojan Flesh",
|
||||
[":kurou"] = "In your Action Phase: you can lose 1 HP; then, draw 2 cards.",
|
||||
["#kurou-active"] = "Use Trojan Flesh, lose 1 HP; then, draw 2 cards",
|
||||
|
||||
["zhouyu"] = "Zhou Yu",
|
||||
["yingzi"] = "Handsome",
|
||||
[":yingzi"] = "In your Draw Phase: you can draw +1 additional card.",
|
||||
["fanjian"] = "Sow Dissension",
|
||||
[":fanjian"] = "Once per Action Phase: you can make another player choose 1 suit; then, that player takes 1 hand card from you and displays it. If the guess was wrong, you cause him 1 DMG.",
|
||||
[":fanjian"] = "Once per Action Phase: you can make another player choose 1 suit; then, he takes 1 hand card from you and displays it. If the guess was wrong, you cause him 1 DMG.",
|
||||
["#fanjian-active"] = "Use Sow Dissension, select another player; he chooses 1 suit;<br />then he takes 1 hand card from you and displays it. If the guess was wrong, you cause him 1 DMG",
|
||||
|
||||
["daqiao"] = "Da Qiao",
|
||||
["guose"] = "National Beauty",
|
||||
[":guose"] = "You can use any diamond card as Indulgence.",
|
||||
["liuli"] = "Shirk",
|
||||
[":liuli"] = "When you become the target of Slash: you can discard 1 card and select another player (except the attacker) within your attack range; then, that player becomes the target of the Slash instead.",
|
||||
[":liuli"] = "When you become the target of Slash: you can discard 1 card and select another player (except the attacker) within your attack range; then, he becomes the target of the Slash instead.",
|
||||
["#liuli-target"] = "Shirk: you can discard 1 card and transfer the Slash",
|
||||
|
||||
["luxun"] = "Lu Xun",
|
||||
|
@ -128,10 +132,12 @@ Fk:loadTranslationTable({
|
|||
[":xiaoji"] = "After you lose 1 card in your equipment area: you can draw 2 cards.",
|
||||
["jieyin"] = "Marriage",
|
||||
[":jieyin"] = "Once per Action Phase: you can discard 2 hand cards and select a hurt male character; then, both of you heal 1 HP.",
|
||||
["#jieyin-active"] = "Use Marriage, discard 2 hand cards and select a hurt male character; then, both of you heal 1 HP",
|
||||
|
||||
["huatuo"] = "Hua Tuo",
|
||||
["qingnang"] = "Green Salve",
|
||||
[":qingnang"] = "Once per Action Phase: you can discard 1 hand card and select a wounded player; then, he heals 1 HP.",
|
||||
["#qingnang-active"] = "Use Green Salve, discard 1 hand card and select a wounded player; then, he heals 1 HP",
|
||||
["jijiu"] = "First Aid",
|
||||
[":jijiu"] = "Outside of your turn: you can use any red card as Peach.",
|
||||
|
||||
|
@ -142,6 +148,7 @@ Fk:loadTranslationTable({
|
|||
["diaochan"] = "Diao Chan",
|
||||
["lijian"] = "Seed of Animosity",
|
||||
[":lijian"] = "Once per Action Phase: you may discard 1 card and select 2 male characters; then, this is regarded as one of them having used Duel to target the other. This Duel can't be countered by Nullification.",
|
||||
["#lijian-active"] = "Use Seed of Animosity, discard 1 card and select 2 male characters;<br />then, this is regarded as one of them having used Duel to target the other.<br />This Duel can't be countered by Nullification",
|
||||
["biyue"] = "Envious by Moon",
|
||||
[":biyue"] = "In your Finish Phase, you can draw 1 card.",
|
||||
|
||||
|
|
|
@ -100,6 +100,7 @@ Fk:loadTranslationTable{
|
|||
["$rende2"] = "唯贤唯德,能服于人。",
|
||||
["rende"] = "仁德",
|
||||
[":rende"] = "出牌阶段,你可以将至少一张手牌任意分配给其他角色。你于本阶段内以此法给出的手牌首次达到两张或更多后,你回复1点体力。",
|
||||
["#rende-active"] = "发动 仁德,将至少一张手牌交给其他角色",
|
||||
["$jijiang1"] = "蜀将何在?",
|
||||
["$jijiang2"] = "尔等敢应战否?",
|
||||
["jijiang"] = "激将",
|
||||
|
@ -175,7 +176,8 @@ Fk:loadTranslationTable{
|
|||
["$zhiheng1"] = "容我三思。",
|
||||
["$zhiheng2"] = "且慢。",
|
||||
["zhiheng"] = "制衡",
|
||||
[":zhiheng"] = "出牌阶段限一次,你可以弃置至少一张牌然后摸等量的牌。",
|
||||
[":zhiheng"] = "出牌阶段限一次,你可以弃置任意张牌,然后摸等量的牌。",
|
||||
["#zhiheng-active"] = "发动 制衡,弃置任意张牌,然后摸等量的牌",
|
||||
["$jiuyuan1"] = "有汝辅佐,甚好!",
|
||||
["$jiuyuan2"] = "好舒服啊。",
|
||||
["jiuyuan"] = "救援",
|
||||
|
@ -206,7 +208,8 @@ Fk:loadTranslationTable{
|
|||
["$kurou1"] = "请鞭笞我吧,公瑾!",
|
||||
["$kurou2"] = "赴汤蹈火,在所不辞!",
|
||||
["kurou"] = "苦肉",
|
||||
[":kurou"] = "出牌阶段,你可以失去1点体力然后摸两张牌。",
|
||||
[":kurou"] = "出牌阶段,你可以失去1点体力,然后摸两张牌。",
|
||||
["#kurou-active"] = "发动 苦肉,失去1点体力,然后摸两张牌",
|
||||
|
||||
["zhouyu"] = "周瑜",
|
||||
["#zhouyu"] = "大都督",
|
||||
|
@ -219,7 +222,8 @@ Fk:loadTranslationTable{
|
|||
["$fanjian1"] = "挣扎吧,在血和暗的深渊里!",
|
||||
["$fanjian2"] = "痛苦吧,在仇与恨的地狱中!",
|
||||
["fanjian"] = "反间",
|
||||
[":fanjian"] = "阶段技。你可以令一名其他角色选择一种花色,然后正面朝上获得你的一张手牌。若此牌花色与该角色所选花色不同,你对其造成1点伤害。",
|
||||
[":fanjian"] = "出牌阶段限一次,你可以令一名其他角色选择一种花色,然后正面朝上获得你的一张手牌。若此牌花色与其所选花色不同,你对其造成1点伤害。",
|
||||
["#fanjian-active"] = "发动 反间,选择一名其他角色,令其选择一种花色,然后正面朝上获得你的一张手牌<br />若此牌花色与其所选花色不同,你对其造成1点伤害",
|
||||
|
||||
["daqiao"] = "大乔",
|
||||
["#daqiao"] = "矜持之花",
|
||||
|
@ -246,7 +250,7 @@ Fk:loadTranslationTable{
|
|||
["$lianying1"] = "牌不是万能的,但是没牌是万万不能的。",
|
||||
["$lianying2"] = "旧的不去,新的不来。",
|
||||
["lianying"] = "连营",
|
||||
[":lianying"] = "当你失去最后的手牌后,你可以摸一张牌。",
|
||||
[":lianying"] = "当你失去手牌后,若你没有手牌,你可以摸一张牌。",
|
||||
|
||||
["sunshangxiang"] = "孙尚香",
|
||||
["#sunshangxiang"] = "弓腰姬",
|
||||
|
@ -259,7 +263,8 @@ Fk:loadTranslationTable{
|
|||
["$jieyin1"] = "夫君,身体要紧。",
|
||||
["$jieyin2"] = "他好,我也好。",
|
||||
["jieyin"] = "结姻",
|
||||
[":jieyin"] = "出牌阶段限一次,你可以弃置两张手牌并选择一名已受伤的男性角色:若如此做,你和该角色各回复1点体力。",
|
||||
[":jieyin"] = "出牌阶段限一次,你可以弃置两张手牌并选择一名已受伤的男性角色,然后你与其各回复1点体力。",
|
||||
["#jieyin-active"] = "发动 结姻,弃置两张手牌并选择一名已受伤的男性角色,你与其各回复1点体力",
|
||||
|
||||
["huatuo"] = "华佗",
|
||||
["#huatuo"] = "神医",
|
||||
|
@ -268,7 +273,8 @@ Fk:loadTranslationTable{
|
|||
["$qingnang1"] = "早睡早起,方能养生。",
|
||||
["$qingnang2"] = "越老越要补啊。",
|
||||
["qingnang"] = "青囊",
|
||||
[":qingnang"] = "出牌阶段限一次,你可以弃置一张手牌并选择一名已受伤的角色:若如此做,该角色回复1点体力。",
|
||||
[":qingnang"] = "出牌阶段限一次,你可以弃置一张手牌并选择一名已受伤的角色,然后其回复1点体力。",
|
||||
["#qingnang-active"] = "发动 青囊,弃置一张手牌并选择一名已受伤的角色,其回复1点体力",
|
||||
["$jijiu1"] = "别紧张,有老夫呢。",
|
||||
["$jijiu2"] = "救人一命,胜造七级浮屠。",
|
||||
["jijiu"] = "急救",
|
||||
|
@ -291,6 +297,7 @@ Fk:loadTranslationTable{
|
|||
["$lijian2"] = "夫君,你要替妾身作主啊……",
|
||||
["lijian"] = "离间",
|
||||
[":lijian"] = "出牌阶段限一次,你可以弃置一张牌并选择两名其他男性角色,后选择的角色视为对先选择的角色使用了一张不能被【无懈可击】的【决斗】。",
|
||||
["#lijian-active"] = "发动 离间,弃置一张手牌并选择两名其他男性角色,后选择的角色视为对先选择的角色使用了一张不能被【无懈可击】的【决斗】",
|
||||
["$biyue1"] = "失礼了~",
|
||||
["$biyue2"] = "羡慕吧~",
|
||||
["biyue"] = "闭月",
|
||||
|
@ -529,4 +536,7 @@ Fk:loadTranslationTable{
|
|||
["revealDeputy"] = "明置副将 %arg",
|
||||
|
||||
["game_rule"] = "弃牌阶段",
|
||||
["replace_equip"] = "替换装备",
|
||||
["#EquipmentChoice"] = "%arg",
|
||||
["#GameRuleReplaceEquipment"] = "请选择要置入的区域",
|
||||
}
|
||||
|
|
|
@ -13,11 +13,7 @@ local jianxiong = fk.CreateTriggerSkill{
|
|||
anim_type = "masochism",
|
||||
events = {fk.Damaged},
|
||||
can_trigger = function(self, event, target, player, data)
|
||||
if target == player and player:hasSkill(self) and data.card then
|
||||
local room = player.room
|
||||
local subcards = data.card:isVirtual() and data.card.subcards or {data.card.id}
|
||||
return #subcards>0 and table.every(subcards, function(id) return room:getCardArea(id) == Card.Processing end)
|
||||
end
|
||||
return target == player and player:hasSkill(self) and data.card and player.room:getCardArea(data.card) == Card.Processing
|
||||
end,
|
||||
on_use = function(self, event, target, player, data)
|
||||
player.room:obtainCard(player.id, data.card, true, fk.ReasonJustMove)
|
||||
|
@ -157,11 +153,11 @@ local tuxi = fk.CreateTriggerSkill{
|
|||
events = {fk.EventPhaseStart},
|
||||
can_trigger = function(self, event, target, player, data)
|
||||
return target == player and player:hasSkill(self) and player.phase == Player.Draw and
|
||||
table.find(player.room:getOtherPlayers(player), function(p) return not p:isKongcheng() end)
|
||||
table.find(player.room:getOtherPlayers(player, false), function(p) return not p:isKongcheng() end)
|
||||
end,
|
||||
on_cost = function(self, event, target, player, data)
|
||||
local room = player.room
|
||||
local targets = table.map(table.filter(room:getOtherPlayers(player), function(p)
|
||||
local targets = table.map(table.filter(room:getOtherPlayers(player, false), function(p)
|
||||
return not p:isKongcheng() end), Util.IdMapper)
|
||||
|
||||
local result = room:askForChoosePlayers(player, targets, 1, 2, "#tuxi-ask", self.name)
|
||||
|
@ -273,7 +269,8 @@ local yiji = fk.CreateTriggerSkill{
|
|||
for _, id in ipairs(ret.cards) do
|
||||
table.removeOne(ids, id)
|
||||
end
|
||||
room:moveCardTo(ret.cards, Card.PlayerHand, room:getPlayerById(ret.targets[1]), fk.ReasonGive, self.name, nil, false, player.id)
|
||||
room:moveCardTo(ret.cards, Card.PlayerHand, room:getPlayerById(ret.targets[1]), fk.ReasonGive,
|
||||
self.name, nil, false, player.id, nil, player.id)
|
||||
if #ids == 0 then break end
|
||||
if player.dead then
|
||||
room:moveCards({
|
||||
|
@ -357,6 +354,7 @@ zhenji:addSkill(qingguo)
|
|||
|
||||
local rende = fk.CreateActiveSkill{
|
||||
name = "rende",
|
||||
prompt = "#rende-active",
|
||||
anim_type = "support",
|
||||
card_filter = function(self, to_select, selected)
|
||||
return Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
|
||||
|
@ -633,6 +631,7 @@ huangyueying:addSkill(qicai)
|
|||
|
||||
local zhiheng = fk.CreateActiveSkill{
|
||||
name = "zhiheng",
|
||||
prompt = "#zhiheng-active",
|
||||
anim_type = "drawcard",
|
||||
can_use = function(self, player)
|
||||
return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
|
||||
|
@ -737,10 +736,9 @@ lvmeng:addSkill(keji)
|
|||
|
||||
local kurou = fk.CreateActiveSkill{
|
||||
name = "kurou",
|
||||
prompt = "#kurou-active",
|
||||
anim_type = "drawcard",
|
||||
card_filter = function(self, to_select, selected, selected_targets)
|
||||
return false
|
||||
end,
|
||||
card_filter = Util.FalseFunc,
|
||||
on_use = function(self, room, effect)
|
||||
local from = room:getPlayerById(effect.from)
|
||||
room:loseHp(from, 1, self.name)
|
||||
|
@ -762,6 +760,7 @@ local yingzi = fk.CreateTriggerSkill{
|
|||
}
|
||||
local fanjian = fk.CreateActiveSkill{
|
||||
name = "fanjian",
|
||||
prompt = "#fanjian-active",
|
||||
can_use = function(self, player)
|
||||
return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
|
||||
end,
|
||||
|
@ -937,6 +936,7 @@ local xiaoji = fk.CreateTriggerSkill{
|
|||
}
|
||||
local jieyin = fk.CreateActiveSkill{
|
||||
name = "jieyin",
|
||||
prompt = "#jieyin-active",
|
||||
anim_type = "support",
|
||||
can_use = function(self, player)
|
||||
return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
|
||||
|
@ -978,6 +978,7 @@ sunshangxiang:addSkill(jieyin)
|
|||
|
||||
local qingnang = fk.CreateActiveSkill{
|
||||
name = "qingnang",
|
||||
prompt = "#qingnang-active",
|
||||
anim_type = "support",
|
||||
can_use = function(self, player)
|
||||
return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
|
||||
|
@ -993,8 +994,8 @@ local qingnang = fk.CreateActiveSkill{
|
|||
card_num = 1,
|
||||
on_use = function(self, room, effect)
|
||||
local from = room:getPlayerById(effect.from)
|
||||
room:throwCard(effect.cards, self.name, from, from)
|
||||
local to = room:getPlayerById(effect.tos[1])
|
||||
room:throwCard(effect.cards, self.name, from, from)
|
||||
if to:isAlive() and to:isWounded() then
|
||||
room:recover({
|
||||
who = to,
|
||||
|
@ -1063,6 +1064,7 @@ lvbu:addSkill(wushuang)
|
|||
|
||||
local lijian = fk.CreateActiveSkill{
|
||||
name = "lijian",
|
||||
prompt = "#lijian-active",
|
||||
anim_type = "offensive",
|
||||
can_use = function(self, player)
|
||||
return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
|
||||
|
@ -1072,7 +1074,9 @@ local lijian = fk.CreateActiveSkill{
|
|||
end,
|
||||
target_filter = function(self, to_select, selected)
|
||||
if #selected < 2 and to_select ~= Self.id then
|
||||
return Fk:currentRoom():getPlayerById(to_select):isMale()
|
||||
local target = Fk:currentRoom():getPlayerById(to_select)
|
||||
return target:isMale() and (#selected == 0 or
|
||||
target:canUseTo(Fk:cloneCard("duel"), Fk:currentRoom():getPlayerById(selected[1])))
|
||||
end
|
||||
end,
|
||||
target_num = 2,
|
||||
|
@ -1151,12 +1155,10 @@ local role_getlogic = function()
|
|||
end)
|
||||
room:returnToGeneralPile(generals)
|
||||
|
||||
room:setPlayerGeneral(lord, lord_general, true)
|
||||
room:prepareGeneral(lord, lord_general, deputy, true)
|
||||
|
||||
room:askForChooseKingdom({lord})
|
||||
room:broadcastProperty(lord, "general")
|
||||
room:broadcastProperty(lord, "kingdom")
|
||||
room:setDeputyGeneral(lord, deputy)
|
||||
room:broadcastProperty(lord, "deputyGeneral")
|
||||
|
||||
-- 显示技能
|
||||
local canAttachSkill = function(player, skillName)
|
||||
|
@ -1210,8 +1212,7 @@ local role_getlogic = function()
|
|||
end
|
||||
|
||||
local nonlord = room:getOtherPlayers(lord, true)
|
||||
local generals = room:getNGenerals(#nonlord * generalNum)
|
||||
table.shuffle(generals)
|
||||
local generals = table.random(room.general_pile, #nonlord * generalNum)
|
||||
for i, p in ipairs(nonlord) do
|
||||
local arg = table.slice(generals, (i - 1) * generalNum + 1, i * generalNum + 1)
|
||||
p.request_data = json.encode{ arg, n }
|
||||
|
@ -1221,30 +1222,22 @@ local role_getlogic = function()
|
|||
room:notifyMoveFocus(nonlord, "AskForGeneral")
|
||||
room:doBroadcastRequest("AskForGeneral", nonlord)
|
||||
|
||||
local selected = {}
|
||||
for _, p in ipairs(nonlord) do
|
||||
local general, deputy
|
||||
if p.general == "" and p.reply_ready then
|
||||
local general_ret = json.decode(p.client_reply)
|
||||
local general = general_ret[1]
|
||||
local deputy = general_ret[2]
|
||||
table.insertTableIfNeed(selected, general_ret)
|
||||
room:setPlayerGeneral(p, general, true, true)
|
||||
room:setDeputyGeneral(p, deputy)
|
||||
general = general_ret[1]
|
||||
deputy = general_ret[2]
|
||||
else
|
||||
table.insertTableIfNeed(selected, p.default_reply)
|
||||
room:setPlayerGeneral(p, p.default_reply[1], true, true)
|
||||
room:setDeputyGeneral(p, p.default_reply[2])
|
||||
general = p.default_reply[1]
|
||||
deputy = p.default_reply[2]
|
||||
end
|
||||
room:findGeneral(general)
|
||||
room:findGeneral(deputy)
|
||||
room:prepareGeneral(p, general, deputy)
|
||||
p.default_reply = ""
|
||||
end
|
||||
|
||||
generals = table.filter(generals, function(g)
|
||||
return not table.find(selected, function(lg)
|
||||
return Fk.generals[lg].trueName == Fk.generals[g].trueName
|
||||
end)
|
||||
end)
|
||||
room:returnToGeneralPile(generals)
|
||||
|
||||
room:askForChooseKingdom(nonlord)
|
||||
end
|
||||
|
||||
|
|
|
@ -52,6 +52,8 @@ Fk:loadTranslationTable({
|
|||
["method_draw"] = "draw",
|
||||
["method_discard"] = "discard",
|
||||
|
||||
["prohibit"] = " prohibit ",
|
||||
|
||||
["slash"] = "Slash",
|
||||
[":slash"] = "Slash (basic card)<br /><b>Phase</b>: Action phase<br /><b>Target</b>: Another player within your ATK range<br /><b>Effect</b>: Deal 1 DMG to the targets.<br/><b>Note</b>: You can only use 1 Slash per action phase.",
|
||||
["#slash-jink"] = "%src used Slash to you, please use a Dodge",
|
||||
|
|
|
@ -52,10 +52,12 @@ Fk:loadTranslationTable{
|
|||
["method_draw"] = "摸",
|
||||
["method_discard"] = "弃置",
|
||||
|
||||
["prohibit"] = "禁",
|
||||
|
||||
["slash"] = "杀",
|
||||
[":slash"] = "基本牌<br /><b>时机</b>:出牌阶段<br /><b>目标</b>:攻击范围内的一名角色<br /><b>效果</b>:对目标角色造成1点伤害。",
|
||||
["#slash-jink"] = "%src 对你使用了杀,请使用一张闪",
|
||||
["#slash-jink-multi"] = "%src 对你使用了杀,请使用一张闪(此为第 %arg 张,共需 %arg2 张)",
|
||||
["#slash-jink"] = "%src 对你使用了【杀】,请使用一张【闪】",
|
||||
["#slash-jink-multi"] = "%src 对你使用了【杀】,请使用一张【闪】(此为第 %arg 张,共需 %arg2 张)",
|
||||
["#slash_skill"] = "选择攻击范围内的一名角色,对其造成1点伤害",
|
||||
["#slash_skill_multi"] = "选择攻击范围内的至多%arg名角色,对这些角色各造成1点伤害",
|
||||
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 25 KiB |
|
@ -622,6 +622,7 @@ local amazingGraceSkill = fk.CreateActiveSkill{
|
|||
ids = toDisplay,
|
||||
toArea = Card.Processing,
|
||||
moveReason = fk.ReasonPut,
|
||||
proposer = use.from,
|
||||
})
|
||||
|
||||
table.forEach(room.players, function(p)
|
||||
|
@ -722,7 +723,17 @@ local lightningSkill = fk.CreateActiveSkill{
|
|||
local nextp = to
|
||||
repeat
|
||||
nextp = nextp:getNextAlive(true)
|
||||
if nextp == to then break end
|
||||
if nextp == to then
|
||||
if nextp:isProhibited(nextp, effect.card) then
|
||||
room:moveCards{
|
||||
ids = room:getSubcardsByRule(effect.card, { Card.Processing }),
|
||||
toArea = Card.DiscardPile,
|
||||
moveReason = fk.ReasonPut
|
||||
}
|
||||
return
|
||||
end
|
||||
break
|
||||
end
|
||||
until not nextp:hasDelayedTrick("lightning") and not nextp:isProhibited(nextp, effect.card)
|
||||
|
||||
|
||||
|
@ -816,10 +827,16 @@ local crossbowAudio = fk.CreateTriggerSkill{
|
|||
local crossbowSkill = fk.CreateTargetModSkill{
|
||||
name = "#crossbow_skill",
|
||||
attached_equip = "crossbow",
|
||||
bypass_times = function(self, player, skill, scope)
|
||||
if player:hasSkill(self) and skill.trueName == "slash_skill"
|
||||
and scope == Player.HistoryPhase then
|
||||
return true
|
||||
bypass_times = function(self, player, skill, scope, card)
|
||||
if player:hasSkill(self) and skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
|
||||
--FIXME: 无法检测到非转化的cost选牌的情况,如活墨等
|
||||
local cardIds = Card:getIdList(card)
|
||||
local crossbows = table.filter(player:getEquipments(Card.SubtypeWeapon), function(id)
|
||||
return Fk:getCardById(id).equip_skill == self
|
||||
end)
|
||||
return #crossbows == 0 or not table.every(crossbows, function(id)
|
||||
return table.contains(cardIds, id)
|
||||
end)
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
@ -1156,9 +1173,13 @@ local eightDiagramSkill = fk.CreateTriggerSkill{
|
|||
attached_equip = "eight_diagram",
|
||||
events = {fk.AskForCardUse, fk.AskForCardResponse},
|
||||
can_trigger = function(self, event, target, player, data)
|
||||
return target == player and player:hasSkill(self) and
|
||||
(data.cardName == "jink" or (data.pattern and Exppattern:Parse(data.pattern):matchExp("jink|0|nosuit|none"))) and
|
||||
(event == fk.AskForCardUse and not player:prohibitUse(Fk:cloneCard("jink")) or not player:prohibitResponse(Fk:cloneCard("jink")))
|
||||
if not (target == player and player:hasSkill(self) and
|
||||
(data.cardName == "jink" or (data.pattern and Exppattern:Parse(data.pattern):matchExp("jink|0|nosuit|none")))) then return end
|
||||
if event == fk.AskForCardUse then
|
||||
return not player:prohibitUse(Fk:cloneCard("jink"))
|
||||
else
|
||||
return not player:prohibitResponse(Fk:cloneCard("jink"))
|
||||
end
|
||||
end,
|
||||
on_use = function(self, event, target, player, data)
|
||||
local room = player.room
|
||||
|
|
10
sgs
Normal file
10
sgs
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"banwords": [ "习近", "近平", "共产党", "介石", "刘少奇", "邓小平", "江泽民", "胡锦涛", "毛泽东" ],
|
||||
"description": "新月杀 [0.4.15] 主力联机服务器!请素质交流、理性对局!<b>交流请去贴吧[新月杀]吧</b>",
|
||||
"iconUrl": "http://175.178.66.93/ba-freekill.png",
|
||||
"capacity": 800,
|
||||
"tempBanTime": 15,
|
||||
"motd": "6.5更新\n\n手杀测试服:司马孚、成济、SP毌丘俭、李昭焦伯;十周年(一将24获奖版初稿):宣公主、徐琨、令狐愚、司马孚\n\n6.3~6.4更新\n\nOL:界法正、蒋琬(注:暂不实现禁用手牌排序,且点击“牌序”按钮并不影响真实顺序,如不小心点击则通过点击武将上的“自若”标记查看真实顺序);十周年:韩嵩、马铁;线下:周姬、鄂焕\n\n5.31~6.1更新\n\n十周年:乐诸葛果、小孙权、乐邹氏、乐祢衡、谋张绣;\n\n\n\n请为新月杀的Github仓库点一个star吧!感谢! https://github.com/Notify-ctrl/FreeKill\n\n## 点此查看游玩教程: https://fkbook-all-in-one.readthedocs.io",
|
||||
"hiddenPacks": [],
|
||||
"enableBots": false
|
||||
}
|
|
@ -8,10 +8,14 @@ set(freekill_SRCS
|
|||
"network/server_socket.cpp"
|
||||
"network/client_socket.cpp"
|
||||
"network/router.cpp"
|
||||
"server/auth.cpp"
|
||||
"server/server.cpp"
|
||||
"server/serverplayer.cpp"
|
||||
"server/roombase.cpp"
|
||||
"server/lobby.cpp"
|
||||
"server/room.cpp"
|
||||
"server/roomthread.cpp"
|
||||
"server/scheduler.cpp"
|
||||
"ui/qmlbackend.cpp"
|
||||
"swig/freekill-wrap.cxx"
|
||||
)
|
||||
|
@ -21,7 +25,7 @@ if (NOT DEFINED FK_SERVER_ONLY)
|
|||
"client/client.cpp"
|
||||
"client/clientplayer.cpp"
|
||||
"client/replayer.cpp"
|
||||
"ui/mod.cpp"
|
||||
# "ui/mod.cpp"
|
||||
)
|
||||
endif ()
|
||||
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "client.h"
|
||||
#include "client_socket.h"
|
||||
#include "clientplayer.h"
|
||||
#include "qmlbackend.h"
|
||||
#include "util.h"
|
||||
#include "server.h"
|
||||
#include <qforeach.h>
|
||||
#include <qlogging.h>
|
||||
#include "client/client.h"
|
||||
#include "client/clientplayer.h"
|
||||
#include "ui/qmlbackend.h"
|
||||
#include "core/util.h"
|
||||
#include "server/server.h"
|
||||
#include "network/client_socket.h"
|
||||
|
||||
Client *ClientInstance = nullptr;
|
||||
ClientPlayer *Self = nullptr;
|
||||
|
|
|
@ -3,12 +3,11 @@
|
|||
#ifndef _CLIENT_H
|
||||
#define _CLIENT_H
|
||||
|
||||
#include "router.h"
|
||||
#include "clientplayer.h"
|
||||
#include <qfilesystemwatcher.h>
|
||||
#include "network/router.h"
|
||||
#include "client/clientplayer.h"
|
||||
|
||||
#ifndef FK_SERVER_ONLY
|
||||
#include "qmlbackend.h"
|
||||
#include "ui/qmlbackend.h"
|
||||
#endif
|
||||
|
||||
class Client : public QObject {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "clientplayer.h"
|
||||
#include "client/clientplayer.h"
|
||||
|
||||
ClientPlayer::ClientPlayer(int id, QObject *parent) : Player(parent) {
|
||||
setId(id);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#ifndef _CLIENTPLAYER_H
|
||||
#define _CLIENTPLAYER_H
|
||||
|
||||
#include "player.h"
|
||||
#include "core/player.h"
|
||||
|
||||
class ClientPlayer : public Player {
|
||||
Q_OBJECT
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "replayer.h"
|
||||
#include "client.h"
|
||||
#include "qmlbackend.h"
|
||||
#include "util.h"
|
||||
#include "client/replayer.h"
|
||||
#include "client/client.h"
|
||||
#include "ui/qmlbackend.h"
|
||||
#include "core/util.h"
|
||||
|
||||
Replayer::Replayer(QObject *parent, const QString &filename) :
|
||||
QThread(parent), fileName(filename), roomSettings(""), origPlayerInfo(""),
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "packman.h"
|
||||
#include "core/packman.h"
|
||||
#include "git2.h"
|
||||
#include "util.h"
|
||||
#include "qmlbackend.h"
|
||||
#include <qjsondocument.h>
|
||||
#include "core/util.h"
|
||||
#include "ui/qmlbackend.h"
|
||||
|
||||
PackMan *Pacman;
|
||||
|
||||
|
@ -70,13 +69,16 @@ void PackMan::loadSummary(const QString &jsonData, bool useThread) {
|
|||
auto obj = e.toObject();
|
||||
auto name = obj["name"].toString();
|
||||
auto url = obj["url"].toString();
|
||||
#ifndef FK_SERVER_ONLY
|
||||
Backend->showToast(tr("[%1/%2] upgrading package '%3'").arg(i).arg(arr.count()).arg(name));
|
||||
#endif
|
||||
bool toast_showed = false;
|
||||
if (SelectFromDatabase(
|
||||
db,
|
||||
QString("SELECT name FROM packages WHERE name='%1';").arg(name))
|
||||
.isEmpty()) {
|
||||
#ifndef FK_SERVER_ONLY
|
||||
Backend->showToast(tr("[%1/%2] upgrading package '%3'")
|
||||
.arg(i).arg(arr.count()).arg(name));
|
||||
toast_showed = true;
|
||||
#endif
|
||||
downloadNewPack(url);
|
||||
}
|
||||
ExecSQL(db, QString("UPDATE packages SET hash='%1' WHERE name='%2'")
|
||||
|
@ -85,6 +87,11 @@ void PackMan::loadSummary(const QString &jsonData, bool useThread) {
|
|||
enablePack(name);
|
||||
|
||||
if (head(name) != obj["hash"].toString()) {
|
||||
#ifndef FK_SERVER_ONLY
|
||||
if (!toast_showed)
|
||||
Backend->showToast(tr("[%1/%2] upgrading package '%3'")
|
||||
.arg(i).arg(arr.count()).arg(name));
|
||||
#endif
|
||||
updatePack(name);
|
||||
}
|
||||
}
|
||||
|
@ -171,7 +178,7 @@ void PackMan::updatePack(const QString &pack) {
|
|||
if (error != 0) {
|
||||
#ifndef FK_SERVER_ONLY
|
||||
if (Backend != nullptr) {
|
||||
Backend->showToast(tr("packages/%1: some error occured.").arg(pack));
|
||||
Backend->dialog("critical", tr("packages/%1: some error occured.").arg(pack));
|
||||
}
|
||||
#endif
|
||||
return;
|
||||
|
@ -193,7 +200,7 @@ void PackMan::upgradePack(const QString &pack) {
|
|||
if (error != 0) {
|
||||
#ifndef FK_SERVER_ONLY
|
||||
if (Backend != nullptr) {
|
||||
Backend->showToast(tr("packages/%1: some error occured.").arg(pack));
|
||||
Backend->showDialog("critical", tr("packages/%1: some error occured.").arg(pack));
|
||||
}
|
||||
#endif
|
||||
return;
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
#ifndef _PACKMAN_H
|
||||
#define _PACKMAN_H
|
||||
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
// 管理拓展包所需的类,本质上是libgit2接口的再封装。
|
||||
class PackMan : public QObject {
|
||||
Q_OBJECT
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "player.h"
|
||||
#include "core/player.h"
|
||||
|
||||
Player::Player(QObject *parent)
|
||||
: QObject(parent), id(0), state(Player::Invalid), totalGameTime(0), ready(false),
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "util.h"
|
||||
#include "packman.h"
|
||||
#include <qcryptographichash.h>
|
||||
#include <qnamespace.h>
|
||||
#include <qregularexpression.h>
|
||||
#include "core/util.h"
|
||||
#include "core/packman.h"
|
||||
#include <QSysInfo>
|
||||
|
||||
extern "C" {
|
||||
|
@ -172,6 +169,23 @@ static void writeDirMD5(QFile &dest, const QString &dir,
|
|||
}
|
||||
}
|
||||
|
||||
static void writeFkVerMD5(QFile &dest) {
|
||||
QFile flist("fk_ver");
|
||||
if (flist.exists() && flist.open(QIODevice::ReadOnly)) {
|
||||
flist.readLine();
|
||||
QStringList allNames;
|
||||
while (true) {
|
||||
QByteArray bytes = flist.readLine().simplified();
|
||||
if (bytes.isNull()) break;
|
||||
allNames << QString::fromLocal8Bit(bytes);
|
||||
}
|
||||
allNames.sort();
|
||||
foreach(auto s, allNames) {
|
||||
writeFileMD5(dest, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString calcFileMD5() {
|
||||
// First, generate flist.txt
|
||||
// flist.txt is a file contains all md5sum for code files
|
||||
|
@ -180,12 +194,13 @@ QString calcFileMD5() {
|
|||
qFatal("Cannot open flist.txt. Quitting.");
|
||||
}
|
||||
|
||||
writeFkVerMD5(flist);
|
||||
writeDirMD5(flist, "packages", "*.lua");
|
||||
writeDirMD5(flist, "packages", "*.qml");
|
||||
writeDirMD5(flist, "packages", "*.js");
|
||||
writeDirMD5(flist, "lua", "*.lua");
|
||||
writeDirMD5(flist, "Fk", "*.qml");
|
||||
writeDirMD5(flist, "Fk", "*.js");
|
||||
// writeDirMD5(flist, "lua", "*.lua");
|
||||
// writeDirMD5(flist, "Fk", "*.qml");
|
||||
// writeDirMD5(flist, "Fk", "*.js");
|
||||
|
||||
// then, return flist.txt's md5
|
||||
flist.close();
|
||||
|
|
20
src/main.cpp
20
src/main.cpp
|
@ -1,14 +1,14 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "client.h"
|
||||
#include "util.h"
|
||||
#include "client/client.h"
|
||||
#include "core/util.h"
|
||||
using namespace fkShell;
|
||||
|
||||
#include "packman.h"
|
||||
#include "server.h"
|
||||
#include "core/packman.h"
|
||||
#include "server/server.h"
|
||||
|
||||
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
|
||||
#include "shell.h"
|
||||
#include "server/shell.h"
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_WIN32)
|
||||
|
@ -22,7 +22,7 @@ using namespace fkShell;
|
|||
#ifndef Q_OS_ANDROID
|
||||
#include <QQuickStyle>
|
||||
#endif
|
||||
#include "qmlbackend.h"
|
||||
#include "ui/qmlbackend.h"
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_ANDROID)
|
||||
|
@ -113,10 +113,10 @@ void fkMsgHandler(QtMsgType type, const QMessageLogContext &context,
|
|||
break;
|
||||
}
|
||||
|
||||
fprintf(stderr, "\r%02d/%02d ", date.month(), date.day());
|
||||
fprintf(stderr, "%02d/%02d ", date.month(), date.day());
|
||||
fprintf(stderr, "%s ",
|
||||
QTime::currentTime().toString("hh:mm:ss").toLatin1().constData());
|
||||
fprintf(file, "\r%02d/%02d ", date.month(), date.day());
|
||||
fprintf(file, "%02d/%02d ", date.month(), date.day());
|
||||
fprintf(file, "%s ",
|
||||
QTime::currentTime().toString("hh:mm:ss").toLatin1().constData());
|
||||
|
||||
|
@ -150,8 +150,7 @@ void fkMsgHandler(QtMsgType type, const QMessageLogContext &context,
|
|||
"C", localMsg.constData());
|
||||
#ifndef FK_SERVER_ONLY
|
||||
if (Backend != nullptr) {
|
||||
Backend->notifyUI(
|
||||
"ErrorDialog",
|
||||
Backend->notifyUI("ErrorDialog",
|
||||
QString("⛔ %1/Error occured!\n %2").arg(threadName).arg(localMsg));
|
||||
}
|
||||
#endif
|
||||
|
@ -329,6 +328,7 @@ int main(int argc, char *argv[]) {
|
|||
#if defined(Q_OS_ANDROID)
|
||||
system = "Android";
|
||||
#elif defined(Q_OS_WIN32)
|
||||
qputenv("QT_MEDIA_BACKEND", "windows");
|
||||
system = "Win";
|
||||
::system("chcp 65001");
|
||||
#elif defined(Q_OS_LINUX)
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "client_socket.h"
|
||||
#include "network/client_socket.h"
|
||||
#include <openssl/aes.h>
|
||||
#include <qabstractsocket.h>
|
||||
#include <qrandom.h>
|
||||
|
||||
ClientSocket::ClientSocket() : socket(new QTcpSocket(this)) {
|
||||
aes_ready = false;
|
||||
|
@ -35,7 +33,7 @@ void ClientSocket::connectToHost(const QString &address, ushort port) {
|
|||
void ClientSocket::getMessage() {
|
||||
while (socket->canReadLine()) {
|
||||
auto msg = socket->readLine();
|
||||
msg = aesDecrypt(msg);
|
||||
msg = aesDec(msg);
|
||||
if (msg.startsWith("Compressed")) {
|
||||
msg = msg.sliced(10);
|
||||
msg = qUncompress(QByteArray::fromBase64(msg));
|
||||
|
@ -54,9 +52,9 @@ void ClientSocket::send(const QByteArray &msg) {
|
|||
if (msg.length() >= 1024) {
|
||||
auto comp = qCompress(msg);
|
||||
_msg = "Compressed" + comp.toBase64();
|
||||
_msg = aesEncrypt(_msg) + "\n";
|
||||
_msg = aesEnc(_msg) + "\n";
|
||||
} else {
|
||||
_msg = aesEncrypt(msg) + "\n";
|
||||
_msg = aesEnc(msg) + "\n";
|
||||
}
|
||||
|
||||
socket->write(_msg);
|
||||
|
@ -156,7 +154,7 @@ void ClientSocket::installAESKey(const QByteArray &key) {
|
|||
aes_ready = true;
|
||||
}
|
||||
|
||||
QByteArray ClientSocket::aesEncrypt(const QByteArray &in) {
|
||||
QByteArray ClientSocket::aesEnc(const QByteArray &in) {
|
||||
if (!aes_ready) {
|
||||
return in;
|
||||
}
|
||||
|
@ -182,7 +180,7 @@ QByteArray ClientSocket::aesEncrypt(const QByteArray &in) {
|
|||
|
||||
return iv + out.toBase64();
|
||||
}
|
||||
QByteArray ClientSocket::aesDecrypt(const QByteArray &in) {
|
||||
QByteArray ClientSocket::aesDec(const QByteArray &in) {
|
||||
if (!aes_ready) {
|
||||
return in;
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ private slots:
|
|||
void raiseError(QAbstractSocket::SocketError error);
|
||||
|
||||
private:
|
||||
QByteArray aesEncrypt(const QByteArray &in);
|
||||
QByteArray aesDecrypt(const QByteArray &out);
|
||||
QByteArray aesEnc(const QByteArray &in);
|
||||
QByteArray aesDec(const QByteArray &out);
|
||||
AES_KEY aes_key;
|
||||
bool aes_ready;
|
||||
QTcpSocket *socket;
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "router.h"
|
||||
#include "client.h"
|
||||
#include "client_socket.h"
|
||||
#include "roomthread.h"
|
||||
#include <qjsondocument.h>
|
||||
#include "server.h"
|
||||
#include "serverplayer.h"
|
||||
#include "util.h"
|
||||
#include "network/router.h"
|
||||
#include "client/client.h"
|
||||
#include "network/client_socket.h"
|
||||
#include "server/roomthread.h"
|
||||
#include "server/server.h"
|
||||
#include "server/serverplayer.h"
|
||||
#include "core/util.h"
|
||||
|
||||
Router::Router(QObject *parent, ClientSocket *socket, RouterType type)
|
||||
: QObject(parent) {
|
||||
|
@ -160,7 +159,7 @@ void Router::handlePacket(const QByteArray &rawPacket) {
|
|||
return;
|
||||
}
|
||||
|
||||
Room *room = player->getRoom();
|
||||
auto room = player->getRoom();
|
||||
room->handlePacket(player, command, jsonData);
|
||||
}
|
||||
} else if (type & TYPE_REQUEST) {
|
||||
|
@ -180,10 +179,13 @@ void Router::handlePacket(const QByteArray &rawPacket) {
|
|||
|
||||
ServerPlayer *player = qobject_cast<ServerPlayer *>(parent());
|
||||
player->setThinking(false);
|
||||
// qDebug() << "wake up!";
|
||||
auto room = player->getRoom();
|
||||
if (room->getThread()) {
|
||||
room->getThread()->wakeUp();
|
||||
auto _room = player->getRoom();
|
||||
if (!_room->isLobby()) {
|
||||
auto room = qobject_cast<Room *>(_room);
|
||||
if (room->getThread()) {
|
||||
room->getThread()->wakeUp(room->getId());
|
||||
// TODO: signal
|
||||
}
|
||||
}
|
||||
|
||||
if (requestId != this->expectedReplyId)
|
||||
|
|
|
@ -1,22 +1,57 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "server_socket.h"
|
||||
#include "client_socket.h"
|
||||
#include "network/server_socket.h"
|
||||
#include "network/client_socket.h"
|
||||
#include "server/server.h"
|
||||
#include "core/util.h"
|
||||
#include <QNetworkDatagram>
|
||||
|
||||
ServerSocket::ServerSocket() {
|
||||
ServerSocket::ServerSocket(QObject *parent) : QObject(parent) {
|
||||
server = new QTcpServer(this);
|
||||
connect(server, &QTcpServer::newConnection, this,
|
||||
&ServerSocket::processNewConnection);
|
||||
|
||||
udpSocket = new QUdpSocket(this);
|
||||
connect(udpSocket, &QUdpSocket::readyRead,
|
||||
this, &ServerSocket::readPendingDatagrams);
|
||||
}
|
||||
|
||||
bool ServerSocket::listen(const QHostAddress &address, ushort port) {
|
||||
udpSocket->bind(port);
|
||||
return server->listen(address, port);
|
||||
}
|
||||
|
||||
void ServerSocket::processNewConnection() {
|
||||
QTcpSocket *socket = server->nextPendingConnection();
|
||||
ClientSocket *connection = new ClientSocket(socket);
|
||||
connect(connection, &ClientSocket::disconnected, this,
|
||||
[connection]() { connection->deleteLater(); });
|
||||
// 这里怎么能一断连就自己删呢,应该让上层的来
|
||||
//connect(connection, &ClientSocket::disconnected, this,
|
||||
// [connection]() { connection->deleteLater(); });
|
||||
emit new_connection(connection);
|
||||
}
|
||||
|
||||
void ServerSocket::readPendingDatagrams() {
|
||||
while (udpSocket->hasPendingDatagrams()) {
|
||||
QNetworkDatagram datagram = udpSocket->receiveDatagram();
|
||||
if (datagram.isValid()) {
|
||||
processDatagram(datagram.data(), datagram.senderAddress(), datagram.senderPort());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ServerSocket::processDatagram(const QByteArray &msg, const QHostAddress &addr, uint port) {
|
||||
auto server = qobject_cast<Server *>(parent());
|
||||
if (msg == "fkDetectServer") {
|
||||
udpSocket->writeDatagram("me", addr, port);
|
||||
} else if (msg.startsWith("fkGetDetail,")) {
|
||||
udpSocket->writeDatagram(JsonArray2Bytes(QJsonArray({
|
||||
FK_VERSION,
|
||||
server->getConfig("iconUrl"),
|
||||
server->getConfig("description"),
|
||||
server->getConfig("capacity"),
|
||||
server->getPlayers().count(),
|
||||
msg.sliced(12).constData(),
|
||||
})), addr, port);
|
||||
}
|
||||
udpSocket->flush();
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ class ServerSocket : public QObject {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ServerSocket();
|
||||
ServerSocket(QObject *parent = nullptr);
|
||||
|
||||
bool listen(const QHostAddress &address = QHostAddress::Any, ushort port = 9527u);
|
||||
|
||||
|
@ -20,9 +20,12 @@ signals:
|
|||
private slots:
|
||||
// 新建一个ClientSocket,然后立刻交给Server相关函数处理。
|
||||
void processNewConnection();
|
||||
void readPendingDatagrams();
|
||||
|
||||
private:
|
||||
QTcpServer *server;
|
||||
QUdpSocket *udpSocket; // 服务器列表页面显示服务器信息用
|
||||
void processDatagram(const QByteArray &msg, const QHostAddress &addr, uint port);
|
||||
};
|
||||
|
||||
#endif // _SERVER_SOCKET_H
|
||||
|
|
196
src/server/auth.cpp
Normal file
196
src/server/auth.cpp
Normal file
|
@ -0,0 +1,196 @@
|
|||
#include "server/auth.h"
|
||||
#include "server/server.h"
|
||||
#include "server/serverplayer.h"
|
||||
#include "core/util.h"
|
||||
#include "network/client_socket.h"
|
||||
#include <openssl/bn.h>
|
||||
|
||||
AuthManager::AuthManager(QObject *parent) : QObject(parent) {
|
||||
rsa = initRSA();
|
||||
|
||||
QFile file("server/rsa_pub");
|
||||
file.open(QIODevice::ReadOnly);
|
||||
QTextStream in(&file);
|
||||
public_key = in.readAll();
|
||||
}
|
||||
|
||||
AuthManager::~AuthManager() noexcept {
|
||||
RSA_free(rsa);
|
||||
}
|
||||
|
||||
RSA *AuthManager::initRSA() {
|
||||
RSA *rsa = RSA_new();
|
||||
if (!QFile::exists("server/rsa_pub")) {
|
||||
BIGNUM *bne = BN_new();
|
||||
BN_set_word(bne, RSA_F4);
|
||||
RSA_generate_key_ex(rsa, 2048, bne, NULL);
|
||||
|
||||
BIO *bp_pub = BIO_new_file("server/rsa_pub", "w+");
|
||||
PEM_write_bio_RSAPublicKey(bp_pub, rsa);
|
||||
BIO *bp_pri = BIO_new_file("server/rsa", "w+");
|
||||
PEM_write_bio_RSAPrivateKey(bp_pri, rsa, NULL, NULL, 0, NULL, NULL);
|
||||
|
||||
BIO_free_all(bp_pub);
|
||||
BIO_free_all(bp_pri);
|
||||
QFile("server/rsa")
|
||||
.setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner);
|
||||
BN_free(bne);
|
||||
}
|
||||
FILE *keyFile = fopen("server/rsa_pub", "r");
|
||||
PEM_read_RSAPublicKey(keyFile, &rsa, NULL, NULL);
|
||||
fclose(keyFile);
|
||||
keyFile = fopen("server/rsa", "r");
|
||||
PEM_read_RSAPrivateKey(keyFile, &rsa, NULL, NULL);
|
||||
fclose(keyFile);
|
||||
return rsa;
|
||||
}
|
||||
|
||||
bool AuthManager::checkClientVersion(ClientSocket *client, const QString &cver) {
|
||||
auto server = qobject_cast<Server *>(parent());
|
||||
auto client_ver = QVersionNumber::fromString(cver);
|
||||
auto ver = QVersionNumber::fromString(FK_VERSION);
|
||||
int cmp = QVersionNumber::compare(ver, client_ver);
|
||||
if (cmp != 0) {
|
||||
auto errmsg = QString();
|
||||
if (cmp < 0) {
|
||||
errmsg = QString("[\"server is still on version %%2\",\"%1\"]")
|
||||
.arg(FK_VERSION, "1");
|
||||
} else {
|
||||
errmsg = QString("[\"server is using version %%2, please update\",\"%1\"]")
|
||||
.arg(FK_VERSION, "1");
|
||||
}
|
||||
|
||||
server->sendEarlyPacket(client, "ErrorDlg", errmsg);
|
||||
client->disconnectFromHost();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QJsonObject AuthManager::queryUserInfo(ClientSocket *client, const QString &name,
|
||||
const QByteArray &password) {
|
||||
auto server = qobject_cast<Server *>(parent());
|
||||
auto db = server->getDatabase();
|
||||
auto pw = password;
|
||||
|
||||
auto sql_find = QString("SELECT * FROM userinfo WHERE name='%1';")
|
||||
.arg(name);
|
||||
|
||||
auto result = SelectFromDatabase(db, sql_find);
|
||||
if (result.isEmpty()) {
|
||||
auto salt_gen = QRandomGenerator::securelySeeded();
|
||||
auto salt = QByteArray::number(salt_gen(), 16);
|
||||
pw.append(salt);
|
||||
auto passwordHash =
|
||||
QCryptographicHash::hash(pw, QCryptographicHash::Sha256).toHex();
|
||||
|
||||
auto sql_reg = QString("INSERT INTO userinfo (name,password,salt,\
|
||||
avatar,lastLoginIp,banned) VALUES ('%1','%2','%3','%4','%5',%6);")
|
||||
.arg(name).arg(QString(passwordHash))
|
||||
.arg(salt).arg("liubei").arg(client->peerAddress())
|
||||
.arg("FALSE");
|
||||
|
||||
ExecSQL(db, sql_reg);
|
||||
result = SelectFromDatabase(db, sql_find); // refresh result
|
||||
auto obj = result[0].toObject();
|
||||
|
||||
auto info_update = QString("INSERT INTO usergameinfo (id, registerTime) VALUES (%1, %2);").arg(obj["id"].toString().toInt()).arg(QDateTime::currentSecsSinceEpoch());
|
||||
ExecSQL(db, info_update);
|
||||
}
|
||||
|
||||
return result[0].toObject();
|
||||
}
|
||||
|
||||
QJsonObject AuthManager::checkPassword(ClientSocket *client, const QString &name,
|
||||
const QString &password) {
|
||||
|
||||
auto server = qobject_cast<Server *>(parent());
|
||||
bool passed = false;
|
||||
QString error_msg;
|
||||
QJsonObject obj;
|
||||
int id;
|
||||
QByteArray salt;
|
||||
QByteArray passwordHash;
|
||||
auto players = server->getPlayers();
|
||||
|
||||
auto encryted_pw = QByteArray::fromBase64(password.toLatin1());
|
||||
unsigned char buf[4096] = {0};
|
||||
RSA_private_decrypt(RSA_size(rsa), (const unsigned char *)encryted_pw.data(),
|
||||
buf, rsa, RSA_PKCS1_PADDING);
|
||||
auto decrypted_pw =
|
||||
QByteArray::fromRawData((const char *)buf, strlen((const char *)buf));
|
||||
|
||||
if (decrypted_pw.length() > 32) {
|
||||
auto aes_bytes = decrypted_pw.first(32);
|
||||
|
||||
// tell client to install aes key
|
||||
server->sendEarlyPacket(client, "InstallKey", "");
|
||||
client->installAESKey(aes_bytes);
|
||||
decrypted_pw.remove(0, 32);
|
||||
} else {
|
||||
// FIXME
|
||||
// decrypted_pw = "\xFF";
|
||||
error_msg = "unknown password error";
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
if (!CheckSqlString(name) || !server->checkBanWord(name)) {
|
||||
error_msg = "invalid user name";
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
if (server->getConfig("whitelist").isArray() &&
|
||||
!server->getConfig("whitelist").toArray().toVariantList().contains(name)) {
|
||||
error_msg = "user name not in whitelist";
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
obj = queryUserInfo(client, name, decrypted_pw);
|
||||
|
||||
// check ban account
|
||||
id = obj["id"].toString().toInt();
|
||||
passed = obj["banned"].toString().toInt() == 0;
|
||||
if (!passed) {
|
||||
error_msg = "you have been banned!";
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
// check if password is the same
|
||||
salt = obj["salt"].toString().toLatin1();
|
||||
decrypted_pw.append(salt);
|
||||
passwordHash =
|
||||
QCryptographicHash::hash(decrypted_pw, QCryptographicHash::Sha256).toHex();
|
||||
passed = (passwordHash == obj["password"].toString());
|
||||
if (!passed) {
|
||||
error_msg = "username or password error";
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
if (players.value(id)) {
|
||||
auto player = players.value(id);
|
||||
// 顶号机制,如果在线的话就让他变成不在线
|
||||
if (player->getState() == Player::Online || player->getState() == Player::Robot) {
|
||||
player->doNotify("ErrorDlg", "others logged in again with this name");
|
||||
emit player->kicked();
|
||||
}
|
||||
|
||||
if (player->getState() == Player::Offline) {
|
||||
player->reconnect(client);
|
||||
passed = true;
|
||||
return QJsonObject();
|
||||
} else {
|
||||
error_msg = "others logged in with this name";
|
||||
passed = false;
|
||||
}
|
||||
}
|
||||
|
||||
FAIL:
|
||||
if (!passed) {
|
||||
qInfo() << client->peerAddress() << "lost connection:" << error_msg;
|
||||
server->sendEarlyPacket(client, "ErrorDlg", error_msg);
|
||||
client->disconnectFromHost();
|
||||
return QJsonObject();
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
27
src/server/auth.h
Normal file
27
src/server/auth.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
#ifndef _AUTH_H
|
||||
#define _AUTH_H
|
||||
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/pem.h>
|
||||
|
||||
class ClientSocket;
|
||||
|
||||
class AuthManager : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
AuthManager(QObject *parent = nullptr);
|
||||
~AuthManager() noexcept;
|
||||
auto getPublicKey() const { return public_key; }
|
||||
|
||||
bool checkClientVersion(ClientSocket *client, const QString &ver);
|
||||
QJsonObject checkPassword(ClientSocket *client, const QString &name, const QString &password);
|
||||
|
||||
private:
|
||||
RSA *rsa;
|
||||
QString public_key;
|
||||
|
||||
static RSA *initRSA();
|
||||
QJsonObject queryUserInfo(ClientSocket *client, const QString &name, const QByteArray &password);
|
||||
};
|
||||
|
||||
#endif // _AUTH_H
|
162
src/server/lobby.cpp
Normal file
162
src/server/lobby.cpp
Normal file
|
@ -0,0 +1,162 @@
|
|||
#include "server/lobby.h"
|
||||
#include "server/server.h"
|
||||
#include "server/serverplayer.h"
|
||||
#include "core/util.h"
|
||||
|
||||
Lobby::Lobby(Server *server) {
|
||||
this->server = server;
|
||||
setParent(server);
|
||||
}
|
||||
|
||||
void Lobby::addPlayer(ServerPlayer *player) {
|
||||
if (!player) return;
|
||||
|
||||
players.append(player);
|
||||
player->setRoom(this);
|
||||
|
||||
if (player->getState() == Player::Robot) {
|
||||
removePlayer(player);
|
||||
player->deleteLater();
|
||||
} else {
|
||||
player->doNotify("EnterLobby", "[]");
|
||||
}
|
||||
|
||||
server->updateOnlineInfo();
|
||||
}
|
||||
|
||||
void Lobby::removePlayer(ServerPlayer *player) {
|
||||
players.removeOne(player);
|
||||
server->updateOnlineInfo();
|
||||
}
|
||||
|
||||
void Lobby::updateAvatar(ServerPlayer *sender, const QString &jsonData) {
|
||||
auto arr = String2Json(jsonData).array();
|
||||
auto avatar = arr[0].toString();
|
||||
|
||||
if (CheckSqlString(avatar)) {
|
||||
auto sql = QString("UPDATE userinfo SET avatar='%1' WHERE id=%2;")
|
||||
.arg(avatar)
|
||||
.arg(sender->getId());
|
||||
ExecSQL(ServerInstance->getDatabase(), sql);
|
||||
sender->setAvatar(avatar);
|
||||
sender->doNotify("UpdateAvatar", avatar);
|
||||
}
|
||||
}
|
||||
|
||||
void Lobby::updatePassword(ServerPlayer *sender, const QString &jsonData) {
|
||||
auto arr = String2Json(jsonData).array();
|
||||
auto oldpw = arr[0].toString();
|
||||
auto newpw = arr[1].toString();
|
||||
auto sql_find =
|
||||
QString("SELECT password, salt FROM userinfo WHERE id=%1;")
|
||||
.arg(sender->getId());
|
||||
|
||||
auto passed = false;
|
||||
auto arr2 = SelectFromDatabase(ServerInstance->getDatabase(), sql_find);
|
||||
auto result = arr2[0].toObject();
|
||||
passed = (result["password"].toString() ==
|
||||
QCryptographicHash::hash(
|
||||
oldpw.append(result["salt"].toString()).toLatin1(),
|
||||
QCryptographicHash::Sha256)
|
||||
.toHex());
|
||||
if (passed) {
|
||||
auto sql_update =
|
||||
QString("UPDATE userinfo SET password='%1' WHERE id=%2;")
|
||||
.arg(QCryptographicHash::hash(
|
||||
newpw.append(result["salt"].toString()).toLatin1(),
|
||||
QCryptographicHash::Sha256)
|
||||
.toHex())
|
||||
.arg(sender->getId());
|
||||
ExecSQL(ServerInstance->getDatabase(), sql_update);
|
||||
}
|
||||
|
||||
sender->doNotify("UpdatePassword", passed ? "1" : "0");
|
||||
}
|
||||
|
||||
void Lobby::createRoom(ServerPlayer *sender, const QString &jsonData) {
|
||||
auto arr = String2Json(jsonData).array();
|
||||
auto name = arr[0].toString();
|
||||
auto capacity = arr[1].toInt();
|
||||
auto timeout = arr[2].toInt();
|
||||
auto settings =
|
||||
QJsonDocument(arr[3].toObject()).toJson(QJsonDocument::Compact);
|
||||
ServerInstance->createRoom(sender, name, capacity, timeout, settings);
|
||||
}
|
||||
|
||||
void Lobby::getRoomConfig(ServerPlayer *sender, const QString &jsonData) {
|
||||
auto arr = String2Json(jsonData).array();
|
||||
auto roomId = arr[0].toInt();
|
||||
auto room = ServerInstance->findRoom(roomId);
|
||||
if (room) {
|
||||
auto settings = room->getSettings();
|
||||
// 手搓JSON数组 跳过编码解码
|
||||
sender->doNotify("GetRoomConfig", QString("[%1,%2]").arg(roomId).arg(settings));
|
||||
} else {
|
||||
sender->doNotify("ErrorMsg", "no such room");
|
||||
}
|
||||
}
|
||||
|
||||
void Lobby::enterRoom(ServerPlayer *sender, const QString &jsonData) {
|
||||
auto arr = String2Json(jsonData).array();
|
||||
auto roomId = arr[0].toInt();
|
||||
auto room = ServerInstance->findRoom(roomId);
|
||||
if (room) {
|
||||
auto settings = QJsonDocument::fromJson(room->getSettings());
|
||||
auto password = settings["password"].toString();
|
||||
if (password.isEmpty() || arr[1].toString() == password) {
|
||||
if (room->isOutdated()) {
|
||||
sender->doNotify("ErrorMsg", "room is outdated");
|
||||
} else {
|
||||
room->addPlayer(sender);
|
||||
}
|
||||
} else {
|
||||
sender->doNotify("ErrorMsg", "room password error");
|
||||
}
|
||||
} else {
|
||||
sender->doNotify("ErrorMsg", "no such room");
|
||||
}
|
||||
}
|
||||
|
||||
void Lobby::observeRoom(ServerPlayer *sender, const QString &jsonData) {
|
||||
auto arr = String2Json(jsonData).array();
|
||||
auto roomId = arr[0].toInt();
|
||||
auto room = ServerInstance->findRoom(roomId);
|
||||
if (room) {
|
||||
auto settings = QJsonDocument::fromJson(room->getSettings());
|
||||
auto password = settings["password"].toString();
|
||||
if (password.isEmpty() || arr[1].toString() == password) {
|
||||
if (room->isOutdated()) {
|
||||
sender->doNotify("ErrorMsg", "room is outdated");
|
||||
} else {
|
||||
room->addObserver(sender);
|
||||
}
|
||||
} else {
|
||||
sender->doNotify("ErrorMsg", "room password error");
|
||||
}
|
||||
} else {
|
||||
sender->doNotify("ErrorMsg", "no such room");
|
||||
}
|
||||
}
|
||||
|
||||
void Lobby::refreshRoomList(ServerPlayer *sender, const QString &) {
|
||||
ServerInstance->updateRoomList(sender);
|
||||
};
|
||||
|
||||
typedef void (Lobby::*room_cb)(ServerPlayer *, const QString &);
|
||||
|
||||
void Lobby::handlePacket(ServerPlayer *sender, const QString &command,
|
||||
const QString &jsonData) {
|
||||
static const QMap<QString, room_cb> lobby_actions = {
|
||||
{"UpdateAvatar", &Lobby::updateAvatar},
|
||||
{"UpdatePassword", &Lobby::updatePassword},
|
||||
{"CreateRoom", &Lobby::createRoom},
|
||||
{"GetRoomConfig", &Lobby::getRoomConfig},
|
||||
{"EnterRoom", &Lobby::enterRoom},
|
||||
{"ObserveRoom", &Lobby::observeRoom},
|
||||
{"RefreshRoomList", &Lobby::refreshRoomList},
|
||||
{"Chat", &Lobby::chat},
|
||||
};
|
||||
|
||||
auto func = lobby_actions[command];
|
||||
if (func) (this->*func)(sender, jsonData);
|
||||
}
|
27
src/server/lobby.h
Normal file
27
src/server/lobby.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
#ifndef _LOBBY_H
|
||||
#define _LOBBY_H
|
||||
|
||||
#include "server/roombase.h"
|
||||
|
||||
class Lobby : public RoomBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Lobby(Server *server);
|
||||
|
||||
void addPlayer(ServerPlayer *player);
|
||||
void removePlayer(ServerPlayer *player);
|
||||
|
||||
void handlePacket(ServerPlayer *sender, const QString &command,
|
||||
const QString &jsonData);
|
||||
private:
|
||||
// for handle packet
|
||||
void updateAvatar(ServerPlayer *, const QString &);
|
||||
void updatePassword(ServerPlayer *, const QString &);
|
||||
void createRoom(ServerPlayer *, const QString &);
|
||||
void getRoomConfig(ServerPlayer *, const QString &);
|
||||
void enterRoom(ServerPlayer *, const QString &);
|
||||
void observeRoom(ServerPlayer *, const QString &);
|
||||
void refreshRoomList(ServerPlayer *, const QString &);
|
||||
};
|
||||
|
||||
#endif // _LOBBY_H
|
|
@ -1,28 +1,25 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "room.h"
|
||||
|
||||
#include <qjsonarray.h>
|
||||
#include <qjsondocument.h>
|
||||
#include "server/room.h"
|
||||
#include "server/lobby.h"
|
||||
|
||||
#ifdef FK_SERVER_ONLY
|
||||
static void *ClientInstance = nullptr;
|
||||
#else
|
||||
#include "client.h"
|
||||
#include "client/client.h"
|
||||
#endif
|
||||
|
||||
#include "client_socket.h"
|
||||
#include "roomthread.h"
|
||||
#include "server.h"
|
||||
#include "serverplayer.h"
|
||||
#include "util.h"
|
||||
#include "network/client_socket.h"
|
||||
#include "server/roomthread.h"
|
||||
#include "server/server.h"
|
||||
#include "server/serverplayer.h"
|
||||
#include "core/util.h"
|
||||
|
||||
Room::Room(RoomThread *m_thread) {
|
||||
auto server = ServerInstance;
|
||||
id = server->nextRoomId;
|
||||
server->nextRoomId++;
|
||||
this->server = server;
|
||||
setThread(m_thread);
|
||||
if (m_thread) { // In case of lobby
|
||||
m_thread->addRoom(this);
|
||||
}
|
||||
|
@ -36,14 +33,8 @@ Room::Room(RoomThread *m_thread) {
|
|||
|
||||
m_ready = true;
|
||||
|
||||
// 如果是普通房间而不是大厅,就初始化Lua,否则置Lua为nullptr
|
||||
if (!isLobby()) {
|
||||
// 如果不是大厅,那么:
|
||||
// * 只要房间添加人了,那么从大厅中移掉这个人
|
||||
// * 只要有人离开房间,那就把他加到大厅去
|
||||
connect(this, &Room::playerAdded, server->lobby(), &Room::removePlayer);
|
||||
connect(this, &Room::playerRemoved, server->lobby(), &Room::addPlayer);
|
||||
}
|
||||
connect(this, &Room::playerAdded, server->lobby(), &Lobby::removePlayer);
|
||||
connect(this, &Room::playerRemoved, server->lobby(), &Lobby::addPlayer);
|
||||
}
|
||||
|
||||
Room::~Room() {
|
||||
|
@ -56,8 +47,6 @@ Room::~Room() {
|
|||
}
|
||||
}
|
||||
|
||||
Server *Room::getServer() const { return server; }
|
||||
|
||||
RoomThread *Room::getThread() const { return m_thread; }
|
||||
|
||||
void Room::setThread(RoomThread *t) {
|
||||
|
@ -71,8 +60,6 @@ int Room::getId() const { return id; }
|
|||
|
||||
void Room::setId(int id) { this->id = id; }
|
||||
|
||||
bool Room::isLobby() const { return id == 0; }
|
||||
|
||||
QString Room::getName() const { return name; }
|
||||
|
||||
void Room::setName(const QString &name) { this->name = name; }
|
||||
|
@ -88,9 +75,6 @@ const QByteArray Room::getSettings() const { return settings; }
|
|||
void Room::setSettings(QByteArray settings) { this->settings = settings; }
|
||||
|
||||
bool Room::isAbandoned() const {
|
||||
if (isLobby())
|
||||
return false;
|
||||
|
||||
if (players.isEmpty())
|
||||
return true;
|
||||
|
||||
|
@ -151,72 +135,60 @@ void Room::addPlayer(ServerPlayer *player) {
|
|||
auto mode = settings["gameMode"].toString();
|
||||
|
||||
// 告诉房里所有玩家有新人进来了
|
||||
if (!isLobby()) {
|
||||
jsonData << player->getId();
|
||||
jsonData << player->getScreenName();
|
||||
jsonData << player->getAvatar();
|
||||
jsonData << player->isReady();
|
||||
jsonData << player->getTotalGameTime();
|
||||
doBroadcastNotify(getPlayers(), "AddPlayer", JsonArray2Bytes(jsonData));
|
||||
}
|
||||
jsonData << player->getId();
|
||||
jsonData << player->getScreenName();
|
||||
jsonData << player->getAvatar();
|
||||
jsonData << player->isReady();
|
||||
jsonData << player->getTotalGameTime();
|
||||
doBroadcastNotify(getPlayers(), "AddPlayer", JsonArray2Bytes(jsonData));
|
||||
|
||||
players.append(player);
|
||||
player->setRoom(this);
|
||||
|
||||
if (isLobby()) {
|
||||
// 有机器人进入大厅(可能因为被踢),那么改为销毁
|
||||
if (player->getState() == Player::Robot) {
|
||||
removePlayer(player);
|
||||
player->deleteLater();
|
||||
} else {
|
||||
player->doNotify("EnterLobby", "[]");
|
||||
}
|
||||
} else {
|
||||
// Second, let the player enter room and add other players
|
||||
// Second, let the player enter room and add other players
|
||||
jsonData = QJsonArray();
|
||||
jsonData << this->capacity;
|
||||
jsonData << this->timeout;
|
||||
jsonData << QJsonDocument::fromJson(this->settings).object();
|
||||
player->doNotify("EnterRoom", JsonArray2Bytes(jsonData));
|
||||
|
||||
foreach (ServerPlayer *p, getOtherPlayers(player)) {
|
||||
jsonData = QJsonArray();
|
||||
jsonData << this->capacity;
|
||||
jsonData << this->timeout;
|
||||
jsonData << QJsonDocument::fromJson(this->settings).object();
|
||||
player->doNotify("EnterRoom", JsonArray2Bytes(jsonData));
|
||||
jsonData << p->getId();
|
||||
jsonData << p->getScreenName();
|
||||
jsonData << p->getAvatar();
|
||||
jsonData << p->isReady();
|
||||
jsonData << p->getTotalGameTime();
|
||||
player->doNotify("AddPlayer", JsonArray2Bytes(jsonData));
|
||||
|
||||
foreach (ServerPlayer *p, getOtherPlayers(player)) {
|
||||
jsonData = QJsonArray();
|
||||
jsonData << p->getId();
|
||||
jsonData << p->getScreenName();
|
||||
jsonData << p->getAvatar();
|
||||
jsonData << p->isReady();
|
||||
jsonData << p->getTotalGameTime();
|
||||
player->doNotify("AddPlayer", JsonArray2Bytes(jsonData));
|
||||
|
||||
jsonData = QJsonArray();
|
||||
jsonData << p->getId();
|
||||
foreach (int i, p->getGameData()) {
|
||||
jsonData << i;
|
||||
}
|
||||
player->doNotify("UpdateGameData", JsonArray2Bytes(jsonData));
|
||||
jsonData = QJsonArray();
|
||||
jsonData << p->getId();
|
||||
foreach (int i, p->getGameData()) {
|
||||
jsonData << i;
|
||||
}
|
||||
|
||||
if (this->owner != nullptr) {
|
||||
jsonData = QJsonArray();
|
||||
jsonData << this->owner->getId();
|
||||
player->doNotify("RoomOwner", JsonArray2Bytes(jsonData));
|
||||
}
|
||||
|
||||
if (player->getLastGameMode() != mode) {
|
||||
player->setLastGameMode(mode);
|
||||
updatePlayerGameData(player->getId(), mode);
|
||||
} else {
|
||||
auto jsonData = QJsonArray();
|
||||
jsonData << player->getId();
|
||||
foreach (int i, player->getGameData()) {
|
||||
jsonData << i;
|
||||
}
|
||||
doBroadcastNotify(getPlayers(), "UpdateGameData", JsonArray2Bytes(jsonData));
|
||||
}
|
||||
// 玩家手动启动
|
||||
// if (isFull() && !gameStarted)
|
||||
// start();
|
||||
player->doNotify("UpdateGameData", JsonArray2Bytes(jsonData));
|
||||
}
|
||||
|
||||
if (this->owner != nullptr) {
|
||||
jsonData = QJsonArray();
|
||||
jsonData << this->owner->getId();
|
||||
player->doNotify("RoomOwner", JsonArray2Bytes(jsonData));
|
||||
}
|
||||
|
||||
if (player->getLastGameMode() != mode) {
|
||||
player->setLastGameMode(mode);
|
||||
updatePlayerGameData(player->getId(), mode);
|
||||
} else {
|
||||
auto jsonData = QJsonArray();
|
||||
jsonData << player->getId();
|
||||
foreach (int i, player->getGameData()) {
|
||||
jsonData << i;
|
||||
}
|
||||
doBroadcastNotify(getPlayers(), "UpdateGameData", JsonArray2Bytes(jsonData));
|
||||
}
|
||||
// 玩家手动启动
|
||||
// if (isFull() && !gameStarted)
|
||||
// start();
|
||||
emit playerAdded(player);
|
||||
}
|
||||
|
||||
|
@ -251,12 +223,7 @@ void Room::removePlayer(ServerPlayer *player) {
|
|||
}
|
||||
emit playerRemoved(player);
|
||||
|
||||
if (isLobby())
|
||||
return;
|
||||
|
||||
QJsonArray jsonData;
|
||||
jsonData << player->getId();
|
||||
doBroadcastNotify(getPlayers(), "RemovePlayer", JsonArray2Bytes(jsonData));
|
||||
doBroadcastNotify(getPlayers(), "RemovePlayer", JsonArray2Bytes({ player->getId() }));
|
||||
} else {
|
||||
// 否则给跑路玩家召唤个AI代打
|
||||
// TODO: if the player is died..
|
||||
|
@ -273,9 +240,6 @@ void Room::removePlayer(ServerPlayer *player) {
|
|||
// 然后基于跑路玩家的socket,创建一个新ServerPlayer对象用来通信
|
||||
ServerPlayer *runner = new ServerPlayer(this);
|
||||
runner->setSocket(socket);
|
||||
connect(runner, &ServerPlayer::disconnected, server,
|
||||
&Server::onUserDisconnected);
|
||||
connect(runner, &Player::stateChanged, server, &Server::onUserStateChanged);
|
||||
runner->setScreenName(player->getScreenName());
|
||||
runner->setAvatar(player->getAvatar());
|
||||
runner->setId(player->getId());
|
||||
|
@ -287,7 +251,7 @@ void Room::removePlayer(ServerPlayer *player) {
|
|||
// 原先的跑路机器人会在游戏结束后自动销毁掉
|
||||
server->addPlayer(runner);
|
||||
|
||||
m_thread->wakeUp();
|
||||
// m_thread->wakeUp();
|
||||
|
||||
// 发出信号,让大厅添加这个人
|
||||
emit playerRemoved(runner);
|
||||
|
@ -312,22 +276,6 @@ void Room::removePlayer(ServerPlayer *player) {
|
|||
}
|
||||
}
|
||||
|
||||
QList<ServerPlayer *> Room::getPlayers() const { return players; }
|
||||
|
||||
QList<ServerPlayer *> Room::getOtherPlayers(ServerPlayer *expect) const {
|
||||
QList<ServerPlayer *> others = getPlayers();
|
||||
others.removeOne(expect);
|
||||
return others;
|
||||
}
|
||||
|
||||
ServerPlayer *Room::findPlayer(int id) const {
|
||||
foreach (ServerPlayer *p, players) {
|
||||
if (p->getId() == id)
|
||||
return p;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Room::addObserver(ServerPlayer *player) {
|
||||
// 首先只能旁观在运行的房间,因为旁观是由Lua处理的
|
||||
if (!gameStarted) {
|
||||
|
@ -371,6 +319,10 @@ int Room::getTimeout() const { return timeout; }
|
|||
|
||||
void Room::setTimeout(int timeout) { this->timeout = timeout; }
|
||||
|
||||
void Room::delay(int ms) {
|
||||
m_thread->delay(id, ms);
|
||||
}
|
||||
|
||||
bool Room::isOutdated() {
|
||||
bool ret = md5 != server->getMd5();
|
||||
if (ret) md5 = "";
|
||||
|
@ -379,42 +331,6 @@ bool Room::isOutdated() {
|
|||
|
||||
bool Room::isStarted() const { return gameStarted; }
|
||||
|
||||
void Room::doBroadcastNotify(const QList<ServerPlayer *> targets,
|
||||
const QString &command, const QString &jsonData) {
|
||||
foreach (ServerPlayer *p, targets) {
|
||||
p->doNotify(command, jsonData);
|
||||
}
|
||||
}
|
||||
|
||||
void Room::chat(ServerPlayer *sender, const QString &jsonData) {
|
||||
auto doc = String2Json(jsonData).object();
|
||||
auto type = doc["type"].toInt();
|
||||
doc["sender"] = sender->getId();
|
||||
|
||||
// 屏蔽.号,防止有人在HTML文本发链接,而正常发链接看不出来有啥改动
|
||||
auto msg = doc["msg"].toString();
|
||||
msg.replace(".", "․");
|
||||
// 300字限制,与客户端相同
|
||||
msg.erase(msg.begin() + 300, msg.end());
|
||||
doc["msg"] = msg;
|
||||
if (!server->checkBanWord(msg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == 1) {
|
||||
doc["userName"] = sender->getScreenName();
|
||||
auto json = QJsonDocument(doc).toJson(QJsonDocument::Compact);
|
||||
doBroadcastNotify(players, "Chat", json);
|
||||
} else {
|
||||
auto json = QJsonDocument(doc).toJson(QJsonDocument::Compact);
|
||||
doBroadcastNotify(players, "Chat", json);
|
||||
doBroadcastNotify(observers, "Chat", json);
|
||||
}
|
||||
|
||||
qInfo("[Chat] %s: %s", sender->getScreenName().toUtf8().constData(),
|
||||
doc["msg"].toString().toUtf8().constData());
|
||||
}
|
||||
|
||||
static const QString findWinRate =
|
||||
QString("SELECT win, lose, draw "
|
||||
"FROM winRate WHERE id = %1 and general = '%2' and mode = '%3';");
|
||||
|
@ -551,18 +467,18 @@ void Room::updatePlayerGameData(int id, const QString &mode) {
|
|||
auto room = player->getRoom();
|
||||
player->setGameData(total, win, run);
|
||||
auto data_arr = QJsonArray({ player->getId(), total, win, run });
|
||||
if (!room->isLobby()) {
|
||||
room->doBroadcastNotify(room->getPlayers(), "UpdateGameData", JsonArray2Bytes(data_arr));
|
||||
}
|
||||
room->doBroadcastNotify(room->getPlayers(), "UpdateGameData", JsonArray2Bytes(data_arr));
|
||||
}
|
||||
|
||||
void Room::gameOver() {
|
||||
if (!gameStarted) return;
|
||||
insideGameOver = true;
|
||||
gameStarted = false;
|
||||
runned_players.clear();
|
||||
// 清理所有状态不是“在线”的玩家,增加逃率、游戏时长
|
||||
auto settings = QJsonDocument::fromJson(this->settings);
|
||||
auto mode = settings["gameMode"].toString();
|
||||
server->beginTransaction();
|
||||
foreach (ServerPlayer *p, players) {
|
||||
auto pid = p->getId();
|
||||
|
||||
|
@ -578,7 +494,7 @@ void Room::gameOver() {
|
|||
realPlayer->doNotify("AddTotalGameTime", bytes);
|
||||
}
|
||||
|
||||
// 摸了,这么写总之不会有问题
|
||||
// 将游戏时间更新到数据库中
|
||||
auto info_update = QString("UPDATE usergameinfo SET totalGameTime = "
|
||||
"IIF(totalGameTime IS NULL, %2, totalGameTime + %2) WHERE id = %1;").arg(pid).arg(time);
|
||||
ExecSQL(server->getDatabase(), info_update);
|
||||
|
@ -587,18 +503,13 @@ void Room::gameOver() {
|
|||
if (p->getState() != Player::Online) {
|
||||
if (p->getState() == Player::Offline) {
|
||||
addRunRate(pid, mode);
|
||||
// addRunRate(pid, mode);
|
||||
server->temporarilyBan(pid);
|
||||
}
|
||||
p->deleteLater();
|
||||
}
|
||||
}
|
||||
// 旁观者不能在这清除,因为removePlayer逻辑不一样
|
||||
// observers.clear();
|
||||
// 玩家也不能在这里清除,因为要能返回原来房间继续玩呢
|
||||
// players.clear();
|
||||
// owner = nullptr;
|
||||
// clearRequest();
|
||||
server->endTransaction();
|
||||
insideGameOver = false;
|
||||
}
|
||||
|
||||
void Room::manuallyStart() {
|
||||
|
@ -620,7 +531,6 @@ void Room::pushRequest(const QString &req) {
|
|||
}
|
||||
|
||||
void Room::addRejectId(int id) {
|
||||
if (isLobby()) return;
|
||||
rejected_players << id;
|
||||
}
|
||||
|
||||
|
@ -629,184 +539,84 @@ void Room::removeRejectId(int id) {
|
|||
}
|
||||
|
||||
// ------------------------------------------------
|
||||
static void updateAvatar(ServerPlayer *sender, const QString &jsonData) {
|
||||
auto arr = String2Json(jsonData).array();
|
||||
auto avatar = arr[0].toString();
|
||||
|
||||
if (CheckSqlString(avatar)) {
|
||||
auto sql = QString("UPDATE userinfo SET avatar='%1' WHERE id=%2;")
|
||||
.arg(avatar)
|
||||
.arg(sender->getId());
|
||||
ExecSQL(ServerInstance->getDatabase(), sql);
|
||||
sender->setAvatar(avatar);
|
||||
sender->doNotify("UpdateAvatar", avatar);
|
||||
}
|
||||
}
|
||||
|
||||
static void updatePassword(ServerPlayer *sender, const QString &jsonData) {
|
||||
auto arr = String2Json(jsonData).array();
|
||||
auto oldpw = arr[0].toString();
|
||||
auto newpw = arr[1].toString();
|
||||
auto sql_find =
|
||||
QString("SELECT password, salt FROM userinfo WHERE id=%1;")
|
||||
.arg(sender->getId());
|
||||
|
||||
auto passed = false;
|
||||
auto arr2 = SelectFromDatabase(ServerInstance->getDatabase(), sql_find);
|
||||
auto result = arr2[0].toObject();
|
||||
passed = (result["password"].toString() ==
|
||||
QCryptographicHash::hash(
|
||||
oldpw.append(result["salt"].toString()).toLatin1(),
|
||||
QCryptographicHash::Sha256)
|
||||
.toHex());
|
||||
if (passed) {
|
||||
auto sql_update =
|
||||
QString("UPDATE userinfo SET password='%1' WHERE id=%2;")
|
||||
.arg(QCryptographicHash::hash(
|
||||
newpw.append(result["salt"].toString()).toLatin1(),
|
||||
QCryptographicHash::Sha256)
|
||||
.toHex())
|
||||
.arg(sender->getId());
|
||||
ExecSQL(ServerInstance->getDatabase(), sql_update);
|
||||
}
|
||||
|
||||
sender->doNotify("UpdatePassword", passed ? "1" : "0");
|
||||
}
|
||||
|
||||
static void createRoom(ServerPlayer *sender, const QString &jsonData) {
|
||||
auto arr = String2Json(jsonData).array();
|
||||
auto name = arr[0].toString();
|
||||
auto capacity = arr[1].toInt();
|
||||
auto timeout = arr[2].toInt();
|
||||
auto settings =
|
||||
QJsonDocument(arr[3].toObject()).toJson(QJsonDocument::Compact);
|
||||
ServerInstance->createRoom(sender, name, capacity, timeout, settings);
|
||||
}
|
||||
|
||||
static void enterRoom(ServerPlayer *sender, const QString &jsonData) {
|
||||
auto arr = String2Json(jsonData).array();
|
||||
auto roomId = arr[0].toInt();
|
||||
auto room = ServerInstance->findRoom(roomId);
|
||||
if (room) {
|
||||
auto settings = QJsonDocument::fromJson(room->getSettings());
|
||||
auto password = settings["password"].toString();
|
||||
if (password.isEmpty() || arr[1].toString() == password) {
|
||||
if (room->isOutdated()) {
|
||||
sender->doNotify("ErrorMsg", "room is outdated");
|
||||
} else {
|
||||
room->addPlayer(sender);
|
||||
}
|
||||
} else {
|
||||
sender->doNotify("ErrorMsg", "room password error");
|
||||
}
|
||||
} else {
|
||||
sender->doNotify("ErrorMsg", "no such room");
|
||||
}
|
||||
}
|
||||
|
||||
static void observeRoom(ServerPlayer *sender, const QString &jsonData) {
|
||||
auto arr = String2Json(jsonData).array();
|
||||
auto roomId = arr[0].toInt();
|
||||
auto room = ServerInstance->findRoom(roomId);
|
||||
if (room) {
|
||||
auto settings = QJsonDocument::fromJson(room->getSettings());
|
||||
auto password = settings["password"].toString();
|
||||
if (password.isEmpty() || arr[1].toString() == password) {
|
||||
if (room->isOutdated()) {
|
||||
sender->doNotify("ErrorMsg", "room is outdated");
|
||||
} else {
|
||||
room->addObserver(sender);
|
||||
}
|
||||
} else {
|
||||
sender->doNotify("ErrorMsg", "room password error");
|
||||
}
|
||||
} else {
|
||||
sender->doNotify("ErrorMsg", "no such room");
|
||||
}
|
||||
}
|
||||
|
||||
static void refreshRoomList(ServerPlayer *sender, const QString &) {
|
||||
ServerInstance->updateRoomList(sender);
|
||||
};
|
||||
|
||||
static void quitRoom(ServerPlayer *player, const QString &) {
|
||||
auto room = player->getRoom();
|
||||
room->removePlayer(player);
|
||||
if (room->isOutdated()) {
|
||||
void Room::quitRoom(ServerPlayer *player, const QString &) {
|
||||
removePlayer(player);
|
||||
if (isOutdated()) {
|
||||
player->kicked();
|
||||
}
|
||||
}
|
||||
|
||||
static void addRobot(ServerPlayer *player, const QString &) {
|
||||
auto room = player->getRoom();
|
||||
void Room::addRobotRequest(ServerPlayer *player, const QString &) {
|
||||
if (ServerInstance->getConfig("enableBots").toBool())
|
||||
room->addRobot(player);
|
||||
addRobot(player);
|
||||
}
|
||||
|
||||
static void kickPlayer(ServerPlayer *player, const QString &jsonData) {
|
||||
auto room = player->getRoom();
|
||||
void Room::kickPlayer(ServerPlayer *player, const QString &jsonData) {
|
||||
int i = jsonData.toInt();
|
||||
auto p = room->findPlayer(i);
|
||||
if (p && !room->isStarted()) {
|
||||
room->removePlayer(p);
|
||||
room->addRejectId(i);
|
||||
QTimer::singleShot(30000, room, [=]() {
|
||||
room->removeRejectId(i);
|
||||
auto p = findPlayer(i);
|
||||
if (p && !isStarted()) {
|
||||
removePlayer(p);
|
||||
addRejectId(i);
|
||||
QTimer::singleShot(30000, this, [=]() {
|
||||
removeRejectId(i);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static void ready(ServerPlayer *player, const QString &) {
|
||||
auto room = player->getRoom();
|
||||
void Room::ready(ServerPlayer *player, const QString &) {
|
||||
player->setReady(!player->isReady());
|
||||
room->doBroadcastNotify(room->getPlayers(), "ReadyChanged",
|
||||
doBroadcastNotify(getPlayers(), "ReadyChanged",
|
||||
QString("[%1,%2]").arg(player->getId()).arg(player->isReady()));
|
||||
}
|
||||
|
||||
static void startGame(ServerPlayer *player, const QString &) {
|
||||
auto room = player->getRoom();
|
||||
if (room->isOutdated()) {
|
||||
foreach (auto p, room->getPlayers()) {
|
||||
void Room::startGame(ServerPlayer *player, const QString &) {
|
||||
if (isOutdated()) {
|
||||
foreach (auto p, getPlayers()) {
|
||||
p->doNotify("ErrorMsg", "room is outdated");
|
||||
p->kicked();
|
||||
}
|
||||
} else {
|
||||
room->manuallyStart();
|
||||
manuallyStart();
|
||||
}
|
||||
}
|
||||
|
||||
typedef void (*room_cb)(ServerPlayer *, const QString &);
|
||||
static const QMap<QString, room_cb> lobby_actions = {
|
||||
{"UpdateAvatar", updateAvatar},
|
||||
{"UpdatePassword", updatePassword},
|
||||
{"CreateRoom", createRoom},
|
||||
{"EnterRoom", enterRoom},
|
||||
{"ObserveRoom", observeRoom},
|
||||
{"RefreshRoomList", refreshRoomList},
|
||||
};
|
||||
|
||||
static const QMap<QString, room_cb> room_actions = {
|
||||
{"QuitRoom", quitRoom},
|
||||
{"AddRobot", addRobot},
|
||||
{"KickPlayer", kickPlayer},
|
||||
{"Ready", ready},
|
||||
{"StartGame", startGame},
|
||||
};
|
||||
typedef void (Room::*room_cb)(ServerPlayer *, const QString &);
|
||||
|
||||
void Room::handlePacket(ServerPlayer *sender, const QString &command,
|
||||
const QString &jsonData) {
|
||||
if (command == "Chat") {
|
||||
chat(sender, jsonData);
|
||||
static const QMap<QString, room_cb> room_actions = {
|
||||
{"QuitRoom", &Room::quitRoom},
|
||||
{"AddRobot", &Room::addRobotRequest},
|
||||
{"KickPlayer", &Room::kickPlayer},
|
||||
{"Ready", &Room::ready},
|
||||
{"StartGame", &Room::startGame},
|
||||
{"Chat", &Room::chat},
|
||||
};
|
||||
|
||||
if (command == "PushRequest") {
|
||||
pushRequest(QString("%1,").arg(sender->getId()) + jsonData);
|
||||
return;
|
||||
} else if (command == "PushRequest") {
|
||||
if (!isLobby())
|
||||
pushRequest(QString("%1,").arg(sender->getId()) + jsonData);
|
||||
}
|
||||
|
||||
auto func_table = lobby_actions;
|
||||
if (!isLobby()) func_table = room_actions;
|
||||
auto func = func_table[command];
|
||||
if (func) {
|
||||
func(sender, jsonData);
|
||||
}
|
||||
auto func = room_actions[command];
|
||||
if (func) (this->*func)(sender, jsonData);
|
||||
}
|
||||
|
||||
// Lua用:request之前设置计时器防止等到死。
|
||||
void Room::setRequestTimer(int ms) {
|
||||
request_timer = new QTimer();
|
||||
request_timer->setSingleShot(true);
|
||||
request_timer->setInterval(ms);
|
||||
connect(request_timer, &QTimer::timeout, this, [=](){
|
||||
m_thread->wakeUp(id);
|
||||
});
|
||||
request_timer->start();
|
||||
}
|
||||
|
||||
// Lua用:当request完成后手动销毁计时器。
|
||||
void Room::destroyRequestTimer() {
|
||||
if (!request_timer) return;
|
||||
request_timer->stop();
|
||||
delete request_timer;
|
||||
request_timer = nullptr;
|
||||
}
|
||||
|
|
|
@ -3,11 +3,13 @@
|
|||
#ifndef _ROOM_H
|
||||
#define _ROOM_H
|
||||
|
||||
#include "server/roombase.h"
|
||||
|
||||
class Server;
|
||||
class ServerPlayer;
|
||||
class RoomThread;
|
||||
|
||||
class Room : public QObject {
|
||||
class Room : public RoomBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Room(RoomThread *m_thread);
|
||||
|
@ -15,12 +17,11 @@ class Room : public QObject {
|
|||
|
||||
// Property reader & setter
|
||||
// ==================================={
|
||||
Server *getServer() const;
|
||||
RoomThread *getThread() const;
|
||||
void setThread(RoomThread *t);
|
||||
|
||||
int getId() const;
|
||||
void setId(int id);
|
||||
bool isLobby() const;
|
||||
QString getName() const;
|
||||
void setName(const QString &name);
|
||||
int getCapacity() const;
|
||||
|
@ -38,9 +39,6 @@ class Room : public QObject {
|
|||
void addPlayer(ServerPlayer *player);
|
||||
void addRobot(ServerPlayer *player);
|
||||
void removePlayer(ServerPlayer *player);
|
||||
QList<ServerPlayer *> getPlayers() const;
|
||||
QList<ServerPlayer *> getOtherPlayers(ServerPlayer *expect) const;
|
||||
ServerPlayer *findPlayer(int id) const;
|
||||
|
||||
void addObserver(ServerPlayer *player);
|
||||
void removeObserver(ServerPlayer *player);
|
||||
|
@ -49,16 +47,13 @@ class Room : public QObject {
|
|||
|
||||
int getTimeout() const;
|
||||
void setTimeout(int timeout);
|
||||
void delay(int ms);
|
||||
|
||||
bool isOutdated();
|
||||
|
||||
bool isStarted() const;
|
||||
// ====================================}
|
||||
|
||||
void doBroadcastNotify(const QList<ServerPlayer *> targets,
|
||||
const QString &command, const QString &jsonData);
|
||||
void chat(ServerPlayer *sender, const QString &jsonData);
|
||||
|
||||
void updateWinRate(int id, const QString &general, const QString &mode,
|
||||
int result, bool dead);
|
||||
void gameOver();
|
||||
|
@ -71,6 +66,13 @@ class Room : public QObject {
|
|||
// router用
|
||||
void handlePacket(ServerPlayer *sender, const QString &command,
|
||||
const QString &jsonData);
|
||||
|
||||
void setRequestTimer(int ms);
|
||||
void destroyRequestTimer();
|
||||
|
||||
// FIXME
|
||||
volatile bool insideGameOver = false;
|
||||
|
||||
signals:
|
||||
void abandoned();
|
||||
|
||||
|
@ -78,8 +80,7 @@ class Room : public QObject {
|
|||
void playerRemoved(ServerPlayer *player);
|
||||
|
||||
private:
|
||||
Server *server;
|
||||
RoomThread *m_thread;
|
||||
RoomThread *m_thread = nullptr;
|
||||
int id; // Lobby's id is 0
|
||||
QString name; // “阴间大乱斗”
|
||||
int capacity; // by default is 5, max is 8
|
||||
|
@ -87,8 +88,6 @@ class Room : public QObject {
|
|||
bool m_abandoned; // If room is empty, delete it
|
||||
|
||||
ServerPlayer *owner; // who created this room?
|
||||
QList<ServerPlayer *> players;
|
||||
QList<ServerPlayer *> observers;
|
||||
QList<int> runned_players;
|
||||
QList<int> rejected_players;
|
||||
int robot_id;
|
||||
|
@ -98,8 +97,17 @@ class Room : public QObject {
|
|||
int timeout;
|
||||
QString md5;
|
||||
|
||||
QTimer *request_timer = nullptr;
|
||||
|
||||
void addRunRate(int id, const QString &mode);
|
||||
void updatePlayerGameData(int id, const QString &mode);
|
||||
|
||||
// handle packet
|
||||
void quitRoom(ServerPlayer *, const QString &);
|
||||
void addRobotRequest(ServerPlayer *, const QString &);
|
||||
void kickPlayer(ServerPlayer *, const QString &);
|
||||
void ready(ServerPlayer *, const QString &);
|
||||
void startGame(ServerPlayer *, const QString &);
|
||||
};
|
||||
|
||||
#endif // _ROOM_H
|
||||
|
|
66
src/server/roombase.cpp
Normal file
66
src/server/roombase.cpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
#include "server/roombase.h"
|
||||
#include "server/serverplayer.h"
|
||||
#include "server/server.h"
|
||||
#include "core/util.h"
|
||||
|
||||
Server *RoomBase::getServer() const { return server; }
|
||||
|
||||
bool RoomBase::isLobby() const {
|
||||
return inherits("Lobby");
|
||||
}
|
||||
|
||||
QList<ServerPlayer *> RoomBase::getPlayers() const { return players; }
|
||||
|
||||
QList<ServerPlayer *> RoomBase::getOtherPlayers(ServerPlayer *expect) const {
|
||||
QList<ServerPlayer *> others = getPlayers();
|
||||
others.removeOne(expect);
|
||||
return others;
|
||||
}
|
||||
|
||||
ServerPlayer *RoomBase::findPlayer(int id) const {
|
||||
foreach (ServerPlayer *p, players) {
|
||||
if (p->getId() == id)
|
||||
return p;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void RoomBase::doBroadcastNotify(const QList<ServerPlayer *> targets,
|
||||
const QString &command, const QString &jsonData) {
|
||||
foreach (ServerPlayer *p, targets) {
|
||||
p->doNotify(command, jsonData);
|
||||
}
|
||||
}
|
||||
|
||||
void RoomBase::chat(ServerPlayer *sender, const QString &jsonData) {
|
||||
auto doc = String2Json(jsonData).object();
|
||||
auto type = doc["type"].toInt();
|
||||
doc["sender"] = sender->getId();
|
||||
|
||||
auto msg = doc["msg"].toString();
|
||||
if (!server->checkBanWord(msg)) {
|
||||
return;
|
||||
}
|
||||
// 屏蔽.号和百分号,防止有人在HTML文本发链接,而正常发链接看不出来有啥改动
|
||||
msg.replace(".", "․");
|
||||
msg.replace("%", "%");
|
||||
// 300字限制,与客户端相同
|
||||
msg.erase(msg.begin() + 300, msg.end());
|
||||
doc["msg"] = msg;
|
||||
|
||||
if (type == 1) {
|
||||
doc["userName"] = sender->getScreenName();
|
||||
auto json = QJsonDocument(doc).toJson(QJsonDocument::Compact);
|
||||
doBroadcastNotify(players, "Chat", json);
|
||||
} else {
|
||||
auto json = QJsonDocument(doc).toJson(QJsonDocument::Compact);
|
||||
doBroadcastNotify(players, "Chat", json);
|
||||
doBroadcastNotify(observers, "Chat", json);
|
||||
}
|
||||
|
||||
qInfo("[Chat/%s] %s: %s",
|
||||
isLobby() ? "Lobby" : QString("#%1").arg(qobject_cast<Room *>(this)
|
||||
->getId()).toUtf8().constData(),
|
||||
sender->getScreenName().toUtf8().constData(),
|
||||
doc["msg"].toString().toUtf8().constData());
|
||||
}
|
30
src/server/roombase.h
Normal file
30
src/server/roombase.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
#ifndef _ROOMBASE_H
|
||||
#define _ROOMBASE_H
|
||||
|
||||
class Server;
|
||||
class ServerPlayer;
|
||||
|
||||
class RoomBase : public QObject {
|
||||
public:
|
||||
Server *getServer() const;
|
||||
bool isLobby() const;
|
||||
QList<ServerPlayer *> getPlayers() const;
|
||||
QList<ServerPlayer *> getOtherPlayers(ServerPlayer *expect) const;
|
||||
ServerPlayer *findPlayer(int id) const;
|
||||
|
||||
void doBroadcastNotify(const QList<ServerPlayer *> targets,
|
||||
const QString &command, const QString &jsonData);
|
||||
|
||||
void chat(ServerPlayer *sender, const QString &jsonData);
|
||||
|
||||
virtual void addPlayer(ServerPlayer *player) = 0;
|
||||
virtual void removePlayer(ServerPlayer *player) = 0;
|
||||
virtual void handlePacket(ServerPlayer *sender, const QString &command,
|
||||
const QString &jsonData) = 0;
|
||||
protected:
|
||||
Server *server;
|
||||
QList<ServerPlayer *> players;
|
||||
QList<ServerPlayer *> observers;
|
||||
};
|
||||
|
||||
#endif // _ROOMBASE_H
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user