Пример #1
0
        public void ExportToMeta(ref AgentMeta agentMeta)
        {
            AgentMeta meta = agentMeta;

            meta.tag        = tag;
            meta.name       = name;
            meta.damage     = damage;
            meta.damageTime = damageTime;
            meta.num        = num;
            meta.speed      = speed;
            meta.health     = health;
            meta.defense    = defense;
            meta.level      = level;
            meta.cost       = cost;
            meta.gameObject = gameObject;
        }
Пример #2
0
        public DayMeta NextDay(ref Dictionary <string, GameObject> treeBook)
        {
            DayMeta nextDayMeta = new DayMeta();

            nextDayMeta.day = day + 1;
            // tree
            nextDayMeta.treeMeta = treeMeta;
            bool levelUpTree = false;

            for (int i = 0; i < nextDayMeta.treeMeta.Count; i++)
            {
                if (nextDayMeta.treeMeta [i].level < 6)
                {
                    nextDayMeta.treeMeta [i] = nextDayMeta.treeMeta [i].NextDay(ref treeBook);
                    levelUpTree = true;
                    break;
                }
            }
            if (!levelUpTree)
            {
                // add new tree
                AgentMeta meta = new AgentMeta();
                if (treeBook.ContainsKey("Tree Spirit 1"))
                {
                    treeBook ["Tree Spirit 1"].GetComponent <Agent> ().ExportToMeta(ref meta);
                    nextDayMeta.treeMeta.Add(meta);
                }
            }
            // spirit
            nextDayMeta.spiritMeta = spiritMeta;
            for (int i = 0; i < nextDayMeta.spiritMeta.Count; i++)
            {
                nextDayMeta.spiritMeta [i] = nextDayMeta.spiritMeta [i].NextDay();
            }
            // ghost
            nextDayMeta.ghostMeta = ghostMeta;
            for (int i = 0; i < nextDayMeta.ghostMeta.Count; i++)
            {
                nextDayMeta.ghostMeta [i] = nextDayMeta.ghostMeta [i].NextDay();
            }
            nextDayMeta.numOfSpirits = numOfSpirits + 6;
            nextDayMeta.numOfGhosts  = numOfGhosts + 8;
            return(nextDayMeta);
        }
Пример #3
0
        public AgentMeta NextDay()
        {
            AgentMeta nextAgentMeta = new AgentMeta();

            nextAgentMeta.tag        = tag;
            nextAgentMeta.name       = name;
            nextAgentMeta.damage     = damage;
            nextAgentMeta.damageTime = damageTime;
            nextAgentMeta.num        = num;
            nextAgentMeta.speed      = speed;
            nextAgentMeta.health     = health;
            nextAgentMeta.defense    = defense;
            nextAgentMeta.level      = level;
            nextAgentMeta.rate       = rate;
            nextAgentMeta.gameObject = gameObject;

            if (nextAgentMeta.tag == "Ghost")
            {
                nextAgentMeta.LevelUp(ref nextAgentMeta);
                nextAgentMeta.rate++;
            }

            return(nextAgentMeta);
        }
Пример #4
0
        public void Init()
        {
            trees.Clear();
            treeBook.Clear();
            spirits.Clear();
            spiritBook.Clear();
            ghosts.Clear();
            ghostBook.Clear();

            int index;

            // trees
            index = 1;
            foreach (GameObject tree in allTrees)
            {
                Agent agent = tree.GetComponent <Agent>();
                if (!treeBook.ContainsKey(agent.name))
                {
                    treeBook.Add(agent.name, agent.gameObject);
                    agent.id = index;
                    // agent.level = 1;
                    agent.agentManager = this;
                    trees.Add(agent);
                    index++;
                }
            }

            // spirits
            index = 1;
            foreach (GameObject spirit in allSpirits)
            {
                Agent agent = spirit.GetComponent <Agent>();
                if (!spiritBook.ContainsKey(agent.name))
                {
                    spiritBook.Add(agent.name, agent.gameObject);
                    agent.id = index;
                    // agent.level = 1;
                    agent.agentManager = this;
                    spirits.Add(agent);
                    index++;
                }
            }

            // ghosts
            index = 1;
            foreach (GameObject ghost in allGhosts)
            {
                Agent agent = ghost.GetComponent <Agent>();
                if (!ghostBook.ContainsKey(agent.name))
                {
                    ghostBook.Add(agent.name, agent.gameObject);
                    agent.id = index;
                    // agent.level = 1;
                    agent.agentManager = this;
                    ghosts.Add(agent);
                    index++;
                }
            }

            // dictionary
            dayMeta.Clear();

            // AgentMeta todaysTree = null;
            List <AgentMeta> todaysTrees   = new List <AgentMeta> ();
            List <AgentMeta> todaysSpirits = new List <AgentMeta> ();
            List <AgentMeta> todaysGhosts  = new List <AgentMeta> ();
            DayMeta          todaysMeta;
            AgentMeta        agentMeta;
            int day       = 0;
            int spiritNum = 0;
            int ghostNum  = 0;
            int lineNum   = 0;
            int lineIndex = 0;
            // string line;

            //-------start loading data
            TextAsset txt     = (TextAsset)Resources.Load("DayMeta", typeof(TextAsset));
            string    content = txt.text;

            string[] lines = Regex.Split(content, "\n|\r|\r\n");
            // StreamReader theReader = new StreamReader ("Assets/Data/DayMeta.txt", Encoding.Default);
            // using (theReader)
            // {
            // do
            // {
            // line = theReader.ReadLine();
            // if (line != null)
            // {
            foreach (string line in lines)
            {
                string[] entries = line.Split(',');
                if (entries.Length == 4)
                {
                    day       = int.Parse(entries [0]);
                    spiritNum = int.Parse(entries [1]);
                    ghostNum  = int.Parse(entries [2]);
                    lineNum   = int.Parse(entries [3]);
                    lineIndex = 0;
                    // todaysTree = null;
                    todaysTrees   = new List <AgentMeta> ();
                    todaysSpirits = new List <AgentMeta> ();
                    todaysGhosts  = new List <AgentMeta> ();
                }

                if (lineIndex < lineNum)
                {
                    if (entries.Length == 12)
                    {
                        lineIndex++;
                        if (day != int.Parse(entries [0]))
                        {
                            continue;
                        }
                        if (treeBook.ContainsKey(entries [2]))
                        {
                            agentMeta = new AgentMeta(entries [1], entries [2], entries [3], entries [4], entries [5], entries [6], entries [7], entries [8], entries [9], entries [10], entries [11], treeBook [entries [2]]);
                            agentMeta.ExportToPrefab();
                            agentMeta.ExportFromPrefab();
                            todaysTrees.Add(agentMeta);
                        }
                        if (spiritBook.ContainsKey(entries [2]))
                        {
                            agentMeta = new AgentMeta(entries [1], entries [2], entries [3], entries [4], entries [5], entries [6], entries [7], entries [8], entries [9], entries [10], entries [11], spiritBook [entries [2]]);
                            agentMeta.ExportToPrefab();
                            agentMeta.ExportFromPrefab();
                            todaysSpirits.Add(agentMeta);
                        }
                    }
                    if (entries.Length == 13)
                    {
                        lineIndex++;
                        if (day != int.Parse(entries [0]))
                        {
                            continue;
                        }
                        if (ghostBook.ContainsKey(entries [2]))
                        {
                            agentMeta = new AgentMeta(entries [1], entries [2], entries [3], entries [4], entries [5], entries [6], entries [7], entries [8], entries [9], entries [10], entries [11], ghostBook [entries [2]]);
                            agentMeta.ExportToPrefab();
                            agentMeta.ExportFromPrefab();
                            agentMeta.LevelUp(int.Parse(entries [12]));
                            todaysGhosts.Add(agentMeta);
                        }
                    }
                }

                if (lineIndex == lineNum)
                {
                    lineIndex++;
                    todaysMeta = new DayMeta(day, todaysTrees, todaysSpirits, todaysGhosts, spiritNum, ghostNum);
                    dayMeta.Add(todaysMeta);
                }
            }
            // }
            // }
            // while (line != null);
            // theReader.Close();
            //  }
            //-------finish loading data
        }
Пример #5
0
        public void LevelUp(ref AgentMeta meta)
        {
            if (meta.tag == "Ghost")
            {
                if (meta.defense != -1)
                {
                    meta.damage *= 1.1f;
                }

                if (meta.health != -1)
                {
                    meta.health *= 1.1f;
                }

                if (meta.defense != -1)
                {
                    meta.defense *= 1.05f;
                }

                if (meta.defense > 0.7f)
                {
                    meta.defense = 0.7f;
                }
            }

            if (meta.tag == "Spirit")
            {
                if (meta.defense != -1)
                {
                    meta.damage *= 1.1f;
                }

                if (meta.health != -1)
                {
                    meta.health *= 1.1f;
                }

                if (meta.defense != -1)
                {
                    meta.defense *= 1.05f;
                }

                if (meta.defense > 0.7f)
                {
                    meta.defense = 0.7f;
                }

                if (meta.cost != -1)
                {
                    meta.cost *= 2;
                }
            }

            if (meta.tag == "Tree")
            {
                if (meta.health != -1)
                {
                    meta.health += 40;
                }
            }

            meta.level += 1;

            ExportToPrefab();
        }