Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keep stardust count updated #5187

Merged
merged 1 commit into from
Sep 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ def player_data(self):
"""
return self._player

@property
def stardust(self):
return filter(lambda y: y['name'] == 'STARDUST', self._player['currencies'])[0]['amount']

@stardust.setter
def stardust(self, value):
filter(lambda y: y['name'] == 'STARDUST', self._player['currencies'])[0]['amount'] = value

def __init__(self, db, config):

self.database = db
Expand Down Expand Up @@ -430,6 +438,7 @@ def _register_events(self):
parameters=(
'pokemon',
'ncp', 'cp', 'iv', 'iv_display', 'exp',
'stardust',
'encounter_id',
'latitude',
'longitude',
Expand Down
1 change: 1 addition & 0 deletions pokemongo_bot/cell_workers/incubate_eggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def _hatch_eggs(self):
)
# hatching egg gets exp too!
inventory.player().exp += xp[i]
self.bot.stardust += stardust[i]

with self.bot.database as conn:
c = conn.cursor()
Expand Down
84 changes: 42 additions & 42 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,31 +562,48 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):
pokemon.unique_id = response_dict['responses']['CATCH_POKEMON']['captured_pokemon_id']
self.bot.metrics.captured_pokemon(pokemon.name, pokemon.cp, pokemon.iv_display, pokemon.iv)

try:
inventory.pokemons().add(pokemon)
exp_gain = sum(response_dict['responses']['CATCH_POKEMON']['capture_award']['xp'])
# update player's exp
inventory.player().exp += exp_gain
awards = response_dict['responses']['CATCH_POKEMON']['capture_award']
exp_gain, candy_gain, stardust_gain = self.extract_award(awards)

self.emit_event(
'pokemon_caught',
formatted='Captured {pokemon}! [CP {cp}] [NCP {ncp}] [Potential {iv}] [{iv_display}] ({caught_last_24_hour}/{daily_catch_limit}) [+{exp} exp]',
data={
'pokemon': pokemon.name,
'ncp': round(pokemon.cp_percent, 2),
'cp': pokemon.cp,
'iv': pokemon.iv,
'iv_display': pokemon.iv_display,
'exp': exp_gain,
'encounter_id': self.pokemon['encounter_id'],
'latitude': self.pokemon['latitude'],
'longitude': self.pokemon['longitude'],
'pokemon_id': pokemon.pokemon_id,
'caught_last_24_hour': self.caught_last_24_hour + 1,
'daily_catch_limit': self.daily_catch_limit
}
self.emit_event(
'pokemon_caught',
formatted='Captured {pokemon}! [CP {cp}] [NCP {ncp}] [Potential {iv}] [{iv_display}] ({caught_last_24_hour}/{daily_catch_limit}) [+{exp} exp] [+{stardust} stardust]',
data={
'pokemon': pokemon.name,
'ncp': round(pokemon.cp_percent, 2),
'cp': pokemon.cp,
'iv': pokemon.iv,
'iv_display': pokemon.iv_display,
'exp': exp_gain,
'stardust': stardust_gain,
'encounter_id': self.pokemon['encounter_id'],
'latitude': self.pokemon['latitude'],
'longitude': self.pokemon['longitude'],
'pokemon_id': pokemon.pokemon_id,
'caught_last_24_hour': self.caught_last_24_hour + 1,
'daily_catch_limit': self.daily_catch_limit
}
)

)
inventory.pokemons().add(pokemon)
inventory.player().exp += exp_gain
self.bot.stardust += stardust_gain
candy = inventory.candies().get(pokemon.pokemon_id)
candy.add(candy_gain)

self.emit_event(
'gained_candy',
formatted='You now have {quantity} {type} candy!',
data = {
'quantity': candy.quantity,
'type': candy.type,
},
)

self.bot.softban = False


try:
with self.bot.database as conn:
c = conn.cursor()
c.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='catch_log'")
Expand Down Expand Up @@ -623,20 +640,6 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):
except IOError as e:
self.logger.info('[x] Error while opening location file: %s' % e)

candy = inventory.candies().get(pokemon.pokemon_id)
candy.add(self.get_candy_gained_count(response_dict))

self.emit_event(
'gained_candy',
formatted='You now have {quantity} {type} candy!',
data = {
'quantity': candy.quantity,
'type': candy.type,
},
)

self.bot.softban = False

elif catch_pokemon_status == CATCH_STATUS_MISSED:
self.emit_event(
'pokemon_capture_failed',
Expand All @@ -649,11 +652,8 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):

break

def get_candy_gained_count(self, response_dict):
total_candy_gained = 0
for candy_gained in response_dict['responses']['CATCH_POKEMON']['capture_award']['candy']:
total_candy_gained += candy_gained
return total_candy_gained
def extract_award(self, awards):
return sum(awards['xp']), sum(awards['candy']), sum(awards['stardust'])

def generate_spin_parameter(self, throw_parameters):
spin_success_rate = self.catch_throw_parameters_spin_success_rate
Expand Down