1313 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1414 */
1515
16-
1716package com .pokegoapi .api .inventory ;
1817
19- import POGOProtos .Inventory .Item .ItemDataOuterClass ;
2018import POGOProtos .Inventory .Item .ItemDataOuterClass .ItemData ;
2119import POGOProtos .Inventory .Item .ItemIdOuterClass .ItemId ;
2220import POGOProtos .Networking .Requests .Messages .RecycleInventoryItemMessageOuterClass .RecycleInventoryItemMessage ;
21+ import POGOProtos .Networking .Requests .Messages .UseIncenseMessageOuterClass .UseIncenseMessage ;
2322import POGOProtos .Networking .Requests .RequestTypeOuterClass ;
2423import POGOProtos .Networking .Responses .RecycleInventoryItemResponseOuterClass ;
2524import POGOProtos .Networking .Responses .RecycleInventoryItemResponseOuterClass .RecycleInventoryItemResponse .Result ;
25+ import POGOProtos .Networking .Responses .UseIncenseResponseOuterClass .UseIncenseResponse ;
26+
2627import com .google .protobuf .InvalidProtocolBufferException ;
2728import com .pokegoapi .api .PokemonGo ;
2829import com .pokegoapi .exceptions .LoginFailedException ;
2930import com .pokegoapi .exceptions .RemoteServerException ;
3031import com .pokegoapi .main .ServerRequest ;
32+ import com .pokegoapi .util .Log ;
3133
3234import java .util .Collection ;
3335import java .util .HashMap ;
@@ -55,44 +57,48 @@ public void addItem(Item item) {
5557 /**
5658 * Remove item result.
5759 *
58- * @param id the id
59- * @param quantity the quantity
60+ * @param id
61+ * the id
62+ * @param quantity
63+ * the quantity
6064 * @return the result
61- * @throws RemoteServerException the remote server exception
62- * @throws LoginFailedException the login failed exception
65+ * @throws RemoteServerException
66+ * the remote server exception
67+ * @throws LoginFailedException
68+ * the login failed exception
6369 */
6470 public Result removeItem (ItemId id , int quantity ) throws RemoteServerException , LoginFailedException {
6571 Item item = getItem (id );
6672 if (item .getCount () < quantity ) {
6773 throw new IllegalArgumentException ("You cannont remove more quantity than you have" );
6874 }
6975
70- RecycleInventoryItemMessage msg = RecycleInventoryItemMessage .newBuilder ()
71- .setItemId (id )
72- .setCount (quantity )
76+ RecycleInventoryItemMessage msg = RecycleInventoryItemMessage .newBuilder ().setItemId (id ).setCount (quantity )
7377 .build ();
7478
7579 ServerRequest serverRequest = new ServerRequest (RequestTypeOuterClass .RequestType .RECYCLE_INVENTORY_ITEM , msg );
7680 pgo .getRequestHandler ().sendServerRequests (serverRequest );
7781
7882 RecycleInventoryItemResponseOuterClass .RecycleInventoryItemResponse response ;
7983 try {
80- response = RecycleInventoryItemResponseOuterClass .RecycleInventoryItemResponse .parseFrom (serverRequest .getData ());
84+ response = RecycleInventoryItemResponseOuterClass .RecycleInventoryItemResponse
85+ .parseFrom (serverRequest .getData ());
8186 } catch (InvalidProtocolBufferException e ) {
8287 throw new RemoteServerException (e );
8388 }
8489
85- if (response .getResult () == RecycleInventoryItemResponseOuterClass .RecycleInventoryItemResponse .Result .SUCCESS ) {
90+ if (response
91+ .getResult () == RecycleInventoryItemResponseOuterClass .RecycleInventoryItemResponse .Result .SUCCESS ) {
8692 item .setCount (response .getNewCount ());
8793 }
8894 return response .getResult ();
8995 }
9096
91-
9297 /**
9398 * Gets item.
9499 *
95- * @param type the type
100+ * @param type
101+ * the type
96102 * @return the item
97103 */
98104 public Item getItem (ItemId type ) {
@@ -108,7 +114,6 @@ public Item getItem(ItemId type) {
108114 return items .get (type );
109115 }
110116
111-
112117 public Collection <Item > getItems () {
113118 return items .values ();
114119 }
@@ -125,4 +130,46 @@ public int getItemsCount() {
125130 }
126131 return ct ;
127132 }
133+
134+ public void useItem (ItemId type ) throws RemoteServerException , LoginFailedException {
135+ if (type == ItemId .UNRECOGNIZED ) {
136+ throw new IllegalArgumentException ("You cannot use item for UNRECOGNIZED" );
137+ }
138+
139+ switch (type ) {
140+ case ITEM_INCENSE_ORDINARY :
141+ case ITEM_INCENSE_SPICY :
142+ case ITEM_INCENSE_COOL :
143+ case ITEM_INCENSE_FLORAL :
144+ useIncense (type );
145+ break ;
146+ default :
147+ break ;
148+ }
149+ }
150+
151+ public void useIncense (ItemId type ) throws RemoteServerException , LoginFailedException {
152+ UseIncenseMessage useIncenseMessage =
153+ UseIncenseMessage .newBuilder ()
154+ .setIncenseType (type )
155+ .setIncenseTypeValue (type .getNumber ())
156+ .build ();
157+
158+ ServerRequest useIncenseRequest = new ServerRequest (RequestTypeOuterClass .RequestType .USE_INCENSE ,
159+ useIncenseMessage );
160+ pgo .getRequestHandler ().sendServerRequests (useIncenseRequest );
161+
162+ UseIncenseResponse response = null ;
163+ try {
164+ response = UseIncenseResponse .parseFrom (useIncenseRequest .getData ());
165+ Log .i ("Main" , "Use incense result: " + response .getResult ());
166+ } catch (InvalidProtocolBufferException e ) {
167+ throw new RemoteServerException (e );
168+ }
169+ }
170+
171+ public void useIncense () throws RemoteServerException , LoginFailedException {
172+ useIncense (ItemId .ITEM_INCENSE_ORDINARY );
173+ }
174+
128175}
0 commit comments