Beispiel #1
0
def parse_target_sheet(sh, tbTarget, tbCondition):
    for row in range(1, sh.nrows):

        targetId = get_str_from_sheet(sh, row, 0)
        targetFuncName = "target" + upFirstChar(targetId)

        memo = get_str_from_sheet(sh, row, 1)
        fanwei = get_str_from_sheet(sh, row, 2)
        sortMethod = get_str_from_sheet(sh, row, 3)
        selectCnt = get_int_from_sheet(sh, row, 4)
        if (selectCnt == 0):
            selectCnt = 9999

        #in buff
        inBuff = get_str_array_from_sheet(sh, row, 5)
        #not in buff
        notInBuff = get_str_array_from_sheet(sh, row, 6)

        #print(targetId, memo, fanwei, sortMethod, selectCnt, inBuff, notInBuff)

        # 解析
        sortKey = ""
        intAsc = 1

        if (len(sortMethod)):
            lstSortMethod = sortMethod.split(",")
            sortKey = lstSortMethod[0]

            if (len(lstSortMethod) > 1):
                intAsc = int(lstSortMethod[1])

        paramDefine = ""
        srcCnd = ""
        dicParam = {}

        for col in range(7, sh.ncols):
            cnd = get_str_from_sheet(sh, row, col)

            if len(cnd) == 0:
                continue

            if (cnd in tbCondition):
                srcCnd += u'''
        if ( !(%s( ai_obj, nil)) ) continue;
''' % ("cnd" + upFirstChar(cnd))
            else:
                exp = parse_expr_right(cnd, dicVar, 1, dicParam)
                paramDefine += exp[0]
                srcCnd += u'''
        if ( !(%s) ) continue;
''' % exp[1]

        src = srcTargetFunction % (memo, targetFuncName, fanwei, sortKey,
                                   intAsc, selectCnt, paramDefine + srcCnd)
        #print( src )
        tbTarget[targetId] = src
Beispiel #2
0
def parse_condition_sheet(sh, tbCondition):
    # cnd_hpmax_50
    for row in range(1, sh.nrows):
        # 条件id
        conditionId = get_str_from_sheet(sh, row, 0)

        if conditionId == "":
            continue

        cndFuncName = "cnd" + upFirstChar(conditionId)

        # 条件备注
        conditionMemo = get_str_from_sheet(sh, row, 1)

        paramDefine = ""
        cnds = ""

        dicParam = {}

        for col in range(2, sh.ncols):
            cnd = (get_str_from_sheet(sh, row, col))
            if (len(cnd) == 0):
                continue
            exp = parse_expr_right(cnd, dicVar, 0, dicParam)
            #print("exp[0]", exp[0])
            #print("exp[1]", exp[1])
            paramDefine += exp[0]
            cnds += '''
    // %s
    if ( !(%s) ) return 0;
''' % (cnd, exp[1])

        conditionSrc = srcConditionFunction % (conditionMemo, cndFuncName,
                                               paramDefine + cnds)

        #print( conditionId, conditionMemo )
        #print( conditionSrc )

        tbCondition[conditionId] = conditionSrc
Beispiel #3
0
def parse_formula_sheet(sh, output_file):

    print(dicVar)
    all_fun = begin
    for row in range(3, sh.nrows):
        skill_id_str = get_str_from_sheet(sh, row, 0)
        #skill_name_str = get_str_from_sheet(sh, row, 1)
        skill_formula_str = get_str_from_sheet(sh, row, 1)
        print(skill_id_str, skill_formula_str)
        #fun_str = parse_function(skill_formula_str, u"技能ID:"+skill_id_str, u"param_%s" % skill_id_str, dicVar, srcSkillFormla)
        #print( fun_str );

        expSrc = parse_expr_right(skill_formula_str, dicVar, 0, {})

        fun_str = srcSkillFormla % (skill_id_str, skill_id_str,
                                    skill_formula_str, expSrc[1])
        print(fun_str)

        all_fun += fun_str
    write_src(output_file, begin, end, all_fun, "utf-8")

    all_fun += end
    write_file(output_file, all_fun)
Beispiel #4
0
def parse_xls(filename, parseAIFlg):

    ai_path = "data/ai/"

    try:
        # 打开excel文件
        book = xlrd.open_workbook(filename)
    except:
        msg = "can't open file?", filename
        print(msg, )
        usage()

        raise

    # 先处理变量表
    for x in xrange(book.nsheets):
        sh = book.sheet_by_index(x)
        sheetname = sh.name
        if sheetname == u"服务器端变量表":
            parse_var_sheet(sh, dicVar)
            break

    tbCondition = {}
    tbTarget = {}

    if parseAIFlg == u"1":
        #处理条件表
        for x in xrange(book.nsheets):
            sh = book.sheet_by_index(x)
            sheetname = sh.name
            if sheetname == u"条件":
                parse_condition_sheet(sh, tbCondition)
                break

        #解析目标
        for x in xrange(book.nsheets):
            sh = book.sheet_by_index(x)
            sheetname = sh.name
            if sheetname == u"目标":
                parse_target_sheet(sh, tbTarget, tbCondition)
                break

        #解析AI
        for x in xrange(book.nsheets):
            sh = book.sheet_by_index(x)
            sheetname = sh.name
            if sheetname == u"AI":
                #暂时屏蔽AI
                parse_ai_sheet(sh, ai_path, tbCondition, tbTarget)
                break

    formula = None
    hasPlot = False
    cehuaDecideWin = 0
    #for x in xrange(book.nsheets):
    #	sh = book.sheet_by_index(x)
    #	if sh.name == shname:
    #		tbAttr = {};
    #		#parse_fuben_sheet(sh, ai_path, tbAttr )
    # 遍历xls
    for x in xrange(book.nsheets):
        sh = book.sheet_by_index(x)
        sheetname = sh.name
        if sheetname == u"battle_scene":
            battle_id = common.get_str_from_sheet(sh, 0, 1)
            battle_type = common.get_str_from_sheet(sh, 0, 3)
            # 策划决定战斗胜利
            cehuaDecideWin = common.get_int_from_sheet(sh, 0, 5)
            # 玩家入场ai_list和x,y,dir
            player_ai_list = common.get_str_array_from_sheet(sh, 1, 1)
            player_x = common.get_int_from_sheet(sh, 1, 2)
            player_y = common.get_int_from_sheet(sh, 1, 3)
            player_dir = common.get_int_from_sheet(sh, 1, 4)
            target_dir = common.get_int_from_sheet(sh, 1, 5)
            scene_id = common.get_int_from_sheet(sh, 2, 1)
            # 场景AI
            scene_ai_list = common.get_str_array_from_sheet(sh, 2, 3)
            # 战斗时长
            fight_timeout = common.get_int_from_sheet(sh, 2, 5)
            reward = common.get_str_array_from_sheet(sh, 4, 1)
            level_type = common.get_int_from_sheet(sh, 4, 3)
            # 敌方入场数据
            scene_data, row_line = common.parse_table(sh, 5, 0)
            print "row_line:", row_line
            if (row_line == sh.nrows):
                continue
            # 公式数据
            srcTmp = common.get_str_from_sheet(sh, row_line, 0)

            # 寻找公式
            while srcTmp != u"公式" and row_line < sh.nrows:
                srcTmp = common.get_str_from_sheet(sh, row_line, 0)
                row_line = row_line + 1

            if (row_line == sh.nrows):
                continue
            # 公式数据
            formula, row_line = common.parse_table(sh, row_line, 0)

        if sheetname == u"ships":
            # 敌方入场数据
            ships, row_line = common.parse_table(sh, 0, 0)
        if sheetname == u"plot":
            hasPlot = True

    if (hasPlot):
        plotId = int(battle_id)
    else:
        plotId = 0

    if not scene_data:
        return

    srcAttribute = u''
    lstAttribute = []
    if player_ai_list and (len(player_ai_list) >= 1):
        lstAttribute.append(("str_array", u"玩家AI", "AI", player_ai_list))
    if scene_ai_list and (len(scene_ai_list) >= 1):
        lstAttribute.append(("str_array", u"场景AI", "SceneAI", scene_ai_list))
    # fight_timeout
    # FightTimeout
    if fight_timeout and ((fight_timeout) >= 60):
        lstAttribute.append(("int", u"战斗时长", "FightTimeout", fight_timeout))
    lstAttribute.append(("int", u"玩家X", "UserX", player_x))
    lstAttribute.append(("int", u"玩家Y", "UserY", player_y))
    lstAttribute.append(("int", u"玩家Dir", "UserDir", player_dir))
    lstAttribute.append(("int", u"舰队Dir", "FleetDir", target_dir))
    lstAttribute.append(("int", u"地图ID", "SceneId", scene_id))
    lstAttribute.append(("int", u"策划决定战斗胜利", "CehuaDecideWin", cehuaDecideWin))
    if level_type:
        lstAttribute.append(("int", u"等级类型", "LevelType", level_type))
    if reward and (len(reward) >= 1):
        lstAttribute.append(("str_array", u"奖励", "Reward", reward))

    if hasPlot:
        lstAttribute.append(("int", u"剧情ID", "PlotId", plotId))
    for attr in lstAttribute:
        type = attr[0]
        memo = attr[1]
        param = attr[2]
        value = attr[3]
        srcTmp = u''
        if type == "int":
            srcTmp = srcIntData % (memo, param, value)
        elif type == "str_array":
            srcTmp = srcData % (memo, param, PythonData2Lpc(value))

        srcAttribute += srcTmp

    baseName = dicBase[battle_type]
    srcFunctions = u""
    formulaResult = {}
    if formula:
        for k, v in formula.items():
            formula_name = "formula_%s" % k
            dicParam = {}
            exp = parse_expr_right(v["formula"], dicVar, 0, dicParam)
            #srcFunc = parse_function( v["formula"], formula_name, formula_name, dicVar, srcFormulaFunction )
            srcFunc = srcFormulaFunction % (v["memo"], formula_name, exp[0],
                                            v["formula"], exp[1])
            srcFunctions += srcFunc
            formulaResult[k] = u"@@%s" % formula_name

    for k, v in ships.items():
        for fk, fn in formulaResult.items():
            if v.has_key(fk):
                v[fk] = fn
    srcSceneData = srcSceneDataTemplete % (PythonData2Lpc(
        scene_data, True, 1, 1))
    srcShipData = srcShipDataTemplete % (PythonData2Lpc(ships, True, 1, 1))
    srcFightData = srcFightDataTemplete % (
        baseName, srcAttribute, srcFunctions, srcSceneData, srcShipData)

    srcPath = (dicFilePath[battle_type]) % (battle_id)

    print formula
    #TODO:输出scene_data,ships
    write_src(srcPath, begin, end, srcFightData, "utf-8")
    add_to_file("tmp/update_file.txt", srcPath)
Beispiel #5
0
def parse_ai_sheet(sh, path, tbCondition, tbTarget):
    srcCnd = ""

    for cndId in tbCondition:
        srcTmp = tbCondition[cndId]
        srcCnd += srcTmp

    srcTarget = ""
    for targetId in tbTarget:
        srcTmp = tbTarget[targetId]
        srcTarget += srcTmp

    for row in range(1, sh.nrows):
        #srcAITemplete
        aiId = get_str_from_sheet(sh, row, 0)
        if aiId == "":
            continue
        # 1 ai memo
        memo = get_str_from_sheet(sh, row, 1)
        # 2 ai class name
        aiClsName = "ClsAI" + upFirstChar(aiId)
        # 3 base attr funcs
        #   id
        funcId = srcStrData % (u"AI ID", "AIId", aiId)
        srcBaseAttrFuncs = funcId
        #   时机
        opportunity = get_str_from_sheet(sh, row, 2)
        if opportunity not in dicOpportunity:
            print(u"ERROR:unknow opportunity:" + opportunity)
            strOpportunity = "ERROR:" + opportunity
        else:
            strOpportunity = "@@" + dicOpportunity[opportunity]

        funcOpportunity = srcData % (u"AI时机", "Opportunity",
                                     PythonData2Lpc(strOpportunity))

        srcBaseAttrFuncs += funcOpportunity
        #   优先级别
        priority = get_int_from_sheet(sh, row, 3)
        funcPriority = srcIntData % (u"AI优先级别", "Priority", priority)
        srcBaseAttrFuncs += funcPriority

        # 停止标记
        stop_other_flg = get_int_from_sheet(sh, row, 4)
        funcStopOtherFlg = srcIntData % (u"AI停止标记", "StopOtherFlg",
                                         stop_other_flg)
        srcBaseAttrFuncs += funcStopOtherFlg

        # 删除标记
        delete_other_flg = get_int_from_sheet(sh, row, 5)
        funcDeleteOtherFlg = srcIntData % (u"AI删除标记", "DeleteOtherFlg",
                                           delete_other_flg)
        srcBaseAttrFuncs += funcDeleteOtherFlg

        lstTarget = []
        lstCnd = []

        # 4 cnd funcs
        cnd = get_str_from_sheet(sh, row, 6)
        conditionSrc = ""
        if (len(cnd)):

            # 处理条件
            if (cnd in tbCondition):
                cndFunName = "cnd" + upFirstChar(cnd)
                srcTmp = u'''\treturn %s(mpAI, 0)''' % cndFunName
                lstCnd.append(cnd)
            else:
                dicParam = {}
                exp = parse_expr_right(cnd, dicVar, 0, dicParam)
                #print("xxxxxxxxxxxxxx", cnd, exp)
                srcTmp = u'''\t%s\n\treturn (%s)''' % (exp[0], exp[1])

            conditionSrc = srcCheckConditionFunction % (srcTmp)

            #srcCnd += conditionSrc

        lstAct = []
        tbActionFuncs = {}
        index = 0
        for col in range(7, sh.ncols, 3):
            # 5 target funcs
            target = get_str_from_sheet(sh, row, col)
            # 6 act funcs
            action = get_str_from_sheet(sh, row, col + 1)
            if (len(action) == 0):
                continue
            # 7 actions
            action_content = get_str_from_sheet(sh, row, col + 2)

            # {"delay", "SELF", { 6000, }},
            tmpAction = [
                dicAction[action],
                "",
                [],
            ]
            if (target in tbTarget):
                tmpAction[1] = "@@target" + upFirstChar(target)
            else:
                tmpAction[1] = target

            #TODO:parse action functions
            params = parse_action_function(aiId, index, action, action_content,
                                           tbActionFuncs)
            tmpAction[2] = params

            lstAct.append(tmpAction)
            index += 1

        srcActFuncs = ""
        for actFunctionName in tbActionFuncs:
            srcActFuncs += tbActionFuncs[actFunctionName]

        dictTargetMethod = {}
        for targetMethod in tbTarget.keys():
            dictTargetMethod[targetMethod] = "@@target" + upFirstChar(
                targetMethod)

        aiSrc = srcAITemplete % (memo, srcBaseAttrFuncs, srcCnd + conditionSrc,
                                 srcTarget, srcActFuncs,
                                 PythonData2Lpc(lstAct, True, 1, 1),
                                 PythonData2Lpc(dictTargetMethod, True, 1, 1))

        ai_str = ("/" + aiId + ".c").encode(sys.getfilesystemencoding())
        #print(aiSrc)
        #print(path + ai_str)
        #print(begin)
        #print(end)
        write_src(path + ai_str, begin, end, aiSrc, "utf-8")
        print(">>> [I] ai success write to " + path + ai_str)
Beispiel #6
0
def parse_sheet(sh, outputpath):
    # 读取奖励表
    print sh.name

    startRow = get_int_from_sheet(sh, 3, 1) - 1
    rRewardId = get_str_from_sheet(sh, 0, 5)
    rType = get_str_from_sheet(sh, 4, 4)

    endRow = sh.nrows

    srcAttr = u""

    srcAttr += u'''
RESET_ONUPDATE_VAR(Id, %s)
''' % PythonData2Lpc(rRewardId)
    srcAttr += u'''
RESET_ONUPDATE_VAR(Type, TB_TYPE_%s)
''' % rType

    srcFunction = u""

    rewardData = {}
    for row in range(startRow, endRow):
        #序号	类型	名字	类型ID	数量	概率	商会公告   公告	   说明
        #reward_no(str)	type(str)		id(int)	cnt(int)	rate(int)		memo(str)
        #reward_no(str)	type(str)		id(int)	cnt(int)	rate(int)	group_gonggao(str)   gonggao(str)	memo(str)    condition(str)
        no = get_str_from_sheet(sh, row, 0)
        rTypeName = get_str_from_sheet(sh, row, 1)
        rType = get_str_from_sheet(sh, row, 2)
        rName = get_str_from_sheet(sh, row, 3)
        rId = get_str_from_sheet(sh, row, 4)
        if (rId != "" and not rId.isdigit()):
            funcName = u"CalcId%s" % no
            expTmp = parse_expr_right(rId, dicVar, 0, {})
            srcTmp = srcFuncTemplete % ("奖励ID计算函数,只为公会红包准备", funcName,
                                        expTmp[1])

            srcFunction += srcTmp

            rId = "@@%s" % funcName
        else:
            if (rId == ""):
                rId = 0
            else:
                rId = int(rId)

        rAmount = get_str_from_sheet(sh, row, 5)
        rRate = get_int_from_sheet(sh, row, 6)

        # 商会公告(目前应该没用)
        rGroupGonggao = get_str_array_from_sheet(sh, row, 7)
        if (len(rGroupGonggao) > 0):
            rGroupGonggao[0] = int(rGroupGonggao[0])

        # 公告 = 世界公告;商会公告;系统提示
        rGonggao = get_str_from_sheet(sh, row, 8)
        gonggaos = []
        if (len(rGonggao) > 0):
            gonggaos = rGonggao.split(";")
            if (len(gonggaos) != 3):
                raise Exception("奖励公告格式错误")
            i = 0
            for gonggao in gonggaos:
                gonggaos[i] = gonggao.split(",")
                if len(gonggao) > 0:
                    gonggaos[i] = gonggao.split(",")
                    gonggaos[i][0] = int(gonggaos[i][0])
                else:
                    gonggaos[i] = []
                i += 1

        rMemo = get_str_from_sheet(sh, row, 10)
        rArgs = get_map_from_sheet(sh, row, 9)
        rCnd = ""

        if (rAmount != "" and not rAmount.isdigit()):
            funcName = u"CalcAmount%s" % no
            expTmp = parse_expr_right(rAmount, dicVar, 0, {})
            srcTmp = srcFuncTemplete % ("奖励数量计算函数", funcName, expTmp[1])

            srcFunction += srcTmp

            rAmount = "@@%s" % funcName
        else:
            if (rAmount == ""):
                rAmount = 0
            else:
                rAmount = int(rAmount)

        if (sh.ncols > 11):
            rCnd = get_str_from_sheet(sh, row, 11)
            if (len(rCnd)):
                funcName = u"Condition%s" % no

                expTmp = parse_expr_right(rCnd, dicVar, 0, {})
                srcTmp = srcFuncTemplete % (u"条件函数", funcName, expTmp[1])

                srcFunction += srcTmp

                rCnd = "@@%s" % funcName

        rewardData[no] = (rType, rName, rId, rAmount, rRate, gonggaos, rMemo,
                          rCnd, rGroupGonggao, rArgs)

    srcAll = strRewardTemplete % (srcAttr, srcFunction,
                                  PythonData2Lpc(rewardData, True, 2, 2))

    print(srcAll)
    output_file = outputpath + "%s.c" % rRewardId
    print(output_file)
    write_src(output_file, begin, end, srcAll, "utf-8")