2
Moves - How to Add a New Type
Tanner Van Teeffelen edited this page 2025-07-15 11:58:29 -04:00
- In the folder /scripts/objects/moves, create a new .cs file corresponding to the proper type of move (for example, PhysicalMove.cs).
- Within the constructor, inherit the original Move class, and override the string Type to set to the moves name (see example below).
public class PhysicalMove : Move
{
public override string Type => "PhysicalMove";
public PhysicalMove(string name, string description, int power, string action) : base(name, description)
{
Action = action;
}
}
Add any additional variables as required.
- Next, within the MoveConverter.cs class (/scripts/loaders/), add an entry into the switch statement that matches the Type string that you set up in the class. In addition, set up a blank object as well (see example below).
public class MoveConverter : JsonConverter<Move>
{
//Overrides the ReadJson function.
public override Move ReadJson(JsonReader reader, Type objectType, Move? existingValue, bool hasExistingValue, JsonSerializer serializer)
{
//Load the raw JSON object from the reader.
JObject obj = JObject.Load(reader);
// Read the "Type" field
string? type = obj["Type"]?.ToString();
//Create a temporary item object.
Move move;
//Uses the Type field to determine what kind of object to create, to allow for a mixed list.
switch (type)
{
case "PhysicalMove":
move = new PhysicalMove("", "", 0, "");
break;
default:
throw new JsonSerializationException($"Unknown item type: {type}");
}
// Populate the item with values from JSON
serializer.Populate(obj.CreateReader(), move);
return move;
}
After doing so, you should be able to create and add Moves of that type, and have them inside of generic Move Lists as well, allowing for a mixed List of different kinds of Moves.