99
edits
(Create Event/MinEvent tutorial) |
m (Restore LiquidVolume variable, alter event header) |
||
Line 5: | Line 5: | ||
You can read more about traditional application events in Microsoft's [https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/events/ C# Programming Guide], the implementation is different but they fulfill the same function. | You can read more about traditional application events in Microsoft's [https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/events/ C# Programming Guide], the implementation is different but they fulfill the same function. | ||
= | =Standard Events= | ||
Events are typically listened for in generic Parts or Effects, which is what implements more advanced functionality of an object.<br/> | Events are typically listened for in generic Parts or Effects, which is what implements more advanced functionality of an object.<br/> | ||
[[Mutations]] ([[Modding:Creating_New_Mutations|Creation]]) and [[Skills_and_Powers|Skills]] are both Parts. Effects such as sleep, prone or poison are handled separately from Parts as they are usually temporary. | [[Mutations]] ([[Modding:Creating_New_Mutations|Creation]]) and [[Skills_and_Powers|Skills]] are both Parts. Effects such as sleep, prone or poison are handled separately from Parts as they are usually temporary. | ||
Line 127: | Line 127: | ||
What all that jargon means is that you can write separate methods for each event type which is much simpler to organize. | What all that jargon means is that you can write separate methods for each event type which is much simpler to organize. | ||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
// A volume/container of liquid, like a puddle or flagon. | |||
LiquidVolume liquid = new LiquidVolume(); | |||
// This method handles the GiveDramsEvent. | // This method handles the GiveDramsEvent. | ||
public bool HandleEvent(GiveDramsEvent E) { | public bool HandleEvent(GiveDramsEvent E) { | ||
Line 176: | Line 179: | ||
{ | { | ||
// If the cascade variable has the inventory bit... | // If the cascade variable has the inventory bit... | ||
if (MinEvent.CascadeTo(cascade, MinEvent.CASCADE_INVENTORY)) | if (MinEvent.CascadeTo(cascade, MinEvent.CASCADE_INVENTORY)) { | ||
// Check if any item in our inventory wants this event. | // Check if any item in our inventory wants this event. | ||
foreach(GameObject item in Inventory) { | foreach(GameObject item in Inventory) { | ||
Line 191: | Line 193: | ||
{ | { | ||
// If the CascadeLevel has the inventory bit... | // If the CascadeLevel has the inventory bit... | ||
if (E.CascadeTo(MinEvent.CASCADE_INVENTORY)) | if (E.CascadeTo(MinEvent.CASCADE_INVENTORY)) { | ||
// Allow each item in the inventory to handle the event. | // Allow each item in the inventory to handle the event. | ||
// Stops processing should any of them return false. | // Stops processing should any of them return false. |