diff options
| author | Starla Insigna <hatkirby@fourisland.com> | 2009-01-17 10:36:37 -0500 |
|---|---|---|
| committer | Starla Insigna <hatkirby@fourisland.com> | 2009-01-17 10:36:37 -0500 |
| commit | 69b495c392bffe96dab97306a42466edd4b2474e (patch) | |
| tree | 2adccc01f4027bcb76bbefee03bb6a9622ce3e00 /src/com/fourisland/fourpuzzle/gamestate/mapview/event | |
| parent | 4c768483aecd687529b9abb48ed42950fabc886f (diff) | |
| download | fourpuzzle-69b495c392bffe96dab97306a42466edd4b2474e.tar.gz fourpuzzle-69b495c392bffe96dab97306a42466edd4b2474e.tar.bz2 fourpuzzle-69b495c392bffe96dab97306a42466edd4b2474e.zip | |
Imported sources
Diffstat (limited to 'src/com/fourisland/fourpuzzle/gamestate/mapview/event')
27 files changed, 1443 insertions, 0 deletions
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java new file mode 100644 index 0000000..e7901df --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; | ||
| 7 | |||
| 8 | /** | ||
| 9 | * | ||
| 10 | * @author hatkirby | ||
| 11 | */ | ||
| 12 | public enum AnimationType { | ||
| 13 | CommonWithoutStepping, | ||
| 14 | CommonWithStepping, | ||
| 15 | WithoutStepping, | ||
| 16 | FixedGraphic, | ||
| 17 | TurnLeft, | ||
| 18 | TurnRight | ||
| 19 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/CommonEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/CommonEvent.java new file mode 100644 index 0000000..edfdb8f --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/CommonEvent.java | |||
| @@ -0,0 +1,62 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.gamestate.mapview.event.precondition.Precondition; | ||
| 9 | import java.util.ArrayList; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * | ||
| 13 | * @author hatkirby | ||
| 14 | */ | ||
| 15 | public class CommonEvent { | ||
| 16 | |||
| 17 | private ArrayList<Precondition> preconditions; | ||
| 18 | private EventCallTime calltime; | ||
| 19 | private EventCall callback; | ||
| 20 | |||
| 21 | public CommonEvent() | ||
| 22 | { | ||
| 23 | calltime = EventCallTime.ParallelProcess; | ||
| 24 | callback = EventCall.getEmptyEventCall(); | ||
| 25 | |||
| 26 | preconditions = new ArrayList<Precondition>(); | ||
| 27 | } | ||
| 28 | |||
| 29 | public void addPrecondition(Precondition precondition) | ||
| 30 | { | ||
| 31 | preconditions.add(precondition); | ||
| 32 | } | ||
| 33 | |||
| 34 | public Precondition getPrecondition(int i) | ||
| 35 | { | ||
| 36 | return preconditions.get(i); | ||
| 37 | } | ||
| 38 | |||
| 39 | public int preconditions() | ||
| 40 | { | ||
| 41 | return preconditions.size(); | ||
| 42 | } | ||
| 43 | |||
| 44 | public EventCall getCallback() | ||
| 45 | { | ||
| 46 | return callback; | ||
| 47 | } | ||
| 48 | |||
| 49 | public void setCallback(EventCall callback) | ||
| 50 | { | ||
| 51 | this.callback = callback; | ||
| 52 | } | ||
| 53 | |||
| 54 | public EventCallTime getCalltime() { | ||
| 55 | return calltime; | ||
| 56 | } | ||
| 57 | |||
| 58 | public void setCalltime(EventCallTime calltime) { | ||
| 59 | this.calltime = calltime; | ||
| 60 | } | ||
| 61 | |||
| 62 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java new file mode 100644 index 0000000..1aa74c1 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.Direction; | ||
| 9 | import com.fourisland.fourpuzzle.Layer; | ||
| 10 | import java.awt.Graphics; | ||
| 11 | import java.awt.Point; | ||
| 12 | |||
| 13 | /** | ||
| 14 | * | ||
| 15 | * @author hatkirby | ||
| 16 | */ | ||
| 17 | public interface Event { | ||
| 18 | |||
| 19 | public String getLabel(); | ||
| 20 | |||
| 21 | public Point getLocation(); | ||
| 22 | |||
| 23 | public void setLocation(Point location); | ||
| 24 | public void setLocation(int x, int y); | ||
| 25 | |||
| 26 | public void render(Graphics g) throws Exception; | ||
| 27 | |||
| 28 | public Direction getDirection() throws Exception; | ||
| 29 | public void setDirection(Direction direction) throws Exception; | ||
| 30 | |||
| 31 | public boolean isMoving(); | ||
| 32 | public void startMoving(Direction direction) throws Exception; | ||
| 33 | |||
| 34 | public Layer getLayer() throws Exception; | ||
| 35 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java new file mode 100644 index 0000000..daca678 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; | ||
| 7 | |||
| 8 | /** | ||
| 9 | * | ||
| 10 | * @author hatkirby | ||
| 11 | */ | ||
| 12 | public abstract class EventCall extends SpecialEvent implements Runnable { | ||
| 13 | |||
| 14 | public static EventCall getEmptyEventCall() | ||
| 15 | { | ||
| 16 | return new EventCall() { | ||
| 17 | @Override | ||
| 18 | public void run() { | ||
| 19 | } | ||
| 20 | }; | ||
| 21 | } | ||
| 22 | |||
| 23 | public abstract void run(); | ||
| 24 | |||
| 25 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCallTime.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCallTime.java new file mode 100644 index 0000000..821f891 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCallTime.java | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; | ||
| 7 | |||
| 8 | /** | ||
| 9 | * | ||
| 10 | * @author hatkirby | ||
| 11 | */ | ||
| 12 | public enum EventCallTime { | ||
| 13 | PushKey, | ||
| 14 | OnHeroTouch, | ||
| 15 | ParallelProcess | ||
| 16 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java new file mode 100644 index 0000000..3bdb9de --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java | |||
| @@ -0,0 +1,157 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.Layer; | ||
| 9 | import java.awt.Graphics; | ||
| 10 | import java.awt.Point; | ||
| 11 | import com.fourisland.fourpuzzle.Direction; | ||
| 12 | import com.fourisland.fourpuzzle.Game; | ||
| 13 | import com.fourisland.fourpuzzle.GameCharacter; | ||
| 14 | import com.fourisland.fourpuzzle.gamestate.mapview.CharSet; | ||
| 15 | import com.fourisland.fourpuzzle.NoCharactersInPartyException; | ||
| 16 | |||
| 17 | /** | ||
| 18 | * | ||
| 19 | * @author hatkirby | ||
| 20 | */ | ||
| 21 | public class HeroEvent implements Event { | ||
| 22 | |||
| 23 | public HeroEvent() | ||
| 24 | { | ||
| 25 | location = new Point(); | ||
| 26 | } | ||
| 27 | |||
| 28 | public String getLabel() | ||
| 29 | { | ||
| 30 | return "Hero"; | ||
| 31 | } | ||
| 32 | |||
| 33 | private Point location; | ||
| 34 | public Point getLocation() | ||
| 35 | { | ||
| 36 | return location; | ||
| 37 | } | ||
| 38 | public void setLocation(Point location) | ||
| 39 | { | ||
| 40 | this.location = location; | ||
| 41 | } | ||
| 42 | public void setLocation(int x, int y) | ||
| 43 | { | ||
| 44 | location.setLocation(x, y); | ||
| 45 | } | ||
| 46 | |||
| 47 | public void render(Graphics g) throws Exception | ||
| 48 | { | ||
| 49 | int x = (location.x * 16) - 4; | ||
| 50 | int y = (location.y * 16) - 16; | ||
| 51 | |||
| 52 | if (moving) | ||
| 53 | { | ||
| 54 | if (moveDirection == Direction.North) | ||
| 55 | { | ||
| 56 | y -= (4 - moveTimer) * 4; | ||
| 57 | } else if (moveDirection == Direction.West) | ||
| 58 | { | ||
| 59 | x -= (4 - moveTimer) * 4; | ||
| 60 | } else if (moveDirection == Direction.South) | ||
| 61 | { | ||
| 62 | y += (4 - moveTimer) * 4; | ||
| 63 | } else if (moveDirection == Direction.East) | ||
| 64 | { | ||
| 65 | x += (4 - moveTimer) * 4; | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | try | ||
| 70 | { | ||
| 71 | GameCharacter toDraw = Game.getSaveFile().getParty().getLeader(); | ||
| 72 | if (!toDraw.getGraphic().equals("blank")) | ||
| 73 | { | ||
| 74 | g.drawImage(CharSet.getCharSet(toDraw.getGraphic()).getImage(toDraw.getGraphicOffset(), direction, animationStep), x, y, null); | ||
| 75 | } | ||
| 76 | } catch (NoCharactersInPartyException ex) | ||
| 77 | { | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | |||
| 82 | private boolean moving = false; | ||
| 83 | public boolean isMoving() | ||
| 84 | { | ||
| 85 | return moving; | ||
| 86 | } | ||
| 87 | public void setMoving(boolean moving) | ||
| 88 | { | ||
| 89 | this.moving = moving; | ||
| 90 | } | ||
| 91 | |||
| 92 | private int moveTimer; | ||
| 93 | private Direction moveDirection; | ||
| 94 | public void startMoving(Direction toMove) throws Exception | ||
| 95 | { | ||
| 96 | setDirection(toMove); | ||
| 97 | setAnimationStep(2); | ||
| 98 | moveTimer = 4; | ||
| 99 | moving = true; | ||
| 100 | moveDirection = toMove; | ||
| 101 | } | ||
| 102 | public void processMoving() throws Exception | ||
| 103 | { | ||
| 104 | if (moving) | ||
| 105 | { | ||
| 106 | moveTimer--; | ||
| 107 | if (moveTimer == 2) | ||
| 108 | { | ||
| 109 | setAnimationStep(0); | ||
| 110 | } else if (moveTimer == 0) | ||
| 111 | { | ||
| 112 | setAnimationStep(1); | ||
| 113 | moving = false; | ||
| 114 | |||
| 115 | if (moveDirection == Direction.North) | ||
| 116 | { | ||
| 117 | setLocation(getLocation().x,getLocation().y-1); | ||
| 118 | } else if (moveDirection == Direction.West) | ||
| 119 | { | ||
| 120 | setLocation(getLocation().x-1,getLocation().y); | ||
| 121 | } else if (moveDirection == Direction.South) | ||
| 122 | { | ||
| 123 | setLocation(getLocation().x,getLocation().y+1); | ||
| 124 | } else if (moveDirection == Direction.East) | ||
| 125 | { | ||
| 126 | setLocation(getLocation().x+1,getLocation().y); | ||
| 127 | } | ||
| 128 | } | ||
| 129 | } | ||
| 130 | } | ||
| 131 | |||
| 132 | private Direction direction = Direction.South; | ||
| 133 | public Direction getDirection() | ||
| 134 | { | ||
| 135 | return direction; | ||
| 136 | } | ||
| 137 | public void setDirection(Direction direction) | ||
| 138 | { | ||
| 139 | this.direction = direction; | ||
| 140 | } | ||
| 141 | |||
| 142 | private int animationStep = 1; | ||
| 143 | public int getAnimationStep() | ||
| 144 | { | ||
| 145 | return animationStep; | ||
| 146 | } | ||
| 147 | public void setAnimationStep(int animationStep) | ||
| 148 | { | ||
| 149 | this.animationStep = animationStep; | ||
| 150 | } | ||
| 151 | |||
| 152 | public Layer getLayer() throws Exception | ||
| 153 | { | ||
| 154 | return Layer.Middle; | ||
| 155 | } | ||
| 156 | |||
| 157 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java new file mode 100644 index 0000000..92cfd54 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java | |||
| @@ -0,0 +1,207 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.Layer; | ||
| 9 | import java.awt.Graphics; | ||
| 10 | import java.awt.Point; | ||
| 11 | import java.util.ArrayList; | ||
| 12 | import com.fourisland.fourpuzzle.Direction; | ||
| 13 | import com.fourisland.fourpuzzle.gamestate.mapview.Map; | ||
| 14 | |||
| 15 | /** | ||
| 16 | * | ||
| 17 | * @author hatkirby | ||
| 18 | */ | ||
| 19 | public class LayerEvent implements Event { | ||
| 20 | |||
| 21 | /** Create a new Event instance | ||
| 22 | * | ||
| 23 | * @param x The horizontal location of the Event on the Map | ||
| 24 | * @param y The vertical location of the Event on the Map | ||
| 25 | */ | ||
| 26 | public LayerEvent(int x, int y) | ||
| 27 | { | ||
| 28 | location = new Point(x,y); | ||
| 29 | events = new ArrayList<PossibleEvent>(); | ||
| 30 | } | ||
| 31 | |||
| 32 | /** Create a new Event instance | ||
| 33 | * | ||
| 34 | * @param x The horizontal location of the Event on the Map | ||
| 35 | * @param y The vertical location of the Event on the Map | ||
| 36 | * @param label An identifying label for the Event | ||
| 37 | */ | ||
| 38 | public LayerEvent(int x, int y, String label) | ||
| 39 | { | ||
| 40 | this(x,y); | ||
| 41 | this.label = label; | ||
| 42 | } | ||
| 43 | |||
| 44 | private String label; | ||
| 45 | public String getLabel() | ||
| 46 | { | ||
| 47 | return label; | ||
| 48 | } | ||
| 49 | |||
| 50 | private Point location; | ||
| 51 | public Point getLocation() | ||
| 52 | { | ||
| 53 | return location; | ||
| 54 | } | ||
| 55 | public void setLocation(Point location) | ||
| 56 | { | ||
| 57 | this.location = location; | ||
| 58 | } | ||
| 59 | public void setLocation(int x, int y) | ||
| 60 | { | ||
| 61 | location.setLocation(x, y); | ||
| 62 | } | ||
| 63 | |||
| 64 | private ArrayList<PossibleEvent> events; | ||
| 65 | public void addEvent(PossibleEvent pe) | ||
| 66 | { | ||
| 67 | events.add(pe); | ||
| 68 | } | ||
| 69 | |||
| 70 | private PossibleEvent getPossibleEvent() throws Exception | ||
| 71 | { | ||
| 72 | int i; | ||
| 73 | for (i=(events.size()-1);i>-1;i--) | ||
| 74 | { | ||
| 75 | boolean good = true; | ||
| 76 | int j; | ||
| 77 | for (j=0;j<events.get(i).preconditions();j++) | ||
| 78 | { | ||
| 79 | good = (good ? events.get(i).getPrecondition(j).match() : false); | ||
| 80 | } | ||
| 81 | |||
| 82 | if (good) | ||
| 83 | { | ||
| 84 | return events.get(i); | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | return new PossibleEvent(); | ||
| 89 | } | ||
| 90 | |||
| 91 | public void render(Graphics g) throws Exception | ||
| 92 | { | ||
| 93 | int x = (location.x * 16) - 4; | ||
| 94 | int y = (location.y * 16) - 16; | ||
| 95 | |||
| 96 | if (moving) | ||
| 97 | { | ||
| 98 | if (moveDirection == Direction.North) | ||
| 99 | { | ||
| 100 | y -= (4 - moveTimer) * 4; | ||
| 101 | } else if (moveDirection == Direction.West) | ||
| 102 | { | ||
| 103 | x -= (4 - moveTimer) * 4; | ||
| 104 | } else if (moveDirection == Direction.South) | ||
| 105 | { | ||
| 106 | y += (4 - moveTimer) * 4; | ||
| 107 | } else if (moveDirection == Direction.East) | ||
| 108 | { | ||
| 109 | x += (4 - moveTimer) * 4; | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | PossibleEvent toDraw = getPossibleEvent(); | ||
| 114 | if (!toDraw.getGraphic().equals("blank")) | ||
| 115 | { | ||
| 116 | g.drawImage(toDraw.getImage(), x, y, null); | ||
| 117 | } | ||
| 118 | } | ||
| 119 | |||
| 120 | |||
| 121 | private boolean moving = false; | ||
| 122 | public boolean isMoving() | ||
| 123 | { | ||
| 124 | return moving; | ||
| 125 | } | ||
| 126 | public void setMoving(boolean moving) | ||
| 127 | { | ||
| 128 | this.moving = moving; | ||
| 129 | } | ||
| 130 | |||
| 131 | private int moveTimer; | ||
| 132 | private Direction moveDirection; | ||
| 133 | public void startMoving(Map map) throws Exception | ||
| 134 | { | ||
| 135 | Direction toMove = getPossibleEvent().getMovement().startMoving(); | ||
| 136 | |||
| 137 | if (toMove != null) | ||
| 138 | { | ||
| 139 | if (!map.checkForCollision(getLocation().x, getLocation().y, toMove)) | ||
| 140 | { | ||
| 141 | startMoving(toMove); | ||
| 142 | } | ||
| 143 | } | ||
| 144 | } | ||
| 145 | public void startMoving(Direction toMove) throws Exception | ||
| 146 | { | ||
| 147 | getPossibleEvent().setDirection(toMove); | ||
| 148 | getPossibleEvent().setAnimationStep(2); | ||
| 149 | moveTimer = 4; | ||
| 150 | moving = true; | ||
| 151 | moveDirection = toMove; | ||
| 152 | } | ||
| 153 | public void processMoving() throws Exception | ||
| 154 | { | ||
| 155 | if (moving) | ||
| 156 | { | ||
| 157 | moveTimer--; | ||
| 158 | if (moveTimer == 2) | ||
| 159 | { | ||
| 160 | getPossibleEvent().setAnimationStep(0); | ||
| 161 | } else if (moveTimer == 0) | ||
| 162 | { | ||
| 163 | getPossibleEvent().setAnimationStep(1); | ||
| 164 | moving = false; | ||
| 165 | |||
| 166 | if (moveDirection == Direction.North) | ||
| 167 | { | ||
| 168 | setLocation(getLocation().x,getLocation().y-1); | ||
| 169 | } else if (moveDirection == Direction.West) | ||
| 170 | { | ||
| 171 | setLocation(getLocation().x-1,getLocation().y); | ||
| 172 | } else if (moveDirection == Direction.South) | ||
| 173 | { | ||
| 174 | setLocation(getLocation().x,getLocation().y+1); | ||
| 175 | } else if (moveDirection == Direction.East) | ||
| 176 | { | ||
| 177 | setLocation(getLocation().x+1,getLocation().y); | ||
| 178 | } | ||
| 179 | } | ||
| 180 | } | ||
| 181 | } | ||
| 182 | |||
| 183 | public Direction getDirection() throws Exception | ||
| 184 | { | ||
| 185 | return getPossibleEvent().getDirection(); | ||
| 186 | } | ||
| 187 | public void setDirection(Direction direction) throws Exception | ||
| 188 | { | ||
| 189 | getPossibleEvent().setDirection(direction); | ||
| 190 | } | ||
| 191 | |||
| 192 | public Layer getLayer() throws Exception | ||
| 193 | { | ||
| 194 | return getPossibleEvent().getLayer(); | ||
| 195 | } | ||
| 196 | |||
| 197 | public EventCallTime getCalltime() throws Exception | ||
| 198 | { | ||
| 199 | return getPossibleEvent().getCalltime(); | ||
| 200 | } | ||
| 201 | |||
| 202 | public EventCall getCallback() throws Exception | ||
| 203 | { | ||
| 204 | return getPossibleEvent().getCallback(); | ||
| 205 | } | ||
| 206 | |||
| 207 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java new file mode 100644 index 0000000..ce9773f --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java | |||
| @@ -0,0 +1,141 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.Layer; | ||
| 9 | import com.fourisland.fourpuzzle.gamestate.mapview.event.precondition.Precondition; | ||
| 10 | import java.util.ArrayList; | ||
| 11 | import com.fourisland.fourpuzzle.Direction; | ||
| 12 | import com.fourisland.fourpuzzle.gamestate.mapview.event.graphic.BlankEventGraphic; | ||
| 13 | import com.fourisland.fourpuzzle.gamestate.mapview.event.graphic.EventGraphic; | ||
| 14 | import com.fourisland.fourpuzzle.gamestate.mapview.event.movement.MovementType; | ||
| 15 | import com.fourisland.fourpuzzle.gamestate.mapview.event.movement.StayStillMovementType; | ||
| 16 | import com.fourisland.fourpuzzle.util.Functions; | ||
| 17 | import java.awt.image.BufferedImage; | ||
| 18 | |||
| 19 | /** | ||
| 20 | *w | ||
| 21 | * @author hatkirby | ||
| 22 | */ | ||
| 23 | public class PossibleEvent { | ||
| 24 | |||
| 25 | private EventGraphic graphic; | ||
| 26 | private Layer layer; | ||
| 27 | private AnimationType animation; | ||
| 28 | private MovementType movement; | ||
| 29 | private EventCallTime calltime; | ||
| 30 | private EventCall callback; | ||
| 31 | private ArrayList<Precondition> preconditions; | ||
| 32 | |||
| 33 | private Direction direction; | ||
| 34 | private int animationStep; | ||
| 35 | |||
| 36 | public PossibleEvent() | ||
| 37 | { | ||
| 38 | graphic = new BlankEventGraphic(); | ||
| 39 | layer = Layer.Below; | ||
| 40 | animation = AnimationType.CommonWithStepping; | ||
| 41 | movement = new StayStillMovementType(); | ||
| 42 | calltime = EventCallTime.PushKey; | ||
| 43 | callback = EventCall.getEmptyEventCall(); | ||
| 44 | preconditions = new ArrayList<Precondition>(); | ||
| 45 | |||
| 46 | direction = Direction.South; | ||
| 47 | animationStep = 1; | ||
| 48 | } | ||
| 49 | |||
| 50 | public BufferedImage getImage() throws Exception | ||
| 51 | { | ||
| 52 | return graphic.getImage(); | ||
| 53 | } | ||
| 54 | |||
| 55 | public EventGraphic getGraphic() { | ||
| 56 | return graphic; | ||
| 57 | } | ||
| 58 | |||
| 59 | public void setGraphic(EventGraphic graphic) { | ||
| 60 | this.graphic = graphic; | ||
| 61 | } | ||
| 62 | |||
| 63 | public Layer getLayer() { | ||
| 64 | return layer; | ||
| 65 | } | ||
| 66 | |||
| 67 | public void setLayer(Layer layer) { | ||
| 68 | this.layer = layer; | ||
| 69 | } | ||
| 70 | |||
| 71 | public AnimationType getAnimation() { | ||
| 72 | return animation; | ||
| 73 | } | ||
| 74 | |||
| 75 | public void setAnimation(AnimationType animation) { | ||
| 76 | this.animation = animation; | ||
| 77 | } | ||
| 78 | |||
| 79 | public MovementType getMovement() { | ||
| 80 | return movement; | ||
| 81 | } | ||
| 82 | |||
| 83 | public void setMovement(MovementType movement) { | ||
| 84 | this.movement = movement; | ||
| 85 | } | ||
| 86 | |||
| 87 | public Direction getDirection() { | ||
| 88 | return direction; | ||
| 89 | } | ||
| 90 | |||
| 91 | public void setDirection(Direction direction) throws Exception { | ||
| 92 | if (Functions.canTurn(this)) | ||
| 93 | { | ||
| 94 | this.direction = direction; | ||
| 95 | graphic.setDirection(direction); | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | public int getAnimationStep() { | ||
| 100 | return animationStep; | ||
| 101 | } | ||
| 102 | |||
| 103 | public void setAnimationStep(int animationStep) { | ||
| 104 | this.animationStep = animationStep; | ||
| 105 | graphic.setAnimationStep(animationStep); | ||
| 106 | } | ||
| 107 | |||
| 108 | public void addPrecondition(Precondition precondition) | ||
| 109 | { | ||
| 110 | preconditions.add(precondition); | ||
| 111 | } | ||
| 112 | |||
| 113 | public Precondition getPrecondition(int i) | ||
| 114 | { | ||
| 115 | return preconditions.get(i); | ||
| 116 | } | ||
| 117 | |||
| 118 | public int preconditions() | ||
| 119 | { | ||
| 120 | return preconditions.size(); | ||
| 121 | } | ||
| 122 | |||
| 123 | public EventCall getCallback() | ||
| 124 | { | ||
| 125 | return callback; | ||
| 126 | } | ||
| 127 | |||
| 128 | public void setCallback(EventCall callback) | ||
| 129 | { | ||
| 130 | this.callback = callback; | ||
| 131 | } | ||
| 132 | |||
| 133 | public EventCallTime getCalltime() { | ||
| 134 | return calltime; | ||
| 135 | } | ||
| 136 | |||
| 137 | public void setCalltime(EventCallTime calltime) { | ||
| 138 | this.calltime = calltime; | ||
| 139 | } | ||
| 140 | |||
| 141 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java new file mode 100644 index 0000000..26f89c7 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java | |||
| @@ -0,0 +1,173 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.*; | ||
| 9 | import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEvent; | ||
| 10 | import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread; | ||
| 11 | import java.util.concurrent.BrokenBarrierException; | ||
| 12 | import java.util.concurrent.CyclicBarrier; | ||
| 13 | import java.util.logging.Level; | ||
| 14 | import java.util.logging.Logger; | ||
| 15 | |||
| 16 | /** | ||
| 17 | * | ||
| 18 | * @author hatkirby | ||
| 19 | */ | ||
| 20 | public class SpecialEvent { | ||
| 21 | |||
| 22 | /** | ||
| 23 | * Display a message on the screen. | ||
| 24 | * | ||
| 25 | * Usually used for dialogue. If SetFace() is | ||
| 26 | * | ||
| 27 | * used prior to this, the face set is displayed | ||
| 28 | * on the left side. | ||
| 29 | * | ||
| 30 | * Display of the message area can be modified using | ||
| 31 | * MessageDisplaySettings(). | ||
| 32 | * | ||
| 33 | * This function also automatically splits your | ||
| 34 | * message up into blocks that will fit on | ||
| 35 | * the screen (breaks at spaces). If there are too | ||
| 36 | * many words, they will be held and displayed in | ||
| 37 | * the message area after the prior message has | ||
| 38 | * been read. | ||
| 39 | * | ||
| 40 | * @param message The message to display | ||
| 41 | */ | ||
| 42 | public void DisplayMessage(String message) | ||
| 43 | { | ||
| 44 | throw new UnsupportedOperationException("Not yet implemented"); | ||
| 45 | } | ||
| 46 | |||
| 47 | /** | ||
| 48 | * Sets the face used when displaying a message | ||
| 49 | * | ||
| 50 | * See DisplayMessage() for more info | ||
| 51 | * | ||
| 52 | * @param faceSet The name of the FaceSet to use | ||
| 53 | * @param face The number of the face in the FaceSet | ||
| 54 | * to use. The faces are numbered | ||
| 55 | * horizontally. | ||
| 56 | */ | ||
| 57 | public void SetFace(String faceSet, int face) | ||
| 58 | { | ||
| 59 | throw new UnsupportedOperationException("Not yet implemented"); | ||
| 60 | } | ||
| 61 | |||
| 62 | /** | ||
| 63 | * Clears the face used when displaying a message | ||
| 64 | * | ||
| 65 | * See DisplayMessage() for more info | ||
| 66 | */ | ||
| 67 | public void EraseFace() | ||
| 68 | { | ||
| 69 | throw new UnsupportedOperationException("Not yet implemented"); | ||
| 70 | } | ||
| 71 | |||
| 72 | /** | ||
| 73 | * Sets a Switch to a [boolean] value | ||
| 74 | * | ||
| 75 | * @param switchID The Switch to set | ||
| 76 | * @param value The value to set the Switch to | ||
| 77 | */ | ||
| 78 | public void SetSwitch(String switchID, boolean value) | ||
| 79 | { | ||
| 80 | Game.getSaveFile().getSwitches().put(switchID, value); | ||
| 81 | } | ||
| 82 | |||
| 83 | /** | ||
| 84 | * Toggles a Switch's [boolean] value | ||
| 85 | * | ||
| 86 | * @param switchID The Switch to toggle | ||
| 87 | */ | ||
| 88 | public void ToggleSwitch(String switchID) | ||
| 89 | { | ||
| 90 | if (Game.getSaveFile().getSwitches().containsKey(switchID)) | ||
| 91 | { | ||
| 92 | Game.getSaveFile().getSwitches().put(switchID, !Game.getSaveFile().getSwitches().get(switchID)); | ||
| 93 | } else { | ||
| 94 | Game.getSaveFile().getSwitches().put(switchID, true); | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | /** | ||
| 99 | * Performs actions on the hero | ||
| 100 | * | ||
| 101 | * @param actions An array of MoveEvents to perform on the hero | ||
| 102 | */ | ||
| 103 | public void MoveEvent(MoveEvent[] actions) | ||
| 104 | { | ||
| 105 | MoveEvent(actions, Game.getHeroEvent()); | ||
| 106 | } | ||
| 107 | |||
| 108 | /** | ||
| 109 | * Performs actions on an event | ||
| 110 | * | ||
| 111 | * @param actions An array of MoveEvents to perform on the event | ||
| 112 | * @param ev The event to act upon | ||
| 113 | */ | ||
| 114 | public void MoveEvent(MoveEvent[] actions, Event ev) | ||
| 115 | { | ||
| 116 | new Thread(new MoveEventThread(ev, actions)).start(); | ||
| 117 | } | ||
| 118 | |||
| 119 | /** | ||
| 120 | * Waits until all previously called MoveEvent()s have finished | ||
| 121 | */ | ||
| 122 | public void MoveEventWait() | ||
| 123 | { | ||
| 124 | try { | ||
| 125 | MoveEventThread.moveEventWait.await(); | ||
| 126 | } catch (InterruptedException ex) { | ||
| 127 | Logger.getLogger(SpecialEvent.class.getName()).log(Level.SEVERE, null, ex); | ||
| 128 | } | ||
| 129 | } | ||
| 130 | |||
| 131 | /** | ||
| 132 | * Triggers the Game Over sequence | ||
| 133 | * @throws Exception | ||
| 134 | */ | ||
| 135 | public void GameOver() throws Exception | ||
| 136 | { | ||
| 137 | throw new UnsupportedOperationException("Not yet implemented"); | ||
| 138 | } | ||
| 139 | |||
| 140 | /** | ||
| 141 | * Returns the player to the Title Screen | ||
| 142 | * @throws Exception | ||
| 143 | */ | ||
| 144 | public void TitleScreen() throws Exception | ||
| 145 | { | ||
| 146 | throw new UnsupportedOperationException("Not yet implemented"); | ||
| 147 | } | ||
| 148 | |||
| 149 | /** | ||
| 150 | * Moves the player to a different map | ||
| 151 | * | ||
| 152 | * @param map The name of the map to move to | ||
| 153 | * @param x The X position on the map to move to | ||
| 154 | * @param y The Y position on the map to move to | ||
| 155 | * @throws java.lang.Exception | ||
| 156 | */ | ||
| 157 | public void Teleport(String map, int x, int y) throws Exception | ||
| 158 | { | ||
| 159 | throw new UnsupportedOperationException("Not yet implemented"); | ||
| 160 | } | ||
| 161 | |||
| 162 | /** | ||
| 163 | * Waits for a specified interval | ||
| 164 | * | ||
| 165 | * @param wait The time to wait in milliseconds | ||
| 166 | * @throws java.lang.InterruptedException | ||
| 167 | */ | ||
| 168 | public void Wait(int wait) throws InterruptedException | ||
| 169 | { | ||
| 170 | Thread.sleep(wait); | ||
| 171 | } | ||
| 172 | |||
| 173 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/BlankEventGraphic.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/BlankEventGraphic.java new file mode 100644 index 0000000..592c8a7 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/BlankEventGraphic.java | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.graphic; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.Direction; | ||
| 9 | import java.awt.image.BufferedImage; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * | ||
| 13 | * @author hatkirby | ||
| 14 | */ | ||
| 15 | public class BlankEventGraphic implements EventGraphic { | ||
| 16 | |||
| 17 | private Direction direction; | ||
| 18 | private int animationStep; | ||
| 19 | |||
| 20 | public BufferedImage getImage() throws Exception { | ||
| 21 | return null; | ||
| 22 | } | ||
| 23 | |||
| 24 | public Direction getDirection() { | ||
| 25 | return direction; | ||
| 26 | } | ||
| 27 | |||
| 28 | public void setDirection(Direction direction) { | ||
| 29 | this.direction = direction; | ||
| 30 | } | ||
| 31 | |||
| 32 | public int getAnimationStep() { | ||
| 33 | return animationStep; | ||
| 34 | } | ||
| 35 | |||
| 36 | public void setAnimationStep(int animationStep) { | ||
| 37 | this.animationStep = animationStep; | ||
| 38 | } | ||
| 39 | |||
| 40 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/CharSetEventGraphic.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/CharSetEventGraphic.java new file mode 100644 index 0000000..b71a0b8 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/CharSetEventGraphic.java | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.graphic; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.Direction; | ||
| 9 | import com.fourisland.fourpuzzle.gamestate.mapview.CharSet; | ||
| 10 | import java.awt.image.BufferedImage; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * | ||
| 14 | * @author hatkirby | ||
| 15 | */ | ||
| 16 | public class CharSetEventGraphic implements EventGraphic { | ||
| 17 | |||
| 18 | private Direction direction = Direction.South; | ||
| 19 | private int animationStep = 1; | ||
| 20 | private String graphic; | ||
| 21 | private int graphicOffset; | ||
| 22 | |||
| 23 | public CharSetEventGraphic(String graphic, int graphicOffset) | ||
| 24 | { | ||
| 25 | this.graphic = graphic; | ||
| 26 | this.graphicOffset = graphicOffset; | ||
| 27 | } | ||
| 28 | |||
| 29 | public BufferedImage getImage() throws Exception | ||
| 30 | { | ||
| 31 | return CharSet.getCharSet(getGraphic()).getImage(getGraphicOffset(), getDirection(), getAnimationStep()); | ||
| 32 | } | ||
| 33 | |||
| 34 | public Direction getDirection() | ||
| 35 | { | ||
| 36 | return direction; | ||
| 37 | } | ||
| 38 | |||
| 39 | public void setDirection(Direction direction) | ||
| 40 | { | ||
| 41 | this.direction = direction; | ||
| 42 | } | ||
| 43 | |||
| 44 | public String getGraphic() { | ||
| 45 | return graphic; | ||
| 46 | } | ||
| 47 | |||
| 48 | public void setGraphic(String graphic) { | ||
| 49 | this.graphic = graphic; | ||
| 50 | } | ||
| 51 | |||
| 52 | public int getGraphicOffset() { | ||
| 53 | return graphicOffset; | ||
| 54 | } | ||
| 55 | |||
| 56 | public void setGraphicOffset(int graphicOffset) { | ||
| 57 | this.graphicOffset = graphicOffset; | ||
| 58 | } | ||
| 59 | |||
| 60 | public int getAnimationStep() { | ||
| 61 | return animationStep; | ||
| 62 | } | ||
| 63 | |||
| 64 | public void setAnimationStep(int animationStep) { | ||
| 65 | this.animationStep = animationStep; | ||
| 66 | } | ||
| 67 | |||
| 68 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/EventGraphic.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/EventGraphic.java new file mode 100644 index 0000000..60afca5 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/EventGraphic.java | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.graphic; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.Direction; | ||
| 9 | import java.awt.image.BufferedImage; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * | ||
| 13 | * @author hatkirby | ||
| 14 | */ | ||
| 15 | public interface EventGraphic { | ||
| 16 | |||
| 17 | public BufferedImage getImage() throws Exception; | ||
| 18 | |||
| 19 | public Direction getDirection(); | ||
| 20 | public void setDirection(Direction direction); | ||
| 21 | |||
| 22 | public int getAnimationStep(); | ||
| 23 | public void setAnimationStep(int animationStep); | ||
| 24 | |||
| 25 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/CustomMovementType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/CustomMovementType.java new file mode 100644 index 0000000..3e3773f --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/CustomMovementType.java | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.movement; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.Direction; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * | ||
| 12 | * @author hatkirby | ||
| 13 | */ | ||
| 14 | public class CustomMovementType implements MovementType { | ||
| 15 | |||
| 16 | private Direction[] moves; | ||
| 17 | private int step = 0; | ||
| 18 | |||
| 19 | public CustomMovementType(Direction[] moves) | ||
| 20 | { | ||
| 21 | this.moves = moves; | ||
| 22 | } | ||
| 23 | |||
| 24 | public Direction startMoving() throws Exception | ||
| 25 | { | ||
| 26 | if (step >= moves.length) | ||
| 27 | { | ||
| 28 | step = 0; | ||
| 29 | } | ||
| 30 | |||
| 31 | return moves[step++]; | ||
| 32 | } | ||
| 33 | |||
| 34 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java new file mode 100644 index 0000000..4911a54 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.movement; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.Direction; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * | ||
| 12 | * @author hatkirby | ||
| 13 | */ | ||
| 14 | public interface MovementType { | ||
| 15 | |||
| 16 | public Direction startMoving() throws Exception; | ||
| 17 | |||
| 18 | } | ||
| 19 | |||
| 20 | /* | ||
| 21 | CycleUpDown | ||
| 22 | CycleLeftRight | ||
| 23 | StepTowardHero | ||
| 24 | StepAwayFromHero | ||
| 25 | */ \ No newline at end of file | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/RandomMovementType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/RandomMovementType.java new file mode 100644 index 0000000..d0d96ce --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/RandomMovementType.java | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.movement; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.Direction; | ||
| 9 | import java.util.Random; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * | ||
| 13 | * @author hatkirby | ||
| 14 | */ | ||
| 15 | public class RandomMovementType implements MovementType { | ||
| 16 | |||
| 17 | public Direction startMoving() throws Exception { | ||
| 18 | Random r = new Random(); | ||
| 19 | int ra = r.nextInt(1000); | ||
| 20 | Direction toMove = null; | ||
| 21 | boolean letsMove = false; | ||
| 22 | |||
| 23 | if (ra < 25) | ||
| 24 | { | ||
| 25 | toMove = Direction.North; | ||
| 26 | letsMove = true; | ||
| 27 | } else if (ra < 50) | ||
| 28 | { | ||
| 29 | toMove = Direction.West; | ||
| 30 | letsMove = true; | ||
| 31 | } else if (ra < 75) | ||
| 32 | { | ||
| 33 | toMove = Direction.South; | ||
| 34 | letsMove = true; | ||
| 35 | } else if (ra < 100) | ||
| 36 | { | ||
| 37 | toMove = Direction.East; | ||
| 38 | letsMove = true; | ||
| 39 | } | ||
| 40 | |||
| 41 | if (letsMove) | ||
| 42 | { | ||
| 43 | return toMove; | ||
| 44 | } | ||
| 45 | |||
| 46 | return null; | ||
| 47 | } | ||
| 48 | |||
| 49 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/StayStillMovementType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/StayStillMovementType.java new file mode 100644 index 0000000..a34a1f1 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/StayStillMovementType.java | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.movement; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.Direction; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * | ||
| 12 | * @author hatkirby | ||
| 13 | */ | ||
| 14 | public class StayStillMovementType implements MovementType { | ||
| 15 | |||
| 16 | public Direction startMoving() throws Exception | ||
| 17 | { | ||
| 18 | return null; // Do nothing, stay still | ||
| 19 | } | ||
| 20 | |||
| 21 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroInPartyPrecondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroInPartyPrecondition.java new file mode 100644 index 0000000..7700674 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroInPartyPrecondition.java | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.Game; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * | ||
| 12 | * @author hatkirby | ||
| 13 | */ | ||
| 14 | public class HeroInPartyPrecondition implements Precondition { | ||
| 15 | |||
| 16 | private String heroName; | ||
| 17 | |||
| 18 | public HeroInPartyPrecondition(String heroName) | ||
| 19 | { | ||
| 20 | this.heroName = heroName; | ||
| 21 | } | ||
| 22 | |||
| 23 | public boolean match() { | ||
| 24 | return Game.getSaveFile().getParty().exists(heroName); | ||
| 25 | } | ||
| 26 | |||
| 27 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroLevelPrecondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroLevelPrecondition.java new file mode 100644 index 0000000..1b10e91 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroLevelPrecondition.java | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.Game; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * | ||
| 12 | * @author hatkirby | ||
| 13 | */ | ||
| 14 | public class HeroLevelPrecondition implements Precondition { | ||
| 15 | |||
| 16 | private String heroName; | ||
| 17 | private int level; | ||
| 18 | |||
| 19 | public HeroLevelPrecondition(String heroName, int level) | ||
| 20 | { | ||
| 21 | this.heroName = heroName; | ||
| 22 | this.level = level; | ||
| 23 | } | ||
| 24 | |||
| 25 | public boolean match() throws Exception { | ||
| 26 | return (Game.getSaveFile().getParty().exists(heroName) && (Game.getSaveFile().getParty().get(heroName).getLevel() == level)); | ||
| 27 | } | ||
| 28 | |||
| 29 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/Precondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/Precondition.java new file mode 100644 index 0000000..3f75984 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/Precondition.java | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition; | ||
| 7 | |||
| 8 | /** | ||
| 9 | * | ||
| 10 | * @author hatkirby | ||
| 11 | */ | ||
| 12 | public interface Precondition { | ||
| 13 | |||
| 14 | public boolean match() throws Exception; | ||
| 15 | |||
| 16 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/SwitchPrecondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/SwitchPrecondition.java new file mode 100644 index 0000000..794eae4 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/SwitchPrecondition.java | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.Game; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * | ||
| 12 | * @author hatkirby | ||
| 13 | */ | ||
| 14 | public class SwitchPrecondition implements Precondition { | ||
| 15 | |||
| 16 | private String switchID; | ||
| 17 | |||
| 18 | public SwitchPrecondition(String switchID) | ||
| 19 | { | ||
| 20 | this.switchID = switchID; | ||
| 21 | } | ||
| 22 | |||
| 23 | public boolean match() { | ||
| 24 | return (Game.getSaveFile().getSwitches().containsKey(switchID) && Game.getSaveFile().getSwitches().get(switchID)); | ||
| 25 | } | ||
| 26 | |||
| 27 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableNumberPrecondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableNumberPrecondition.java new file mode 100644 index 0000000..a3ce086 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableNumberPrecondition.java | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.util.Comparison; | ||
| 9 | import com.fourisland.fourpuzzle.Game; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * | ||
| 13 | * @author hatkirby | ||
| 14 | */ | ||
| 15 | public class VariableNumberPrecondition implements Precondition { | ||
| 16 | |||
| 17 | private String variableID; | ||
| 18 | private Comparison comparison; | ||
| 19 | private int number; | ||
| 20 | |||
| 21 | public VariableNumberPrecondition(String variableID, Comparison comparison, int number) | ||
| 22 | { | ||
| 23 | this.variableID = variableID; | ||
| 24 | this.comparison = comparison; | ||
| 25 | this.number = number; | ||
| 26 | } | ||
| 27 | |||
| 28 | public boolean match() { | ||
| 29 | if (Game.getSaveFile().getVariables().containsKey(variableID)) | ||
| 30 | { | ||
| 31 | int n1 = Game.getSaveFile().getVariables().get(variableID); | ||
| 32 | int n2 = number; | ||
| 33 | |||
| 34 | switch (comparison) | ||
| 35 | { | ||
| 36 | case Less: return (n1 < n2); | ||
| 37 | case Greater: return (n1 > n2); | ||
| 38 | case Equal: return (n1 == n2); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | return false; | ||
| 43 | } | ||
| 44 | |||
| 45 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java new file mode 100644 index 0000000..1eb9b0c --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.util.Comparison; | ||
| 9 | import com.fourisland.fourpuzzle.Game; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * | ||
| 13 | * @author hatkirby | ||
| 14 | */ | ||
| 15 | public class VariableVariablePrecondition implements Precondition { | ||
| 16 | |||
| 17 | private String variableID; | ||
| 18 | private Comparison comparison; | ||
| 19 | private String variableID2; | ||
| 20 | |||
| 21 | public VariableVariablePrecondition(String variableID, Comparison comparison, String variableID2) | ||
| 22 | { | ||
| 23 | this.variableID = variableID; | ||
| 24 | this.comparison = comparison; | ||
| 25 | this.variableID2 = variableID2; | ||
| 26 | } | ||
| 27 | |||
| 28 | public boolean match() { | ||
| 29 | if (Game.getSaveFile().getVariables().containsKey(variableID)) | ||
| 30 | { | ||
| 31 | int n1 = Game.getSaveFile().getVariables().get(variableID); | ||
| 32 | int n2 = Game.getSaveFile().getVariables().get(variableID2); | ||
| 33 | |||
| 34 | switch (comparison) | ||
| 35 | { | ||
| 36 | case Less: return (n1 < n2); | ||
| 37 | case Greater: return (n1 > n2); | ||
| 38 | case Equal: return (n1 == n2); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | return false; | ||
| 43 | } | ||
| 44 | |||
| 45 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/FaceMoveEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/FaceMoveEvent.java new file mode 100644 index 0000000..a9dc891 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/FaceMoveEvent.java | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.Direction; | ||
| 9 | import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * | ||
| 13 | * @author hatkirby | ||
| 14 | */ | ||
| 15 | public class FaceMoveEvent implements MoveEvent { | ||
| 16 | |||
| 17 | Direction direction; | ||
| 18 | public FaceMoveEvent(Direction direction) | ||
| 19 | { | ||
| 20 | this.direction = direction; | ||
| 21 | } | ||
| 22 | |||
| 23 | public void doAction(Event ev) throws Exception | ||
| 24 | { | ||
| 25 | ev.setDirection(direction); | ||
| 26 | } | ||
| 27 | |||
| 28 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEvent.java new file mode 100644 index 0000000..66c9f6d --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEvent.java | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | |||
| 2 | /* | ||
| 3 | * To change this template, choose Tools | Templates | ||
| 4 | * and open the template in the editor. | ||
| 5 | */ | ||
| 6 | |||
| 7 | package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove; | ||
| 8 | |||
| 9 | import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * | ||
| 13 | * @author hatkirby | ||
| 14 | */ | ||
| 15 | public interface MoveEvent { | ||
| 16 | |||
| 17 | public void doAction(Event ev) throws Exception; | ||
| 18 | |||
| 19 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java new file mode 100644 index 0000000..4c16197 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; | ||
| 9 | import java.util.concurrent.CountDownLatch; | ||
| 10 | import java.util.concurrent.CyclicBarrier; | ||
| 11 | import java.util.logging.Level; | ||
| 12 | import java.util.logging.Logger; | ||
| 13 | |||
| 14 | /** | ||
| 15 | * | ||
| 16 | * @author hatkirby | ||
| 17 | */ | ||
| 18 | public class MoveEventThread implements Runnable { | ||
| 19 | |||
| 20 | public static volatile CountDownLatch moveEventWait = new CountDownLatch(0); | ||
| 21 | public static volatile int countMoveEventThreads = 0; | ||
| 22 | |||
| 23 | Event ev; | ||
| 24 | MoveEvent[] actions; | ||
| 25 | |||
| 26 | public MoveEventThread(Event ev, MoveEvent[] actions) | ||
| 27 | { | ||
| 28 | this.ev = ev; | ||
| 29 | this.actions = actions; | ||
| 30 | } | ||
| 31 | |||
| 32 | public void run() { | ||
| 33 | MoveEventThread.countMoveEventThreads++; | ||
| 34 | moveEventWait = new CountDownLatch(countMoveEventThreads); | ||
| 35 | |||
| 36 | int i=0; | ||
| 37 | for (i=0;i<actions.length;i++) | ||
| 38 | { | ||
| 39 | try { | ||
| 40 | actions[i].doAction(ev); | ||
| 41 | } catch (Exception ex) { | ||
| 42 | Logger.getLogger(MoveEventThread.class.getName()).log(Level.SEVERE, null, ex); | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | MoveEventThread.countMoveEventThreads--; | ||
| 47 | moveEventWait.countDown(); | ||
| 48 | } | ||
| 49 | |||
| 50 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/StepMoveEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/StepMoveEvent.java new file mode 100644 index 0000000..12b2421 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/StepMoveEvent.java | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.Direction; | ||
| 9 | import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * | ||
| 13 | * @author hatkirby | ||
| 14 | */ | ||
| 15 | public class StepMoveEvent implements MoveEvent { | ||
| 16 | |||
| 17 | Direction direction; | ||
| 18 | public StepMoveEvent(Direction direction) | ||
| 19 | { | ||
| 20 | this.direction = direction; | ||
| 21 | } | ||
| 22 | |||
| 23 | public void doAction(Event ev) throws Exception | ||
| 24 | { | ||
| 25 | ev.startMoving(direction); | ||
| 26 | |||
| 27 | while (ev.isMoving()) | ||
| 28 | { | ||
| 29 | Thread.sleep(2); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | } | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/WaitMoveEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/WaitMoveEvent.java new file mode 100644 index 0000000..d9823d5 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/WaitMoveEvent.java | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * | ||
| 12 | * @author hatkirby | ||
| 13 | */ | ||
| 14 | public class WaitMoveEvent implements MoveEvent { | ||
| 15 | |||
| 16 | int wait; | ||
| 17 | public WaitMoveEvent(int wait) | ||
| 18 | { | ||
| 19 | this.wait = wait; | ||
| 20 | } | ||
| 21 | |||
| 22 | public void doAction(Event ev) throws Exception | ||
| 23 | { | ||
| 24 | Thread.sleep(wait); | ||
| 25 | } | ||
| 26 | |||
| 27 | } | ||
