这应该是几年程序员可以写出的代码?

2018-01-29 09:14:12 +08:00
 huanyingch01

如下代码是是在某个类中的某个 api,项目中各处充斥着大量这种函数

function ChangeUserPropertiesResult:execute()
    local processQueue = {}

    local resultData = self.mData.resultData
    local allAnimationData = {}

    --dump(resultData, "resultData resultData", 10, 2)
    if resultData.uaitems and next(resultData.uaitems)  then
        for _,item in pairs(resultData.uaitems) do
            local aniResult = {}
            local userid = item.userId or item.userid

            if item.name == Player.DIRECTION then 
                SingletonShareData:getPlayerWithId(userid):updateDataBonusWithName(Player.DIRECTION,{count = item.count})
                --
                local bd = MapDataManager:getUserPosition(userid).branchDirection or -1
                MapDataManager:saveUserPosition(bd,userid,"branchDirection")

                local posData = MapDataManager:getUserPosition(userid)
                -- local nextPaths = PathFinder:findPathFromToEnd(posData.nowPos, item.count, 1)
                -- local nextPath = nextPaths[1]
                local tilePath = posData.nowPos
                -- AvatarWalker:setStandAction(userid, tilePath, nextPath)
                AvatarWalker:setAvatarPosition(userid,tilePath)

            elseif string.find(item.name,"c_") ~= nil then
                local cardid = string.sub(item.name, 3, -1)
                local action = ""
                if item.count > 0 then
                    action = "add"
                elseif item.count == 0 then
                    action = "clear"
                else
                    action = "remove"
                end

            
                local itemType,itemName = unpack(string.split(item.name,"_"))
                local cradsData = cc.exports.SingletonShareData:getPlayerWithId(userid):getDataBonusWithName(Player.CARDS)
                local isHasBaoXianKa = false
                if cradsData then 
                   for k,v in pairs(cradsData) do
                        if tonumber(v) == 29 then
                            isHasBaoXianKa = true
                            break
                        end
                    end
                end
            
                local isEnterHospital = cc.exports.SingletonShareData:getPlayerWithId(userid):hasStatusWithName("hospital")
            
                if (isEnterHospital == true and isHasBaoXianKa == true) and tonumber(itemName) == 29 and item.count < 0 then
                    local data = {}
                    data.cardId = tonumber(itemName)
                    data.playerId = userid
                    local dialog = require("app.process.CardUseController").new() --// 建议位置
                    dialog:setInputData(data)
                    if data.cardId then
                       table.insert(processQueue, dialog)
                    end
                    --行为记录
                    PlayerActionRecordHelper:pushRecordData({tips_name="tips_card_other",function_name="getCardContent",data={userId=userid,resultData={cardid=data.cardId}}})

                    EmotionResult:getInstance():pushEmotionData({userId = userid,action = EA_USE_CARD,cardId = E_CARD_INSURANCE})
                    EmotionResult:getInstance():execute()                    
                end

                aniResult = {userId = userid,action=action,itemName = cardid,itemType = "card"}
                if item.count > 0 then
                   for k = 1,item.count do
                       cc.exports.SingletonShareData:getPlayerWithId(userid):updateDataBonusWithName(Player.CARDS,{itemName = cardid, action = action})
                    end
                else
                    cc.exports.SingletonShareData:getPlayerWithId(userid):updateDataBonusWithName(Player.CARDS,{itemName = cardid, action = action})
                end
            else
                cc.exports.SingletonShareData:getPlayerWithId(userid):updateDataBonusWithName(
                                                item.name,{itemCount = item.count})
                if item.count > 0 then
                    aniResult = {userId = userid,action="add",itemName = item.name,itemType = "points"}
                end
            end

            allAnimationData[#allAnimationData + 1] = aniResult
        end
    end


    local diplayCtrlName = self.mExtraData and self.mExtraData.displayCtrlClass --or "UserPropertiesDisplayResult"
    if diplayCtrlName then
        local ctrl = require("app.processResult.displayResult."..diplayCtrlName).new()
        ctrl:setInputData(allAnimationData)
        ctrl:setCallBack(handler(self,self.executeProcessComplete))

        table.insert(processQueue, ctrl)
    end

    if next(processQueue) then
        local processCtrl = require("app.process.ProcessQueue").new(processQueue,function()
            self:executeProcessComplete()
        end)
        processCtrl:handlerQueue()
    else
        self:executeProcessComplete()
    end
end
9368 次点击
所在节点    程序员
87 条回复
mentalidade
2018-01-29 10:06:59 +08:00
怎么会觉有人得是 PHP 和 java😓
yujieyu7
2018-01-29 10:07:53 +08:00
@m939594960 这是 tp ?
fenglangjuxu
2018-01-29 10:09:35 +08:00
我只能说这个人的 lua 水平应该很不错.当然如果不是复制粘贴码上去的话.
fyxerma
2018-01-29 10:12:07 +08:00
cocos ?
Light3
2018-01-29 10:13:46 +08:00
@v2410117
php 就没有啥 then 这应该是 Lua...
Len1133
2018-01-29 10:14:39 +08:00
起码有 1 年吧
sudodo
2018-01-29 10:19:40 +08:00
你是没见过某大厂 82 年的老程序员写的 bullshit 代码……

200 行一个方法,变量套三层……
sunny352787
2018-01-29 10:21:48 +08:00
游戏的 lua 代码,是一个道具效果的执行部分,我为什么知道呢,因为这代码架构应该是和我同一个师傅教的...不过也不能说这个代码写的很烂,因为很明显这段代码是不断增补变成这样的,勤快点的可能会做个重构,但这个貌似已经是过了 N 手了,也没人敢大动,只能一点点打补丁
jyf
2018-01-29 10:23:01 +08:00
这明显是写惯了 c 的人写的 lua 嘛 (怎么判断很简单 有 end 有 pairs)
嫌麻烦建议用 moonscript 直接编译到 lua
sunny352787
2018-01-29 10:24:42 +08:00
卧槽,刚发现,EmotionResult 不是这么用的啊...谁审的代码啊,这么写打死算了
micean
2018-01-29 10:30:42 +08:00
除了没注释挺好的
xavier007
2018-01-29 10:31:38 +08:00
首先不是 PHP,PHP 最明显的就是$符号吗。其次他是有 end 且缩进的语法,那么也就那么几个语言,而且代码中有 player 字样,那么最接近的应该是 lua,lua 最长作为游戏脚本来用。会 lua 的一眼就看出来了,不会的分析下也看出来了
woscaizi
2018-01-29 10:35:55 +08:00
@gemini767 就刚刚,库克钦定的。
jjianwen68
2018-01-29 10:43:31 +08:00
这段代码的性能如何,刚看到个 https://segmentfault.com/a/1190000004372649
whx20202
2018-01-29 10:47:41 +08:00
我工作一年多了,没看出明显问题啊,谁能科普下槽点在哪里
mars0prince
2018-01-29 10:52:27 +08:00
没看出有啥毛病,if else 蛮多的,不过也正常,可能是不断打补丁
coffeecato
2018-01-29 10:53:27 +08:00
几年程序员不知道,使用 lua 开发一年左右应该差不多了。
onehao28
2018-01-29 10:54:04 +08:00
最近在写 nginx 的 lua 脚本,看用法感觉是 lua 脚本吧
m939594960
2018-01-29 10:55:21 +08:00
我先来,做个排除法首先他不是 html 代码
HuHui
2018-01-29 10:56:31 +08:00
isHasBaoXianKa
尿了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/426672

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX