Skip to content

Commit 7ab27c2

Browse files
committed
Hold LMB to auto cast
1 parent 83670ed commit 7ab27c2

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

world/entities/types/humanoids/Player.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
public class Player extends HumanoidEntity {
2525

2626
private double[] moveTarget;
27-
private boolean allowUserMovement, godMode;
27+
private boolean allowUserMovement, godMode, isCasting;
2828

2929
public Player() {
3030

@@ -50,17 +50,15 @@ public Player() {
5050
.on(MousePressedEvent.class.toString(), new EventHandler() {
5151
@Override
5252
public void handle(Event e) {
53-
if (isDead() || !getActionQueue("arms").isEmpty()) return;
5453
MousePressedEvent mce = (MousePressedEvent)e;
55-
ActionGroup actions = new ActionGroup();
56-
if (getSpellbook().getParent().getMana() >= 1 && mce.getButton() == 0
57-
&& that.getActionQueue().isEmpty()) {
58-
//HACK
59-
if (getLocation() != null) getLocation().lookAt(mce.getX(), mce.getY());
60-
actions.add(new CastSpellAction(mce.getX(), mce.getY()));
61-
actions.add(new ChangeAnimationAction("arms", "casting", true, true));
62-
getSpellbook().getParent().getActionQueue("arms").queueActions(actions);
63-
}
54+
if (mce.getButton() == 0) isCasting = true;
55+
}
56+
})
57+
.on(MouseReleaseEvent.class.toString(), new EventHandler() {
58+
@Override
59+
public void handle(Event e) {
60+
MouseReleaseEvent mce = (MouseReleaseEvent)e;
61+
if (mce.getButton() == 0) isCasting = false;
6462
}
6563
})
6664
.on(KeyDownEvent.class.toString(), new EventHandler() {
@@ -133,6 +131,8 @@ public void update() {
133131
getLocation().getCoordinates()[1],
134132
mouse_wc[0], mouse_wc[1]));
135133

134+
if (isCasting) cast(mouse_wc[0], mouse_wc[1]);
135+
136136
getMover().setSpeed(4);
137137
getMover().setIndependent(true);
138138
if ((dx != 0 || dy != 0) && allowUserMovement) {
@@ -162,4 +162,17 @@ public void activateGodMode() {
162162
this.addDyes(1000);
163163
}
164164

165+
private void cast(double wx, double wy) {
166+
if (isDead() || !getActionQueue("arms").isEmpty()) return;
167+
ActionGroup actions = new ActionGroup();
168+
if (getSpellbook().getParent().getMana() >= 1
169+
&& getActionQueue().isEmpty()) {
170+
//HACK
171+
if (getLocation() != null) getLocation().lookAt(wx, wy);
172+
actions.add(new CastSpellAction(wx, wy));
173+
actions.add(new ChangeAnimationAction("arms", "casting", true, true));
174+
getSpellbook().getParent().getActionQueue("arms").queueActions(actions);
175+
}
176+
}
177+
165178
}

0 commit comments

Comments
 (0)