Esempio n. 1
0
        private void join(User user, AllianceMember rights = null)
        {
            this.members.Add(user);
            if (rights != null)
            {
                this.memberRights.Add(rights);
            }
            else
            {
                this.memberRights.Add(AllianceMember.noRights(user.id, this.id));
            }
            user.group      = this;
            user.allianceId = this.id;

            foreach (System.Collections.DictionaryEntry HashEntry in GeometryIndex.allFields)
            {
                Field fieldToSet = (Field)HashEntry.Value;

                if (fieldToSet.Influence.Count == 0)
                {
                    continue;
                }
                if (fieldToSet.Owner == user)
                {
                    fieldToSet.Entity = user.GetEntity();
                }
            }


            JoinSecondarySpecificationGain(user);
        }
Esempio n. 2
0
        private void leave(User user)
        {
            this.members.Remove(user);
            this.memberRights.RemoveAll(e => e.userId == user.id);
            user.group      = null;
            user.allianceId = 0;

            var allianceCommNode = CommunicationNode.GetAllianceNode(this);

            if (allianceCommNode != null)
            {
                allianceCommNode.commNodeUsers.TryRemove(user.id);
                Core.Instance.dataConnection.DeleteCommNodeUsers(allianceCommNode, user);
            }

            //remove his secondary trait from other members
            this.RemoveSecondarySpecificationGain(user);

            //remove ALL secondary traits from this user
            List <UserResearch> AllNewUserResearchs = new List <UserResearch>();

            foreach (var SpecGroup in Core.Instance.SpecializationGroups.Where(specGroup => specGroup.SpecializationResearches.Any(SpecResearch => SpecResearch.SecondaryResearchId != null)))
            {
                foreach (var SpecResearch in SpecGroup.SpecializationResearches)
                {
                    if (!user.PlayerResearch.Any(e => e.isCompleted == 1 && e.researchId == SpecResearch.SecondaryResearchId))
                    {
                        continue;
                    }
                    var PlayerResearch = user.PlayerResearch.First(e => e.researchId == SpecResearch.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);
                }
            }

            foreach (System.Collections.DictionaryEntry HashEntry in GeometryIndex.allFields)
            {
                Field fieldToSet = (Field)HashEntry.Value;

                if (fieldToSet.Influence.Count == 0)
                {
                    continue;
                }
                if (fieldToSet.Owner == user)
                {
                    fieldToSet.Entity = user.GetEntity();
                }
            }
        }