Пример #1
0
 private static RoleMessages.IRoleMessage GetItemLangInfo(this BaseRole role, ILanguage language)
 {
     if (role?.Player != null && variantsCache.ContainsKey(role))
     {
         return(variantsCache[role]);
     }
     if (language.RoleMessages.TryGetValue(role.GetType().Name, out var result))
     {
         if (role?.Player != null)
         {
             variantsCache[role] = result;
             if (!availableVariantsCache.ContainsKey(result))
             {
                 if (result.Variants != null && result.Variants.Length > 0)
                 {
                     availableVariantsCache[result] = result.Variants.ToList();
                 }
                 else
                 {
                     availableVariantsCache[result] = new List <RoleMessages.Variant>();
                 }
             }
             if (availableVariantsCache.ContainsKey(result) && availableVariantsCache[result].Count > 0)
             {
                 int idx = r.Next(availableVariantsCache[result].Count);
                 variantsCache[role] = availableVariantsCache[result][idx];
                 availableVariantsCache[result].RemoveAt(idx);
             }
             return(variantsCache[role]);
         }
         return(result);
     }
     return(null);
 }
Пример #2
0
 private static RoleMessages.RoleMessage GetItemLangInfo(this BaseRole role, ILanguage language)
 {
     if (language.RoleMessages.TryGetValue(role.GetType().Name, out var result))
     {
         return(result);
     }
     return(null);
 }
Пример #3
0
        public static string[] GetNameCases(this BaseRole role, ILanguage language)
        {
            var info = GetItemLangInfo(role, language);

            if (info?.NameCases != null)
            {
                return(info.NameCases);
            }
            return(Enumerable.Repeat($"#ROLE_NAME_{role.GetType().Name}", 6).ToArray());
        }
Пример #4
0
        public static string[] GetNameCases(this BaseRole role, ILanguage language)
        {
            var info   = GetItemLangInfo(role, language);
            var result = Enumerable.Repeat($"#ROLE_NAME_{role.GetType().Name}", 6).ToArray();

            if (info?.NameCases != null)
            {
                Array.Copy(info.NameCases, result, info.NameCases.Length);
            }
            return(result);
        }
Пример #5
0
 public static string GetName(this BaseRole role, ILanguage language)
 {
     return(GetItemLangInfo(role, language)?.Name ?? $"#ROLE_NAME_{role.GetType().Name}");
 }
Пример #6
0
        public static string GetDescription(this BaseRole role, ILanguage language)
        {
            string description = language.Messages.get($"RoleHelp_{role.GetType().Name}");

            return(!string.IsNullOrEmpty(description) ? description : $"#ROLE_DESC_{role.GetType().Name}");
        }
Пример #7
0
 public static string GetImage(this BaseRole role, ILanguage language)
 {
     return(GetItemLangInfo(role, language)?.ImagePath ?? $"roles/card{role.GetType().Name}.png");
 }