Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket Respond to EggsListEvent #1439

Merged
merged 2 commits into from
Jul 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion PoGo.NecroBot.CLI/WebSocketInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,15 @@ private void HandleEvent(ProfileEvent evt)

private async void HandleMessage(WebSocketSession session, string message)
{
if (message == "PokemonList") await Logic.Tasks.PokemonListTask.Execute(_session);
switch (message)
{
case "PokemonList":
await Logic.Tasks.PokemonListTask.Execute(_session);
break;
case "EggsList":
await Logic.Tasks.EggsListTask.Execute(_session);
break;
}
}

private void HandleSession(WebSocketSession session)
Expand Down
17 changes: 17 additions & 0 deletions PoGo.NecroBot.Logic/Event/EggsListEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#region using directives

using System;
using System.Collections.Generic;
using POGOProtos.Data;
using POGOProtos.Inventory;

#endregion

namespace PoGo.NecroBot.Logic.Event
{
public class EggsListEvent : IEvent
{
public List<EggIncubator> Incubators { get; set; }
public object UnusedEggs { get; set; }
}
}
38 changes: 38 additions & 0 deletions PoGo.NecroBot.Logic/Tasks/EggsListTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#region using directives

using System;
using System.Linq;
using System.Threading.Tasks;
using PoGo.NecroBot.Logic.DataDumper;
using PoGo.NecroBot.Logic.Event;
using PoGo.NecroBot.Logic.PoGoUtils;
using PoGo.NecroBot.Logic.State;
using POGOProtos.Inventory.Item;

#endregion

namespace PoGo.NecroBot.Logic.Tasks
{
public class EggsListTask
{
public static async Task Execute(ISession session)
{
var incubators = (await session.Inventory.GetEggIncubators())
.Where(x => x.UsesRemaining > 0 || x.ItemId == ItemId.ItemIncubatorBasicUnlimited)
.OrderByDescending(x => x.ItemId == ItemId.ItemIncubatorBasicUnlimited)
.ToList();

var unusedEggs = (await session.Inventory.GetEggs())
.Where(x => string.IsNullOrEmpty(x.EggIncubatorId))
.OrderBy(x => x.EggKmWalkedTarget - x.EggKmWalkedStart)
.ToList();

session.EventDispatcher.Send(
new EggsListEvent
{
Incubators = incubators,
UnusedEggs = unusedEggs
});
}
}
}