public ErrorCodes InsuranceDelete(Character character, long targetEid)
        {
            //auto clean
            InsuranceHelper.CleanUpInsurances();

            var item = Item.GetOrThrow(targetEid);

            var insurance = _insuranceHelper.GetInsurance(targetEid);

            if (insurance == null)
            {
                return(ErrorCodes.NoError);
            }

            if (insurance.corporationEid != null)
            {
                var corporation = character.GetCorporation();
                var role        = corporation.GetMemberRole(character);

                //ha nem az issuer akarja torolni
                if (insurance.character != character)
                {
                    //akkor torolhetio a CEO, dpCEO
                    if (!role.IsAnyRole(CorporationRole.DeputyCEO, CorporationRole.CEO, CorporationRole.Accountant))
                    {
                        return(ErrorCodes.InsufficientPrivileges);
                    }
                }
            }
            else
            {
                //le lehet torolni ha
                // - nalad van
                // - te kototted

                if (!((item.Owner == character.Eid) || (insurance.character == character)))
                {
                    return(ErrorCodes.AccessDenied);
                }
            }

            _insuranceHelper.DeleteAndInform(insurance, item.Eid);
            return(ErrorCodes.NoError);
        }
        public void WriteToSql(Container container, Dictionary <int, int> randomComponentResults)
        {
            var logQuantity = _item.Quantity;

            //delete source item
            if (_wasDeleted)
            {
                _insuranceHelper.DeleteAndInform(_item);
                Entity.Repository.Delete(_item);
            }
            else
            {
                logQuantity    = _item.Quantity - _resultQuantity;
                _item.Quantity = _resultQuantity;
            }

            _character.LogTransaction(TransactionLogEvent.Builder().SetTransactionType(TransactionType.ReprocessDeleted).SetCharacter(_character).SetItem(_item.Definition, logQuantity));

            if (!randomizeComponents)
            {
                //make the resulting components
                foreach (var component in _components)
                {
                    if (component.realAmount <= 0)
                    {
                        continue;
                    }

                    var resultItem = (Item)Entity.Factory.CreateWithRandomEID(component.definition);
                    resultItem.Owner    = _item.Owner;
                    resultItem.Quantity = component.realAmount;

                    container.AddItem(resultItem, true);

                    var b = TransactionLogEvent.Builder().SetTransactionType(TransactionType.ReprocessCreated).SetCharacter(_character).SetItem(resultItem);
                    _character.LogTransaction(b);
                }
            }
            else
            {
                //pick random components and add them to the container

                Logger.Info("creating random components for " + _item.Eid);

                var configComponents = ProductionComponentCollector.Collect(_item);
                if (configComponents.Count == 0)
                {
                    return;
                }

                var sumAmount  = configComponents.Sum(r => r.Amount);
                var randomPool = new List <int>(sumAmount);

                foreach (var productionComponent in configComponents)
                {
                    for (var i = 0; i < productionComponent.Amount; i++)
                    {
                        randomPool.Add(productionComponent.EntityDefault.Definition);
                    }
                }

                var chosenDefinition = randomPool.ElementAt(FastRandom.NextInt(0, randomPool.Count - 1));

                var chosenComponent = configComponents.First(r => r.EntityDefault.Definition == chosenDefinition);

                var resultItem = (Item)Entity.Factory.CreateWithRandomEID(chosenComponent.EntityDefault.Definition);
                resultItem.Owner    = _item.Owner;
                resultItem.Quantity = chosenComponent.Amount * _item.Quantity;

                container.AddItem(resultItem, true);

                _character.WriteItemTransactionLog(TransactionType.ReprocessCreated, resultItem);

                if (randomComponentResults.ContainsKey(resultItem.Definition))
                {
                    randomComponentResults[resultItem.Definition] += resultItem.Quantity;
                }
                else
                {
                    randomComponentResults.Add(resultItem.Definition, resultItem.Quantity);
                }
            }
        }
Example #3
0
 public override void OnDeleteFromDb()
 {
     InsuranceHelper.DeleteAndInform(this);
     base.OnDeleteFromDb();
 }