coopani-world-journey 2.2.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # 更新日志
2
2
 
3
+ ## 2.3.0 — 2026-11-21(钱不够就别接约:算的是整趟,不是一张票)
4
+
5
+ Mr.Q:「钱不够最好让她不要接邀约比较好(花销开关打开的情况下)」。
6
+
7
+ 原来 `takeInvite` 只判了**票**买不买得起(余钱的一半)。可一趟约不是一张票 ——
8
+ 她还得在那儿住几天、吃几天。票买得起、到了那儿第三晚就住不起,第二天只能往回走,
9
+ 那和「买不起票」是同一种难看,只是晚了三天。
10
+
11
+ - **新增「整趟撑得住吗」判据**:`需要 = 票(每段最便宜那张)+(最便宜的一张床 + 一天饭钱)× 天数`,
12
+ 超过余钱就不接。有会合点时两段票都算。
13
+ - **床价不掷骰子**(`cheapestBed()`):同一份状态接不接得上一条约,不该看运气。
14
+ 系数、地板和 `rollLodging` 同一套,不另写一份算价规则。
15
+ - **发约也拦**:自己撑不住的约别发出去 —— 别人接了,到那天只能取消,那边白等一场。
16
+ - **回执把四笔数摆出来**(票 / 床 / 饭 / 手上有多少),否则她只能笼统说「钱不够」,
17
+ 用户没法判断是不是自己预算填错了。
18
+ - **记账关着时一个字不管**:`purseLeft()` 是 `null` 就一律放行,老行为不变。
19
+
20
+ 测试:新增 `test/pledge-purse.test.mjs`(5 条:床价可重放、无钱概念放行、三档预算、
21
+ 接约被拦且回执带数字、钱够照常接)。全量 1189/1189 + `ui-smoke` 25/25。
22
+
3
23
  ## 2.2.1 — 2026-11-21(相册点开看大图)
4
24
 
5
25
  读者来信:「在这个界面做一个一键放大……有时候复制原图路径后打开是一堆桌面的截屏」。
package/README.md CHANGED
@@ -197,6 +197,11 @@ https://cooppetsjourney.top
197
197
  一天最多发 3 条、接 1 条。她在家歇着、在路上、或者已经在往回走的时候接不了 ——
198
198
  那几种状态下这条约一定兑现不了,接了比不接难看。
199
199
 
200
+ **钱不够也不接(2.3.0)。** 打开「记花销」之后,接约前会先算一遍整趟:
201
+ 票钱 + 在那座城住几天、吃几天,超过手上能动的钱就不接,并且把「票 / 一张床 / 一天饭钱 / 还剩多少」
202
+ 四笔数说清楚。发约也一样 —— 自己撑不住的约不往外发。**记账关着时这条不生效**,
203
+ 跟以前完全一样。
204
+
200
205
  **需要服务端支持。** 上面第 2 步那三张表要一起建;如果服务器还是只实现了碰面的旧版,
201
206
  她会直说「那台还是旧版」,而不是假装发出去了。
202
207
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coopani-world-journey",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
4
4
  "type": "module",
5
5
  "description": "大肥鱼环游世界 · 让桌宠真的出门去旅行:走遍 193 座城市,路上耗着真实时间、按当地作息吃饭看日出、写旅行日记,还能在城里偶遇别人的宠物、月底生成一份手账。(需 Coopani 0.2.17+)",
6
6
  "author": {
@@ -377,6 +377,29 @@ export function rollLodging(
377
377
  return { ...raw, price: withFloor(raw.tier, scaleNum(raw.price, scale)) };
378
378
  }
379
379
 
380
+ /**
381
+ * 这座城最便宜的一张床(只算价,不掷骰子)。
382
+ *
383
+ * ## 为什么要一个「不掷」的版本
384
+ *
385
+ * 用在「接一趟约之前先算整趟撑不撑得住」(2026-11-21,Mr.Q:「钱不够最好让她不要接邀约」)。
386
+ * 那一步要的是**下界**:她到那座城至少要住得下去、吃得上一日三餐。
387
+ *
388
+ * 而 `rollLodging` 是随机的 —— 拿它算判据,同一个决定会时而成立时而不成立:
389
+ * 同一天、同样的钱,接不接得上一条邀约全看那颗骰子。那不像判断,像抽卡。
390
+ *
391
+ * 取 `budget` 与 `dingy` 两张池子里最低的那一档,套上和 `rollLodging`
392
+ * **同一套系数**(国内乘 `priceIdx`、国外乘 `abroadFactor`),
393
+ * 地板也一样走 `withFloor` —— 两处算价不能有第二套规则。
394
+ */
395
+ export function cheapestBed(priceIdx: number, abroad = false, terrain?: Terrain): number {
396
+ const P = poolsOf(abroad, terrain);
397
+ const raw = Math.min(...[...P.budget, ...P.dingy].map((x) => x.price));
398
+ const scale = abroad ? abroadFactor(priceIdx) : priceIdx;
399
+ /* 走 `scaleNum`,不自己 `Math.round` —— 那一行会把价格取整到 10 的倍数,两处算价要同一个数。 */
400
+ return withFloor('dingy', Math.max(1, scaleNum(raw, scale)));
401
+ }
402
+
380
403
  /**
381
404
  * 真名的语义 → 更贴的类别。**档次不动,只换说法。**
382
405
  *
@@ -30,7 +30,7 @@ import { actionsPrompt } from './pet-vocab.ts';
30
30
  import { VersionCheck } from './version-check.ts';
31
31
  import { AMAP_KEY_NAME, IMAGE_KEY_NAME, adoptKey, readKey, type KeyPorts } from './secrets.ts';
32
32
  import {
33
- rollLodging, rerollLodging, withHotel, lodgingLabel,
33
+ rollLodging, rerollLodging, withHotel, lodgingLabel, cheapestBed,
34
34
  type Lodging, type LodgingWant,
35
35
  } from './plan/lodging.ts';
36
36
  import { HotelDirectory } from './geo/hotels.ts';
@@ -573,11 +573,60 @@ export const purseMethods: Record<string, any> = {
573
573
  const left = this.purseLeft();
574
574
  if (left === null) return true;
575
575
  if (left <= 0) return false;
576
- const cheapest = Math.min(...(['bus', 'train', 'plane', 'ship', 'car'] as const)
577
- .map((id) => this.fareOf(id, km, crossBorder)));
576
+ const cheapest = this.cheapestFare(km, crossBorder);
578
577
  return cheapest <= left * 0.8;
579
578
  },
580
579
 
580
+ /** 这一对上最便宜那张票(不问方式,只问价 —— 别问「她会不会挑最便宜的」,那是另一件事)。 */
581
+ cheapestFare(km: number, crossBorder = false): number {
582
+ return Math.min(...(['bus', 'train', 'plane', 'ship', 'car'] as const)
583
+ .map((id) => this.fareOf(id, km, crossBorder)));
584
+ },
585
+
586
+
587
+ /**
588
+ * 接一趟约,**整趟**撑不撑得住(2026-11-21,Mr.Q:「钱不够最好让她不要接邀约」)。
589
+ *
590
+ * ## 为什么票钱那道闸不够
591
+ *
592
+ * `takeInvite` 早就判了「票买不买得起」,判据是 `affordMode` 的一半余钱。
593
+ * 但一趟约不是一张票:她还要在那儿住 `days` 天、吃 `days` 天。
594
+ * 票买得起、到了那儿第三晚就住不起,第二天只能往回走 ——
595
+ * 那和「没买起票」是同一种难看,只是晚了三天。
596
+ *
597
+ * ## 判据只有一条:下界 ≤ 余钱
598
+ *
599
+ * ```
600
+ * 需要 = 票(每段最便宜那张) + (最便宜的一张床 + 一日三餐)× 天数
601
+ * ```
602
+ *
603
+ * - 床用 `cheapestBed()`,**不掷骰子**:同一份状态接不接得上一条约,不该看运气。
604
+ * - 不乘折扣系数:票钱那一层已经卡在「余钱一半」,这里再乘一遍等于双重要求,
605
+ * 结果是她几乎再也接不上任何约。要的是「撑得住」,不是「宽裕」。
606
+ * - 记账关着 / 预算不限时 `purseLeft()` 是 `null` → **一律放行**(老行为一个字不变)。
607
+ *
608
+ * 回执要把四笔数都摆出来,否则她只能笼统说「钱不够」,用户没法判断是不是自己预算填错了。
609
+ */
610
+ pledgeAffordable(
611
+ legs: readonly { readonly km: number; readonly crossBorder?: boolean }[],
612
+ days: number,
613
+ to: City,
614
+ ): {
615
+ ok: boolean; need: number; left: number | null;
616
+ fare: number; bed: number; meals: number; days: number;
617
+ } {
618
+ const left = this.purseLeft();
619
+ const n = Math.min(14, Math.max(1, Math.round(Number(days) || 1)));
620
+ const bed = cheapestBed(to.priceIdx ?? 1, to.country !== 'CN', terrainOf(to));
621
+ /*
622
+ * **票钱取整**。`fareOf` 是 0.33 元/公里那种算式,直接拼进回执会变成
623
+ * 「票 204.60000000000002」—— 浮点尾巴进了给人看的句子,一眼就是机器写的。
624
+ */
625
+ const fare = Math.round(legs.reduce((sum, l) => sum + this.cheapestFare(l.km, l.crossBorder === true), 0));
626
+ const need = fare + (bed + MEALS_PER_DAY) * n;
627
+ return { ok: left === null || need <= left, need, left, fare, bed, meals: MEALS_PER_DAY, days: n };
628
+ },
629
+
581
630
 
582
631
  /**
583
632
  * 买得起哪种票。
@@ -887,6 +887,29 @@ export const socialMethods: Record<string, any> = {
887
887
  if (meetCity && meetCity.id === c.id) meetCity = null;
888
888
 
889
889
  const d = Math.min(14, Math.max(1, Math.round(Number(days) || 2)));
890
+ /*
891
+ * **自己撑不住的约不要发**(2026-11-21,和 `takeInvite` 同一条判据)。
892
+ *
893
+ * 发出去之后别人接了,这趟就变成「她已经答应过的事」—— 到那天发现钱不够,
894
+ * 只能再去取消,那边的人白等一场。**入口拦一次,比事后取消两次便宜。**
895
+ */
896
+ const legs = meetCity
897
+ ? [
898
+ { km: Math.round(distanceKm(here, meetCity)), crossBorder: here.country !== meetCity.country },
899
+ { km: Math.round(distanceKm(meetCity, c)), crossBorder: meetCity.country !== c.country },
900
+ ]
901
+ : [{ km: Math.round(distanceKm(here, c)), crossBorder: here.country !== c.country }];
902
+ const trip = this.pledgeAffordable(legs, d, c);
903
+ if (!trip.ok) {
904
+ return {
905
+ text: `这趟她自己算下来撑不住:票 ${trip.fare} + ${trip.days} 天住吃`
906
+ + `(一张床最低 ${trip.bed}、一天饭钱 ${trip.meals})≈ ${trip.need},`
907
+ + `手上能动用的只有 ${trip.left}。`
908
+ + '先别约人 —— 发出去别人接了,到那天她只能取消,那边白等一场。'
909
+ + '换个近点的地方、少待几天,或者先把花销关掉。',
910
+ isError: true,
911
+ };
912
+ }
890
913
  const r = await sendInvite(meet, {
891
914
  from: here.id,
892
915
  to: c.id,
@@ -1180,6 +1203,33 @@ export const socialMethods: Record<string, any> = {
1180
1203
  isError: true,
1181
1204
  };
1182
1205
  }
1206
+ /*
1207
+ * **整趟撑不住也不接**(2026-11-21,Mr.Q:「钱不够最好让她不要接邀约(花销开关打开的情况下)」)。
1208
+ *
1209
+ * 上面那条只判了票。一趟约不是一张票:她还得在那儿住几天、吃几天。
1210
+ * 票买得起、到了那儿第三晚住不起,第二天只能往回走 —— 和「买不起票」是同一种难看,
1211
+ * 只是晚了三天才丢人。
1212
+ *
1213
+ * 有会合点的时候两段票都要算:去成都的票和从成都去拉萨的票不是一个价。
1214
+ * 记账关着时 `purseLeft()` 是 `null`,`pledgeAffordable` 一律放行 —— 老行为不变。
1215
+ */
1216
+ const legs = useMeet
1217
+ ? [
1218
+ { km: Math.round(distanceKm(here, useMeet)), crossBorder: here.country !== useMeet.country },
1219
+ { km: Math.round(distanceKm(useMeet, dest)), crossBorder: useMeet.country !== dest.country },
1220
+ ]
1221
+ : [{ km, crossBorder: here.country !== firstStop.country }];
1222
+ const trip = this.pledgeAffordable(legs, one.days, dest);
1223
+ if (!trip.ok) {
1224
+ return {
1225
+ text: `这趟她撑不住:票 ${trip.fare}(最便宜那种)+ ${trip.days} 天住吃`
1226
+ + `(一张床最低 ${trip.bed}、一天饭钱 ${trip.meals})≈ ${trip.need},`
1227
+ + `手上能动用的只有 ${trip.left}。`
1228
+ + '先别接 —— 到了那儿住不了两晚就得往回走,比不答应更难看。'
1229
+ + '(要把花销关掉、或者把预算调大,这条才会放开。)',
1230
+ isError: true,
1231
+ };
1232
+ }
1183
1233
  /*
1184
1234
  * **赶得到吗**(2026-11-07 的 invite 档抓到)。
1185
1235
  *