⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 npcsdk.lua

📁 top web admin panel (tales of pirates)
💻 LUA
📖 第 1 页 / 共 5 页
字号:
	WriteByte( packet, tradetype )
	WriteDword( packet, p1 )

	local typecount = 0
	for i = 1, 4, 1 do
		if trade[i] ~= nil then
			typecount = typecount + 1
		else
			break
		end
	end
	WriteByte( packet, typecount )
	PRINT( "SendTradePage: typecount = ", typecount )

	for i = 1, typecount, 1 do
		if trade[i].itemtype ~= nil and trade[i].count ~= nil and trade[i].item ~= nil then
			if trade[i].count > 120 then
				trade[i].count = 120
			end
			PRINT( "SendTradePage: itemtype = ,  count = ", trade[i].itemtype, trade[i].count )
			WriteByte( packet, trade[i].itemtype )
			WriteByte( packet, trade[i].count )
			--写入物品ID数据
			for n = 1, trade[i].count, 1 do
				if trade[i].item[n] ~= nil then
					if tradetype == TRADE_GOODS then
						PRINT( "SendTradePage:writedword : id =, count =, price =, tradetp ", trade[i].item[n].id, trade[i].item[n].count, trade[i].price[n].curprice, tradetype )
						WriteWord( packet, trade[i].item[n].id )
						WriteWord( packet, trade[i].item[n].count )
						WriteDword( packet, trade[i].price[n].curprice )
						WriteByte( packet, trade[i].item[n].level )
					else
						WriteWord( packet, trade[i].item[n] )
					end
				else
					WriteWord( packet, ROLE_INVALID_ID )
					if tradetype == TRADE_GOODS then
						WriteDword( packet, 0 )
					end
				end
			end
		else
			EXLG( "NpcSdk_error", "npc trade item quantity or type error, please check! NpcName = %s", GetCharName( npc ) )
			return SystemNotice( character, "npc trade item value or type error, please check!" )
		end
	end

	PRINT( "SendTradePage: SendPacket" )
	SendPacket( character, packet )
end

--更新交易
function SendTradeUpdate( character, npc, trade, tradetype, p1 )
	if trade == nil or tradetype == nil then
		return SystemNotic( character, "SendTradeUpdate:函数参数错误!" )
	end

	PRINT( "SendTradeUpdate: send start. tradetype = ", tradetype )
	local packet = GetPacket()
	WriteCmd( packet, CMD_MC_BLACKMARKET_TRADEUPDATE )
	local npcid = GetCharID( npc )
	WriteDword( packet, npcid )
	WriteByte( packet, tradetype )
	WriteDword( packet, p1 )

	local typecount = 0
	for i = 1, 4, 1 do
		if trade[i] ~= nil then
			typecount = typecount + 1
		else
			break
		end
	end
	WriteByte( packet, typecount )
	PRINT( "SendTradeUpdate: typecount = ", typecount )

	for i = 1, typecount, 1 do
		if trade[i].itemtype ~= nil and trade[i].count ~= nil and trade[i].item ~= nil then
			if trade[i].count > 120 then
				trade[i].count = 120
			end
			PRINT( "SendTradeUpdate: itemtype = ,  count = ", trade[i].itemtype, trade[i].count )
			WriteByte( packet, trade[i].itemtype )
			WriteByte( packet, trade[i].count )
			--写入物品ID数据
			for n = 1, trade[i].count, 1 do
				if trade[i].item[n] ~= nil then
					if tradetype == TRADE_GOODS then
						PRINT( "SendTradeUpdate:writedword : id =, count =, price =, tradetp ", trade[i].item[n].id, trade[i].item[n].count, trade[i].price[n].curprice, tradetype )
						WriteWord( packet, trade[i].item[n].id )
						WriteWord( packet, trade[i].item[n].count )
						WriteDword( packet, trade[i].price[n].curprice )
						WriteByte( packet, trade[i].item[n].level )
					else
						WriteWord( packet, trade[i].item[n] )
					end
				else
					WriteWord( packet, ROLE_INVALID_ID )
					if tradetype == TRADE_GOODS then
						WriteDword( packet, 0 )
					end
				end
			end
		else
			EXLG( "NpcSdk_error", "npc 交易物品数量或者类型错误,请查询!NpcName = %s", GetCharName( npc ) )
			return SystemNotice( character, "npc 交易物品数量或者类型错误,请查询!" )
		end
	end

	PRINT( "SendTradeUpdate: SendPacket" )
	SynPacket( npc, packet )
end

--交易
function SendUpdateTradePage( character, npc, cmd, trade, tradetype, p1 )
	if cmd == nil or trade == nil or tradetype == nil then
		return SystemNotic( character, "SendUpdateTradePage:Function parameter error!" )
	end

	PRINT( "SendUpdateTradePage: send start. tradetype = ", tradetype )
	local packet = GetPacket()
	WriteCmd( packet, cmd )
	local npcid = GetCharID( npc )
	WriteDword( packet, npcid )
	WriteByte( packet, tradetype )
	WriteDword( packet, p1 )

	local typecount = 0
	for i = 1, 4, 1 do
		if trade[i] ~= nil then
			typecount = typecount + 1
		else
			break
		end
	end
	WriteByte( packet, typecount )
	PRINT( "SendUpdateTradePage: typecount = ", typecount )

	for i = 1, typecount, 1 do
		if trade[i].itemtype ~= nil and trade[i].count ~= nil and trade[i].item ~= nil then
			if trade[i].count > 120 then
				trade[i].count = 120
			end
			PRINT( "SendUpdateTradePage: itemtype = ,  count = ", trade[i].itemtype, trade[i].count )
			WriteByte( packet, trade[i].itemtype )
			WriteByte( packet, trade[i].count )
			--写入物品ID数据
			for n = 1, trade[i].count, 1 do
				if trade[i].item[n] ~= nil then
					if tradetype == TRADE_GOODS then
						PRINT( "SendUpdateTradePage:writedword : id =, count =, price =, tradetp ", trade[i].item[n].id, trade[i].item[n].count, trade[i].price[n].curprice, tradetype )
						WriteWord( packet, trade[i].item[n].id )
						WriteWord( packet, trade[i].item[n].count )
						WriteDword( packet, trade[i].price[n].curprice )
						WriteByte( packet, trade[i].item[n].level )
					else
						WriteWord( packet, trade[i].item[n] )
					end
				else
					WriteWord( packet, ROLE_INVALID_ID )
					if tradetype == TRADE_GOODS then
						WriteWord( packet, 0 )
						WriteDword( packet, 0 )
						WriteByte( packet, 0 )
					end
				end
			end
		else
			EXLG( "NpcSdk_error", "SendUpdateTradePage:npc trade quantity or type error, please check!NpcName = %s", GetCharName( npc ) )
			return SystemNotice( character, "SendUpdateTradePage:npc trade item quantity or type error, please check!" )
		end
	end

	PRINT( "SendUpdateTradePage: SendPacket" )
	SynPacket( character, packet )
end

function TradePage( character, npc, trade, tradetype, p1 )
	PRINT( "TradePage" )
	SendTradePage( character, npc, CMD_MC_TRADEPAGE, trade, tradetype, p1 )
end

--出售命令函数
function SalePage( character, npc, trade )
	PRINT( "Send sale page info!" )
	TradePage( character, npc, trade, TRADE_SALE, 0 )
end

--购买命令函数
function BuyPage( character, npc, trade )
	PRINT( "Send buy page info!" )
	TradePage( character, npc, trade, TRADE_BUY, 0 )
end

--播放特效
function PlayEffect( npc, id )
	PRINT( "PlayEffect" )
	ChaPlayEffect( npc, id )
end

--交易船舱货物
function TradeGoods( character, npc, trade, index )
	PRINT( "Send TradeGoods page info, trade, index", trade, index )
	local ret, boatid = GetBoatID( character, index )
	if ret ~= LUA_TRUE then
		PRINT( "ship trade option error, does not find target ship index p!index = "..index )
		SystemNotice( character, "ship trade option error, does not find target ship index p!index = "..index )
		return
	end
	PRINT( "tradepage" )
	TradePage( character, npc, trade, TRADE_GOODS, boatid )
end

--角色交易停泊列表
function TradeBerthList( character, npc, berth )
	PRINT( "TadeBerthList: show list of ship docked in harbor for trade!" )
	local npcid = GetCharID( npc )
	return BoatBerthList( character, npcid, BERTH_TRADE_LIST, berth, 0, 0, 0 )
end

--角色船只停泊列表
function LuanchBerthList( character, npc, berth, xpos, ypos, dir )
	PRINT( "LuanchBerthList: show docked ship list!" )
	local npcid = GetCharID( npc )
	--local ret1 = RemoveYS( character )
	--if ret1 ~= 1 then
	--	PRINT( "LuanchBerthList:RemoveYS 失败!" )
	--	SystemNotice( character, "LuanchBerthList:RemoveYS 失败!" )
	--	return --LUA_FALSE
	--end
	return BoatBerthList( character, npcid, BERTH_LUANCH_LIST, berth, xpos, ypos, dir )
end

--修理船只列表
function RepairBerthList( character, npc, berth )
	PRINT( "RepairBerthList: show repair list of ships docked in harbor!" )
	local npcid = GetCharID( npc )
	return BoatBerthList( character, npcid, BERTH_REPAIR_LIST, berth, 0, 0, 0 )
end

--打捞船只列表
function SalvageBerthList( character, npc, berth )
	PRINT( "SalvageBerthList: show list of ship docked in harbor to salvage!" )
	local npcid = GetCharID( npc )
	return BoatBerthList( character, npcid, BERTH_SALVAGE_LIST, berth, 0, 0, 0 )
end

--补给船只列表
function SupplyBerthList( character, npc, berth )
	PRINT( "SupplyBerthList: Show ship docked at harbor list for refuel!" )
	local npcid = GetCharID( npc )
	return BoatBerthList( character, npcid, BERTH_SUPPLY_LIST, berth, 0, 0, 0 )
end

--船只升级列表
function BoatLevelBerthList( character, npc, berth )
	PRINT( "BoatLevelList: Show upgrade list of ships docked in this harbor!" )
	local npcid = GetCharID( npc )
	return BoatBerthList( character, npcid, BERTH_BOATLEVEL_LIST, berth, 0, 0, 0 )
end

--出售物品
function Sale( character, npc, index, count )
	PRINT( "Sale" )
	if index == nil or count == nil then
		PRINT( "Sale:Function parameter error!" )
		SystemNotice( character, "Sale:Function parameter error!" )
		return LUA_FALSE
	end

	SafeSale( character, index, count )
	return LUA_TRUE
end

--购买物品
function Buy( character, npc, trade, itemtype, index1, index2, count )
	PRINT( "Buy" )
	itemtype = itemtype + 1
	index1 = index1 + 1
	if trade[itemtype] == nil or trade[itemtype].item == nil or trade[itemtype].item[index1] == nil then
		--信息错误
		PRINT( "Buy:function parameter error!" )
		SystemNotice( character, "Buy:function parameter error!" )
		return LUA_FALSE
	end
	local itemid = trade[itemtype].item[index1]
	SafeBuy( character, itemid, index2, count )
	return LUA_TRUE
end

--出售货物
function SaleGoods( character, npc, trade, boatid, index, count )
	PRINT( "SaleGoods" )
	if boatid == nil or index == nil or count == nil or trade == nil then
		PRINT( "SaleGoods:Function parameter error!" )
		SystemNotice( character, "SaleGoods:Function parameter error!" )
		return LUA_FALSE
	end
	
	local ret = BoatTrade( character, trade.berth )
	if ret ~= LUA_TRUE then
		return LUA_FALSE
	end
	
	local ret, itemid = GetSaleGoodsItem( character, boatid, index )
	if ret ~= LUA_TRUE then
		PRINT( "SaleGoods:GetSaleGoodsItem, obtain goods notice failed!index = "..index )
		SystemNotice( character, "SaleGoods:GetSaleGoodsItem, obtain goods notice failed!index = "..index )
		return LUA_FALSE
	end
	PRINT( "SaleGoods: boatid = , index = , itemid = ", boatid, index, itemid )
	--校验是否npc收购该物品
	local price = 0
	for n = 1, trade[2].count, 1 do
		if trade[2].item[n].id == itemid then
			price = trade[2].price[n].curprice
			break
		end
	end
	PRINT( "SaleGoods: boatid = , index = , itemid = , count =, price = ", boatid, index, itemid, count, price )

	local ret, level, cess = GetTradeItemData( character )
	if ret ~= LUA_TRUE then
		cess = 1
	end
	PRINT( "SaleGoods:GetTradeItemData: level = , cess = ", level, cess )

	PRINT( "SaleGoods:3-1, cess, price = ", cess, price )
	if cess == 0 then
		cess = 1
	end
	local param = (math.max ( 0, 30-math.pow(cess,0.5) )+math.pow(cess , (-0.5) ) ) /100
	local cessdata = math.floor( price*param + 0.5 )
	PRINT( "SaleGoods:3-1, cessdata, price = ", cessdata, price )
	local cessprice = price - cessdata
	PRINT( "SaleGoods:3, cessprice = ", cessprice )

	local ret = SafeSaleGoods( character, boatid, index, count, cessprice )
	if ret ~= LUA_TRUE then
		PRINT( "SaleGoods: sale of commerce goods failed!boatid, index, count, price", boatid, index, count, price )
		SystemNotice( character, "SaleGoods: Sales of commerce products failed!" )
		LG( "trade_error", "SaleGoods: sale of commerce goods failed!boatid, index, count, price", boatid, index, count, price )
		return LUA_FALSE
	end
	local allcessdata = cessdata*count
	SystemNotice( character, "Deduct Tax. Total: ("..allcessdata.."G). Unit: ("..cessdata.."G)" )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -