Ejemplo n.º 1
0
def getAllGuns(userId, mode):
    """
    获得所有皮肤炮数据
    """
    clientId = util.getClientId(userId)
    assert isinstance(userId, int) and userId > 0
    _key = _buildUserGunKey(userId, mode)
    value = daobase.executeUserCmd(userId, "HGETALL", _key)
    if value:
        gunInfos = {}
        savaData = []
        for index in xrange(0, len(value), 2):
            gunId = value[index]
            if gunId in config.getAllGunIds(clientId, mode):
                gunData = strutil.loads(value[index + 1], False, True)
                if len(gunData) <= 2:
                    gunConfig = config.getGunConf(gunId, clientId,
                                                  gunData[INDEX_LEVEL], mode)
                    gunData.append(gunConfig["skins"][0])
                    savaData.append(gunId)
                    savaData.append(strutil.dumps(gunData))
                gunInfos[gunId] = gunData

        if savaData:
            daobase.executeUserCmd(userId, "HMSET", _key, *savaData)
        return gunInfos
    return {}
Ejemplo n.º 2
0
def updateGun(userId, gunId, mode):
    """
    更新新增炮数据
    """
    clientId = util.getClientId(userId)
    assert int(gunId) in config.getAllGunIds(clientId, mode)
    gunConf = config.getGunConf(gunId, clientId, mode=mode)
    gunInfo = [1, 0, gunConf["skins"][0]]  # 皮肤炮熟练等级 | 经验 | 默认皮肤
    daobase.executeUserCmd(userId, "HSETNX", _buildUserGunKey(userId, mode),
                           str(gunId), json.dumps(gunInfo))
Ejemplo n.º 3
0
def reportBILogOnLogin(userId):
    """
    首次登录上报BI数据
    """
    # 上报玩家火炮剩余天数
    timestamp = int(time.time())
    userBag = hallitem.itemSystem.loadUserAssets(userId).getUserBag()
    clientId = util.getClientId(userId)
    for mode in config.GAME_MODES:
        for itemId in config.getAllGunIds(clientId, mode):
            item = userBag.getItemByKindId(itemId)
            if item and not item.isDied(timestamp):
                bireport.reportGameEvent("BI_NFISH_GE_GUN_SKIN", userId, FISH_GAMEID, 0,
                                         0, int(itemId), item.balance(timestamp), mode, 0, [], clientId)
Ejemplo n.º 4
0
def setGunData(userId, gunId, gunInfo, mode):
    """
    存储单个炮数据
    """
    clientId = util.getClientId(userId)
    assert int(gunId) in config.getAllGunIds(clientId, mode)
    assert isinstance(gunInfo, list) and len(gunInfo) == 3
    skins = config.getGunConf(gunId, clientId, mode=mode).get("skins")
    if gunInfo[INDEX_SKINID] not in skins:
        ftlog.error("setGunData, not find skin, userId =", userId, "gunId =",
                    gunId, "gunInfo =", gunInfo, "skins =", skins, "mode =",
                    mode, "clientId =", clientId)
        gunInfo[INDEX_SKINID] = skins[0]
    daobase.executeUserCmd(userId, "HSET", _buildUserGunKey(userId, mode),
                           str(gunId), json.dumps(gunInfo))
Ejemplo n.º 5
0
def initGun(userId):
    """
    初始化炮数据
    """
    clientId = util.getClientId(userId)
    for mode in config.GAME_MODES:
        for gunId in config.getAllGunIds(clientId, mode):
            updateGun(userId, gunId, mode)
            gunData = getGunData(userId, gunId, mode)
            skinId = gunData[INDEX_SKINID]
            skins = config.getGunConf(gunId, clientId,
                                      mode=mode).get("skins")  # 配置炮的皮肤
            if skinId not in skins:
                gunData[INDEX_SKINID] = skins[0]
                setGunData(userId, gunId, gunData, mode)
Ejemplo n.º 6
0
def getGunData(userId, gunId, mode):
    """
    获得单个皮肤炮数据
    """
    clientId = util.getClientId(userId)
    assert int(gunId) in config.getAllGunIds(clientId, mode)
    gunConf = config.getGunConf(gunId, clientId, mode=mode)
    value = daobase.executeUserCmd(userId, "HGET",
                                   _buildUserGunKey(userId, mode), str(gunId))
    if value:
        value = strutil.loads(value, False, True)
        if len(value) <= 2:
            value.append(gunConf["skins"][0])  # 默认皮肤
        return value
    # 获取初始化的值
    return [1, 0, gunConf["skins"][0]]
Ejemplo n.º 7
0
def getGunIds(userId, mode):
    """
    玩家当前拥有的火炮ID
    """
    clientId = util.getClientId(userId)
    gunIds = [0]
    userBag = hallitem.itemSystem.loadUserAssets(userId).getUserBag()
    ownGunSkinSkinsKey = GameData.ownGunSkinSkins
    ownGunSkinSkins = gamedata.getGameAttrJson(userId, FISH_GAMEID,
                                               ownGunSkinSkinsKey, [])
    for kindId in config.getAllGunIds(clientId, mode):
        item = userBag.getItemByKindId(kindId)
        gunConf = config.getGunConf(kindId, clientId, mode=mode)
        if gunConf["skins"][0] in ownGunSkinSkins:  # 是否拥有皮肤炮默认永久皮肤
            gunIds.append(kindId)
        elif item and not item.isDied(int(time.time())):  # 皮肤炮是否过期   没过期
            gunIds.append(kindId)
    return gunIds
Ejemplo n.º 8
0
def sendExpiredGunMsg(userId, mode):
    """
    返回火炮皮肤过期提示
    """
    ownGunSkinsKey = GameData.ownGunSkins  # 最近一次已拥有的皮肤炮列表
    gunSkinIdKey = GameData.gunSkinId if mode == CLASSIC_MODE else GameData.gunSkinId_m  # 用户当前皮肤炮ID
    promptedGunSkinsKey = GameData.promptedGunSkins  # 已发送了过期提示弹窗的皮肤炮
    ownGuns = gamedata.getGameAttrJson(userId, FISH_GAMEID, ownGunSkinsKey, [])
    currentGunIds = getGunIds(userId, mode)[1:]  # 玩家当前拥有的火炮ID
    clientId = util.getClientId(userId)
    allGunIds = config.getAllGunIds(clientId, mode)
    for idx in range(len(ownGuns) - 1, -1, -1):
        if ownGuns[idx] not in allGunIds:
            ownGuns.pop(idx)
    # 当前已过期的皮肤 = 最近一次已拥有皮肤炮 - 当前已拥有皮肤炮
    expiredGuns = list(set(ownGuns) - set(currentGunIds))
    if expiredGuns:
        gunId = gamedata.getGameAttr(userId, FISH_GAMEID, gunSkinIdKey)
        if gunId in expiredGuns:
            expiredGun = gunId
        else:
            expiredGun = expiredGuns[-1]
        gunIds1 = getGunIds(userId, CLASSIC_MODE)[1:]
        gunIds2 = getGunIds(userId, MULTIPLE_MODE)[1:]
        gunIds1.extend(gunIds2)
        gamedata.setGameAttr(userId, FISH_GAMEID, ownGunSkinsKey,
                             json.dumps(list(set(gunIds1))))
        promptedGuns = gamedata.getGameAttrJson(userId, FISH_GAMEID,
                                                promptedGunSkinsKey, [])
        if expiredGun not in promptedGuns:
            promptedGuns.append(expiredGun)
            gamedata.setGameAttr(userId, FISH_GAMEID, promptedGunSkinsKey,
                                 json.dumps(promptedGuns))
            mo = MsgPack()
            mo.setCmd("expired_gun")
            mo.setResult("gameId", FISH_GAMEID)
            mo.setResult("userId", userId)
            mo.setResult("gunId", expiredGun)
            mo.setResult("gameMode", mode)
            router.sendToUser(mo, userId)
Ejemplo n.º 9
0
def sendGunListMsg(userId, mode):
    """
    发送火炮列表消息
    """
    clientId = util.getClientId(userId)
    guns = []
    installedGunId = refreshGunId(userId, mode)  # 当前已装备的皮肤炮过期时,默认装备已拥有的最后一个皮肤炮
    userBag = hallitem.itemSystem.loadUserAssets(userId).getUserBag()
    allGuns = getAllGuns(userId, mode)  # 获得所有皮肤炮数据
    lang = util.getLanguage(userId)
    ownGunSkinSkinsKey = GameData.ownGunSkinSkins
    ownGunSkinSkins = gamedata.getGameAttrJson(userId, FISH_GAMEID,
                                               ownGunSkinSkinsKey,
                                               [])  # 已拥有的皮肤炮皮肤
    for gunId in config.getAllGunIds(clientId, mode):
        if gunId not in allGuns:
            continue
        gun = {}
        gunLv = allGuns[gunId][INDEX_LEVEL]
        gunExp = allGuns[gunId][INDEX_EXP]
        skinId = allGuns[gunId][INDEX_SKINID]
        gunConf = config.getGunConf(gunId, clientId, gunLv, mode)
        gun["gunId"] = gunId
        gun["name"] = config.getMultiLangTextConf(gunConf["name"], lang=lang)
        gun["unlockDesc"] = gunConf["unlockDesc"]  # 解锁描述
        if gunConf["unlockDesc"]:
            gun["unlockDesc"] = config.getMultiLangTextConf(
                gunConf["unlockDesc"], lang=lang) % gunConf.get(
                    "unlockValue", 0)
        gun["equipDesc"] = gunConf.get("equipDesc")  # 装备描述
        if gunConf["equipDesc"]:
            gun["equipDesc"] = config.getMultiLangTextConf(
                gunConf["equipDesc"], lang=lang) % gunConf.get(
                    "equipValue", 0)
        gun["level"] = gunLv
        gun["exp"] = gunExp - (gunConf["totalExp"] - gunConf["exp"]
                               )  # 炮经验-上一级的经验
        gun["totalExp"] = gunConf["exp"]  # 本级所需经验
        gun["expires"] = -1  # 有效期
        gun["state"] = 1
        gun["mode"] = 0
        gun["skinId"] = skinId if skinId in gunConf["skins"] else gunConf[
            "skins"][0]  # 皮肤炮皮肤
        gun["skins"] = []
        for skinId_ in gunConf["skins"]:
            skinState = SKIN_NOTOPEN
            if skinId_ != -1 and config.getGunSkinConf(skinId_, clientId,
                                                       mode):
                skinState = SKIN_GOT if (skinId_
                                         in ownGunSkinSkins) else SKIN_NOTGOT
            elif skinId_ == 0:
                skinState = SKIN_GOT
            skinData = {"skinId": skinId_, "state": skinState}
            gun["skins"].append(skinData)
        unLock = isUnlock(userId, gunId, gunConf, mode)
        item = userBag.getItemByKindId(gunId)
        if gunConf["skins"][0] in ownGunSkinSkins:  # 永久获得
            if installedGunId == gunId:
                gun["state"] = 0
            if not unLock:  # 未解锁拥有(试用)
                gun["mode"] = 1
        elif item and not item.isDied(int(time.time())):  # 试用
            gun["expires"] = item.expiresTime  # 用道具购买有效期
            if installedGunId == gunId:
                gun["state"] = 0
            if not unLock:  # 未解锁拥有(试用)
                gun["mode"] = 1
        elif gunId == 0:
            if installedGunId == gunId:
                gun["state"] = 0
        else:
            gun["expires"] = 0
            gun["state"] = 2
            if not unLock:
                gun["state"] = 3
        gun["equipState"] = 1 if isCanEquip(userId, gunId, mode) else 0
        guns.append(gun)

    mo = MsgPack()
    mo.setCmd("guns_list")
    mo.setResult("gameId", FISH_GAMEID)
    mo.setResult("userId", userId)
    mo.setResult("gameMode", mode)
    mo.setResult("guns", guns)
    router.sendToUser(mo, userId)