Skip to content

Commit

Permalink
1. 武器卡距離加入判斷
Browse files Browse the repository at this point in the history
  • Loading branch information
Parsons committed Jul 6, 2024
1 parent 8fff13c commit e88c44d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
8 changes: 8 additions & 0 deletions assets/weaponFeatures.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"麒麟弓": {
"attackDistance": 5
},
"諸葛連弩": {
"attackDistance": 1
}
}
22 changes: 20 additions & 2 deletions src/classes/MainPlayer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { Card, Player, BattleScene } from './index'
import threeKingdomsCards from '~/assets/cards.json'
import threeKingdomsCardsJson from '~/assets/cards.json'
import { atkLine } from '../utils/drawing'
import { roleMap } from '~/src/utils/domain'
import type { ThreeKingdomsCardIds, ThreeKingdomsGeneralIds } from '~/src/types'
import weaponFeaturesJson from '~/assets/weaponFeatures.json'
import type {
ThreeKingdomsCardIds,
ThreeKingdomsGeneralIds,
ThreeKingdomsCard,
WeaponFeature,
} from '~/src/types'
import Game from './Game'

const threeKingdomsCards: { [key in ThreeKingdomsCardIds]: ThreeKingdomsCard } =
threeKingdomsCardsJson as { [key in ThreeKingdomsCardIds]: ThreeKingdomsCard }
const weaponFeatures: { [key: string]: WeaponFeature } = weaponFeaturesJson
export default class MainPlayer extends Player {
handCards: Card[] = []
selectedCard: Card | null = null
Expand Down Expand Up @@ -319,6 +329,14 @@ export default class MainPlayer extends Player {
if (this.equipments[1]) {
distance -= 1
}
if (this.equipments[3]) {
// 考慮武器攻擊距離
const weaponCard = threeKingdomsCards[this.equipments[3]]
const weaponFeature = weaponFeatures[weaponCard.name]
if (weaponFeature?.attackDistance) {
distance -= weaponFeature.attackDistance - 1
}
}
if (distance > 1) player.setOutOfDistance(true)
})
return
Expand Down
12 changes: 12 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import threeKingdomsCards from '~/assets/cards.json'
import threeKingdomsGenerals from '~/assets/generalCards.json'
import weaponFeatures from '~/assets/weaponFeatures.json'
import { roleMap } from './utils/domain'
export type ThreeKingdomsCardIds = keyof typeof threeKingdomsCards
export type ThreeKingdomsGeneralIds = keyof typeof threeKingdomsGenerals
Expand Down Expand Up @@ -46,3 +47,14 @@ export interface Audios {
shadowrunner: string
redHare: string
}
export interface ThreeKingdomsCard {
id: ThreeKingdomsCardIds
name: string
rank: number
suit: string
audio: string
}

export interface WeaponFeature {
attackDistance: number
}

0 comments on commit e88c44d

Please sign in to comment.