public static CreateItemResult TryDropToCharacter( IReadOnlyDropItemsList dropItemsList, ICharacter character, bool sendNoFreeSpaceNotification, double probabilityMultiplier, DropItemContext context) { if (character == null) { return(new CreateItemResult() { IsEverythingCreated = false }); } var itemsService = Api.Server.Items; var result = dropItemsList.Execute( (protoItem, count) => itemsService.CreateItem(character, protoItem, count), context, probabilityMultiplier); if (sendNoFreeSpaceNotification && !result.IsEverythingCreated) { NotificationSystem.ServerSendNotificationNoSpaceInInventory(character); } return(result); }
public static CreateItemResult TryDropToContainer( IReadOnlyDropItemsList dropItemsList, IItemsContainer toContainer, double probabilityMultiplier, DropItemContext context) { var result = dropItemsList.Execute( (protoItem, count) => Items.CreateItem(protoItem, toContainer, count), context, probabilityMultiplier); return(result); }
public static CreateItemResult TryDropToCharacterOrGround( IReadOnlyDropItemsList dropItemsList, ICharacter toCharacter, Vector2Ushort tilePosition, bool sendNotificationWhenDropToGround, double probabilityMultiplier, DropItemContext context, out IItemsContainer groundContainer) { var containersProvider = new CharacterAndGroundContainersProvider(toCharacter, tilePosition); var result = dropItemsList.Execute( (protoItem, count) => Items.CreateItem(protoItem, containersProvider, count), context, probabilityMultiplier); groundContainer = containersProvider.GroundContainer; if (groundContainer is null) { return(result); } if (groundContainer.OccupiedSlotsCount == 0) { // nothing is spawned, the ground container should be destroyed World.DestroyObject(groundContainer.OwnerAsStaticObject); groundContainer = null; } else { if (sendNotificationWhenDropToGround && result.TotalCreatedCount > 0) { // notify player that there were not enough space in inventory so the items were dropped to the ground NotificationSystem.ServerSendNotificationNoSpaceInInventoryItemsDroppedToGround( toCharacter, protoItemForIcon: result.ItemAmounts .Keys .FirstOrDefault( k => k.Container == containersProvider.GroundContainer)? .ProtoItem); } WorldObjectClaimSystem.ServerTryClaim(groundContainer.OwnerAsStaticObject, toCharacter, WorldObjectClaimDuration.GroundItems); } return(result); }