Skip to content

Commit

Permalink
fix: ♻️ Applied necessary changes from the last review
Browse files Browse the repository at this point in the history
  • Loading branch information
blinkuz committed Oct 27, 2024
1 parent 3d4d271 commit 4156cbd
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Intersect.Server.Core/Entities/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3059,7 +3059,7 @@ protected virtual void DropItems(Entity killer, bool sendUpdate = true)
// Spawn the actual item!
if (MapController.TryGetInstanceFromMap(MapId, MapInstanceId, out var instance))
{
var itemSource = this.GetItemSource();
var itemSource = this.AsItemSource();
instance.SpawnItem(itemSource, X, Y, drop, drop.Quantity, lootOwner, sendUpdate);
}

Expand All @@ -3068,7 +3068,7 @@ protected virtual void DropItems(Entity killer, bool sendUpdate = true)
}
}

protected abstract EntityItemSource GetItemSource();
protected abstract EntityItemSource? AsItemSource();

public bool IsDead()
{
Expand Down
2 changes: 1 addition & 1 deletion Intersect.Server.Core/Entities/Events/EventPageInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ public bool ShouldDespawn(MapController map)
return false;
}

protected override EntityItemSource GetItemSource()
protected override EntityItemSource? AsItemSource()
{
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion Intersect.Server.Core/Entities/Npc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,7 @@ public override EntityPacket EntityPacket(EntityPacket packet = null, Player for
return pkt;
}

protected override EntityItemSource GetItemSource()
protected override EntityItemSource? AsItemSource()
{
return new EntityItemSource
{
Expand Down
8 changes: 4 additions & 4 deletions Intersect.Server.Core/Entities/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2782,7 +2782,7 @@ public bool TryGiveItem(Item item, ItemHandling handler = ItemHandling.Normal, b
// Do we have any items to spawn to the map?
if (spawnAmount > 0 && MapController.TryGetInstanceFromMap(Map.Id, MapInstanceId, out var instance))
{
instance.SpawnItem(GetItemSource(), overflowTileX > -1 ? overflowTileX : X, overflowTileY > -1 ? overflowTileY : Y, item, spawnAmount, Id);
instance.SpawnItem(AsItemSource(), overflowTileX > -1 ? overflowTileX : X, overflowTileY > -1 ? overflowTileY : Y, item, spawnAmount, Id);
return spawnAmount != item.Quantity;
}

Expand Down Expand Up @@ -2826,7 +2826,7 @@ public bool TryGiveItem(Item item, ItemHandling handler = ItemHandling.Normal, b
/// Creates an item source for the player entity.
/// </summary>
/// <returns>A new <see cref="EntityItemSource"/> object.</returns>
protected override EntityItemSource GetItemSource()
protected override EntityItemSource? AsItemSource()
{
return new EntityItemSource
{
Expand Down Expand Up @@ -3149,7 +3149,7 @@ public bool TryDropItemFrom(int slotIndex, int amount)
return false;
}

mapInstance.SpawnItem(GetItemSource(),X, Y, itemInSlot, itemDescriptor.IsStackable ? amount : 1, Id);
mapInstance.SpawnItem(AsItemSource(),X, Y, itemInSlot, itemDescriptor.IsStackable ? amount : 1, Id);

itemInSlot.Quantity = Math.Max(0, itemInSlot.Quantity - amount);

Expand Down Expand Up @@ -4987,7 +4987,7 @@ public void ReturnTradeItems()
return;
}

var itemSource = GetItemSource();
var itemSource = AsItemSource();

foreach (var offer in Trading.Offer)
{
Expand Down
2 changes: 1 addition & 1 deletion Intersect.Server.Core/Entities/Projectile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ public override EntityType GetEntityType()
return EntityType.Projectile;
}

protected override EntityItemSource GetItemSource()
protected override EntityItemSource? AsItemSource()
{
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions Intersect.Server.Core/Entities/Resource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void SpawnResourceItems(Entity killer)
selectedTile = tiles[Randomization.Next(0, tiles.Count)];
}

var itemSource = GetItemSource();
var itemSource = AsItemSource();

// Drop items
foreach (var item in Items)
Expand All @@ -178,7 +178,7 @@ public void SpawnResourceItems(Entity killer)
Items.Clear();
}

protected override EntityItemSource GetItemSource()
protected override EntityItemSource? AsItemSource()
{
return new EntityItemSource
{
Expand Down
4 changes: 2 additions & 2 deletions Intersect.Server.Core/Maps/MapInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -933,9 +933,9 @@ private void SpawnAttributeItem(int x, int y)

var mapItemSource = new MapItemSource
{
MapInstanceId = MapInstanceId,
Id = MapInstanceId,
MapInstanceReference = new WeakReference<IMapInstance>(this),
MapControllerId = mMapController.Id,
DescriptorId = mMapController.Id,
};

AddItem(mapItemSource, mapItem);
Expand Down
5 changes: 2 additions & 3 deletions Intersect.Server.Framework/Items/MapItemSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

namespace Intersect.Server.Framework.Items;

public partial class MapItemSource: IItemSource
public partial class MapItemSource : IItemSource
{
public Guid Id { get; init; }
public ItemSourceType SourceType => ItemSourceType.Map;
public WeakReference<IMapInstance> MapInstanceReference { get; init; }
public Guid MapInstanceId { get; init; }
public Guid MapControllerId { get; init; }
public Guid DescriptorId { get; init; }
}

0 comments on commit 4156cbd

Please sign in to comment.