Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…o dev
  • Loading branch information
solderzzc committed Sep 2, 2016
2 parents 8b22f93 + 8edc2a8 commit 27534e0
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
12 changes: 12 additions & 0 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@
"use_lucky_egg": false
}
},
{
"type": "UseIncense",
"config": {
"use_incense": false,
"use_order": [
"ordinary",
"spicy",
"cool",
"floral"
]
}
},
{
"type": "RecycleItems",
"config": {
Expand Down
5 changes: 5 additions & 0 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,11 @@ def _register_events(self):
'forts_found',
parameters=('json')
)
# UseIncense
self.event_manager.register_event(
'use_incense',
parameters=('type', 'incense_count')
)

def tick(self):
self.health_record.heartbeat()
Expand Down
1 change: 1 addition & 0 deletions pokemongo_bot/cell_workers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
from random_alive_pause import RandomAlivePause
from show_best_pokemon import ShowBestPokemon
from telegram_task import TelegramTask
from use_incense import UseIncense
80 changes: 80 additions & 0 deletions pokemongo_bot/cell_workers/use_incense.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import time
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.worker_result import WorkerResult
from pokemongo_bot.item_list import Item
from pokemongo_bot import inventory

class UseIncense(BaseTask):
SUPPORTED_TASK_API_VERSION = 1

def initialize(self):
self.start_time = 0
self.use_incense = self.config.get('use_incense', False)
self.use_order = self.config.get('use_order', {})
self._update_inventory()

self.types = {
401: "Ordinary",
402: "Spicy",
403: "Cool",
404: "Floral"
}

def _get_type(self):
for order in self.use_order:
if order == "ordinary" and self.incense_ordinary_count > 0:
return Item.ITEM_INCENSE_ORDINARY.value
if order == "spicy" and self.incense_spicy_count > 0:
return Item.ITEM_INCENSE_SPICY.value
if order == "cool" and self.incense_cool_count > 0:
return Item.ITEM_INCENSE_COOL.value
if order == "floral" and self.incense_floral_count > 0:
return Item.ITEM_INCENSE_FLORAL.value

return Item.ITEM_INCENSE_ORDINARY.value

def _update_inventory(self):
self.incense_ordinary_count = inventory.items().get(Item.ITEM_INCENSE_ORDINARY.value).count
self.incense_spicy_count = inventory.items().get(Item.ITEM_INCENSE_SPICY.value).count
self.incense_cool_count = inventory.items().get(Item.ITEM_INCENSE_COOL.value).count
self.incense_floral_count = inventory.items().get(Item.ITEM_INCENSE_FLORAL.value).count

def _has_count(self):
return self.incense_ordinary_count > 0 or self.incense_spicy_count > 0 or self.incense_cool_count > 0 or self.incense_floral_count > 0

def _should_run(self):
if self._has_count() > 0 and self.start_time == 0:
return True

using_incense = time.time() - self.start_time < 1800
if not using_incense:
self._update_inventory()
if self._has_count() and self.use_incense:
return True

def work(self):
if self._should_run():
self.start_time = time.time()
type = self._get_type()
response_dict = self.bot.api.use_incense(incense_type=type)
result = response_dict.get('responses', {}).get('USE_INCENSE', {}).get('result', 0)
if result is 1:
self.emit_event(
'use_incense',
formatted="Using {type} incense. {incense_count} incense remaining",
data={
'type': self.types.get(type, 'Unknown'),
'incense_count': inventory.items().get(type).count
}
)
else:
self.emit_event(
'use_incense',
formatted="Unable to use incense {type}. {incense_count} incense remaining",
data={
'type': self.types.get(type, 'Unknown'),
'incense_count': inventory.items().get(type).count
}
)

return WorkerResult.SUCCESS
1 change: 1 addition & 0 deletions pokemongo_bot/event_handlers/colored_logging_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class ColoredLoggingHandler(EventHandler):
'unknown_spin_result': 'red',
'unset_pokemon_nickname': 'red',
'vip_pokemon': 'red',
'use_incense': 'blue',

'arrived_at_cluster': 'none',
'arrived_at_fort': 'none',
Expand Down

0 comments on commit 27534e0

Please sign in to comment.