Пример #1
0
        public static void ServerInitCharacterTechnologies(PlayerCharacterTechnologies technologies)
        {
            foreach (var techGroup in FindProtoEntities <TechGroup>())
            {
                if (techGroup.GroupRequirements.Count > 0)
                {
                    continue;
                }

                // add free group
                technologies.ServerAddGroup(techGroup);

                foreach (var techNode in techGroup.RootNodes)
                {
                    ProcessNode(techNode);
                }
            }

            void ProcessNode(TechNode techNode)
            {
                if (techNode.LearningPointsPrice > 0)
                {
                    return;
                }

                // add free node
                technologies.ServerAddNode(techNode);

                foreach (var dependentNode in techNode.DependentNodes)
                {
                    ProcessNode(dependentNode);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// This method ensures that free tech groups are added automatically.
        /// </summary>
        private static void ServerEnsureFreeTechGroupsUnlocked(PlayerCharacterTechnologies technologies)
        {
            foreach (var techGroup in TechGroup.AvailableTechGroups)
            {
                if (techGroup.LearningPointsPrice > 0 ||
                    techGroup.GroupRequirements.Count > 0)
                {
                    continue;
                }

                technologies.ServerAddGroup(techGroup);
            }
        }
Пример #3
0
        public static void ServerInitCharacterTechnologies(PlayerCharacterTechnologies technologies)
        {
            var needToResetTheTechTree = false;
            var techNodes  = technologies.Nodes;
            var techGroups = technologies.Groups;

            for (var index = 0; index < techNodes.Count; index++)
            {
                var techNode = techNodes[index];
                if (!(techNode is null))
                {
                    continue;
                }

                // tech node not found
                needToResetTheTechTree = true;
                techNodes.RemoveAt(index);
                index--;
            }

            for (var index = 0; index < techGroups.Count; index++)
            {
                var techGroup = techGroups[index];
                if (!(techGroup is null))
                {
                    continue;
                }

                // tech group not found
                needToResetTheTechTree = true;
                techGroups.RemoveAt(index);
                index--;
            }

            if (needToResetTheTechTree)
            {
                ServerResetTechTreeAndRefundLearningPoints(technologies);
            }

            ServerEnsureFreeTechGroupsUnlocked(technologies);
        }
Пример #4
0
        public static void ServerResetTechTreeAndRefundLearningPoints(PlayerCharacterTechnologies technologies)
        {
            var lpToRefund = 0;

            foreach (var techNode in technologies.Nodes)
            {
                lpToRefund += techNode.LearningPointsPrice;
            }

            technologies.Nodes.Clear();

            foreach (var techGroup in technologies.Groups)
            {
                lpToRefund += techGroup.LearningPointsPrice;
            }

            technologies.Groups.Clear();

            technologies.ServerRefundLearningPoints(lpToRefund);
            technologies.IsTechTreeChanged = true;

            ServerEnsureFreeTechGroupsUnlocked(technologies);
        }
Пример #5
0
        public void Setup(PlayerCharacterPrivateState privateState)
        {
            TechGroupsChanged = null;
            TechNodesChanged  = null;

            this.technologies = privateState.Technologies;
            this.techGroups   = this.technologies.Groups;
            this.techNodes    = this.technologies.Nodes;

            this.technologies.ClientSubscribe(
                _ => _.LearningPoints,
                _ => LearningPointsChanged?.Invoke(),
                this);

            this.techGroups.ClientAnyModification += this.TechGroupsClientAnyModificationHandler;
            this.techNodes.ClientAnyModification  += this.TechNodesClientAnyModificationHandler;

            instance = this;

            CurrentTechnologiesChanged?.Invoke();
            TechGroupsChanged?.Invoke();
            TechNodesChanged?.Invoke();
            LearningPointsChanged?.Invoke();
        }