GmAction.lua 8.2 KB
local _M = {}
local redisproxy = redisproxy
function _M.clientRequest(agent, data)
	local msg = MsgPack.unpack(data)
	local role = agent.role
	local action = _M[msg.cmd]
	local bin = MsgPack.pack({ cmd = "指令失败" })
	if not action then
		SendPacket(actionCodes.Gm_receiveResponse, bin)
		return true
	end
	local ret = action(role, msg)
	bin = MsgPack.pack({ cmd = ret })
	SendPacket(actionCodes.Gm_receiveResponse, bin)
	return true
end

function _M.testhotfix(role, pms)
	return csvdb["itemCsv"][1]["name"] .. " -=- " .. csvdb["itemCsv"][2]["name"] .. " -=- " .. role:getItemCount(123) .. " -=- " .. table.pack(next(role.heros))[2]:getBattleValue()
end

local helpDes = {{"描述", "指令", "参数1", "参数2"	,"参数3"}}

table.insert(helpDes, {"获得角色"	, "hero", "角色类型"})
function _M.hero(role, pms)
	local heroType = tonum(pms.pm1)
	if not role:addHero({type = heroType}) then
		return "失败"
	end
	return "成功"
end

table.insert(helpDes, {"获得装备"	, "equip", "装备类型"	, "装备等级", "装备个数"})
function _M.equip(role, pms)
	local typ = tonum(pms.pm1)
	local level = tonum(pms.pm2)
	local count = tonum(pms.pm3)
	role:addEquip({type = typ,level = level,count = count})
	return "成功"
end

table.insert(helpDes, {"获得零件"	, "rune", "零件类型", "零件id"})
function _M.rune(role, pms)
	local typ = tonum(pms.pm1)
	local id = tonum(pms.pm2)
	local result = role:addRune({type = typ,id = id})
	return result
end

table.insert(helpDes, {"通关挂机副本", "fb", "挂卡id"})
function _M.fb(role, pms) -- 直接通关
	local carbonId = tonum(pms.pm1)
	if not csvdb["idle_battleCsv"][carbonId] then return "不存在的carbon" end
	local passCarbon = role:getProperty("hangPass")
	local addPre 
	addPre = function(carbonId)
		local carbonData = csvdb["idle_battleCsv"][carbonId]
		for _, pre in ipairs(carbonData.prepose:toArray(true, "=")) do
			passCarbon[pre] = 1
			role:checkTaskEnter("HangPass", {id = pre})
			addPre(pre)
		end
	end
	passCarbon[carbonId] = 1
	addPre(carbonId)
	role:updateProperty({field = "hangPass", value = passCarbon})
	role:checkTaskEnter("HangPass", {id = carbonId})
	return "成功"
end

table.insert(helpDes, {"抵达挂机副本", "fbc", "副本id"})
function _M.fbc(role, pms) -- 直接通关
	local carbonId = tonum(pms.pm1)
	if not csvdb["idle_battleCsv"][carbonId] then return "不存在的carbon" end
	local passCarbon = {}
	local addPre 
	addPre = function(carbonId)
		local carbonData = csvdb["idle_battleCsv"][carbonId]
		for _, pre in ipairs(carbonData.prepose:toArray(true, "=")) do
			passCarbon[pre] = 1
			role:checkTaskEnter("HangPass", {id = pre})
			addPre(pre)
		end
	end
	addPre(carbonId)
	role:updateProperty({field = "hangInfo", value = {}})
	role:updateProperty({field = "hangPass", value = passCarbon})
	role:checkTaskEnter("HangPass", {id = carbonId})
	return "成功"
end

table.insert(helpDes, {"好感度", "love", "角色类型", "好感度等级", "好感度经验"})
function _M.love(role, pms)
	local heroType = tonum(pms.pm1)
	local level = tonum(pms.pm2)
	local exp = tonum(pms.pm3)
	local curPlus = csvdb["unit_love_plusCsv"][heroType]
	if not curPlus then return "参数错误" end
	level = math.max(math.min(curPlus.limit, level), 0)
	local curEffect = csvdb["unit_love_effectCsv"][level]
	exp = math.max(math.min(curEffect.loveValue, exp) , 0)
	for _, hero in pairs(role.heros) do
		if hero:getProperty("type") == heroType then
			hero:updateProperty({field = "loveL", value = level})
			hero:updateProperty({field = "loveExp", value = exp})
			if role:getProperty("loveStatus"):getv(heroType, 0) < level then
				role:changeUpdates({{type = "loveStatus", field = heroType, value = level}}) -- 总的
			end
			role:checkTaskEnter("LoveBreak", {heroType = heroType, loveL = level})
		end
	end
	return "成功"
end

table.insert(helpDes, {"玩家经验", "exp", "经验"})
function _M.exp(role, pms)
	local exp =  tonum(pms.pm1)
	exp = math.floor(math.max(exp, 0))
	role:addPlayExp(exp)
	return "成功"
end

table.insert(helpDes, {"获得物品", "get", "物品ID", "个数"})
table.insert(helpDes, {"获得所有物品", "get", "ALL"})
table.insert(helpDes, {"获得所有装备", "get", "EQUIP"})
table.insert(helpDes, {"获得所有零件", "get", "RUNE"})
table.insert(helpDes, {"获得所有碎片", "get", "FRAG"})
table.insert(helpDes, {"获得所有食物", "get", "FOOD"})
table.insert(helpDes, {"获得所有角色", "get", "HERO"})
function _M.get(role, pms)
	if pms.pm1 == "ALL" then
		local reward = {}
		for id, data in pairs(csvdb["gm_getallCsv"]) do
			if csvdb["itemCsv"][id] then
				reward[id] = data.number
			end
		end
		role:award(reward)
	elseif pms.pm1 == "EQUIP" then
		for itemId = 7000 , 8000 do
			if csvdb["itemCsv"][itemId] then
				role:award({[itemId] = 100})
			end
		end
	elseif pms.pm1 == "RUNE" then
		for itemId = 2000 , 3000 do
			if csvdb["itemCsv"][itemId] then
				role:award({[itemId] = 1})
			end
		end
	elseif pms.pm1 == "FRAG" then
		for itemId = 100 , 400 do
			if csvdb["itemCsv"][itemId] then
				role:award({[itemId] = 100})
			end
		end
	elseif pms.pm1 == "FOOD" then
		for itemId = 4000 , 5000 do
			if csvdb["itemCsv"][itemId] then
				role:award({[itemId] = 100})
			end
		end
	elseif pms.pm1 == "HERO" then
		for itemId = 400 , 700 do
			if csvdb["itemCsv"][itemId] then
				role:award({[itemId] = 1})
			end
		end
	else
		local itemId = tonum(pms.pm1)
		if not csvdb["itemCsv"][itemId] then
			return "物品不存在"
		end
		local count = tonum(pms.pm2, 1)
		role:award({[itemId] = count})
	end
	return "成功"
end

table.insert(helpDes, {"冒险清除"	, "advc"})
function _M.advc(role, pms)
	role:updateProperty({field = "advInfo", value = {}})
	role:updateProperty({field = "advTask", value = {}})
	role:updateProperty({field = "advItems", value = ""})
	role:updateProperty({field = "advTeam", value = {}})
	role.advData = nil
	return "成功"
end

table.insert(helpDes, {"冒险次数恢复", "advf"})
function _M.advf(role, pms)
	role.dailyData:updateProperty({field = "advC", value = 0})
	return "成功"
end

table.insert(helpDes, {"冒险通关", "adv", "章节id", "层数"})
function _M.adv(role, pms)
	local chapterId = tonum(pms.pm1)
	local layer = tonum(pms.pm2)

	local advData = csvdb["adv_chapterCsv"][chapterId]
	if not advData then return end
	layer = math.min(layer, advData.limitlevel)
	local advPass = role:getProperty("advPass")
	local addPre 
	addPre = function(chapterId)
		local advData = csvdb["adv_chapterCsv"][chapterId]
		for pre, l in ipairs(advData.prepose:toNumMap()) do
			if (advPass[pre] or 0) < l then
				advPass[pre] = l
				addPre(pre)
			end
		end
	end
	if (advPass[chapterId] or 0) < layer then
		advPass[chapterId] = layer
		addPre(chapterId)
		role:updateProperty({field = "advPass", value = advPass})
	end

	return "成功"
end

table.insert(helpDes, {"冒险到达指定层", "advt", "章节id", "层数"})
function _M.advt(role, pms)
	local chapterId = tonum(pms.pm1)
	local layer = tonum(pms.pm2)
	local advData = csvdb["adv_chapterCsv"][chapterId]
	if not advData then return "不存在的章节" end
	layer = math.min(layer, advData.limitlevel)
	local advData = role:getAdvData()

	if not advData.chapterId then
		return "先随便开启一关"
	end

	_M.adv(role, {pm1 = chapterId, pm2 = layer - 1})

	
	advData.chapterId = chapterId
	advData.level = layer

	advData:saveDB()

	return "成功"
end

table.insert(helpDes, {"冒险队等级增加", "advl", "通关次数"})
function _M.advl(role, pms)
	local winCount = tonum(pms.pm1)
	winCount = math.max(0, winCount)
	role:checkAdvLvByAddWin(winCount)
	return "成功"
end

table.insert(helpDes, {"挂机清除"	, "idlec"})
function _M.idlec(role, pms)
	role:updateProperty({field = "hangTeam", value = {}})
	role:updateProperty({field = "hangInfo", value = {}})
	role:updateProperty({field = "hangBag", value = {}})
	role.advData = nil
	return "成功"
end

table.insert(helpDes, {"爬塔到指定层", "tower", "层数"})
function _M.tower(role, pms)
	local level = tonum(pms.pm1, 1)
	if not csvdb["tower_battleCsv"][level] then return  "不存在" end
	role:updateProperty({field = "towerInfo", value = {c = globalCsv.tower_count_limit, l = level}})
	return "成功"
end


function _M.helpRpc(agent, data)
	SendPacket(actionCodes.Gm_helpRpc, MsgPack.pack({help = helpDes}))
	return true
end


return _M