Skip to content

Commit

Permalink
Fixed wallstreet average purchase price
Browse files Browse the repository at this point in the history
  • Loading branch information
VForiel committed Oct 30, 2023
1 parent bd3ef38 commit 8653dd3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ scoreboard players operation #quantity(%) ctx /= #max_stock ctx

scoreboard players operation #ideal_quantity(%) ctx = #current_stock(%) ctx
scoreboard players operation #ideal_quantity(%) ctx -= #ideal_stock(%) ctx
# Always autorize to buy 10% more than the ideal quantity
scoreboard players operation #ideal_quantity(%) ctx += 10 const

scoreboard players set #tax ctx 0
execute if score #quantity(%) ctx < #ideal_quantity(%) ctx run return 0

scoreboard players operation #ideal_quantity(%) ctx -= 10 const
# Always autorize to buy 10% more than the ideal quantity
execute if score #quantity(%) ctx matches ..10 run return 0

scoreboard players operation #tax ctx = #quantity(%) ctx
scoreboard players operation #tax ctx -= #ideal_quantity(%) ctx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ scoreboard players operation #quantity(%) ctx /= #max_stock ctx

scoreboard players operation #ideal_quantity(%) ctx = #ideal_stock(%) ctx
scoreboard players operation #ideal_quantity(%) ctx -= #current_stock(%) ctx
# Always autorize to sell 10% more than the ideal quantity
scoreboard players operation #ideal_quantity(%) ctx += 10 const

scoreboard players set #tax ctx 0
execute if score #quantity(%) ctx < #ideal_quantity(%) ctx run return 0

scoreboard players operation #ideal_quantity(%) ctx -= 10 const
# Always autorize to sell 10% more than the ideal quantity
execute if score #quantity(%) ctx matches ..10 run return 0

scoreboard players operation #tax ctx = #quantity(%) ctx
scoreboard players operation #tax ctx -= #ideal_quantity(%) ctx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ scoreboard players operation #capacity ctx -= #current_stock ctx
execute if score @s wallstreet.selected_quantity > #client_stock ctx run tag @s add wallstreet.villager.quantity.limited_by_player_stock
execute if score @s wallstreet.selected_quantity > #capacity ctx run tag @s add wallstreet.villager.quantity.limited_by_villager_max_stock

execute if entity @s[tag=wallstreet.villager.quantity.limited_by_player_stock] run say limited_by_player_stock
execute if entity @s[tag=wallstreet.villager.quantity.limited_by_villager_max_stock] run say limited_by_villager_max_stock

scoreboard players operation @s wallstreet.selected_quantity < #max_stock ctx
scoreboard players operation @s wallstreet.selected_quantity < #client_stock ctx

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@

function wallstreet:villager/utils/get_transaction_value
function wallstreet:villager/utils/get_client_purchase_price
function wallstreet:villager/utils/get_client_stock

scoreboard players operation #old_purchase_price ctx = #purchase_price ctx
# Computing the new average price
scoreboard players operation #old ctx = #client_stock ctx
scoreboard players operation #old ctx *= #purchase_price ctx

scoreboard players operation #purchase_price ctx = #transaction_value ctx
scoreboard players operation #purchase_price ctx *= 1000 const
scoreboard players operation #purchase_price ctx /= #quantity ctx

# Computing the new average price
scoreboard players operation #old ctx = #old_quantity ctx
scoreboard players operation #old ctx *= #old_purchase_price ctx

scoreboard players operation #new ctx = #quantity ctx
scoreboard players operation #new ctx *= #purchase_price ctx

scoreboard players operation #weighted_sum ctx = #old ctx
scoreboard players operation #weighted_sum ctx += #new ctx

scoreboard players operation #total_weights ctx = #old_quantity ctx
scoreboard players operation #total_weights ctx = #client_stock ctx
scoreboard players operation #total_weights ctx += #quantity ctx

scoreboard players operation #average_price ctx = #weighted_sum ctx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,12 @@ function wallstreet:villager/utils/get_quantity
scoreboard players operation #transaction_value ctx = #price ctx
scoreboard players operation #transaction_value ctx *= #quantity ctx

# tellraw @a {"text":"----------"}
# tellraw @a [{"text":"Max stock: "},{"score":{"name":"#max_stock","objective":"ctx"}}]
# tellraw @a [{"text":"Current stock: "},{"score":{"name":"#current_stock","objective":"ctx"}}]
# tellraw @a [{"text":"Price/item: "},{"score":{"name":"#price","objective":"ctx"}}]
# tellraw @a [{"text":"Transaction HT: "},{"score":{"name":"#transaction_value","objective":"ctx"}}]
# tellraw @a [{"text":"Quantity: "},{"score":{"name":"#quantity","objective":"ctx"}}]

execute if entity @s[tag=!wallstreet.villager.sell] run function wallstreet:economy_model/get_buy_tax
execute if entity @s[tag=wallstreet.villager.sell] run function wallstreet:economy_model/get_sell_tax

# tellraw @a [{"text":"Tax %: "},{"score":{"name":"#tax","objective":"ctx"}}]

scoreboard players operation #transaction_taxes ctx = #tax ctx
scoreboard players operation #transaction_taxes ctx *= #transaction_value ctx
scoreboard players operation #transaction_taxes ctx /= 100 const

# tellraw @a [{"text":"Taxes: "},{"score":{"name":"#transaction_taxes","objective":"ctx"}}]

execute if entity @s[tag=!wallstreet.villager.sell] run scoreboard players operation #transaction_value ctx += #transaction_taxes ctx
execute if entity @s[tag=wallstreet.villager.sell] run scoreboard players operation #transaction_value ctx -= #transaction_taxes ctx

# tellraw @a [{"text":"Transaction TTC: "},{"score":{"name":"#transaction_value","objective":"ctx"}}]
execute if entity @s[tag=wallstreet.villager.sell] run scoreboard players operation #transaction_value ctx -= #transaction_taxes ctx

0 comments on commit 8653dd3

Please sign in to comment.