Exemplo n.º 1
0
        public List <SpacegameServer.Core.UserResearch> getPlayerResearch()
        {
            List <SpacegameServer.Core.UserResearch> researches = new List <UserResearch>();

            foreach (var research in Core.Instance.Researchs.Where(e => e != null))
            {
                UserResearch existingData = null;
                if (PlayerResearch.Any(pr => pr.researchId == research.id))
                {
                    existingData = PlayerResearch.First(pr => pr.researchId == research.id);
                }

                UserResearch userResearch = new UserResearch();
                userResearch.researchId = research.id;
                userResearch.userId     = this.id;
                //take data from existingData if possible
                userResearch.researchable = existingData != null ? existingData.researchable :
                                            (this.canResearch(research) ? (byte)1 : (byte)0);
                userResearch.isCompleted =
                    existingData != null ? existingData.isCompleted : (byte)0;
                userResearch.investedResearchpoints =
                    existingData != null ? existingData.investedResearchpoints : 0;
                userResearch.researchPriority =
                    existingData != null ? existingData.researchPriority : (short)0;

                researches.Add(userResearch);
            }

            return(researches);
        }
Exemplo n.º 2
0
        public void AddSecondarySpecificationGain(Research research)
        {
            if (!research.IsSpecification())
            {
                return;
            }
            var SpecData = research.GetSpecification();

            if (SpecData.SecondaryResearchId == null)
            {
                return;
            }

            List <UserResearch> AllNewUserResearchs = new List <UserResearch>();

            //Add to players having neither first nor second research
            var UserToUpdate = Core.Instance.users.Values.Where(user => user.allianceId == this.id && !user.PlayerResearch.Any(userResearch => userResearch.isCompleted == 1 && (userResearch.researchId == SpecData.ResearchId || userResearch.researchId == SpecData.SecondaryResearchId)));

            foreach (var User in UserToUpdate)
            {
                UserResearch NewUserResearch;
                if (User.PlayerResearch.Any(userResearch => userResearch.isCompleted == 1 && (userResearch.researchId == SpecData.ResearchId || userResearch.researchId == SpecData.SecondaryResearchId)))
                {
                    NewUserResearch = User.PlayerResearch.First(userResearch => userResearch.isCompleted == 1 && (userResearch.researchId == SpecData.ResearchId || userResearch.researchId == SpecData.SecondaryResearchId));
                }
                else
                {
                    NewUserResearch = new UserResearch(User.id, (short)SpecData.SecondaryResearchId);
                }

                NewUserResearch.isCompleted = 1;
                NewUserResearch.research    = research;
                User.PlayerResearch.Add(NewUserResearch);
                AllNewUserResearchs.Add(NewUserResearch);
            }

            if (AllNewUserResearchs.Count > 0)
            {
                try
                {
                    Core.Instance.dataConnection.SaveResearch(AllNewUserResearchs);
                }
                catch (Exception ex)
                {
                    SpacegameServer.Core.Core.Instance.writeExceptionToLog(ex);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// called after a user left the alliance, checks if some senodary gains should be removed
        /// </summary>
        /// <param name="user"></param>
        public void RemoveSecondarySpecificationGain(User user)
        {
            //check if the user has a research that is the primary research from a specResearch with a secondary research
            if (!user.PlayerResearch.Any(e =>
                                         e.isCompleted == 1 &&
                                         Core.Instance.SpecializationGroups.Any(specGroup => specGroup.SpecializationResearches.Any(SpecResearch => SpecResearch.ResearchId == e.researchId && SpecResearch.SecondaryResearchId != null))))
            {
                return;
            }

            UserResearch PrimaryResearch = user.PlayerResearch.First(e => e.isCompleted == 1 && Core.Instance.SpecializationGroups.Any(specGroup => specGroup.SpecializationResearches.Any(SpecResearch => SpecResearch.ResearchId == e.researchId && SpecResearch.SecondaryResearchId != null)));

            //if someone in the alliance yet has the research, skip...
            if (Core.Instance.users.Values.Any(e => e.allianceId == this.id && e.PlayerResearch.Any(userResearch => userResearch.researchId == PrimaryResearch.researchId && userResearch.isCompleted == 1)))
            {
                return;
            }

            //now remove all Secondary gains of this research:
            short SecondaryResearchId = (short)PrimaryResearch.research.GetSpecification().SecondaryResearchId;

            List <UserResearch> AllNewUserResearchs = new List <UserResearch>();
            var UserToUpdate = Core.Instance.users.Values.Where(u => u.allianceId == this.id && u.PlayerResearch.Any(userResearch => userResearch.researchId == SecondaryResearchId && userResearch.isCompleted == 1));

            foreach (var User in UserToUpdate)
            {
                var PlayerResearch = User.PlayerResearch.First(e => e.researchId == SecondaryResearchId && e.isCompleted == 1);
                PlayerResearch.isCompleted = 0;
                AllNewUserResearchs.Add(PlayerResearch);
            }

            if (AllNewUserResearchs.Count > 0)
            {
                try
                {
                    Core.Instance.dataConnection.SaveResearch(AllNewUserResearchs);
                }
                catch (Exception ex)
                {
                    SpacegameServer.Core.Core.Instance.writeExceptionToLog(ex);
                }
            }
        }