Beispiel #1
0
        public void Init(DRLevel levelData)
        {
            if (levelData == null)
            {
                Log.Error("data is invalid.");
                return;
            }
            LevelId   = levelData.Id;
            LevelName = levelData.Name;
            SceneId   = (SceneId)levelData.Scene;

            DBPlayer player = GameEntry.Database.GetDBRow <DBPlayer>(GameEntry.Database.GetPlayerId());

            if (levelData.LevelRequest <= player.Level)
            {
                IsLock = false;
                m_Ctrl.selectedIndex = levelData.Icon;
                m_Level.color        = Color.green;
            }
            else
            {
                IsLock = true;
                m_Ctrl.selectedIndex = 0;
                m_Level.color        = Color.red;
            }
            m_Title.text = levelData.Name;
            m_Level.text = "LV." + levelData.LevelRequest;
        }
        private void CalcResult()
        {
            LevelResultFormData data = new LevelResultFormData();

            if (m_Victory == false)
            {
                data.Victory   = false;
                data.StarCount = 0;
                data.GlodAward = 0;
                data.ExpAward  = 0;
                GameEntry.UI.OpenUIForm(UIFormId.LevelResultForm, data);
                return;
            }

            DRLevel drLevel = GameEntry.DataTable.GetDataTable <DRLevel>().GetDataRow(LevelID);

            if (drLevel == null)
            {
                Log.Error("the level dr data is no exist.");
                return;
            }

            int starCount = CalcStar(drLevel);
            int money     = drLevel.GetMoneyRatio;
            int exp       = drLevel.GetExpRatio;


            data.Victory   = true;
            data.StarCount = starCount;
            data.GlodAward = money;
            data.ExpAward  = exp;
            GameEntry.UI.OpenUIForm(UIFormId.LevelResultForm, data);
        }
        private int CalcStar(DRLevel copy)
        {
            int star = 0;

            bool[] passContents = new bool[3];
            if (m_Victory == false)
            {
                return(0);
            }

            StarConditionType[] starConditions = new StarConditionType[3];
            starConditions[0] = (StarConditionType)copy.StarCondition1;
            starConditions[1] = (StarConditionType)copy.StarCondition2;
            starConditions[2] = (StarConditionType)copy.StarCondition3;

            int[] starValues = new int[3];
            starValues[0] = copy.StarValue1;
            starValues[1] = copy.StarValue2;
            starValues[2] = copy.StarValue3;

            for (int i = 0; i < starConditions.Length; i++)
            {
                StarConditionType type = starConditions[i];
                int v = starValues[i];
                switch (type)
                {
                case StarConditionType.Health:
                {
                    if (PlayerActor != null)
                    {
                        int   maxHealth = PlayerActor.Attrbute.GetValue(AttributeType.MaxHp);
                        int   curHealth = PlayerActor.Attrbute.GetValue(AttributeType.Hp);
                        float ratio     = curHealth / (maxHealth * 1f);
                        if (ratio >= v / 100f)
                        {
                            star++;
                            passContents[i] = true;
                        }
                    }
                }
                break;

                case StarConditionType.Pass:
                {
                    if (m_Victory)
                    {
                        star++;
                        passContents[i] = true;
                    }
                }
                break;

                case StarConditionType.TimeLimit:
                {
                    if (CurTime < v)
                    {
                        star++;
                        passContents[i] = true;
                    }
                }
                break;
                }
            }
            return(star);
        }