private XElement SerializeAction(ActionInformation action) { var result = new XElement("Action"); result.Add(new XAttribute(Namespaces.XmlNs + "f", Namespaces.Function10.NamespaceName)); result.Add(new XAttribute("name", action.ConfigurationElement.Name)); foreach (var parameter in action.ParameterValues) { var profile = action.ParameterProfiles.Single(p => p.Name == parameter.Item1); object value = parameter.Item2; if (value == profile.GetDefaultValue()) { continue; } string serializedValue = (string)ValueTypeConverter.Convert(parameter.Item2, typeof(string)); result.Add(new XElement(Namespaces.Function10 + "param", new XAttribute("name", parameter.Item1), new XAttribute("value", serializedValue))); } return(result); }
private bool BindStateAndValidate(ActionInformation action, bool showWarnings) { if (_isInitialRequest || action.Initializing || !action.ParameterProfiles.Any()) { return(true); } action.Control.BindStateToControlProperties(); Dictionary <string, Exception> validationErrors = action.FormTreeCompiler.SaveAndValidateControlProperties(); if (showWarnings) { ShowServerValidationErrors(action.FormTreeCompiler, validationErrors); } foreach (var pair in action.FormTreeCompiler.BindingObjects) { var record = new Tuple <string, object>(pair.Key, pair.Value); var index = action.ParameterValues.FindIndex(p => p.Item1 == pair.Key); if (index != -1) { action.ParameterValues[index] = record; } else { action.ParameterValues.Add(record); } } return(validationErrors == null || validationErrors.Count == 0); }
private void BuildWidgets(ActionInformation action, PlaceHolder placeHolder, bool createEvenIfDisabled) { if (!action.Enabled && !createEvenIfDisabled) { return; } var bindings = new Dictionary <string, object>(); foreach (var parameterProfile in action.ParameterProfiles) { var loadedValue = action.ParameterValues.FirstOrDefault(p => p.Item1 == parameterProfile.Name); object parameterValue = loadedValue != null ? loadedValue.Item2 : parameterProfile.GetDefaultValue(); bindings.Add(parameterProfile.Name, parameterValue); } action.FormTreeCompiler = FunctionUiHelper.BuildWidgetForParameters( action.ParameterProfiles, bindings, "widgets", StringResourceSystemFacade.ParseString(action.ConfigurationElement.Label), WebManagementChannel.Identifier); action.Control = (IWebUiControl)action.FormTreeCompiler.UiControl; action.ControlPlaceHolder = placeHolder; var webControl = action.Control.BuildWebControl(); placeHolder.Controls.Add(webControl); }
private void LoadParameterValues(ActionInformation action) { var parameterValues = new List <Tuple <string, object> >(); if (action.Element != null) { foreach (XElement parameterNode in action.Element.Elements()) { string parameterName = (string)parameterNode.Attribute("name"); var parameterProfile = action.ParameterProfiles.FirstOrDefault(p => p.Name == parameterName); Verify.IsNotNull(parameterProfile, "There's no parameter named '{0}' on the function representing action '{1}'", parameterName, action.ConfigurationElement.Name); // TODO: Support for <f:paramelement ... /> string stringValue = (string)parameterNode.Attribute("value"); object value = ValueTypeConverter.Convert(stringValue, parameterProfile.Type); parameterValues.Add(new Tuple <string, object>(parameterName, value)); } } action.ParameterValues = parameterValues; }
public void ShowPath() { ActionInformation.Show("Movement", "0", "You know, lets you move"); Menu.Hide(); selected = Cursor.hovered; _path = Helpers.DeriveShortestPath(selected.xPos, selected.zPos, Unit.current.xPos, Unit.current.zPos, Unit.current); HighlightTiles(_path); }
public static bool IsUserAuthorized(UserCredentials creds, ActionInformation actionInfo) { var result = ServiceProxy.Execute <MySecurityService, bool> ( svc => svc.IsUserAuthorized(creds, actionInfo) ); return(result); }
/** * Plan what sequence of actions can fulfill the goal. * Returns null if a plan could not be found, or a list of the actions * that must be performed, in order, to fulfill the goal. */ public void plan(GameObject agent, HashSet <GoapAction> availableActions, HashSet <KeyValuePair <string, object> > worldState, HashSet <KeyValuePair <string, object> > goal) { // reset the actions so we can start fresh with them foreach (GoapAction a in availableActions) { a.doReset(); } // check what actions can run using their checkProceduralPrecondition HashSet <GoapAction> usableActions = new HashSet <GoapAction> (); foreach (GoapAction a in availableActions) { if (a.checkProceduralPrecondition(agent)) { usableActions.Add(a); } } // we now have all actions that can run, stored in usableActions // build up the tree and record the leaf nodes that provide a solution to the goal. List <Node> leaves = new List <Node>(); // build graph Node start = new Node(null, 0, worldState, null); List <ActionInformation> actionInfo = new List <ActionInformation>(); int i = 0; foreach (var item in usableActions) { ActionInformation info = new ActionInformation(); string o = "Type: " + item; Debug.Log(o); string output = o.Split('(', ')')[1]; info.type = output; Debug.Log(output); info.preconditions = item.Preconditions; info.effects = item.Effects; info.cost = item.cost; info.targetID = item.target.GetInstanceID(); Debug.Log(item.target.GetInstanceID()); actionInfo.Add(info); } // Send a message with usable actions, goal and ID to python via a public method from the goap agent GoapRequestObject requestObject = new GoapRequestObject(agent.GetComponent <GoapAgent>().ID, actionInfo, worldState, goal); string json = JsonConvert.SerializeObject(requestObject); agent.GetComponent <GoapAgent>().SendPlanRequestToServer(json); }
/// <summary> /// Submits the action. /// </summary> /// <returns>Returns 0 if action submission is successful. Returns 1 if a parameters is missing. Returns 2 if Post fails</returns> async Task <int> submitAction() { bool postSuccess = false; string msg = string.Empty; // CREATE A NEW CONTRACT if (string.IsNullOrEmpty(contractId)) { var newContractAction = new ActionInformation(); var values = getParametersForUpload(); if (values != null) { newContractAction.WorkflowActionParameters = values; newContractAction.WorkflowFunctionId = contractAction.Id; if (contractAction.Parameters == null) { return(1); } (postSuccess, msg) = await GatewayApi.Instance.CreateNewContractAsync(newContractAction, workflowId, App.ViewModel.CurrentApplication.Id.ToString(), connectionId); } else { return(1); } } else { var newContractAction = new ActionInformation(); newContractAction.WorkflowActionParameters = getParametersForUpload(); newContractAction.WorkflowFunctionId = contractAction.Id; if (newContractAction.WorkflowActionParameters == null) { return(1); } (postSuccess, msg) = await GatewayApi.Instance.PostWorkflowActionAsync(newContractAction, contractId); } if (!postSuccess) { Device.BeginInvokeOnMainThread(async() => { await DisplayAlert("Action Failed", msg, "OK"); }); return(2); } return(0); }
public static void RefreshPlayerView() { CursorController.HideAttackCursors(); CursorController.HideConfirmAttackCursors(); CursorController.ShowMoveCells(); CursorController.RefreshAlarmCursors(); SetState(State.PickAction); Menu.Refresh(); ActionInformation.Hide(); DeathInformation.Refresh(); MenuCamera.Refresh(); }
public async Task <string> CreateNewContractAsync(ActionInformation action, string workflowID, string contractCodeID, string connectionID) { var url = $"{BaseUrl}contracts?workflowId={workflowID}&contractCodeId={contractCodeID}&connectionId={connectionID}"; var(success, error) = await postDataObjectAsync(action, url); if (success) { return(string.Empty); } return(error); }
public async Task <string> PostWorkflowActionAsync(ActionInformation action, string contractID) { var url = $"{BaseUrl}contracts/{contractID}/actions"; var(success, error) = await postDataObjectAsync(action, url); if (success) { return(string.Empty); } return(error); }
// Update is called once per frame public static void Cancel() { ActionInformation.Hide(); if (GameController.state == GameController.State.PickAction && selected) { ResetPath(); } if (GameController.state == GameController.State.PickTarget || GameController.state == GameController.State.ConfirmTarget) { GameController.CancelAttack(); } }
private void LoadParameterProfiles(ActionInformation action) { XElement functionNode = action.ConfigurationElement.FunctionNode; string functionName = (string)functionNode.Attribute("name"); IFunction function = FunctionFacade.GetFunction(functionName); Verify.IsNotNull(function, "Failed to get C1 function '{0}'", functionName); List <string> predefinedParameterNames = functionNode.Elements().Select(el => (string)el.Attribute("name")).ToList(); action.ParameterProfiles = function.ParameterProfiles.Where(p => !predefinedParameterNames.Contains(p.Name)).ToArray(); }
static List <ActionInformation> LoadActions(XElement actionsElement, XElement disabledActionsElement) { var result = new List <ActionInformation>(); var definedActions = actionsElement.Elements().ToDictionary( handlerElement => (string)handlerElement.Attribute("name"), handlerElement => handlerElement); var disabledActions = disabledActionsElement.Elements().ToDictionary( handlerElement => (string)handlerElement.Attribute("name"), handlerElement => handlerElement); foreach (var action in FormBuilderConfiguration.GetActions()) { var info = new ActionInformation { ConfigurationElement = action }; if (definedActions.ContainsKey(action.Name)) { info.Enabled = true; info.Element = definedActions[action.Name]; definedActions.Remove(action.Name); } else if (disabledActions.ContainsKey(action.Name)) { info.Element = disabledActions[action.Name]; disabledActions.Remove(action.Name); } result.Add(info); } if (definedActions.Count > 0) { throw new InvalidOperationException("Action '{0}' is not defined in the FormBuilder configuration file".FormatWith(definedActions.Keys.First())); } return(result); }
public void DoAction(int x, int z, int actionIndex) { MainCamera.Lock(); MainCamera.CenterOnWorldPoint(Unit.current.transform.position); ActionInformation.Hide(); GameObject actionObject = Actions()[actionIndex]; UnitAction action = actionObject.GetComponent <UnitAction>(); Cursor cursor = CursorController.cursorMatrix[x][z]; GameObject actionDialogueObject = Instantiate(actionDialoguePrefab, transform.position, Quaternion.identity); actionDialogueObject.GetComponent <ActionDialogue>().message = action.Name(); actionDialogueObject.GetComponent <ActionDialogue>().unit = this; actionObject.GetComponent <UnitAction>().currentMp = currentMp; System.Action beginAction = () => { actionObject.GetComponent <UnitAction>().BeginAction(cursor.gameObject); }; currentMp -= action.MpCost(); actionDialogueObject.GetComponent <ActionDialogue>().whenDone = beginAction; LookToward(x, z); }
public static void ShowActionCursors(Unit unit, int actionIndex) { showingActionCursors = true; UnitAction action = unit.Actions()[actionIndex].GetComponent <UnitAction>(); ActionInformation.Show(action.Name(), action.MpCost().ToString(), action.actionType().ToString() + " -- " + action.Description()); Unit.Coordinate projectedCoordinate = unit.ProjectedCoordinate(); int xPos = projectedCoordinate.xPos; int zPos = projectedCoordinate.zPos; List <Cursor> tiles = Helpers.GetRadialTiles(xPos, zPos, action.MaxDistance(), action.MaxHeightDifference(), action.CanTargetOthers(), action.MinDistance(), action.HeightAssisted()); foreach (Cursor tile in tiles) { if (IsValidTarget(Unit.Subject(), action, tile, xPos, zPos)) { tile.SetAttack(); } } }
public void OnPointerEnter(PointerEventData eventData) { ActionInformation.Show(actionName, mpCost, description); }
public void OnPointerExit(PointerEventData eventData) { ActionInformation.Hide(); }
List <Atribute> BuildActionsAndAtributes() { Atribute fullness = new Atribute("Fullness", 0, 100, -3); Atribute awake = new Atribute("Awake", 0, 100, -1); Atribute relax = new Atribute("Relax", 0, 100, -1); Atribute clean = new Atribute("Clean", 0, 100, -1); Atribute money = new Atribute("Money", 0, 100, -2); Atribute energy = new Atribute("Energy", 0, 100, +1); Action action = new Action(new LogisticUtilityFunction("Fullness", 1, System.Math.E)); ActionInformation information = new ActionInformation("Eat", 4 * UPDATE_SECONDS); information.AddSpecialModifier(fullness, 10); actionInformation.Add(action, information); action = new Action(new LogitUtilityFunction("Awake", 1, System.Math.E)); information = new ActionInformation("Sleep", 8 * UPDATE_SECONDS); information.AddSpecialModifier(awake, 5); information.AddSpecialModifier(relax, 1); actionInformation.Add(action, information); action = new Action(new LinearUtilityFunction("Money", 0.8, 0.2)); information = new ActionInformation("Work", 6 * UPDATE_SECONDS); information.AddSpecialModifier(money, 8); information.AddSpecialModifier(relax, -4); actionInformation.Add(action, information); List <UtilityFunction> composedFunctions = new List <UtilityFunction> { new ConstantUtilityFunction(0), new LinearUtilityFunction("Stress", 2, -1.2) }; double[] cutPoints = new double[] { 0.6 }; action = new Action(new ComposedUtilityFunction("Relax", composedFunctions, cutPoints)); information = new ActionInformation("Exercise", 4 * UPDATE_SECONDS); information.AddSpecialModifier(relax, 15); information.AddSpecialModifier(clean, -5); information.AddSpecialModifier(energy, -10); actionInformation.Add(action, information); action = new Action(new ConstantUtilityFunction(0.3)); information = new ActionInformation("Watch TV", 2 * UPDATE_SECONDS); information.AddSpecialModifier(relax, 10); actionInformation.Add(action, information); action = new Action(new QuadraticUtilityFunction("Clean", 5, 0, 0)); information = new ActionInformation("Shower", 3 * UPDATE_SECONDS); information.AddSpecialModifier(clean, 40); actionInformation.Add(action, information); List <Atribute> atributes = new List <Atribute> { fullness, awake, relax, clean, money, energy }; return(atributes); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { try{ log.LogInformation("Getting Auth Token"); // Make a call to the GetAuthToken method we have defined. var authenticationToken = await GetAuthToken(log); // Using the .NET Workbench SDK, set the Auth token and the API URL // Documentation here: https://github.com/Azure-Samples/blockchain/tree/master/blockchain-workbench/rest-api-samples/dotnet GatewayApi.SiteUrl = API_URL; GatewayApi.Instance.SetAuthToken(authenticationToken); /* * FIRST - Check if use can create or access workbench API's - IE - Do they have a role set? * This will return FALSE the first time you try to run it, because we haven't set the role for our Function yet. * Nevertheless we have to call this at least ONCE so that workbench creates the ethereum account for our Azure Function. */ var canUserAccessWorkbench = await GatewayApi.Instance.CanCurrentUserCreateContractsForWorkflow(WORKFLOW_ID); if (!canUserAccessWorkbench) { return(new BadRequestObjectResult("You are not assigned a role in this blockchain account. Please speak with Administrator")); } // Read the request body. For the purposes of this example we'll just create a dynamic object that has the parameters we want string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject <object>(requestBody); if (string.IsNullOrEmpty(requestBody)) { return(new BadRequestObjectResult("Request Body is Empty")); } /* * Create a new contract using the Workbench SDK * All "Actions" have action information, and the functionID we're actually calling is set on the next line. */ var workflowAction = new ActionInformation(); workflowAction.WorkflowFunctionId = CONSTRUCTOR_ID; /* * Here, we'll set the parameters that our "contructor" function is expecting. * How do we know them? WE CREATED IT IN THE JSON file! * Otherwise - you can hit the API at /api/v1/applications/workflows/{workflowId} * and take a look at the CONSTRUCTOR, and what the "name" of the parameters are */ /* THE FOLLOWING IS FOR THE ASSET TRANSFER CONTRACT ON THE WORKBENCH GITHUB PAGE: * https://github.com/Azure-Samples/blockchain/tree/master/blockchain-workbench/application-and-smart-contract-samples/asset-transfer */ /***** NOTE: "PRICE" IS AN INTEGER TYPE AND THAT'S ASSUMED HERE. You will have to add your own type checking *****/ workflowAction.WorkflowActionParameters.Add(new WorkflowActionParameter() { Name = "description", Value = data?.description }); workflowAction.WorkflowActionParameters.Add(new WorkflowActionParameter() { Name = "price", Value = data?.price }); log.LogInformation(JsonConvert.SerializeObject(workflowAction)); /* * Tuples FTW :) * The SDK returns a success/failure result and also the body of the response. * In this case, the Create endpoint returns the ID of the contract */ var(success, newContractID) = await GatewayApi.Instance.CreateNewContractAsync(workflowAction, WORKFLOW_ID, CONTRACT_CODE_ID, CONNECTION_ID); log.LogInformation($"POST params: \nworkflowID:{WORKFLOW_ID}\ncontractCodeId:{CONTRACT_CODE_ID}\nConnectionID:{CONNECTION_ID}"); log.LogInformation("POST Result: " + success); if (success) { // Lets return the contractID of the new contract that was created! return((ActionResult) new OkObjectResult($"New Contract ID: {newContractID}")); } else { return(new BadRequestObjectResult($"Request Failed - please look at Function logs - error: {newContractID}")); } } catch (Exception e) { return(new BadRequestObjectResult(e.Message)); } }
public async Task <(bool, string)> CreateNewContractAsync(ActionInformation action, string workflowID, string contractCodeID, string connectionID) { var url = $"{BaseUrl}contracts?workflowId={workflowID}&contractCodeId={contractCodeID}&connectionId={connectionID}"; return(await postDataObjectAsync(action, url)); }
protected void LoadActionModifierInfo(ActionInformation actionInfo, XmlNode modifiersNode) { if (modifiersNode != null) { foreach (XmlNode node in modifiersNode.SelectNodes("./icons/icon")) { actionInfo.actionModifierSpriteNames.Add(node.InnerText); } } }
public void StartMoving() { ActionInformation.Hide(); GameController.StartMoving(this); MainCamera.Lock(); }
public void SetUnit(UnitConfig unitConfig, int index, ConfigTypes configType) { transform.Find("InfoPanel").Find("UnitName").GetComponent <Text>().text = unitConfig.unitName; transform.Find("InfoPanel").Find("UnitClass").GetComponent <Text>().text = unitConfig.unitClass.Name(); int i = 0; List <string> actions = unitConfig.unitClass.Actions(); List <string> unitActions = unitConfig.actions; if (configType == ConfigTypes.Stance) { actions = unitConfig.unitClass.Stances(); unitActions = unitConfig.stances; } foreach (Transform entry in transform.Find("Grid")) { bool enableClick = true; int c = i; entry.GetComponent <Button>().onClick.RemoveAllListeners(); if (i < actions.Count) { entry.gameObject.active = true; string label = ""; string description = ""; string mpCost = ""; if (configType == ConfigTypes.Stance) { label = unitConfig.stanceMap[actions[c]].Name(); description = unitConfig.stanceMap[actions[c]].Description(); mpCost = "0"; } else { UnitAction action = unitConfig.actionMap[actions[c]]; label = unitConfig.actionMap[actions[c]].Name(); description = action.actionType().ToString() + " -- " + action.Description(); if (action.VariableMp()) { mpCost = "Variable"; } else { mpCost = unitConfig.actionMap[actions[c]].MpCost().ToString(); } } entry.Find("Text").GetComponent <Text>().text = label; entry.Find("Text").GetComponent <Text>().color = Color.white; if (actions[c] == unitActions[index]) { entry.Find("Text").GetComponent <Text>().color = Color.green; } else if (unitActions.Contains(actions[c])) { enableClick = false; entry.Find("Text").GetComponent <Text>().color = new Color(1, 1, 1, .5f); } ActionConfigButton configButton = entry.GetComponent <ActionConfigButton>(); configButton.actionName = label; configButton.description = description; configButton.mpCost = mpCost; if (enableClick) { entry.GetComponent <Button>().onClick.AddListener( () => { ActionInformation.Hide(); this.SetAction(unitConfig, index, actions[c], configType); }); } } else { entry.gameObject.active = false; } i++; } }
public BaseInformation() { actionInformation = new ActionInformation(); }
public async Task <(bool, string)> PostWorkflowActionAsync(ActionInformation action, string contractID) { var url = $"{BaseUrl}contracts/{contractID}/actions"; return(await postDataObjectAsync(action, url)); }
/// <summary> /// Processes the command key. /// </summary> /// <seealso cref="M:System.Windows.Forms.Form.ProcessCmdKey(Message@,Keys)"/> protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (Globals.IsReady) { switch (keyData) { // Top menu system case Keys.Alt | Keys.S: ActionSettings.ShowDropDown(); return(true); case Keys.Alt | Keys.I: ActionInformation.ShowDropDown(); return(true); case Keys.F9: ActionPreferences.PerformClick(); return(true); case Keys.Alt | Keys.Control | Keys.F4: ActionExit.PerformClick(); return(true); case Keys.Escape: if (!EditESCtoExit.Checked || EditMeanings.IsCurrentCellInEditMode) { break; } ActionExit.PerformClick(); return(true); // Rotate view case Keys.Control | Keys.Shift | Keys.Tab: if (Globals.AllowClose) { SetView(Settings.CurrentView.Previous(ViewMode.Notebook));// TODO notebook remove when ready } return(true); case Keys.Control | Keys.Tab: if (Globals.AllowClose) { SetView(Settings.CurrentView.Next(ViewMode.Notebook));// TODO notebook remove when ready } return(true); // Change view case Keys.F1: ActionViewAnalysis.PerformClick(); return(true); case Keys.F2: ActionViewLetters.PerformClick(); return(true); case Keys.F3: if (!Globals.IsDebugExecutable) { break; // TODO remove when ready } ActionViewNotebook.PerformClick(); return(true); // Application functions case Keys.F5: case Keys.Control | Keys.F: ActionSearchTerm.PerformClick(); return(true); case Keys.Control | Keys.N: ActionNewInstance.PerformClick(); return(true); // Top menu system case Keys.Alt | Keys.T: ActionTools.ShowDropDown(); return(true); case Keys.Alt | Keys.L: if (ActionWebLinks.Enabled) { ActionWebLinks.ShowDropDown(); } return(true); // Data edition case Keys.Control | Keys.S: ActionSave.PerformClick(); return(true); case Keys.Control | Keys.Back: ActionUndo.Focus(); ActionUndo.PerformClick(); return(true); } } // Letters navigation if (Globals.AllowClose && Settings.CurrentView == ViewMode.Letters) { switch (keyData) { case Keys.Control | Keys.Home: LettersNavigator.ActionFirst.PerformClick(); return(true); case Keys.Control | Keys.End: LettersNavigator.ActionLast.PerformClick(); return(true); case Keys.Control | Keys.PageUp: LettersNavigator.ActionPrevious.PerformClick(); return(true); case Keys.Control | Keys.PageDown: LettersNavigator.ActionNext.PerformClick(); return(true); } } return(base.ProcessCmdKey(ref msg, keyData)); }
protected void LoadActionInfo(ActionInformation actionInfo, XmlNode actionNode) { actionInfo.actionRange = float.Parse(actionNode.SelectSingleNode("./range").InnerText); actionInfo.actionSpeed = float.Parse(actionNode.SelectSingleNode("./speed").InnerText); actionInfo.magnitude = float.Parse(actionNode.SelectSingleNode("./magnitude").InnerText); LoadActionModifierInfo(actionInfo, actionNode.SelectSingleNode("./actionModifiers")); }