Ejemplo n.º 1
0
 public static void SaveDifficultyControlDataMap(DifficultyControlDataMap fileDataMap, int gameID, DifficultyControlData fileData)
 {
     //Init Data Map
     if (fileDataMap == null || fileDataMap.MapFileData == null)
     {
         fileDataMap             = new DifficultyControlDataMap();
         fileDataMap.MapFileData = new Dictionary <int, DifficultyControlData>();
     }
     //Init Data
     if (fileData == null || fileData.DifficultyConfig == null)
     {
         fileData = new DifficultyControlData();
         fileData.DifficultyConfig = new Dictionary <string, DifficultyConfig>();
     }
     //Save Data
     if (fileDataMap.MapFileData.ContainsKey(gameID))
     {
         fileDataMap.MapFileData[gameID] = fileData;
     }
     else
     {
         fileDataMap.MapFileData.Add(gameID, fileData);
     }
     //Save File
     byte[] data = ThriftSerialize.Serialize(fileDataMap);
     FileUtils.WriteByteFile(GetDifficultyControlDataPath(), data);
 }
Ejemplo n.º 2
0
    public GameDifficulty GetGameDifficulty(string difficultyName, int gameID)
    {
        if (m_DifficultyControlDataMap == null || m_DifficultyControlDataMap.MapFileData == null)
        {
            Debuger.LogError("m_DifficultyControlDataMap not Initialized !");
            return(null);
        }
        if (!m_DifficultyControlDataMap.MapFileData.ContainsKey(gameID))
        {
            Debuger.LogError("current game id is not found " + gameID);
            return(null);
        }
        m_nCurrentGameID = gameID;


        DifficultyControlData currentDifficultyControlData = m_DifficultyControlDataMap.MapFileData[gameID];
        float minDiff = 0f;
        float maxDiff = 1f;

        CalculateGameDifficulty(difficultyName, currentDifficultyControlData, ref minDiff, ref maxDiff);

        GameDifficulty result = new GameDifficulty(minDiff, maxDiff);

        Debuger.Log("current diff:" + difficultyName + " min : " + minDiff + " max : " + maxDiff);

        return(result);
    }
 private void SaveFile()
 {
     // Save Data
     m_DifficultyControlData = new DifficultyControlData();
     m_DifficultyControlData.DifficultyConfig = new Dictionary <string, DifficultyConfig>();
     if (m_lstDifficultyInfo == null)
     {
         m_lstDifficultyInfo = new List <DifficultyInfo>();
     }
     for (int i = 0; i < m_lstDifficultyInfo.Count; i++)
     {
         if (m_lstDifficultyInfo[i].Name == null || m_lstDifficultyInfo[i].Name == "")
         {
             EditorUtility.DisplayDialog("保存失败", "难度名称不能为空", "确定");
             return;
         }
         DifficultyConfig diffConfig = new DifficultyConfig();
         diffConfig.DifficultyOffset = AdaptiveDifficultyManager.ConvertInt(m_lstDifficultyInfo[i].Offset);
         diffConfig.DifficultyRange  = AdaptiveDifficultyManager.ConvertInt(m_lstDifficultyInfo[i].Range);
         diffConfig.TalentEffect     = new Dictionary <string, int>();
         foreach (string talent in m_lstDifficultyInfo[i].TalentEffects.Keys)
         {
             diffConfig.TalentEffect.Add(talent, AdaptiveDifficultyManager.ConvertInt(m_lstDifficultyInfo[i].TalentEffects[talent]));
         }
         m_DifficultyControlData.DifficultyConfig.Add(m_lstDifficultyInfo[i].Name, diffConfig);
     }
     //Save File
     EditorUtility.DisplayDialog("保存成功", "保存成功", "确定");
     ADE_Helper.SaveDifficultyControlDataMap(m_DifficultyControlDataMap, m_GameID, m_DifficultyControlData);
 }
 private void Refresh()
 {
     m_lstDifficultyInfo = null;
     // Check File
     if (m_DifficultyControlDataMap == null || m_DifficultyControlDataMap.MapFileData == null)
     {
         return;
     }
     if (m_DifficultyControlDataMap.MapFileData.Count <= 0)
     {
         return;
     }
     // Game Difficulty
     if (!m_DifficultyControlDataMap.MapFileData.ContainsKey(m_GameID))
     {
         m_DifficultyCount     = 0;
         m_DifficultyLastCount = 0;
         return;
     }
     m_DifficultyControlData = m_DifficultyControlDataMap.MapFileData[m_GameID];
     // Difficulty Count
     m_DifficultyCount     = m_DifficultyControlData.DifficultyConfig.Count;
     m_DifficultyLastCount = m_DifficultyCount;
     // Editor Data
     m_lstDifficultyInfo = new List <DifficultyInfo>();
     foreach (string diffName in m_DifficultyControlData.DifficultyConfig.Keys)
     {
         DifficultyInfo temp = new DifficultyInfo();
         temp.Name   = diffName;
         temp.Offset = AdaptiveDifficultyManager.ConvertFloat(m_DifficultyControlData.DifficultyConfig[diffName].DifficultyOffset);
         temp.Range  = AdaptiveDifficultyManager.ConvertFloat(m_DifficultyControlData.DifficultyConfig[diffName].DifficultyRange);
         Dictionary <string, float> effect            = new Dictionary <string, float>();
         DefaultUserTalent          defaultUserTalent = ConfigManager.Instance.GetDefaultUserTalent();
         foreach (string talentName in defaultUserTalent.MapTalent.Keys)
         {
             if (m_DifficultyControlData.DifficultyConfig[diffName].TalentEffect.ContainsKey(talentName))
             {
                 float effectValue = AdaptiveDifficultyManager.ConvertFloat(m_DifficultyControlData.DifficultyConfig[diffName].TalentEffect[talentName]);
                 effect.Add(talentName, effectValue);
             }
             else
             {
                 effect.Add(talentName, 0f);
             }
         }
         temp.TalentEffects = effect;
         // add to list
         m_lstDifficultyInfo.Add(temp);
     }
 }
Ejemplo n.º 5
0
    // Difficulty Control
    private void CalculateGameDifficulty(string difficultyName, DifficultyControlData currentDifficultyControlData, ref float minDiff, ref float maxDiff)
    {
        if (m_CharTalentMap == null)
        {
            ResetUserTalent();
        }
        if (currentDifficultyControlData.DifficultyConfig.ContainsKey(difficultyName))
        {
            DifficultyConfig difficultyConfig = currentDifficultyControlData.DifficultyConfig[difficultyName];
            float            diff             = ConvertFloat(difficultyConfig.DifficultyOffset);
            foreach (string talentName in difficultyConfig.TalentEffect.Keys)
            {
                if (m_CharTalentMap.ContainsKey(talentName))
                {
                    float score  = ConvertFloat(m_CharTalentMap[talentName]);
                    float effect = ConvertFloat(difficultyConfig.TalentEffect[talentName]);
                    diff += score * effect;
                }
                else
                {
                    Debuger.LogWarning("Wrong Talent Name in DifficultyConfig : " + talentName + ", it does not Exist in UserTalent");
                }
            }
            minDiff = diff - ConvertFloat(difficultyConfig.DifficultyRange);
            maxDiff = diff + ConvertFloat(difficultyConfig.DifficultyRange);

            //check
            if (minDiff < 0.0f)
            {
                minDiff = 0.0f;
            }
            if (maxDiff > 1.0f)
            {
                maxDiff = 1.0f;
            }
            if (minDiff > maxDiff)
            {
                minDiff = maxDiff;
            }
        }
        else
        {
            Debuger.LogWarning("Wrong Difficulty Name : " + difficultyName + ", it does not Exist in DifficultyControlData");
        }
    }