Beispiel #1
0
def lock_device_and_skip_guide(entityID):
    from entity.manager import g_entityManager
    from player.model import Player, OfflineAttrType
    entityID = int(entityID)
    deviceID = request.POST.getone('deviceID', '')
    lock_level = int(request.POST.getone('lock_level', '50'))
    role = g_entityManager.get_player(entityID)
    if not role:
        Player.add_offline_attr(entityID,
                                Player.getAttributeIDByName('skip_guide'),
                                True, OfflineAttrType.Set)
        Player.add_offline_attr(entityID,
                                Player.getAttributeIDByName('lock_level'),
                                lock_level, OfflineAttrType.Set)
    else:
        role.skip_guide = True
        role.lock_level = lock_level
        role.save()
        role.sync()

    # lock device
    if not role:
        userID = Player.simple_load(entityID, ['userID']).userID
    else:
        userID = role.userID

    from user.model import User
    u = User.simple_load(userID, ['lock_device', 'imsi'])
    u.lock_device = deviceID or u.imsi
    u.save()
    return SUCCESS
Beispiel #2
0
def resetAttr(entityID, attrName):
    from entity.manager import g_entityManager
    entityID = int(entityID)
    p = g_entityManager.get_player(entityID)
    if not p:
        from player.model import Player, OfflineAttrType
        Player.add_offline_attr(entityID,
                                Player.getAttributeIDByName(attrName),
                                None,
                                type=OfflineAttrType.Reset)
        return SUCCESS
    else:
        try:
            f = p.fields[attrName]
            if callable(f.default):
                default = f.default()
            else:
                default = f.default
            setattr(p, attrName, default)
            p.save()
            p.sync()
        except:
            import traceback
            traceback.print_exc()
            return FAILURE
    return SUCCESS
Beispiel #3
0
def addAttr(entityID, attrName, value):
    from entity.manager import g_entityManager
    entityID = int(entityID)
    value = int(value)
    role = g_entityManager.get_player(entityID)
    if not role:
        from player.model import Player
        Player.add_offline_attr(entityID,
                                Player.getAttributeIDByName(attrName), value)
        return SUCCESS
    try:
        if not hasattr(role, attrName):
            return FAILURE
        current = getattr(role, attrName)
        if not isinstance(current, (int or long)):
            raise TypeError
        if attrName == "exp":
            from reward.base import set_exp
            set_exp(role, value)
        elif attrName == "level":
            if value == 0:
                return FAILURE
            from config.configs import get_config, LevelupConfig
            lconfigs = get_config(LevelupConfig)
            exp = 0
            for i in range(role.level + 1, role.level + value + 1):
                c = lconfigs.get(i)
                if not c:
                    return FAILURE
                exp += c.exp
            from reward.base import set_exp
            set_exp(role, exp)
        elif attrName == "totalbp":
            from pvp.rank import incr_score
            from player.model import PlayerRankRanking
            incr_score(entityID, value)
            PlayerRankRanking.sync_player(role)
        else:
            setattr(role, attrName, current + value)
        role.save()
        role.sync()
    except:
        import traceback
        traceback.print_exc()
        return FAILURE
    return SUCCESS
Beispiel #4
0
def setAttr(entityID, attrName, value):
    from entity.manager import g_entityManager
    entityID = int(entityID)
    value = int(value)
    role = g_entityManager.get_player(entityID)
    if not role:
        from player.model import Player, OfflineAttrType
        Player.add_offline_attr(entityID,
                                Player.getAttributeIDByName(attrName),
                                value,
                                type=OfflineAttrType.Set)
        return SUCCESS
    try:
        current = getattr(role, attrName)
        if not isinstance(current, (int or long)):
            raise TypeError
        setattr(role, attrName, value)
        role.save()
        role.sync()
    except:
        return FAILURE
    return SUCCESS