24
24
import com .bladecoder .engine .model .InteractiveActor ;
25
25
import com .bladecoder .engine .model .VerbRunner ;
26
26
import com .bladecoder .engine .model .World ;
27
+ import com .bladecoder .engine .util .EngineLogger ;
27
28
28
29
@ ActionDescription ("Walks to the selected position" )
29
30
public class GotoAction implements Action {
@@ -32,27 +33,27 @@ public enum Align {
32
33
}
33
34
34
35
@ ActionPropertyDescription ("The walking actor" )
35
- @ ActionProperty (type = Type .CHARACTER_ACTOR , required = true )
36
+ @ ActionProperty (type = Type .CHARACTER_ACTOR , required = true )
36
37
private String actor ;
37
38
38
39
@ ActionPropertyDescription ("Walks to this actor" )
39
40
@ ActionProperty (type = Type .ACTOR )
40
41
private String target ;
41
-
42
+
42
43
@ ActionProperty
43
44
@ ActionPropertyDescription ("The absolute position to walk to if no target actor is selected. Relative to target if selected." )
44
45
private Vector2 pos ;
45
-
46
- @ ActionProperty (required = true , defaultValue = "false" )
46
+
47
+ @ ActionProperty (required = true , defaultValue = "false" )
47
48
@ ActionPropertyDescription ("Ignore the walking zone and walk in a straight line." )
48
49
private boolean ignoreWalkZone = false ;
49
50
50
51
@ ActionProperty (required = true , defaultValue = "true" )
51
52
@ ActionPropertyDescription ("If this param is 'false' the text is showed and the action continues inmediatly" )
52
53
private boolean wait = true ;
53
-
54
+
54
55
private World w ;
55
-
56
+
56
57
@ Override
57
58
public void init (World w ) {
58
59
this .w = w ;
@@ -62,35 +63,40 @@ public void init(World w) {
62
63
public boolean run (VerbRunner cb ) {
63
64
64
65
CharacterActor actor = (CharacterActor ) w .getCurrentScene ().getActor (this .actor , false );
65
-
66
+
66
67
float x = actor .getX ();
67
68
float y = actor .getY ();
68
69
69
70
if (target != null ) {
70
- BaseActor target = w .getCurrentScene ().getActor (this .target , false );
71
-
72
- x = target .getX ();
73
- y = target .getY ();
74
-
75
- if (target instanceof InteractiveActor && target != actor ) {
76
- Vector2 refPoint = ((InteractiveActor ) target ).getRefPoint ();
77
- x += refPoint .x ;
78
- y += refPoint .y ;
71
+ BaseActor targetActor = w .getCurrentScene ().getActor (target , false );
72
+
73
+ if (targetActor == null ) {
74
+ EngineLogger .error (target + " not found in the current scene." );
75
+ return false ;
79
76
}
80
-
81
- if (pos != null ){
77
+
78
+ x = targetActor .getX ();
79
+ y = targetActor .getY ();
80
+
81
+ if (targetActor instanceof InteractiveActor && targetActor != actor ) {
82
+ Vector2 refPoint = ((InteractiveActor ) targetActor ).getRefPoint ();
83
+ x += refPoint .x ;
84
+ y += refPoint .y ;
85
+ }
86
+
87
+ if (pos != null ) {
82
88
float scale = EngineAssetManager .getInstance ().getScale ();
83
-
89
+
84
90
x += pos .x * scale ;
85
91
y += pos .y * scale ;
86
92
}
87
- } else if (pos != null ){
93
+ } else if (pos != null ) {
88
94
float scale = EngineAssetManager .getInstance ().getScale ();
89
-
95
+
90
96
x = pos .x * scale ;
91
97
y = pos .y * scale ;
92
98
}
93
-
99
+
94
100
actor .goTo (new Vector2 (x , y ), wait ? cb : null , ignoreWalkZone );
95
101
96
102
return wait ;
0 commit comments