summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Desktop/PlayerTrade.fs
diff options
context:
space:
mode:
authorSomhairle H. Marisol <[email protected]>2026-09-29 00:24:08 +0800
committerSomhairle H. Marisol <[email protected]>2026-09-29 00:24:08 +0800
commita59a4bbe1ab45adb29d1367995230d3f09847d9b (patch)
tree9570b3c7168a6252920138e380e2a9d9cb6f9acf /src/LivingVillage.Desktop/PlayerTrade.fs
parent80c99bc9251e4ca6304761ef9bd88f2724642278 (diff)
downloadliving-village-a59a4bbe1ab45adb29d1367995230d3f09847d9b.tar.gz
p55: 当日任务经济闭环——设计口径物品报酬入账(夜捕鱼×2/送粮食物×1, 其余不发) + 连续完成天数(streak 跨日保留/漏完成清零) + v3 streak 尾段与 save(None) 兼容 + LV_P55_SHOT 证据
Diffstat (limited to 'src/LivingVillage.Desktop/PlayerTrade.fs')
-rw-r--r--src/LivingVillage.Desktop/PlayerTrade.fs28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/LivingVillage.Desktop/PlayerTrade.fs b/src/LivingVillage.Desktop/PlayerTrade.fs
index 540445d..407536c 100644
--- a/src/LivingVillage.Desktop/PlayerTrade.fs
+++ b/src/LivingVillage.Desktop/PlayerTrade.fs
@@ -23,15 +23,12 @@ module PlayerTrade =
Succeeded: bool
/// 成交时的职业偏置后单位价(失败为 None)。
UnitPrice: float32 option
+ /// P55:本次交易若完成当日任务,设计口径发放的物品奖励。
+ Reward: (ItemKind * int) option
/// 面向 HUD 的短中文反馈。
Message: string }
- let private itemName (item: ItemKind) : string =
- match item with
- | Food -> "食物"
- | Fish -> "鱼"
- | Spice -> "香料"
- | Scroll -> "卷轴"
+ let private itemName (item: ItemKind) : string = Occupation.itemNameOf item
let private quantityOf (item: ItemKind) (inventory: Map<ItemKind, int>) : int =
inventory |> Map.tryFind item |> Option.defaultValue 0
@@ -112,12 +109,13 @@ module PlayerTrade =
| _ -> sprintf "trade tick=%d" world.Tick }
Sim.appendAnnal entry { world with Events = world.Events @ [ event ] }
- /// P54:交易事件同时推进当日任务(Offered 须先接受;判定走 Kernel 纯函数)。
- let private advanceOccupation (event: InteractionEvent) (occupation: Occupation.State) : Occupation.State =
- Occupation.advanceTask event occupation
+ /// P54/P55:交易事件同时推进当日任务(Offered 须先接受;判定走 Kernel 纯函数),
+ /// 并把任务的物品奖励一并返回。
+ let private advanceOccupation (event: InteractionEvent) (occupation: Occupation.State) : Occupation.State * (ItemKind * int) option =
+ Occupation.advanceTaskWithReward event occupation
let private failure (state: Occupation.State option) (world: World) (message: string) : Outcome =
- { World = world; Occupation = state; Succeeded = false; UnitPrice = None; Message = message }
+ { World = world; Occupation = state; Succeeded = false; UnitPrice = None; Reward = None; Message = message }
/// 玩家向 `counterparty` 买入 `quantity` 件 `item`。
let buy
@@ -163,13 +161,14 @@ module PlayerTrade =
|> (fun w -> { w with Avatar = { w.Avatar with Mind = avatarMind } })
|> replaceNpc updatedSeller
|> recordTrade tradeEvent
- let nextOccupation =
- { occupation with Backpack = changeBackpack item quantity occupation.Backpack }
+ let nextOccupation, reward =
+ ({ occupation with Backpack = changeBackpack item quantity occupation.Backpack })
|> advanceOccupation tradeEvent
{ World = nextWorld
Occupation = Some nextOccupation
Succeeded = true
UnitPrice = Some unitPrice
+ Reward = reward
Message = sprintf "买入%s ×%d,单价 %.2f" (itemName item) quantity unitPrice }
/// 玩家向 `counterparty` 卖出 `quantity` 件 `item`(须在背包内)。
@@ -216,13 +215,14 @@ module PlayerTrade =
|> (fun w -> { w with Avatar = { w.Avatar with Mind = avatarMind } })
|> replaceNpc updatedBuyer
|> recordTrade tradeEvent
- let nextOccupation =
- { occupation with Backpack = changeBackpack item -quantity occupation.Backpack }
+ let nextOccupation, reward =
+ ({ occupation with Backpack = changeBackpack item -quantity occupation.Backpack })
|> advanceOccupation tradeEvent
{ World = nextWorld
Occupation = Some nextOccupation
Succeeded = true
UnitPrice = Some unitPrice
+ Reward = reward
Message = sprintf "卖出%s ×%d,单价 %.2f" (itemName item) quantity unitPrice }
/// HUD 入口:向 `counterparty` 买 1 件食物。