1 /*
2  * Copyright (c) 2017-2019 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: Copyright (c) 2017-2019 sel-project
25  * License: MIT
26  * Authors: Kripth
27  * Source: $(HTTP github.com/sel-project/selery/source/selery/entity/util.d, selery/entity/util.d)
28  */
29 module selery.entity.util;
30 
31 import std.traits : isFinalClass, isAbstractClass;
32 
33 import selery.entity.entity : Entity;
34 
35 /**
36  * Example:
37  * ---
38  * alias ZombieProjection = Projection!(Noai!Zombie, "direction-10,y+5");
39  * auto zombie = world.spawn!ZombieProjection;
40  * zombie.attach(player);
41  * ---
42  */
43 template Projection(T:Entity, string algorithm="") if(!isFinalClass!T && !isAbstractClass!T) {
44 
45 	//TODO check algorithm
46 
47 	class Projection : T {
48 
49 		public this(E...)(E args) {
50 			super(args);
51 		}
52 
53 		public override void tick() {
54 			super.tick();
55 			//TODO do programmed moves
56 		}
57 
58 		public void attach(Player player) {
59 			player += &move_event;
60 		}
61 
62 		public void move_event(PlayerMoveEvent event) {
63 			int x = event.position.x;
64 			int y = event.position.y;
65 			int z = event.position.z;
66 			//TODO move using the algorithm directives
67 			// [x y z direction] [+ - * / pow log] [float auto]
68 		}
69 
70 	}
71 
72 }
73 
74 /**
75  * Example:
76  * ---
77  * alias ChickenFollower = Follower!(Noai!Chicken);
78  * auto chicken = world.spawn!ChickenFollower();
79  * chicken.follow(player!"Kripth");
80  * ---
81  */
82 template Follower(T:Entity) if(!isFinalClass!T && !isAbstractClass!T) {
83 
84 	class Follower : T {
85 
86 		public this(E...)(E args) {
87 			super(args);
88 		}
89 
90 		public void follow(Entity entity) {}
91 
92 		public void unfollow() {}
93 
94 	}
95 
96 }