Пример #1
0
        private void UpdateBrowsedPrivilege(int curLev)
        {
            vipData.BrowsedPrivileges.Clear();

            VIPPrivilege oldPrivilege = VIPTemplateManager.Instance.GetTemplate(curLev - 1);
            VIPPrivilege privilege    = VIPTemplateManager.Instance.GetTemplate(curLev);

            Dictionary <string, int> .Enumerator   numEnumerator     = privilege.GetNumEnumerator();
            Dictionary <string, float> .Enumerator percentEnumerator = privilege.GetPercentEnumerator();
            while (numEnumerator.MoveNext())
            {
                string key = numEnumerator.Current.Key;
                if (vipData.VipCertificates.Contains(key))
                {
                    int value = privilege.GetTotalNum(key);                    // + VIPTemplateManager.Instance.GetMonthVIPNum(key);
                    //if (value > 0) AppendPrivilegeItem(key, value, curLev);
                    AppendOrUpdatePrivilegeItem(ref vipData.BrowsedPrivileges, key, value, value > 0, oldPrivilege);
                }
            }
            while (percentEnumerator.MoveNext())
            {
                string key = percentEnumerator.Current.Key;
                if (vipData.VipCertificates.Contains(key))
                {
                    float value = privilege.GetPercent(key);
                    bool  valid = key.Equals(VIPPrivilegeKey.ShopDiscount) ? value > 0 && value < 1 : value > 0;
                    //if (value > 0) AppendPrivilegeItem(key, value, curLev);
                    AppendOrUpdatePrivilegeItem(ref vipData.BrowsedPrivileges, key, value, valid, oldPrivilege);
                }
            }
            OnEquipmentGift(ref vipData.BrowsedPrivileges, privilege, oldPrivilege);

            vipData.CheckedLevel = curLev;
        }
Пример #2
0
        private Dictionary <string, VIPPrivilegeItem> GetPrivilegeDict(VIPPrivilege profile)
        {
            Dictionary <string, VIPPrivilegeItem> privileges = new Dictionary <string, VIPPrivilegeItem>();

            if (profile == null)
            {
                return(privileges);
            }

            Dictionary <string, int> .Enumerator   numEnumerator     = profile.GetNumEnumerator();
            Dictionary <string, float> .Enumerator percentEnumerator = profile.GetPercentEnumerator();
            while (numEnumerator.MoveNext())
            {
                string key = numEnumerator.Current.Key;
                if (vipData.VipCertificates.Contains(key))
                {
                    int value = profile.GetTotalNum(key);                    // + VIPTemplateManager.Instance.GetMonthVIPNum(key);
                    if (value > 0)
                    {
                        VIPPrivilegeItem item = new VIPPrivilegeItem();
                        item.Value = value;
                        privileges.Add(key, item);
                    }
                }
            }
            while (percentEnumerator.MoveNext())
            {
                string key = percentEnumerator.Current.Key;
                if (vipData.VipCertificates.Contains(key))
                {
                    float value = profile.GetPercent(key);
                    bool  valid = key.Equals(VIPPrivilegeKey.ShopDiscount) ? value > 0 && value < 1 : value > 0;
                    if (valid)
                    {
                        VIPPrivilegeItem item = new VIPPrivilegeItem();
                        item.Percent = value;
                        privileges.Add(key, item);
                    }
                }
            }
            return(privileges);
        }
Пример #3
0
        private void AppendOrUpdatePrivilegeItem(ref Dictionary <string, VIPPrivilegeItem> privileges, string key, object value, bool valid, VIPPrivilege comparer)
        {
            Dictionary <string, VIPPrivilegeItem> oldPrivileges = GetPrivilegeDict(comparer);

            if (!valid)
            {
                privileges.Remove(key);
                return;
            }

            bool has = privileges.TryGetValue(key, out VIPPrivilegeItem item);

            if (item == null)
            {
                item = new VIPPrivilegeItem();
            }

            if (comparer == null || (comparer != null && !oldPrivileges.ContainsKey(key)))
            {
                item.Status = comparer == null ? PrivilegeStatus.Ordinary : PrivilegeStatus.Newly;
            }
            else
            {
                if (value is int)
                {
                    int oldValue = comparer.GetTotalNum(key);
                    item.Status = oldValue != (int)value ? PrivilegeStatus.HasChanged : PrivilegeStatus.Ordinary;
                }
                else
                {
                    float oldValue = comparer.GetPercent(key);
                    item.Status = oldValue != (float)value ? PrivilegeStatus.HasChanged : PrivilegeStatus.Ordinary;
                }
            }
            item.Format  = GetPrivilegeKeyWords(key);
            item.Value   = value is int?(int)value     : item.Value;
            item.Percent = value is float?(float)value : item.Percent;
            if (!has)
            {
                privileges.Add(key, item);
            }
        }