Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////////////////
- // //
- // EVENT SUBSCRIPTION EXAMPLE //
- // //
- //////////////////////////////////
- using System;
- namespace RenegadeCore
- {
- public partial class Weather
- {
- //This is called by the core weather system from other parts of the game.
- [GeneratesEvent("SpawnWeatherCheck")]
- public bool SpawnWeather(Weather weather, ChunkColumn column)
- {
- if(column.HasWeather())
- return;
- }
- }
- }
- namespace AwesomeMod
- {
- public partial class ArceusThunderstorm
- {
- public int ThunderstormCount { get; protected set; }
- public ArceusThunderstorm()
- {
- ThunderstormCount = 0;
- }
- [PrependEvent("SpawnWeatherCheck", Priority.Highest)]
- public bool PreWeatherSpawn(Weather weather, ChunkColumn column)
- {
- if(ThunderstormCount >= 100)
- {
- SpawnArceus(column.zero);
- ThunderstormCount = 0;
- return false;
- }
- return true;
- }
- [AppendEvent("SpawnWeatherCheck")]
- public void PostWeatherSpawn(Weather weather, ChunkColumn column)
- {
- ThunderstormCount++;
- }
- }
- }
- //results in:
- using System;
- namespace RenegadeCore
- {
- public partial class Weather
- {
- public class SpawnWeatherCheckEventArgs : XGEFEventArgs
- {
- public Weather weather { get; set; }
- public ChunkColumn column { get; set; }
- }
- //This is called by the core weather system from other parts of the game.
- public void SpawnWeather(Weather weather, ChunkColumn column)
- {
- //Automatically inserted
- SpawnWeatherCheckEventArgs args = new SpawnWeatherCheckEventArgs() { weather = weather, column = column };
- args = XGEF.Events.EventHandler.Instance.InvokeEvent(this, args);
- if(args.Cancel)
- return;
- if(column.HasWeather())
- return;
- //Automatically inserted
- XGEF.Events.EventHandler.Instance.InvokePostEvent("SpawnWeatherCheck", this, args);
- }
- //Automatically generated if it didn't exist
- public Weather()
- {
- XGEF.Events.EventHandler.Instance.CreateEvent("SpawnWeatherCheck", this, "WeatherMod", SpawnWeatherCheckEventArgs);
- }
- }
- }
- namespace AwesomeMod
- {
- public partial class ArceusThunderstorm
- {
- public int ThunderstormCount { get; protected set; }
- public ArceusThunderstorm()
- {
- ThunderstormCount = 0;
- //Automatically inserted
- XGEF.Events.EventHandler.Instance.RegisterPreEvent("SpawnWeatherCheck", PreWeatherSpawn, Priority.Highest);
- XGEF.Events.EventHandler.Instance.RegisterPostEvent("SpawnWeatherCheck", PostWeatherSpawn, Priority.Normal);
- }
- public void PreWeatherSpawn(Weather weather, ChunkColumn column)
- {
- if(ThunderstormCount >= 100)
- {
- SpawnArceus(column.zero);
- ThunderstormCount = 0;
- args.Cancel = true;
- return;
- }
- args.Cancel = false;
- return;
- }
- public void PostWeatherSpawn(Weather weather, ChunkColumn column)
- {
- ThunderstormCount++;
- }
- }
- }
Add Comment
Please, Sign In to add comment