public static CreateItemResult TryDropToGround( IReadOnlyDropItemsList dropItemsList, Vector2Ushort tilePosition, double probabilityMultiplier, DropItemContext context, [CanBeNull] out IItemsContainer groundContainer) { // obtain the ground container to drop the items into var tile = Api.Server.World.GetTile(tilePosition); groundContainer = ObjectGroundItemsContainer .ServerTryGetOrCreateGroundContainerAtTileOrNeighbors(tile); if (groundContainer == null) { // cannot drop because there are no free space available on the ground return(new CreateItemResult() { IsEverythingCreated = false }); } var result = dropItemsList.TryDropToContainer(groundContainer, context, probabilityMultiplier); if (result.TotalCreatedCount == 0 && groundContainer.OccupiedSlotsCount == 0) { // nothing is spawned, the ground container should be destroyed Api.Server.World.DestroyObject(groundContainer.OwnerAsStaticObject); groundContainer = null; } return(result); }
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 ReadOnlyMineralDropItemsConfig(MineralDropItemsConfig config) { this.Stage1 = config.Stage1; this.Stage2 = config.Stage2; this.Stage3 = config.Stage3; this.Stage4 = config.Stage4; }
protected override void PrepareProtoStaticWorldObject() { base.PrepareProtoStaticWorldObject(); var droplist = new DropItemsList(); this.PrepareLootDroplist(droplist); this.LootDroplist = droplist.AsReadOnly(); }
public Entry( IReadOnlyDropItemsList entryNestedList, DropItemConditionDelegate condition, DropItemRollFunctionDelegate rollFunction) : this(condition, rollFunction) { this.EntryNestedList = entryNestedList; }
public Entry( IReadOnlyDropItemsList entryNestedList, DropItemConditionDelegate condition, double probability) : this(condition, probability) { this.EntryNestedList = entryNestedList; }
protected sealed override void PrepareProtoVegetation() { var gatherDroplist = new DropItemsList(); this.PrepareGatheringDroplist(gatherDroplist); this.GatherDroplist = gatherDroplist.AsReadOnly(); this.PrepareProtoGatherableVegetation(); }
protected override void PrepareProtoItemConsumable() { base.PrepareProtoItemConsumable(); this.droplist = new DropItemsList() // penny coins 20-50 .Add <ItemCoinPenny>(count: 20, countRandom: 30) // shiny coins 1-5 with 20% chance .Add <ItemCoinShiny>(count: 1, countRandom: 4, probability: 0.2); }
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); }
public static CreateItemResult TryDropToCharacterOrGround( IReadOnlyDropItemsList dropItemsList, ICharacter toCharacter, Vector2Ushort tilePosition, bool sendNotificationWhenDropToGround, double probabilityMultiplier, DropItemContext context, out IItemsContainer groundContainer) { CreateItemResult result; if (toCharacter != null) { result = TryDropToCharacter( dropItemsList, toCharacter, sendNoFreeSpaceNotification: false, probabilityMultiplier, context); if (result.IsEverythingCreated) { groundContainer = null; return(result); } // cannot add to character - rollback and drop on ground instead result.Rollback(); } result = TryDropToGround(dropItemsList, tilePosition, probabilityMultiplier, context, out groundContainer); 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, result.ItemAmounts.FirstOrDefault().Key?.ProtoItem); } return(result); }
public bool ContainsDroplist(IReadOnlyDropItemsList other) { if (this == other) { return(true); } foreach (var entry in this.entries) { var includedList = entry.Value.EntryNestedList; if (includedList != null && includedList.ContainsDroplist(other)) { return(true); } } return(false); }