Skip to content

Unify item modification #340

Open
Open
@seionmoya

Description

@seionmoya

In

  • RagFairBuyOfferItemEventController
  • TradingConfirmEventController

The following gets repeated:

if (itemInstance.Updatable.StackObjectsCount <= 0)
{
    profile.Pmc.Inventory.RemoveItem(itemInstance);
    context.Response.ProfileChanges[profile.Pmc._id].Items.Delete.Add(itemInstance);
}
else
{
    context.Response.ProfileChanges[profile.Pmc._id].Items.Change.Add(itemInstance);
}
var stacks = ItemFactoryService.Instance.CreateItemsFromTradeRequest(itemsToBuy, request.Count);

foreach (var stack in stacks)
{
    (int itemWidth, int itemHeight) = _itemService.CalculateItemSize(stack);
    var targetLocation = profile.Pmc.Inventory.GetNextFreeSlot(_itemService, itemWidth, itemHeight, out string gridName);

    if (targetLocation == null)
    {
        throw new Exception("No room for item");
    }

    var rootItem = stack[0];
    rootItem.Location = targetLocation;
    rootItem.SlotId = gridName;
    rootItem.ParentId = profile.Pmc.Inventory.Stash;

    profile.Pmc.Inventory.AddItems(_itemService, ItemFactoryService.Instance,
        stack);

    context.Response.ProfileChanges[profile.Pmc._id].Items.New.AddRange(stack);
}

Look into if unifying the code actually makes sense to do so, and update all places where it makes sense to do this

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendRelated to Fuyu.BackendenhancementNew feature or request

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions