예제 #1
0
 public InsufficientFundsAreaConsumptionResult(IAreaConsumption consumption)
 {
     if (consumption == null)
     {
         throw new ArgumentNullException(nameof(consumption));
     }
     AreaConsumption = consumption;
 }
예제 #2
0
 public void DrawHighlighter(IAreaConsumption consumption) => _drawHighligterAction?.Invoke(consumption);
예제 #3
0
        private IAreaConsumptionResult ConsumeZoneAtPrivate(IReadOnlyZoneInfo readOnlyZoneInfo,
                                                            IAreaConsumption consumption)
        {
            var zoneInfo = readOnlyZoneInfo as ZoneInfo;

            if (zoneInfo == null)
            {
                throw new ArgumentNullException(nameof(readOnlyZoneInfo));
            }

            lock (_zoneConsumptionLock)
            {
                if (consumption is IAreaZoneConsumption)
                {
                    var zoneClusterMember =
                        zoneInfo.ConsumptionState.GetZoneConsumption() as ZoneClusterMemberConsumption;
                    if (consumption is EmptyZoneConsumption && zoneClusterMember != null &&
                        zoneClusterMember.IsCentralClusterMember)
                    {
                        List <IConsumeAreaOperation> consumeAreaOperations = null;
                        zoneClusterMember.ParentBaseZoneClusterConsumption.WithUnlockedClusterMembers(() =>
                        {
                            consumeAreaOperations = zoneClusterMember
                                                    .ParentBaseZoneClusterConsumption
                                                    .ZoneClusterMembers
                                                    .Select(zoneMemberConsumption => _zoneInfoGrid
                                                            .GetZoneInfoFor(zoneMemberConsumption)
                                                            )
                                                    .Where(x => x.HasMatch)
                                                    .Select(clusterMemberZoneInfo => clusterMemberZoneInfo
                                                            .MatchingObject
                                                            .ConsumptionState
                                                            .TryConsumeWith(new RubbishZoneConsumption())
                                                            )
                                                    .ToList();
                            if (consumeAreaOperations.All(x => x.CanOverrideWithResult.WillSucceed))
                            {
                                foreach (var consumeAreaOperation in consumeAreaOperations)
                                {
                                    consumeAreaOperation.Apply();
                                }
                            }
                        });

                        if (consumeAreaOperations == null)
                        {
                            throw new InvalidOperationException();
                        }
                        return(new AreaConsumptionResult(consumption, true, consumeAreaOperations.First().Description
                                                         ));
                    }

                    var consumptionOperation = zoneInfo
                                               .ConsumptionState
                                               .TryConsumeWith(consumption as IAreaZoneConsumption);

                    if (consumptionOperation.CanOverrideWithResult.WillSucceed)
                    {
                        consumptionOperation.Apply();
                    }

                    return(new AreaConsumptionResult(consumption, consumptionOperation.CanOverrideWithResult.WillSucceed,
                                                     consumptionOperation.Description
                                                     ));
                }
                if (consumption is IAreaZoneClusterConsumption)
                {
                    var clusterZoneConsumption = consumption as IAreaZoneClusterConsumption;

                    var queryResults = clusterZoneConsumption
                                       .ZoneClusterMembers
                                       .Select(member =>
                                               new
                    {
                        QueryResult = zoneInfo
                                      .GetRelativeZoneInfo(new RelativeZoneInfoQuery(member.RelativeToParentCenterX,
                                                                                     member.RelativeToParentCenterY)),
                        ConsumptionZoneMember = member
                    }
                                               )
                                       .ToArray();

                    if (queryResults.Any(x => x.QueryResult.HasNoMatch))
                    {
                        return(new AreaConsumptionResult(consumption, false, "Cannot build across map boundaries."
                                                         ));
                    }

                    var consumeAreaOperations = queryResults
                                                .Select(x => x
                                                        .QueryResult
                                                        .MatchingObject
                                                        .ConsumptionState
                                                        .TryConsumeWith(x.ConsumptionZoneMember)
                                                        )
                                                .ToArray();

                    if (consumeAreaOperations.All(x => x.CanOverrideWithResult.WillSucceed))
                    {
                        foreach (var consumeAreaOperation in consumeAreaOperations)
                        {
                            consumeAreaOperation.Apply();
                        }

                        return(new AreaConsumptionResult(consumption, true, consumeAreaOperations.First().Description));
                    }
                    return(new AreaConsumptionResult(consumption, false, string.Join(", ", consumeAreaOperations
                                                                                     .Where(x => !x.CanOverrideWithResult.WillSucceed)
                                                                                     .Select(x => x.Description)
                                                                                     .Distinct()
                                                                                     )
                                                     ));
                }
                throw new InvalidOperationException();
            }
        }
예제 #4
0
        public IAreaConsumptionResult ConsumeZoneAt(IReadOnlyZoneInfo readOnlyZoneInfo, IAreaConsumption consumption)
        {
            var result = ConsumeZoneAtPrivate(readOnlyZoneInfo, consumption);

            OnAreaConsumptionResult?.Invoke(this, new AreaConsumptionResultEventArgs(result));

            /*if (consumption is IAreaZoneClusterConsumption)
             * {
             *  foreach (
             *      var zoneInfo in
             *          (consumption as IAreaZoneClusterConsumption)
             *              .ZoneClusterMembers
             *              .Select(x => x.GetZoneInfo())
             *              .Where(x => x.HasMatch)
             *              .Select(x => x.MatchingObject))
             *  {
             *      ZoneInfoUpdated?.Invoke(this, new ZoneInfoEventArgs(zoneInfo));
             *
             *  }
             * }
             * else
             * {
             *  ZoneInfoUpdated?.Invoke(this, new ZoneInfoEventArgs(readOnlyZoneInfo));
             * }*/

            return(result);
        }
예제 #5
0
 public AreaConsumptionResult(IAreaConsumption areaConsumption, bool success, string message)
 {
     AreaConsumption = areaConsumption;
     Message         = message;
     Success         = success;
 }
예제 #6
0
        public IAreaConsumptionResult ConsumeZoneAt(IReadOnlyZoneInfo readOnlyZoneInfo, IAreaConsumption consumption)
        {
            if (_cityBudget.CurrentAmount < consumption.Cost && !_simulationOptions.ProcessOptions.GetIsMoneyCheatEnabled())
            {
                var insufficientFundsResult = new InsufficientFundsAreaConsumptionResult(consumption);
                RaiseAreaHotMessageEvent("Insufficient funds", insufficientFundsResult.Message);
                return(insufficientFundsResult);
            }

            var result = _area.ConsumeZoneAt(readOnlyZoneInfo, consumption);

            if (result.Success)
            {
                _cityBudget.Handle(result);
            }
            return(result);
        }