Beispiel #1
0
        public ErrorCodes DoResearchKitMerge(PublicContainer publicContainer, Character character, int nextDefinition,
                                             int nextLevel, double fullPrice, int availableQuantity, int searchDefinition, out Dictionary <string, object> result, bool useCorporationWallet)
        {
            var ec            = ErrorCodes.NoError;
            var foundQuantity = 0;

            result = new Dictionary <string, object>();
            var amountToLookFor = availableQuantity * 2;

            foreach (var item in publicContainer.GetItems().Where(i => i.Definition == searchDefinition))
            {
                if (item.Quantity <= amountToLookFor - foundQuantity)
                {
                    foundQuantity += item.Quantity;

                    Repository.Delete(item);
                }
                else
                {
                    item.Quantity = item.Quantity - (amountToLookFor - foundQuantity);

                    foundQuantity = amountToLookFor;
                    break;
                }
            }

            if (foundQuantity != amountToLookFor)
            {
                //safe check
                return(ErrorCodes.ItemNotFound);
            }

            publicContainer.CreateAndAddItem(nextDefinition, true, item =>
            {
                item.Owner    = character.Eid;
                item.Quantity = availableQuantity;
            });

            var wallet = character.GetWalletWithAccessCheck(useCorporationWallet, TransactionType.ResearchKitMerge, CorporationRole.ProductionManager);

            wallet.Balance -= fullPrice;

            var b = TransactionLogEvent.Builder()
                    .SetTransactionType(TransactionType.ResearchKitMerge)
                    .SetCreditBalance(wallet.Balance)
                    .SetCreditChange(-fullPrice)
                    .SetCharacter(character);

            var corpWallet = wallet as CorporationWallet;

            if (corpWallet != null)
            {
                b.SetCorporation(corpWallet.Corporation);
                corpWallet.Corporation.LogTransaction(b);
            }
            else
            {
                character.LogTransaction(b);
            }

            result = new Dictionary <string, object> {
                { k.container, publicContainer.ToDictionary() }
            };
            return(ec);
        }
Beispiel #2
0
        public ErrorCodes PrepareResearchKitMerge(
            PublicContainer publicContainer,
            Character character, long target, int quantity,
            out int nextDefinition,
            out int nextLevel,
            out double fullPrice,
            out int availableQuantity,
            out int searchDefinition)
        {
            ErrorCodes ec;

            nextDefinition    = 0;
            nextLevel         = 0;
            fullPrice         = 0;
            availableQuantity = 0;
            searchDefinition  = 0;

            var researchKit = (ResearchKit)publicContainer.GetItem(target, true);

            if (researchKit == null)
            {
                return(ErrorCodes.ItemNotFound);
            }

            var definition = researchKit.Definition;

            searchDefinition = definition;

            EntityDefault ed;

            if (!EntityDefault.TryGet(definition, out ed))
            {
                return(ErrorCodes.DefinitionNotSupported);
            }

            int level = ed.Options.Level;

            if (level == 0)
            {
                Logger.Error("no level was defined for research kit: " + ed.Name + " " + ed.Definition);
                return(ErrorCodes.ConsistencyError);
            }

            if (level == 10)
            {
                return(ErrorCodes.MaximumResearchLevelReached);
            }

            nextLevel = level + 1;

            var sameDefinitions = publicContainer.GetItems().Where(i => i.Definition == definition).Sum(i => i.Quantity);

            if (sameDefinitions % 2 == 1)
            {
                sameDefinitions--;
            }

            var pairs = sameDefinitions / 2;

            if ((ec = ProductionHelper.FindResearchKitDefinitionByLevel(nextLevel, out nextDefinition)) != ErrorCodes.NoError)
            {
                return(ec);
            }

            availableQuantity = Math.Min(pairs, quantity);

            fullPrice = GetReserchKitMergePrice(nextLevel, character) * availableQuantity;

            return(ec);
        }