示例#1
0
        /// <summary>
        /// Add a netbios name.
        /// </summary>
        /// <param name="name">The name to add.</param>
        /// <param name="type">The type to use.</param>
        /// <param name="suffix">The suffix to use.</param>
        /// <returns>True on success, false on failure.</returns>
        public bool AddName(string name, NameType type, MsSuffix suffix)
        {
            Name node = new Name();

            node.UncompressedName = UncompressName(name, suffix);
            node.Type             = type;

            // Send request
            StartCapture();

            for (int i = 0; i < BCAST_REQ_RETRY_COUNT; i++)
            {
                Request(node, HeaderOpcode.Registration);
                Thread.Sleep(3 * BCAST_REQ_RETRY_TIMEOUT);  // Three times, otherwise FEZ can't follow :(

                if (denyCaptured)
                {
                    break;
                }
            }

            if (!StopCapture())
            {
                return(false);   // Name in use
            }
            Request(node, HeaderOpcode.Update);

            lock (nameList)
                nameList.Add(node);

            updateTimer.Change(NAME_UPDATE_INTERVAL_MS, Timeout.Infinite);

            return(true);
        }
示例#2
0
        private void MsSuffixOnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (_changingBase)
            {
                return;
            }

            if (e.PropertyName == nameof(ModSelectorViewModel.SelectedValues))
            {
                RecalculateItem();
                return;
            }
            if (e.PropertyName != nameof(ModSelectorViewModel.SelectedAffix))
            {
                return;
            }

            using (Monitor.Enter())
            {
                var ms = (ModSelectorViewModel)sender;

                foreach (var other in MsSuffix)
                {
                    if (other != ms)
                    {
                        var blockedSuffixes = MsSuffix.Where(m => m != other).Select(m => m.SelectedAffix);
                        other.Affixes = _suffixes.Except(blockedSuffixes).ToList();
                    }
                }
            }
        }
示例#3
0
        public CraftingViewModel(EquipmentData equipmentData)
            : base(equipmentData,
                   equipmentData.ItemBases.Where(b => equipmentData.AffixesPerItemType.ContainsKey(b.ItemType)))
        {
            MsPrefix.ForEach(ms => ms.PropertyChanged += MsPrefixOnPropertyChanged);
            MsSuffix.ForEach(ms => ms.PropertyChanged += MsSuffixOnPropertyChanged);

            Init();
        }
        protected override IEnumerable <IGrouping <ModLocation, StatIdValuePair> > RecalculateItemSpecific(out int requiredLevel)
        {
            var selectedPrefixes = MsPrefix.Where(s => !s.IsEmptySelection).ToArray();
            var selectedSuffixes = MsSuffix.Where(s => !s.IsEmptySelection).ToArray();

            if (selectedPrefixes.Length + selectedSuffixes.Length == 0)
            {
                Item.Frame = FrameType.White;
            }
            else if (selectedPrefixes.Length <= 1 && selectedSuffixes.Length <= 1)
            {
                Item.Frame = FrameType.Magic;
                var typeline = "";

                if (selectedPrefixes.Length > 0)
                {
                    var pref = selectedPrefixes[0];
                    typeline = pref.Query().Name + " ";
                }

                typeline += Item.BaseType;

                if (selectedSuffixes.Length > 0)
                {
                    var suff = selectedSuffixes[0];
                    typeline += " " + suff.Query().Name;
                }

                Item.TypeLine = typeline;
            }
            else
            {
                Item.Frame = FrameType.Rare;
            }
            UpdateItemNameLine();

            requiredLevel = selectedPrefixes.Concat(selectedSuffixes)
                            .Select(ms => ms.Query().RequiredLevel)
                            .DefaultIfEmpty()
                            .Max();

            return
                (from ms in MsPrefix.Concat(MsSuffix)
                 where !ms.IsEmptySelection
                 let location = ms.Query().Domain == ModDomain.Crafted ? ModLocation.Crafted : ModLocation.Explicit
                                from tuple in ms.GetStatValues()
                                group tuple by location);
        }
示例#5
0
        RecalculateItemSpecific(out int requiredLevel)
        {
            var selectedPrefixes = MsPrefix.Where(s => !s.IsEmptySelection).ToArray();
            var selectedSuffixes = MsSuffix.Where(s => !s.IsEmptySelection).ToArray();

            if (selectedPrefixes.Length + selectedSuffixes.Length == 0)
            {
                Item.Frame = FrameType.White;
            }
            else if (selectedPrefixes.Length <= 1 && selectedSuffixes.Length <= 1)
            {
                Item.Frame = FrameType.Magic;
                var typeline = "";

                if (selectedPrefixes.Length > 0)
                {
                    var pref = selectedPrefixes[0];
                    typeline = pref.Query().Name + " ";
                }

                typeline += Item.BaseType;

                if (selectedSuffixes.Length > 0)
                {
                    var suff = selectedSuffixes[0];
                    typeline += " " + suff.Query().Name;
                }

                Item.TypeLine = typeline;
            }
            else
            {
                Item.Frame = FrameType.Rare;
            }
            UpdateItemNameLine();

            requiredLevel = selectedPrefixes.Concat(selectedSuffixes)
                            .Select(ms => ms.Query().RequiredLevel)
                            .DefaultIfEmpty()
                            .Max();

            var(craftedMs, explicitMs) = MsPrefix.Concat(MsSuffix)
                                         .Where(s => !s.IsEmptySelection)
                                         .Partition(s => s.Query().Domain == ModDomain.Crafted);
            return(explicitMs.SelectMany(s => s.GetStatValues()), craftedMs.SelectMany(s => s.GetStatValues()));
        }
示例#6
0
        protected override IEnumerable <ItemMod> RecalculateItemSpecific()
        {
            var selectedPreff = MsPrefix.Where(s => !s.IsEmptySelection).ToArray();
            var selectedSuff  = MsSuffix.Where(s => !s.IsEmptySelection).ToArray();

            if (selectedPreff.Length + selectedSuff.Length == 0)
            {
                Item.Frame = FrameType.White;
            }
            else if (selectedPreff.Length <= 1 && selectedSuff.Length <= 1)
            {
                Item.Frame = FrameType.Magic;
                var typeline = "";

                if (selectedPreff.Length > 0)
                {
                    var pref = selectedPreff[0];
                    typeline = pref.Query().First().Name + " ";
                }

                typeline += Item.BaseType;

                if (selectedSuff.Length > 0)
                {
                    var suff = selectedSuff[0];
                    typeline += " " + suff.Query().First().Name;
                }

                Item.TypeLine = typeline;
            }
            else
            {
                Item.Frame = FrameType.Rare;
            }
            UpdateItemNameLine();

            var prefixes = selectedPreff.SelectMany(p => p.GetExactMods());
            var suffixes = selectedSuff.SelectMany(p => p.GetExactMods());

            return(prefixes.Concat(suffixes)
                   .GroupBy(m => m.Attribute)
                   .Select(g => g.Aggregate((m1, m2) => m1.Sum(m2))));
        }
示例#7
0
        protected override void UpdateBaseSpecific()
        {
            _prefixes = CreateAffixes(_allPrefixes).ToList();
            _suffixes = CreateAffixes(_allSuffixes).ToList();

            _changingBase = true;
            MsPrefix.ForEach(ms => ms.Affixes = _prefixes);
            foreach (var ms in MsPrefix)
            {
                var blockedPrefixes = MsPrefix.Where(m => m != ms).Select(m => m.SelectedAffix);
                ms.Affixes = _prefixes.Except(blockedPrefixes).ToList();
            }
            MsSuffix.ForEach(ms => ms.Affixes = _suffixes);
            foreach (var ms in MsSuffix)
            {
                var blockedSuffixes = MsSuffix.Where(m => m != ms).Select(m => m.SelectedAffix);
                ms.Affixes = _suffixes.Except(blockedSuffixes).ToList();
            }
            _changingBase = false;
        }
示例#8
0
        public CraftingViewModel(EquipmentData equipmentData)
            : base(equipmentData, SelectCraftableBases(equipmentData))
        {
            _allPrefixes = equipmentData.ModDatabase[ModGenerationType.Prefix];
            _allSuffixes = equipmentData.ModDatabase[ModGenerationType.Suffix];

            MsPrefix = new[] {
                new ModSelectorViewModel(EquipmentData.StatTranslator),
                new ModSelectorViewModel(EquipmentData.StatTranslator),
                new ModSelectorViewModel(EquipmentData.StatTranslator)
            };
            MsPrefix.ForEach(ms => ms.PropertyChanged += MsPrefixOnPropertyChanged);
            MsSuffix = new[] {
                new ModSelectorViewModel(EquipmentData.StatTranslator),
                new ModSelectorViewModel(EquipmentData.StatTranslator),
                new ModSelectorViewModel(EquipmentData.StatTranslator)
            };
            MsSuffix.ForEach(ms => ms.PropertyChanged += MsSuffixOnPropertyChanged);

            Init();
        }
示例#9
0
        /// <summary>
        /// Converts a human-readable name to an uncompressed NetBIOS name.
        /// </summary>
        /// <param name="name">The compressed, human-readable name.</param>
        /// <param name="suffix">The name suffix as introduced by Microsoft.</param>
        /// <returns>The uncompressed NetBIOS name.</returns>
        private static string UncompressName(string name, MsSuffix suffix)
        {
            if (name.Length > 15)
            {
                throw new ArgumentException("Name cannot contain more than 15 characters");
            }

            char[] result = new char[32];
            int    offset = 0;

            for (int i = 0; i < 15; i++)
            {
                char c = i < name.Length ? name[i] : ' ';
                result[offset++] = (char)('A' + (c >> 4));
                result[offset++] = (char)('A' + (c & 15));
            }
            result[offset++] = (char)('A' + ((byte)suffix >> 4));
            result[offset++] = (char)('A' + ((byte)suffix & 15));

            return(new string(result));
        }
示例#10
0
        /// <summary>
        /// Remove a netbios name.
        /// </summary>
        /// <param name="name">The name to remove.</param>
        /// <param name="type">The type used.</param>
        /// <param name="suffix">The suffix used.</param>
        /// <returns>True on success, false on failure.</returns>
        public bool RemoveName(string name, NameType type, MsSuffix suffix)
        {
            Name node = new Name();

            node.UncompressedName = UncompressName(name, suffix);
            node.Type             = type;

            lock (nameList)
            {
                int i = 0;
                for (; i < nameList.Count; i++)
                {
                    Name n = (Name)nameList[i];
                    if ((n.UncompressedName == node.UncompressedName) && (n.Type == node.Type))
                    {
                        break;
                    }
                }

                if (i >= nameList.Count)
                {
                    return(false);   // Name not found
                }
                nameList.RemoveAt(i);

                if (nameList.Count == 0)
                {
                    updateTimer.Change(Timeout.Infinite, Timeout.Infinite);
                }
            }

            // Send request
            for (int i = 0; i < BCAST_REQ_RETRY_COUNT; i++)
            {
                Request(node, HeaderOpcode.Release);
                Thread.Sleep(BCAST_REQ_RETRY_TIMEOUT);
            }

            return(true);
        }
示例#11
0
        protected override void UpdateBaseSpecific()
        {
            var aaff = EquipmentData.AffixesPerItemType[Item.ItemType];

            _prefixes = aaff.Where(a => a.ModType == ModType.Prefix).ToList();
            _suffixes = aaff.Where(a => a.ModType == ModType.Suffix).ToList();

            _changingBase = true;
            MsPrefix.ForEach(ms => ms.Affixes = _prefixes);
            foreach (var ms in MsPrefix)
            {
                var blockedPrefixes = MsPrefix.Where(m => m != ms).Select(m => m.SelectedAffix);
                ms.Affixes = _prefixes.Except(blockedPrefixes).ToList();
            }
            MsSuffix.ForEach(ms => ms.Affixes = _suffixes);
            foreach (var ms in MsSuffix)
            {
                var blockedSuffixes = MsSuffix.Where(m => m != ms).Select(m => m.SelectedAffix);
                ms.Affixes = _suffixes.Except(blockedSuffixes).ToList();
            }
            _changingBase = false;
        }
示例#12
0
        /// <summary>
        /// Converts an uncompressed NetBIOS name to a compressed, human-readable name.
        /// </summary>
        /// <param name="name">The uncompressed NetBIOS name.</param>
        /// <param name="suffix">The name suffix as introduced by Microsoft.</param>
        /// <returns>The compressed, human-readable name.</returns>
        private static string CompressName(string name, out MsSuffix suffix)
        {
            if (name.Length != 32)
            {
                throw new ArgumentException("Unsupported name length, should be 32 characters", "name");
            }

            suffix = MsSuffix.Default;

            int offset = 0;

            char[] result = new char[15];

            for (int i = 0; i < 16; i++)
            {
                byte b1 = (byte)(name[offset++] - 'A');
                byte b2 = (byte)(name[offset++] - 'A');

                if ((b1 > 15) || (b2 > 15))
                {
                    throw new ArgumentException("Invalid characters in name", "name");
                }

                b1 <<= 4;
                b1  += b2;

                if (i < 15)
                {
                    result[i] = (char)b1;
                }
                else
                {
                    suffix = (MsSuffix)b1;
                }
            }

            return(new string(result).TrimEnd(new char[] { ' ' }));
        }
示例#13
0
        /// <summary>
        /// Converts a human-readable name to an uncompressed NetBIOS name.
        /// </summary>
        /// <param name="name">The compressed, human-readable name.</param>
        /// <param name="suffix">The name suffix as introduced by Microsoft.</param>
        /// <returns>The uncompressed NetBIOS name.</returns>
        private static string UncompressName(string name, MsSuffix suffix)
        {
            if (name.Length > 15)
                throw new ArgumentException("Name cannot contain more than 15 characters");

            char[] result = new char[32];
            int offset = 0;

            for (int i = 0; i < 15; i++)
            {
                char c = i < name.Length ? name[i] : ' ';
                result[offset++] = (char)('A' + (c >> 4));
                result[offset++] = (char)('A' + (c & 15));
            }
            result[offset++] = (char)('A' + ((byte)suffix >> 4));
            result[offset++] = (char)('A' + ((byte)suffix & 15));

            return new string(result);
        }
示例#14
0
        /// <summary>
        /// Converts an uncompressed NetBIOS name to a compressed, human-readable name.
        /// </summary>
        /// <param name="name">The uncompressed NetBIOS name.</param>
        /// <param name="suffix">The name suffix as introduced by Microsoft.</param>
        /// <returns>The compressed, human-readable name.</returns>
        private static string CompressName(string name, out MsSuffix suffix)
        {
            if (name.Length != 32)
                throw new ArgumentException("Unsupported name length, should be 32 characters", "name");

            suffix = MsSuffix.Default;

            int offset = 0;
            char[] result = new char[15];

            for (int i = 0; i < 16; i++)
            {
                byte b1 = (byte)(name[offset++] - 'A');
                byte b2 = (byte)(name[offset++] - 'A');

                if ((b1 > 15) || (b2 > 15))
                    throw new ArgumentException("Invalid characters in name", "name");

                b1 <<= 4;
                b1 += b2;

                if (i < 15)
                    result[i] = (char)b1;
                else
                    suffix = (MsSuffix)b1;
            }

            return new string(result).TrimEnd(new char[] { ' ' });
        }
示例#15
0
        /// <summary>
        /// Remove a netbios name.
        /// </summary>
        /// <param name="name">The name to remove.</param>
        /// <param name="type">The type used.</param>
        /// <param name="suffix">The suffix used.</param>
        /// <returns>True on success, false on failure.</returns>
        public bool RemoveName(string name, NameType type, MsSuffix suffix)
        {
            Name node = new Name();
            node.UncompressedName = UncompressName(name, suffix);
            node.Type = type;

            lock (nameList)
            {
                int i = 0;
                for (; i < nameList.Count; i++)
                {
                    Name n = (Name)nameList[i];
                    if ((n.UncompressedName == node.UncompressedName) && (n.Type == node.Type))
                        break;
                }

                if (i >= nameList.Count)
                    return false;   // Name not found

                nameList.RemoveAt(i);

                if (nameList.Count == 0)
                    updateTimer.Change(Timeout.Infinite, Timeout.Infinite);
            }

            // Send request
            for (int i = 0; i < BCAST_REQ_RETRY_COUNT; i++)
            {
                Request(node, HeaderOpcode.Release);
                Thread.Sleep(BCAST_REQ_RETRY_TIMEOUT);
            }

            return true;
        }
示例#16
0
        /// <summary>
        /// Add a netbios name.
        /// </summary>
        /// <param name="name">The name to add.</param>
        /// <param name="type">The type to use.</param>
        /// <param name="suffix">The suffix to use.</param>
        /// <returns>True on success, false on failure.</returns>
        public bool AddName(string name, NameType type, MsSuffix suffix)
        {
            Name node = new Name();
            node.UncompressedName = UncompressName(name, suffix);
            node.Type = type;

            // Send request
            StartCapture();

            for (int i = 0; i < BCAST_REQ_RETRY_COUNT; i++)
            {
                Request(node, HeaderOpcode.Registration);
                Thread.Sleep(3 * BCAST_REQ_RETRY_TIMEOUT);  // Three times, otherwise FEZ can't follow :(

                if (denyCaptured)
                    break;
            }

            if (!StopCapture())
                return false;   // Name in use

            Request(node, HeaderOpcode.Update);

            lock (nameList)
                nameList.Add(node);

            updateTimer.Change(NAME_UPDATE_INTERVAL_MS, Timeout.Infinite);

            return true;
        }