예제 #1
0
        public void SaveProgress()
        {
            serializer.SaveFileFromData(CreateDTO(), gameFiles.PlayerProgressFilePath);

            FullDTO CreateDTO()
            {
                FullDTO fullDTO = new FullDTO {
                    CurrentScenario = campaignRepository.CurrentScenario?.Id
                };

                foreach (Campaign campaign in campaignRepository.Campaigns)
                {
                    CampaignDTO campaignDTO = new CampaignDTO
                    {
                        Id            = campaign.Id,
                        State         = campaign.State,
                        FirstScenario = campaign.FirstScenario.Id
                    };
                    fullDTO.CampaignsList.Add(campaignDTO);
                }

                foreach (Investigator investigator in investigatorRepository.Investigators)
                {
                    InvestigatorDTO investigatorDTO = new InvestigatorDTO
                    {
                        Id           = investigator.Id,
                        PhysicTrauma = investigator.PhysicTrauma,
                        MentalTrauma = investigator.MentalTrauma,
                        Xp           = investigator.Xp,
                        IsPlaying    = investigator.IsPlaying,
                        IsRetired    = investigator.State == InvestigatorState.Retired
                    };

                    investigatorDTO.Deck           = investigator.CardsInDeckIds;
                    investigatorDTO.MandatoryCards = investigator.MandatoryCardsIds;
                    fullDTO.InvestigatorsList.Add(investigatorDTO);
                }

                fullDTO.InvestigatorsSelectedList = selectorRepository.InvestigatorsIdInSelector;
                fullDTO.UnlockCards = unlockCardsRepository.Serialize();
                return(fullDTO);
            }
        }
예제 #2
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));
                }
            }
        }