Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/xxyheaven/FreeKill
Browse files Browse the repository at this point in the history
  • Loading branch information
xxyheaven committed Apr 6, 2024
2 parents 0f863c2 + e75836f commit 61b18c4
Show file tree
Hide file tree
Showing 39 changed files with 548 additions and 247 deletions.
4 changes: 3 additions & 1 deletion Fk/LobbyElement/RoomGeneralSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ Flickable {
arr = config.curScheme.banPkg[k];
if (arr.length !== 0) {
const generals = lcall("GetGenerals", k);
disabledGenerals.push(...generals.filter(g => !arr.includes(g)));
if (generals.length !== 0) {
disabledGenerals.push(...generals.filter(g => !arr.includes(g)));
}
}
}
for (k in config.curScheme.normalPkg) {
Expand Down
12 changes: 5 additions & 7 deletions Fk/Logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,12 @@ callbacks["UpdateRoomList"] = (jsonData) => {
const current = mainStack.currentItem; // should be lobby
if (mainStack.depth === 2) {
current.roomModel.clear();
JSON.parse(jsonData).forEach(function (room) {
JSON.parse(jsonData).forEach(room => {
const [roomId, roomName, gameMode, playerNum, capacity, hasPassword,
outdated] = room;
current.roomModel.append({
roomId: room[0],
roomName: room[1],
gameMode: room[2],
playerNum: room[3],
capacity: room[4],
hasPassword: room[5] ? true : false,
roomId, roomName, gameMode, playerNum, capacity,
hasPassword, outdated,
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions Fk/Pages/GeneralsOverview.qml
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,8 @@ Item {

function loadPackages() {
if (loaded) return;
const _mods = lcall("GetAllModNames")
const modData = lcall("GetAllMods")
const _mods = lcall("GetAllModNames");
const modData = lcall("GetAllMods");
const packs = lcall("GetAllGeneralPack");
_mods.forEach(name => {
const pkgs = modData[name].filter(p => packs.includes(p)
Expand Down
10 changes: 8 additions & 2 deletions Fk/Pages/Lobby.qml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ Item {
Text {
horizontalAlignment: Text.AlignLeft
Layout.fillWidth: true
text: roomName
text: {
let ret = roomName;
if (outdated) {
ret = '<font color="grey"><del>' + ret + '</del></font>';
}
return ret;
}
font.pixelSize: 20
elide: Label.ElideRight
}
Expand Down Expand Up @@ -94,7 +100,7 @@ Item {
text: (playerNum < capacity) ? luatr("Enter") :
luatr("Observe")

enabled: !opTimer.running
enabled: !opTimer.running && !outdated

onClicked: {
opTimer.start();
Expand Down
2 changes: 1 addition & 1 deletion Fk/Pages/RoomLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ callbacks["AskForGeneral"] = (jsonData) => {
});
box.choiceNum = n;
box.convertDisabled = !!convert;
box.needSameKingdom = !!heg;
box.hegemony = !!heg;
for (let i = 0; i < generals.length; i++)
box.generalList.append({ "name": generals[i] });
box.updatePosition();
Expand Down
39 changes: 36 additions & 3 deletions Fk/RoomElement/ChooseGeneralBox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ GraphicsBox {
property var selectedItem: []
property bool loaded: false
property bool convertDisabled: false
property bool needSameKingdom: false
property bool hegemony: false

ListModel {
id: generalList
Expand Down Expand Up @@ -230,6 +230,14 @@ GraphicsBox {
return false;
}

function updateCompanion(gcard1, gcard2, overwrite) {
if (lcall("IsCompanionWith", gcard1.name, gcard2.name)) {
gcard1.hasCompanions = true;
} else if (overwrite) {
gcard1.hasCompanions = false;
}
}

function updatePosition()
{
choices = [];
Expand All @@ -248,12 +256,37 @@ GraphicsBox {
root.choicesChanged();

fightButton.enabled = (choices.length == choiceNum) &&
(needSameKingdom ? isHegPair(selectedItem[0], selectedItem[1]) : true);
(hegemony ? isHegPair(selectedItem[0], selectedItem[1]) : true);

for (i = 0; i < generalCardList.count; i++) {
item = generalCardList.itemAt(i);
item.selectable = needSameKingdom ? isHegPair(selectedItem[0], item)
item.selectable = hegemony ? isHegPair(selectedItem[0], item)
: true;
if (hegemony) {
if (selectedItem[0]) {
if (selectedItem[1]) {
if (selectedItem[0] === item) {
updateCompanion(item, selectedItem[1], true);
} else if (selectedItem[1] === item) {
updateCompanion(item, selectedItem[0], true);
} else {
item.hasCompanions = false;
}
} else {
if (selectedItem[0] !== item) {
updateCompanion(item, selectedItem[0], true);
} else {
for (let j = 0; j < generalList.count; j++) {
updateCompanion(item, generalList.get(j), false);
}
}
}
} else {
for (let j = 0; j < generalList.count; j++) {
updateCompanion(item, generalList.get(j), false);
}
}
}
if (selectedItem.indexOf(item) != -1)
continue;

Expand Down
15 changes: 15 additions & 0 deletions Fk/RoomElement/GeneralCardItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ CardItem {
property int shieldNum
property string pkgName: ""
property bool detailed: true
property alias hasCompanions: companions.visible
name: ""
// description: Sanguosha.getGeneralDescription(name)
suit: ""
Expand Down Expand Up @@ -157,6 +158,7 @@ CardItem {
height: 80
x: 2
y: lineCount > 6 ? 30 : 34
z: 999
text: name !== "" ? luatr(name) : "nil"
visible: luatr(name).length <= 6 && detailed && known
color: "white"
Expand All @@ -170,6 +172,7 @@ CardItem {
Text {
x: 0
y: 12
z: 999
rotation: 90
transformOrigin: Item.BottomLeft
text: luatr(name)
Expand All @@ -184,6 +187,7 @@ CardItem {
visible: pkgName !== "" && detailed && known
height: 16
width: childrenRect.width + 4
z: 100
anchors.bottom: parent.bottom
anchors.bottomMargin: 4
anchors.right: parent.right
Expand All @@ -205,6 +209,17 @@ CardItem {
}
}

Image {
id: companions
width: parent.width
fillMode: Image.PreserveAspectFit
visible: false
source: SkinBank.getGeneralCardDir(kingdom) + kingdom + "-companions"
anchors.horizontalCenter: parent.horizontalCenter
y: 80
z: 1
}

onNameChanged: {
const data = lcall("GetGeneralData", name);
kingdom = data.kingdom;
Expand Down
Binary file added image/card/general/qun-companions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/card/general/shu-companions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/card/general/wei-companions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/card/general/wild-companions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/card/general/wu-companions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions lang/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@
<source>room password error</source>
<translation>房间密码错误</translation>
</message>
<message>
<source>room is outdated</source>
<translation>房间已过时</translation>
</message>
<message>
<source>no such room</source>
<translation>房间不存在</translation>
Expand Down
33 changes: 18 additions & 15 deletions lua/client/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,28 @@ function Client:getPlayerById(id)
return nil
end

---@param cardId integer | card
---@param cardId integer | Card
---@return CardArea
function Client:getCardArea(cardId)
if type(cardId) ~= "number" then
assert(cardId and cardId:isInstanceOf(Card))
cardId = cardId:getEffectiveId()
end
if table.contains(Self.player_cards[Player.Hand], cardId) then
return Card.PlayerHand
end
if table.contains(Self.player_cards[Player.Equip], cardId) then
return Card.PlayerEquip
end
for _, t in pairs(Self.special_cards) do
if table.contains(t, cardId) then
return Card.PlayerSpecial
local cardIds = Card:getIdList(cardId)
local resultPos = {}
for _, cid in ipairs(cardIds) do
if not table.contains(resultPos, Card.PlayerHand) and table.contains(Self.player_cards[Player.Hand], cid) then
table.insert(resultPos, Card.PlayerHand)
end
if not table.contains(resultPos, Card.PlayerEquip) and table.contains(Self.player_cards[Player.Equip], cid) then
table.insert(resultPos, Card.PlayerEquip)
end
for _, t in pairs(Self.special_cards) do
if table.contains(t, cid) then
table.insertIfNeed(resultPos, Card.PlayerSpecial)
end
end
end
if #resultPos == 1 then
return resultPos[1]
end
error("Client:getCardArea can only judge cards in your hand or equip area")
return Card.Unknown
end

function Client:moveCards(moves)
Expand Down
7 changes: 6 additions & 1 deletion lua/client/client_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ function GetSameGenerals(name)
return json.encode(Fk:getSameGenerals(name))
end

function IsCompanionWith(general, general2)
local _general, _general2 = Fk.generals[general], Fk.generals[general2]
return json.encode(_general:isCompanionWith(_general2))
end

local cardSubtypeStrings = {
[Card.SubtypeNone] = "none",
[Card.SubtypeDelayedTrick] = "delayed_trick",
Expand Down Expand Up @@ -146,7 +151,7 @@ function GetAllGeneralPack()
end

function GetGenerals(pack_name)
if not Fk.packages[pack_name] then return "{}" end
if not Fk.packages[pack_name] then return "[]" end
local ret = {}
for _, g in ipairs(Fk.packages[pack_name].generals) do
if not g.total_hidden then
Expand Down
6 changes: 5 additions & 1 deletion lua/client/i18n/zh_CN.lua
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,12 @@ Fk:loadTranslationTable{
["$DiscardOther"] = "%to 弃置了 %from 的 %arg 张牌 %card",
["$PutToDiscard"] = "%arg 张牌 %card 被置入弃牌堆",

["#AbortArea"] = "%from 的 %arg 被废除",
["#ResumeArea"] = "%from 的 %arg 被恢复",

["#ShowCard"] = "%from 展示了牌 %card",
["#Recast"] = "%from 重铸了 %card",
["#RecastBySkill"] = "%from 发动了 “%arg” 重铸了 %card",
["#RecastBySkill"] = "%from “%arg” 重铸了 %card",

-- phase
["#PhaseSkipped"] = "%from 跳过了 %arg",
Expand Down Expand Up @@ -495,6 +498,7 @@ Fk:loadTranslationTable{
["#ChainStateChange"] = "%from %arg 了武将牌",
["#ChainDamage"] = "%from 处于连环状态,将受到传导的伤害",
["#ChangeKingdom"] = "%from 的国籍从 %arg 变成了 %arg2",
["#RoomOutdated"] = "服务器更新完毕!该房间已过期,将无法再次游玩",
}

-- card footnote
Expand Down
12 changes: 10 additions & 2 deletions lua/core/general.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ function General:getSkillNameList(include_lord)
return ret
end

--- 为武将增加珠联璧合关系武将(1个或多个),只需写trueName
---@param name string[] @ 武将真名(表)
--- 为武将增加珠联璧合关系武将(1个或多个)。
---@param name string|string[] @ 武将名(表)
function General:addCompanions(name)
if type(name) == "table" then
table.insertTable(self.companions, name)
Expand All @@ -120,4 +120,12 @@ function General:addCompanions(name)
end
end

--- 是否与另一武将构成珠联璧合关系。
---@param other General @ 另一武将
function General:isCompanionWith(other)
return table.contains(self.companions, other.name) or table.contains(other.companions, self.name)
or (string.find(self.name, "lord") and (other.kingdom == self.kingdom or other.subkingdom == self.kingdom))
or (string.find(other.name, "lord") and (self.kingdom == other.kingdom or self.subkingdom == other.kingdom))
end

return General
55 changes: 54 additions & 1 deletion lua/core/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,30 @@ function Player:distanceTo(other, mode, ignore_dead)
return math.max(ret, 1)
end

--- 比较距离
---@param other Player @ 终点角色
---@param num integer @ 比较基准
---@param operator string @ 运算符,有 ``"<"`` ``">"`` ``"<="`` ``">="`` ``"=="`` ``"~="``
---@return boolean @ 返回比较结果,不计入距离结果永远为false
function Player:compareDistance(other, num, operator)
local distance = self:distanceTo(other)
if distance < 0 or num < 0 then return false end
if operator == ">" then
return distance > num
elseif operator == "<" then
return distance < num
elseif operator == "==" then
return distance == num
elseif operator == ">=" then
return distance >= num
elseif operator == "<=" then
return distance <= num
elseif operator == "~=" then
return distance ~= num
end
return false
end

--- 获取其他玩家是否在玩家的攻击范围内。
---@param other Player @ 其他玩家
---@param fixLimit? integer @ 卡牌距离限制增加专用
Expand Down Expand Up @@ -762,7 +786,12 @@ function Player:hasSkill(skill, ignoreNullified, ignoreAlive)
end

if table.contains(self.player_skills, skill) then
return true
if not skill:isInstanceOf(StatusSkill) then return true end
if self:isInstanceOf(ServerPlayer) then
return not self:isFakeSkill(skill)
else
return table.contains(self.player_skills, skill)
end
end

if self:isInstanceOf(ServerPlayer) and -- isInstanceOf(nil) will return false
Expand All @@ -781,6 +810,20 @@ function Player:hasSkill(skill, ignoreNullified, ignoreAlive)
return false
end

--- 技能是否亮出
---@param skill string | Skill
---@return boolean
function Player:hasShownSkill(skill, ignoreNullified, ignoreAlive)
if not self:hasSkill(skill, ignoreNullified, ignoreAlive) then return false end

if self:isInstanceOf(ServerPlayer) then
return not self:isFakeSkill(skill)
else
if type(skill) == "string" then skill = Fk.skills[skill] end
return table.contains(self.player_skills, skill)
end
end

--- 为玩家增加对应技能。
---@param skill string | Skill @ 技能名
---@param source_skill? string | Skill @ 本有技能(和衍生技能相对)
Expand Down Expand Up @@ -1137,4 +1180,14 @@ function Player:compareGenderWith(other, diff)
end
end

--- 是否为男性(包括双性)。
function Player:isMale()
return self.gender == General.Male or self.gender == General.Bigender
end

--- 是否为女性(包括双性)。
function Player:isFemale()
return self.gender == General.Female or self.gender == General.Bigender
end

return Player
Loading

0 comments on commit 61b18c4

Please sign in to comment.