MCPcopy
hub / github.com/PokemonGoF/PokemonGo-Bot / Item

Class Item

pokemongo_bot/inventory.py:181–245  ·  view source on GitHub ↗

Representation of an item.

Source from the content-addressed store, hash-verified

179
180
181class Item(object):
182 """
183 Representation of an item.
184 """
185 def __init__(self, item_id, item_count):
186 """
187 Representation of an item
188 :param item_id: ID of the item
189 :type item_id: int
190 :param item_count: Quantity of the item
191 :type item_count: int
192 :return: An item
193 :rtype: Item
194 """
195 self.id = item_id
196 self.name = Items.name_for(self.id)
197 self.count = item_count
198
199 def remove(self, amount):
200 """
201 Remove a specified amount of an item from the cached inventory.
202 Note that it does **NOT** removes it in the server, it only removes it from the local cached inventory.
203 :param amount: Amount to remove
204 :type amount: int
205 :return: Nothing
206 :rtype: None
207 """
208 if self.count < amount:
209 raise Exception('Tried to remove more {} than you have'.format(self.name))
210 self.count -= amount
211
212 def recycle(self, amount_to_recycle):
213 """
214 Recycle (discard) the specified amount of item from the item inventory.
215 It is making a call to the server to request a recycling as well as updating the cached inventory.
216 :param amount_to_recycle: The amount to recycle.
217 :type amount_to_recycle: int
218 :return: Returns whether or not the task went well
219 :rtype: worker_result.WorkerResult
220 """
221 if self.count < amount_to_recycle:
222 raise Exception('Tried to remove more {} than you have'.format(self.name))
223
224 item_recycler = ItemRecycler(_inventory.bot, self, amount_to_recycle)
225 item_recycler_work_result = item_recycler.work()
226
227 if item_recycler.is_recycling_success():
228 self.remove(amount_to_recycle)
229
230 return item_recycler_work_result
231
232 def add(self, amount):
233 """
234 Add a specified amount of the item to the local cached inventory
235 :param amount: Amount to add
236 :type amount: int
237 :return: Nothing.
238 :rtype: None

Callers 3

parseMethod · 0.70
getMethod · 0.70
getMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected