コード例 #1
0
def recharge_strategy(player_token, value):
    value = decimal.Decimal(value)
    activate = KeyValue.get_value(Keys.RECHARGE_TACTICS_ACTIVATE.value)
    if activate != str(True):
        return
    info = KeyValue.get_value(Keys.RECHARGE_TACTICS_INFO.value)
    if info is None or info == {}:
        return
    info = json.loads(info)
    now_time = int(time.strftime("%Y%m%d%H%M%S"))
    reward = 0
    if int(info['range'][0]) < now_time < int(info['range'][1]):
        if info['method'] == "INTERVAL":  # 区间
            for v in info['value']:
                if decimal.Decimal(v['min']) <= value < decimal.Decimal(v['max']):
                    reward = v['reward']
                    break
        if info['method'] == "FIXED":  # 固定值
            for v in info['value']:
                if decimal.Decimal(v['recharge_amount']) == value:
                    reward = v['reward_amount']
                    break
        if info['method'] == "PERCENTAGE":  # 百分比
            x = decimal.Decimal(info['value']) / 100
            reward = value * x
        if reward == 0:
            return
        if info['type'] == RechargeType.GOLD.value:
            Player.update_player_gold(player_token, reward)
        elif info['type'] == RechargeType.INTEGRAL.value:
            Player.update_player_integral(player_token, reward)
コード例 #2
0
def update_player_gold(token, value, lock_gold=0):
    """
    更新玩家金币
    :param lock_gold:
    :param token: 玩家Token
    :param value: 变动金额
    :return: Boolean
    """
    return Player.update_player_gold(token, value, lock_gold)
コード例 #3
0
def check(**params):
    if params['allow'] == RechargeStatusEnum.SUCCEED.value:
        ok, obj = RechargeRecord.check_recharge(**params)
        ok, player = Player.update_player_gold(obj.player.token, obj.pay_money)
        recharge_strategy(obj.player.token, obj.pay_money)
        return ok, player
    elif params['allow'] == RechargeStatusEnum.FAILED.value:
        ok, _ = RechargeRecord.check_recharge(**params)
        return ok, None
    return False, None
コード例 #4
0
def pig_open(player_id, token):
    """
    开奖
    :return: gold
    """
    gold = random.randint(1, 50)
    Player.update_player_integral(token, -500)
    ok, player = Player.update_player_gold(token, gold, gold)
    value = int(KeyValue.get_value(Keys.GOLDEN_PIG.value))
    KeyValue.update_value(Keys.GOLDEN_PIG.value, (value - 1))
    PigRecord.create(player_id=player_id, gold=gold)
    update_player_info(player)
    return gold