Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 3
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)