增加聊天功能
修bug
This commit is contained in:
notify 2023-04-10 21:34:23 +08:00 committed by GitHub
parent 90ad7fee5f
commit b4f6e58f07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 86 additions and 8 deletions

View File

@ -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"

View File

@ -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

View File

@ -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)

View File

@ -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 = {}

View File

@ -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)

View File

@ -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

View File

@ -57,6 +57,7 @@ Item {
Text {
text: Backend.translate("Observe")
visible: false // FIXME
font.pixelSize: 24
TapHandler {
onTapped: {

View File

@ -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);
}