Esempio n. 1
0
        /// <summary>
        /// Multideliver
        ///     Collects all deliverable targets and tries to look up the items they require
        /// </summary>
        public void DeliverMissionByRequest(Character character, int locationId = 0)
        {
            Logger.Info("++ Deliver targets begins. characterId:" + character.Id);

            //var deliveryState = DeliverResult.nothingHappened;

            //get the affected characters from the gang
            var charactersToProcess = GetGangMembersCached(character);

            var isDocked = character.IsDocked;

            MissionLocation location;

            if (isDocked)
            {
                location = _missionDataCache.GetLocationByEid(character.CurrentDockingBaseEid);
            }
            else
            {
                //ok, let's use the optional parameter
                locationId.ThrowIfEqual(0, ErrorCodes.WTFErrorMedicalAttentionSuggested);

                if (!_missionDataCache.GetLocationById(locationId, out location))
                {
                    throw new PerpetuumException(ErrorCodes.InvalidMissionLocation);
                }
            }

            //safety
            location.ThrowIfNull(ErrorCodes.WTFErrorMedicalAttentionSuggested);

            var interestingTargets = new List <MissionTargetInProgress>();

            //let's collect the targets
            foreach (var processedCharacter in charactersToProcess)
            {
                if (MissionAdministrator.RunningMissionsCount(processedCharacter) == 0)
                {
                    continue;
                }

                MissionInProgressCollector collector;
                if (MissionAdministrator.GetMissionInProgressCollector(processedCharacter, out collector))
                {
                    foreach (var mip in collector.GetMissionsInProgress())
                    {
                        if (mip.IsMissionFinished)
                        {
                            continue;
                        }

                        interestingTargets.AddRange(mip.CollectTargetsWithDefinitionsToDeliverInCurrentState(location));
                    }
                }
            }

            DeliverMissionByTargetList(interestingTargets, character, location);
        }
        public void AbortMissionByRequest(Character character, Guid missionGuid, ErrorCodes errorToInfo)
        {
            Logger.Info("Aborting mission " + missionGuid + " character: " + character.Id);

            (MissionAdministrator.RunningMissionsCount(character) == 0).ThrowIfTrue(ErrorCodes.ItemNotFound);

            MissionInProgress missionInProgress;

            MissionAdministrator.FindMissionInProgressByMissionGuid(character, missionGuid, out missionInProgress).ThrowIfFalse(ErrorCodes.ItemNotFound);

            missionInProgress?.OnMissionAbort(this, errorToInfo);
        }
Esempio n. 3
0
        /// <summary>
        ///     Deliver items to a single mission
        /// </summary>
        public void DeliverSingleMission(Character character, Guid missionGuid, int locationId = 0)
        {
            Logger.Info($"++ Deliver starts for character:{character} missionGuid:{missionGuid}");

            var isDocked = character.IsDocked;

            MissionLocation location;

            if (isDocked)
            {
                location = _missionDataCache.GetLocationByEid(character.CurrentDockingBaseEid);
            }
            else
            {
                //ok, let's use the optional parameter
                locationId.ThrowIfEqual(0, ErrorCodes.WTFErrorMedicalAttentionSuggested);

                if (!_missionDataCache.GetLocationById(locationId, out location))
                {
                    throw new PerpetuumException(ErrorCodes.InvalidMissionLocation);
                }
            }

            //safety
            location.ThrowIfNull(ErrorCodes.WTFErrorMedicalAttentionSuggested);

            //get the affected characters from the gang
            var charactersToProcess = GetGangMembersCached(character);

            MissionInProgress missionInProgress = null;

            //let's collect the targets
            foreach (var processedCharacter in charactersToProcess)
            {
                if (MissionAdministrator.RunningMissionsCount(processedCharacter) == 0)
                {
                    continue;
                }

                MissionInProgressCollector collector;
                if (MissionAdministrator.GetMissionInProgressCollector(processedCharacter, out collector))
                {
                    foreach (var mip in collector.GetMissionsInProgress())
                    {
                        if (mip.missionGuid == missionGuid)
                        {
                            missionInProgress = mip;
                            break;
                        }
                    }
                }
            }

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

            if (missionInProgress == null)
            {
                // mission was not found
                Message.Builder.SetCommand(Commands.MissionDeliver)
                .WithError(ErrorCodes.MissionNotFound)
                .ToCharacter(character)
                .Send();
                return;
            }

            if (missionInProgress.IsMissionFinished)
            {
                Message.Builder.SetCommand(Commands.MissionDeliver)
                .WithError(ErrorCodes.MissionAlreadyDone)
                .ToCharacter(character)
                .Send();
                return;
            }

            var interestingTargets = missionInProgress.CollectTargetsWithDefinitionsToDeliverInCurrentState(location).ToList();

            DeliverMissionByTargetList(interestingTargets, character, location);
        }