Skip to content

Commit

Permalink
Fixed battle
Browse files Browse the repository at this point in the history
Moved more of P3D specific code to the P3D project
Disabled Pokemon Validation code for now
  • Loading branch information
Aragas committed Jun 6, 2023
1 parent 64f8403 commit 4ce7197
Show file tree
Hide file tree
Showing 78 changed files with 233 additions and 183 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.Extensions.DependencyInjection;

using P3D.Legacy.Common.Packets;
using P3D.Legacy.Server.Application.CommandHandlers.Administration;
using P3D.Legacy.Server.Application.CommandHandlers.Player;
using P3D.Legacy.Server.Application.CommandHandlers.Trade;
Expand Down Expand Up @@ -51,7 +50,6 @@ public static IServiceCollection AddApplication(this IServiceCollection services
services.AddQueryHandler<GetWorldStateQueryHandler>();


services.AddSingleton<IP3DPacketFactory, P3DPacketServerFactory>();

services.AddScoped<ConnectionContextHandlerFactory>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging;
/*
using Microsoft.Extensions.Logging;
using P3D.Legacy.Common.Monsters;
using P3D.Legacy.Server.Application.Queries.Player;
Expand Down Expand Up @@ -31,4 +32,5 @@ public async Task<IMonsterInstance> HandleAsync(GetMonsterByDataQuery query, Can
return await _monsterRepository.GetByDataAsync(monsterData, ct);
}
}
}
}
*/
2 changes: 1 addition & 1 deletion src/P3D.Legacy.Server.Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

using P3D.Legacy.Common.Packets;
using P3D.Legacy.Server.Benchmark.Options;
using P3D.Legacy.Server.Benchmark.Services;
using P3D.Legacy.Server.Client.P3D;
using P3D.Legacy.Server.Client.P3D.Packets;

using System.CommandLine.Binding;
using System.CommandLine.Builder;
Expand Down
8 changes: 4 additions & 4 deletions src/P3D.Legacy.Server.Benchmark/Services/BenchmarkService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
using Microsoft.Extensions.Options;

using P3D.Legacy.Common;
using P3D.Legacy.Common.Packets;
using P3D.Legacy.Common.Packets.Chat;
using P3D.Legacy.Common.Packets.Common;
using P3D.Legacy.Common.Packets.Server;
using P3D.Legacy.Server.Benchmark.Options;
using P3D.Legacy.Server.Client.P3D;
using P3D.Legacy.Server.Client.P3D.Packets;
using P3D.Legacy.Server.Client.P3D.Packets.Chat;
using P3D.Legacy.Server.Client.P3D.Packets.Common;
using P3D.Legacy.Server.Client.P3D.Packets.Server;

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

using P3D.Legacy.Common.Packets.Client;
using P3D.Legacy.Common.Packets.Server;
using P3D.Legacy.Server.Benchmark.Options;
using P3D.Legacy.Server.Client.P3D;
using P3D.Legacy.Server.Client.P3D.Packets.Client;
using P3D.Legacy.Server.Client.P3D.Packets.Server;

using System;
using System.Diagnostics;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace P3D.Legacy.Common.Data.P3DDatas
namespace P3D.Legacy.Server.Client.P3D.Data.P3DDatas
{
public sealed record BattleClientData : P3DData
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

namespace P3D.Legacy.Common.Data.P3DDatas
namespace P3D.Legacy.Server.Client.P3D.Data.P3DDatas
{
public sealed record BattleEndRoundData : P3DData
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

namespace P3D.Legacy.Common.Data.P3DDatas
namespace P3D.Legacy.Server.Client.P3D.Data.P3DDatas
{
public sealed record BattleHostData : P3DData
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Globalization;

namespace P3D.Legacy.Common.Data.P3DDatas
namespace P3D.Legacy.Server.Client.P3D.Data.P3DDatas
{
// If LeadMonsterIndex is not null, this is a confirmation, else client just gives the monsters for the battle
public sealed record BattleOfferData : P3DData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;

namespace P3D.Legacy.Common.Data.P3DDatas
namespace P3D.Legacy.Server.Client.P3D.Data.P3DDatas
{
public abstract record P3DData
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace P3D.Legacy.Common.Data.P3DDatas
namespace P3D.Legacy.Server.Client.P3D.Data.P3DDatas
{
public sealed record TradeData : P3DData
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
using System;
using P3D.Legacy.Common;

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Globalization;
using System.Linq;

namespace P3D.Legacy.Common
namespace P3D.Legacy.Server.Client.P3D
{
public sealed record DataItemStorage : IReadOnlyCollection<string>
{
private static int BootlegCount(IReadOnlyDictionary<int, string> dataItems) => dataItems.Count > 0 ? dataItems.LastOrDefault().Key + 1 : 0;
private static int BootlegCount(Dictionary<int, string> dataItems) => dataItems.Count > 0 ? dataItems.LastOrDefault().Key + 1 : 0;

private static IEnumerable<string> Iterate(IReadOnlyDictionary<int, string> dataItems)
private static IEnumerable<string> Iterate(Dictionary<int, string> dataItems)
{
var min = 0;
var max = BootlegCount(dataItems);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using P3D.Legacy.Common.Packets;
using P3D.Legacy.Server.Abstractions;
using P3D.Legacy.Server.Abstractions;
using P3D.Legacy.Server.Client.P3D.Packets;
using P3D.Legacy.Server.CQERS.Events;

namespace P3D.Legacy.Server.Client.P3D.Events
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using P3D.Legacy.Common;
using P3D.Legacy.Server.Abstractions;
using P3D.Legacy.Server.Client.P3D.Data.P3DDatas;
using P3D.Legacy.Server.CQERS.Events;

namespace P3D.Legacy.Server.Client.P3D.Events
{
public sealed record PlayerTradeOfferedP3DMonsterEvent(IPlayer Player, Origin Partner, TradeData Data) : IEvent;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;

namespace P3D.Legacy.Common.Extensions
namespace P3D.Legacy.Server.Client.P3D.Extensions
{
public static class DataItemsExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Globalization;
using System.Text;

namespace P3D.Legacy.Common.Extensions
namespace P3D.Legacy.Server.Client.P3D.Extensions
{
public static class MonsterExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using P3D.Legacy.Server.Application.Services;
using P3D.Legacy.Server.Client.P3D.EventHandlers;
using P3D.Legacy.Server.Client.P3D.Packets;
using P3D.Legacy.Server.Client.P3D.Services;
using P3D.Legacy.Server.CQERS.Extensions;

Expand All @@ -19,6 +20,8 @@ public static IServiceCollection AddClientP3D(this IServiceCollection services)
//services.AddTransient<StatisticsHandler>();
//services.AddEvents(sp => sp.GetRequiredService<StatisticsHandler>());

services.AddSingleton<IP3DPacketFactory, P3DPacketServerFactory>();

services.AddHostedService<P3DPlayerMovementCompensationService>();

services.AddScoped<P3DConnectionContextHandler>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Numerics;
using System.Text;

namespace P3D.Legacy.Common.Extensions
namespace P3D.Legacy.Server.Client.P3D.Extensions
{
public static class Vector3Extensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using P3D.Legacy.Common.Extensions;
using P3D.Legacy.Common.Monsters;
using P3D.Legacy.Common.Monsters;
using P3D.Legacy.Server.Client.P3D.Extensions;

using System;
using System.Collections.Generic;
using System.Globalization;

namespace P3D.Legacy.Server.Infrastructure.Models.Monsters
namespace P3D.Legacy.Server.Client.P3D.Models.Monsters
{
public sealed class MonsterEntity : IMonsterInstance
public sealed class P3DMonsterEntity : IMonsterInstance
{
public IMonsterStaticData StaticData { get; }
public CatchInfo CatchInfo { get; }
Expand All @@ -27,7 +27,7 @@ public sealed class MonsterEntity : IMonsterInstance
public IItemInstance? HeldItem { get; }
public IDictionary<string, string> Metadata { get; } = new Dictionary<string, string>(StringComparer.Ordinal);

public MonsterEntity(in ReadOnlySpan<char> monsterData, IMonsterStaticData monsterStaticData, IReadOnlyList<IAttackInstance> attacks, IItemInstance? heldItem)
public P3DMonsterEntity(in ReadOnlySpan<char> monsterData, IMonsterStaticData monsterStaticData, IReadOnlyList<IAttackInstance> attacks, IItemInstance? heldItem)
{
StaticData = monsterStaticData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
using OpenTelemetry.Trace;

using P3D.Legacy.Common;
using P3D.Legacy.Common.Packets;
using P3D.Legacy.Common.Packets.Chat;
using P3D.Legacy.Common.Packets.Common;
using P3D.Legacy.Common.Packets.Server;
using P3D.Legacy.Server.Abstractions;
using P3D.Legacy.Server.Client.P3D.Packets;
using P3D.Legacy.Server.Client.P3D.Packets.Chat;
using P3D.Legacy.Server.Client.P3D.Packets.Common;
using P3D.Legacy.Server.Client.P3D.Packets.Server;

using System;
using System.Diagnostics;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using P3D.Legacy.Common;
using P3D.Legacy.Common.Extensions;
using P3D.Legacy.Common.Packets.Battle;
using P3D.Legacy.Common.Packets.Chat;
using P3D.Legacy.Common.Packets.Server;
using P3D.Legacy.Common.Packets.Trade;
using P3D.Legacy.Common.PlayerEvents;
using P3D.Legacy.Server.Abstractions;
using P3D.Legacy.Server.Abstractions.Events;
Expand All @@ -12,6 +7,11 @@
using P3D.Legacy.Server.Application.Queries.Options;
using P3D.Legacy.Server.Application.Queries.Player;
using P3D.Legacy.Server.Client.P3D.Events;
using P3D.Legacy.Server.Client.P3D.Extensions;
using P3D.Legacy.Server.Client.P3D.Packets.Battle;
using P3D.Legacy.Server.Client.P3D.Packets.Chat;
using P3D.Legacy.Server.Client.P3D.Packets.Server;
using P3D.Legacy.Server.Client.P3D.Packets.Trade;
using P3D.Legacy.Server.CQERS.Events;

using System;
Expand Down Expand Up @@ -41,7 +41,7 @@ internal partial class P3DConnectionContextHandler :
IEventHandler<PlayerTradeInitiatedEvent>,
IEventHandler<PlayerTradeAcceptedEvent>,
IEventHandler<PlayerTradeAbortedEvent>,
IEventHandler<PlayerTradeOfferedPokemonEvent>,
IEventHandler<PlayerTradeOfferedP3DMonsterEvent>,
IEventHandler<PlayerTradeConfirmedEvent>,
IEventHandler<ServerStoppingEvent>
{
Expand Down Expand Up @@ -274,19 +274,21 @@ public async Task HandleAsync(IReceiveContext<PlayerTradeAbortedEvent> context,
await SendPacketAsync(new TradeQuitPacket { Origin = player.Origin, DestinationPlayerOrigin = partner }, ct);
}

public async Task HandleAsync(IReceiveContext<PlayerTradeOfferedPokemonEvent> context, CancellationToken ct)
public async Task HandleAsync(IReceiveContext<PlayerTradeOfferedP3DMonsterEvent> context, CancellationToken ct)
{
var (player, target, data) = context.Message;

if (Origin != target) return;

var cancel = false;
/*
var serverOptions = await _queryDispatcher.DispatchAsync(new GetServerOptionsQuery(), ct);
if (serverOptions.ValidationEnabled)
{
var monster = await _queryDispatcher.DispatchAsync(new GetMonsterByDataQuery(data.MonsterData), ct);
cancel = !monster.IsValidP3D();
}
*/

if (cancel)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
using Microsoft.Extensions.Logging;

using P3D.Legacy.Common;
using P3D.Legacy.Common.Extensions;
using P3D.Legacy.Common.Packets;
using P3D.Legacy.Common.Packets.Battle;
using P3D.Legacy.Common.Packets.Chat;
using P3D.Legacy.Common.Packets.Client;
using P3D.Legacy.Common.Packets.Common;
using P3D.Legacy.Common.Packets.Server;
using P3D.Legacy.Common.Packets.Trade;
using P3D.Legacy.Common.PlayerEvents;
using P3D.Legacy.Server.Abstractions;
using P3D.Legacy.Server.Abstractions.Events;
Expand All @@ -18,6 +10,14 @@
using P3D.Legacy.Server.Application.Queries.Player;
using P3D.Legacy.Server.Application.Queries.World;
using P3D.Legacy.Server.Client.P3D.Events;
using P3D.Legacy.Server.Client.P3D.Extensions;
using P3D.Legacy.Server.Client.P3D.Packets;
using P3D.Legacy.Server.Client.P3D.Packets.Battle;
using P3D.Legacy.Server.Client.P3D.Packets.Chat;
using P3D.Legacy.Server.Client.P3D.Packets.Client;
using P3D.Legacy.Server.Client.P3D.Packets.Common;
using P3D.Legacy.Server.Client.P3D.Packets.Server;
using P3D.Legacy.Server.Client.P3D.Packets.Trade;

using System;
using System.Collections.Immutable;
Expand Down Expand Up @@ -422,7 +422,7 @@ private async Task HandleTradeOfferAsync(TradeOfferFromClientPacket packet, Canc
if (State != PlayerState.Initialized)
return;

await _eventDispatcher.DispatchAsync(new PlayerTradeOfferedPokemonEvent(this, packet.DestinationPlayerOrigin, packet.TradeData), ct);
await _eventDispatcher.DispatchAsync(new PlayerTradeOfferedP3DMonsterEvent(this, packet.DestinationPlayerOrigin, packet.TradeData), ct);
}
private async Task HandleTradeStartAsync(TradeStartPacket packet, CancellationToken ct)
{
Expand Down Expand Up @@ -459,6 +459,7 @@ private async Task HandleBattleOfferAsync(BattleOfferFromClientPacket packet, Ca
return;

var cancel = false;
/*
var serverOptions = await _queryDispatcher.DispatchAsync(new GetServerOptionsQuery(), ct);
if (serverOptions.ValidationEnabled)
{
Expand All @@ -475,6 +476,7 @@ await foreach (var monster in query)
}
}
}
*/

if (cancel)
{
Expand Down
Loading

0 comments on commit 4ce7197

Please sign in to comment.