예제 #1
0
파일: CBattleUI.cs 프로젝트: AllenGX/Design
    // Update is called once per frame
    void Update()
    {
        if (!m_IsPlay)
        {
            //输入命令阶段
            if (m_NowInputNum == 4)                 //结算阶段
            {
                m_IsOver = SendToControl();         //发送信息,结算数据
                //Debug.Log("SendToControl " + m_IsOver);
                if (m_IsOver == -2)                 //三个人命令未输完
                {
                    Init(m_NowPlayerID + 1);
                }
                else                                //数完后开始准备播放,更新数据
                {
                    m_FlyBloodPlay.Clear();
                    m_AniPlay.Clear();
                    m_IsPlay = true;
                    float now = 0f;
                    m_AniStartTime = Time.time;
                    foreach (GameInfo info in gameControl.gameInfo)         //计算时间
                    {
                        //info.PrintInfo();
                        int ObjID  = info.ObjID;             //技能帧数获得,还没有写
                        int PlayID = ObjID;
                        if (PlayID < 50)
                        {
                            PlayID = 0;
                        }
                        // 道具部分全部转为负数
                        // 默认技能伤害是正数
                        if (info.InjuryInfo.Count == 0)
                        {
                            continue;
                        }

                        //for(int i=0;i<info.InjuryInfo.Count;i++){
                        //    for(int j=0;j<info.InjuryInfo[i].Count;j++){
                        //        if(ObjID==0){
                        //            //info.InjuryInfo[i][j].Injuty=-info.InjuryInfo[i][j].Injuty;
                        //        }
                        //    }
                        //}


                        AniFactory af = new AniFactory();
                        //Debug.Log(af.ToString() + " " + ObjID);
                        //Debug.Log(af.aniDicts.ToString());
                        Dictionary <string, List <string> > nowSkillPlay = null;
                        nowSkillPlay = af.aniDicts[PlayID];



                        //Debug.Log(nowSkillPlay);
                        if (nowSkillPlay == null)
                        {
                            continue;
                        }
                        bool flag1 = false;
                        for (int i = 0; i < info.InjuryInfo.Count; i++)
                        {
                            for (int j = 0; j < info.InjuryInfo[i].Count; j++)
                            {
                                flag1 = true;
                            }
                        }
                        if (!flag1)
                        {
                            continue;
                        }
                        foreach (string skillpath in nowSkillPlay["我方"])
                        {
                            AniInfo aniInfo = af.aniDict[skillpath];
                            m_AniPlay.Add(now, new AniInformation(info.CasterPos, 0, skillpath));      //技能播放名字获得,还没有写

                            float iMusicTime = GetMusicTime(skillpath);
                            if (GetMusicTime(skillpath) != 0)
                            {
                                m_MusicPlay.Add(now, skillpath);
                            }
                            now += 0.05f * aniInfo.AniCount;
                            now += 1;
                        }
                        for (int i = 0; i < info.InjuryInfo.Count; i++)
                        {
                            bool flag = true;
                            for (int j = 0; j < info.InjuryInfo[i].Count; j++)
                            {
                                foreach (string skillpath in af.aniDicts[PlayID]["敌方"])
                                {
                                    float iMusicTime = GetMusicTime(skillpath);
                                    if (GetMusicTime(skillpath) != 0 && flag)
                                    {
                                        m_MusicPlay.Add(now, skillpath);

                                        flag = false;
                                    }
                                    m_AniPlay.Add(now, new AniInformation(info.CasterPos, info.InjuryInfo[i][j].TargetPos, skillpath));      //技能播放名字获得,还没有写
                                    now += 0.05f;
                                }
                                m_FlyBloodPlay.Add(now, info.InjuryInfo[i][j]);
                            }
                            if (af.aniDicts[PlayID]["敌方"].Count > 0)
                            {
                                AniInfo aniInfo = af.aniDict[af.aniDicts[PlayID]["敌方"][0]];
                                now += 0.05f * aniInfo.AniCount;
                            }
                            now += 1.5f;    //飙血时间延迟1.5s
                        }
                        now += 0.5f;
                        //for (int i = 0; i < info.InjuryInfo.Count; i++)
                        //{
                        //    for (int j = 0; j < info.InjuryInfo[i].Count; j++)
                        //    {
                        //        m_FlyBloodPlay.Add(now, info.InjuryInfo[i][j]);
                        //        now += 0.05f;
                        //    }
                        //    now += 1f;
                        //}
                    }
                }
            }
        }
        else
        {
            //动画播放阶段,每一帧去扫所有播放字典,时间到的既能播放,后从字典删除
            if (m_NowInputNum == 4)
            {
                List <float> tamplist = new List <float>();
                foreach (float key in m_FlyBloodPlay.Keys)
                {
                    if (key < Time.time - m_AniStartTime)
                    {
                        //Debug.Log(m_FlyBloodPlay[key].TargetPos.ToString() + " " + m_FlyBloodPlay[key].Injuty.ToString());
                        FlyBloodPlay(m_FlyBloodPlay[key].TargetPos, m_FlyBloodPlay[key].Injuty);
                        m_DataShowUI.GetComponent <CBattleShow>().Refresh();

                        m_self.GetComponent <CWarriorObj>().AtkBloodByLocal(m_FlyBloodPlay[key].TargetPos, m_FlyBloodPlay[key].Injuty);
                        //Debug.Log(" "+ m_self.GetComponent<CWarriorObj>().GetScrollbar(m_FlyBloodPlay[key].TargetPos).IsDie() + " Refresh(m_FlyBloodPlay[key].TargetPos)" + m_FlyBloodPlay[key].TargetPos);
                        if (m_self.GetComponent <CWarriorObj>().GetScrollbar(m_FlyBloodPlay[key].TargetPos).IsDie())
                        {
                            m_self.GetComponent <CWarriorObj>().Refresh(m_FlyBloodPlay[key].TargetPos);
                        }
                        tamplist.Add(key);
                    }
                }

                foreach (float key in m_MusicPlay.Keys)
                {
                    if (key < Time.time - m_AniStartTime)
                    {
                        //Debug.Log(m_MusicPlay[key].ToString());

                        PlayMusic(m_MusicPlay[key]);
                        tamplist.Add(key);
                    }
                }


                foreach (float key in m_AniPlay.Keys)
                {
                    if (key < Time.time - m_AniStartTime)
                    {
                        //Debug.Log(m_AniPlay[key].Casterlocal.ToString() + " " + m_AniPlay[key].Targetlocal.ToString() + " " + m_AniPlay[key].AniName1.ToString());
                        PlayAni(m_AniPlay[key].Casterlocal, m_AniPlay[key].Targetlocal, m_AniPlay[key].AniName1);
                        tamplist.Add(key);
                    }
                }

                foreach (float key in tamplist)
                {
                    if (m_FlyBloodPlay.ContainsKey(key))
                    {
                        m_FlyBloodPlay.Remove(key);
                    }
                    if (m_AniPlay.ContainsKey(key))
                    {
                        m_AniPlay.Remove(key);
                    }
                    if (m_MusicPlay.ContainsKey(key))
                    {
                        m_MusicPlay.Remove(key);
                    }
                }
                //int IsOver = gameControl.GameStart(ref startTime);


                if (m_FlyBloodPlay.Count == 0 && m_AniPlay.Count == 0)  //技能播放完毕,更新数据,这里血条才会更新,没能随着播放动画更新
                {
                    m_IsPlay = false;

                    m_NowInputNum = 0;
                    m_DataShowUI.GetComponent <CBattleShow>().Refresh();
                    playDieAni();
                    //m_self.GetComponent<CWarriorObj>().Refresh();
                    m_self.GetComponent <CWarriorObj>().RefreshBuff();

                    if (m_IsOver == 0)                                  //若未结束战斗开始新的回合
                    {
                        Init(0);
                    }
                    else if (m_IsOver == -1)                            //结束战斗结算,还没有写
                    {
                        StartCoroutine(BattleEndL());
                        // 播放结束音乐
                        //。。。
                        BgMusic.dd.StopBgMusic();
                        BgMusic.dd.LoadMusicSource("fail");
                        BgMusic.dd.PlayBgMusic();
                    }
                    else if (m_IsOver == 1)
                    {
                        BgMusic.dd.StopBgMusic();
                        BgMusic.dd.LoadMusicSource();
                        BgMusic.dd.PlayBgMusic();
                        Debug.Log("Win!");
                        int exp  = 0;
                        int gold = 0;
                        foreach (Person p in gameControl.GameSence.enemyList)
                        {
                            exp  += p.Experience;
                            gold += p.Money;
                        }
                        CPlayerData.pd.bag.Money += gold;
                        foreach (Person p in gameControl.GameSence.playerList)
                        {
                            p.buffs.Clear();
                            p.CurrentExperience += exp;
                            if (p.CurrentExperience > p.CalculateExperienceMax())
                            {
                                p.LvUp();
                            }
                        }

                        StartCoroutine(BattleEndV());
                        int i = UnityEngine.Random.Range(0, 1);
                        if (i == 0)
                        {
                            int      nowtask = CPlayerData.pd.GetTaskNum();
                            TaskList tl      = CPlayerData.pd.tl;
                            Task     nowTask = tl.GetTaskStatus(nowtask);
                            if (nowTask != null)
                            {
                                if (m_NowBattle == nowTask.FightID)
                                {
                                    //完成5此任务,用来测试
                                    tl.AddTaskCurrentNumber(nowtask, m_MonsterTask[m_NowBattle]);
                                    Debug.Log("get! " + nowtask + " " + m_MonsterTask[m_NowBattle]);
                                }
                                if (tl.CheckTask(nowtask))
                                {
                                    CPlayerData.pd.SetTaskNum(nowtask + 1);
                                    Debug.Log("complite");
                                }
                            }
                        }
                    }
                }
            }
        }
    }