1 /* 2 * Copyright (c) 2017-2018 sel-project 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a copy 5 * of this software and associated documentation files (the "Software"), to deal 6 * in the Software without restriction, including without limitation the rights 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 * copies of the Software, and to permit persons to whom the Software is 9 * furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in all 12 * copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 * SOFTWARE. 21 * 22 */ 23 /** 24 * Copyright: 2017-2018 sel-project 25 * License: MIT 26 * Authors: Kripth 27 * Source: $(HTTP github.com/sel-project/selery/source/selery/event/world/world.d, selery/event/world/world.d) 28 */ 29 module selery.event.world.world; 30 31 import selery.about : tick_t; 32 import selery.entity.entity : Entity; 33 import selery.event.event : Event, Cancellable; 34 import selery.math.vector : EntityPosition; 35 import selery.world.world : World; 36 37 /** 38 * Generic event related to the world. 39 */ 40 interface WorldEvent : Event { 41 42 /** 43 * Gets the world where the event has happened. 44 */ 45 public pure nothrow @property @safe @nogc World world(); 46 47 public static mixin template Implementation() { 48 49 private World n_world; 50 51 public final override pure nothrow @property @safe @nogc World world() { 52 return this.n_world; 53 } 54 55 } 56 57 } 58 59 /** 60 * Called it starts to rain or snow in the world. 61 */ 62 final class StartRainEvent : WorldEvent, Cancellable { 63 64 mixin Cancellable.Implementation; 65 66 mixin WorldEvent.Implementation; 67 68 private tick_t m_duration; 69 70 public pure nothrow @safe @nogc this(World world, tick_t duration) { 71 this.n_world = world; 72 this.m_duration = duration; 73 } 74 75 /** 76 * Gets the duration of the precipitations is ticks. 77 */ 78 public pure nothrow @property @safe @nogc tick_t duration() { 79 return this.m_duration; 80 } 81 82 /** 83 * Sets the duration of the precipitation in ticks. 84 * Example: 85 * --- 86 * event.duration = 1; 87 * --- 88 */ 89 public pure nothrow @property @safe @nogc tick_t duration(tick_t duration) { 90 return this.m_duration = duration; 91 } 92 93 } 94 95 /// ditto 96 alias StartSnowEvent = StartRainEvent; 97 98 /** 99 * Event called when it stops to rain or snow in the world. 100 */ 101 final class StopRainEvent : WorldEvent { 102 103 mixin WorldEvent.Implementation; 104 105 public pure nothrow @safe @nogc this(World world) { 106 this.n_world = world; 107 } 108 109 } 110 111 /// ditto 112 alias StopSnowEvent = StopRainEvent; 113 114 /** 115 * Event called when a lighting strikes in the world. 116 */ 117 final class LightningStrikeEvent : WorldEvent, Cancellable { 118 119 mixin Cancellable.Implementation; 120 121 mixin WorldEvent.Implementation; 122 123 private EntityPosition n_position; 124 private Entity n_target; 125 126 public pure nothrow @safe @nogc this(World world, EntityPosition position) { 127 this.n_world = world; 128 this.n_position = position; 129 } 130 131 public pure nothrow @safe @nogc this(World world, Entity target) { 132 this(world, target.position); 133 this.n_target = target; 134 } 135 136 /** 137 * Gets the position where the lightning has struck. 138 */ 139 public pure nothrow @property @safe @nogc EntityPosition position() { 140 return this.n_position; 141 } 142 143 /** 144 * Gets the target of the lightning, it may be null if the lightning 145 * struck randomly. 146 */ 147 public pure nothrow @property @safe @nogc Entity target() { 148 return this.n_target; 149 } 150 151 } 152 153 interface ExplosionEvent : WorldEvent, Cancellable { 154 155 public pure nothrow @property @safe @nogc float power(); 156 157 public pure nothrow @property @safe @nogc float power(float power); 158 159 mixin template Implementation() { 160 161 mixin Cancellable.Implementation; 162 163 private float m_power; 164 165 public override pure nothrow @property @safe @nogc float power() { 166 return this.m_power; 167 } 168 169 public override pure nothrow @property @safe @nogc float power(float power) { 170 return this.m_power = power; 171 } 172 173 } 174 175 }