public static bool Counter(ScriptCondition condition, ScriptExecutionContext context) { var counterName = condition.Arguments[0].StringValue; var op = (CounterOperator)condition.Arguments[1].IntValue.Value; var comparedValue = condition.Arguments[2].IntValue.Value; return(EvaluateOperator(context.Scripting.Counters[counterName], op, comparedValue)); }
public static ScriptingCondition Get(ScriptCondition condition) { if (!Conditions.TryGetValue(condition.ContentType, out var conditionFunction)) { // TODO: Implement this condition type. return(MiscConditions.False); } return(conditionFunction); }
public static MapScriptCondition Create(ScriptCondition condition, SceneSettings sceneSettings) { if (!Factories.TryGetValue(condition.ContentType, out var factory)) { // TODO: Implement this condition type. return(new FalseCondition()); } return(factory(condition, sceneSettings)); }
public static bool Flag(ScriptCondition condition, ScriptExecutionContext context) { var flagName = condition.Arguments[0].StringValue; var comparedFlagValue = condition.Arguments[1].IntValueAsBool; if (!context.Scripting.Flags.TryGetValue(flagName, out var flagValue)) { return(false); } return(flagValue == comparedFlagValue); }
public void TestCounter(ScriptingComparison comparison, int compareValue, bool expectedResult) { _fixture.Game.Scripting.Counters["MyCounter"] = 5; var condition = new ScriptCondition( ScriptConditionType.Counter, new ScriptArgument(ScriptArgumentType.CounterName, "MyCounter"), new ScriptArgument(ScriptArgumentType.Comparison, (int)comparison), new ScriptArgument(ScriptArgumentType.Integer, compareValue)); var result = _fixture.Game.Scripting.EvaluateScriptCondition(condition); Assert.Equal(expectedResult, result); }
/// <summary> /// Constructeur principal /// </summary> private FormsManager() { AnimationManagerContainer = new AnimationManagerContainer(); ResourcesManager = new ResourcesManager(); DialogManager = new DialogManager(); TriggerManager = new TriggerManager(); ItemManager = new ItemManager(); CharacterManager = new CharacterManager(); VariableManager = new VariableManager(); CoordsManager = new CoordsManager(); EventManager = new EventManager(); EventActions = new EventActions(); ScriptCondition = new ScriptCondition(); ScriptLoop = new ScriptLoop(); ScriptChoice = new ScriptChoice(); }
public void TestCounter(ScriptingComparison comparison, int compareValue, bool expectedResult) { var game = _fixture.GetGame(SageGame.CncGenerals); game.Scripting.SetCounterValue("MyCounter", 5); var condition = new ScriptCondition( ScriptConditionType.Counter, new ScriptArgument(ScriptArgumentType.CounterName, "MyCounter"), new ScriptArgument(ScriptArgumentType.Comparison, (int)comparison), new ScriptArgument(ScriptArgumentType.Integer, compareValue)); var result = game.Scripting.EvaluateScriptCondition(condition); Assert.Equal(expectedResult, result); }
/// <summary> /// Creates Game2. /// </summary> public GMGame CreateGame2() { //create conditions ACondition falseCond = new FalseCondition(); ACondition trueCond = new TrueCondition(); ScriptCondition<bool> scriptCond = new ScriptCondition<bool>(TestScriptConditionEvaulateBool, true); //create triggers ScriptTrigger<int> trigger1 = new ScriptTrigger<int>(2, 2, trueCond.Check, trueCond.Check, TestScriptFunctionInt, 1); ScriptTrigger<float> trigger2 = new ScriptTrigger<float>(5, 10, trueCond.Check, falseCond.Check, TestScriptFunctionFloat, 2.2f); ScriptTrigger<string> trigger3 = new ScriptTrigger<string>(1, 3, null, null, TestScriptFunctionString, "no conditions"); DialogTrigger trigger4 = new DialogTrigger(1, 3, scriptCond.Check, null, "myDialog"); //create games and add triggers GMGame game = new GMGame("game2"); game.AddTrigger(trigger1); game.AddTrigger(trigger2); game.AddTrigger(trigger3); game.AddTrigger(trigger4); return game; }
public static bool TimerExpired(ScriptCondition condition, ScriptExecutionContext context) { var timerName = condition.Arguments[0].StringValue; return(context.Scripting.Timers.IsTimerExpired(timerName)); }
private static void LoadScriptBlock(Level level, ScriptDef targetSD, XmlNode node, ScriptBlock root, string firstChildName = "") { if (node == null || root == null) { return; } var child = node.FirstChild; if (child == null) { return; } do { if (!firstChildName.Equals("")) { if (!child.Name.Equals(firstChildName, StringComparison.InvariantCultureIgnoreCase)) { Log.WriteInfo("Attention ! Impossible d'ajouter le scriptBlock : " + child.Name + " alors que le scriptBlock obligatoire est : " + firstChildName); continue; } } ScriptBlock scriptBlock = null; switch (child.Name.ToLower()) { case "action": { var a = child.Attributes?["a"]; if (a == null) throw new Exception(" le scriptBlock <action> ne contient pas d'action \"a\" !"); var p = child.Attributes?["p"]; if (p == null) throw new Exception(" le scriptBlock <action> ne contient pas de paramètres ! \"p\" "); var parameters = new List<string>(); var i = 1; do { parameters.Add(p.Value); ++i; } while ((p = child.Attributes?["p" + i]) != null); scriptBlock = new ScriptAction(level, a.Value, parameters); } break; case "update": { var delayA = child.Attributes?["delay"]; if (delayA == null) throw new Exception(" le scriptBlock <update> ne contient pas de delay"); double delay = 0.0; if (delayA.Value.Equals("$FRAME_RATE")) { delay = 1.0 / 60.0; } else { if (!double.TryParse(delayA.Value, out delay)) throw new Exception(" le scriptBlock <update> ne contient pas de delay valide !"); if (delay <= 0) throw new Exception(" le scriptBlock <update> ne contient pas un delay valide ! Il est plus petit ou égal à 0 !"); } scriptBlock = new ScriptUpdate(delay); LoadScriptBlock(level, targetSD, child, scriptBlock); } break; case "condition": { var varRefA = child.Attributes?["ref"]; var valueConditionA = child.Attributes?["value"]; if (varRefA == null || valueConditionA == null) throw new Exception(" le scriptBlock <condition> ne contient pas la référence vers la variable ou sa condition \"ref\" ou \"value\" !"); if (!targetSD.Variables.ContainsKey(varRefA.Value)) throw new Exception(" le scriptBlock <condition> utilise la variable : " + varRefA.Value + " alors qu'elle n'est pas définie dans <variables> !"); var variable = targetSD.Variables[varRefA.Value]; if (variable is int) { if (!int.TryParse(valueConditionA.Value, out var condition)) { throw new Exception(" dans le scriptBlock <condition>, la condition utilisée ne peut pas être convertie en nombre (int) !"); } scriptBlock = new ScriptCondition<int>(varRefA.Value, condition); } else if (variable is bool) { if (!bool.TryParse(valueConditionA.Value, out var condition)) { throw new Exception(" dans le scriptBlock <condition>, la condition utilisée ne peut pas être convertie en booléen (bool) !"); } scriptBlock = new ScriptCondition<bool>(varRefA.Value, condition); } else throw new Exception(" le scriptBlock <condition> utilise une variable dont le type est inconnu !"); LoadScriptBlock(level, targetSD, child, scriptBlock); } break; case "collision": { var dirSide = child.Attributes?["side"]; var typeRef = child.Attributes?["typeRef"]; if (dirSide == null || typeRef == null) throw new Exception(" le scriptBlock <collision> ne contient pas la direction \"side\" ou la référence \"typeRef\" !"); var sides = new List<PhysicsBody.CollisionSide>(); var rawSides = dirSide.Value.Split('|'); foreach (var rawSide in rawSides) { if (!Enum.TryParse<PhysicsBody.CollisionSide>(rawSide, out var side)) throw new Exception(" le scriptBlock <collision> contient une erreur ! Impossible de convertir : " + dirSide.Value + " en direction !"); sides.Add(side); } scriptBlock = new ScriptCollisionEvent(sides, typeRef.Value); LoadScriptBlock(level, targetSD, child, scriptBlock); } break; case "key": { var codeA = child.Attributes?["code"]; var justPressedA = child.Attributes?["justPressed"]; var upA = child.Attributes?["up"]; if (codeA == null) throw new Exception(" le scriptBlock <key> ne contient pas la touche \"code\""); if (!Enum.TryParse<Keyboard.Key>(codeA.Value, true, out var key)) { throw new Exception(" le scriptBlock <key> contient une touche qui n'existe pas ! : " + codeA.Value); } bool justPressed = false, up = false; if (justPressedA != null) { if (!bool.TryParse(justPressedA.Value, out justPressed)) throw new Exception(" le scriptBlock <key> contient des erreurs ! Impossible de convertir : " + justPressedA.Value + " en valeur booléenne !"); } if (upA != null) { if (!bool.TryParse(upA.Value, out up)) throw new Exception(" le scriptBlock <key> contient des erreurs ! Impossible de convertir : " + upA.Value + " en valeur booléenne !"); } scriptBlock = new ScriptInput(key, justPressed, up); LoadScriptBlock(level, targetSD, child, scriptBlock); } break; } if (scriptBlock == null) throw new Exception(" le script contient un scriptBlock inconnu !"); root.AddChild(scriptBlock); } while ((child = child.NextSibling) != null); }
public TimerExpiredCondition(ScriptCondition condition) { _timerName = condition.Arguments[0].StringValue; }
public FlagCondition(ScriptCondition condition) { _flagName = condition.Arguments[0].StringValue; _flagValue = condition.Arguments[1].IntValueAsBool; }
public static bool True(ScriptCondition condition, ScriptExecutionContext context) => true;
private bool VerifyCondition(ScriptCondition c) { bool returnValue = false; string comparisonValue = c.ComparisonValue; // if (c.Domain == Domains.HomeAutomation_HomeGenie && (c.Target == SourceModule.Scheduler || c.Target == SourceModule.Automation) && (c.Property == "Scheduler.TimeEvent" || c.Property == "Scheduler.CronEvent")) { return(HomeGenie.ProgramManager.SchedulerService.IsScheduling(DateTime.Now, c.ComparisonValue)); } // // if the comparison value starts with ":", then the value is read from another module property // eg: ":HomeAutomation.X10/B3/Level" // if (comparisonValue.StartsWith(":")) { string[] propertyPath = comparisonValue.Substring(1).Split('/'); comparisonValue = ""; if (propertyPath.Length >= 3) { string domain = propertyPath[0]; string address = propertyPath[1]; string propertyName = propertyPath[2]; var targetModule = HomeGenie.Modules.Find(m => m.Domain == domain && m.Address == address); if (targetModule == null) { // abbreviated path, eg: ":X10/B3/Level" targetModule = HomeGenie.Modules.Find(m => m.Domain.EndsWith("." + domain) && m.Address == address); } // if (targetModule != null) { var mprop = Utility.ModuleParameterGet(targetModule, propertyName); if (mprop != null) { comparisonValue = mprop.Value; } } } } // // the following "Programs.*" parameters are deprecated, just left for compatibility with HG < r340 // Also the target SourceModule.Automation is deprecated and left for compatibility with HG < 499 // ModuleParameter parameter = null; if (c.Domain == Domains.HomeAutomation_HomeGenie && (c.Target == SourceModule.Scheduler || c.Target == SourceModule.Automation)) { parameter = new ModuleParameter(); parameter.Name = c.Property; switch (parameter.Name) { case "Programs.DateDay": case "Scheduler.DateDay": parameter.Value = DateTime.Now.Day.ToString(); break; case "Programs.DateMonth": case "Scheduler.DateMonth": parameter.Value = DateTime.Now.Month.ToString(); break; case "Programs.DateDayOfWeek": case "Scheduler.DateDayOfWeek": parameter.Value = ((int)DateTime.Now.DayOfWeek).ToString(); break; case "Programs.DateYear": case "Scheduler.DateYear": parameter.Value = DateTime.Now.Year.ToString(); break; case "Programs.DateHour": case "Scheduler.DateHour": parameter.Value = DateTime.Now.Hour.ToString(); break; case "Programs.DateMinute": case "Scheduler.DateMinute": parameter.Value = DateTime.Now.Minute.ToString(); break; case "Programs.Date": case "Scheduler.Date": parameter.Value = DateTime.Now.ToString("YY-MM-dd"); break; case "Programs.Time": case "Scheduler.Time": parameter.Value = DateTime.Now.ToString("HH:mm:ss"); break; case "Programs.DateTime": case "Scheduler.DateTime": parameter.Value = DateTime.Now.ToString("YY-MM-dd HH:mm:ss"); break; //default: // Module module = homegenie.Modules.Find(m => m.Address == c.Target && m.Domain == c.Domain); // if (module != null) // parameter = module.Properties.Find(mp => mp.Name == c.Property); // break; } } else { Module module = HomeGenie.Modules.Find(m => m.Address == c.Target && m.Domain == c.Domain); if (module != null) { parameter = module.Properties.Find(mp => mp.Name == c.Property); } } if (parameter != null) { IComparable lvalue = parameter.Value; IComparable rvalue = comparisonValue; // double dval = 0; DateTime dtval = new DateTime(); // if (double.TryParse(parameter.Value.Replace(",", "."), NumberStyles.Float | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out dval)) { lvalue = dval; rvalue = double.Parse(comparisonValue.Replace(",", "."), NumberStyles.Float | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture); } else if (DateTime.TryParse(parameter.Value, out dtval)) { lvalue = dtval; rvalue = DateTime.Parse(comparisonValue); } // int comparisonresult = lvalue.CompareTo(rvalue); if (c.ComparisonOperator == ComparisonOperator.LessThan && comparisonresult < 0) { returnValue = true; } else if (c.ComparisonOperator == ComparisonOperator.Equals && comparisonresult == 0) { returnValue = true; } else if (c.ComparisonOperator == ComparisonOperator.GreaterThan && comparisonresult > 0) { returnValue = true; } } return(returnValue); }
//------------------------------------------------------------------------------ // Use this for initialization public void Awake() { WebPlayerDebugManager.addOutput ("Version build: " + buildTime, 1); dbModuleManager = DBModuleManager.Instance; if(useDBModule) StartCoroutine("addServiceURL"); //Debug.Log ("TWISTGame Awake"); base.Awake(); //------- TODO WORKAROUND ------- GameScenario gs = GameScenario.Instance; gs.currentDate = System.DateTime.Now; //Edit StartPoint System.DateTime startDate = GameScenario.Instance.currentDate; //WebPlayerDebugManager.addOutput("Get Current Date: " + startDate, 3); startDate = startDate.AddDays (-28); string text; text = i18n.Get("CP1_2_2", "004").Replace( "15.3.2014", startDate.Day + "." + startDate.Month + "." + startDate.Year ); i18n.Set("CP1_2_2", "004", text); //Edit EndPoint startDate = GameScenario.Instance.currentDate; startDate = startDate.AddDays (14); text = i18n.Get ("CP1_2_2", "004").Replace( "1.5.2014", startDate.Day + "." + startDate.Month + "." + startDate.Year ); i18n.Set ("CP1_2_2", "004", text); text = i18n.Get ("CP1_5_5", "001").Replace( "1.5.2014", startDate.Day + "." + startDate.Month + "." + startDate.Year ); i18n.Set ("CP1_5_5", "001", text); text = i18n.Get ("CP1_6_1", "001").Replace( "1.5.2014", startDate.Day + "." + startDate.Month + "." + startDate.Year ); i18n.Set ("CP1_6_1", "001", text); //SIMMode = false; //TWISTMode = true; SIMMode = SIM; TWISTMode = TWIST; SIMOptions = ActivateSimOptions; //------- /WORKAROUND ------- Log.Info("Starting TWISTBueBe..."); // We have two sub game games to the main game GMGameCP gameCP = new GMGameCP("CP"); gm.Add(gameCP); GMGameSIM gameSIM = new GMGameSIM("SIM"); gm.Add(gameSIM); /*GameObject objSIM = UIManager.Instance.GetHud("TimeLineSIM"); goSIM = objSIM.GetComponent<TimeLine>(); /*gm.Start ("CP"); gm.Get("CP").Pause();*/ //gm.Start ("SIM"); //gm.Get("SIM").Pause(); //gm.Start ("CP"); /* // get the view object GameObject objCP = UIManager.Instance.GetHud("TimeLineCP"); goCP = objCP.GetComponent<TimeLine>(); */ //create conditions ACondition falseCond = new FalseCondition(); ACondition trueCond = new TrueCondition(); ScriptCondition<bool> scriptCond = new ScriptCondition<bool>( TestScriptConditionEvaulateBool, true); //Log.Info("Number of screens:"+ui.NumberOfScreens); //Log.Assert(ui.NumberOfScreens > 0, // "No screen found! Did you tag any screen as UIScreen?"); // Log.Assert(startScreen, // "Missing start screen: '" // +startScreenName+"' for " // +gameObject.name); // //ui.ActivateScreen(startScreenName); // //startScreen.SetActive(true); }
}//TestScriptConditionEvaulateBool() //------------------------------------------------------------------------------ // Use this for initialization public void Awake() { Debug.Log ("AquaSphereMini awake."); WebPlayerDebugManager.addOutput ("Version build: " + buildTime, 1); dbModuleManager = DBModuleManager.Instance; if(useDBModule) StartCoroutine("addServiceURL"); base.Awake(); //------- TODO WORKAROUND ------- GameScenario gs = GameScenario.Instance; gs.currentDate = System.DateTime.Now; //Edit StartPoint System.DateTime startDate = GameScenario.Instance.currentDate; //WebPlayerDebugManager.addOutput( // "Get Current Date: " + startDate, 3); startDate = startDate.AddDays (-28); Log.Info("Starting AquaSphereMini..."); //create conditions ACondition falseCond = new FalseCondition(); ACondition trueCond = new TrueCondition(); ScriptCondition<bool> scriptCond = new ScriptCondition<bool>( TestScriptConditionEvaulateBool, true); }
public static bool False(ScriptCondition condition, ScriptExecutionContext context) => false;