public void InitDay(int day)
        {
            endDay = false;

            DeleteExit();

            PlaceMoon(day);

            dayMeta = agentManager.GetDayMeta(day);

            if (dayMeta != null)
            {
                rollTotal = 0;
                if (curtain.activeSelf)
                {
                    curtain.SetActive(false);
                }
                SetupUI.SetActive(true);
                SetupUI.transform.Find("Text").GetComponent <Text> ().text = "DAY " + day;
                todaysSpirits    = dayMeta.spiritMeta;
                todaysGhosts     = dayMeta.ghostMeta;
                todaysTrees      = dayMeta.treeMeta;
                numOfSpirits     = dayMeta.numOfSpirits;
                numOfGhosts      = dayMeta.numOfGhosts;
                numOfSpiritsLeft = numOfSpirits;
                numOfGhostsLeft  = numOfGhosts;

                if (todaysSpirits != null && todaysSpirits.Count > 0)
                {
                    for (int i = 0; i < todaysSpirits.Count; i++)
                    {
                        if (agentManager.spiritBook.ContainsKey(todaysSpirits[i].name))
                        {
                            agentManager.spiritBook [todaysSpirits[i].name].GetComponent <Agent> ().ExportToMeta(ref todaysSpirits, i);
                            if (i == 0)
                            {
                                minCost = todaysSpirits[0].cost;
                            }
                            else
                            {
                                minCost = Mathf.Min(minCost, todaysSpirits[i].cost);
                            }
                        }
                    }
                }

                if (exp >= minCost)
                {
                    StartCoroutine(StartState(States.UPGRADE, 3f));
                }
                else
                {
                    next_state = States.SETUP;
                }
            }
            else
            {
                // no more day to setup
            }
        }
예제 #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 DayMeta GetDayMeta(int day)
        {
            if (day < 0)
            {
                return(null);
            }

            if (day > dayMeta.Count)
            {
                while (dayMeta.Count < day)
                {
                    DayMeta lastdayMeta = dayMeta [dayMeta.Count - 1];
                    DayMeta todaysMeta  = lastdayMeta.NextDay(ref treeBook);
                    dayMeta.Add(todaysMeta);
                }
            }

            return(dayMeta [day - 1]);
        }
예제 #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
        }