This repository has been archived by the owner on Jul 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from AndikaTanpaH/master
add ability for websocket to manually level up pokemon
- Loading branch information
Showing
5 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
PoGo.NecroBot.CLI/WebSocketHandler/ActionCommands/LevelUpPokemonHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |