示例#1
0
        public void LoadProgress()
        {
            FullDTO repositoryDTO = applicationValues.CanContinue ? ContinueData() : NewGameData();

            LoadCampaigns(repositoryDTO.CampaignsList, repositoryDTO.CurrentScenario);
            LoadInvestigators(repositoryDTO.InvestigatorsList);
            LoadSelectors(repositoryDTO.InvestigatorsSelectedList);
            LoadUnlockCards(repositoryDTO.UnlockCards);

            FullDTO NewGameData() => serializer.CreateDataFromResources <FullDTO>(gameFiles.PlayerProgressDefaultFilePath);
            FullDTO ContinueData() => serializer.CreateDataFromFile <FullDTO>(gameFiles.PlayerProgressFilePath);

            void LoadCampaigns(IEnumerable <CampaignDTO> campaigns, string currentScenario)
            {
                campaignRepository.Reset();
                foreach (CampaignDTO campaign in campaigns)
                {
                    Campaign newCampaing = new Campaign
                    {
                        Id            = campaign.Id,
                        State         = campaign.State,
                        FirstScenario = factory.CreateInstance <Scenario>(campaign.FirstScenario)
                    };
                    campaignRepository.Add(newCampaing);
                    campaignRepository.SetScenario(factory.CreateInstance <Scenario>(currentScenario));
                }
            }

            void LoadInvestigators(IEnumerable <InvestigatorDTO> investigators)
            {
                investigatorRepository.Reset();
                foreach (InvestigatorDTO investigator in investigators)
                {
                    Investigator newInvestigator = new Investigator(
                        investigator.PhysicTrauma,
                        investigator.MentalTrauma,
                        investigator.Xp,
                        investigator.IsPlaying,
                        investigator.IsRetired,
                        cardRepository.Get(investigator.Id),
                        factory.CreateInstance <DeckBuildingRules>(investigator.Id)
                        );

                    investigator.MandatoryCards.ForEach(card => newInvestigator.AddToMandatory(cardRepository.Get(card)));
                    investigator.Deck.ForEach(card => newInvestigator.AddToDeck(cardRepository.Get(card)));
                    investigatorRepository.Add(newInvestigator);
                }
            }

            void LoadUnlockCards(IEnumerable <string> unlockCards)
            {
                unlockCardsRepository.Reset();
                foreach (string cardId in unlockCards)
                {
                    unlockCardsRepository.Add(cardRepository.Get(cardId));
                }
            }

            void LoadSelectors(IEnumerable <string> investigatorsSelected)
            {
                selectorRepository.Reset();
                foreach (string investigatorId in investigatorsSelected)
                {
                    selectorRepository.Add(investigatorRepository.Get(investigatorId));
                }
            }
        }