Exemplo n.º 1
0
 public static IDictionary <string, object> GetStandingForDefaultAlliances(this IStandingHandler standingHandler, Character character)
 {
     return(DefaultCorporationDataCache.GetMegaCorporationEids().ToDictionary("s", allianceEID =>
     {
         var standing = standingHandler.GetStanding(allianceEID, character.Eid);
         var entry = new Dictionary <string, object>()
         {
             { k.eid, allianceEID },
             { k.standing, standing },
         };
         return entry;
     }));
 }
Exemplo n.º 2
0
 public static IDictionary <string, object> GetStandingForDefaultCorporations(this IStandingHandler standingHandler, Character character)
 {
     return(DefaultCorporationDataCache.GetAllDefaultCorporationEid().ToDictionary("s", corporationEID =>
     {
         var standing = standingHandler.GetStanding(corporationEID, character.Eid);
         var entry = new Dictionary <string, object>
         {
             { k.eid, corporationEID },
             { k.standing, standing }
         };
         return entry;
     }));
 }
Exemplo n.º 3
0
        private void CheckStanding(Character character, ItemShopEntry shopEntry)
        {
            if (shopEntry.Standing == null)
            {
                return;
            }

            var standing = _standingHandler.GetStanding(Owner, character.Eid);

            if (standing < shopEntry.Standing)
            {
                throw new PerpetuumException(ErrorCodes.StandingTooLow);
            }
        }
        public bool IsStandingMatch(long sourceCorporationEid, long targetCorporationEid, double?standingLimit)
        {
            if (standingLimit == null || sourceCorporationEid == 0)
            {
                return(true);
            }

            //my corp -> ok
            if (sourceCorporationEid == targetCorporationEid)
            {
                return(true);
            }

            var standing = _standingHandler.GetStanding(sourceCorporationEid, targetCorporationEid);

            return(standing >= standingLimit);
        }
Exemplo n.º 5
0
        private bool HasAccess(long playersCorporationEid)
        {
            if (playersCorporationEid == Owner)
            {
                //own corporation -> ok
                return(true);
            }

            if (DefaultCorporationDataCache.IsCorporationDefault(playersCorporationEid))
            {
                //only private corporation members
                return(false);
            }

            var standingValue = _standingHandler.GetStanding(Owner, playersCorporationEid);

            //match standing level
            return(standingValue > StandingLimit);
        }
Exemplo n.º 6
0
 public static void GetStandingData(Character character, long allianceEid, out double standing, out int missionLevel)
 {
     standing = _standingHandler.GetStanding(allianceEid, character.Eid);
     //0.1->0  1.0->1  1.1->1  -2.3->0
     missionLevel = (int)(Math.Floor(standing).Clamp(0, double.MaxValue));
 }
Exemplo n.º 7
0
        private static void CollectHangarRent(IStandingHandler standingHandler)
        {
            var storage = EntityDefault.GetByName(DefinitionNames.PUBLIC_CORPORATE_HANGARS_STORAGE);

            var hangarEids = Db.Query().CommandText("select eid from entities where parent in (SELECT eid FROM dbo.getLiveDockingbaseChildren() WHERE definition=@hangarDef) order by parent")
                             .SetParameter("@hangarDef", storage.Definition)
                             .Execute()
                             .Select(h => (CorporateHangar)GetOrThrow(h.GetValue <long>(0)))
                             .ToArray();

            Logger.Info("--- hangars collected for rent check: " + hangarEids.Count());

            using (var scope = Db.CreateTransaction())
            {
                try
                {
                    foreach (var hangar in hangarEids)
                    {
                        var hangarStorage = hangar.GetHangarStorage();
                        switch (hangarStorage.GetParentDockingBase())
                        {
                        case Outpost outpost:
                        {
                            var siteInfo = outpost.GetIntrusionSiteInfo();
                            if (siteInfo?.Owner != null)
                            {
                                //it has an owner
                                if (hangar.Owner != siteInfo.Owner)
                                {
                                    //the owner is not the hangar's owner
                                    var dockingStandingLimit = siteInfo.DockingStandingLimit;
                                    if (dockingStandingLimit != null)
                                    {
                                        //the outpost has standing limit set
                                        var standingTowardsOwner = standingHandler.GetStanding((long)siteInfo.Owner, hangar.Owner);

                                        if (standingTowardsOwner < dockingStandingLimit)
                                        {
                                            //the hangar is inaccessible
                                            Logger.Info("hangar is inaccessible for corp. " + hangar.Owner + " hangaried:" + hangar.Eid + " standing:" + standingTowardsOwner + " dockingStandingLimit:" + dockingStandingLimit);
                                            continue;
                                        }
                                    }
                                }
                            }
                            break;
                        }

                        case PBSDockingBase pbsDockingBase:
                        {
                            if (pbsDockingBase.StandingEnabled)
                            {
                                var standingTowardsOwner = standingHandler.GetStanding(pbsDockingBase.Owner, hangar.Owner);

                                if (standingTowardsOwner < pbsDockingBase.StandingLimit)
                                {
                                    Logger.Info("hangar is inaccessible for corp. " + hangar.Owner + " hangaried:" + hangar.Eid + " standing:" + standingTowardsOwner + " dockingStandingLimit:" + pbsDockingBase.StandingLimit);
                                    continue;
                                }
                            }
                            break;
                        }
                        }

                        var rentInfo = hangarStorage.GetCorporationHangarRentInfo();

                        // rent expired?

                        if (hangar.IsLeaseExpired)
                        {
                            continue;
                        }

                        if (DateTime.Now > hangar.LeaseEnd)
                        {
                            var corporation = hangar.GetCorporation();

                            Logger.Info("--- hangar rent process started for hangarEID:" + hangar.Eid + " hangarName:" + hangar.Name + " corporaration:" + corporation.Eid + " corpname:" + corporation.Description.name);

                            var wallet = new CorporationWallet(corporation);

                            if (wallet.Balance < rentInfo.price)
                            {
                                Logger.Info("--- corporation is broken. corporationEID:" + corporation.Eid + " hangar closed. EID:" + hangar.Eid);

                                //corporation broken
                                hangar.IsLeaseExpired = true; //block the hangar's content

                                //alert accountants
                                var info = new Dictionary <string, object> {
                                    { k.containerEID, hangar.Eid }
                                };

                                Message.Builder.SetCommand(Commands.CorporationHangarRentExpired)
                                .WithData(info)
                                .ToCorporation(corporation, CorporationRole.Accountant)
                                .Send();
                            }
                            else
                            {
                                wallet.Balance -= rentInfo.price;

                                var b = TransactionLogEvent.Builder()
                                        .SetCorporation(corporation)
                                        .SetTransactionType(TransactionType.hangarRentAuto)
                                        .SetCreditBalance(wallet.Balance)
                                        .SetCreditChange(-rentInfo.price);

                                corporation.LogTransaction(b);

                                hangarStorage.GetParentDockingBase().AddCentralBank(TransactionType.hangarRentAuto, rentInfo.price);

                                hangar.LeaseStart     = DateTime.Now;
                                hangar.LeaseEnd       = DateTime.Now + rentInfo.period;
                                hangar.IsLeaseExpired = false;

                                Logger.Info("--- hangar price paid. hangarEID: " + hangar.Eid + " lease ended:" + hangar.LeaseEnd + " lease extened:" + hangar.LeaseEnd);
                            }

                            hangar.Save();
                        }
                        else
                        {
                            Logger.Info("--- hangar still paid. eid:" + hangar.Eid + " lease end:" + hangar.LeaseEnd);
                        }
                    }

                    scope.Complete();
                }
                catch (Exception ex)
                {
                    Logger.Exception(ex);
                }
            }
        }
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var sparkId   = request.Data.GetOrDefault <int>(k.sparkID);
                var character = request.Session.Character;

                character.IsDocked.ThrowIfFalse(ErrorCodes.CharacterHasToBeDocked);

                var spark = _sparkHelper.GetSpark(sparkId).ThrowIfNull(ErrorCodes.ItemNotFound);
                spark.defaultSpark.ThrowIfTrue(ErrorCodes.SparkAlreadyUnlocked);
                spark.unlockable.ThrowIfFalse(ErrorCodes.WTFErrorMedicalAttentionSuggested);

                _sparkHelper.GetUnlockedSparkData(character).Any(uls => uls.sparkId == sparkId).ThrowIfTrue(ErrorCodes.SparkAlreadyUnlocked);

                if (spark.unlockPrice != null)
                {
                    character.SubtractFromWallet(TransactionType.SparkUnlock, (double)spark.unlockPrice);
                }

                if (spark.definition != null)
                {
                    var publicContainer = character.GetPublicContainerWithItems();

                    //keress meg itemet
                    var foundItems = publicContainer.GetItems().Where(i => i.Definition == spark.definition);

                    var needed = (int)spark.quantity;

                    foreach (var item in foundItems)
                    {
                        if (item.Quantity > needed)
                        {
                            item.Quantity = item.Quantity - needed;
                            needed        = 0;
                            break; //found more
                        }

                        if (item.Quantity <= needed)
                        {
                            needed = needed - item.Quantity;

                            Entity.Repository.Delete(item);

                            if (needed <= 0)
                            {
                                break; //found enough
                            }
                        }
                    }

                    needed.ThrowIfGreater(0, ErrorCodes.SparkNotEnoughItems);
                    publicContainer.Save();
                }

                if (spark.energyCredit != null)
                {
                    //%%% itt a cucc
                }

                if (spark.allianceEid != null)
                {
                    var standing = _standingHandler.GetStanding((long)spark.allianceEid, character.Eid);
                    standing.ThrowIfLess((double)spark.standingLimit, ErrorCodes.StandingTooLow);
                }

                _sparkHelper.UnlockSpark(character, sparkId);

                //return list
                Transaction.Current.OnCommited(() => _sparkHelper.SendSparksList(request));

                scope.Complete();
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Matches level with standing
        /// Used in config mission start
        /// </summary>
        /// <param name="character"></param>
        /// <param name="standingHandler"></param>
        /// <returns></returns>
        public bool MatchStandingToLevel(Character character, IStandingHandler standingHandler)
        {
            var standing = standingHandler.GetStanding(issuerAllianceEid, character.Eid);

            return(standing >= MissionLevel);
        }