From b4f6e58f079b47a312de33d308fca43d57f7d310 Mon Sep 17 00:00:00 2001 From: notify Date: Mon, 10 Apr 2023 21:34:23 +0800 Subject: [PATCH] Chat (#112) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加聊天功能 修bug --- lua/client/client_util.lua | 1 + lua/core/player.lua | 11 ++--- lua/core/skill_type/active.lua | 2 +- lua/server/room.lua | 2 +- packages/standard_cards/init.lua | 5 ++- qml/Logic.js | 1 + qml/Pages/Lobby.qml | 1 + qml/Pages/Room.qml | 71 ++++++++++++++++++++++++++++++++ 8 files changed, 86 insertions(+), 8 deletions(-) diff --git a/lua/client/client_util.lua b/lua/client/client_util.lua index b749da6d..c3f699da 100644 --- a/lua/client/client_util.lua +++ b/lua/client/client_util.lua @@ -262,6 +262,7 @@ end function GetSkillData(skill_name) local skill = Fk.skills[skill_name] + if not skill then return "null" end local freq = "notactive" if skill:isInstanceOf(ActiveSkill) or skill:isInstanceOf(ViewAsSkill) then freq = "active" diff --git a/lua/core/player.lua b/lua/core/player.lua index 035f9fae..e5c1b47e 100644 --- a/lua/core/player.lua +++ b/lua/core/player.lua @@ -356,6 +356,12 @@ function Player:getAttackRange() local weapon = Fk:getCardById(self:getEquipment(Card.SubtypeWeapon)) local baseAttackRange = math.max(weapon and weapon.attack_range or 1, 0) + local status_skills = Fk:currentRoom().status_skills[AttackRangeSkill] or {} + for _, skill in ipairs(status_skills) do + local correct = skill:getCorrect(self, other) + baseAttackRange = baseAttackRange + correct + end + return math.max(baseAttackRange, 0) end @@ -410,11 +416,6 @@ function Player:inMyAttackRange(other) return false end local baseAttackRange = self:getAttackRange() - local status_skills = Fk:currentRoom().status_skills[AttackRangeSkill] or {} - for _, skill in ipairs(status_skills) do - local correct = skill:getCorrect(self, other) - baseAttackRange = baseAttackRange + correct - end return self:distanceTo(other) <= baseAttackRange end diff --git a/lua/core/skill_type/active.lua b/lua/core/skill_type/active.lua index 4b5243b2..4c08bdb0 100644 --- a/lua/core/skill_type/active.lua +++ b/lua/core/skill_type/active.lua @@ -120,7 +120,7 @@ function ActiveSkill:getMaxCardNum() end function ActiveSkill:getDistanceLimit(player, card) - local ret = self.distance_limit + local ret = self.distance_limit or 0 local status_skills = Fk:currentRoom().status_skills[TargetModSkill] or {} for _, skill in ipairs(status_skills) do local correct = skill:getDistanceLimit(player, self, card) diff --git a/lua/server/room.lua b/lua/server/room.lua index 8c0bf245..c0808bd9 100644 --- a/lua/server/room.lua +++ b/lua/server/room.lua @@ -898,7 +898,7 @@ function Room:askForDiscard(player, minNum, maxNum, includeEquip, skillName, can minNum = math.min(#canDiscards, minNum) if minNum < 1 then - return nil + return {} end local toDiscard = {} diff --git a/packages/standard_cards/init.lua b/packages/standard_cards/init.lua index b3fb0963..3ceacc32 100644 --- a/packages/standard_cards/init.lua +++ b/packages/standard_cards/init.lua @@ -13,7 +13,10 @@ local slashSkill = fk.CreateActiveSkill{ target_filter = function(self, to_select, selected, _, card) if #selected < self:getMaxTargetNum(Self, card) then local player = Fk:currentRoom():getPlayerById(to_select) - return Self ~= player and Self:inMyAttackRange(player) + return Self ~= player and + (self:getDistanceLimit(Self, card) -- for no distance limit for slash + + Self:getAttackRange() + >= Self:distanceTo(player)) end end, on_effect = function(self, room, effect) diff --git a/qml/Logic.js b/qml/Logic.js index 105887fe..3c3992e6 100644 --- a/qml/Logic.js +++ b/qml/Logic.js @@ -121,6 +121,7 @@ callbacks["Chat"] = function(jsonData) { let general = Backend.translate(data.general); let time = data.time; let msg = data.msg; + if (general === "") current.addToChat(pid, data, `[${time}] ${userName}: ${msg}`); else diff --git a/qml/Pages/Lobby.qml b/qml/Pages/Lobby.qml index 424c6cf4..a9305a54 100644 --- a/qml/Pages/Lobby.qml +++ b/qml/Pages/Lobby.qml @@ -57,6 +57,7 @@ Item { Text { text: Backend.translate("Observe") + visible: false // FIXME font.pixelSize: 24 TapHandler { onTapped: { diff --git a/qml/Pages/Room.qml b/qml/Pages/Room.qml index f7010245..cb1c6b34 100644 --- a/qml/Pages/Room.qml +++ b/qml/Pages/Room.qml @@ -673,6 +673,10 @@ Item { function addToChat(pid, raw, msg) { if (raw.type === 1) return; + + if (raw.msg.startsWith("$")) { + if (specialChat(pid, data, raw.msg.slice(1))) return; + } chat.append(msg); let photo = Logic.getPhotoOrSelf(pid); if (photo === undefined) @@ -680,6 +684,73 @@ Item { photo.chat(raw.msg); } + function specialChat(pid, data, msg) { + // skill audio: %s%d + // death audio: ~%s + // something special: .%s:... + + let time = data.time; + let userName = data.userName; + let general = Backend.translate(data.general); + + if (msg.startsWith(".")) { + let splited = msg.split(":"); + let type = splited[0].slice(1); + switch (type) { + case "egg": { + return true; + } + case "flower": { + return true; + } + default: + return false; + } + } else if (msg.startsWith("~")) { + let g = msg.slice(1); + let extension = JSON.parse(Backend.callLuaFunction("GetGeneralData", [g])).extension; + Backend.playSound("./packages/" + extension + "/audio/death/" + g); + + let m = Backend.translate("~" + g); + if (general === "") + chat.append(`[${time}] ${userName}: ${m}`); + else + chat.append(`[${time}] ${userName}(${general}): ${m}`); + + let photo = Logic.getPhotoOrSelf(pid); + if (photo === undefined) + return true; + photo.chat(m); + + return true; + } else { + let splited = msg.split(":"); + if (splited.length < 2) return false; + let skill = splited[0]; + let idx = parseInt(splited[1]); + + let data2 = JSON.parse(Backend.callLuaFunction("GetSkillData", [skill])); + if (!data2) return false; + let extension = data2.extension; + Backend.playSound("./packages/" + extension + "/audio/skill/" + skill, idx); + + let m = Backend.translate("$" + skill + idx.toString()); + if (general === "") + chat.append(`[${time}] ${userName}: ${m}`); + else + chat.append(`[${time}] ${userName}(${general}): ${m}`); + + let photo = Logic.getPhotoOrSelf(pid); + if (photo === undefined) + return true; + photo.chat(m); + + return true; + } + + return false; + } + function addToLog(msg) { log.append(msg); }