9
9
import com .interrupt .dungeoneer .entities .Door ;
10
10
import com .interrupt .dungeoneer .entities .DynamicLight ;
11
11
import com .interrupt .dungeoneer .entities .Entity ;
12
- import com .interrupt .dungeoneer .entities .Monster ;
13
12
import com .interrupt .dungeoneer .entities .Mover ;
14
13
import com .interrupt .dungeoneer .entities .Particle ;
15
14
import com .interrupt .dungeoneer .entities .Player ;
16
- import com .interrupt .dungeoneer .entities .PositionedSound ;
17
15
import com .interrupt .dungeoneer .entities .items .Weapon .DamageType ;
18
16
import com .interrupt .dungeoneer .entities .triggers .Trigger ;
19
17
import com .interrupt .dungeoneer .game .Game ;
@@ -30,12 +28,13 @@ public Teleport(DamageType damageType) {
30
28
this .damageType = damageType ;
31
29
}
32
30
31
+ /** Handles individual teleport (ex. casting a spell from a scroll). */
33
32
@ Override
34
33
public void doCast (Entity owner , Vector3 direction , Vector3 position ) {
35
- Vector3 pos = new Vector3 (owner .x , owner .y , owner .z );
36
34
teleport (owner , Game .rand .nextInt ());
37
35
}
38
36
37
+ /** Handles teleport for every actor, including the player, within a certain radius (ex. stepping on a pressure plate trap). */
39
38
public void doCast (Vector3 pos , Vector3 direction ) {
40
39
Level level = Game .GetLevel ();
41
40
@@ -48,12 +47,16 @@ public void doCast(Vector3 pos, Vector3 direction) {
48
47
}
49
48
50
49
Player p = Game .instance .player ;
51
- if (Math .abs (p .x + 0.5f - pos .x ) < 0.5f + p .collision .x && Math .abs (p .y + 0.5f - pos .y ) < 0.5f + p .collision .y ) {
50
+ if (Math .abs (p .x - pos .x ) < 0.5f + p .collision .x && Math .abs (p .y - pos .y ) < 0.5f + p .collision .y ) {
52
51
teleport (p , seed );
53
52
p .history .teleported ();
54
53
}
55
54
}
56
55
56
+ /**
57
+ * Teleports the specified entity to a random location based on the provided seed number. Providing the same seed
58
+ * will result in the same location. Any actor entity, such as a monster, already at that location will be killed.
59
+ */
57
60
public void teleport (Entity e , int seed ) {
58
61
Level level = Game .GetLevel ();
59
62
if (level .dungeonLevel == 0 ) return ;
@@ -67,32 +70,14 @@ public void teleport(Entity e, int seed) {
67
70
if (checkTile .CanSpawnHere ()) {
68
71
e .x = checkX + 0.5f ;
69
72
e .y = checkY + 0.5f ;
70
-
71
- float height1 = checkTile .getFloorHeight (e .x - e .collision .x , e .y - e .collision .y );
72
- float height2 = checkTile .getFloorHeight (e .x - e .collision .x , e .y + e .collision .y );
73
- float height3 = checkTile .getFloorHeight (e .x + e .collision .x , e .y - e .collision .y );
74
- float height4 = checkTile .getFloorHeight (e .x + e .collision .x , e .y + e .collision .y );
75
- float max = Math .max (height4 , Math .max (height3 , Math .max (height1 , height2 )));
76
-
77
- e .z = max + 0.5f ;
78
-
79
- if (e instanceof Player ) {
80
- e .x -= 0.5 ;
81
- e .y -= 0.5 ;
82
- }
83
-
73
+ e .z = level .maxFloorHeight (e .x , e .y , 0 , e .collision .x ) + 0.5f ; // Assumes collision.x and y are the same.
74
+
84
75
Entity toFrag = level .checkEntityCollision (e .x , e .y , e .z , e .collision , e );
85
- if (toFrag != null && toFrag instanceof Actor ) {
86
- ((Actor )toFrag ).hp = 0 ;
76
+ if (toFrag == null || toFrag instanceof Actor ) {
77
+ if (toFrag instanceof Actor ) ((Actor )toFrag ).hp = 0 ; // Kill an actor already in that position.
78
+ doCastEffect (new Vector3 (e .x , e .y , e .z ), level , e );
79
+ return ;
87
80
}
88
- else if (toFrag != null ) {
89
- // this didn't work out, try again
90
- continue ;
91
- }
92
-
93
- doCastEffect (new Vector3 ((float )checkX + 0.5f , (float )checkY + 0.5f , checkTile .floorHeight + 0.5f ), level , e );
94
-
95
- return ;
96
81
}
97
82
}
98
83
}
0 commit comments