Skip to content
Open
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
42 changes: 42 additions & 0 deletions src/Fibula.Communications.Packets/Outgoing/PlayerModesPacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// -----------------------------------------------------------------
// <copyright file="PlayerModesPacket.cs" company="2Dudes">
// Copyright (c) | Jose L. Nunez de Caceres et al.
// https://linkedin.com/in/nunezdecaceres
//
// All Rights Reserved.
//
// Licensed under the MIT License. See LICENSE in the project root for license information.
// </copyright>
// -----------------------------------------------------------------

namespace Fibula.Communications.Packets.Outgoing
{
using Fibula.Common.Contracts.Enumerations;
using Fibula.Communications.Contracts.Abstractions;
using Fibula.Communications.Contracts.Enumerations;

/// <summary>
/// Class that represents a player's modes packet.
/// </summary>
public class PlayerModesPacket : IOutboundPacket
{
/// <summary>
/// Initializes a new instance of the <see cref="PlayerModesPacket"/> class.
/// </summary>
/// <param name="chaseMode">The chase mode.</param>
public PlayerModesPacket(ChaseMode chaseMode)
{
this.ChaseMode = chaseMode;
}

/// <summary>
/// Gets the type of this packet.
/// </summary>
public OutgoingPacketType PacketType => OutgoingPacketType.PlayerModes;

/// <summary>
/// Gets the chase mode to set.
/// </summary>
public ChaseMode ChaseMode { get; }
}
}
2 changes: 1 addition & 1 deletion src/Fibula.Mechanics/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ public void SetCombatantModes(ICombatant combatant, FightMode fightMode, ChaseMo
return;
}

var changeModesOp = new ChangeModesOperation(combatant.Id, fightMode, chaseMode, safeModeOn);
var changeModesOp = new ChangeModesOperation(combatant, fightMode, chaseMode, safeModeOn);

this.DispatchOperation(changeModesOp);
}
Expand Down
21 changes: 17 additions & 4 deletions src/Fibula.Mechanics/Operations/ChangeModesOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@

namespace Fibula.Mechanics.Operations
{
using System.Collections.Generic;
using Fibula.Common.Contracts.Enumerations;
using Fibula.Communications.Packets.Outgoing;
using Fibula.Creatures.Contracts.Abstractions;
using Fibula.Map.Contracts.Extensions;
using Fibula.Mechanics.Contracts.Abstractions;
using Fibula.Mechanics.Notifications;

/// <summary>
/// Class that represents a change modes operation.
Expand All @@ -22,18 +27,24 @@ public class ChangeModesOperation : Operation
/// <summary>
/// Initializes a new instance of the <see cref="ChangeModesOperation"/> class.
/// </summary>
/// <param name="requestorId">The id of the creature setting the modes.</param>
/// <param name="creature">The creature which is changing mode.</param>
/// <param name="fightMode">The fight mode to set.</param>
/// <param name="chaseMode">The chase mode to set.</param>
/// <param name="safeModeOn">A value indicating whether the safety mode is on.</param>
public ChangeModesOperation(uint requestorId, FightMode fightMode, ChaseMode chaseMode, bool safeModeOn)
: base(requestorId)
public ChangeModesOperation(ICreature creature, FightMode fightMode, ChaseMode chaseMode, bool safeModeOn)
: base(creature.Id)
{
this.Creature = creature;
this.FightMode = fightMode;
this.ChaseMode = chaseMode;
this.IsSafeModeOn = safeModeOn;
}

/// <summary>
/// Gets a reference to the creature turning.
/// </summary>
public ICreature Creature { get; }

/// <summary>
/// Gets the fight mode to set.
/// </summary>
Expand All @@ -55,7 +66,7 @@ public ChangeModesOperation(uint requestorId, FightMode fightMode, ChaseMode cha
/// <param name="context">A reference to the operation context.</param>
protected override void Execute(IOperationContext context)
{
var onCreature = this.GetRequestor(context.CreatureFinder);
ICreature onCreature = this.GetRequestor(context.CreatureFinder);

if (onCreature == null || !(onCreature is ICombatant combatantCreature))
{
Expand All @@ -77,6 +88,8 @@ protected override void Execute(IOperationContext context)
}

/* combatantCreature.SafeMode = this.IsSafeModeOn; */

this.SendNotification(context, new GenericNotification(() => context.Map.PlayersThatCanSee(this.Creature.Location), new PlayerModesPacket(this.ChaseMode)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public static void AddProtocol772GameServerComponents(this IServiceCollection se
{ OutgoingPacketType.CancelAttack, typeof(PlayerCancelAttackPacketWriter) },
{ OutgoingPacketType.CancelWalk, typeof(PlayerCancelWalkPacketWriter) },
{ OutgoingPacketType.WorldLight, typeof(WorldLightPacketWriter) },
{ OutgoingPacketType.PlayerModes, typeof(PlayerModesPacketWriter) },
};

foreach (var (packetType, type) in packetWritersToAdd)
Expand Down
47 changes: 47 additions & 0 deletions src/Fibula.Protocol.V772/PacketWriters/PlayerModesPacketWriter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// -----------------------------------------------------------------
// <copyright file="PlayerModesPacketWriter.cs" company="2Dudes">
// Copyright (c) | Jose L. Nunez de Caceres et al.
// https://linkedin.com/in/nunezdecaceres
//
// All Rights Reserved.
//
// Licensed under the MIT License. See LICENSE in the project root for license information.
// </copyright>
// -----------------------------------------------------------------

namespace Fibula.Protocol.V772.PacketWriters
{
using Fibula.Communications;
using Fibula.Communications.Contracts.Abstractions;
using Fibula.Communications.Packets.Outgoing;
using Fibula.Protocol.V772.Extensions;
using Serilog;

/// <summary>
/// Class that represents a player mode packet writer for the game server.
/// </summary>
public class PlayerModesPacketWriter : BasePacketWriter
{
/// <summary>
/// Initializes a new instance of the <see cref="PlayerModesPacketWriter"/> class.
/// </summary>
/// <param name="logger">A reference to the logger in use.</param>
public PlayerModesPacketWriter(ILogger logger)
: base(logger)
{
}

/// <inheritdoc/>
public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message)
{
if (!(packet is PlayerModesPacket playerModePacket))
{
this.Logger.Warning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}");

return;
}

message.AddByte(playerModePacket.PacketType.ToByte());
}
}
}