Line data Source code
1 : package query
2 :
3 : import (
4 : "github.com/kijimaD/ruins/internal/consts"
5 : "github.com/kijimaD/ruins/internal/rawschema"
6 : w "github.com/kijimaD/ruins/internal/world"
7 : "github.com/mlange-42/ark/ecs"
8 : )
9 :
10 : // 価格倍率
11 : const (
12 : BuyPriceMultiplier = 2.0 // 購入価格は価値の2倍
13 : SellPriceMultiplier = 0.5 // 売却価格は価値の半分
14 : )
15 :
16 : // CalculateBuyPrice は購入価格を計算する(価値の2倍)
17 : func CalculateBuyPrice(baseValue int) consts.Currency {
18 1 : return consts.Currency(float64(baseValue) * BuyPriceMultiplier)
19 1 : }
20 :
21 : // CalculateSellPrice は売却価格を計算する(価値の半分)
22 : func CalculateSellPrice(baseValue int) consts.Currency {
23 1 : return consts.Currency(float64(baseValue) * SellPriceMultiplier)
24 1 : }
25 :
26 : // BuyPrice はプレイヤーが entity を買うときの、交渉スキルの買値倍率込みの購入価格を返す。
27 : // base は価値と個数の積。店頭の表示価格と取引価格をこの1関数で揃える
28 : func BuyPrice(world w.World, player ecs.Entity, entity ecs.Entity) consts.Currency {
29 1 : base := GetItemValue(world, entity) * GetEntityCount(world, entity)
30 1 : price := CalculateBuyPrice(base)
31 1 : return consts.Currency(ProficiencyValue(world, player, rawschema.ProficiencyIdBuyPrice).ApplyInt(int(price)))
32 1 : }
33 :
34 : // SellPrice はプレイヤーが entity を売るときの、交渉スキルの売値倍率込みの売却価格を返す。
35 : // base は価値と個数の積。店頭の表示価格と取引価格をこの1関数で揃える。
36 : // 無価値な品は素直に 0 を返す。売却自体は他の品と同様に可能で、対価が 0 になるだけ
37 : func SellPrice(world w.World, player ecs.Entity, entity ecs.Entity) consts.Currency {
38 1 : base := GetItemValue(world, entity) * GetEntityCount(world, entity)
39 1 : price := CalculateSellPrice(base)
40 1 : return consts.Currency(ProficiencyValue(world, player, rawschema.ProficiencyIdSellPrice).ApplyInt(int(price)))
41 1 : }
42 :
43 : // GetItemValue はアイテムの基本価値を取得する
44 : func GetItemValue(world w.World, entity ecs.Entity) int {
45 1 : if !world.Components.Value.Has(entity) {
46 1 : return 0
47 1 : }
48 1 : return world.Components.Value.Get(entity).Value
49 : }
|