Ejemplo n.º 1
0
 public OperationMetaData(int precedence, Associativity assoc, MethodInfo method, Affix affix, T oper)
 {
     Precedence    = precedence;
     Associativity = assoc;
     VisitorMethod = method;
     OperatorToken = oper;
     Affix         = affix;
 }
        private static Stat CreateTestStat(Affix affix, int testValue1, int?testValue2 = null)
        {
            Stat stat = new Stat();

            stat.Affix  = affix;
            stat.Value1 = testValue1;
            stat.Value2 = testValue2;
            return(stat);
        }
Ejemplo n.º 3
0
        private static Affix CreateTestAffix(string modName, AffixType affixType)
        {
            Affix affix = new Affix();

            affix.Group          = modName;
            affix.Type           = modName;
            affix.GenerationType = affixType.ToString();
            return(affix);
        }
 public OperationAttribute(string stringToken, Affix affix, Associativity assoc, int precedence)
 {
     StringToken   = stringToken;
     IsStringToken = true;
     IsIntToken    = false;
     Affix         = affix;
     Assoc         = assoc;
     Precedence    = precedence;
 }
 private ItemProperty AffixToItemProperty(Affix affix, StatValueType valueType, List <int> values = null)
 {
     return(new ItemProperty()
     {
         Group = affix.Group,
         Values = GetTypedValue(affix, valueType, values),
         Type = (AffixType)Enum.Parse(typeof(AffixType), affix.GenerationType, true)
     });
 }
Ejemplo n.º 6
0
 private void AddAffix(AffixType affixType)
 {
     if (!AffixTypes.Contains(affixType))
     {
         AffixTypes.Add(affixType);
         Affix newAffix = GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.Affix].AllocateGameObject <Affix>(AffixContainer);
         newAffix.Initialize(affixType);
         Affixes.Add(newAffix);
     }
 }
Ejemplo n.º 7
0
        private static void UpdateNodeText(TreeNode node, Affix d3Object)
        {
            var sources = new[] { d3Object.Attributes.Primary, d3Object.Attributes.Secondary, d3Object.Attributes.Passive };
            var text    = sources.Where(s => s != null)
                          .SelectMany(s => s)
                          .Select(s => $"[{s.Text}]")
                          .Aggregate((c, s) => c + s);

            node.Text += $" >> {text}";
        }
        public void MetamodFlatTotalDamageSevenPrefixesSuperiorElementalTest()
        {
            Equipment testEquipment = new Equipment();
            ItemBase  itemBase      = new ItemBase();

            itemBase.Properties = new Dictionary <string, double>
            {
                { ItemProperties.MinDamage, 10 },
                { ItemProperties.MaxDamage, 30 },
                { ItemProperties.AttackTime, 500 }
            };
            testEquipment.ItemBase = itemBase;

            Affix affix1 = CreateTestAffix(_random, AffixTypesByStat.FlatChaosDamage, AffixType.Prefix);
            Affix affix2 = CreateTestAffix(_random, AffixTypesByStat.FlatColdDamage, AffixType.Prefix);
            Affix affix3 = CreateTestAffix(_random, AffixTypesByStat.FlatFireDamage, AffixType.Prefix);
            Affix affix4 = CreateTestAffix(_random, AffixTypesByStat.FlatLightningDamage, AffixType.Prefix);
            Affix affix5 = CreateTestAffix(_random, AffixTypesByStat.FlatPhysicalDamage, AffixType.Prefix);
            Affix affix6 = CreateTestAffix(AffixTypes.LocalPhysicalPercent, AffixType.Prefix);
            Affix affix7 = CreateTestAffix(AffixTypes.LocalPhysicalHybrid, AffixType.Prefix);
            Affix affix8 = CreateTestAffix(AffixTypes.LocalAttackSpeed, AffixType.Suffix);

            Stat stat1 = CreateTestStat(affix1, 1, 10);

            testEquipment.Stats.Add(stat1);
            Stat stat2 = CreateTestStat(affix2, 10, 30);

            testEquipment.Stats.Add(stat2);
            Stat stat3 = CreateTestStat(affix3, 10, 20);

            testEquipment.Stats.Add(stat3);
            Stat stat4 = CreateTestStat(affix4, 60, 80);

            testEquipment.Stats.Add(stat4);
            Stat stat5 = CreateTestStat(affix5, 10, 30);

            testEquipment.Stats.Add(stat5);
            Stat stat6 = CreateTestStat(affix6, 80);

            testEquipment.Stats.Add(stat6);
            Stat stat7 = CreateTestStat(affix7, 20);

            testEquipment.Stats.Add(stat7);
            Stat stat8 = CreateTestStat(affix8, 100);

            testEquipment.Stats.Add(stat8);

            List <int> eleDamagePhys      = _affixValueCalculator.GetAffixValues(AffixTypes.TotalPhysicalDps, testEquipment, AffixType.Meta, StatValueType.Flat);
            List <int> eleDamageEleDamage = _affixValueCalculator.GetAffixValues(AffixTypes.TotalElementalDps, testEquipment, AffixType.Meta, StatValueType.Flat);
            List <int> eleDamageTotal     = _affixValueCalculator.GetAffixValues(AffixTypes.TotalDps, testEquipment, AffixType.Meta, StatValueType.Flat);

            Assert.AreEqual(352, eleDamagePhys[0]);
            Assert.AreEqual(420, eleDamageEleDamage[0]);
            Assert.AreEqual(420, eleDamageTotal[0]);
        }
Ejemplo n.º 9
0
        public void RemoveAffix(Affix affix)
        {
            if (!Affixes.Contains(affix))
            {
                return;
            }

            affix.Disable();
            Affixes.Remove(affix);
            Dirty = true;
        }
Ejemplo n.º 10
0
        public AffixDialogViewModel(Affix affix, DictionaryEditorViewModel parent)
        {
            _affix  = affix;
            _parent = parent;
            var vms = affix.Values.Select(a => new PossibilityViewModel {
                Value = a
            });

            Possibilities = new ObservableCollection <PossibilityViewModel>(vms);
            Name          = affix.Name;
        }
Ejemplo n.º 11
0
        public void AffixNoSuffixesWhenFullTest()
        {
            String item       = "Murderous Eye Jewel";
            String defaultTag = "abyss_jewel_melee";

            var          testItem   = _itemFactory.Jewel.First(x => x.Name == item);
            List <Affix> allAffixes = new List <Affix>();

            var p1 = getTestAffix("test_p1", "test_p1", new Dictionary <string, int>()
            {
                { defaultTag, 100 }
            });
            var p2 = getTestAffix("test_p2", "test_p2", new Dictionary <string, int>()
            {
                { defaultTag, 100 }
            });
            var p3 = getTestAffix("test_p3", "test_p3", new Dictionary <string, int>()
            {
                { defaultTag, 100 }
            });

            p1.GenerationType = "suffix";
            p2.GenerationType = "suffix";
            p3.GenerationType = "suffix";

            var existing = new List <Affix>()
            {
                p1, p2, p3
            };

            allAffixes.AddRange(existing);

            for (int i = 0; i < 10; i++)
            {
                Affix affix = getTestAffix("test_" + i, "test" + i, new Dictionary <string, int>()
                {
                    { defaultTag, 100 }
                });
                affix.GenerationType = i < 5 ? "prefix" : "suffix";
                allAffixes.Add(affix);
            }

            AffixManager affixManager = new AffixManager(testItem, allAffixes, new List <Affix>());

            List <Affix> generated = new List <Affix>();
            IRandom      random    = SetupRandom().Object;

            for (var i = 0; i < 10; i++)
            {
                generated.Add(affixManager.GetAffix(existing, EquipmentRarity.Rare, random));
            }

            Assert.IsFalse(generated.Any(x => x.GenerationType == "suffix"));
        }
Ejemplo n.º 12
0
        private static bool IsFull(Equipment item, Affix affix)
        {
            int affixesCount = item.Rarity == EquipmentRarity.Normal ? 0 :
                               item.Rarity == EquipmentRarity.Magic ? 1 :
                               item.Rarity == EquipmentRarity.Rare ? 3 : 0;

            var canAddPrefix = affix.GenerationType == "prefix" && item.Prefixes.Count < affixesCount;
            var canAddSuffix = affix.GenerationType == "suffix" && item.Suffixes.Count < affixesCount;

            return(!canAddPrefix && !canAddSuffix);
        }
        private static Stat CreateStat(int value, string modType)
        {
            Affix affix = new Affix {
                Group = modType, GenerationType = "Prefix"
            };
            Stat stat = new Stat {
                Value1 = value, Affix = affix
            };

            stat.Affix = affix;
            return(stat);
        }
Ejemplo n.º 14
0
 public virtual void Save(Context context)
 {
     if (ShortAffix != null)
     {
         ShortAffix.Persist(context);
     }
     if (Affix != null)
     {
         Affix.Persist(context);
     }
     context.Persist(this);
 }
Ejemplo n.º 15
0
        private void BaseSelection_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (BaseSelection.SelectedItem == null)
            {
                Item = null;
                return;
            }

            var d = _monitor.Enter();

            msp1.Affixes = msp2.Affixes = msp3.Affixes = mss1.Affixes = mss1.Affixes = mss2.Affixes = mss3.Affixes = null;

            var ibase = (ItemBase)BaseSelection.SelectedItem;

            Item = ibase.CreateItem();

            if (ibase.ImplicitMods.Any())
            {
                msImplicitMods.Affixes = new List <Affix>
                {
                    new Affix(ibase.ImplicitMods.Select(s => s.Name).ToArray(), new[] { new ItemModTier(ibase.ImplicitMods) })
                };
                Item.ImplicitMods = msImplicitMods.GetExactMods().ToList();
                ApplyLocals();
            }
            else
            {
                msImplicitMods.Affixes = null;
            }
            if (ibase.CanHaveQuality)
            {
                var qualityStat  = new Stat(QualityModName, new Range <float>(0, 20), Item.ItemType, null);
                var qualityAffix = new Affix(new[] { QualityModName }, new[] { new ItemModTier(new[] { qualityStat }) });
                MsQuality.Affixes = new List <Affix>(new[] { qualityAffix });
            }
            else
            {
                MsQuality.Affixes = null;
            }

            var aaff = _equipmentData.AffixesPerItemType[Item.ItemType].ToArray();

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

            msp1.Affixes    = msp2.Affixes = msp3.Affixes = _prefixes;
            mss1.Affixes    = mss2.Affixes = mss3.Affixes = _suffixes;
            msp3.Visibility = Item.ItemGroup == ItemGroup.Jewel ? Visibility.Hidden : Visibility.Visible;
            mss3.Visibility = Item.ItemGroup == ItemGroup.Jewel ? Visibility.Hidden : Visibility.Visible;

            d.Dispose();
        }
Ejemplo n.º 16
0
        public Affix GenerateAffix(Character character, string name, int tier = 0, int roll = 0)
        {
            var affixData = GameData.Affixes.FirstOrDefault(x => x.Name == name);

            if (affixData == null)
            {
                return(null);
            }

            roll = Math.Max(roll, 1);
            var affix = new Affix(character, affixData, tier, roll);

            if (affixData.Conditions != null)
            {
                foreach (var conditionLine in affixData.Conditions)
                {
                    string[] postParams     = null;
                    var      parenthesisIdx = conditionLine.IndexOf('(');
                    var      condName       = conditionLine;
                    if (parenthesisIdx != -1)
                    {
                        condName = conditionLine.Substring(0, parenthesisIdx);
                        var parameterList = conditionLine.Substring(parenthesisIdx + 1, conditionLine.IndexOf(')') - parenthesisIdx - 1);
                        postParams = Array.ConvertAll(parameterList.Split(','), p => p.Trim());
                    }

                    var condData = GameData.Conditions.First(x => x.Name == condName);
                    if (condData != null)
                    {
                        var condType  = (ConditionType)Enum.Parse(typeof(ConditionType), condData.Type);
                        var condition = condData.Condition;
                        affix.AddNode(new ScriptedCondition(affix, condType, () => LuaContext, condition, postParams));
                        break;
                    }
                }
            }

            var affixType = (AffixType)Enum.Parse(typeof(AffixType), affixData.Type);

            switch (affixType)
            {
            case AffixType.AttributeModifier:
                affix.AddNode(new AttributeModifier(affix));
                break;

            case AffixType.Logic:
                affix.AddNode(new LogicNode(affix, () => LuaContext, affixData));
                break;
            }

            return(affix);
        }
        public void MetamodFlatPhysicalDamageTest()
        {
            Equipment testEquipment = new Equipment();
            ItemBase  itemBase      = new ItemBase();

            itemBase.Properties = new Dictionary <string, double>
            {
                { ItemProperties.MinDamage, 10 },
                { ItemProperties.MaxDamage, 30 },
                { ItemProperties.AttackTime, 500 }
            };
            testEquipment.ItemBase = itemBase;

            List <int> noModsPhys      = _affixValueCalculator.GetAffixValues(AffixTypes.TotalPhysicalDps, testEquipment, AffixType.Meta, StatValueType.Flat);
            List <int> noModsTotal     = _affixValueCalculator.GetAffixValues(AffixTypes.TotalDps, testEquipment, AffixType.Meta, StatValueType.Flat);
            List <int> noModsElemental = _affixValueCalculator.GetAffixValues(AffixTypes.TotalElementalDps, testEquipment, AffixType.Meta, StatValueType.Flat);

            Assert.AreEqual(48, noModsPhys[0]);
            Assert.AreEqual(48, noModsTotal[0]);
            Assert.AreEqual(0, noModsElemental[0]);

            Affix affix1 = CreateTestAffix(AffixTypes.LocalAttackSpeed, AffixType.Suffix);
            Stat  stat1  = CreateTestStat(affix1, 100);

            testEquipment.Stats.Add(stat1);

            List <int> attackSpeedPhys  = _affixValueCalculator.GetAffixValues(AffixTypes.TotalPhysicalDps, testEquipment, AffixType.Meta, StatValueType.Flat);
            List <int> attackSpeedTotal = _affixValueCalculator.GetAffixValues(AffixTypes.TotalDps, testEquipment, AffixType.Meta, StatValueType.Flat);

            Assert.AreEqual(96, attackSpeedPhys[0]);
            Assert.AreEqual(96, attackSpeedTotal[0]);

            Affix affix2 = CreateTestAffix(_random, AffixTypesByStat.FlatPhysicalDamage, AffixType.Prefix);
            Affix affix3 = CreateTestAffix(AffixTypes.LocalPhysicalPercent, AffixType.Prefix);
            Affix affix4 = CreateTestAffix(AffixTypes.LocalPhysicalHybrid, AffixType.Prefix);

            Stat stat2 = CreateTestStat(affix2, 10, 30);

            testEquipment.Stats.Add(stat2);
            Stat stat3 = CreateTestStat(affix3, 80);

            testEquipment.Stats.Add(stat3);
            Stat stat4 = CreateTestStat(affix4, 20);

            testEquipment.Stats.Add(stat4);

            List <int> fullPhysModsPhys  = _affixValueCalculator.GetAffixValues(AffixTypes.TotalPhysicalDps, testEquipment, AffixType.Meta, StatValueType.Flat);
            List <int> fullPhysModsTotal = _affixValueCalculator.GetAffixValues(AffixTypes.TotalDps, testEquipment, AffixType.Meta, StatValueType.Flat);

            Assert.AreEqual(352, fullPhysModsPhys[0]);
            Assert.AreEqual(352, fullPhysModsTotal[0]);
        }
Ejemplo n.º 18
0
        public void MetamodFlatElementalDamageTest()
        {
            Equipment testEquipment = new Equipment();
            ItemBase  itemBase      = new ItemBase();

            itemBase.Properties = new Dictionary <string, double>
            {
                { ItemProperties.MinDamage, 10 },
                { ItemProperties.MaxDamage, 30 },
                { ItemProperties.APS, 2 }
            };
            testEquipment.ItemBase = itemBase;

            Affix affix1 = CreateTestAffix(random, AffixGroupings.FlatChaosDamage, AffixType.Prefix);
            Affix affix2 = CreateTestAffix(random, AffixGroupings.FlatColdDamage, AffixType.Prefix);
            Affix affix3 = CreateTestAffix(random, AffixGroupings.FlatFireDamage, AffixType.Prefix);
            Affix affix4 = CreateTestAffix(random, AffixGroupings.FlatLightningDamage, AffixType.Prefix);

            Stat stat1 = CreateTestStat(affix1, 1, 10);

            testEquipment.Stats.Add(stat1);
            Stat stat2 = CreateTestStat(affix2, 10, 30);

            testEquipment.Stats.Add(stat2);
            Stat stat3 = CreateTestStat(affix3, 10, 20);

            testEquipment.Stats.Add(stat3);
            Stat stat4 = CreateTestStat(affix4, 20, 30);

            testEquipment.Stats.Add(stat4);

            List <int> eleDamagePhys      = affixValueCalculator.GetAffixValues(AffixNames.TotalPhysicalDps, testEquipment, AffixType.Meta, StatValueType.Flat);
            List <int> eleDamageEleDamage = affixValueCalculator.GetAffixValues(AffixNames.TotalElementalDps, testEquipment, AffixType.Meta, StatValueType.Flat);
            List <int> eleDamageTotal     = affixValueCalculator.GetAffixValues(AffixNames.TotalDps, testEquipment, AffixType.Meta, StatValueType.Flat);

            Assert.AreEqual(48, eleDamagePhys[0]);
            Assert.AreEqual(120, eleDamageEleDamage[0]);
            Assert.AreEqual(168, eleDamageTotal[0]);

            Affix affix5 = CreateTestAffix(AffixNames.LocalAttackSpeed, AffixType.Suffix);
            Stat  stat5  = CreateTestStat(affix5, 100);

            testEquipment.Stats.Add(stat5);

            List <int> eleDamageWithAttackSpeedPhys      = affixValueCalculator.GetAffixValues(AffixNames.TotalPhysicalDps, testEquipment, AffixType.Meta, StatValueType.Flat);
            List <int> eleDamageWithAttackSpeedEleDamage = affixValueCalculator.GetAffixValues(AffixNames.TotalElementalDps, testEquipment, AffixType.Meta, StatValueType.Flat);
            List <int> eleDamageWithAttackSpeedTotal     = affixValueCalculator.GetAffixValues(AffixNames.TotalDps, testEquipment, AffixType.Meta, StatValueType.Flat);

            Assert.AreEqual(96, eleDamageWithAttackSpeedPhys[0]);
            Assert.AreEqual(240, eleDamageWithAttackSpeedEleDamage[0]);
            Assert.AreEqual(336, eleDamageWithAttackSpeedTotal[0]);
        }
Ejemplo n.º 19
0
        private void NewAffix()
        {
            var vm = new EditAffixViewModel(_projectService.Project.Segmenter);

            if (_dialogService.ShowModalDialog(this, vm) == true)
            {
                var affix = new Affix(vm.StrRep, vm.Type == AffixViewModelType.Prefix ? AffixType.Prefix : AffixType.Suffix, vm.Category);
                _projectService.Project.Segmenter.Segment(affix);
                DomainVariety.Affixes.Add(affix);
                Messenger.Default.Send(new DomainModelChangedMessage(false));
                SelectedAffix = _affixes.Single(a => a.DomainAffix == affix);
            }
        }
Ejemplo n.º 20
0
        public static bool AddExplicit(IRandom random, Equipment item, Affix affix)
        {
            if (IsFull(item, affix))
            {
                return(false);
            }

            var stat = AffixToStat(random, item, affix);

            item.Stats.Add(stat);

            return(true);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Validly adds a suffix to the item.
        /// </summary>
        /// <param name="item"></param>
        public bool AddRandomSuffix(Item item)
        {
            Affix newSuffix = PoMAffixController.RollNewSuffix(this, item);

            if (newSuffix == null)
            {
                return(false);
            }

            AddAffix(newSuffix, item);

            UpdateName(item);
            return(true);
        }
Ejemplo n.º 22
0
        private Affix ModJsonToAffix(
            ModsJson modsJson,
            int modTier,
            TierType tierType)
        {
            Affix affix = new Affix();

            affix.GenerationType    = modsJson.GenerationType;
            affix.Group             = modsJson.Group;
            affix.Name              = modsJson.Name;
            affix.FullName          = modsJson.FullName;
            affix.RequiredLevel     = (int)modsJson.RequiredLevel;
            affix.Type              = modsJson.Type;
            affix.Tier              = modTier;
            affix.TierType          = tierType;
            affix.Tags              = _modTypeToTags[modsJson.Type];
            affix.AddsTags          = modsJson.AddsTags;
            affix.SpawnWeights      = modsJson.SpawnWeights.ToDictionary(x => x.Tag, x => (int)x.Weight);
            affix.GenerationWeights = modsJson.GenerationWeights.ToDictionary(x => x.Tag, x => (int)x.Weight);


            if (modsJson.Stats.Count > 0)
            {
                int sMin = (int)Math.Abs(modsJson.Stats[0].Min);
                int sMax = (int)Math.Abs(modsJson.Stats[0].Max);

                affix.StatMin1  = sMin <= sMax ? sMin : sMax;
                affix.StatMax1  = sMax >= sMin ? sMax : sMin;
                affix.StatName1 = modsJson.Stats[0].Id;
            }
            if (modsJson.Stats.Count > 1)
            {
                int sMin = (int)Math.Abs(modsJson.Stats[1].Min);
                int sMax = (int)Math.Abs(modsJson.Stats[1].Max);

                affix.StatMin2  = sMin <= sMax ? sMin : sMax;
                affix.StatMax2  = sMax >= sMin ? sMax : sMin;
                affix.StatName2 = modsJson.Stats[1].Id;
            }
            if (modsJson.Stats.Count > 2)
            {
                int sMin = (int)Math.Abs(modsJson.Stats[2].Min);
                int sMax = (int)Math.Abs(modsJson.Stats[2].Max);

                affix.StatMin3  = sMin <= sMax ? sMin : sMax;
                affix.StatMax3  = sMax >= sMin ? sMax : sMin;
                affix.StatName3 = modsJson.Stats[2].Id;
            }
            return(affix);
        }
Ejemplo n.º 23
0
        public void AffixNoPrefixesWhenFullMagicTest()
        {
            String item       = "Murderous Eye Jewel";
            String defaultTag = "abyss_jewel_melee";

            var          testItem   = _itemFactory.Jewel.First(x => x.Name == item);
            List <Affix> allAffixes = new List <Affix>();

            var p1 = GetTestAffix("test_p1", "test_p1", new Dictionary <string, int>()
            {
                { defaultTag, 100 }
            });

            p1.GenerationType = "prefix";

            var existing = new List <Affix>()
            {
                p1
            };

            allAffixes.AddRange(existing);

            for (int i = 0; i < 10; i++)
            {
                Affix affix = GetTestAffix("test_" + i, "test" + i, new Dictionary <string, int>()
                {
                    { defaultTag, 100 }
                });
                affix.GenerationType = i < 5 ? "prefix" : "suffix";
                allAffixes.Add(affix);
            }

            AffixManager affixManager = new AffixManager(testItem, allAffixes, new List <Affix>(), new Dictionary <Influence, List <Affix> >(), new Dictionary <Influence, string>());

            List <Affix> generated = new List <Affix>();
            IRandom      random    = SetupRandom().Object;

            var equipmentModifiers = new EquipmentModifiers(new List <Influence>(),
                                                            new List <string>(),
                                                            new List <string>(),
                                                            100,
                                                            new Dictionary <string, int>());

            for (var i = 0; i < 10; i++)
            {
                generated.Add(affixManager.GetAffix(equipmentModifiers, CurrencyModifier(), existing, EquipmentRarity.Magic, _random));
            }

            Assert.IsFalse(generated.Any(x => x.GenerationType == "prefix"));
        }
Ejemplo n.º 24
0
        public void GetFlatImplicitValueNotYetImplementedTest()
        {
            String    modName    = "testMod";
            int       testValue1 = 5;
            int       testValue2 = 10;
            int       testValue3 = 15;
            AffixType affixType  = AffixType.Implicit;

            Affix     affix         = CreateTestAffix(modName, affixType);
            Stat      stat          = CreateTestStat(testValue1, testValue2, testValue3, affix);
            Equipment testEquipment = CreateTestEquipment(stat);

            List <int> values = _affixValueCalculator.GetAffixValues(modName, testEquipment, affixType, StatValueType.Flat);
        }
Ejemplo n.º 25
0
    private void AddAffixIfModifierNotAdded(Affix affix, ref int amount)
    {
        foreach (Affix a in m_Affixes)
        {
            if (affix.type == a.type &&
                affix.modifier == a.modifier &&
                affix.modifier_type == a.modifier_type)
            {
                return;
            }
        }

        m_Affixes.Add(affix);
        amount++;
    }
Ejemplo n.º 26
0
    /// <summary>
    /// Removes an affix from the container
    /// </summary>
    public void Remove(Affix affix)
    {
        if (!affixTypeMap.ContainsKey(affix.Type))
        {
            throw new ArgumentException($"Could not find affix of type {affix.Type}", nameof(affix));
        }

        // This tries to remove and returns whether or not it was successful
        if (!affixTypeMap[affix.Type].Remove(affix))
        {
            throw new ArgumentException($"Could not find affix \"{affix}\"", nameof(affix));
        }

        PropagateRemove(affix);
    }
Ejemplo n.º 27
0
        /// <summary>
        /// Stem a latvian word. returns the new adjusted length.
        /// </summary>
        public virtual int Stem(char[] s, int len)
        {
            int numVowels = NumVowels(s, len);

            for (int i = 0; i < affixes.Length; i++)
            {
                Affix affix = affixes[i];
                if (numVowels > affix.vc && len >= affix.affix.Length + 3 && StemmerUtil.EndsWith(s, len, affix.affix))
                {
                    len -= affix.affix.Length;
                    return(affix.palatalizes ? Unpalatalize(s, len) : len);
                }
            }

            return(len);
        }
Ejemplo n.º 28
0
 public void RemoveAffix(Affix affix, Item item)
 {
     affix.RemoveAffix(item);
     affixes.Remove(affix);
     if (affix.IsPrefix)
     {
         prefixes.Remove(affix);
     }
     else
     {
         if (affix.IsSuffix)
         {
             suffixes.Remove(affix);
         }
     }
 }
        public static bool Parse(string str, out Affix affix, bool ignoreCase = false)
        {
            affix = Affix.None;

            foreach (var val in Enum.GetValues(typeof(Affix)))
            {
                var afx = (Affix)val;
                if (afx.ToString() == str || (ignoreCase && afx.ToString().ToLower() == str.ToLower()))
                {
                    affix = afx;
                    return(true);
                }
            }

            return(false);
        }
        public void MetamodOpenSuffixesTest()
        {
            String metaModName = AffixTypes.OpenSuffix;

            Affix     affix         = CreateTestAffix("testMod", AffixType.Suffix);
            Stat      stat          = CreateTestStat(affix, 5, 10);
            Equipment testEquipment = new Equipment();

            for (int i = 0; i < 4; i++)
            {
                List <int> values = _affixValueCalculator.GetAffixValues(metaModName, testEquipment, AffixType.Meta, StatValueType.Flat);
                Assert.AreEqual(3 - i, values[0]);
                Assert.AreEqual(1, values.Count);

                testEquipment.Stats.Add(stat);
            }
        }
Ejemplo n.º 31
0
        private void msp_SelectedAffixChanged(object sender, Affix aff)
        {
            var d = _monitor.Enter();
            var ms = sender as ModSelector;

            if (msp1 != ms)
                msp1.Affixes = _prefixes.Except(new[] { msp2.SelectedAffix, msp3.SelectedAffix }).ToList();

            if (msp2 != ms)
                msp2.Affixes = _prefixes.Except(new[] { msp1.SelectedAffix, msp3.SelectedAffix }).ToList();

            if (msp3 != ms)
                msp3.Affixes = _prefixes.Except(new[] { msp2.SelectedAffix, msp1.SelectedAffix }).ToList();
            _selectedPreff = new[] { msp1, msp2, msp3 }.Where(s => s.SelectedAffix != null).ToArray();
            d.Dispose();
        }
Ejemplo n.º 32
0
		public void AddOtherToAffix()
		{
			try
			{
				WordRecord wr = new WordRecord();
				m_gd.WordRecords.Add(wr);
				wr.Prefixes = new List<Affix>();
				Affix afx = new Affix();
				wr.Prefixes.Add(afx);

				afx.Other = m_otherTop;

				AddOtherContents();

				m_otherTop = m_gd.WordRecords[0].Prefixes[0].Other;

				CheckOtherContents();
			}
			finally
			{
				DeleteFile(m_fileName);
			}
		}
        public static bool Parse(string str, out Affix affix, bool ignoreCase = false)
        {
            affix = Affix.None;

            foreach (var val in Enum.GetValues(typeof(Affix)))
            {
                var afx = (Affix)val;
                if (afx.ToString() == str || (ignoreCase && afx.ToString().ToLower() == str.ToLower()))
                {
                    affix = afx;
                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 34
0
 public void ToString(String affixClass, char affixClassFlag, bool isCrossProduct, String expectedLineString)
 {
     Affix affix = new Affix(affixClass, affixClassFlag, isCrossProduct);
     Assert.AreEqual(expectedLineString, affix.ToString());
 }
Ejemplo n.º 35
0
        private void cbBaseSelection_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cbBaseSelection.SelectedItem == null)
            {
                Item = null;
                return;
            }

            SkipRedraw = true;
            msp1.Affixes = msp2.Affixes = msp3.Affixes = mss1.Affixes = mss1.Affixes = mss2.Affixes = mss3.Affixes = null;

            var ibase = ((ItemBase)cbBaseSelection.SelectedItem);
            var itm = ibase.CreateItem();
            Item = itm;

            if (ibase.ImplicitMods != null)
            {
                Affix implaff = new Affix(ibase.ImplicitMods.Select(s => s.Name).ToArray(), new[] { new ItemModTier("implicits", 0, ibase.ImplicitMods) });

                List<string> aliases = new List<string>();

                foreach (var mn in ibase.ImplicitMods)
                {
                    string mname = mn.Name.Replace("-", "").Replace("+", "");
                    var afm = Affix.AllAffixes.FirstOrDefault(a => a.Mod.Contains(mname));
                    if (afm != null)
                    {
                        var indx = afm.Mod.IndexOf(mname);
                        var al = afm.Aliases[indx].First();
                        aliases.Add(al);
                    }
                    else
                        aliases.Add(mn.Name);
                }

                implaff.Aliases = aliases.Select(a => new HashSet<string>() { a }).ToArray();


                msImplicitMods.Affixes = new List<Affix>() { implaff };
            }
            else
            {
                msImplicitMods.Affixes = null;
            }

            var aaff = Affix.AllAffixes.Where(a => a.ApplicableGear.Contains(itm.GearGroup)).ToArray();

            _prefixes = aaff.Where(a => a.IsPrefix).ToList();
            _suffixes = aaff.Where(a => a.IsSuffix).ToList();

            msp1.Affixes = msp2.Affixes = msp3.Affixes = _prefixes;
            mss1.Affixes = mss2.Affixes = mss3.Affixes = _suffixes;

            SkipRedraw = false;

        }
Ejemplo n.º 36
0
		internal void Convert(SqlCommand cmd, GAFAWSData gData, Dictionary<string, FwMsa> prefixes, Dictionary<string, List<FwMsa>> stems, Dictionary<string, FwMsa> suffixes)
		{
			if (!CanConvert)
				return;

			WordRecord wr = new WordRecord();
			// Deal with prefixes, if any.
			int startStemOrd = 0;
			foreach (KeyValuePair<int, FwMorphBundle> kvp in m_morphBundles)
			{
				FwMorphBundle mb = kvp.Value;
				string msaKey = mb.GetMsaKey(cmd);
				if (mb.MSA.Class == 5001 || mb.MSA.Class == 5031 || mb.MSA.Class == 5032 || mb.MSA.Class == 5117) // What about 5117-MoUnclassifiedAffixMsa?
				{
					// stem or derivational prefix, so bail out of this loop.
					startStemOrd = kvp.Key;
					break;
				}

				// Add prefix, if not already present.
				if (wr.Prefixes == null)
					wr.Prefixes = new List<Affix>();
				if (!prefixes.ContainsKey(msaKey))
				{
					prefixes.Add(msaKey, mb.MSA);
					gData.Morphemes.Add(new Morpheme(MorphemeType.prefix, msaKey));
				}
				Affix afx = new Affix();
				afx.MIDREF = msaKey;
				wr.Prefixes.Add(afx);
			}

			// Deal with suffixes, if any.
			// Work through the suffixes from the end of the word.
			// We stop when we hit the stem or a derivational suffix.
			int endStemOrd = 0;
			for (int i = m_morphBundles.Count; i > 0; --i)
			{
				FwMorphBundle mb = m_morphBundles[i];
				string msaKey = mb.GetMsaKey(cmd);
				if (mb.MSA.Class == 5001 || mb.MSA.Class == 5031 || mb.MSA.Class == 5032 || mb.MSA.Class == 5117) // What about 5117-MoUnclassifiedAffixMsa?
				{
					// stem or derivational suffix, so bail out of this loop.
					endStemOrd = i;
					break;
				}

				// Add suffix, if not already present.
				if (wr.Suffixes == null)
					wr.Suffixes = new List<Affix>();
				if (!suffixes.ContainsKey(msaKey))
				{
					suffixes.Add(msaKey, mb.MSA);
					gData.Morphemes.Add(new Morpheme(MorphemeType.suffix, msaKey));
				}
				Affix afx = new Affix();
				afx.MIDREF = msaKey;
				wr.Suffixes.Insert(0, afx);
			}

			// Deal with stem.
			List<FwMsa> localStems = new List<FwMsa>();
			string sStem = "";
			foreach (KeyValuePair<int, FwMorphBundle> kvp in m_morphBundles)
			{
				FwMorphBundle mb = kvp.Value;
				int currentOrd = kvp.Key;
				if (currentOrd >= startStemOrd && currentOrd <= endStemOrd)
				{
					string msaKey = mb.GetMsaKey(cmd);
					string spacer = (currentOrd == 1) ? "" : " ";
					sStem += spacer + msaKey;
				}
			}
			if (!stems.ContainsKey(sStem))
			{
				stems.Add(sStem, localStems);
				gData.Morphemes.Add(new Morpheme(MorphemeType.stem, sStem));
			}

			Stem stem = new Stem();
			stem.MIDREF = sStem;
			wr.Stem = stem;

			// Add wr.
			gData.WordRecords.Add(wr);
		}
Ejemplo n.º 37
0
		/// <summary>
		/// Do whatever it takes to convert the input this processor knows about.
		/// </summary>
		public void Convert()
		{
			string outputPathname = null;

			OpenFileDialog openFileDlg = new OpenFileDialog();

			openFileDlg.InitialDirectory = "c:\\";
			openFileDlg.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
			openFileDlg.FilterIndex = 2;
			openFileDlg.Multiselect = false;

			if (openFileDlg.ShowDialog() == DialogResult.OK)
			{
				string sourcePathname = openFileDlg.FileName;
				if (File.Exists(sourcePathname))
				{
					// Try to convert it.
					using (StreamReader reader = new StreamReader(sourcePathname))
					{
						string line = reader.ReadLine();
						Dictionary<string, bool> dictPrefixes = new Dictionary<string, bool>();
						Dictionary<string, bool> dictStems = new Dictionary<string, bool>();
						Dictionary<string, bool> dictSuffixes = new Dictionary<string, bool>();
						while (line != null)
						{
							line = line.Trim();
							if (line != String.Empty)
							{
								int openAngleLocation = line.IndexOf("<", 0);
								if (openAngleLocation < 0)
									continue;
								int closeAngleLocation = line.IndexOf(">", openAngleLocation + 1);
								if (closeAngleLocation < 0)
									continue;
								WordRecord wrdRec = new WordRecord();
								m_gd.WordRecords.Add(wrdRec);

								// Handle prefixes, if any.
								string prefixes = null;
								if (openAngleLocation > 0)
									prefixes = line.Substring(0, openAngleLocation);
								if (prefixes != null)
								{
									if (wrdRec.Prefixes == null)
										wrdRec.Prefixes = new List<Affix>();
									foreach (string prefix in prefixes.Split('-'))
									{
										if (prefix != null && prefix != "")
										{
											Affix afx = new Affix();
											afx.MIDREF = prefix;
											wrdRec.Prefixes.Add(afx);
											if (!dictPrefixes.ContainsKey(prefix))
											{
												m_gd.Morphemes.Add(new Morpheme(MorphemeType.prefix, prefix));
												dictPrefixes.Add(prefix, true);
											}
										}
									}
								}

								// Handle stem.
								string sStem = null;
								// Stem has content, so use it.
								sStem = line.Substring(openAngleLocation + 1, closeAngleLocation - openAngleLocation - 1);
								if (sStem.Length == 0)
									sStem = "stem";
								Stem stem = new Stem();
								stem.MIDREF = sStem;
								wrdRec.Stem = stem;
								if (!dictStems.ContainsKey(sStem))
								{
									m_gd.Morphemes.Add(new Morpheme(MorphemeType.stem, sStem));
									dictStems.Add(sStem, true);
								}

								// Handle suffixes, if any.
								string suffixes = null;
								if (line.Length > closeAngleLocation + 2)
									suffixes = line.Substring(closeAngleLocation + 1);
								if (suffixes != null)
								{
									if (wrdRec.Suffixes == null)
										wrdRec.Suffixes = new List<Affix>();
									foreach (string suffix in suffixes.Split('-'))
									{
										if (suffix != null && suffix != "")
										{
											Affix afx = new Affix();
											afx.MIDREF = suffix;
											wrdRec.Suffixes.Add(afx);
											if (!dictSuffixes.ContainsKey(suffix))
											{
												m_gd.Morphemes.Add(new Morpheme(MorphemeType.suffix, suffix));
												dictSuffixes.Add(suffix, true);
											}
										}
									}
								}
							}
							line = reader.ReadLine();
						}

						// Main processing.
						PositionAnalyzer anal = new PositionAnalyzer();
						anal.Process(m_gd);

						// Do any post-analysis processing here, if needed.
						// End of any optional post-processing.

						// Save, so it can be transformed.
						outputPathname = GetOutputPathname(sourcePathname);
						m_gd.SaveData(outputPathname);

						// Transform.
						XslCompiledTransform trans = new XslCompiledTransform();
						try
						{
							trans.Load(XSLPathname);
						}
						catch
						{
							MessageBox.Show("Could not load the XSL file.", "Information");
							return;
						}

						string htmlOutput = Path.GetTempFileName() + ".html";
						try
						{
							trans.Transform(outputPathname, htmlOutput);
						}
						catch
						{
							MessageBox.Show("Could not transform the input file.", "Information");
							return;
						}
						finally
						{
							if (outputPathname != null && File.Exists(outputPathname))
								File.Delete(outputPathname);
						}
						Process.Start(htmlOutput);
					} // end 'using'
				}
			}

			// Reset m_gd, in case it gets called for another file.
			m_gd = GAFAWSData.Create();
		}
Ejemplo n.º 38
0
        private void mss1_SelectedAffixChanged(object sender, Affix aff)
        {
            var ms = sender as ModSelector;
            List<Affix> exc = new List<Affix>();
            if (mss1 != ms)
                mss1.Affixes = _suffixes.Except(new[] { mss2.SelectedAffix, mss3.SelectedAffix }).ToList();

            if (mss2 != ms)
                mss2.Affixes = _suffixes.Except(new[] { mss1.SelectedAffix, mss3.SelectedAffix }).ToList();

            if (mss3 != ms)
                mss3.Affixes = _suffixes.Except(new[] { mss2.SelectedAffix, mss1.SelectedAffix }).ToList();

            _selectedSuff = new[] { mss1, mss2, mss3 }.Where(s => s.SelectedAffix != null).ToArray();

            RecalculateItem();
        }
Ejemplo n.º 39
0
        private void msp1_SelectedAffixChanged(object sender, Affix aff)
        {
            SkipRedraw = true;
            var ms = sender as ModSelector;
            List<Affix> exc = new List<Affix>();
            if (msp1 != ms)
                msp1.Affixes = _prefixes.Except(new[] { msp2.SelectedAffix, msp3.SelectedAffix }).ToList();

            if (msp2 != ms)
                msp2.Affixes = _prefixes.Except(new[] { msp1.SelectedAffix, msp3.SelectedAffix }).ToList();

            if (msp3 != ms)
                msp3.Affixes = _prefixes.Except(new[] { msp2.SelectedAffix, msp1.SelectedAffix }).ToList();
            _selectedPreff = new[] { msp1, msp2, msp3 }.Where(s => s.SelectedAffix != null).ToArray();
            SkipRedraw = false;
        }
Ejemplo n.º 40
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Convert the affix to the data layer.
		/// </summary>
		/// -----------------------------------------------------------------------------------
		internal override void Convert()
		{
			Affix afx = new Affix();
			LastRecord.Suffixes.Add(afx);
			m_dataLayerMorpheme = afx;
			base.Convert();
		}
Ejemplo n.º 41
0
        private void BaseSelection_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (BaseSelection.SelectedItem == null)
            {
                Item = null;
                return;
            }

            var d = _monitor.Enter();
            msp1.Affixes = msp2.Affixes = msp3.Affixes = mss1.Affixes = mss1.Affixes = mss2.Affixes = mss3.Affixes = null;

            var ibase = (ItemBase)BaseSelection.SelectedItem;
            Item = ibase.CreateItem();

            if (ibase.ImplicitMods.Any())
            {
                msImplicitMods.Affixes = new List<Affix>
                {
                    new Affix(ibase.ImplicitMods.Select(s => s.Name).ToArray(), new[] { new ItemModTier(ibase.ImplicitMods) })
                };
                Item.ImplicitMods = msImplicitMods.GetExactMods().ToList();
                ApplyLocals();
            }
            else
            {
                msImplicitMods.Affixes = null;
            }
            if (ibase.CanHaveQuality)
            {
                var qualityStat = new Stat(QualityModName, new Range<float>(0, 20), Item.ItemType, null);
                var qualityAffix = new Affix(new[] {QualityModName}, new[] {new ItemModTier(new[] {qualityStat})});
                MsQuality.Affixes = new List<Affix>(new[] {qualityAffix});
            }
            else
            {
                MsQuality.Affixes = null;
            }

            var aaff = _equipmentData.AffixesPerItemType[Item.ItemType].ToArray();

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

            msp1.Affixes = msp2.Affixes = msp3.Affixes = _prefixes;
            mss1.Affixes = mss2.Affixes = mss3.Affixes = _suffixes;
            msp3.Visibility = Item.ItemGroup == ItemGroup.Jewel ? Visibility.Hidden : Visibility.Visible;
            mss3.Visibility = Item.ItemGroup == ItemGroup.Jewel ? Visibility.Hidden : Visibility.Visible;

            d.Dispose();
        }