singlerider / lorenzotherobot

Twitch Chat bot written in Python
17 stars 9 forks source link

!catch chances #73

Closed kyroskoh closed 8 years ago

kyroskoh commented 8 years ago

Since now the !catch is all along 100% chance to catch a wild pokemon... how about add some % probability to be random so that the chance to be lower to allow the user to !catch it.

singlerider commented 8 years ago

When designing the !catch feature, I wanted to reward players for a timely response. I reasoned, at the time that it would provide less incentive to players if their Pokemon were less guaranteed to be captured, in a competitive sense, even if they were the first to attempt to catch it.

An alternative I would recommend is Pokeballs, Greatballs, Masterballs, etc. This would be an additional hurdle to jump through for players though and I think you'll see a lower rate of player interaction. If you want it for your version, I can help you build it, but mine will remain the same.

kyroskoh commented 8 years ago

It is great that you could help me on that!

That type of balls would work... I am not sure if it requires much efforts to develop that type of chances using the balls...

If not, the probability will be fine.

Thanks in advance. :+1:

singlerider commented 8 years ago

players will need these items in their inventory and a way to use them instead of just !catch. I think it will be confusing for players.

kyroskoh commented 8 years ago

Rethinking about it, it will be a bit of hassle (which add more steps) for the users to interact with the bot... I just feel like making !catch (with % luck) -- not just for the first person to !catch it, just let an user with that (high % of luck) to !catch it.

Probably using a random int (1-10) to do a probability?

6-10 = Success 1-5 = Failed

singlerider commented 8 years ago

Replace your src/lib/commands/catch.py with:

https://gist.github.com/singlerider/16ebb1bcdc09276ea4e4813c899131f4

import random

import globals
from src.lib.queries.points_queries import *
from src.lib.queries.pokemon_queries import *

PROBABILITY = 90  # out of 100

def catch(**kwargs):
    if PROBABILITY > 100:
        PROBABILITY = 100
    channel = kwargs.get("channel", "testchannel").lstrip("#")
    if globals.CHANNEL_INFO[channel]['caught'] is False:
        pokemon_trainer = kwargs.get("username", "testuser")
        # This is here for if the user is brand new. This creates an entry in
        # the users table, which userpokemon is dependent on
        modify_user_points(pokemon_trainer, 0)
        open_position, occupied_positions = find_open_party_positions(
            pokemon_trainer)
        desired_level = 5
        pokemon_id = get_pokemon_id_from_name(
            globals.CHANNEL_INFO[channel]['pokemon'])
        if pokemon_id is None:
            return "Pokemon not found! Check your spelling"
        if len(open_position) > 0:
            probability_decision = random.randint(1,100)
            if probability_decision <= PROBABILITY:
                globals.CHANNEL_INFO[channel]['caught'] = True
                return insert_user_pokemon(
                    pokemon_trainer, pokemon_trainer, open_position[0],
                    pokemon_id, desired_level,
                    globals.CHANNEL_INFO[channel]['pokemon'],
                    None, None)
            else:
                return "You missed! Try again!!!!"
        else:
            return "No open slots in your party."
    else:
        return "Too slow!"
kyroskoh commented 8 years ago

Hey dude, when I load the new catch.py, the !catch isn't working... It displayed as "How to use !catch: !catch"

singlerider commented 8 years ago

I didn't test the code. Check the command line console to find the error.

On Mon, May 2, 2016, 2:05 AM Kyros Koh notifications@github.com wrote:

Hey dude, when I load the new catch.py, the !catch isn't working... It displayed as "How to use !catch: !catch"

— You are receiving this because you modified the open/close state.

Reply to this email directly or view it on GitHub https://github.com/singlerider/lorenzotherobot/issues/73#issuecomment-216161734

kyroskoh commented 8 years ago

The error as follows:

local variable 'PROBABILITY' referenced before assignment Traceback (most recent call last): File "/root/kyros_pokemon/src/lib/functions_commands.py", line 132, in pass_to_function return function(username=username, channel=channel) File "/root/kyros_pokemon/src/lib/commands/catch.py", line 10, in catch if PROBABILITY > 100: UnboundLocalError: local variable 'PROBABILITY' referenced before assignment

singlerider commented 8 years ago

Just move the top PROBABILITY variable into the catch function

kyroskoh commented 8 years ago

Or do I have to put:

global PROBABILITY ?

singlerider commented 8 years ago

Don't do a global variable. Moving it into the function should be fine

kyroskoh commented 8 years ago

So my code is sort of... like this:

import random

import globals
from src.lib.queries.points_queries import *
from src.lib.queries.pokemon_queries import *

def catch(**kwargs):
    PROBABILITY = 90  # out of 100
    if PROBABILITY > 100:
        PROBABILITY = 100
    channel = kwargs.get("channel", "testchannel").lstrip("#")
    if globals.CHANNEL_INFO[channel]['caught'] is False:
        pokemon_trainer = kwargs.get("username", "testuser")
        # This is here for if the user is brand new. This creates an entry in
        # the users table, which userpokemon is dependent on
        modify_user_points(pokemon_trainer, 0)
        open_position, occupied_positions = find_open_party_positions(
            pokemon_trainer)
        desired_level = 5
        pokemon_id = get_pokemon_id_from_name(
            globals.CHANNEL_INFO[channel]['pokemon'])
        if pokemon_id is None:
            return "Pokemon not found! Check your spelling"
        if len(open_position) > 0:
            probability_decision = random.randint(1,100)
            if probability_decision <= PROBABILITY:
                globals.CHANNEL_INFO[channel]['caught'] = True
                return insert_user_pokemon(
                    pokemon_trainer, pokemon_trainer, open_position[0],
                    pokemon_id, desired_level,
                    globals.CHANNEL_INFO[channel]['pokemon'],
                    None, None)
            else:
                return "You missed! Try again!!!!"
        else:
            return "No open slots in your party."
    else:
        return "Too slow!"
singlerider commented 8 years ago

That should be good