From cedab3ad5acfb7908b35f24c3c47c9538a9caf2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=87=E8=91=A9=E3=81=AE=E7=81=B5=E6=A2=A6?= Date: Wed, 18 Sep 2024 11:00:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8E=A5=E6=83=85=E6=8A=A5?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E7=9A=84=E6=8A=80=E8=83=BD=E9=80=BB=E8=BE=91?= =?UTF-8?q?(resolve=20#293)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/MessageCardValue.kt | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/MessageCardValue.kt b/src/main/kotlin/MessageCardValue.kt index 8ba8adca..f3042a8d 100644 --- a/src/main/kotlin/MessageCardValue.kt +++ b/src/main/kotlin/MessageCardValue.kt @@ -222,6 +222,9 @@ fun Player.calculateMessageCardValue( override fun canUse(g: Game, r: Player, vararg args: Any) = false override fun execute(g: Game, r: Player, vararg args: Any) = Unit } + fun merge(a: Int, b: Int): Int = + if (a == 600 || b == 600) 600 // 其中一个已经赢了,就是赢了,以防共赢的情况下还非要出牌拦敌方 + else a + b if (colors.size == 2 && inFrontOfWhom.skills.any { it is JinShen }) { // 金生火 var valueInFrontOfWhom = 0 for (c in inFrontOfWhom.cards.toList()) { @@ -244,7 +247,7 @@ fun Player.calculateMessageCardValue( } } logger.debug("这是[邵秀]传出的情报,计算[绵里藏针]额外分数为$valueMe") - v1 += valueMe + v1 = merge(v1, valueMe) inFrontOfWhom.messageCards.removeLast() } if (Black in colors && inFrontOfWhom.skills.any { it is YiYaHuanYa }) { // 王魁 @@ -260,7 +263,7 @@ fun Player.calculateMessageCardValue( } } } - v1 += valueMe + v1 = merge(v1, valueMe) logger.debug("这是[王魁]传出的情报,计算[以牙还牙]额外分数为$valueMe") inFrontOfWhom.messageCards.removeLast() } @@ -276,11 +279,11 @@ fun Player.calculateMessageCardValue( } } logger.debug("这是[SP小九]传出的情报,计算[赤子之心]额外分数为$valueMe") - v1 += when { + v1 = merge(v1, when { valueSender > 30 -> valueMe isPartnerOrSelf(sender) -> 20 else -> -20 - } + }) inFrontOfWhom.messageCards.removeLast() } // TODO CP韩梅还要判断一下拿牌,这里就暂时先不写了 @@ -291,16 +294,16 @@ fun Player.calculateMessageCardValue( var valueMe = 0 if (v > 0) valueMe = calculateMessageCardValue(whoseTurn, inFrontOfWhom, listOf(Black)) logger.debug("这是[CP韩梅]传出的情报,计算[暗藏杀机]额外分数为$valueMe") - v1 += valueMe + v1 = merge(v1, valueMe) } inFrontOfWhom.messageCards.removeLast() } fun addScore(p: Player, score: Int) { if (p.identity != Black) { // 军潜:己方加分,敌方减分,神秘人不管 - if (identity == p.identity) v1 += score - if (identity != p.identity && identity != Black) v1 -= score + if (identity == p.identity) v1 = merge(v1, score) + if (identity != p.identity && identity != Black) v1 = merge(v1, -score) } else if (p === this) { // 神秘人:自己加分,其他人不管 - v1 += score + v1 = merge(v1, score) } } if (Black in colors && inFrontOfWhom.skills.any { it is ShiSi }) { // 老汉【视死】 @@ -363,7 +366,7 @@ fun Player.calculateMessageCardValue( } } } - v1 += myValue + v1 = merge(v1, myValue) } if (Black in colors && inFrontOfWhom.skills.any { it is RuGui } && inFrontOfWhom.messageCards.count(Black) == 2) { // 老汉【如归】 @@ -377,7 +380,7 @@ fun Player.calculateMessageCardValue( myValue = calculateMessageCardValue(whoseTurn, whoseTurn, mCard) } } - v1 += myValue + v1 = merge(v1, myValue) } } }