Exemplo n.º 1
0
        private void setAvailableMinionsOfPlayer()
        {
            Type root = null;

            switch (PlayerMe.self.board.scienceType)
            {
            case ScienceType.PHYS:
                root = typeof(PhysicsMinion);
                break;

            case ScienceType.CHEM:
                root = typeof(ChemistryMinion);
                break;

            case ScienceType.BIO:
                root = typeof(BiologyMinion);
                break;
            }

            PlayerMe.availableMinionTypes = new List <Type>();
            for (int i = 0; i < UserMe.unlockedMinions.Length; i++)
            {
                if (UserMe.unlockedMinions[i])
                {
                    Type       minionType = TypeIdGenerator.getMinionType(i);
                    MinionNode minionNode = TypeIdGenerator.getMinionNodeInsts(minionType);
                    if (UserMe.unlockedMinions[i] && minionNode.parent != null && minionNode.parent.minionType == root)
                    {
                        PlayerMe.availableMinionTypes.Add(minionType);
                    }
                }
            }
        }
        private bool checkIfMinionUpgradableTo(int currentMinionTypeId, Type upgradedMinionType)
        {
            MinionNode tn = TypeIdGenerator.getMinionNodeInst(upgradedMinionType);

            if (tn == null)
            {
                return(false);
            }

            return(tn.checkParent(currentMinionTypeId) != null);
        }
Exemplo n.º 3
0
        private static Dictionary <Type, MinionNode> generateInheritanceMinionTreeHashMap <T>()
        {
            Dictionary <Type, MinionNode> resultDictionary = new Dictionary <Type, MinionNode>();
            Type type = typeof(T);

            var types = AppDomain.CurrentDomain.GetAssemblies()
                        .SelectMany(s => s.GetTypes())
                        .Where(p => type.IsAssignableFrom(p) && p.IsClass && !p.IsAbstract);

            var abstypes = AppDomain.CurrentDomain.GetAssemblies()
                           .SelectMany(s => s.GetTypes())
                           .Where(p => type.IsAssignableFrom(p) && p.IsClass && p.IsAbstract);

            List <Type> abstTypes = new List <Type>();

            foreach (Type t in abstypes)
            {
                abstTypes.Add(t);
            }


            List <Type>       typeList     = new List <Type>();
            List <Type>       typeNodes    = new List <Type>();
            List <Type>       nextTypes    = new List <Type>();
            List <Type>       removeList   = new List <Type>();
            List <MinionNode> currentNodes = new List <MinionNode>();
            List <MinionNode> nextNodes    = new List <MinionNode>();

            foreach (Type t in abstTypes)
            {
                MinionNode newNode = new MinionNode();
                newNode.minionType = t;
                newNode.parent     = null;
                currentNodes.Add(newNode);
                typeNodes.Add(t);
            }


            foreach (Type t in types)
            {
                typeList.Add(t);
            }

            for (int i = 0; i < abstTypes.Count; i++)
            {
                if (abstTypes[i] != type)
                {
                    resultDictionary.Add(abstTypes[i], currentNodes[i]);
                }
            }

            while (typeList.Count > 0)
            {
                for (int j = 0; j < typeNodes.Count; j++)
                {
                    for (int i = 0; i < typeList.Count; i++)
                    {
                        if (typeList[i].BaseType == typeNodes[j])
                        {
                            MinionNode newNode = new MinionNode();
                            newNode.minionType = typeList[i];
                            newNode.parent     = currentNodes[j];
                            currentNodes[j].children.Add(newNode);

                            nextNodes.Add(newNode);
                            nextTypes.Add(typeList[i]);

                            resultDictionary.Add(typeList[i], newNode);

                            removeList.Add(typeList[i]);
                        }
                    }
                }

                foreach (Type t in removeList)
                {
                    typeList.Remove(t);
                }
                removeList.Clear();

                currentNodes.Clear();
                currentNodes.AddRange(nextNodes);
                nextNodes.Clear();


                typeNodes.Clear();
                typeNodes.AddRange(nextTypes);
                nextTypes.Clear();
            }


            return(resultDictionary);
        }