Interface | Params |
---|---|
Buy | [
"arg_country",
"arg_num"
] |
Withdraw | [] |
init | [] |
Method | Caller | Call time | Transaction |
---|---|---|---|
Buy |
2020-11-05 22:51:56
| ||
Buy |
2020-11-05 22:50:12
| ||
Buy |
2020-11-05 20:05:08
| ||
Buy |
2020-11-05 19:57:06
| ||
Buy |
2020-11-05 19:55:38
| ||
Buy |
2020-11-05 19:55:28
| ||
Buy |
2020-11-05 19:55:18
| ||
init |
2020-11-05 19:54:58
| ||
Withdraw |
2020-11-05 19:17:24
| ||
Withdraw |
2020-11-05 19:11:24
| ||
Buy |
2020-11-05 19:02:44
| ||
Buy |
2020-11-05 19:02:32
| ||
Buy |
2020-11-05 19:02:22
| ||
Withdraw |
2020-11-05 19:02:00
| ||
init |
2020-11-05 19:01:54
| ||
Buy |
2020-11-05 19:01:12
| ||
Buy |
2020-11-05 18:59:40
| ||
Buy |
2020-11-05 18:52:50
| ||
Buy |
2020-11-05 18:48:54
| ||
Withdraw |
2020-11-05 18:48:42
|
local function _read_data()
-- 读数据
read_list = {public_data = {}, private_data = {}}
chainhelper:read_chain()
end
local function _save_data()
-- 写数据
read_list = {public_data = {}, private_data = {}}
chainhelper:write_chain()
end
function init()
assert(chainhelper:is_owner(), "#没有权限#")
_read_data()
assert(public_data.count == nil, "#游戏已经开始了#");
public_data = {
count = 0,
timestamp = chainhelper:time(),
countrys = {
wei = {num = 0, price = 0},
shu = {num = 0, price = 0},
wu = {num = 0, price = 0}
}
}
_save_data()
end
function Buy(arg_country, arg_num)
-- 增兵
_read_data()
arg_num = math.floor(arg_num)
if private_data.countrys == nil then
private_data.countrys ={
wei = {num = 0, price = 0},
shu = {num = 0, price = 0},
wu = {num = 0, price = 0}
}
end
local public_country = public_data.countrys[country]
local private_country = private_data.countrys[country]
if public_data.num ~= 0 then
public_country.price = public_country.price + num/public_country.num
end
if private_country.num == 0 then
private_country.price = public_country.price
else
local sub_price = public_country.price - private_data.price
local bonus_total = sub_price * private_country.num
local proportion = bonus_total / (private_country.num + arg_num)
local new_sub_price = public_country.price - proportion
private_data.price = new_sub_price
end
private_country.num = private_country.num + arg_num
public_data.countrys[country].num = public_data.countrys[country].num + arg_num
_save_data()
end
function Withdraw()
-- 撤兵
end