Esempio n. 1
0
        private int GetCombinedDefinitionFromPools(MissionInProgress missionInProgress, CategoryFlags categoryFlags)
        {
            if (Type == MissionTargetType.lock_unit)
            {
                Log("intel document was generated.");
                return(EntityDefault.GetByName(DefinitionNames.MISSION_RND_INTEL_DOCUMENT).Definition);
            }

            if (Type == MissionTargetType.drill_mineral)
            {
                Log("mining proof was generated.");
                return(EntityDefault.GetByName(DefinitionNames.MISSION_RND_MINING_PROOF).Definition);
            }

            if (Type == MissionTargetType.harvest_plant)
            {
                Log("harvesting proof was generated.");
                return(EntityDefault.GetByName(DefinitionNames.MISSION_RND_HARVESTING_PROOF).Definition);
            }


            if (generateResearchKit)
            {
                Log("random research kit was generated.");
                return(EntityDefault.GetByName(DefinitionNames.MISSION_RND_RESEARCH_KIT).Definition);
            }

            if (generateCalibrationProgram)
            {
                return(GetCalibrationProgramFromPool(missionInProgress));
            }

            return(GetDefinitionFromMissionItemsPool(missionInProgress, categoryFlags));
        }
        public static PrivateAlliance Create(AllianceDescription description)
        {
            var systemStorage = SystemContainer.GetByName(k.es_private_alliance);
            var newAlliance   = Create(EntityDefault.GetByName(DefinitionNames.PRIVATE_ALLIANCE), systemStorage, description, EntityIDGenerator.Random);

            return((PrivateAlliance)newAlliance);
        }
Esempio n. 3
0
        public static long LoadStorageEid(long facilityEid)
        {
            var eid =
                Db.Query().CommandText("select top 1 eid from entities where parent=@facilityEid and definition=@containerDef")
                .SetParameter("@containerDef", EntityDefault.GetByName(DefinitionNames.SYSTEM_CONTAINER).Definition)
                .SetParameter("@facilityEid", facilityEid)
                .ExecuteScalar <long>();

            Logger.Info("storage loaded for " + facilityEid + " storageEid:" + eid);
            return(eid);
        }
Esempio n. 4
0
        public Dictionary <string, object> LogsToDictionary(int offsetInDays = 0)
        {
            var later   = DateTime.Now.AddDays(-1 * offsetInDays);
            var earlier = later.AddDays(-14);

            const string sqlCmd = @"select memberID,containeraccess,quantity,definition,operationdate 
                          from containerlog 
                          where containerEID = @containerEid or 
                          containerEID in (select eid from entities where parent = @containerEid and definition = @folderDefinition)  
                          and (operationdate between @earlier and @later)";

            var folder  = EntityDefault.GetByName(DefinitionNames.CORPORATE_HANGAR_FOLDER);
            var records = Db.Query().CommandText(sqlCmd).SetParameter("@containerEID", _container.Eid)
                          .SetParameter("@folderDefinition", folder.Definition)
                          .SetParameter("@earlier", earlier)
                          .SetParameter("@later", later)
                          .Execute();

            var result  = new Dictionary <string, object>();
            var counter = 0;

            foreach (var record in records)
            {
                var oneEntry = new Dictionary <string, object>
                {
                    { k.memberID, record.GetValue <int>(0) },
                    { k.operation, record.GetValue <int>(1) }
                };

                if (!record.IsDBNull(2))
                {
                    oneEntry.Add(k.quantity, record.GetValue <int>(2));
                }
                if (!record.IsDBNull(3))
                {
                    oneEntry.Add(k.definition, record.GetValue <int>(3));
                }

                oneEntry.Add(k.date, record.GetValue <DateTime>(4));

                result.Add("c" + counter++, oneEntry);
            }

            var totalDict = new Dictionary <string, object> {
                { k.eid, _container.Eid }, { k.log, result }
            };

            return(totalDict);
        }
Esempio n. 5
0
        public void ClearLog(Character character)
        {
            var folder     = EntityDefault.GetByName(DefinitionNames.CORPORATE_HANGAR_FOLDER);
            var loggedEiDs = Db.Query().CommandText("select eid from entities where parent=@hangarEID and definition=@folderDefinition")
                             .SetParameter("@hangarEID", _container.Eid)
                             .SetParameter("@folderDefinition", folder.Definition)
                             .Execute().Select(r => r.GetValue <long>(0)).ToArray();

            var folderString = loggedEiDs.Any() ? " or containerEID in (" + loggedEiDs.ArrayToString() + ")" : string.Empty;

            Db.Query().CommandText("delete containerlog where containerEID=@containerEID" + folderString)
            .SetParameter("@containerEID", _container.Eid)
            .ExecuteNonQuery();

            AddLogEntry(character, ContainerAccess.LogClear);
        }
        /*
         *  1	usa_great_corp
         *  2	eu_great_corp
         *  3	asia_great_corp
         */
        public int GetRaceSpecificCoinDefinition()
        {
            switch (RaceId)
            {
            case 1:
                return(EntityDefault.GetByName(DefinitionNames.TM_MISSION_COIN).Definition);

            case 2:
                return(EntityDefault.GetByName(DefinitionNames.ICS_MISSION_COIN).Definition);

            case 3:
                return(EntityDefault.GetByName(DefinitionNames.ASI_MISSION_COIN).Definition);

            default:
                throw new PerpetuumException(ErrorCodes.ConsistencyError);
            }
        }
        public long GetTrainingMarketEid()
        {
            if (_trainingMarketEid < 0)
            {
                var query = @"SELECT TOP 1 eid FROM dbo.entities WHERE parent in (SELECT TOP 1 eid FROM dbo.entities WHERE definition=@tb_def)";

                var tbm_eid =
                    Db.Query().CommandText(query)
                    .SetParameter("@tb_def", EntityDefault.GetByName(DefinitionNames.TRAINING_DOCKING_BASE).Definition)
                    .ExecuteScalar <long>();

                Logger.Info("training base market eid was found: " + tbm_eid);

                _trainingMarketEid = tbm_eid;
            }

            return(_trainingMarketEid);
        }
Esempio n. 8
0
        private static bool TryFindContainerRoot(Item item, out Container container)
        {
            var publicContainer = EntityDefault.GetByName(DefinitionNames.PUBLIC_CONTAINER);
            var corporateHangar = EntityDefault.GetByName(DefinitionNames.CORPORATE_HANGAR_STANDARD);

            var rootEid = Db.Query().CommandText("findContainerRoot")
                          .SetParameter("@publicContainerDefinition", publicContainer.Definition)
                          .SetParameter("@corporateHangarDefinition", corporateHangar.Definition)
                          .SetParameter("@itemEid", item.Eid)
                          .ExecuteScalar <long?>();

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

            container = GetOrThrow((long)rootEid);
            return(true);
        }
Esempio n. 9
0
        /*
         *  1	usa_great_corp
         *  2	eu_great_corp
         *  3	asia_great_corp
         */
        public int GetRaceSpecificCoinDefinition()
        {
            //TODO: Fixme: I am a hack for Syndicatification
            if (this.zoneId == 0 || this.zoneId == 8) //For New Virginia and Hershfield
            {
                return(EntityDefault.GetByName(DefinitionNames.UNIVERSAL_MISSION_COIN).Definition);
            }
            //--end hack--
            switch (RaceId)
            {
            case 1:
                return(EntityDefault.GetByName(DefinitionNames.TM_MISSION_COIN).Definition);

            case 2:
                return(EntityDefault.GetByName(DefinitionNames.ICS_MISSION_COIN).Definition);

            case 3:
                return(EntityDefault.GetByName(DefinitionNames.ASI_MISSION_COIN).Definition);

            default:
                throw new PerpetuumException(ErrorCodes.ConsistencyError);
            }
        }
Esempio n. 10
0
        public void Buy(Container container, Character character, int entryID, int quantity = 1)
        {
            if (quantity < 1)
            {
                throw new PerpetuumException(ErrorCodes.WTFErrorMedicalAttentionSuggested);
            }

            var entry = GetEntry(entryID);

            if (entry == null)
            {
                throw new PerpetuumException(ErrorCodes.ItemNotFound);
            }

            entry.CheckGlobalLimit(quantity);
            CheckStanding(character, entry);

            entry.RemoveFromContainer(container, quantity);

            var totalCredit = entry.Credit * quantity;

            if (totalCredit > 0)
            {
                var ownerWallet = _characterWalletFactory(character, TransactionType.ItemShopCreditTake);
                ownerWallet.Balance -= totalCredit;

                character.LogTransaction(TransactionLogEvent.Builder()
                                         .SetTransactionType(TransactionType.ItemShopCreditTake)
                                         .SetCreditBalance(ownerWallet.Balance)
                                         .SetCreditChange(-totalCredit)
                                         .SetCharacter(character)
                                         .Build());
            }

            var targetItem = entry.CreateTargetItem(character, quantity);

            container.AddItem(targetItem, true);

            UpdateGlobalPurchaseCount(targetItem.Definition, targetItem.Quantity);

            if (entry.TmCoin > 0)
            {
                character.LogTransaction(TransactionLogEvent.Builder()
                                         .SetTransactionType(TransactionType.ItemShopTake)
                                         .SetCharacter(character)
                                         .SetContainer(container)
                                         .SetItem(EntityDefault.GetByName(DefinitionNames.TM_MISSION_COIN).Definition, entry.TmCoin * quantity));
            }

            if (entry.IcsCoin > 0)
            {
                character.LogTransaction(TransactionLogEvent.Builder()
                                         .SetTransactionType(TransactionType.ItemShopTake)
                                         .SetCharacter(character)
                                         .SetContainer(container)
                                         .SetItem(EntityDefault.GetByName(DefinitionNames.ICS_MISSION_COIN).Definition, entry.IcsCoin * quantity));
            }

            if (entry.AsiCoin > 0)
            {
                character.LogTransaction(TransactionLogEvent.Builder()
                                         .SetTransactionType(TransactionType.ItemShopTake)
                                         .SetCharacter(character)
                                         .SetContainer(container)
                                         .SetItem(EntityDefault.GetByName(DefinitionNames.ASI_MISSION_COIN).Definition, entry.AsiCoin * quantity));
            }


            character.LogTransaction(TransactionLogEvent.Builder()
                                     .SetTransactionType(TransactionType.ItemShopBuy)
                                     .SetCharacter(character)
                                     .SetItem(targetItem));
        }
Esempio n. 11
0
 public static CorporateHangar Create()
 {
     return((CorporateHangar)Factory.CreateWithRandomEID(EntityDefault.GetByName(DefinitionNames.CORPORATE_HANGAR_STANDARD)));
 }
Esempio n. 12
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);
                }
            }
        }
Esempio n. 13
0
 public static Coin CreateUniversalCoin(int amount)
 {
     return(new Coin(EntityDefault.GetByName(DefinitionNames.UNIVERSAL_MISSION_COIN), amount));
 }
Esempio n. 14
0
 public static Coin CreateASICoin(int amount)
 {
     return(new Coin(EntityDefault.GetByName(DefinitionNames.ASI_MISSION_COIN), amount));
 }
        public static PrivateCorporation Create(CorporationDescription corporationDescription)
        {
            var container = SystemContainer.GetByName(k.es_private_corporation);

            return((PrivateCorporation)Create(EntityDefault.GetByName(DefinitionNames.PRIVATE_CORPORATION), container, corporationDescription, EntityIDGenerator.Random));
        }