classicSequentialRule.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. import { type LonLatPoint } from '../../utils/projection'
  2. import { DEFAULT_GAME_AUDIO_CONFIG } from '../audio/audioConfig'
  3. import { type GameControl, type GameDefinition } from '../core/gameDefinition'
  4. import { type GameEvent } from '../core/gameEvent'
  5. import { type GameEffect, type GameResult } from '../core/gameResult'
  6. import { type GameSessionState } from '../core/gameSessionState'
  7. import { EMPTY_GAME_PRESENTATION_STATE, type GamePresentationState } from '../presentation/presentationState'
  8. import { type HudPresentationState } from '../presentation/hudPresentationState'
  9. import { type MapPresentationState } from '../presentation/mapPresentationState'
  10. import { type RulePlugin } from './rulePlugin'
  11. type ClassicSequentialModeState = {
  12. mode: 'classic-sequential'
  13. phase: 'start' | 'course' | 'finish' | 'done'
  14. }
  15. function getApproxDistanceMeters(a: LonLatPoint, b: LonLatPoint): number {
  16. const avgLatRad = ((a.lat + b.lat) / 2) * Math.PI / 180
  17. const dx = (b.lon - a.lon) * 111320 * Math.cos(avgLatRad)
  18. const dy = (b.lat - a.lat) * 110540
  19. return Math.sqrt(dx * dx + dy * dy)
  20. }
  21. function getScoringControls(definition: GameDefinition): GameControl[] {
  22. return definition.controls.filter((control) => control.kind === 'control')
  23. }
  24. function getSequentialTargets(definition: GameDefinition): GameControl[] {
  25. return definition.controls
  26. }
  27. function getCompletedControlSequences(definition: GameDefinition, state: GameSessionState): number[] {
  28. return getScoringControls(definition)
  29. .filter((control) => state.completedControlIds.includes(control.id) && typeof control.sequence === 'number')
  30. .map((control) => control.sequence as number)
  31. }
  32. function getSkippedControlSequences(definition: GameDefinition, state: GameSessionState): number[] {
  33. return getScoringControls(definition)
  34. .filter((control) => state.skippedControlIds.includes(control.id) && typeof control.sequence === 'number')
  35. .map((control) => control.sequence as number)
  36. }
  37. function getCurrentTarget(definition: GameDefinition, state: GameSessionState): GameControl | null {
  38. return getSequentialTargets(definition).find((control) => control.id === state.currentTargetControlId) || null
  39. }
  40. function getNextTarget(definition: GameDefinition, currentTarget: GameControl): GameControl | null {
  41. const targets = getSequentialTargets(definition)
  42. const currentIndex = targets.findIndex((control) => control.id === currentTarget.id)
  43. return currentIndex >= 0 && currentIndex < targets.length - 1
  44. ? targets[currentIndex + 1]
  45. : null
  46. }
  47. function getCompletedLegIndices(definition: GameDefinition, state: GameSessionState): number[] {
  48. const targets = getSequentialTargets(definition)
  49. const completedLegIndices: number[] = []
  50. for (let index = 1; index < targets.length; index += 1) {
  51. if (state.completedControlIds.includes(targets[index].id)) {
  52. completedLegIndices.push(index - 1)
  53. }
  54. }
  55. return completedLegIndices
  56. }
  57. function getTargetText(control: GameControl): string {
  58. if (control.kind === 'start') {
  59. return '开始点'
  60. }
  61. if (control.kind === 'finish') {
  62. return '终点'
  63. }
  64. return '目标圈'
  65. }
  66. function getGuidanceState(definition: GameDefinition, distanceMeters: number): GameSessionState['guidanceState'] {
  67. const audioConfig = definition.audioConfig || DEFAULT_GAME_AUDIO_CONFIG
  68. const readyDistanceMeters = Math.max(definition.punchRadiusMeters, audioConfig.readyDistanceMeters)
  69. const approachDistanceMeters = Math.max(readyDistanceMeters, audioConfig.approachDistanceMeters)
  70. const distantDistanceMeters = Math.max(approachDistanceMeters, audioConfig.distantDistanceMeters)
  71. if (distanceMeters <= readyDistanceMeters) {
  72. return 'ready'
  73. }
  74. if (distanceMeters <= approachDistanceMeters) {
  75. return 'approaching'
  76. }
  77. if (distanceMeters <= distantDistanceMeters) {
  78. return 'distant'
  79. }
  80. return 'searching'
  81. }
  82. function getGuidanceEffects(
  83. previousState: GameSessionState['guidanceState'],
  84. nextState: GameSessionState['guidanceState'],
  85. controlId: string | null,
  86. ): GameEffect[] {
  87. if (previousState === nextState) {
  88. return []
  89. }
  90. return [{ type: 'guidance_state_changed', guidanceState: nextState, controlId }]
  91. }
  92. function buildPunchHintText(definition: GameDefinition, state: GameSessionState, currentTarget: GameControl | null): string {
  93. if (state.status === 'idle') {
  94. return '先打开始点即可正式开始比赛'
  95. }
  96. if (state.status === 'finished') {
  97. return '本局已完成'
  98. }
  99. if (!currentTarget) {
  100. return '本局已完成'
  101. }
  102. const targetText = getTargetText(currentTarget)
  103. if (state.inRangeControlId !== currentTarget.id) {
  104. return definition.punchPolicy === 'enter'
  105. ? `进入${targetText}自动打点`
  106. : `进入${targetText}后点击打点`
  107. }
  108. return definition.punchPolicy === 'enter'
  109. ? `${targetText}内,自动打点中`
  110. : `${targetText}内,可点击打点`
  111. }
  112. function buildTargetSummaryText(state: GameSessionState, currentTarget: GameControl | null): string {
  113. if (state.status === 'finished') {
  114. return '本局已完成'
  115. }
  116. if (!currentTarget) {
  117. return '等待路线初始化'
  118. }
  119. if (currentTarget.kind === 'start') {
  120. return `${currentTarget.label} / 先打开始点`
  121. }
  122. if (currentTarget.kind === 'finish') {
  123. return `${currentTarget.label} / 前往终点`
  124. }
  125. const sequenceText = typeof currentTarget.sequence === 'number'
  126. ? `第 ${currentTarget.sequence} 点`
  127. : '当前目标点'
  128. return `${sequenceText} / ${currentTarget.label}`
  129. }
  130. function buildSkipFeedbackText(currentTarget: GameControl): string {
  131. if (currentTarget.kind === 'start') {
  132. return '开始点不可跳过'
  133. }
  134. if (currentTarget.kind === 'finish') {
  135. return '终点不可跳过'
  136. }
  137. return `已跳过检查点 ${typeof currentTarget.sequence === 'number' ? currentTarget.sequence : currentTarget.label}`
  138. }
  139. function resolveGuidanceForTarget(
  140. definition: GameDefinition,
  141. previousState: GameSessionState,
  142. target: GameControl | null,
  143. location: LonLatPoint | null,
  144. ): { guidanceState: GameSessionState['guidanceState']; inRangeControlId: string | null; effects: GameEffect[] } {
  145. if (!target || !location) {
  146. const guidanceState: GameSessionState['guidanceState'] = 'searching'
  147. return {
  148. guidanceState,
  149. inRangeControlId: null,
  150. effects: getGuidanceEffects(previousState.guidanceState, guidanceState, target ? target.id : null),
  151. }
  152. }
  153. const distanceMeters = getApproxDistanceMeters(target.point, location)
  154. const guidanceState = getGuidanceState(definition, distanceMeters)
  155. const inRangeControlId = distanceMeters <= definition.punchRadiusMeters ? target.id : null
  156. return {
  157. guidanceState,
  158. inRangeControlId,
  159. effects: getGuidanceEffects(previousState.guidanceState, guidanceState, target.id),
  160. }
  161. }
  162. function buildPresentation(definition: GameDefinition, state: GameSessionState): GamePresentationState {
  163. const scoringControls = getScoringControls(definition)
  164. const sequentialTargets = getSequentialTargets(definition)
  165. const currentTarget = getCurrentTarget(definition, state)
  166. const currentTargetIndex = currentTarget ? sequentialTargets.findIndex((control) => control.id === currentTarget.id) : -1
  167. const completedControls = scoringControls.filter((control) => state.completedControlIds.includes(control.id))
  168. const running = state.status === 'running'
  169. const activeLegIndices = running && currentTargetIndex > 0
  170. ? [currentTargetIndex - 1]
  171. : []
  172. const completedLegIndices = getCompletedLegIndices(definition, state)
  173. const punchButtonEnabled = running && !!currentTarget && state.inRangeControlId === currentTarget.id && definition.punchPolicy === 'enter-confirm'
  174. const activeStart = running && !!currentTarget && currentTarget.kind === 'start'
  175. const completedStart = definition.controls.some((control) => control.kind === 'start' && state.completedControlIds.includes(control.id))
  176. const activeFinish = running && !!currentTarget && currentTarget.kind === 'finish'
  177. const completedFinish = definition.controls.some((control) => control.kind === 'finish' && state.completedControlIds.includes(control.id))
  178. const punchButtonText = currentTarget
  179. ? currentTarget.kind === 'start'
  180. ? '开始打卡'
  181. : currentTarget.kind === 'finish'
  182. ? '结束打卡'
  183. : '打点'
  184. : '打点'
  185. const revealFullCourse = completedStart
  186. const hudPresentation: HudPresentationState = {
  187. actionTagText: '目标',
  188. distanceTagText: '点距',
  189. targetSummaryText: buildTargetSummaryText(state, currentTarget),
  190. hudTargetControlId: currentTarget ? currentTarget.id : null,
  191. progressText: '0/0',
  192. punchButtonText,
  193. punchableControlId: punchButtonEnabled && currentTarget ? currentTarget.id : null,
  194. punchButtonEnabled,
  195. punchHintText: buildPunchHintText(definition, state, currentTarget),
  196. }
  197. const targetingPresentation = {
  198. punchableControlId: punchButtonEnabled && currentTarget ? currentTarget.id : null,
  199. guidanceControlId: currentTarget ? currentTarget.id : null,
  200. hudControlId: currentTarget ? currentTarget.id : null,
  201. highlightedControlId: running && currentTarget ? currentTarget.id : null,
  202. }
  203. if (!scoringControls.length) {
  204. return {
  205. map: {
  206. ...EMPTY_GAME_PRESENTATION_STATE.map,
  207. controlVisualMode: 'single-target',
  208. showCourseLegs: true,
  209. guidanceLegAnimationEnabled: true,
  210. focusableControlIds: [],
  211. focusedControlId: null,
  212. focusedControlSequences: [],
  213. activeStart,
  214. completedStart,
  215. activeFinish,
  216. focusedFinish: false,
  217. completedFinish,
  218. revealFullCourse,
  219. activeLegIndices,
  220. completedLegIndices,
  221. skippedControlIds: [],
  222. skippedControlSequences: [],
  223. },
  224. hud: hudPresentation,
  225. targeting: targetingPresentation,
  226. }
  227. }
  228. const mapPresentation: MapPresentationState = {
  229. controlVisualMode: 'single-target',
  230. showCourseLegs: true,
  231. guidanceLegAnimationEnabled: true,
  232. focusableControlIds: [],
  233. focusedControlId: null,
  234. focusedControlSequences: [],
  235. activeControlIds: running && currentTarget ? [currentTarget.id] : [],
  236. activeControlSequences: running && currentTarget && currentTarget.kind === 'control' && typeof currentTarget.sequence === 'number' ? [currentTarget.sequence] : [],
  237. activeStart,
  238. completedStart,
  239. activeFinish,
  240. focusedFinish: false,
  241. completedFinish,
  242. revealFullCourse,
  243. activeLegIndices,
  244. completedLegIndices,
  245. completedControlIds: completedControls.map((control) => control.id),
  246. completedControlSequences: getCompletedControlSequences(definition, state),
  247. skippedControlIds: state.skippedControlIds,
  248. skippedControlSequences: getSkippedControlSequences(definition, state),
  249. }
  250. return {
  251. map: mapPresentation,
  252. hud: {
  253. ...hudPresentation,
  254. progressText: `${completedControls.length}/${scoringControls.length}`,
  255. },
  256. targeting: targetingPresentation,
  257. }
  258. }
  259. function resolveClassicPhase(nextTarget: GameControl | null, currentTarget: GameControl, finished: boolean): ClassicSequentialModeState['phase'] {
  260. if (finished || currentTarget.kind === 'finish') {
  261. return 'done'
  262. }
  263. if (currentTarget.kind === 'start') {
  264. return nextTarget && nextTarget.kind === 'finish' ? 'finish' : 'course'
  265. }
  266. if (nextTarget && nextTarget.kind === 'finish') {
  267. return 'finish'
  268. }
  269. return 'course'
  270. }
  271. function getInitialTargetId(definition: GameDefinition): string | null {
  272. const firstTarget = getSequentialTargets(definition)[0]
  273. return firstTarget ? firstTarget.id : null
  274. }
  275. function buildCompletedEffect(control: GameControl, punchPolicy: GameDefinition['punchPolicy']): GameEffect {
  276. const allowAutoPopup = punchPolicy === 'enter'
  277. ? false
  278. : (control.displayContent ? control.displayContent.autoPopup : true)
  279. const autoOpenQuiz = control.kind === 'control'
  280. && !!control.displayContent
  281. && control.displayContent.ctas.some((item) => item.type === 'quiz')
  282. if (control.kind === 'start') {
  283. return {
  284. type: 'control_completed',
  285. controlId: control.id,
  286. controlKind: 'start',
  287. sequence: null,
  288. label: control.label,
  289. displayTitle: control.displayContent ? control.displayContent.title : '比赛开始',
  290. displayBody: control.displayContent ? control.displayContent.body : '已完成开始点打卡,前往 1 号点。',
  291. displayAutoPopup: allowAutoPopup,
  292. displayOnce: control.displayContent ? control.displayContent.once : false,
  293. displayPriority: control.displayContent ? control.displayContent.priority : 1,
  294. autoOpenQuiz: false,
  295. }
  296. }
  297. if (control.kind === 'finish') {
  298. return {
  299. type: 'control_completed',
  300. controlId: control.id,
  301. controlKind: 'finish',
  302. sequence: null,
  303. label: control.label,
  304. displayTitle: control.displayContent ? control.displayContent.title : '比赛结束',
  305. displayBody: control.displayContent ? control.displayContent.body : '已完成终点打卡,本局结束。',
  306. displayAutoPopup: allowAutoPopup,
  307. displayOnce: control.displayContent ? control.displayContent.once : false,
  308. displayPriority: control.displayContent ? control.displayContent.priority : 2,
  309. autoOpenQuiz: false,
  310. }
  311. }
  312. const sequenceText = typeof control.sequence === 'number' ? String(control.sequence) : control.label
  313. const displayTitle = control.displayContent ? control.displayContent.title : `完成 ${sequenceText}`
  314. const displayBody = control.displayContent ? control.displayContent.body : control.label
  315. return {
  316. type: 'control_completed',
  317. controlId: control.id,
  318. controlKind: 'control',
  319. sequence: control.sequence,
  320. label: control.label,
  321. displayTitle,
  322. displayBody,
  323. displayAutoPopup: allowAutoPopup,
  324. displayOnce: control.displayContent ? control.displayContent.once : false,
  325. displayPriority: control.displayContent ? control.displayContent.priority : 1,
  326. autoOpenQuiz,
  327. }
  328. }
  329. function applyCompletion(definition: GameDefinition, state: GameSessionState, currentTarget: GameControl, at: number): GameResult {
  330. const completedControlIds = state.completedControlIds.includes(currentTarget.id)
  331. ? state.completedControlIds
  332. : [...state.completedControlIds, currentTarget.id]
  333. const nextTarget = getNextTarget(definition, currentTarget)
  334. const completedFinish = currentTarget.kind === 'finish'
  335. const finished = completedFinish || (!nextTarget && definition.autoFinishOnLastControl)
  336. const nextState: GameSessionState = {
  337. ...state,
  338. endReason: finished ? 'completed' : state.endReason,
  339. startedAt: currentTarget.kind === 'start' && state.startedAt === null ? at : state.startedAt,
  340. completedControlIds,
  341. skippedControlIds: currentTarget.id === state.currentTargetControlId
  342. ? state.skippedControlIds.filter((controlId) => controlId !== currentTarget.id)
  343. : state.skippedControlIds,
  344. currentTargetControlId: nextTarget ? nextTarget.id : null,
  345. inRangeControlId: null,
  346. score: getScoringControls(definition).filter((control) => completedControlIds.includes(control.id)).length,
  347. status: finished ? 'finished' : state.status,
  348. endedAt: finished ? at : state.endedAt,
  349. guidanceState: nextTarget ? 'searching' : 'searching',
  350. modeState: {
  351. mode: 'classic-sequential',
  352. phase: resolveClassicPhase(nextTarget, currentTarget, finished),
  353. },
  354. }
  355. const effects: GameEffect[] = [buildCompletedEffect(currentTarget, definition.punchPolicy)]
  356. if (finished) {
  357. effects.push({ type: 'session_finished' })
  358. }
  359. return {
  360. nextState,
  361. presentation: buildPresentation(definition, nextState),
  362. effects,
  363. }
  364. }
  365. function applySkip(
  366. definition: GameDefinition,
  367. state: GameSessionState,
  368. currentTarget: GameControl,
  369. location: LonLatPoint | null,
  370. ): GameResult {
  371. const nextTarget = getNextTarget(definition, currentTarget)
  372. const nextPhase = nextTarget && nextTarget.kind === 'finish' ? 'finish' : 'course'
  373. const nextGuidance = resolveGuidanceForTarget(definition, state, nextTarget, location)
  374. const nextState: GameSessionState = {
  375. ...state,
  376. skippedControlIds: state.skippedControlIds.includes(currentTarget.id)
  377. ? state.skippedControlIds
  378. : [...state.skippedControlIds, currentTarget.id],
  379. currentTargetControlId: nextTarget ? nextTarget.id : null,
  380. inRangeControlId: nextGuidance.inRangeControlId,
  381. guidanceState: nextGuidance.guidanceState,
  382. modeState: {
  383. mode: 'classic-sequential',
  384. phase: nextTarget ? nextPhase : 'done',
  385. },
  386. }
  387. return {
  388. nextState,
  389. presentation: buildPresentation(definition, nextState),
  390. effects: [
  391. ...nextGuidance.effects,
  392. { type: 'punch_feedback', text: buildSkipFeedbackText(currentTarget), tone: 'neutral' },
  393. ],
  394. }
  395. }
  396. export class ClassicSequentialRule implements RulePlugin {
  397. get mode(): 'classic-sequential' {
  398. return 'classic-sequential'
  399. }
  400. initialize(definition: GameDefinition): GameSessionState {
  401. return {
  402. status: 'idle',
  403. endReason: null,
  404. startedAt: null,
  405. endedAt: null,
  406. completedControlIds: [],
  407. skippedControlIds: [],
  408. currentTargetControlId: getInitialTargetId(definition),
  409. inRangeControlId: null,
  410. score: 0,
  411. guidanceState: 'searching',
  412. modeState: {
  413. mode: 'classic-sequential',
  414. phase: 'start',
  415. },
  416. }
  417. }
  418. buildPresentation(definition: GameDefinition, state: GameSessionState): GamePresentationState {
  419. return buildPresentation(definition, state)
  420. }
  421. reduce(definition: GameDefinition, state: GameSessionState, event: GameEvent): GameResult {
  422. if (event.type === 'session_started') {
  423. const nextState: GameSessionState = {
  424. ...state,
  425. status: 'running',
  426. endReason: null,
  427. startedAt: null,
  428. endedAt: null,
  429. inRangeControlId: null,
  430. guidanceState: 'searching',
  431. modeState: {
  432. mode: 'classic-sequential',
  433. phase: 'start',
  434. },
  435. }
  436. return {
  437. nextState,
  438. presentation: buildPresentation(definition, nextState),
  439. effects: [{ type: 'session_started' }],
  440. }
  441. }
  442. if (event.type === 'session_ended') {
  443. const nextState: GameSessionState = {
  444. ...state,
  445. status: 'finished',
  446. endReason: 'completed',
  447. endedAt: event.at,
  448. guidanceState: 'searching',
  449. modeState: {
  450. mode: 'classic-sequential',
  451. phase: 'done',
  452. },
  453. }
  454. return {
  455. nextState,
  456. presentation: buildPresentation(definition, nextState),
  457. effects: [{ type: 'session_finished' }],
  458. }
  459. }
  460. if (event.type === 'session_timed_out') {
  461. const nextState: GameSessionState = {
  462. ...state,
  463. status: 'failed',
  464. endReason: 'timed_out',
  465. endedAt: event.at,
  466. guidanceState: 'searching',
  467. modeState: {
  468. mode: 'classic-sequential',
  469. phase: 'done',
  470. },
  471. }
  472. return {
  473. nextState,
  474. presentation: buildPresentation(definition, nextState),
  475. effects: [{ type: 'session_timed_out' }],
  476. }
  477. }
  478. if (state.status !== 'running' || !state.currentTargetControlId) {
  479. return {
  480. nextState: state,
  481. presentation: buildPresentation(definition, state),
  482. effects: [],
  483. }
  484. }
  485. const currentTarget = getCurrentTarget(definition, state)
  486. if (!currentTarget) {
  487. return {
  488. nextState: state,
  489. presentation: buildPresentation(definition, state),
  490. effects: [],
  491. }
  492. }
  493. if (event.type === 'gps_updated') {
  494. const distanceMeters = getApproxDistanceMeters(currentTarget.point, { lon: event.lon, lat: event.lat })
  495. const inRangeControlId = distanceMeters <= definition.punchRadiusMeters ? currentTarget.id : null
  496. const guidanceState = getGuidanceState(definition, distanceMeters)
  497. const nextState: GameSessionState = {
  498. ...state,
  499. inRangeControlId,
  500. guidanceState,
  501. }
  502. const guidanceEffects = getGuidanceEffects(state.guidanceState, guidanceState, currentTarget.id)
  503. if (definition.punchPolicy === 'enter' && inRangeControlId === currentTarget.id) {
  504. const completionResult = applyCompletion(definition, nextState, currentTarget, event.at)
  505. return {
  506. ...completionResult,
  507. effects: [...guidanceEffects, ...completionResult.effects],
  508. }
  509. }
  510. return {
  511. nextState,
  512. presentation: buildPresentation(definition, nextState),
  513. effects: guidanceEffects,
  514. }
  515. }
  516. if (event.type === 'punch_requested') {
  517. if (state.inRangeControlId !== currentTarget.id) {
  518. return {
  519. nextState: state,
  520. presentation: buildPresentation(definition, state),
  521. effects: [{ type: 'punch_feedback', text: currentTarget.kind === 'start' ? '未进入开始点打卡范围' : currentTarget.kind === 'finish' ? '未进入终点打卡范围' : '未进入目标打点范围', tone: 'warning' }],
  522. }
  523. }
  524. return applyCompletion(definition, state, currentTarget, event.at)
  525. }
  526. if (event.type === 'skip_requested') {
  527. if (!definition.skipEnabled) {
  528. return {
  529. nextState: state,
  530. presentation: buildPresentation(definition, state),
  531. effects: [{ type: 'punch_feedback', text: '当前配置未开启跳点', tone: 'warning' }],
  532. }
  533. }
  534. if (currentTarget.kind !== 'control') {
  535. return {
  536. nextState: state,
  537. presentation: buildPresentation(definition, state),
  538. effects: [{ type: 'punch_feedback', text: currentTarget.kind === 'start' ? '开始点不可跳过' : '终点不可跳过', tone: 'warning' }],
  539. }
  540. }
  541. if (event.lon === null || event.lat === null) {
  542. return {
  543. nextState: state,
  544. presentation: buildPresentation(definition, state),
  545. effects: [{ type: 'punch_feedback', text: '当前无定位,无法跳点', tone: 'warning' }],
  546. }
  547. }
  548. const distanceMeters = getApproxDistanceMeters(currentTarget.point, { lon: event.lon, lat: event.lat })
  549. if (distanceMeters > definition.skipRadiusMeters) {
  550. return {
  551. nextState: state,
  552. presentation: buildPresentation(definition, state),
  553. effects: [{ type: 'punch_feedback', text: `未进入跳点范围 (${Math.round(definition.skipRadiusMeters)}m)`, tone: 'warning' }],
  554. }
  555. }
  556. return applySkip(
  557. definition,
  558. state,
  559. currentTarget,
  560. { lon: event.lon, lat: event.lat },
  561. )
  562. }
  563. return {
  564. nextState: state,
  565. presentation: buildPresentation(definition, state),
  566. effects: [],
  567. }
  568. }
  569. }