-
Notifications
You must be signed in to change notification settings - Fork 34
Writing your first QuickAction
To explain how to write your first QuickAction we look at the "Add10KEddies" QuickAction. It is assumed that you have read QuickAction Overview and QuickAction Setup.
To get a correct node we can create a variable and use the "where" extension combined with "FirstOrDefault" on the "nodes" variable from the predefiend variables.
Note that the following steps could be done on one line but for claritywe do it seperate.
In this case we search for the first node that is named "inventory" like this:
var inventoryNode = nodes.where(n => n.Name == "inventory").FirstOrDefault();
The actual representation that contains the data in a parsed format is stored in the "Value" property of the node:
var inventory = inventoryNode.Value;
Get the subinventory with Id "1" (this is Vs main Inventory):
var subInventory = inventory.SubInventories.where(si => si.InventoryId == 1).FirstOrDefault()
Get the first Item that has the name "Items.money"
var eddies = subInventory.Items.where(i => i.ItemTdbId.Name == "Items.money").FirstOrDefault();
The data of the of the item needs to be cast into the correct type or else it will only be represented as a string and properties cant be accessed.
In this case we want to cast the "Data" property of our item to "SimpleItemData":
var typedEddieData = host.cast(lib.CyberCAT.Core.Classes.NodeRepresentations.ItemData.SimpleItemData, eddies.Data);
As last step we increment the "Quantity" property by 10.000
typedEddieData.Quantity += 10000;