public IEnumerable <LootItem> GetLootItems()
        {
            var lista = new List <LootItem>();

            foreach (var item in GetItems())
            {
                var resultQuantity   = (int)(Math.Round(item.Quantity * FastRandom.NextDouble()));
                var resutlDefinition = item.Definition;

                if (resultQuantity <= 0)
                {
                    continue;
                }

                var lootItem = LootItemBuilder.Create(resutlDefinition).SetQuantity(resultQuantity).SetRepackaged(item.ED.AttributeFlags.Repackable).Build();
                lista.Add(lootItem);
            }

            return(lista);
        }
Exemple #2
0
        //ennek mindenkepp vegig kell futnia
        private void HandlePlayerDead(IZone zone, Unit killer)
        {
            using (var scope = Db.CreateTransaction())
            {
                EnlistTransaction();
                try
                {
                    killer = zone.ToPlayerOrGetOwnerPlayer(killer) ?? killer;

                    SaveCombatLog(zone, killer);

                    var character = Character;

                    var dockingBase = character.GetHomeBaseOrCurrentBase();
                    dockingBase.DockIn(character, NormalUndockDelay, ZoneExitType.Died);

                    PlayerDeathLogger.Log.Write(zone, this, killer);

                    //pay out insurance if needed
                    var wasInsured = InsuranceHelper.CheckInsuranceOnDeath(Eid, Definition);

                    if (!Session.AccessLevel.IsAdminOrGm())
                    {
                        var robotInventory = GetContainer();
                        Debug.Assert(robotInventory != null);

                        var lootItems = new List <LootItem>();

                        // minden fittelt modul
                        foreach (var module in Modules.Where(m => LootHelper.Roll()))
                        {
                            lootItems.Add(LootItemBuilder.Create(module).AsDamaged().Build());

                            var activeModule = module as ActiveModule;
                            var ammo         = activeModule?.GetAmmo();
                            if (ammo != null)
                            {
                                if (LootHelper.Roll())
                                {
                                    lootItems.Add(LootItemBuilder.Create(ammo).Build());
                                }
                            }

                            // szedjuk le a robotrol
                            module.Parent = robotInventory.Eid; //in case the container is full

                            //toroljuk is le, nem kell ez sehova mar
                            Repository.Delete(module);
                        }

                        foreach (var item in robotInventory.GetItems(true).Where(i => i is VolumeWrapperContainer))
                        {
                            //Transport assignments
                            var wrapper = item as VolumeWrapperContainer;
                            if (wrapper == null)
                            {
                                continue;
                            }

                            lootItems.AddRange(wrapper.GetLootItems());
                            wrapper.SetAllowDelete();
                            Repository.Delete(wrapper);
                        }

                        // elkerunk minden itemet a kontenerbol es valogatunk belole 50% szerint
                        foreach (var item in robotInventory.GetItems().Where(i => LootHelper.Roll() && !i.ED.AttributeFlags.NonStackable))
                        {
                            var qtyMod = FastRandom.NextDouble();
                            item.Quantity = (int)(item.Quantity * qtyMod);

                            if (item.Quantity > 0)
                            {
                                lootItems.Add(LootItemBuilder.Create(item.Definition).SetQuantity(item.Quantity).SetRepackaged(item.ED.AttributeFlags.Repackable).Build());
                            }
                            else
                            {
                                robotInventory.RemoveItemOrThrow(item);

                                //toroljuk is le, nem kell ez mar
                                Repository.Delete(item);
                            }
                        }

                        if (lootItems.Count > 0)
                        {
                            var lootContainer = LootContainer.Create().AddLoot(lootItems).BuildAndAddToZone(zone, CurrentPosition);

                            if (lootContainer != null)
                            {
                                var b = TransactionLogEvent.Builder().SetTransactionType(TransactionType.PutLoot).SetCharacter(character).SetContainer(lootContainer.Eid);
                                foreach (var lootItem in lootItems)
                                {
                                    b.SetItem(lootItem.ItemInfo.Definition, lootItem.ItemInfo.Quantity);
                                    Character.LogTransaction(b);
                                }
                            }
                        }

                        var killedByPlayer = (killer != null && killer.IsPlayer());

                        Trashcan.Get().MoveToTrash(this, Session.DisconnectTime, wasInsured, killedByPlayer, Session.InactiveTime);

                        character.NextAvailableRobotRequestTime = DateTime.Now.AddMinutes(killedByPlayer ? ARKHE_REQUEST_TIMER_MINUTES_PVP : ARKHE_REQUEST_TIMER_MINUTES_NPC);

                        Robot activeRobot = null;

                        if (!killedByPlayer)
                        {
                            activeRobot = dockingBase.CreateStarterRobotForCharacter(character);

                            if (activeRobot != null)
                            {
                                Transaction.Current.OnCommited(() =>
                                {
                                    var starterRobotInfo = new Dictionary <string, object>
                                    {
                                        { k.baseEID, Eid },
                                        { k.robotEID, activeRobot.Eid }
                                    };

                                    Message.Builder.SetCommand(Commands.StarterRobotCreated).WithData(starterRobotInfo).ToCharacter(character).Send();
                                });
                            }
                        }

                        character.SetActiveRobot(activeRobot);
                    }
                    else
                    {
                        // mert rendesek vagyunk
                        this.Repair();

                        // csak az adminok miatt kell
                        var container = dockingBase.GetPublicContainer();
                        container.AddItem(this, false);
                    }

                    this.Save();

                    scope.Complete();
                }
                catch (Exception ex)
                {
                    Logger.Exception(ex);
                }
            }
        }
Exemple #3
0
 public IBuilder <LootItem> GetLootItemBuilder()
 {
     return(LootItemBuilder.Create(Definition)
            .SetQuantity(FastRandom.NextInt(Quantity))
            .SetRepackaged(Packed));
 }