Beispiel #1
0
        private void OnConstructionLevelChanged()
        {
            var zone = _pbsUnit.Zone;

            if (zone == null)
            {
                return;
            }

            var currentLevel = ConstructionLevelCurrent;

            if (currentLevel <= 0)
            {
                //object got deconstructed, remove from zone, add capsule to loot

                if (_contructionLootDropped)
                {
                    return;
                }

                _contructionLootDropped = true;

                using (var scope = Db.CreateTransaction())
                {
                    LootContainer.Create()
                    .AddLoot(PBSHelper.GetCapsuleDefinitionByPBSObject(_pbsUnit), 1)
                    .AddLoot(PBSHelper.GetConstructionAmmoLootOnDeconstruct(_pbsUnit))
                    .BuildAndAddToZone(zone, _pbsUnit.CurrentPosition);

                    var dockingBase = _pbsUnit as PBSDockingBase;
                    if (dockingBase != null)
                    {
                        Logger.DebugInfo("dropping loot from base");
                        PBSHelper.DropLootToZoneFromBaseItems(zone, dockingBase, false);
                    }
                    _pbsUnit.RemoveFromZone();

                    Logger.Info("pbs node got deconstructed. " + _pbsUnit.Eid + " " + _pbsUnit.ED.Name + " owner:" + _pbsUnit.Owner);
                    PBSHelper.WritePBSLog(PBSLogType.deconstructed, _pbsUnit.Eid, _pbsUnit.Definition, _pbsUnit.Owner, zoneId: zone.Id);

                    scope.Complete();
                }

                return;
            }

            if (!IsFullyConstructed)
            {
                return;
            }

            SetToDeconstruct(); //felepult, mostmar lehet lebontani is vagy barmi

            PBSHelper.WritePBSLog(PBSLogType.constructed, _pbsUnit.Eid, _pbsUnit.Definition, _pbsUnit.Owner, zoneId: zone.Id);
            SendNodeUpdate();
        }
Beispiel #2
0
        private void CreateLoots(Player player, Artifact artifact)
        {
            var lootItems = _artifactLootGenerator.GenerateLoot(artifact);

            if (lootItems == null)
            {
                return;
            }

            LootContainer.Create().SetOwner(player).SetEnterBeamType(BeamType.artifact_found).AddLoot(lootItems.LootItems).BuildAndAddToZone(_zone, lootItems.Position);
        }
Beispiel #3
0
        private void HandleNpcDead([NotNull] IZone zone, Unit killer, Player tagger)
        {
            Logger.DebugInfo($"   >>>> NPC died.  Killer unitName:{killer.Name} o:{killer.Owner}   Tagger botname:{tagger?.Name} o:{killer.Owner} characterId:{tagger?.Character.Id}");

            using (var scope = Db.CreateTransaction())
            {
                LootContainer.Create().SetOwner(tagger).AddLoot(LootGenerator).BuildAndAddToZone(zone, CurrentPosition);

                var killerPlayer = zone.ToPlayerOrGetOwnerPlayer(killer);

                if (GetMissionGuid() != Guid.Empty)
                {
                    Logger.DebugInfo("   >>>> NPC is mission related.");

                    SearchForMissionOwnerAndSubmitKill(zone, killer);
                }
                else
                {
                    Logger.DebugInfo("   >>>> independent NPC.");

                    if (killerPlayer != null)
                    {
                        EnqueueKill(killerPlayer, killer);
                    }
                }

                var ep = Db.Query().CommandText("GetNpcKillEp").SetParameter("@definition", Definition).ExecuteScalar <int>();

                //Logger.Warning($"Ep4Npc:{ep} def:{Definition} {ED.Name}");

                if (zone.Configuration.IsBeta)
                {
                    ep *= 2;
                }

                if (zone.Configuration.Type == ZoneType.Training)
                {
                    ep = 0;
                }

                if (ep > 0)
                {
                    foreach (var hostile in ThreatManager.Hostiles)
                    {
                        var hostilePlayer = zone.ToPlayerOrGetOwnerPlayer(hostile.unit);
                        hostilePlayer?.Character.AddExtensionPointsBoostAndLog(EpForActivityType.Npc, ep);
                    }
                }

                scope.Complete();
            }
        }
Beispiel #4
0
        /// <summary>
        /// This function is called when players take over a sap successfully
        /// </summary>
        private void HandleTakeOver(SAP sap)
        {
            Logger.Info($"Intrusion SAP taken. sap = {sap.Eid} {sap.ED.Name} ");

            using (var scope = Db.CreateTransaction())
            {
                try
                {
                    var gen = new LootGenerator(_lootService.GetIntrusionLootInfos(this, sap));
                    LootContainer.Create().AddLoot(gen).BuildAndAddToZone(Zone, sap.CurrentPosition);

                    var winnerCorporation = sap.GetWinnerCorporation();
                    if (winnerCorporation == null)
                    {
                        return;
                    }

                    var siteInfo     = GetIntrusionSiteInfo();
                    var oldStability = siteInfo.Stability;
                    var newStability = siteInfo.Stability;
                    var newOwner     = siteInfo.Owner;
                    var oldOwner     = siteInfo.Owner;

                    var logEvent = new IntrusionLogEvent
                    {
                        OldOwner             = siteInfo.Owner,
                        NewOwner             = siteInfo.Owner,
                        SapDefinition        = sap.Definition,
                        EventType            = IntrusionEvents.sapTakeOver,
                        WinnerCorporationEid = winnerCorporation.Eid,
                        OldStability         = oldStability
                    };

                    if (winnerCorporation is PrivateCorporation)
                    {
                        //Compare the Owner and Winner corp's relations
                        var ownerEid = siteInfo.Owner ?? default(long);
                        var ownerAndWinnerGoodRelation = false;

                        var friendlyOnly = 10;
                        //Compare both relations between corps:
                        //True IFF both corps have strictly friendly relations with eachother
                        ownerAndWinnerGoodRelation = _corporationManager.IsStandingMatch(winnerCorporation.Eid, ownerEid, friendlyOnly);
                        ownerAndWinnerGoodRelation = _corporationManager.IsStandingMatch(ownerEid, winnerCorporation.Eid, friendlyOnly) && ownerAndWinnerGoodRelation;

                        //Stability increase if winner is owner OR winner is in good standing with owner
                        if (winnerCorporation.Eid == siteInfo.Owner || ownerAndWinnerGoodRelation)
                        {
                            newStability = (newStability + sap.StabilityChange).Clamp(0, 100);
                        }
                        else
                        {
                            newStability = (newStability - sap.StabilityChange).Clamp(0, 100);

                            // csak akkor ha 0 lett a stability
                            if (newStability == 0)
                            {
                                if (siteInfo.Owner != null)
                                {
                                    // ha van owner akkor eloszor toroljuk a regit es majd a kovetkezo korben kap ujat
                                    logEvent.EventType = IntrusionEvents.siteOwnershipLost;
                                    newOwner           = null;
                                }
                                else
                                {
                                    // itt kap uj ownert es egy kezdo stability erteket
                                    logEvent.EventType = IntrusionEvents.siteOwnershipGain;
                                    newOwner           = winnerCorporation.Eid;
                                    newStability       = STARTING_STABILITY;
                                }
                            }
                        }

                        //set the resulting values
                        SetIntrusionOwnerAndPoints(newOwner, newStability);
                        ReactStabilityChanges(siteInfo, oldStability, newStability, newOwner, oldOwner);
                    }

                    logEvent.NewOwner     = newOwner;
                    logEvent.NewStability = newStability;
                    InsertIntrusionLog(logEvent);

                    foreach (var playerInfo in sap.GetPlayersWithScore())
                    {
                        var ep        = playerInfo.corporationEid == winnerCorporation.Eid ? EP_WINNER : EP_LOSER;
                        var character = playerInfo.character;
                        character.AddExtensionPointsBoostAndLog(EpForActivityType.Intrusion, ep);
                    }

                    //make dem toast anyways
                    Transaction.Current.OnCommited(() =>
                    {
                        if (oldStability != newStability)
                        {
                            OnIntrusionSiteInfoUpdated();
                            InformAllPlayers();
                        }

                        InformPlayersOnZone(Commands.ZoneSapActivityEnd, new Dictionary <string, object>
                        {
                            { k.siteEID, Eid },
                            { k.eventType, (int)logEvent.EventType },
                            { k.eid, sap.Eid },
                            { k.winner, winnerCorporation.Eid },
                        });
                    });

                    scope.Complete();
                }
                catch (Exception ex)
                {
                    Logger.Exception(ex);
                }
            }
        }
Beispiel #5
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);
                }
            }
        }