堆一堆
- 更改了许褚台词
- 让lua认为prompt可以是string
- 修改魄袭框,添加extra_data和cancelable
- 修复GetNcards的洗牌判定逻辑
- 为聊天添加300字符限制
This commit is contained in:
YoumuKon 2023-10-27 22:19:30 +08:00 committed by GitHub
parent 4d7359d834
commit edf10893e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 68 additions and 38 deletions

View File

@ -114,6 +114,7 @@ Rectangle {
color: "white"
clip: true
font.pixelSize: 14
maximumLength: 300
onAccepted: {
if (text != "") {

View File

@ -1071,13 +1071,15 @@ callbacks["AskForCardsChosen"] = (jsonData) => {
}
callbacks["AskForPoxi"] = (jsonData) => {
const { type, data } = JSON.parse(jsonData);
const { type, data, extra_data, cancelable } = JSON.parse(jsonData);
roomScene.state = "replying";
roomScene.popupBox.sourceComponent = Qt.createComponent("../RoomElement/PoxiBox.qml");
const box = roomScene.popupBox.item;
box.poxi_type = type;
box.card_data = data;
box.extra_data = extra_data;
box.cancelable = cancelable;
for (let d of data) {
const arr = [];
const ids = d[1];

View File

@ -11,13 +11,15 @@ GraphicsBox {
// TODO: Adjust the UI design in case there are more than 7 cards
width: 70 + 700
height: 64 + Math.min(cardView.contentHeight, 400) + 20
height: 64 + Math.min(cardView.contentHeight, 400) + 30
signal cardSelected(int cid)
signal cardsSelected(var ids)
property var selected_ids: []
property string poxi_type
property var card_data
property bool cancelable: true
property var extra_data
ListModel {
id: cardModel
@ -29,14 +31,14 @@ GraphicsBox {
anchors.topMargin: 40
anchors.leftMargin: 20
anchors.rightMargin: 20
anchors.bottomMargin: 20
anchors.bottomMargin: 30
spacing: 20
model: cardModel
clip: true
delegate: RowLayout {
spacing: 15
visible: areaCards.count > 0
// visible: areaCards.count > 0
Rectangle {
border.color: "#A6967A"
@ -72,7 +74,7 @@ GraphicsBox {
selectable: {
return root.selected_ids.includes(model.cid) || JSON.parse(Backend.callLuaFunction(
"PoxiFilter",
[root.poxi_type, model.cid, root.selected_ids, root.card_data]
[root.poxi_type, model.cid, root.selected_ids, root.card_data, root.extra_data]
));
}
onSelectedChanged: {
@ -91,18 +93,36 @@ GraphicsBox {
}
}
MetroButton {
Row {
anchors.margins: 8
anchors.bottom: parent.bottom
text: Backend.translate("OK")
enabled: {
return JSON.parse(Backend.callLuaFunction(
"PoxiFeasible",
[root.poxi_type, root.selected_ids, root.card_data]
));
anchors.horizontalCenter: parent.horizontalCenter
spacing: 32
MetroButton {
width: 120
height: 35
text: Backend.translate("OK")
enabled: {
return JSON.parse(Backend.callLuaFunction(
"PoxiFeasible",
[root.poxi_type, root.selected_ids, root.card_data, root.extra_data]
));
}
onClicked: root.cardsSelected(root.selected_ids)
}
onClicked: root.cardsSelected(root.selected_ids)
MetroButton {
width: 120
height: 35
text: Backend.translate("Cancel")
enabled: root.cancelable
onClicked: root.cardsSelected([])
}
}
onCardSelected: finished();
function findAreaModel(name) {

View File

@ -722,16 +722,16 @@ function PoxiPrompt(poxi_type, data)
return poxi.prompt(data)
end
function PoxiFilter(poxi_type, to_select, selected, data)
function PoxiFilter(poxi_type, to_select, selected, data, extra_data)
local poxi = Fk.poxi_methods[poxi_type]
if not poxi then return "false" end
return json.encode(poxi.card_filter(to_select, selected, data))
return json.encode(poxi.card_filter(to_select, selected, data, extra_data))
end
function PoxiFeasible(poxi_type, selected, data)
function PoxiFeasible(poxi_type, selected, data, extra_data)
local poxi = Fk.poxi_methods[poxi_type]
if not poxi then return "false" end
return json.encode(poxi.feasible(selected, data))
return json.encode(poxi.feasible(selected, data, extra_data))
end
dofile "lua/client/i18n/init.lua"

View File

@ -126,6 +126,7 @@ end
Util.NameMapper = function(e) return e.name end
Util.Name2GeneralMapper = function(e) return Fk.generals[e] end
Util.Name2SkillMapper = function(e) return Fk.skills[e] end
Util.TranslateMapper = function(str) return Fk:translate(str) end
-- for card preset
Util.GlobalCanUse = function(self, player, card)

View File

@ -179,7 +179,7 @@ end
---@field public on_effect nil|fun(self: ActiveSkill, room: Room, cardEffectEvent: CardEffectEvent): bool
---@field public on_nullified nil|fun(self: ActiveSkill, room: Room, cardEffectEvent: CardEffectEvent): bool
---@field public mod_target_filter nil|fun(self: ActiveSkill, to_select: integer, selected: integer[], user: integer, card: Card, distance_limited: boolean): bool
---@field public prompt nil|fun(self: ActiveSkill, selected: integer[], selected_cards: integer[]): string
---@field public prompt nil|string|fun(self: ActiveSkill, selected: integer[], selected_cards: integer[]): string
---@field public interaction any
---@param spec ActiveSkillSpec
@ -228,7 +228,7 @@ end
---@field public enabled_at_play nil|fun(self: ViewAsSkill, player: Player): bool
---@field public enabled_at_response nil|fun(self: ViewAsSkill, player: Player, response: boolean): bool
---@field public before_use nil|fun(self: ViewAsSkill, player: ServerPlayer, use: CardUseStruct)
---@field public prompt nil|fun(self: ActiveSkill, selected: integer[], selected_cards: integer[]): string
---@field public prompt nil|string|fun(self: ActiveSkill, selected: integer[], selected_cards: integer[]): string
---@param spec ViewAsSkillSpec
---@return ViewAsSkill
@ -593,8 +593,8 @@ end
---@class PoxiSpec
---@field name string
---@field card_filter fun(to_select: int, selected: int[], data: any): bool
---@field feasible fun(selected: int[], data: any): bool
---@field post_select nil | fun(selected: int[], data: any): int[]
---@field default_choice nil | fun(data: any): int[]
---@field prompt nil | string | fun(data: any): string
---@field card_filter fun(to_select: int, selected: int[], data: any, extra_data: any): bool
---@field feasible fun(selected: int[], data: any, extra_data: any): bool
---@field post_select nil | fun(selected: int[], data: any, extra_data: any): int[]
---@field default_choice nil | fun(data: any, extra_data: any): int[]
---@field prompt nil | string | fun(data: any, extra_data: any): string

View File

@ -439,15 +439,15 @@ end
function Room:getNCards(num, from)
from = from or "top"
assert(from == "top" or from == "bottom")
if #self.draw_pile < num then
self:shuffleDrawPile()
if #self.draw_pile < num then
self:gameOver("")
end
end
local cardIds = {}
while num > 0 do
if #self.draw_pile < 1 then
self:shuffleDrawPile()
if #self.draw_pile < 1 then
self:gameOver("")
end
end
local index = from == "top" and 1 or #self.draw_pile
table.insert(cardIds, self.draw_pile[index])
@ -1565,8 +1565,10 @@ end
---@param player ServerPlayer
---@param poxi_type string
---@param data any
---@param extra_data any
---@param cancelable nil|bool
---@return integer[]
function Room:askForPoxi(player, poxi_type, data)
function Room:askForPoxi(player, poxi_type, data, extra_data, cancelable)
local poxi = Fk.poxi_methods[poxi_type]
if not poxi then return {} end
@ -1575,12 +1577,14 @@ function Room:askForPoxi(player, poxi_type, data)
local result = self:doRequest(player, command, json.encode {
type = poxi_type,
data = data,
extra_data = extra_data,
cancelable = (cancelable == nil) and true or cancelable
})
if result == "" then
return poxi.default_choice(data)
return poxi.default_choice(data, extra_data)
else
return poxi.post_select(json.decode(result), data)
return poxi.post_select(json.decode(result), data, extra_data)
end
end

View File

@ -52,7 +52,7 @@ Fk:loadTranslationTable{
["xuchu"] = "许褚",
["~xuchu"] = "冷,好冷啊……",
["$luoyi1"] = "",
["$luoyi1"] = "",
["$luoyi2"] = "谁来与我大战三百回合?",
["luoyi"] = "裸衣",
[":luoyi"] = "摸牌阶段,你可以少摸一张牌,若如此做,本回合你使用【杀】或【决斗】对目标角色造成伤害时,此伤害+1。",

View File

@ -93,7 +93,7 @@ local control = fk.CreateActiveSkill{
-- p(room:askForPoxi(from, "test", {
-- { "你自己", from:getCardIds "h" },
-- { "对方", to:getCardIds "h" },
-- }))
-- }, from.hp, false))
-- room:setPlayerMark(from, "@$a", {1,2,3})
-- room:setPlayerMark(from, "@$b", {'slash','duel','axe'})
if to:getMark("mouxushengcontrolled") == 0 then
@ -133,15 +133,15 @@ local control = fk.CreateActiveSkill{
--[[
Fk:addPoxiMethod{
name = "test",
card_filter = function(to_select, selected, data)
card_filter = function(to_select, selected, data, extra_data)
local s = Fk:getCardById(to_select).suit
for _, id in ipairs(selected) do
if Fk:getCardById(id).suit == s then return false end
end
return true
end,
feasible = function(selected, data)
return #selected == 0 or #selected == 4
feasible = function(selected, data, extra_data)
return #selected == 0 or #selected == 4 or #selected == extra_data
end,
prompt = "魄袭:选你们俩手牌总共四个花色,或者不选直接按确定按钮"
}

View File

@ -370,6 +370,8 @@ void Room::chat(ServerPlayer *sender, const QString &jsonData) {
// 屏蔽.号防止有人在HTML文本发链接而正常发链接看不出来有啥改动
auto msg = doc["msg"].toString();
msg.replace(".", "");
// 300字限制与客户端相同
msg.erase(msg.begin() + 300, msg.end());
doc["msg"] = msg;
if (!server->checkBanWord(msg)) {
return;