public LootContainer Build(IZone zone, Position position)
            {
                var definitionName = _containerTypeToName.GetOrDefault(_containerType);
                var container      = (LootContainer)CreateUnitWithRandomEID(definitionName);

                if (container == null)
                {
                    return(null);
                }

                container.PinCode = _pinCode;

                if (_ownerPlayer != null)
                {
                    container.Owner = _ownerPlayer.Owner;
                }

                container.Initialize();

                container.AddLoots(_lootItems.Where(l => !l.ItemInfo.IsRepackaged));

                var stackedLoots = _lootItems.Where(l => l.ItemInfo.IsRepackaged)
                                   .GroupBy(l => l.ItemInfo.Definition)
                                   .Select(grp => LootItemBuilder.Create(grp.Key).AsRepackaged().SetQuantity(grp.Sum(l => l.Quantity)).Build());

                container.AddLoots(stackedLoots);
                zone.UnitService.AddUserUnit(container, position);
                return(container);
            }
Ejemplo n.º 2
0
        public IEnumerable <LootItem> Generate()
        {
            foreach (var info in _lootInfos)
            {
                if (FastRandom.NextDouble() >= info.probability)
                {
                    continue;
                }

                var lootItem = LootItemBuilder.Create(info.item).SetDamaged(info.damaged).Build();
                yield return(lootItem);
            }
        }
        public void PutLoots(Player player, int pinCode, IList <KeyValuePair <long, int> > items)
        {
            HasAccess(player, pinCode);

            Zone.CreateBeam(BeamType.loot_bolt, b => b.WithSource(player)
                            .WithTarget(this)
                            .WithState(BeamState.Hit).WithDuration(1000));

            lock (syncObject)
            {
                using (var scope = Db.CreateTransaction())
                {
                    var container = player.GetContainer();
                    Debug.Assert(container != null, "container != null");
                    container.EnlistTransaction();
                    var progressPacketBuilder = new LootContainerProgressInfoPacketBuilder(container, this, items.Count);

                    var b = TransactionLogEvent.Builder().SetTransactionType(TransactionType.PutLoot).SetCharacter(player.Character).SetContainer(Eid);

                    foreach (var kvp in items)
                    {
                        try
                        {
                            var itemEid  = kvp.Key;
                            var quantity = kvp.Value;

                            var tmpItem = container.GetItemOrThrow(itemEid);

                            //robotot lehet
                            if (tmpItem.ED.AttributeFlags.NonStackable)
                            {
                                continue;
                            }

                            if (tmpItem is VolumeWrapperContainer)
                            {
                                continue;
                            }

                            lock (container)
                            {
                                var resultItem = container.RemoveItem(tmpItem, quantity);
                                if (resultItem == null)
                                {
                                    continue;
                                }

                                Repository.Delete(resultItem);
                                b.SetItem(resultItem);
                                player.Character.LogTransaction(b);

                                //sikerult minden mehet bele a kontenerbe
                                AddLoot(LootItemBuilder.Create(resultItem).Build());
                            }
                        }
                        finally
                        {
                            SendPacketToLooters(progressPacketBuilder);
                            progressPacketBuilder.Increase();
                        }
                    }

                    container.Save();

                    Transaction.Current.OnCompleted((c) =>
                    {
                        SendLootListToLooters();
                        container.SendUpdateToOwnerAsync();
                        SendPacketToLooters(progressPacketBuilder);
                    });

                    scope.Complete();
                }
            }
        }
 public LootContainerBuilder AddLoot(int definition, int quantity)
 {
     return(AddLoot(LootItemBuilder.Create(definition).SetQuantity(quantity)));
 }