Skip to content
This repository has been archived by the owner on Jul 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request #46 from AndikaTanpaH/master
Browse files Browse the repository at this point in the history
add ability for websocket to manually level up pokemon
  • Loading branch information
iwean committed Sep 10, 2016
2 parents 992319a + 0174745 commit f9d79b4
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions PoGo.NecroBot.CLI/PoGo.NecroBot.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@
<Compile Include="WebSocketHandler\ActionCommands\HumanSnipePriorityPokemonHandler.cs" />
<Compile Include="WebSocketHandler\ActionCommands\FavoritePokemonHandler.cs" />
<Compile Include="WebSocketHandler\ActionCommands\DropItemHandler.cs" />
<Compile Include="WebSocketHandler\ActionCommands\LevelUpPokemonHandler.cs" />
<Compile Include="WebSocketHandler\GetCommands\Events\ConfigResponce.cs" />
<Compile Include="WebSocketHandler\GetCommands\Events\SnipeListResponce.cs" />
<Compile Include="WebSocketHandler\GetCommands\Events\WebResponce.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#region using directives

using System.Threading.Tasks;
using PoGo.NecroBot.Logic.State;
using SuperSocket.WebSocket;

#endregion

namespace PoGo.NecroBot.CLI.WebSocketHandler.ActionCommands
{
public class LevelUpPokemonHandler : IWebSocketRequestHandler
{
public string Command { get; private set;}

public LevelUpPokemonHandler()
{
Command = "LevelUpPokemon";
}

public async Task Handle(ISession session, WebSocketSession webSocketSession, dynamic message)
{
await Logic.Tasks.LevelUpSpecificPokemonTask.Execute(session, (ulong)message.PokemonId);
}
}
}
15 changes: 15 additions & 0 deletions PoGo.NecroBot.Logic/Event/PokemonLevelUpEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#region using directives

using POGOProtos.Enums;

#endregion

namespace PoGo.NecroBot.Logic.Event
{
public class PokemonLevelUpEvent : IEvent
{
public int Cp;
public PokemonId Id;
public ulong UniqueId;
}
}
2 changes: 2 additions & 0 deletions PoGo.NecroBot.Logic/PoGo.NecroBot.Logic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
<Compile Include="Event\SnipeEvent.cs" />
<Compile Include="Event\SnipeModeEvent.cs" />
<Compile Include="Event\PokemonListEvent.cs" />
<Compile Include="Event\PokemonLevelUpEvent.cs" />
<Compile Include="Event\SnipeScanEvent.cs" />
<Compile Include="Event\UpgradePokemonEvent.cs" />
<Compile Include="Event\UpdateEvent.cs" />
Expand Down Expand Up @@ -276,6 +277,7 @@
</Compile>
<Compile Include="Tasks\InventoryListTask.cs" />
<Compile Include="Tasks\LevelUpPokemonTask.cs" />
<Compile Include="Tasks\LevelUpSpecificPokemonTask.cs" />
<Compile Include="Tasks\PokemonListTask.cs" />
<Compile Include="Tasks\Farm.cs" />
<Compile Include="State\Session.cs" />
Expand Down
39 changes: 39 additions & 0 deletions PoGo.NecroBot.Logic/Tasks/LevelUpSpecificPokemonTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#region using directives

using System.Linq;
using System.Threading.Tasks;
using PoGo.NecroBot.Logic.Event;
using PoGo.NecroBot.Logic.Logging;
using PoGo.NecroBot.Logic.State;
using PoGo.NecroBot.Logic.Utils;

#endregion

namespace PoGo.NecroBot.Logic.Tasks
{
public class LevelUpSpecificPokemonTask
{
public static async Task Execute(ISession session, ulong pokemonId)
{
var all = await session.Inventory.GetPokemons();
var pokemons = all.OrderByDescending(x => x.Cp).ThenBy(n => n.StaminaMax);
var pokemon = pokemons.FirstOrDefault(p => p.Id == pokemonId);

if (pokemon == null) return;

var upgradeResult = await session.Inventory.UpgradePokemon(pokemon.Id);
if (upgradeResult.Result.ToString().ToLower().Contains("success"))
{
Logger.Write("Pokemon Upgraded:" + session.Translation.GetPokemonTranslation(upgradeResult.UpgradedPokemon.PokemonId) + ":" + upgradeResult.UpgradedPokemon.Cp, LogLevel.LevelUp);

session.EventDispatcher.Send(new PokemonLevelUpEvent{
Id = upgradeResult.UpgradedPokemon.PokemonId,
Cp = upgradeResult.UpgradedPokemon.Cp,
UniqueId = pokemon.Id
});

}
DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 0);
}
}
}

0 comments on commit f9d79b4

Please sign in to comment.