private IEnumerable <Transition> GetCopyTransitions(string sourceId, XElement copyElement) { var transitions = new List <Transition>(); var copyId = copyElement.Attribute("id").Value; //var empty = copyElement.Attribute("empty")?.Value.Equals("true") ?? false; IEnumerable <Transition> list = _graph.GetTransitions(copyId); //Create new copies, because sourceId is different foreach (var transition in list) { transitions.Add(new Transition(sourceId, transition.Target, ConditionContainer.EmptyContainer(), transition.Empty)); } var removeElements = copyElement.Descendants("removeTarget"); foreach (var removeElement in removeElements) { var removeId = removeElement.Attribute("id").Value; transitions.RemoveAll(x => x.Target == removeId); } //var replaceElements = copyElement.Descendants("replaceTarget"); //foreach (var replaceElement in replaceElements) //{ // var oldId = replaceElement.Attribute("old").Value; // var newId = replaceElement.Attribute("new").Value; // transitions.RemoveAll(x => x.Target == oldId); // transitions.Add(new Transition(sourceId, newId, ConditionContainer.EmptyContainer())); //} return(transitions); }
private static Transformation ReadTransform(XmlNode transformNode) { string morpheme = transformNode.Attributes["morpheme"].InnerText; string actionName = transformNode.Attributes["action"].InnerText; string operandOne = transformNode.Attributes["operandOne"] != null ? transformNode.Attributes["operandOne"].InnerText : ""; string operandTwo = transformNode.Attributes["operandTwo"] != null ? transformNode.Attributes["operandTwo"].InnerText : ""; string flag = transformNode.Attributes["flag"] != null ? transformNode.Attributes["flag"].InnerText : ""; BaseAction action = ActionFactory.Create(actionName, _alphabet, operandOne, operandTwo, flag); ConditionContainer conditions = ConditionContainer.EmptyContainer(); if (transformNode.HasChildNodes) { conditions = ReadConditionContainer(transformNode.FirstChild); } return(new Transformation(action, morpheme, conditions)); }
private double GetEleDamage(ConditionContainer a) { var prefixes = a.Affixes.Where(x => x.Type == AffixType.Prefix).ToList(); var chaos = (GetMaxPropertyValue(prefixes, AffixGroupings.FlatChaosDamage) + GetMaxPropertyValue(prefixes, AffixGroupings.FlatChaosDamage, 1)) / 2; var cold = (GetMaxPropertyValue(prefixes, AffixGroupings.FlatColdDamage) + GetMaxPropertyValue(prefixes, AffixGroupings.FlatColdDamage, 1)) / 2; var fire = (GetMaxPropertyValue(prefixes, AffixGroupings.FlatFireDamage) + GetMaxPropertyValue(prefixes, AffixGroupings.FlatFireDamage, 1)) / 2; var lightning = (GetMaxPropertyValue(prefixes, AffixGroupings.FlatLightningDamage) + GetMaxPropertyValue(prefixes, AffixGroupings.FlatLightningDamage, 1)) / 2; var eleList = new List <int> { chaos, cold, fire, lightning }; eleList = eleList.OrderByDescending(x => x).ToList(); eleList = eleList.Take(3).ToList(); return(eleList.Sum()); }
private double BaseDamage(ConditionContainer a) { var minPhysDamage = a.ItemBase.Properties.ContainsKey(ItemProperties.MinDamage) ? a.ItemBase.Properties[ItemProperties.MinDamage] : 0; var maxPhysDamage = a.ItemBase.Properties.ContainsKey(ItemProperties.MaxDamage) ? a.ItemBase.Properties[ItemProperties.MaxDamage] : 0; return((minPhysDamage + maxPhysDamage) / 2); }
private double GetAttackSpeed(ConditionContainer a) { var addedAttackSpeed = 1 + GetMaxPropertyValue(a.Affixes, AffixNames.LocalAttackSpeed) / 100f; var baseAttackSpeed = a.ItemBase.Properties.ContainsKey(ItemProperties.APS) ? a.ItemBase.Properties[ItemProperties.APS] : 0; return(baseAttackSpeed * addedAttackSpeed); }
public RoleCharacterDictionnary involvedCharacter; //creates more serialization problems. At this point it's just worthwhile to make custom editor code for the whole thing. public Goal(ConditionContainer _target, ConditionContainer _discardConditions, RoleCharacterDictionnary _characters, float _importance) { importance = _importance; targetConditions = _target; DiscardConditions = _discardConditions; involvedCharacter = _characters; }
private static ConditionContainer GetConditionContainer(XElement singleElement) { XElement conditionsElement; //try //{ // conditionsElement = singleElement.Descendants("conditions").First(); //} //catch(Exception) //{ // return ConditionContainer.EmptyContainer(); //} if (singleElement.Descendants("conditions").Any()) { conditionsElement = singleElement.Descendants("conditions").First(); } else { return(ConditionContainer.EmptyContainer()); } string flag = conditionsElement.Attribute("flag").Value; return(new ConditionContainer(GetConditions(conditionsElement.Descendants("condition")), flag)); }
public IList <IValidable> Resolve(ConditionContainerDTO source, ConditionContainer destination, IList <IValidable> destMember, ResolutionContext context) { IList <IValidable> list = new List <IValidable>(); var types = AssemblyHelper.GetAllTypes <IValidable>(); foreach (var condition in source.Conditions) { var conditionType = types.FirstOrDefault(c => c.Name.IndexOf(condition.Type) > -1); var cons = conditionType.GetConstructors().FirstOrDefault(); var args = new List <object>(); foreach (var parameter in cons.GetParameters()) { args.Add(context.ConfigurationProvider.ServiceCtor(parameter.ParameterType)); } if (conditionType != null) { list.Add((IValidable)cons.Invoke(args.ToArray())); } } return(list); }
public Transition(string source, string target, ConditionContainer conditions, bool empty = false) { Source = source; Target = target; Conditions = conditions; Id = Source + Delim + Target; Empty = empty; }
public Transformation(BaseAction action, String location, ConditionContainer conditionContainer) { _action = action; _conditionContainer = conditionContainer; if (!Enum.TryParse(location, out _location)) { throw new ArgumentException("Invalid Morpheme Location: " + location); } }
private int GetDefenseConditionValue(ConditionContainer a, string propertyName, string flatDefenseName, List <string> percentDefensesNames, List <string> hybridDefenseNames) { var baseDefense = a.ItemBase.Properties.ContainsKey(propertyName) ? a.ItemBase.Properties[propertyName] : 0; var flatDefense = GetMaxPropertyValue(a.Affixes, flatDefenseName); var percentDefense = GetMaxPropertyValue(a.Affixes, percentDefensesNames); var hybridDefense = GetMaxPropertyValue(a.Affixes, hybridDefenseNames); return((int)((baseDefense + flatDefense) * (120 + percentDefense + hybridDefense) / 100)); }
public List <int> GetAffixValues(string mod, Equipment item, AffixType type, StatValueType valueType) { var conditionItem = new ConditionContainer() { ItemBase = item.ItemBase, Affixes = item.Stats.Select(x => AffixToItemProperty(x.Affix, valueType, x.Values)).ToList() }; return(GetAffixValue(mod, type, conditionItem)); }
public List <int> GetModMax(string modType, ItemBase itemBase, List <Affix> affixes, AffixType type) { var max = StatValueType.Max; var conditionItem = new ConditionContainer { ItemBase = itemBase, Affixes = affixes.Select(x => AffixToItemProperty(x, max)).ToList() }; return(GetAffixValue(modType, type, conditionItem)); }
private int GetTotalDamage(ConditionContainer a) { var physicalDamage = GetPhysicalDamage(a); var eleDamage = GetEleDamage(a); // Calculating the best 3 out of all the possible affixes could be tricky so I cheat a little // When analyzing all possible affixes, I expect that either full phys or full elemental will be better return(IsGeneratedItem(a.Affixes.Count) ? (int)(physicalDamage + eleDamage) : (int)Math.Max(eleDamage, physicalDamage)); }
public static Condition ForType(Type type, ConditionContainer conditions, string propertyName) { if (type == typeof(bool)) return new ConditionBoolean(conditions, propertyName); if (type == typeof(float)) return new ConditionSingle(conditions, propertyName); if (type == typeof(int)) return new ConditionInteger(conditions, propertyName); throw new ArgumentException(string.Format("There is no condition for type {0}.", type), "type"); }
private double GetPhysicalDamage(ConditionContainer a) { var prefixes = a.Affixes.Where(x => x.Type == AffixType.Prefix).ToList(); var percentDamage = GetMaxPropertyValue(prefixes, AffixNames.LocalPhysicalPercent) + GetMaxPropertyValue(prefixes, AffixNames.LocalPhysicalHybrid); var physical = (GetMaxPropertyValue(prefixes, AffixGroupings.FlatPhysicalDamage) + GetMaxPropertyValue(prefixes, AffixGroupings.FlatPhysicalDamage, 1)) / 2; double baseDamage = BaseDamage(a); return((baseDamage + physical) * (120 + percentDamage) / 100); }
private static IEnumerable <Transition <string> > GetSingleTransitions(string sourceId, IEnumerable <XElement> singleElements) { var transitions = new List <Transition <string> >(); foreach (XElement singleElement in singleElements) { string targetId = singleElement.Attribute("id").Value; ConditionContainer conditions = GetConditionContainer(singleElement); //Graph.AddVertex(targetId); transitions.Add(new Transition <string>(sourceId, targetId, conditions)); } return(transitions); }
public async Task Validate_WhenEmptyExpression_ShouldAddANDExpressionAndValidate() { var c1 = Mock.Of <IValidable>(); var c2 = Mock.Of <IValidable>(); Mock.Get(c1).Setup(c => c.Validate()).ReturnsAsync(true); Mock.Get(c2).Setup(c => c.Validate()).ReturnsAsync(true); var container = new ConditionContainer(); container.Conditions.Add(c1); container.Conditions.Add(c2); var result = await container.Validate(); Assert.IsTrue(result); }
public async Task Validate_WithProperExpression_ShouldValidate() { var c1 = Mock.Of <IValidable>(); var c2 = Mock.Of <IValidable>(); Mock.Get(c1).Setup(c => c.Validate()).ReturnsAsync(true); Mock.Get(c2).Setup(c => c.Validate()).ReturnsAsync(false); var container = new ConditionContainer(); container.Conditions.Add(c1); container.Conditions.Add(c2); container.Expression = "C1 and (not C2)"; var result = await container.Validate(); Assert.IsTrue(result); }
private ConditionContainer GetConditionContainer(XElement singleElement) { XElement conditionsElement; if (singleElement.Descendants("conditions").Any()) { conditionsElement = singleElement.Descendants("conditions").First(); } else { return(ConditionContainer.EmptyContainer()); } var flag = conditionsElement.Attribute("flag").Value; return(new ConditionContainer(GetConditions(conditionsElement.Descendants("condition")), flag)); }
public ConditionContainer MapToParams(IList <Condition> conditions) { var container = new ConditionContainer(); IList <int> asd = new List <int>(); foreach (var cond in conditions) { if (cond != null) { container.SourceDeviceTypes += (int)cond.SourceDeviceType + ";"; container.SourceDeviceNames += cond.SourceDeviceName + ";"; container.TargetDeviceNames += cond.TargetDeviceName + ";"; container.RequiredValues += cond.RequiredValue + ";"; container.ConditionTypes += (int)cond.ConditionType + ";"; container.TargetValues += cond.TargetValue + ";"; } } return(container); }
private IEnumerable <Transition> GetGroupTransitions(string sourceId, XElement groupElement) { var transitions = new List <Transition>(); var groupId = groupElement.Attribute("id").Value; var group = _suffixGroupElements.FirstOrDefault(x => x.Id == groupId); if (group == null) { _trace.TraceEvent(TraceEventType.Error, 1, $"Group not found: {groupId}"); return(transitions); } foreach (var suffix in group.Suffixes) { transitions.Add(new Transition(sourceId, suffix.Value, ConditionContainer.EmptyContainer())); } var removeElements = groupElement.Descendants("removeTarget"); foreach (var removeElement in removeElements) { var removeId = removeElement.Attribute("id").Value; transitions.RemoveAll(x => x.Target == removeId); } //var replaceElements = groupElement.Descendants("replaceTarget"); //foreach (var replaceElement in replaceElements) //{ // var oldId = replaceElement.Attribute("old").Value; // var newId = replaceElement.Attribute("new").Value; // transitions.RemoveAll(x => x.Target == oldId); // transitions.Add(new Transition(sourceId, newId, ConditionContainer.EmptyContainer())); //} //var editElements = copyElement.Descendants("edit"); return(transitions); }
private static List <int> GetAffixValue(string mod, AffixType type, ConditionContainer a) { if (type == AffixType.Prefix || type == AffixType.Suffix) { return(a.Affixes .Where(x => x.Type == type) .Where(x => x.Group == mod) .OrderByDescending(x => x.Values.Count < 1 ? 0 : x.Values[0]) .ThenByDescending(x => x.Values.Count < 2 ? 0 : x.Values[1]) .ThenByDescending(x => x.Values.Count < 3 ? 0 : x.Values[2]) .FirstOrDefault()?.Values ?? new List <int>()); } if (type == AffixType.Meta) { MetaAffixValueCalculator calculator = new MetaAffixValueCalculator(); return(new List <int> { calculator.GetMetaConditionValue(mod, a) }); } throw new NotImplementedException($"Affix type {Enum.GetName(typeof(AffixType), type)} has not yet been implemented"); }
private Transformation ReadTransform(XmlNode transformNode) { var morpheme = transformNode.Attributes["morpheme"].InnerText; var actionName = transformNode.Attributes["action"].InnerText; var operandOne = transformNode.Attributes["operandOne"]?.InnerText ?? ""; var operandTwo = transformNode.Attributes["operandTwo"]?.InnerText ?? ""; var flag = transformNode.Attributes["flag"]?.InnerText ?? ""; var action = ActionFactory.Create(actionName, _alphabet, operandOne, operandTwo, flag); var conditions = ConditionContainer.EmptyContainer(); if (transformNode.HasChildNodes) { conditions = ReadConditionContainer(transformNode.FirstChild); } return(new Transformation(action, morpheme, conditions)); }
private int GetDefenseConditionValue( ConditionContainer a, string propertyName, List <string> flatDefenseNames, List <string> flatHybridNames, List <string> percentDefensesNames, List <string> hybridDefenseNames, List <string> percentDefenseNamesSuffix) { var baseDefense = a.ItemBase.Properties.ContainsKey(propertyName) ? a.ItemBase.Properties[propertyName] : 0; var flatDefense = GetMaxPropertyValue(a.Affixes, flatDefenseNames); var hybridFlatDefense = GetMaxPropertyValue(a.Affixes, flatHybridNames); var percentDefense = GetMaxPropertyValue(a.Affixes, percentDefensesNames); var hybridPercentDefense = GetMaxPropertyValue(a.Affixes, hybridDefenseNames); var percentDefenseSuffix = GetMaxPropertyValue(a.Affixes, percentDefenseNamesSuffix); // Take 3 main mods if >3 prefixes are provided if (flatDefense != 0 && hybridPercentDefense != 0 && percentDefense != 0 && hybridPercentDefense != 0) { return((int)((baseDefense + flatDefense) * (120 + percentDefense + hybridPercentDefense) / 100)); } return((int)((baseDefense + flatDefense + hybridFlatDefense) * (120 + percentDefense + hybridPercentDefense + percentDefenseSuffix) / 100)); }
public ConditionEnum(ConditionContainer conditions, string propertyName) : base(conditions, propertyName) { }
public ConditionDateTime(ConditionContainer conditions) : base(conditions) { }
public ConditionDateTime(ConditionContainer conditions, string propertyName) : base(conditions, propertyName) { }
public ConditionAvgAggregate(ConditionContainer conditions, string propertyName) : base(conditions, propertyName) { }
public ConditionDecimal(ConditionContainer conditions, string propertyName) : base(conditions) { PropertyName = propertyName; }
public ConditionDouble(ConditionContainer conditions, string propertyName) : base(conditions, propertyName) { PropertyName = propertyName; }
public Actions Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver) { var dictionary = new Dictionary <string, IAction>(); var count = 0; while (reader.ReadIsInObject(ref count)) { var name = reader.ReadPropertyName(); var actionCount = 0; Time throttlePeriod = null; IAction action = null; string @foreach = null; int? maxIterations = null; TransformContainer transform = null; ConditionContainer condition = null; while (reader.ReadIsInObject(ref actionCount)) { var propertyName = reader.ReadPropertyNameSegmentRaw(); if (Fields.TryGetValue(propertyName, out var value)) { switch (value) { case 0: throttlePeriod = formatterResolver.GetFormatter <Time>() .Deserialize(ref reader, formatterResolver); break; case 1: action = formatterResolver.GetFormatter <EmailAction>() .Deserialize(ref reader, formatterResolver); break; case 2: action = formatterResolver.GetFormatter <WebhookAction>() .Deserialize(ref reader, formatterResolver); break; case 3: action = formatterResolver.GetFormatter <IndexAction>() .Deserialize(ref reader, formatterResolver); break; case 4: action = formatterResolver.GetFormatter <LoggingAction>() .Deserialize(ref reader, formatterResolver); break; case 5: action = formatterResolver.GetFormatter <SlackAction>() .Deserialize(ref reader, formatterResolver); break; case 6: action = formatterResolver.GetFormatter <PagerDutyAction>() .Deserialize(ref reader, formatterResolver); break; case 7: @foreach = reader.ReadString(); break; case 8: transform = formatterResolver.GetFormatter <TransformContainer>() .Deserialize(ref reader, formatterResolver); break; case 9: condition = formatterResolver.GetFormatter <ConditionContainer>() .Deserialize(ref reader, formatterResolver); break; case 10: maxIterations = reader.ReadInt32(); break; } } else { reader.ReadNextBlock(); } } if (action != null) { action.Name = name; action.ThrottlePeriod = throttlePeriod; action.Foreach = @foreach; action.MaxIterations = maxIterations; action.Transform = transform; action.Condition = condition; dictionary.Add(name, action); } } return(new Actions(dictionary)); }
public ConditionString(ConditionContainer conditions, string propertyName) : base(conditions) { PropertyName = propertyName; _likeValuesCaseIns = new List<string>(); }
public int GetMetaConditionValue(string modType, ConditionContainer a) { var prefixes = a.Affixes.Where(x => x.Type == AffixType.Prefix).ToList(); var suffixes = a.Affixes.Where(x => x.Type == AffixType.Suffix).ToList(); if (modType.Contains(AffixNames.OpenPrefix)) { return(prefixes.Count > 3 ? 3 : 3 - prefixes.Count); } if (modType.Contains(AffixNames.OpenSuffix)) { return(suffixes.Count > 3 ? 3 : 3 - suffixes.Count); } if (modType == AffixNames.TotalEnergyShield) { return(GetDefenseConditionValue(a, ItemProperties.EnergyShield, AffixNames.LocalEnergyShield, AffixGroupings.EnergyShieldPercent, AffixGroupings.HybridEnergyShieldPercent)); } if (modType == AffixNames.TotalArmor) { return(GetDefenseConditionValue(a, ItemProperties.Armour, AffixNames.LocalArmour, AffixGroupings.ArmourPercent, AffixGroupings.HybridArmourPercent)); } if (modType == AffixNames.TotalEvasion) { return(GetDefenseConditionValue(a, ItemProperties.Evasion, AffixNames.LocalEvasion, AffixGroupings.EvasionPercent, AffixGroupings.HybridEvasionPercent)); } if (modType == AffixNames.TotalResistances) { var resList = new List <int> { GetMaxPropertyValue(suffixes, AffixNames.ColdResist), GetMaxPropertyValue(suffixes, AffixNames.FireResist), GetMaxPropertyValue(suffixes, AffixNames.LightningResist), GetMaxPropertyValue(suffixes, AffixNames.ChaosResist), GetMaxPropertyValue(suffixes, AffixNames.AllResist) * 3 }; resList = resList.OrderByDescending(x => x).ToList(); resList = resList.Take(3).ToList(); return(resList.Sum()); } if (modType == AffixNames.TotalElementalResistances) { var resList = new List <int> { GetMaxPropertyValue(suffixes, AffixNames.ColdResist), GetMaxPropertyValue(suffixes, AffixNames.FireResist), GetMaxPropertyValue(suffixes, AffixNames.LightningResist), GetMaxPropertyValue(suffixes, AffixNames.AllResist) * 3 }; resList = resList.OrderByDescending(x => x).ToList(); resList = resList.Take(3).ToList(); return(resList.Sum()); } if (modType == AffixNames.TotalDps) { return(GetDps(GetTotalDamage(a), a)); } if (modType == AffixNames.TotalElementalDps) { return(GetDps(GetEleDamage(a), a)); } if (modType == AffixNames.TotalPhysicalDps) { return(GetDps(GetPhysicalDamage(a), a)); } throw new NotImplementedException($"The meta affix {modType} is not recognized"); }
private int GetDps(double flatDamage, ConditionContainer a) { return((int)(flatDamage * GetAttackSpeed(a))); }
public ConditionSingle(ConditionContainer conditions, string propertyName, Single criticalValue) : this(conditions, propertyName) { _criticalValue = criticalValue; }
public Condition(ConditionContainer conditions, string propertyName) { _conditions = conditions; PropertyName = propertyName; }
public Condition(ConditionContainer conditions) { _conditions = conditions; }
public ConditionInteger(ConditionContainer conditions, string propertyName) : base(conditions) { PropertyName = propertyName; }
protected ConditionNumericAbstract(ConditionContainer conditions, string propertyName) : base(conditions) { PropertyName = propertyName; }
public Transition(T source, T target) { Source = source; Target = target; Conditions = ConditionContainer.EmptyContainer(); }
public ConditionBoolean(ConditionContainer conditions, string propertyName) : base(conditions) { PropertyName = propertyName; }
protected ConditionNumericAbstract(ConditionContainer conditions) : base(conditions) { }
private async Task <bool> Reset(List <KeyValueModel> temp = null) { SelectConditions.Clear(); BangumiCollection.Clear(); _page = 1; _isEnd = false; HolderText.Visibility = Visibility.Visible; if (ConditionCollection.Count == 0) { var conditions = await _animeService.GetBangumiIndexConditionAsync(_type); if (conditions != null) { if (conditions.order != null) { var sort = new ConditionContainer() { field = "order", name = "排序", values = new List <ConditionItem>() }; foreach (var so in conditions.order) { var item = new ConditionItem() { name = so.name, keyword = so.field }; sort.values.Add(item); } ConditionCollection.Add(sort); } if (conditions.filter != null) { conditions.filter.ForEach(p => ConditionCollection.Add(p)); } } else { new TipPopup("筛选条件加载失败,请刷新").ShowError(); return(false); } } foreach (var item in ConditionCollection) { bool isPrepare = false; if (temp != null) { var source = temp.Where(p => p.Key == item.field).FirstOrDefault(); if (source != null) { var target = item.values.Where(p => p.keyword == source.Value).FirstOrDefault(); if (target != null) { item.SelectIndex = item.values.IndexOf(target); SelectConditions.Add(source); isPrepare = true; } } } if (!isPrepare) { item.SelectIndex = 0; var first = item.values.First(); SelectConditions.Add(new KeyValueModel(item.field, first.keyword)); } } return(true); }
public Transition(T source, T target, ConditionContainer conditions) { Source = source; Target = target; Conditions = conditions; }