-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 #1719 from nicoschmitt/transfergui
Websocket: Allow Pokemon Transfer from the GUI
- Loading branch information
Showing
4 changed files
with
106 additions
and
5 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
53 changes: 53 additions & 0 deletions
53
PoGo.NecroBot.CLI/WebSocketHandler/BasicGetCommands/Tasks/TransferPokemonTask.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,53 @@ | ||
using PoGo.NecroBot.CLI.WebSocketHandler.BasicGetCommands.Events; | ||
using PoGo.NecroBot.CLI.WebSocketHandler.BasicGetCommands.Helpers; | ||
using PoGo.NecroBot.Logic.State; | ||
using POGOProtos.Inventory.Item; | ||
using SuperSocket.WebSocket; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace PoGo.NecroBot.CLI.WebSocketHandler.BasicGetCommands.Tasks | ||
{ | ||
class TransferPokemonTask | ||
{ | ||
public static async Task Execute(ISession session, WebSocketSession webSocketSession, ulong pokemonId, string requestID) | ||
{ | ||
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 pokemonSettings = await session.Inventory.GetPokemonSettings(); | ||
var pokemonFamilies = await session.Inventory.GetPokemonFamilies(); | ||
|
||
await session.Client.Inventory.TransferPokemon(pokemonId); | ||
await session.Inventory.DeletePokemonFromInvById(pokemonId); | ||
|
||
var bestPokemonOfType = (session.LogicSettings.PrioritizeIvOverCp | ||
? await session.Inventory.GetHighestPokemonOfTypeByIv(pokemon) | ||
: await session.Inventory.GetHighestPokemonOfTypeByCp(pokemon)) ?? pokemon; | ||
|
||
var setting = pokemonSettings.Single(q => q.PokemonId == pokemon.PokemonId); | ||
var family = pokemonFamilies.First(q => q.FamilyId == setting.FamilyId); | ||
|
||
family.Candy_++; | ||
|
||
// Broadcast event as everyone would benefit | ||
session.EventDispatcher.Send(new Logic.Event.TransferPokemonEvent | ||
{ | ||
Id = pokemon.PokemonId, | ||
Perfection = Logic.PoGoUtils.PokemonInfo.CalculatePokemonPerfection(pokemon), | ||
Cp = pokemon.Cp, | ||
BestCp = bestPokemonOfType.Cp, | ||
BestPerfection = Logic.PoGoUtils.PokemonInfo.CalculatePokemonPerfection(bestPokemonOfType), | ||
FamilyCandies = family.Candy_ | ||
}); | ||
|
||
await Task.Delay(500); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
PoGo.NecroBot.CLI/WebSocketHandler/BasicGetCommands/TransferPokemonHandler.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,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using SuperSocket.WebSocket; | ||
using PoGo.NecroBot.CLI.WebSocketHandler.BasicGetCommands.Tasks; | ||
using PoGo.NecroBot.Logic.State; | ||
|
||
namespace PoGo.NecroBot.CLI.WebSocketHandler.BasicGetCommands | ||
{ | ||
public class TransferPokemonHandler : IWebSocketRequestHandler | ||
{ | ||
public string Command { get; private set;} | ||
|
||
public TransferPokemonHandler() | ||
{ | ||
Command = "TransferPokemon"; | ||
} | ||
|
||
public async Task Handle(ISession session, WebSocketSession webSocketSession, dynamic message) | ||
{ | ||
await TransferPokemonTask.Execute(session, webSocketSession, (ulong)message.PokemonId, (string)message.RequestID); | ||
} | ||
} | ||
} |
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