diff options
Diffstat (limited to 'src/LivingVillage.Desktop/PlayerTrade.fs')
| -rw-r--r-- | src/LivingVillage.Desktop/PlayerTrade.fs | 28 |
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 件食物。 |
