Beispiel #1
0
def parse_xls(filename, sn, output_path):
	try:
		book = xlrd.open_workbook(filename)
	except:
		msg = u"can't open file? %s"%filename
		print( msg )
		usage()
		raise

	# 遍历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);
			# 玩家入场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)
			reward = common.get_str_array_from_sheet(sh, 4, 1)
			# 敌方入场数据
			scene_data, row_line = common.parse_table(sh, 5, 0)

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

	# 写文件
	src = srcData % (PythonData2Lpc(player_ai_list, True, 2, 0), player_dir, target_dir, player_x, player_y, scene_id, battle_id, PythonData2Lpc(scene_data, True, 1, 1), PythonData2Lpc(ships, True, 1, 1), PythonData2Lpc(reward, True, 2, 0))
	common.write_src(output_path, begin, end, src, 'utf-8')
Beispiel #2
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 #3
0
def GetSrcByType(headMemo, type, name, sh, row, col, templete):
    src = ""
    if (type == "int"):
        value = get_int_from_sheet(sh, row, col)
        src = templete % (headMemo, name, PythonData2Lpc(value))
    elif (type == "str"):
        value = get_str_from_sheet(sh, row, col)
        src = templete % (headMemo, name, PythonData2Lpc(value))
    elif type == "str_array":
        value = get_str_array_from_sheet(sh, row, col)
        src = templete % (headMemo, name, PythonData2Lpc(value))
    elif type == "status_array":
        tmp = get_str_array_from_sheet(sh, row, col)
        for idx in range(len(tmp)):
            if (tmp[idx] in statusName2Id):
                tmp[idx] = statusName2Id[tmp[idx]]
        value = tmp
        src = templete % (headMemo, name, PythonData2Lpc(value))
    elif type == "macro":
        value = get_str_from_sheet(sh, row, col)
        if (len(value) == 0):
            return src
        src = templete % (headMemo, name, value)
        print("xxxxxxx: src = ", src)
    elif type == "function":
        value = get_str_from_sheet(sh, row, col)
        if (len(value)):
            #print(value)
            #print( dicVar )
            src = parse_function(value, headMemo, name, dicVar, templete)
    else:
        value = get_str_from_sheet(sh, row, col)
        src = templete % (headMemo, name, PythonData2Lpc(value))

    #srcSkill += templete%headMemo, name, PythonData2Lpc(value))
    return src
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_skill_sheet(sh, output_path):
    #print( "xxxxxxxxxxxxxxxxxxxx\n", statusName2Id )
    statusStartCol = 26
    statusColCnt = 13
    # 导技能表
    # parseSkillTable
    for row in range(3, sh.nrows):
        skillId = get_str_from_sheet(sh, row, 0)
        srcSkill = u"""
#include <fight.h>

inherit SKILL_BASE;

#include <var_prop.h>
#include <user_key.h>
#include <skill.h>

"""
        skillFile = "module/skill/" + skillId + ".c"
        for col in range(0, statusStartCol - 1):
            headMemo = get_str_from_sheet(sh, 1, col)
            head = get_str_from_sheet(sh, 2, col)
            if (head not in parseSkillTable):
                continue
            type = parseSkillTable[head]["type"]
            name = parseSkillTable[head]["value_name"]

            templete = parseSkillTable[head]["templete"]
            print(headMemo, type, name, sh, row, col, templete)
            srcSkill += GetSrcByType(headMemo, type, name, sh, row, col,
                                     templete)

        statusIdx = 0
        allStatus = []
        # TODO:操作区解析
        for col in range(statusStartCol, sh.ncols, statusColCnt):
            head = get_str_from_sheet(sh, 2, col)

            # TODO:根据列名逐个获取内容

            curCol = col
            # 无法完整的读出一个状态
            if curCol + statusColCnt > sh.ncols:
                break
            # pre_actions
            curCol = curCol + 1
            # scope
            value = get_str_from_sheet(sh, row, curCol)
            print(head, value)

            if len(value) == 0:
                continue
            status = {}

            print(curCol, value)
            status["@@SCOPE"] = "@@" + value
            # sort_method
            curCol = curCol + 1
            value = get_str_from_sheet(sh, row, curCol)
            if (len(value) > 0):
                status["@@SORT_METHOD"] = "@@" + value
            # select_cnt
            curCol = curCol + 1
            value = get_str_from_sheet(sh, row, curCol)
            if "=" not in value:
                print row, col, value
                value = get_int_from_sheet(sh, row, curCol)
                status["@@SELECT_CNT"] = value
            else:
                funcName = "StatusSelectCnt%d" % (statusIdx)
                statusSelectCnt = parse_function(value, u"状态选择数量", funcName,
                                                 dicVar, srcSelectCntTemplete)
                srcSkill += statusSelectCnt
                status["@@SELECT_CNT"] = "@@" + funcName

            # TargetUnselectMain
            curCol = curCol + 1
            tmp = get_str_array_from_sheet(sh, row, curCol)
            for idx in range(len(tmp)):
                if (tmp[idx] in statusName2Id):
                    tmp[idx] = statusName2Id[tmp[idx]]
            value = tmp
            status["@@UNSELECT_MAIN"] = value
            # effect_name
            curCol = curCol + 1
            # effect_type
            curCol = curCol + 1
            # effect_time
            curCol = curCol + 1
            # StatusAdd
            curCol = curCol + 1
            value = get_str_from_sheet(sh, row, curCol)
            if (value in statusName2Id):
                value = statusName2Id[value]
            status["@@STATUS_ADD"] = value
            # status_duration
            curCol = curCol + 1
            value = get_str_from_sheet(sh, row, curCol)
            if (len(value) > 0):
                if "=" in value:
                    funcName = "StatusDuration%d" % (statusIdx)
                    statusDuration = parse_function(value, u"状态持续时间", funcName,
                                                    dicVar,
                                                    srcStatusRateTemplete)
                    srcSkill += statusDuration
                    status["@@STATUS_DURATION"] = "@@" + funcName
                elif "+" in value:
                    funcName = "StatusDuration%d" % (statusIdx)
                    statusDuration = parse_function(value, u"状态持续时间", funcName,
                                                    dicVar,
                                                    srcStatusDurationTemplete)
                    srcSkill += statusDuration
                    status["@@STATUS_DURATION"] = "@@" + funcName
                elif "/" in value:
                    funcName = "StatusDuration%d" % (statusIdx)
                    statusDuration = parse_function(value, u"状态持续时间", funcName,
                                                    dicVar,
                                                    srcStatusDurationTemplete)
                    srcSkill += statusDuration
                    status["@@STATUS_DURATION"] = "@@" + funcName
                else:
                    print value
                    status["@@STATUS_DURATION"] = get_int_from_sheet(
                        sh, row, curCol)
            # status_break
            curCol = curCol + 1
            value = get_str_from_sheet(sh, row, curCol)
            if (len(value) > 0):
                funcName = "StatusBreak%d" % (statusIdx)
                value = formla_int_to_float(value)
                statusBreak = parse_function(value, u"状态心跳时间", funcName,
                                             dicVar, srcStatusBreakTemplete)
                srcSkill += statusBreak
                status["@@STATUS_BREAK"] = "@@" + funcName
            # 命中率公式
            curCol = curCol + 1
            # skillSimpleFuncTemplete
            value = get_str_from_sheet(sh, row, curCol)
            funcName = "StatusRate%d" % (statusIdx)
            status["@@STATUS_RATE"] = "@@" + funcName
            # 生成函数,加入技能表中去
            statusRate = parse_function(value, u"状态命中", funcName, dicVar,
                                        srcStatusRateTemplete)
            srcSkill += statusRate
            # 处理过程
            curCol = curCol + 1
            value = get_str_from_sheet(sh, row, curCol)
            funcName = "StatusCalc%d" % (statusIdx)
            status["@@STATUS_CALCULATE"] = "@@" + funcName
            statusCalc = parse_function(value, u"状态结算", funcName, dicVar,
                                        srcStatusCalcTemplete)
            srcSkill += statusCalc

            print(status)
            allStatus.append(status)
            # 状态操作区+1
            statusIdx = statusIdx + 1

        # status
        srcSkill += u"""
mapping* allStatus = %s;
mapping* GetAllStatus()
{
    return allStatus;
}
""" % (PythonData2Lpc(allStatus, True, 0))

        # 非操作区的处理
        write_src(skillFile, begin, end, srcSkill, u"utf-8")

    pass
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")
Beispiel #7
0
def parse_sheet(sh, outputpath):
    headRow = 10
    startRow = 11

    for row in xrange(startRow, sh.nrows):
        itemid = get_int_from_sheet(sh, row, 0)
        if (itemid == 0):
            continue

        itemData = {}
        for col in xrange(1, sh.ncols):
            head = get_str_from_sheet(sh, headRow, col)
            if (len(head) == 0):
                continue

            tmp = parse_head.match(head)

            if (tmp == None):
                #print("ERROR:HEAD %s", head)
                #print(tmp)
                continue

            var = tmp.group("var")
            varType = tmp.group("type")

            if (varType == 'int'):
                data = get_int_from_sheet(sh, row, col)
                if data == 0 and var != "type":
                    continue
            elif (varType == 'str'):
                data = get_str_from_sheet(sh, row, col)
                if data == "":
                    continue
            elif (varType == 'macro'):
                data = "@@%s" % get_str_from_sheet(sh, row, col)
            elif (varType == 'str_array'):
                data = get_str_array_from_sheet(sh, row, col)
                if len(data) == 0:
                    continue
            elif (varType == 'map'):
                data = parse_map(get_str_from_sheet(sh, row, col))
            elif varType == 'formula':
                sNote = get_str_from_sheet(sh, headRow - 2, col)
                data = parse_formula(get_str_from_sheet(sh, row, col), sNote)
            itemData[var] = data

        #print( itemid, itemData )
        itemType = ("%s" % itemData["server_item_base"])

        itemBase = PythonData2Lpc(itemType)
        #print( itemType, itemBase )

        # 处理各种类型的特殊参数
        if (itemBase == ITEM_BASE_EXP_BOOK):
            exp = int(itemData["args"])
            itemData["exp"] = exp
        elif (itemBase == ITEM_BASE_GIFT):
            rewards = itemData["args"].split(",")
            itemData["rewards"] = rewards
        elif (itemBase == ITEM_BASE_SKILL_BOOK):
            skillIdStrs = itemData["args"].split(",")
            skillIds = []
            for var in skillIdStrs:
                skillIds += [int(var)]
            itemData["skillIds"] = skillIds
        elif (itemBase == ITEM_BASE_BAWOU_BOX):
            rewards = itemData["args"].split(",")
            itemData["rewards"] = rewards

        srcAttr = u""
        for var in itemData.keys():

            if var not in ParseVarTable:
                continue
            info = ParseVarTable[var]

            data = itemData[var]

            if info[0] == u"attr":
                srcTmp = u'''
RESET_ONUPDATE_VAR(%s, %s)
''' % (info[1], PythonData2Lpc(data))

                srcAttr += srcTmp
            elif info[0] == u"func":
                srcTmp = u'''
%s %s()
{
	return %s;
}

''' % (info[2], info[1], PythonData2Lpc(data))

                srcAttr += srcTmp
            elif info[0] == u"formula":
                if data:
                    srcTmp = info[1] % (data)
                    srcAttr += srcTmp

        src = SRC_ITEM_TEMPLATE % (itemBase, srcAttr)

        #print(src)
        filename = "%s/%d.c" % (outputpath, itemid)
        #print( filename )
        write_src(filename, begin, end, src, "utf-8")