Skip to content

Commit

Permalink
Merge pull request NecronomiconCoding#1439 from nicoschmitt/master
Browse files Browse the repository at this point in the history
WebSocket Respond to EggsListEvent
  • Loading branch information
NecronomiconCoding authored Jul 30, 2016
2 parents b362f65 + 2ac0ad0 commit 0c34852
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
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
});
}
}
}

0 comments on commit 0c34852

Please sign in to comment.