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/entity/noai.d, selery/entity/noai.d) 28 */ 29 module selery.entity.noai; 30 31 import std.conv : to; 32 33 import selery.about; 34 import selery.block.block; 35 import selery.entity.entity; 36 import selery.entity.interfaces; 37 import selery.item.slot : Slot; 38 import selery.math.vector : BlockPosition, EntityPosition, entityPosition; 39 import selery.player.player : Player; 40 import selery.util.util : call; 41 import selery.world.world : World; 42 43 static import sul.entities; 44 45 class ItemEntity : Entity, Collectable { 46 47 public static immutable uint LIFETIME = 5 * 60 * 20; 48 49 public static immutable uint PICKUP_DELAY = 1 * 20; 50 51 public static immutable float WIDTH = .25; 52 53 public static immutable float HEIGHT = .25; 54 55 private Slot n_item; 56 public bool pickUp = true; 57 public uint delay = PICKUP_DELAY; 58 59 public this(World world, EntityPosition position, EntityPosition motion, Slot item) { 60 super(world, position); 61 assert(!item.empty, "Can't drop an empty slot!"); 62 this.n_data = 1; 63 this.m_motion = motion; 64 this.n_item = item; 65 static if(supportedJavaProtocols.length) { 66 import selery.player.java : JavaPlayerImpl; 67 foreach(immutable i ; SupportedJavaProtocols) { 68 mixin("this.metadata.java" ~ to!string(i) ~ ".item = JavaPlayerImpl!" ~ to!string(i) ~ ".toSlot(item);"); 69 } 70 } 71 this.setSize(WIDTH, HEIGHT); 72 this.acceleration = .05; 73 this.terminal_velocity = 100; 74 this.drag = .99; 75 } 76 77 public override pure nothrow @property @safe @nogc sul.entities.Entity data() { 78 return Entities.droppedItem; 79 } 80 81 public override void tick() { 82 super.tick(); 83 if(this.ticks > LIFETIME) { 84 this.despawn(); 85 } 86 if(this.delay > 0) { 87 this.delay--; 88 } else { 89 // check for pickup 90 /+foreach(Entity entity ; this.watchlist) { 91 if(cast(Collector)entity && this.box.grow(.25, .25).intersects(entity.box)) { 92 if((cast(Collector)entity).onCollect(this)) { 93 this.viewers!Player.call!"sendPickupItem"(entity, this); 94 this.despawn(); 95 return; 96 } 97 } 98 }+/ 99 } 100 101 //TODO check if it's into a block 102 103 //this.doPhysic(); 104 105 } 106 107 public pure nothrow @property @safe @nogc Slot item() { 108 return this.n_item; 109 } 110 111 alias slot = item; 112 113 public override @trusted bool shouldSee(Entity entity) { 114 return cast(Collector)entity || (cast(ItemEntity)entity && this.item.item == (cast(ItemEntity)entity).item.item); 115 } 116 117 } 118 119 final class Lightning : Entity { 120 121 public this(World world, EntityPosition position) { 122 super(world, position); 123 } 124 125 public override pure nothrow @property @safe @nogc sul.entities.Entity data() { 126 return Entities.lightning; 127 } 128 129 public override void tick() { 130 super.tick(); 131 if(this.ticks == 4) { 132 //TODO fire 133 //TODO strike the entities 134 super.despawn(); 135 } 136 } 137 138 } 139 140 final class Painting : Entity { 141 142 public static immutable string KEBAB = "Kebab"; 143 public static immutable string AZTEC = "Aztec"; 144 public static immutable string ALBAN = "Alban"; 145 public static immutable string AZTEC2 = "Aztec2"; 146 public static immutable string BOMB = "Bomb"; 147 public static immutable string PLANT = "Plant"; 148 public static immutable string WASTELAND = "Wasteland"; 149 public static immutable string POOL = "Pool"; 150 public static immutable string COURBET = "Courbet"; 151 public static immutable string SEA = "Sea"; 152 public static immutable string SUNSET = "Sunset"; 153 public static immutable string CREEBET = "Creebet"; 154 public static immutable string WANDERER = "Wanderer"; 155 public static immutable string GRAHAM = "Graham"; 156 public static immutable string MATCH = "Match"; 157 public static immutable string BUST = "Bust"; 158 public static immutable string STAGE = "Stage"; 159 public static immutable string VOID = "Void"; 160 public static immutable string SKULL_AND_ROSES = "SkullAndRoses"; 161 public static immutable string WITHER = "Wither"; 162 public static immutable string FIGHTERS = "Fighters"; 163 public static immutable string POINTER = "Pointer"; 164 public static immutable string PIGSCENE = "PigScene"; 165 public static immutable string BURNINGSKULL = "BurningSkull"; 166 public static immutable string SKELETON = "Skeleton"; 167 public static immutable string DONKEYKONG = "DonkeyKong"; 168 169 public bool ticking = false; 170 171 private string n_title; 172 private uint n_direction; 173 174 public this(World world, BlockPosition position, string title, uint direction) { 175 super(world, position.entityPosition); 176 this.n_title = title; 177 this.n_direction = direction; 178 } 179 180 public override pure nothrow @property @safe @nogc sul.entities.Entity data() { 181 return Entities.painting; 182 } 183 184 public pure nothrow @property @safe @nogc string title() { 185 return this.n_title; 186 } 187 188 public pure nothrow @property @safe @nogc uint direction() { 189 return this.n_direction; 190 } 191 192 }