Пример #1
0
        private IList <Item> ProcessOneAdvancedTarget(Character character, MissionTargetInProgress missionTargetInProgress, MissionInProgress missionInProgress, ref bool wasGroupFinished, IDictionary <string, object> info)
        {
            var    gangResultCommand = Commands.MissionTargetUpdate;
            string gangResultMessage = null;


            if (missionTargetInProgress.completed)
            {
                //extract success location
                missionTargetInProgress.GetSuccessInfo(info);
                missionTargetInProgress.WriteSuccessInfo();
                gangResultCommand = Commands.MissionTargetCompleted;
                gangResultMessage = missionTargetInProgress.myTarget.completedMessage;
            }

            //progress occured => save target anyway
            missionTargetInProgress.WriteMissionTargetToSql().ThrowIfError();

            if (missionTargetInProgress.IsBranchNeeded())
            {
                Logger.Info(">>> target is branching " + missionTargetInProgress);

                //ha lefutott, akkor kell ennek taskban elindulnia egy masik tranzakcioban
                Transaction.Current.OnCommited(() => { StartAsync(character, missionInProgress.spreadInGang, missionTargetInProgress.myTarget.BranchMissionId, missionInProgress.myLocation, missionInProgress.MissionLevel); });

                wasGroupFinished = true;
            }
            else
            {
                // Default behaviour
                missionInProgress.TryAdvanceTargetGroup(ref wasGroupFinished).ThrowIfError();
            }

            if (missionInProgress.ExtractDoerCharacter(info, out Character doerCharacter))
            {
                missionInProgress.AddParticipant(doerCharacter);
            }
            else
            {
                doerCharacter = character; //proper eventsource
            }

            var rewarditems = TryFinishMission(missionInProgress);

            Logger.Info("mission advanced! characterID:" + character.Id + " missionID:" + missionInProgress.MissionId + " targetId:" + missionTargetInProgress.MissionTargetId + " completed:" + missionTargetInProgress.completed);

            Transaction.Current.OnCommited(() =>
            {
                var statusInfo = missionInProgress.PrepareInfoDictionary(message: gangResultMessage, sourceCharacterId: doerCharacter.Id);
                missionTargetInProgress.PrepareInfoDictionary(statusInfo);

                missionTargetInProgress.SendTargetStatusToGangAsync(gangResultCommand, statusInfo);
            });

            return(rewarditems);
        }
Пример #2
0
        private void ProcessAdvamcementForOneTarget(MissionTargetInProgress missionTargetInProgress, MissionInProgress missionInProgress, IDictionary <string, object> info, bool isComplete)
        {
            Logger.Info("processing " + missionTargetInProgress + " for " + missionInProgress);

            var ec         = ErrorCodes.NoError;
            var targetType = missionTargetInProgress.TargetType;
            var character  = missionInProgress.character;

            //this character completed the target.
            //note: Partial progress doesn't trigger this
            //for the toast in the client

            if (missionInProgress.ExtractDoerCharacter(info, out Character doerCharacter))
            {
                Logger.Info("    >>>> ASSISTED COMPLETE. characterId:" + doerCharacter.Id + " is helped characterID:" + character.Id + " " + missionTargetInProgress.TargetType + " " + missionInProgress.missionGuid);
            }

            switch (targetType)
            {
            case MissionTargetType.loot_item:

                var lootItemsCount = info.GetOrDefault <int>(k.progressCount);
                ec = missionTargetInProgress.AdvanceTarget_LootItem(isComplete, lootItemsCount);
                break;

            case MissionTargetType.kill_definition:

                if (info.ContainsKey(k.increase))
                {
                    ec = missionTargetInProgress.AdvanceTarget_KillDefinition_IncreaseOnly();
                    break;
                }

                var killDefinitionCount = info.GetOrDefault <int>(k.progressCount);
                ec = missionTargetInProgress.AdvanceTarget_KillDefinition(isComplete, killDefinitionCount);
                break;

            case MissionTargetType.reach_position:

                ec = missionTargetInProgress.AdvanceTarget_ReachPosition();
                break;

            case MissionTargetType.scan_mineral:

                ec = missionTargetInProgress.AdvanceTarget_ScanMineral();
                break;

            case MissionTargetType.scan_unit:

                var scanCount = info.GetOrDefault <int>(k.progressCount);
                ec = missionTargetInProgress.AdvanceTarget_ScanUnit(isComplete, scanCount);
                break;

            case MissionTargetType.scan_container:
                var foundInContainer = info.GetOrDefault <int>(k.progressCount);
                ec = missionTargetInProgress.AdvanceTarget_ScanContainer(isComplete, foundInContainer);
                break;

            case MissionTargetType.drill_mineral:
                var drilledAmount = info.GetOrDefault <int>(k.progressCount);
                ec = missionTargetInProgress.AdvanceTarget_MineralDrilled(isComplete, drilledAmount);
                break;

            case MissionTargetType.submit_item:
                var wasInContainer = info.GetOrDefault <int>(k.progressCount);
                ec = missionTargetInProgress.AdvanceTarget_SubmitItem(isComplete, wasInContainer);
                break;

            case MissionTargetType.use_switch:
                ec = missionTargetInProgress.AdvanceTarget_Alarm();
                break;

            case MissionTargetType.find_artifact:
                ec = missionTargetInProgress.AdvanceTarget_FindArtifact();
                break;

            case MissionTargetType.dock_in:
                var zoneId   = info.GetOrDefault <int>(k.zoneID);
                var position = info.GetOrDefault <Position>(k.position);
                ec = missionTargetInProgress.AdvanceTarget_DockIn(position, zoneId);
                break;

            case MissionTargetType.use_itemsupply:
                var itemCount = info.GetOrDefault <int>(k.progressCount);
                ec = missionTargetInProgress.AdvanceTarget_ItemSupply(isComplete, itemCount);
                break;

            case MissionTargetType.massproduce:

                //needs ct and goes for the produced definition

                var producedDefinition = info.GetOrDefault <int>(k.definition);
                var quantity           = info.GetValue <int>(k.quantity);
                ec = missionTargetInProgress.AdvanceTarget_MassProduce(producedDefinition, quantity, info);
                break;

            case MissionTargetType.prototype:

                //not used

                var protoDefinition = info.GetOrDefault <int>(k.definition);
                ec = missionTargetInProgress.AdvanceTarget_Prototype(protoDefinition);
                break;

            case MissionTargetType.research:

                //needs decoder and goes for the resulting definition -> ct definition

                var researchedDefinition = info.GetOrDefault <int>(k.definition);
                ec = missionTargetInProgress.AdvanceTarget_Research(researchedDefinition, info);
                break;

            case MissionTargetType.teleport:
                var channelId = info.GetOrDefault <int>(k.channel);
                ec = missionTargetInProgress.AdvanceTarget_Teleport(channelId);
                break;

            case MissionTargetType.harvest_plant:
                var harvestedAmount = info.GetOrDefault <int>(k.progressCount);
                ec = missionTargetInProgress.AdvanceTarget_MineralHarvested(isComplete, harvestedAmount);
                break;

            case MissionTargetType.summon_npc_egg:
                var currentProgress = info.GetOrDefault <int>(k.progressCount);
                ec = missionTargetInProgress.AdvanceTarget_SummonNPCEgg(isComplete, currentProgress);
                break;

            case MissionTargetType.pop_npc:
                ec = missionTargetInProgress.AdvanceTarget_PopNpc();
                break;

            case MissionTargetType.fetch_item:

                var quantityFetched = info.GetOrDefault <int>(k.progressCount);
                var location        = info.GetOrDefault <int>(k.location);
                ec = missionTargetInProgress.AdvanceTarget_FetchItem(isComplete, quantityFetched, location);
                break;

            case MissionTargetType.lock_unit:
                var lockedUnitCount = info.GetOrDefault <int>(k.progressCount);
                var lockedNpcEids   = info.GetOrDefault <long[]>("lockedUnits");
                ec = missionTargetInProgress.AdvanceTarget_LockUnit(isComplete, lockedUnitCount, lockedNpcEids);
                break;
            }

            if (ec == ErrorCodes.NothingToDo)
            {
                Logger.Info("Nothing to do exiting " + missionTargetInProgress);
                return;
            }

            ec.ThrowIfError();

            using (var scope = Db.CreateTransaction())
            {
                try
                {
                    var wasGroupFinished = false;
                    ProcessOneAdvancedTarget(character, missionTargetInProgress, missionInProgress, ref wasGroupFinished, info);
                    info[k.wasProgress] = 1; //signal progress to out functions
                    scope.Complete();
                }
                catch (Exception ex)
                {
                    Logger.Exception(ex);
                }
            }
        }