Skip to content

Commit

Permalink
Merge branch 'develop' into feature/luajit
Browse files Browse the repository at this point in the history
  • Loading branch information
MUN1Z committed Dec 27, 2024
2 parents b09f2c3 + b619b7b commit 5518c8f
Show file tree
Hide file tree
Showing 35 changed files with 229 additions and 190 deletions.
4 changes: 3 additions & 1 deletion data/extensions/Events/Startup/VocationConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ public void Run()
foreach (var itemType in _itemTypeStore.All)
{
var vocationsAttr = itemType.Attributes.GetAttributeArray(ItemAttribute.Vocation);
if (vocationsAttr is not string[] vocations) continue;

if (vocationsAttr is not string[] vocations) continue;

itemType.Attributes.SetAttribute(ItemAttribute.VocationNames, vocations);

var vocationsType = new List<byte>(vocations.Length);
foreach (var vocation in vocations)
Expand Down
4 changes: 2 additions & 2 deletions data/extensions/Items/Doors/LevelDoor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ private void TeleportNorthOrSouth(IPlayer player, Direction directionTo)
player.TeleportTo(Location.X, (ushort)(Location.Y + 1), Location.Z);
}

public override string GetLookText(IInspectionTextBuilder inspectionTextBuilder, IPlayer player,
bool isClose = false)
public override string GetLookText(
bool isClose = false, bool showInternalDetails = false)
{
Metadata.Attributes.TryGetAttribute(ItemAttribute.ActionId, out int actionId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public interface IConnection
string Ip { get; }
long TimeStamp { get; }
byte RandomNumber { get; }
ushort OtcV8Version { get; set; }

event EventHandler<IConnectionEventArgs> OnProcessEvent;
event EventHandler<IConnectionEventArgs> OnCloseEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface INetworkMessage : IReadOnlyNetworkMessage
void AddUInt32(uint value);
void WriteUint32(uint value, int position);
byte[] AddHeader(bool addChecksum = true);
void AddItem(IItem item);
void AddItem(IItem item, bool showItemDescription = false);
void AddLocation(Location location);
void AddLength();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
using NeoServer.Networking.Packets.Outgoing.Item;
using NeoServer.Networking.Packets.Outgoing.Npc;
using NeoServer.Server.Common.Contracts;
using NeoServer.Server.Configurations;

namespace NeoServer.Server.Events.Items;

public class ContentModifiedOnContainerEventHandler
{
private readonly ICoinTypeStore _coinTypeStore;
private readonly ClientConfiguration _clientConfiguration;
private readonly IGameServer game;

public ContentModifiedOnContainerEventHandler(IGameServer game, ICoinTypeStore coinTypeStore)
public ContentModifiedOnContainerEventHandler(IGameServer game, ICoinTypeStore coinTypeStore, ClientConfiguration clientConfiguration)
{
this.game = game;
_coinTypeStore = coinTypeStore;
_clientConfiguration = clientConfiguration;
}

public void Execute(IPlayer player, ContainerOperation operation, byte containerId, byte slotIndex, IItem item)
Expand All @@ -30,10 +33,16 @@ public void Execute(IPlayer player, ContainerOperation operation, byte container
connection.OutgoingPackets.Enqueue(new RemoveItemContainerPacket(containerId, slotIndex, item));
break;
case ContainerOperation.ItemAdded:
connection.OutgoingPackets.Enqueue(new AddItemContainerPacket(containerId, item));
connection.OutgoingPackets.Enqueue(new AddItemContainerPacket(containerId, item)
{
ShowItemDescription = connection.OtcV8Version > 0 && _clientConfiguration.OtcV8.GameItemTooltip
});
break;
case ContainerOperation.ItemUpdated:
connection.OutgoingPackets.Enqueue(new UpdateItemContainerPacket(containerId, slotIndex, item));
connection.OutgoingPackets.Enqueue(new UpdateItemContainerPacket(containerId, slotIndex, item)
{
ShowItemDescription = connection.OtcV8Version > 0 && _clientConfiguration.OtcV8.GameItemTooltip
});
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
using NeoServer.Game.Common.Contracts.Items.Types.Containers;
using NeoServer.Networking.Packets.Outgoing.Player;
using NeoServer.Server.Common.Contracts;
using NeoServer.Server.Configurations;

namespace NeoServer.Server.Events.Player.Containers;

public class PlayerOpenedContainerEventHandler
{
private readonly IGameServer game;
private readonly ClientConfiguration _clientConfiguration;

public PlayerOpenedContainerEventHandler(IGameServer game)
public PlayerOpenedContainerEventHandler(IGameServer game, ClientConfiguration clientConfiguration)
{
this.game = game;
_clientConfiguration = clientConfiguration;
}

public void Execute(IPlayer player, byte containerId, IContainer container)
Expand All @@ -23,7 +26,10 @@ private void SendContainerPacket(IPlayer player, byte containerId, IContainer co
{
if (!game.CreatureManager.GetPlayerConnection(player.CreatureId, out var connection)) return;

connection.OutgoingPackets.Enqueue(new OpenContainerPacket(container, containerId));
connection.OutgoingPackets.Enqueue(new OpenContainerPacket(container, containerId)
{
WithDescription = connection.OtcV8Version > 0 && _clientConfiguration.OtcV8.GameItemTooltip
});
connection.Send();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
using NeoServer.Networking.Packets.Outgoing.Npc;
using NeoServer.Networking.Packets.Outgoing.Player;
using NeoServer.Server.Common.Contracts;
using NeoServer.Server.Configurations;

namespace NeoServer.Server.Events.Player;

public class PlayerChangedInventoryEventHandler
{
private readonly ICoinTypeStore _coinTypeStore;
private readonly ClientConfiguration _clientConfiguration;
private readonly IGameServer game;

public PlayerChangedInventoryEventHandler(IGameServer game, ICoinTypeStore coinTypeStore)
public PlayerChangedInventoryEventHandler(IGameServer game, ICoinTypeStore coinTypeStore, ClientConfiguration clientConfiguration)
{
this.game = game;
_coinTypeStore = coinTypeStore;
_clientConfiguration = clientConfiguration;
}

public void Execute(IInventory inventory, IItem item, Slot slot, byte amount = 1)
Expand All @@ -28,7 +31,10 @@ public void Execute(IInventory inventory, IItem item, Slot slot, byte amount = 1

if (!game.CreatureManager.GetPlayerConnection(player.CreatureId, out var connection)) return;

connection.OutgoingPackets.Enqueue(new PlayerInventoryItemPacket(player.Inventory, slot));
connection.OutgoingPackets.Enqueue(new PlayerInventoryItemPacket(player.Inventory, slot)
{
ShowItemDescription = connection.OtcV8Version > 0 && _clientConfiguration.OtcV8.GameItemTooltip
});

if (player.Shopping)
connection.OutgoingPackets.Enqueue(new SaleItemListPacket(player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void Execute(IPlayer player, IThing thing, bool isClose)

var inspectionTextBuilder = GetInspectionTextBuilder(thing);

var text = thing.GetLookText(inspectionTextBuilder, player, isClose);
var text = thing.GetLookText( isClose, player.CanSeeInspectionDetails);

connection.OutgoingPackets.Enqueue(new TextMessagePacket(text, TextMessageOutgoingType.Description));
connection.Send();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@
using NeoServer.Networking.Packets.Outgoing.Player;
using NeoServer.Server.Common.Contracts;
using NeoServer.Server.Common.Contracts.Network;
using NeoServer.Server.Configurations;

namespace NeoServer.Server.Events.Player;

public class PlayerSelfAppearOnMapEventHandler : IEventHandler
{
private readonly IGameServer game;
private readonly IMap map;
private readonly IGameServer _game;
private readonly ClientConfiguration _clientConfiguration;
private readonly IMap _map;

public PlayerSelfAppearOnMapEventHandler(IMap map, IGameServer game)
public PlayerSelfAppearOnMapEventHandler(IMap map, IGameServer game, ClientConfiguration clientConfiguration)
{
this.map = map;
this.game = game;
_map = map;
_game = game;
_clientConfiguration = clientConfiguration;
}

public void Execute(IWalkableCreature creature)
Expand All @@ -29,21 +32,25 @@ public void Execute(IWalkableCreature creature)

if (creature is not IPlayer player) return;

if (!game.CreatureManager.GetPlayerConnection(creature.CreatureId, out var connection)) return;
if (!_game.CreatureManager.GetPlayerConnection(creature.CreatureId, out var connection)) return;

SendPacketsToPlayer(player, connection);
}

private void SendPacketsToPlayer(IPlayer player, IConnection connection)
{
connection.OutgoingPackets.Enqueue(new SelfAppearPacket(player));
connection.OutgoingPackets.Enqueue(new MapDescriptionPacket(player, map));
connection.OutgoingPackets.Enqueue(new MapDescriptionPacket(player, _map));
connection.OutgoingPackets.Enqueue(new MagicEffectPacket(player.Location, EffectT.BubbleBlue));
connection.OutgoingPackets.Enqueue(new PlayerInventoryPacket(player.Inventory));
connection.OutgoingPackets.Enqueue(new PlayerInventoryPacket(player.Inventory)
{
ShowItemDescription = connection.OtcV8Version > 0 && _clientConfiguration.OtcV8.GameItemTooltip
});

connection.OutgoingPackets.Enqueue(new PlayerStatusPacket(player));
connection.OutgoingPackets.Enqueue(new PlayerSkillsPacket(player));

connection.OutgoingPackets.Enqueue(new WorldLightPacket(game.LightLevel, game.LightColor));
connection.OutgoingPackets.Enqueue(new WorldLightPacket(_game.LightLevel, _game.LightColor));

connection.OutgoingPackets.Enqueue(new CreatureLightPacket(player));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
using NeoServer.Networking.Packets.Outgoing.Trade;
using NeoServer.Server.Common.Contracts;
using NeoServer.Server.Common.Contracts.Network;
using NeoServer.Server.Configurations;

namespace NeoServer.Server.Events.Player.Trade;

public class TradeRequestedEventHandler : IEventHandler
{
private readonly IGameServer _gameServer;
private readonly ClientConfiguration _clientConfiguration;

public TradeRequestedEventHandler(IGameServer gameServer)
public TradeRequestedEventHandler(IGameServer gameServer, ClientConfiguration clientConfiguration)
{
_gameServer = gameServer;
_clientConfiguration = clientConfiguration;
}

public void Execute(TradeRequest tradeRequest)
Expand All @@ -27,7 +30,10 @@ public void Execute(TradeRequest tradeRequest)
out var playerRequestedConnection);

playerRequestingConnection.OutgoingPackets.Enqueue(new TradeRequestPacket(tradeRequest.PlayerRequesting.Name,
tradeRequest.Items));
tradeRequest.Items)
{
ShowItemDescription = playerRequestingConnection.OtcV8Version > 0 && _clientConfiguration.OtcV8.GameItemTooltip
});

SendTradeMessage(tradeRequest, playerRequestedConnection);

Expand All @@ -46,7 +52,7 @@ private static void SendTradeMessage(TradeRequest tradeRequest, IConnection play
TextMessageOutgoingType.Small));
}

private static void SendAcknowledgeTradeToBothPlayers(TradeRequest tradeRequest,
private void SendAcknowledgeTradeToBothPlayers(TradeRequest tradeRequest,
IConnection playerRequestingConnection,
IConnection playerRequestedConnection)
{
Expand All @@ -55,9 +61,15 @@ private static void SendAcknowledgeTradeToBothPlayers(TradeRequest tradeRequest,
var items = SafeTradeSystem.GetTradedItems(tradeRequest.PlayerRequested);

playerRequestingConnection.OutgoingPackets.Enqueue(new TradeRequestPacket(tradeRequest.PlayerRequested.Name,
items, true));
items, true)
{
ShowItemDescription = playerRequestingConnection.OtcV8Version > 0 && _clientConfiguration.OtcV8.GameItemTooltip
});

playerRequestedConnection.OutgoingPackets.Enqueue(new TradeRequestPacket(tradeRequest.PlayerRequesting.Name,
tradeRequest.Items, true));
tradeRequest.Items, true)
{
ShowItemDescription = playerRequestedConnection.OtcV8Version > 0 && _clientConfiguration.OtcV8.GameItemTooltip
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,13 @@ public record GrayLogConfiguration(
string HostnameOverride,
string Facility)
{
}

public record ClientConfiguration(ClientConfiguration.OtcV8Configuration OtcV8)

Check notice on line 45 in src/ApplicationServer/NeoServer.Server/Configurations/ServerConfiguration.cs

View check run for this annotation

codefactor.io / CodeFactor

src/ApplicationServer/NeoServer.Server/Configurations/ServerConfiguration.cs#L45

File may only contain a single type. (SA1402)
{
public record OtcV8Configuration(
bool GameExtendedOpcode,
bool GameEnvironmentEffect,
bool GameExtendedClientPing,
bool GameItemTooltip);
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
using System;
using NeoServer.Game.Common.Contracts.Creatures;
using System;
using NeoServer.Game.Common.Contracts.Items;

namespace NeoServer.Game.Common.Contracts.Inspection;

public interface IInspectionTextBuilder
{
string Build(IThing thing, IPlayer player, bool isClose = false);
{
bool IsApplicable(IThing thing);

public static string GetArticle(string name)
{
if (string.IsNullOrWhiteSpace(name)) return "a";

Span<char> vowels = stackalloc char[5] { 'a', 'e', 'i', 'o', 'u' };
Span<char> vowels = ['a', 'e', 'i', 'o', 'u'];
return vowels.Contains(name.ToLower()[0]) ? "an" : "a";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public interface IThing : IUsable

Location.Structs.Location Location { get; }

string GetLookText(IInspectionTextBuilder inspectionTextBuilder, IPlayer player, bool isClose = false);

string GetLookText(bool isClose = false, bool showInternalDetails = false);
public bool IsCloseTo(IThing thing)
{
if (Location.Type is not LocationType.Ground &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,6 @@ public enum ItemAttribute : byte
ManaUse,
CooldownTime,
UseOn,
DecayElapsed
DecayElapsed,
VocationNames
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected set
public uint MaxHealthPoints { get; protected set; }
public string Name => CreatureType.Name;

public string GetLookText(IInspectionTextBuilder inspectionTextBuilder, IPlayer player, bool isClose = false)
public string GetLookText(bool isClose = false, bool showInternalDetails = false)
{
return $"You see {(isClose ? CloseInspectionText : InspectionText)}";
}
Expand Down
13 changes: 7 additions & 6 deletions src/GameWorldSimulator/NeoServer.Game.Items/Bases/BaseItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using NeoServer.Game.Common.Contracts.Items.Types.Containers;
using NeoServer.Game.Common.Location.Structs;
using NeoServer.Game.Items.Factories.AttributeFactory;
using NeoServer.Game.Items.Inspection;

namespace NeoServer.Game.Items.Bases;

Expand Down Expand Up @@ -63,14 +64,14 @@ public void SetNewLocation(Location location)
Location = location;
}

public virtual string GetLookText(IInspectionTextBuilder inspectionTextBuilder, IPlayer player,
bool isClose = false)
public virtual string GetLookText(
bool isClose = false, bool showInternalDetails = false)
{
return inspectionTextBuilder is null
? $"You see {Metadata.Article} {Metadata.Name}."
: inspectionTextBuilder.Build(this, player, isClose);
return InspectionTextBuilder.IsApplicable(this)
? InspectionTextBuilder.Build(this, isClose, showInternalDetails)
: $"You see {Metadata.Article} {Metadata.Name}.";
}

public string FullName => Metadata.FullName;
public byte Amount { get; set; } = 1;

Expand Down
Loading

0 comments on commit 5518c8f

Please sign in to comment.