Skip to content

Commit

Permalink
Added evolve and release push actions for pokemon (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
andythorne authored and Max Leiter committed Jul 31, 2016
1 parent bcb90df commit f1d90b5
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 8 deletions.
3 changes: 2 additions & 1 deletion config/userdata.js.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ var userInfo = {
zoom: 16,
userFollow: true,
gMapsAPIKey: "YOUR_API_KEY_HERE",
botPath: true
botPath: true,
actionsEnabled: false
};
1 change: 1 addition & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ html, body {
right: auto !important;
bottom: 10%;
left:7%;
z-index: 0
}
#bots-list {
max-height: 80vh;
Expand Down
96 changes: 89 additions & 7 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,69 @@
'use strict';

var socket_io;
var pokemonActions;

$(document).ready(function() {
mapView.init();
var socket = io.connect('http://' + document.domain + ':' + location.port + '/event');
socket.on('connect', function() {
socket_io = io.connect('http://' + document.domain + ':' + location.port + '/event');
socket_io.on('connect', function() {
console.log('connected!');
});
socket.on('logging', function(msg) {
socket_io.on('logging', function(msg) {
for(var i = 0; i < msg.length; i++) {
mapView.log({
message: msg[i].output,
color: msg[i].color + "-text"
});
}
});

pokemonActions = function(socket_io){
var actions = {
releasePokemon: {
button: function(pokemon, user_id){
return '<a href="#!" onClick="pokemonActions.releasePokemon.action(\''+pokemon.unique_id+'\')">Release</a>';
},
action: function(id){
if(confirm("Are you sure you want to release this pokemon? THIS CANNOT BE UNDONE!")){
socket_io.emit('user_action', {'event':'release_pokemon', data: {'pokemon_id': id}});
mapView.sortAndShowBagPokemon(false, false);
}
}
},

evolvePokemon: {
button: function(pokemon, user_id){
var pkmnData = mapView.pokemonArray[pokemon.id - 1],
candy = mapView.getCandy(pokemon.id, user_id),
canEvolve = false;
if("undefined" != typeof pkmnData['Next evolution(s)'] && "undefined" != typeof pkmnData['Next Evolution Requirements']){
canEvolve = (candy >= pkmnData['Next Evolution Requirements']['Amount'])
}
return (canEvolve ? '<a href="#!" onClick="pokemonActions.evolvePokemon.action(\''+pokemon.unique_id+'\')">Evolve</a>' : false);
},
action: function(id){
if(confirm("Are you sure you want to evolve this pokemon? THIS CANNOT BE UNDONE!")){
socket_io.emit('user_action', {'event':'evolve_pokemon', data: {'pokemon_id': id}});
mapView.sortAndShowBagPokemon(false, false);
}
}
}
}

var enabledActions = {};
for(var i in actions){
if(mapView.settings.actionsEnabled === true){
enabledActions[i] = actions[i];
} else if(Array.isArray(mapView.settings.actionsEnabled)){
if (mapView.settings.actionsEnabled.indexOf(i) !== -1){
enabledActions[i] = actions[i];
}
}
}

return enabledActions;
}(socket_io)
});

var mapView = {
Expand Down Expand Up @@ -534,8 +584,8 @@ var mapView = {
eggs = 0,
sortedPokemon = [],
out = '',
user = self.user_data[self.settings.users[user_id]],
user_id = user_id || 0;
user_id = user_id || 0,
user = self.user_data[self.settings.users[user_id]];

if (!user.bagPokemon.length) return;

Expand All @@ -547,6 +597,7 @@ var mapView = {
}
var pokemonData = user.bagPokemon[i].inventory_item_data.pokemon_data,
pkmID = pokemonData.pokemon_id,
pkmUID = pokemonData.id,
pkmnName = self.pokemonArray[pkmID - 1].Name,
pkmCP = pokemonData.cp,
pkmIVA = pokemonData.individual_attack || 0,
Expand All @@ -560,6 +611,7 @@ var mapView = {
sortedPokemon.push({
"name": pkmnName,
"id": pkmID,
"unique_id": pkmUID,
"cp": pkmCP,
"iv": pkmIV,
"attack": pkmIVA,
Expand Down Expand Up @@ -628,6 +680,7 @@ var mapView = {
}
for (var i = 0; i < sortedPokemon.length; i++) {
var pkmnNum = sortedPokemon[i].id,
pkmnUnique = sortedPokemon[i].unique_id,
pkmnImage = self.pad_with_zeroes(pkmnNum, 3) + '.png',
pkmnName = self.pokemonArray[pkmnNum - 1].Name,
pkmnCP = sortedPokemon[i].cp,
Expand All @@ -647,8 +700,36 @@ var mapView = {
'<br><b>CP:</b>' + pkmnCP +
'<br><b>IV:</b> ' + (pkmnIV >= 0.8 ? '<span style="color: #039be5">' + pkmnIV + '</span>' : pkmnIV) +
'<br><b>A/D/S:</b> ' + pkmnIVA + '/' + pkmnIVD + '/' + pkmnIVS +
'<br><b>Candy: </b>' + candyNum +
'</div>';
'<br><b>Candy: </b>' + candyNum
;

if(Object.keys(pokemonActions).length){
var actionsOut = ''
for(var pa in pokemonActions){
var content = pokemonActions[pa].button(sortedPokemon[i], user_id);
if(content){
actionsOut += '<li>'+pokemonActions[pa].button(sortedPokemon[i], user_id)+'</li>';
}
}

if(actionsOut){
out +=
'<div>' +
' <a class="dropdown-button btn" href="#" data-activates="poke-actions-'+pkmnUnique+'">' +
' Actions' +
' </a>' +
' <ul id="poke-actions-'+pkmnUnique+'" class="dropdown-content">' +
actionsOut +
' </ul>' +
'</div><br>';
} else {
out += '<div>' +
' <a class="dropdown-button btn disabled" href="#">Actions</a>' +
'</div><br>';
}
}

out += '</div>';
}
// Add number of eggs
out += '<div class="col s12 m4 l3 center" style="float: left;"><img src="image/items/Egg.png" class="png_img"><br><b>You have ' + eggs + ' egg' + (eggs !== 1 ? "s" : "") + '</div>';
Expand Down Expand Up @@ -677,6 +758,7 @@ var mapView = {
return (nth % 4 === 0) ? '</div></div><div class="row"><div' : match;
});
$('#subcontent').html(out);
$('.dropdown-button').dropdown();
},
sortAndShowPokedex: function(sortOn, user_id) {
var self = this,
Expand Down

4 comments on commit f1d90b5

@trentondyck
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Evolve action isn't working for me.. Reading the code I feel like it has something to do with this socket.io 404...
"GET /socket.io/?EIO=3&transport=polling&t=LPcBN8L HTTP/1.0" 404 -

I tried running the default python simple http server as well as nginx for the job with a location ~ .io

@BobbyWibowo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phattrent Did you use OpenPoGoBot?

@trentondyck
Copy link

@trentondyck trentondyck commented on f1d90b5 Aug 7, 2016 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BobbyWibowo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phattrent Yes. That feature was intended to be used with OpenPoGoBot.

Please sign in to comment.