public static KeyValuePair <string, ParamsHolder> Compile(AbstractCondition condition, IDBTraits traits) { ConditionCompiler compiler = new ConditionCompiler(traits); string compiled = compiler.CompileCondition(condition); return(new KeyValuePair <string, ParamsHolder>(compiled, compiler.paramsholder)); }
public void AddCondition(AbstractCondition condition) { lock (_conditions) { _conditions.Add(condition); } }
protected virtual string CompileCondition(AbstractCondition clause) { var name = clause.GetType().Name; name = name.Substring(0, name.IndexOf("Condition")); var methodName = "Compile" + name + "Condition"; var clauseType = clause.GetType(); MethodInfo methodInfo = this.GetType().GetRuntimeMethods().Where(x => x.Name == methodName).FirstOrDefault(); if (methodInfo == null) { throw new Exception($"Failed to locate a compiler for {name}."); } if (clauseType.IsConstructedGenericType && methodInfo.GetGenericArguments().Any()) { methodInfo = methodInfo.MakeGenericMethod(clauseType.GenericTypeArguments); } var result = methodInfo.Invoke(this, new object[] { clause }); return(result as string); }
protected virtual string CompileCondition(SqlResult ctx, AbstractCondition clause) { var clauseType = clause.GetType(); var name = clauseType.Name; name = name.Substring(0, name.IndexOf("Condition")); var methodName = "Compile" + name + "Condition"; var methodInfo = FindCompilerMethodInfo(clauseType, methodName); try { var result = methodInfo.Invoke(this, new object[] { ctx, clause }); return(result as string); } catch (Exception ex) { throw new Exception($"Failed to invoke '{methodName}'", ex); } }
public InsertOrUpdateChange(ISqlObjectTableSpec tableSpec, Dictionary <string, AbstractFieldValue> dataToInsert, Dictionary <string, AbstractFieldValue> dataToUpdate, AbstractCondition condition) : base(tableSpec, (from kvp in dataToInsert select kvp.Value).Union(from kvp in dataToUpdate select kvp.Value)) { this.id = null; this.condition = condition; this.dataToInsert = dataToInsert; this.dataToUpdate = dataToUpdate; }
public InsertOrUpdateChange(ISqlObjectTableSpec tableSpec, Dictionary<string, AbstractFieldValue> dataToInsert, Dictionary<string, AbstractFieldValue> dataToUpdate, AbstractCondition condition) : base(tableSpec, (from kvp in dataToInsert select kvp.Value).Union(from kvp in dataToUpdate select kvp.Value)) { this.id = null; this.condition = condition; this.dataToInsert = dataToInsert; this.dataToUpdate = dataToUpdate; }
private void AddCondition(string name, AbstractCondition condition) { var node = new Node(); node.Text = name; node.Tag = condition; AddNode(node); }
public void ChildSatisfied(AbstractCondition child) { this.successes++; if (this.successes >= this.conditionCount) { this.parent.CompleteMission(3); this.parent.OnSuccessHook(); } }
public abstract void AddStarterDeck(); // Should be called at the start of character creation (for players) or at start of combat (for enemies.) public void StartTurn() { for (int i = 0; i < this.conditions.Count; i++) { AbstractCondition condition = this.conditions[i]; condition.StartTurn(); } conditions.RemoveAll(item => item == null); // Actually remove any conditions that marked themselves for removal. }
protected virtual string CompileCondition(AbstractCondition clause) { var name = clause.GetType().Name; name = name.Substring(0, name.IndexOf("Condition")); var methodName = "Compile" + name + "Condition"; return(dynamicCompile(methodName, clause)); }
public DynamicCommandBindingTrigger(AbstractCondition condition, Func <object> getDataContext, TCommand command, object parameter = null) : base(condition) { Contract.Requires(condition != null); _getDataContext = getDataContext; _desiredCommand = command; _parameter = parameter; ConditionsMet += TriggerAction; }
internal void LoadController(XmlNodeList xmlNodeList, RuleController ruleController) { foreach (XmlNode xmlMainNode in xmlNodeList) { foreach (XmlNode xmlNode in xmlMainNode.ChildNodes) { if (xmlNode.Name.Equals("Rule")) { //We got our hands on a rule, lets load it. var rule = new Rule(); foreach (XmlNode childNode in xmlNode) { switch (childNode.Name) { case "Name": rule.Name = childNode.InnerText; break; case "Script": rule.Script = childNode.InnerText; break; case "MatchAll": rule.MatchAll = Convert.ToBoolean(childNode.InnerText); break; case "ShouldTarget": rule.ShouldTarget = (Target)Enum.Parse(typeof(Target), childNode.InnerText); break; case "Priority": rule.Priority = Convert.ToInt32(childNode.InnerText); break; case "Action": rule.LoadAction(childNode); break; default: AbstractCondition condition = LoadConditions(childNode); if (condition != null) { rule.AddCondition(condition); } break; } } ruleController.AddRule(rule); } } } }
private void StartCounting() { this.conditions = new List <AbstractCondition>(); this.conditionCount = this.parent.MissionVO.Conditions.Count; for (int i = 0; i < this.conditionCount; i++) { AbstractCondition abstractCondition = ConditionFactory.GenerateCondition(this.parent.MissionVO.Conditions[i], this, this.startingValues[this.parent.MissionVO.Conditions[i].Uid]); this.conditions.Add(abstractCondition); abstractCondition.Start(); } }
public CommandBindingTrigger(AbstractCondition condition, FrameworkElement element, TCommand command, object parameter = null) : base(condition) { Contract.Requires(condition != null && element != null); _desiredCommand = command; _parameter = parameter; ConditionsMet += TriggerAction; element.DataContextChanged += OnDataContextChanged; }
// Remove a condition from the user. This version is GENERALLY called from AbstractConditions once stacks reach 0 but may be invoked by certain cards that remove random debuffs. // Conditions that remove themselves via RemoveCondition() will be set to null instead of just removing themselves directly from here so that iteration isn't messed up after removing a condition. public void RemoveCondition(AbstractCondition cd) { cd.RemoveEffects(); for (int i = 0; i < this.conditions.Count; i++) { if (this.conditions[i] == cd) { this.conditions[i] = null; return; } } }
private void GenerateConditionIcons() { nextSlotPosition = transform.position; int i = 0; foreach (GameObject condition in conditions) { AbstractCondition con = condition.GetComponent <AbstractCondition>(); GameObject newIcon = Instantiate(con.Icon, nextSlotPosition, Quaternion.identity) as GameObject; i++; nextSlotPosition.x += i; newIcon.transform.parent = this.gameObject.transform; } }
public void EndTurn() { for (int i = 0; i < this.conditions.Count; i++) { AbstractCondition condition = this.conditions[i]; condition.EndTurn(); } conditions.RemoveAll(item => item == null); // Actually remove any conditions that marked themselves for removal. EndOfTurnDiscard(); // At the end of your turn, set your AP to 0, then gain AP equal to max AP, then draw 5 cards. this.curAP = 0; CombatManager.Instance.AddAction(new GainActionsAction(this, this.maxAP)); Draw(5 + drawModifier); }
private string CompileCondition(AbstractCondition condition) { if (condition is NotEmptyCondition) { return(CompileCondition((NotEmptyCondition)condition)); } else if (condition is EmptyCondition) { return(CompileCondition((EmptyCondition)condition)); } else { throw new NotSupportedException(); } }
private void AllConditions_NodeClick(object sender, TreeNodeMouseEventArgs e) { Node node = e.Node; if (node.Tag is AbstractCondition) { AllConditions.BeginUpdate(); selected = (AbstractCondition)node.Tag; ConditionEditor.Nodes.Clear(); foreach (Node conNode in selected.GetNodes()) { ConditionEditor.Nodes.Add(conNode); } AllConditions.EndUpdate(); } }
public void ChildSatisfied(AbstractCondition child) { if (!this.successes.Contains(child.GetConditionVo().Uid)) { this.successes.Add(child.GetConditionVo().Uid); } if (this.successes.Count >= this.conditionCount) { if (Service.Get <GameStateMachine>().CurrentState is HomeState) { this.parent.OnSuccessHook(); this.parent.CompleteMission(3); return; } Service.Get <EventManager>().RegisterObserver(this, EventId.GameStateChanged, EventPriority.Default); } }
private ConditionLibrary() { float startUp = Time.realtimeSinceStartup; Assembly assembly = typeof(AbstractCondition).Assembly; // Use reflection to grab all of the subclasses of AbstractCondition. // Definitely eats performance. But this *should* only be called once at the start of the game? Type[] conditionClasses = assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(AbstractCondition))).ToArray(); foreach (Type condition in conditionClasses) { // For each card that inherits from AbstractCondition, create one instance of it to grab the ID so we can form an ID -> class pairing. AbstractCondition instance = Activator.CreateInstance(condition) as AbstractCondition; table.Add(instance.ID, condition); } float endStartUp = Time.realtimeSinceStartup; Debug.Log("ConditionLibrary loaded definition of ALL conditions; took " + (endStartUp - startUp) + " seconds."); }
public bool CheckConditions() { GetPiecesFromSlots(); //Debug.Log(pieces.Count); bool AreAllConditionsMet = false; if (ArePiecesEqualToSlots() && pieces.Count > 0) { foreach (GameObject conditionObject in conditions) { AbstractCondition condition = conditionObject.GetComponent <AbstractCondition>(); if (condition.ConditionMet(pieces) == false) { return(AreAllConditionsMet); } } AreAllConditionsMet = true; } return(AreAllConditionsMet); }
// Add a condition to the user, or add stacks to the condition if the user already has it. public void AddCondition(string cID, int stacks) { AbstractCondition alreadyExists = this.FindCondition(cID); if (alreadyExists != null) { alreadyExists.stacks += stacks; alreadyExists.Recalculate(stacks); return; } // Condition is not currently on user; create a new condition and add its effects to the user. This works similarly to Deck.cs' 'AddCard()' method. Type newCondition = ConditionLibrary.Instance.Lookup(cID); if (newCondition == null) { return; } AbstractCondition newCd = Activator.CreateInstance(newCondition, this, stacks) as AbstractCondition; // Extra two arguments to CreateInstance supply the AbstractCharacter and stack count. newCd.ApplyEffects(); this.conditions.Add(newCd); }
public void GetMissionProgress(CampaignMissionVO mission, out int current, out int total) { if (!this.missions.ContainsKey(mission.Uid)) { current = 0; total = 1; } current = 0; total = 0; for (int i = 0; i < mission.Conditions.Count; i++) { Dictionary <string, int> counters = this.missions[mission.Uid].Counters; ConditionVO conditionVO = mission.Conditions[i]; int startingValue = (counters != null && counters.ContainsKey(conditionVO.Uid)) ? counters[conditionVO.Uid] : 0; AbstractCondition abstractCondition = ConditionFactory.GenerateCondition(conditionVO, null, startingValue); int num; int num2; abstractCondition.GetProgress(out num, out num2); current += num; total += num2; abstractCondition.Destroy(); } }
/// <summary> /// Initialise an input trigger with the given condition. /// </summary> /// <param name = "condition"></param> public EventTrigger(AbstractCondition condition) { _inputCondition = condition; Enabled = true; }
public ConditionDecisionNode(AbstractCondition condition, FlowElement <T> master) : base(master) { this.condition = condition; }
public void ChildUpdated(AbstractCondition child, int delta) { }
public static List<string> LoadIdsByConditions(this IDBConnection connection, ITableSpec table, AbstractCondition conditions, Diapasone diapasone, params JoinSpec[] joins) { return connection.LoadIdsByConditions(table, conditions, diapasone, joins, new SortSpec[] { new SortSpec(table.getIdSpec(), true) }); }
public static List<string> LoadIdsByConditions(this IDBConnection connection, ITableSpec table, AbstractCondition conditions, Diapasone diapasone, ColumnSpec idSpec, params SortSpec[] sorts) { return connection.LoadIdsByConditions(table, conditions, diapasone, new JoinSpec[0], sorts, idSpec, false); }
public void ChildUpdated(AbstractCondition child, int delta) { this.parent.UpdateCounter(child.GetConditionVo().Uid, delta); }
private string CompileCondition(AbstractCondition condition) { if(condition is NotEmptyCondition) { return CompileCondition((NotEmptyCondition)condition); } else if(condition is EmptyCondition) { return CompileCondition((EmptyCondition)condition); } else { throw new NotSupportedException(); } }
public void ChildFailed(AbstractCondition child) { }
public static KeyValuePair<string, ParamsHolder> Compile(AbstractCondition condition, IDBTraits traits) { ConditionCompiler compiler = new ConditionCompiler(traits); string compiled = compiler.CompileCondition(condition); return new KeyValuePair<string,ParamsHolder>(compiled, compiler.paramsholder); }
public void InitializeTest() { InputController = new WTC.InputController(); AlwaysTrue = new DelegateCondition(() => true); }
public static List<string> LoadIdsByConditions(this IDBConnection connection, ITableSpec table, AbstractCondition conditions, Diapasone diapasone, JoinSpec[] joins, SortSpec[] sorts) { return connection.LoadIdsByConditions(table, conditions, diapasone, joins, sorts, table.getIdSpec(), false); }
public ActivityRule(AbstractCondition condition, AbstractActivity activity) : base(condition) { this.activity = activity; }