local systrannpcmetamo = 99262 --寄售Npc形象
local systrannpcmap = 1000 --寄售Npc所在地图
local systrannpcposx = 241 --寄售Npc x坐标
local systrannpcposy = 103 --寄售Npc y坐标
local systrannpcdir = 6 --寄售Npc方向
local systrannpcname = "金币商人阿芙拉" --寄售Npc名字
local maxgold = 100000000--系统上限魔币
local maxitem = 1000000--收购上限的阿尔卡迪亚金币数量
----------------------------------
local gold_itemnum = 79500--阿尔卡迪亚金币编号
local base_stack = 99999--阿尔卡迪亚金币叠加上限
local base_Price = base_Price or 3000--基础1枚阿尔卡迪亚金币的价格
local min_Price = 2300--最低收购价格
local max_Price = 3500--最高收购价格
local base_quantity = base_quantity or 0--基础阿尔卡迪亚金币的数量
local limit_Price = 2850 --警戒价格,低于这个价格,每15分钟会提高1%基础base_Price价格
----------------------------------
----------------------------------
Global_Reg.RegInit("Gold_consign_inte");--注册创建NPC事件
function Gold_consign_inte()
Gold_consign_NPC();
Gold_consign_NPC2();--loop用NPC
return 0;
end
function Gold_consign_NPC(npc)
if npc == nil or npc < 0 then
npc = NL.CreateNpc(nil,"Gold_consign_NPC_event")
end
Char.SetData(npc,%对象_形象%,systrannpcmetamo)
Char.SetData(npc,%对象_原形%,systrannpcmetamo)
Char.SetData(npc,%对象_地图%,systrannpcmap)
Char.SetData(npc,%对象_X%,systrannpcposx)
Char.SetData(npc,%对象_Y%,systrannpcposy)
Char.SetData(npc,%对象_方向%,systrannpcdir)
Char.SetData(npc,%对象_原名%,systrannpcname)
NLG.UpChar(npc)
LuaNpcIndex["Gold_consign"]=npc;--GA无需填写,GP需要填写
Char.SetTalkedEvent(nil, "Gold_consign_talk",npc)
Char.SetWindowTalkedEvent(nil,"Gold_consign_window",npc)
return true
end
function Gold_consign_NPC2(npc)
if npc == nil or npc < 0 then
npc = NL.CreateNpc(nil,"Gold_consign_NPC_event")
end
Char.SetData(npc,%对象_形象%,systrannpcmetamo)
Char.SetData(npc,%对象_原形%,systrannpcmetamo)
Char.SetData(npc,%对象_地图%,777)
Char.SetData(npc,%对象_X%,47)
Char.SetData(npc,%对象_Y%,47)
Char.SetData(npc,%对象_方向%,systrannpcdir)
Char.SetData(npc,%对象_原名%,systrannpcname)
NLG.UpChar(npc)
Char.SetLoopEvent(nil, "Gold_consign_loop",npc,900000)--15分钟loop一次
return true
end
function Gold_consign_NPC_event(index)
return true;
end
function Gold_consign_start()
local up ="SELECT * FROM tbl_Gold_consign"
local resset = SQL.Run(up)
if(type(resset) == "table")then
base_quantity=tonumber(resset["0_0"]);
base_Price=tonumber(resset["0_1"]);
end
return 0
end
function Gold_consign_down()
local up ="update tbl_Gold_consign set quantity='"..base_quantity.."',Price='"..base_Price.."'"
SQL.Run(up)
end
function Gold_consign_loop(npc)
if base_quantity>max_Price then
local num = math.random(2,4)
base_quantity = math.floor(base_quantity*(1-num/100))
base_Price = math.floor(base_Price*1.01)
end
if base_Price<limit_Price then
base_Price=math.floor(base_Price*1.01)
end
local up ="update tbl_Gold_consign set quantity='"..base_quantity.."',Price='"..base_Price.."'"
SQL.Run(up)
return 0
end
function Gold_consign_talk(npc,player)
if NLG.CanTalk(npc,player) == false then
return
end
local msg = "7\n@p("..systrannpcmetamo..",130,190) 您好,我是金币商人阿芙拉,想购买或者出售\n $4《阿尔卡迪亚金币》$0吗?\n\n 当前阿尔卡迪亚金币库存 4"..base_quantity.."$0枚\n 当前出售价格 8"..base_Price.."$0魔币\n 当前收购价格 8"..math.floor(base_Price*0.95).."$0魔币\n\n 「我想$4购买$0阿尔卡迪亚金币」\n 「我想$4出售$0阿尔卡迪亚金币」"
NLG.ShowWindowTalked(player,2,2,1,msg,npc)
end
function Gold_consign_window(npc,player,_Seqno,_Select,_Data)
--print("\n _Seqno是:"..(_Seqno or "空").."它的类型是"..type(_Seqno).."\n _Select是:".. (_Select or "空").."它的类型是"..type(_Select).."\n _Data是:"..(_Data or "空").."它的类型是"..type(_Data))
if _Select ~= 2 then
if _Seqno ==1 then
if _Data=="1" then--购买
local msg = "99262|金币商人阿芙拉|您需要买几枚金币呢?|\n你的钱不够!|您的道具栏放不下了\n\n请检查$4当页背包$0是否有足够空位"..lua_Gold_consign_msg(gold_itemnum,base_Price,1)..lua_Gold_consign_msg(gold_itemnum,base_Price*10,2)..lua_Gold_consign_msg(gold_itemnum,base_Price*100,3)
NLG.ShowWindowTalked(player,6,2,2,msg,npc)
elseif _Data=="2" then--出售
local msg = "99262|金币商人阿芙拉|您需要卖几枚阿尔卡迪\n亚金币呢?|\n你的阿尔卡迪亚金币不够!|您的道具栏放不下了\n\n请检查$4当页背包$0是否有足够空位|"..gold_itemnum.."|阿尔卡迪亚金币|装满金币的钱袋|27403|1|"..base_stack.."|\n每出售一枚$4阿尔卡迪亚金币$0可获得\n$4"..math.floor(base_Price*0.95).."魔币\n$9当贩卖数量极多并影响收购价格时将$9会依据浮动后的收购价格,以税收方 $9式$4自动扣除$9高于市价比例的魔币\n\n$5备注:按住Shift可添加10枚数量$0"
NLG.ShowWindowTalked(player,28,2,3,msg,npc)
end
elseif _Seqno==2 then--成功购买
local newinfo = Split(_Data,"|")
local long = tablength(newinfo)
local num = 0
if long==2 then
local item1 = tonumber(newinfo[1])
if item1==0 then
num = num + tonumber(newinfo[2])
elseif item1==1 then
num = num + tonumber(newinfo[2])*10
elseif item1==2 then
num = num + tonumber(newinfo[2])*100
end
elseif long==4 then
local item1 = tonumber(newinfo[1])
if item1==0 then
num = num + tonumber(newinfo[2])
elseif item1==1 then
num = num + tonumber(newinfo[2])*10
elseif item1==2 then
num = num + tonumber(newinfo[2])*100
end
local item1 = tonumber(newinfo[3])
if item1==0 then
num = num + tonumber(newinfo[4])
elseif item1==1 then
num = num + tonumber(newinfo[4])*10
elseif item1==2 then
num = num + tonumber(newinfo[4])*100
end
elseif long==6 then
local item1 = tonumber(newinfo[1])
if item1==0 then
num = num + tonumber(newinfo[2])
elseif item1==1 then
num = num + tonumber(newinfo[2])*10
elseif item1==2 then
num = num + tonumber(newinfo[2])*100
end
local item1 = tonumber(newinfo[3])
if item1==0 then
num = num + tonumber(newinfo[4])
elseif item1==1 then
num = num + tonumber(newinfo[4])*10
elseif item1==2 then
num = num + tonumber(newinfo[4])*100
end
local item1 = tonumber(newinfo[5])
if item1==0 then
num = num + tonumber(newinfo[6])
elseif item1==1 then
num = num + tonumber(newinfo[6])*10
elseif item1==2 then
num = num + tonumber(newinfo[6])*100
end
end
if base_quantity<num then
NLG.SystemMessage(player,"[阿芙拉]当前阿尔卡迪亚金币库存只剩下"..base_quantity.."个啦")
else
local gold = num*base_Price
if lua_Gold_consign_help(player,-gold)>=0 then
--NLG.SystemMessage(player,"您一次购买了大量阿尔卡迪亚金币,收取额外手续费"..(gold-oldgold).."魔币")
local bili = math.floor(num/100)
if num>20 and num<100 then
base_Price = math.floor(base_Price*1.01)
elseif bili~=0 then
for i=1,bili do
base_Price = math.floor(base_Price*1.01)
end
end
if base_Price>max_Price then
base_Price=max_Price
end
NLG.AddGold(player,-gold)
NLG.GiveItem(player,gold_itemnum,num)
base_quantity = base_quantity - num
else
NLG.SystemMessage(player,"您的钱不够了")
end
end
elseif _Seqno==3 then--成功贩卖
local newinfo = Split(_Data,"|")
local num = tonumber(newinfo[2])--贩卖数量
if (num+base_quantity)>maxitem then
NLG.SystemMessage(player,"[阿芙拉]我的钱只能再收购"..(maxitem-base_quantity).."枚阿尔卡迪亚金币了")
else
local gold = num*math.floor(base_Price*0.95)
local oldgold = math.floor(base_Price*0.95)
if lua_Gold_consign_help(player,gold)>=0 then
local itemNum = Char.ItemNum(player,gold_itemnum)
if itemNum>=num then
local bili = math.floor(num/100)
--[[if bili==0 then
bili=1
end--]]
if bili~=0 then
for i=1,bili do
base_Price = math.floor(base_Price*0.988)
end
else
base_Price = math.floor(base_Price*0.988)
end
if base_Price<min_Price then
base_Price=min_Price
end
local ewsxf = 0
if bili~=0 then
for i=1,bili do
--NLG.SystemMessage(player,"执行1次")
if i==bili then
ewsxf= ewsxf + (num-100*(bili-1))*oldgold
break
end
ewsxf=ewsxf + oldgold*100
oldgold=oldgold*0.975
if oldgold<min_Price then
oldgold=min_Price
end
end
ewsxf = math.floor(gold-ewsxf)
NLG.SystemMessage(player,"您一次寄售了大量阿尔卡迪亚金币,收取额外手续费"..ewsxf.."魔币")
end
NLG.AddGold(player,gold-ewsxf)
NLG.DelItem(player,gold_itemnum,num)
base_quantity = base_quantity + num
else
NLG.SystemMessage(player,"你没有那么多阿尔卡迪亚金币")
end
else
NLG.SystemMessage(player,"您装不下那么多钱了")
end
end
elseif _Seqno==100 then--从其他地方打开寄售平台
local msg = "7\n@p("..systrannpcmetamo..",130,190) 您好,我是金币商人阿芙拉,想购买或者出售\n $4《阿尔卡迪亚金币》$0吗?\n\n 当前阿尔卡迪亚金币库存 4"..base_quantity.."$0枚\n 当前出售价格 8"..base_Price.."$0魔币\n 当前收购价格 8"..math.floor(base_Price*0.95).."$0魔币\n\n 「我想$4购买$0阿尔卡迪亚金币」\n 「我想$4出售$0阿尔卡迪亚金币」"
NLG.ShowWindowTalked(player,2,2,1,msg,npc)
end
end
end
function lua_Gold_consign_msg(itemid,gold,mold)
if gold==nil then
gold=1
end
local msg = "|"
local iteminfo = Item.MakeItemStatusDateString(itemid)
local newinfo = Split(iteminfo,"|")
local name = newinfo[1]
if mold==1 then
name=name.."1枚"
elseif mold==2 then
name=name.."10枚"
elseif mold==3 then
name=name.."100枚"
end
local itemmsg = newinfo[3]
itemmsg = string.gsub(itemmsg,"\\S"," ")
itemmsg = string.gsub(itemmsg,"\\\\","\\")
local img = newinfo[4]
msg = msg..name.."|"..img.."|"..gold.."|"..itemmsg.."|1|"..base_stack
return msg
end
function lua_Gold_consign_help(player,value)
local gold = Char.GetData(player,%对象_金币%) + value
if gold >= 0 and gold <= maxgold then
return gold
else
return -1
end
end
Gold_consign_start()
|
|