diff options
| author | Somhairle H. Marisol <[email protected]> | 2026-09-28 23:55:20 +0800 |
|---|---|---|
| committer | Somhairle H. Marisol <[email protected]> | 2026-09-28 23:55:20 +0800 |
| commit | 3669d9710e3783c325385a5648766b798d20ec77 (patch) | |
| tree | 5fc618616b4a2eab252ea3bb1c32dd5b1f9ddc36 /src/LivingVillage.Desktop/PlayerTrade.fs | |
| parent | 6ea696b31ea342e43b61cf16aa1b3378a2bc68a3 (diff) | |
| download | living-village-3669d9710e3783c325385a5648766b798d20ec77.tar.gz | |
p54: 当日任务玩家可见与可完成——Kernel 状态机接入真实事件/环境信号(接受/对话/交易/到达/夜水边),HUD 短中文反馈 + 任务面板接受提示 + v3 任务态往返与 save(None) 兼容 + LV_P54_SHOT 证据
Diffstat (limited to 'src/LivingVillage.Desktop/PlayerTrade.fs')
| -rw-r--r-- | src/LivingVillage.Desktop/PlayerTrade.fs | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/src/LivingVillage.Desktop/PlayerTrade.fs b/src/LivingVillage.Desktop/PlayerTrade.fs index e1ea53e..540445d 100644 --- a/src/LivingVillage.Desktop/PlayerTrade.fs +++ b/src/LivingVillage.Desktop/PlayerTrade.fs @@ -100,25 +100,22 @@ module PlayerTrade = let private replaceNpc (npc: Npc) (world: World) : World = { world with Npcs = world.Npcs |> Array.map (fun current -> if current.Id = npc.Id then npc else current) } - let private recordTrade - (buyer: NpcId) - (seller: NpcId) - (item: ItemKind) - (quantity: int) - (unitPrice: float32) - (world: World) - : World = - let event = - { Tick = world.Tick - Kind = TradeEvent(buyer, seller, item, quantity, unitPrice) } + let private recordTrade (event: InteractionEvent) (world: World) : World = let entry = { Tick = world.Tick Kind = TradeAnnal event Summary = - sprintf "trade tick=%d buyer=%A seller=%A item=%A quantity=%d price=%.2f" - world.Tick buyer seller item quantity unitPrice } + match event.Kind with + | TradeEvent(buyer, seller, item, quantity, unitPrice) -> + sprintf "trade tick=%d buyer=%A seller=%A item=%A quantity=%d price=%.2f" + world.Tick buyer seller item quantity unitPrice + | _ -> 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 + let private failure (state: Occupation.State option) (world: World) (message: string) : Outcome = { World = world; Occupation = state; Succeeded = false; UnitPrice = None; Message = message } @@ -158,13 +155,19 @@ module PlayerTrade = { seller.Mind with Needs = { seller.Mind.Needs with Money = seller.Mind.Needs.Money + total } Memory = recordMemory world.Tick (Sold(playerId, item, quantity, unitPrice)) seller.Mind.Memory } } + let tradeEvent = + { Tick = world.Tick + Kind = TradeEvent(playerId, counterparty, item, quantity, unitPrice) } let nextWorld = world |> (fun w -> { w with Avatar = { w.Avatar with Mind = avatarMind } }) |> replaceNpc updatedSeller - |> recordTrade playerId counterparty item quantity unitPrice + |> recordTrade tradeEvent + let nextOccupation = + { occupation with Backpack = changeBackpack item quantity occupation.Backpack } + |> advanceOccupation tradeEvent { World = nextWorld - Occupation = Some { occupation with Backpack = changeBackpack item quantity occupation.Backpack } + Occupation = Some nextOccupation Succeeded = true UnitPrice = Some unitPrice Message = sprintf "买入%s ×%d,单价 %.2f" (itemName item) quantity unitPrice } @@ -205,13 +208,19 @@ module PlayerTrade = { buyer.Mind with Needs = { buyer.Mind.Needs with Money = buyer.Mind.Needs.Money - total } Memory = recordMemory world.Tick (Bought(playerId, item, quantity, unitPrice)) buyer.Mind.Memory } } + let tradeEvent = + { Tick = world.Tick + Kind = TradeEvent(counterparty, playerId, item, quantity, unitPrice) } let nextWorld = world |> (fun w -> { w with Avatar = { w.Avatar with Mind = avatarMind } }) |> replaceNpc updatedBuyer - |> recordTrade counterparty playerId item quantity unitPrice + |> recordTrade tradeEvent + let nextOccupation = + { occupation with Backpack = changeBackpack item -quantity occupation.Backpack } + |> advanceOccupation tradeEvent { World = nextWorld - Occupation = Some { occupation with Backpack = changeBackpack item -quantity occupation.Backpack } + Occupation = Some nextOccupation Succeeded = true UnitPrice = Some unitPrice Message = sprintf "卖出%s ×%d,单价 %.2f" (itemName item) quantity unitPrice } |
