Exemple #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')
Exemple #2
0
def parse_fuben_sheet(sh, path, tbAttr ):
	for row in range(0, sh.nrows):
		head = get_str_from_sheet(sh, row, 0)
		#print(head)
		if (len(head) == 0):
			continue;

		if head not in dicParseTable:
			continue;

		parseInfo = dicParseTable[head]
		if parseInfo == u"pass":
			continue

		#print( parseInfo )
		result = parseInfo[0](sh, row, 0)
		#print(result)
		tbAttr[parseInfo[1]] = { "data":result[0], "memo":head }
		row = result[1]
		#tbAttr.append( (passInfo[1], )

	srcAttr = u''
	for attrName in tbAttr:
		attrData = tbAttr[attrName]
		if ( attrName != u"FubenDispatch" ):
			srcAttr += (u'''
// %s
RESET_ONUPDATE_VAR( %s, %s )'''%(attrData["memo"], attrName, PythonData2Lpc(attrData["data"], True)))
		else:
			srcAttr += (u'''
// %s
mapping mpFubenDispatch = %s;
mapping GetFubenDispatch()
{
	return mpFubenDispatch;
}
'''%(attrData["memo"], PythonData2Lpc(attrData["data"], True)))
			

	src = srcFubenTemplete % srcAttr

	#print( src )
	#print( path + "../scene" )
	#print(tbAttr)
	fubenId = tbAttr[u"FubenId"]["data"];
	srcFile = path + "/../fuben/" + fubenId + ".c"
	#print( srcFile )
	write_src(srcFile, begin, end, src, "utf-8")
Exemple #3
0
def parse_status_sheet(sh, dicVar):
    idCol = 0
    headRow = 1
    for row in range(2, sh.nrows):
        status = get_str_from_sheet(sh, row, idCol)
        print status
        srcStatus = u"""
#include <fight.h>

inherit STAUTS_BASE;

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

// 状态ID
RESET_ONUPDATE_VAR(StatusId, "%s")

""" % (status)
        for col in range(1, sh.ncols):
            headMemo = get_str_from_sheet(sh, 0, col)
            head = get_str_from_sheet(sh, 1, col)
            type = parseStatusTable[head]["type"]
            name = parseStatusTable[head]["value_name"]
            templete = parseStatusTable[head]["templete"]

            srcStatus += GetSrcByType(headMemo, type, name, sh, row, col,
                                      templete)

            if (head == "status_name"):
                value = get_str_from_sheet(sh, row, col)
                statusName2Id[value] = status

        if (status in statusRelation):
            #状态关系表
            #ExcludeStatus
            #OverwriteStatus
            srcStatus += u"""
// 排斥状态
RESET_ONUPDATE_VAR(ExcludeStatus, %s)
""" % (PythonData2Lpc(statusRelation[status]["exclude"]))
            srcStatus += u"""
// 覆盖状态
RESET_ONUPDATE_VAR(OverwriteStatus, %s)
""" % (PythonData2Lpc(statusRelation[status]["overwrite"]))
        statusFile = "module/fight/status/%s.c" % status

        write_src(statusFile, begin, end, srcStatus, u"utf-8")
Exemple #4
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)
Exemple #5
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)
Exemple #6
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)
Exemple #7
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
Exemple #8
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")
Exemple #9
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")