コード例 #1
0
            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);
            }
コード例 #2
0
 public LootContainerBuilder AddLoot(int definition, int quantity)
 {
     return(AddLoot(LootItemBuilder.Create(definition).SetQuantity(quantity)));
 }
コード例 #3
0
        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 = DbQuery.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);
                                Character.LogTransaction(b);

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

                    Repository.Save(container);

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

                    scope.Complete();
                }
            }
        }