source: lost-perception/main/LostHavenRPG.java@ c3b2f42

Last change on this file since c3b2f42 was c3b2f42, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 6 years ago

Make the loading screen show correctly on OSX, remove some .class files that were accidentally committed, and change the name of the jar file generated by make from LostHavenRPG.jar to LostPerception.jar.

  • Property mode set to 100644
File size: 77.1 KB
Line 
1package main;
2
3import java.io.OutputStream;
4import java.io.PrintStream;
5import java.io.FileOutputStream;
6
7import java.awt.event.KeyEvent;
8import java.awt.GraphicsEnvironment;
9import java.awt.geom.Point2D;
10import java.awt.event.MouseEvent;
11import java.util.Iterator;
12import java.text.DecimalFormat;
13import java.util.ArrayList;
14import java.awt.geom.Rectangle2D;
15import java.awt.geom.Ellipse2D;
16import java.awt.MouseInfo;
17import java.awt.Shape;
18import java.awt.Rectangle;
19import java.awt.image.BufferStrategy;
20import java.awt.GraphicsConfiguration;
21import java.awt.Toolkit;
22import java.awt.GraphicsDevice;
23import java.awt.geom.Area;
24import java.awt.FontMetrics;
25import java.awt.Color;
26import java.awt.Font;
27import java.awt.Frame;
28import java.util.HashMap;
29import java.awt.Graphics;
30import java.awt.Point;
31import java.awt.event.MouseListener;
32import java.awt.event.KeyListener;
33
34import collision.Bound;
35
36import gamegui.ScrollBar;
37import gamegui.Align;
38import gamegui.Member;
39import gamegui.Textbox;
40import gamegui.Label;
41import gamegui.Button;
42import gamegui.ScrollList;
43import gamegui.Window;
44
45import utils.DynamicImage;
46import utils.Utils;
47import utils.WrappedString;
48
49public class LostHavenRPG implements KeyListener, MouseListener {
50 private static final boolean RUNNING_FROM_JAR = false;
51 GameState gameState;
52 AuxState auxState;
53 Point playerLoc;
54 boolean started;
55 boolean done;
56 boolean showFps;
57 boolean bounds;
58 boolean passable;
59 boolean minimizedGui;
60 int frameCount;
61 int lastFrameCount;
62 int refreshRate;
63 long lastFpsUpdate;
64 Graphics g;
65 HashMap<Integer, Tile> imageMap;
66 HashMap<Integer, Creature> crMap;
67 static HashMap<String, Item> itemMap;
68 Map map;
69 Frame frmMain;
70 Window wndMain;
71 Window wndCreateAccount;
72 Window wndLoadGame;
73 Window wndCredits;
74 Window wndStatDisplay;
75 Window wndDiagnostics;
76 Window wndCharacter;
77 Window wndInventory;
78 Window wndQuests;
79 boolean showCharacter;
80 boolean showInventory;
81 boolean showQuests;
82 ScrollList lstSavedGames;
83 Window wndMessage;
84 Button btnMenu;
85 Button btnStats;
86 Button btnGems;
87 Button btnInventory;
88 Button btnMap;
89 Label lblGemVal;
90 Label lblSpellCost;
91 ScrollList lstInventory;
92 ScrollList lstGems;
93 DynamicImage fullGui;
94 DynamicImage miniGui;
95 DynamicImage hpBar;
96 DynamicImage mpBar;
97 DynamicImage xpBar;
98 DynamicImage titleBg;
99 DynamicImage darkBg;
100 DynamicImage horBorder;
101 DynamicImage fireIcon;
102 DynamicImage iceIcon;
103 DynamicImage windIcon;
104 DynamicImage hpHoverBar;
105 DynamicImage gcsLogo;
106 DynamicImage dialogBg;
107 DynamicImage characterBg;
108 DynamicImage questsBg;
109 DynamicImage inventoryBg;
110 DynamicImage yellowCursor;
111 DynamicImage greenCursor;
112 DynamicImage redCursor;
113 DynamicImage cursor;
114 DynamicImage plus;
115 DynamicImage darkPlus;
116 Textbox selectedText;
117 Button selectedButton;
118 Font font11;
119 Font font12;
120 Font font14;
121 Font font24;
122 Font fontTT;
123 Font fontCustom11;
124 Font fontCustom12;
125 Font fontCustom14;
126 Font fontCustom24;
127 Font fontCustom30;
128 Font guiFont12;
129 Font guiFont14;
130 Color color1;
131 Color color2;
132 Player player;
133 Enemy cr1;
134 NPC npc;
135 FontMetrics m;
136 Dialog curDialog;
137 Item curItem;
138 Point offset;
139 boolean equipped;
140 int equipNum;
141 Area fullBorder;
142 Area miniBorder;
143 Area miniBtn;
144 Area miniBtn1;
145 Area miniBtn2;
146 Area iBtn;
147 Area eBtn;
148 Area qBtn;
149 Area mainBtn;
150 Area areaCharacter;
151 Area areaInventory;
152 Area areaQuests;
153 Area equipWeapon;
154 Area equipHead;
155 Area equipHands;
156 Area equipBody;
157 Area equipFeet;
158 WrappedString descStrength;
159 WrappedString descDexterity;
160 WrappedString descConstitution;
161 WrappedString descIntelligence;
162 Color redHaze;
163 Color blueHaze;
164 Point playerMapLoc;
165
166 public LostHavenRPG(final GraphicsDevice device) {
167 this.started = false;
168 try {
169 final GraphicsConfiguration gc = device.getDefaultConfiguration();
170 (this.frmMain = new Frame(gc)).setUndecorated(true);
171 this.frmMain.setIgnoreRepaint(true);
172 device.setFullScreenWindow(this.frmMain);
173 if (device.isDisplayChangeSupported()) {
174 Utils.chooseBestDisplayMode(device, 800, 600);
175 }
176 this.frmMain.addMouseListener(this);
177 this.frmMain.addKeyListener(this);
178 this.frmMain.createBufferStrategy(2);
179 final BufferStrategy bufferStrategy = this.frmMain.getBufferStrategy();
180 this.g = bufferStrategy.getDrawGraphics();
181 this.refreshRate = device.getDisplayMode().getRefreshRate();
182 Utils.init(gc, RUNNING_FROM_JAR);
183 this.gameState = GameState.Main;
184 this.auxState = AuxState.None;
185 this.done = false;
186 this.showFps = false;
187 this.frameCount = 0;
188 this.lastFrameCount = 0;
189 this.lastFpsUpdate = System.nanoTime();
190 this.playerLoc = new Point(400, 300);
191 this.selectedText = null;
192 this.selectedButton = null;
193 this.curItem = null;
194 this.redHaze = new Color(255, 0, 0, 100);
195 this.blueHaze = new Color(0, 0, 255, 100);
196 final boolean showCharacter = false;
197 this.showQuests = showCharacter;
198 this.showInventory = showCharacter;
199 this.showCharacter = showCharacter;
200 this.bounds = false;
201 this.passable = false;
202 this.minimizedGui = false;
203 final Toolkit tk = Toolkit.getDefaultToolkit();
204 this.frmMain.setCursor(tk.createCustomCursor(tk.createImage(""), new Point(), null));
205 this.loadGUI(bufferStrategy);
206 this.loadMap();
207 this.loadItems();
208 this.loadCreatures();
209 this.started = true;
210 while (!this.done) {
211 this.g = bufferStrategy.getDrawGraphics();
212 this.handleGameEvents();
213 this.render(this.g);
214 this.detectMouseOver(this.g);
215 if (MouseInfo.getPointerInfo().getLocation() != null) {
216 this.cursor.draw(this.g, MouseInfo.getPointerInfo().getLocation().x - 5, MouseInfo.getPointerInfo().getLocation().y - 2);
217 }
218 this.g.dispose();
219 bufferStrategy.show();
220 ++this.frameCount;
221 if (System.nanoTime() - 1000000000L >= this.lastFpsUpdate) {
222 this.lastFpsUpdate = System.nanoTime();
223 this.lastFrameCount = this.frameCount;
224 this.frameCount = 0;
225 }
226 }
227 } catch (Exception e) {
228 e.printStackTrace();
229 return;
230 } finally {
231 device.setFullScreenWindow(null);
232 }
233 device.setFullScreenWindow(null);
234 }
235
236 private void updateLoadingScreen(final BufferStrategy bufferStrategy) {
237 this.g = bufferStrategy.getDrawGraphics();
238 this.gcsLogo.draw(this.g, 0, 0);
239 this.g.setColor(Color.black);
240 this.g.setFont(this.guiFont12);
241 this.g.drawString("Loading...", 368, 31);
242 this.g.dispose();
243 bufferStrategy.show();
244 }
245
246 private void loadGUI(final BufferStrategy bufferStrategy) {
247 this.gcsLogo = new DynamicImage("gui/gcslogo.png");
248 this.guiFont12 = new Font("Garamond", 1, 12);
249 this.m = this.g.getFontMetrics(this.guiFont12);
250 this.updateLoadingScreen(bufferStrategy);
251
252 this.font11 = new Font("Arial", 0, 11);
253 this.font12 = new Font("Arial", 0, 12);
254 this.font14 = new Font("Arial", 0, 14);
255 this.font24 = new Font("Arial", 0, 24);
256 this.fontTT = new Font("Courier New", 0, 11);
257 this.guiFont14 = new Font("Garamond", 1, 14);
258 try {
259 final Font fontCustom = Utils.loadFont("images/gui/Last_words.ttf");
260 this.fontCustom11 = fontCustom.deriveFont(0, 11.0f);
261 this.fontCustom12 = fontCustom.deriveFont(0, 12.0f);
262 this.fontCustom14 = fontCustom.deriveFont(0, 14.0f);
263 this.fontCustom24 = fontCustom.deriveFont(0, 24.0f);
264 this.fontCustom30 = fontCustom.deriveFont(0, 30.0f);
265 } catch (Exception e) {
266 e.printStackTrace();
267 }
268 this.yellowCursor = new DynamicImage("gui/cursor.png");
269 this.greenCursor = new DynamicImage("gui/cursorgreen.png");
270 this.redCursor = new DynamicImage("gui/cursorred.png");
271 this.cursor = this.yellowCursor;
272 this.fullGui = new DynamicImage("gui/gui_full.png");
273 this.miniGui = new DynamicImage("gui/gui_mini.png");
274 this.hpBar = new DynamicImage("gui/hpbar.png");
275 this.mpBar = new DynamicImage("gui/mpbar.png");
276 this.xpBar = new DynamicImage("gui/xpbar2.png");
277 this.titleBg = new DynamicImage("gui/titlebg_circle.png");
278 this.darkBg = new DynamicImage("gui/darkerscreenbg.png");
279 (this.fullBorder = new Area(new Rectangle(0, 478, 291, 121))).add(new Area(new Rectangle(291, 560, 87, 39)));
280 (this.miniBorder = new Area(new Rectangle(0, 553, 291, 46))).add(new Area(new Rectangle(291, 560, 87, 39)));
281 this.fireIcon = new DynamicImage("gui/fire_icon.png");
282 this.iceIcon = new DynamicImage("gui/ice_icon.png");
283 this.windIcon = new DynamicImage("gui/wind_icon.png");
284 this.miniBtn1 = new Area(new Ellipse2D.Double(135.0, 478.0, 10.0, 10.0));
285 this.miniBtn2 = new Area(new Ellipse2D.Double(135.0, 553.0, 10.0, 10.0));
286 this.iBtn = new Area(new Ellipse2D.Double(301.0, 581.0, 17.0, 17.0));
287 this.eBtn = new Area(new Ellipse2D.Double(327.0, 581.0, 17.0, 17.0));
288 this.qBtn = new Area(new Ellipse2D.Double(353.0, 581.0, 17.0, 17.0));
289 this.mainBtn = new Area(new Rectangle(293, 563, 81, 15));
290 this.hpHoverBar = new DynamicImage("gui/hp_igbarsmall.png");
291 Creature.hpBar = this.hpHoverBar;
292 this.dialogBg = new DynamicImage("gui/dialoguebg.png");
293 this.characterBg = new DynamicImage("gui/window250x360.png");
294 this.questsBg = new DynamicImage("gui/window200x250.png");
295 this.inventoryBg = this.questsBg;
296 this.plus = new DynamicImage("gui/greenplus.png");
297 this.darkPlus = new DynamicImage("gui/darkgreenplus.png");
298 this.areaCharacter = new Area(new Rectangle(0, 98, 250, 360));
299 this.areaQuests = new Area(new Rectangle(600, 0, 250, 300));
300 this.areaInventory = new Area(new Rectangle(600, 270, 250, 300));
301 this.equipWeapon = new Area(new Rectangle(40, 285, 40, 60));
302 this.equipHead = new Area(new Rectangle(105, 275, 40, 40));
303 this.equipHands = new Area(new Rectangle(40, 360, 40, 40));
304 this.equipBody = new Area(new Rectangle(105, 330, 40, 60));
305 this.equipFeet = new Area(new Rectangle(105, 404, 40, 40));
306 this.descStrength = new WrappedString("Strength raises the damage you deal per hit", this.m, 163);
307 this.descDexterity = new WrappedString("Dexterity raises your attack rate", this.m, 163);
308 this.descConstitution = new WrappedString("Constitution raises your hitpoints", this.m, 163);
309 this.descIntelligence = new WrappedString("Intelligence raises your manapoints", this.m, 163);
310 this.wndMain = new Window("main", 0, 0, 800, 600, true);
311 final Button title = new Button("title", 0, 0, 800, 213, Utils.loadImg("gui/title.png"));
312 this.wndMain.add(title);
313 this.wndMain.background = this.titleBg;
314 this.color1 = new Color(80, 80, 80);
315 this.color2 = new Color(20, 20, 20);
316 FontMetrics metrics = this.g.getFontMetrics(this.fontCustom30);
317 this.wndMain.add(new Button("new game", 100, 270, metrics.stringWidth("Enter the world"), metrics.getHeight(), "Enter the world", this.fontCustom30, this.color1, false));
318 this.wndMain.add(new Button("load game", 140, 320, metrics.stringWidth("Back so soon?"), metrics.getHeight(), "Back so soon?", this.fontCustom30, this.color1, false));
319 this.wndMain.add(new Button("game info", 180, 370, metrics.stringWidth("How do I get there?"), metrics.getHeight(), "How do I get there?", this.fontCustom30, this.color1, false));
320 metrics = this.g.getFontMetrics(this.fontCustom24);
321 this.wndMain.add(new Button("credits", 15, 565, metrics.stringWidth("Credits"), metrics.getHeight(), "Credits", this.fontCustom24, this.color1, false));
322 this.wndMain.add(new Button("quit", 730, 565, metrics.stringWidth("Quit"), metrics.getHeight(), "Quit", this.fontCustom24, this.color1, false));
323 this.wndCharacter = new Window("character", 0, 158, 250, 299, false);
324 this.wndInventory = new Window("inventory", 600, 270, 199, 249, false);
325 this.wndQuests = new Window("quests", 600, 0, 199, 249, false);
326 this.wndStatDisplay = new Window("stat display", 0, 550, 799, 49, false);
327 this.btnMenu = new Button("main menu", 360, 10, 80, 20, "Main Menu", this.font12);
328 this.btnStats = new Button("stats", 600, 5, 80, 16, "Character", this.font12);
329 this.btnInventory = new Button("inventory", 700, 5, 80, 16, "Inventory", this.font12);
330 this.btnGems = new Button("gems", 600, 29, 80, 16, "Gems", this.font12);
331 this.btnMap = new Button("map", 700, 29, 80, 16, "Map", this.font12);
332 this.lblGemVal = new Label("gemVal", 515, 5, 67, 20, "Gem Value: 0", this.font12, Align.Right);
333 this.lblSpellCost = new Label("spellCost", 515, 24, 67, 20, "Spell Cost: 0", this.font12, Align.Right);
334 this.wndStatDisplay.add(this.btnMenu);
335 this.wndStatDisplay.add(this.btnStats);
336 this.wndStatDisplay.add(this.btnGems);
337 this.wndStatDisplay.add(this.btnInventory);
338 this.wndStatDisplay.add(this.btnMap);
339 this.wndStatDisplay.add(this.lblGemVal);
340 this.wndStatDisplay.add(this.lblSpellCost);
341 (this.wndLoadGame = new Window("load", 0, 0, 800, 600, true)).add(new Label("title", 250, 15, 300, 20, "Load Game", this.font24));
342 (this.lstSavedGames = new ScrollList("saved games", 300, 200, 200, 200, this.font14, this.frmMain.getBufferStrategy().getDrawGraphics().getFontMetrics(this.font14))).addScrollBar(new ScrollBar("scrollsave", 200, 0, 20, 200, 3, false));
343 this.wndLoadGame.add(this.lstSavedGames);
344 (this.wndCredits = new Window("main", 0, 0, 800, 600, true)).add(new Label("title", 250, 15, 300, 20, "Credits", this.fontCustom24, new Color(20, 20, 20)));
345 this.wndCredits.background = this.darkBg;
346 this.wndCredits.add(new Label("1", 250, 160, 300, 20, "Dmitry Portnoy", this.guiFont14, new Color(20, 20, 20)));
347 this.wndCredits.add(new Label("2", 250, 180, 300, 20, "Team Leader", this.guiFont12, new Color(20, 20, 20)));
348 this.wndCredits.add(new Label("3", 250, 195, 300, 20, "Programmer", this.guiFont12, new Color(20, 20, 20)));
349 this.wndCredits.add(new Label("4", 250, 235, 300, 20, "Daniel Vu", this.guiFont14, new Color(20, 20, 20)));
350 this.wndCredits.add(new Label("5", 250, 255, 300, 20, "Gui and Item Art", this.guiFont12, new Color(20, 20, 20)));
351 this.wndCredits.add(new Label("6", 250, 295, 300, 20, "David Huang", this.guiFont14, new Color(20, 20, 20)));
352 this.wndCredits.add(new Label("7", 250, 315, 300, 20, "Designer", this.guiFont12, new Color(20, 20, 20)));
353 this.wndCredits.add(new Label("4", 250, 355, 300, 20, "Free Art", this.guiFont14, new Color(20, 20, 20)));
354 this.wndCredits.add(new Label("5", 250, 375, 300, 20, "Tileset - Danc (lostgarden.com)", this.guiFont12, new Color(20, 20, 20)));
355 this.wndCredits.add(new Label("4", 250, 390, 300, 20, "Creatures - Reiner \"Tiles\" Prokein (reinerstileset.4players.de)", this.guiFont12, new Color(20, 20, 20)));
356 this.wndCredits.add(new Label("8", 250, 430, 300, 20, "Special thanks to", this.guiFont14, new Color(20, 20, 20)));
357 this.wndCredits.add(new Label("9", 250, 450, 300, 20, "The Game Creation Society", this.guiFont12, new Color(20, 20, 20)));
358 (this.wndMessage = new Window("message", 290, 135, 220, 160)).add(new Label("label", 20, 15, 180, 12, "none", this.font12));
359 this.wndMessage.add(new Button("button", 70, 115, 80, 30, "OK", this.font12));
360 this.wndDiagnostics = new Window("diagnostics", 0, 0, 400, 140, true);
361 }
362
363 private void loadMap() {
364 this.imageMap = new HashMap<Integer, Tile>();
365 this.crMap = new HashMap<Integer, Creature>();
366 for (int x = 0; x < 16; ++x) {
367 this.imageMap.put(MapImage.nextKey(), new Tile(new MapImage(new DynamicImage("tiles/ground" + (x + 1) + ".png"), MapType.Ground)));
368 }
369 for (int x = 0; x < 12; ++x) {
370 this.imageMap.put(MapImage.nextKey(), new Tile(new MapImage(new DynamicImage("tiles/cliff" + (x + 1) + ".png"), MapType.Ground)));
371 }
372 int last = 15;
373 this.imageMap.get(last + 1).getImg().setDrawOffset(-40, 0);
374 this.imageMap.get(last + 3).getImg().setDrawOffset(-40, 0);
375 this.imageMap.get(last + 5).getImg().setDrawOffset(0, -40);
376 this.imageMap.get(last + 6).getImg().setDrawOffset(0, -40);
377 this.imageMap.get(last + 7).getImg().setDrawOffset(-40, -40);
378 this.imageMap.get(last + 8).getImg().setDrawOffset(0, -40);
379 this.imageMap.get(last + 9).getImg().setDrawOffset(-40, 0);
380 this.imageMap.get(last + 1).getImg().setSortOffset(-18, 0);
381 this.imageMap.get(last + 2).getImg().setSortOffset(62, 0);
382 this.imageMap.get(last + 3).getImg().setSortOffset(-18, 0);
383 this.imageMap.get(last + 4).getImg().setSortOffset(62, 0);
384 this.imageMap.get(last + 5).getImg().setSortOffset(0, 32);
385 this.imageMap.get(last + 6).getImg().setSortOffset(0, 32);
386 this.imageMap.get(last + 7).getImg().setSortOffset(-18, 32);
387 this.imageMap.get(last + 8).getImg().setSortOffset(62, 32);
388 this.imageMap.get(last + 9).getImg().setSortOffset(-18, 75);
389 this.imageMap.get(last + 10).getImg().setSortOffset(62, 75);
390 this.imageMap.get(last + 11).getImg().setSortOffset(0, 75);
391 this.imageMap.get(last + 12).getImg().setSortOffset(0, 75);
392 this.imageMap.get(last + 1).setBound(new Bound(new Rectangle2D.Double(20.0, 0.0, 15.0, 40.0)));
393 this.imageMap.get(last + 2).setBound(new Bound(new Rectangle2D.Double(45.0, 0.0, 21.0, 40.0)));
394 this.imageMap.get(last + 3).setBound(new Bound(new Rectangle2D.Double(20.0, 0.0, 15.0, 40.0)));
395 this.imageMap.get(last + 4).setBound(new Bound(new Rectangle2D.Double(45.0, 0.0, 21.0, 40.0)));
396 this.imageMap.get(last + 5).setBound(new Bound(new Rectangle2D.Double(0.0, 20.0, 40.0, 15.0)));
397 this.imageMap.get(last + 6).setBound(new Bound(new Rectangle2D.Double(0.0, 20.0, 40.0, 15.0)));
398 this.imageMap.get(last + 11).setBound(new Bound(new Rectangle2D.Double(0.0, 45.0, 40.0, 27.0)));
399 this.imageMap.get(last + 12).setBound(new Bound(new Rectangle2D.Double(0.0, 45.0, 40.0, 27.0)));
400 Bound b1 = new Bound(new Ellipse2D.Double(20.0, -48.0, 120.0, 120.0));
401 b1.intersect(new Bound(new Rectangle2D.Double(20.0, 12.0, 60.0, 60.0)));
402 b1.add(new Bound(new Rectangle2D.Double(20.0, 0.0, 15.0, 12.0)));
403 b1.subtract(new Bound(new Ellipse2D.Double(35.0, -21.0, 66.0, 66.0)));
404 b1.subtract(new Bound(new Rectangle2D.Double(68.0, 35.0, 12.0, 10.0)));
405 final Bound b2 = new Bound(new Ellipse2D.Double(-66.0, -60.0, 132.0, 132.0));
406 b2.intersect(new Bound(new Rectangle2D.Double(0.0, 6.0, 66.0, 66.0)));
407 b2.add(new Bound(new Rectangle2D.Double(45.0, 0.0, 21.0, 6.0)));
408 b2.subtract(new Bound(new Ellipse2D.Double(-45.0, -45.0, 90.0, 90.0)));
409 final Bound b3 = new Bound(new Ellipse2D.Double(-54.0, 20.0, 120.0, 120.0));
410 b3.intersect(new Bound(new Rectangle2D.Double(6.0, 20.0, 60.0, 60.0)));
411 b3.add(new Bound(new Rectangle2D.Double(0.0, 20.0, 6.0, 15.0)));
412 b3.subtract(new Bound(new Ellipse2D.Double(-33.0, 35.0, 78.0, 78.0)));
413 b3.subtract(new Bound(new Rectangle2D.Double(39.0, 74.0, 6.0, 6.0)));
414 final Bound b4 = new Bound(new Ellipse2D.Double(20.0, 20.0, 120.0, 120.0));
415 b4.intersect(new Bound(new Rectangle2D.Double(20.0, 20.0, 60.0, 60.0)));
416 b4.subtract(new Bound(new Ellipse2D.Double(35.0, 35.0, 90.0, 90.0)));
417 this.imageMap.get(last + 7).setBound(b4);
418 this.imageMap.get(last + 8).setBound(b3);
419 this.imageMap.get(last + 9).setBound(b1);
420 this.imageMap.get(last + 10).setBound(b2);
421 this.imageMap.get(last + 7).getImg().setNeedsBase(true);
422 this.imageMap.get(last + 8).getImg().setNeedsBase(true);
423 for (int x2 = 0; x2 < 6; ++x2) {
424 this.imageMap.put(MapImage.nextKey(), new Tile(new MapImage(new DynamicImage("tiles/rock" + (x2 + 1) + ".png"), MapType.Ground)));
425 }
426 last = 33;
427 this.imageMap.put(MapImage.nextKey(), new Tile(new MapImage(new DynamicImage("objects/rock1.png"), MapType.Object)));
428 this.imageMap.put(MapImage.nextKey(), new Tile(new MapImage(new DynamicImage("objects/rock2.png"), MapType.Object)));
429 this.imageMap.put(MapImage.nextKey(), new Tile(new MapImage(new DynamicImage("objects/tree1.png"), MapType.Object)));
430 this.imageMap.put(MapImage.nextKey(), new Tile(new MapImage(new DynamicImage("objects/tree2.png"), MapType.Object)));
431 this.imageMap.get(last + 1).getImg().setDrawOffset(-22, -28);
432 this.imageMap.get(last + 2).getImg().setDrawOffset(-16, -50);
433 this.imageMap.get(last + 3).getImg().setDrawOffset(-36, -100);
434 this.imageMap.get(last + 4).getImg().setDrawOffset(-58, -83);
435 this.imageMap.get(last + 1).setBound(new Bound(new Ellipse2D.Double(-6.0, -6.0, 12.0, 12.0)));
436 this.imageMap.get(last + 2).setBound(new Bound(new Ellipse2D.Double(-6.0, -6.0, 12.0, 12.0)));
437 this.imageMap.get(last + 3).setBound(new Bound(new Ellipse2D.Double(-16.0, -16.0, 32.0, 32.0)));
438 this.imageMap.get(last + 4).setBound(new Bound(new Ellipse2D.Double(-30.0, -30.0, 60.0, 60.0)));
439 for (int x2 = 0; x2 < 19; ++x2) {
440 this.imageMap.put(MapImage.nextKey(), new Tile(new MapImage(new DynamicImage("tiles/pave" + (x2 + 1) + ".png"), MapType.Ground)));
441 }
442 for (int x2 = 0; x2 < 13; ++x2) {
443 this.imageMap.put(MapImage.nextKey(), new Tile(new MapImage(new DynamicImage("tiles/fence" + (x2 + 1) + ".png"), MapType.Structure)));
444 }
445 last = 56;
446 this.imageMap.get(last + 1).getImg().setDrawOffset(-19, -85);
447 this.imageMap.get(last + 2).getImg().setDrawOffset(-20, -85);
448 this.imageMap.get(last + 3).getImg().setDrawOffset(-20, -97);
449 this.imageMap.get(last + 4).getImg().setDrawOffset(-16, -72);
450 this.imageMap.get(last + 5).getImg().setDrawOffset(-20, -81);
451 this.imageMap.get(last + 6).getImg().setDrawOffset(-13, -45);
452 this.imageMap.get(last + 7).getImg().setDrawOffset(-20, -67);
453 this.imageMap.get(last + 8).getImg().setDrawOffset(-13, -51);
454 this.imageMap.get(last + 9).getImg().setDrawOffset(-17, -95);
455 this.imageMap.get(last + 10).getImg().setDrawOffset(-22, -95);
456 this.imageMap.get(last + 11).getImg().setDrawOffset(-19, -86);
457 this.imageMap.get(last + 12).getImg().setDrawOffset(-20, -67);
458 this.imageMap.get(last + 13).getImg().setDrawOffset(-20, -84);
459 b1 = new Bound(new Rectangle2D.Double(-14.0, -40.0, 34.0, 40.0));
460 b1.add(new Bound(new Rectangle2D.Double(-20.0, -25.0, 6.0, 25.0)));
461 this.imageMap.get(last + 1).setBound(new Bound(new Rectangle2D.Double(-14.0, -25.0, 34.0, 25.0)));
462 this.imageMap.get(last + 2).setBound(new Bound(new Rectangle2D.Double(-20.0, -25.0, 40.0, 25.0)));
463 this.imageMap.get(last + 3).setBound(new Bound(new Rectangle2D.Double(-20.0, -25.0, 40.0, 25.0)));
464 this.imageMap.get(last + 5).setBound(b1);
465 this.imageMap.get(last + 6).setBound(new Bound(new Rectangle2D.Double(-14.0, -40.0, 34.0, 40.0)));
466 this.imageMap.get(last + 7).setBound(new Bound(new Rectangle2D.Double(-20.0, -25.0, 40.0, 25.0)));
467 this.imageMap.get(last + 8).setBound(new Bound(new Rectangle2D.Double(-14.0, -40.0, 34.0, 40.0)));
468 this.imageMap.get(last + 9).setBound(new Bound(new Rectangle2D.Double(-20.0, -25.0, 40.0, 25.0)));
469 this.imageMap.get(last + 10).setBound(new Bound(new Rectangle2D.Double(-20.0, -25.0, 40.0, 25.0)));
470 this.imageMap.get(last + 11).setBound(new Bound(new Rectangle2D.Double(-14.0, -40.0, 34.0, 40.0)));
471 this.imageMap.get(last + 12).setBound(new Bound(new Rectangle2D.Double(-20.0, -25.0, 40.0, 25.0)));
472 }
473
474 private void loadItems() {
475 LostHavenRPG.itemMap = new HashMap<String, Item>();
476 final DynamicImage dagger1 = new DynamicImage("items/dagger1.png");
477 final DynamicImage dagger2 = new DynamicImage("items/dagger2.png");
478 final DynamicImage sword1 = new DynamicImage("items/sword1.png");
479 final DynamicImage sword2 = new DynamicImage("items/sword2.png");
480 final DynamicImage maul1 = new DynamicImage("items/maul1.png");
481 final DynamicImage maul2 = new DynamicImage("items/maul2.png");
482 final DynamicImage helm1 = new DynamicImage("items/helm1.png");
483 final DynamicImage helm2 = new DynamicImage("items/helm2.png");
484 final DynamicImage armor1 = new DynamicImage("items/armor1.png");
485 final DynamicImage armor2 = new DynamicImage("items/armor2.png");
486 final DynamicImage gauntlets1 = new DynamicImage("items/gauntlets1.png");
487 final DynamicImage gauntlets2 = new DynamicImage("items/gauntlets2.png");
488 final DynamicImage boots1 = new DynamicImage("items/boots1.png");
489 final DynamicImage boots2 = new DynamicImage("items/boots2.png");
490 LostHavenRPG.itemMap.put("Dirk", new Weapon("Dirk", dagger2, 10, 0.9));
491 LostHavenRPG.itemMap.put("Ripper", new Weapon("Ripper", dagger2, 18, 0.8));
492 LostHavenRPG.itemMap.put("Assassin's Blade", new Weapon("Assassin's Blade", dagger1, 35, 0.7));
493 LostHavenRPG.itemMap.get("Assassin's Blade").addEffect(new Effect.MoveSpeed(1.1));
494 LostHavenRPG.itemMap.put("Wind Rider", new Weapon("Wind Rider", dagger2, 50, 0.5));
495 LostHavenRPG.itemMap.get("Wind Rider").addEffect(new Effect.MoveSpeed(1.35));
496 LostHavenRPG.itemMap.put("Blood Seeker", new Weapon("Blood Seeker", dagger1, 70, 0.6));
497 LostHavenRPG.itemMap.get("Blood Seeker").addEffect(new Effect.MoveSpeed(1.25));
498 LostHavenRPG.itemMap.get("Blood Seeker").addEffect(new Effect.Hitpoints(60));
499 LostHavenRPG.itemMap.put("Long Sword", new Weapon("Long Sword", sword1, 14, 1.2));
500 LostHavenRPG.itemMap.put("War Sword", new Weapon("War Sword", sword1, 30, 1.4));
501 LostHavenRPG.itemMap.put("Tears of Hamlet", new Weapon("Tears of Hamlet", sword1, 50, 0.9));
502 LostHavenRPG.itemMap.get("Tears of Hamlet").addEffect(new Effect.Hitpoints(15));
503 LostHavenRPG.itemMap.put("Blade of Light", new Weapon("Blade of Light", sword2, 70, 0.9));
504 LostHavenRPG.itemMap.get("Blade of Light").addEffect(new Effect.Hitpoints(25));
505 LostHavenRPG.itemMap.put("Cursed Knight", new Weapon("Cursed Knight", sword2, 90, 0.8));
506 LostHavenRPG.itemMap.get("Cursed Knight").addEffect(new Effect.MoveSpeed(1.2));
507 LostHavenRPG.itemMap.get("Cursed Knight").addEffect(new Effect.Hitpoints(-40));
508 LostHavenRPG.itemMap.put("Warhammer", new Weapon("Warhammer", maul1, 25, 1.6));
509 LostHavenRPG.itemMap.put("Destructive Maul", new Weapon("Destructive Maul", maul1, 50, 1.5));
510 LostHavenRPG.itemMap.put("Warrior's Might", new Weapon("Warrior's Might", maul2, 80, 1.2));
511 LostHavenRPG.itemMap.get("Warrior's Might").addEffect(new Effect.Hitpoints(30));
512 LostHavenRPG.itemMap.put("Ogre's Revenge", new Weapon("Ogre's Revenge", maul1, 120, 1.4));
513 LostHavenRPG.itemMap.put("Storm Breaker", new Weapon("Storm Breaker", maul2, 100, 1.0));
514 LostHavenRPG.itemMap.get("Storm Breaker").addEffect(new Effect.Hitpoints(80));
515 LostHavenRPG.itemMap.put("Leather Helmet", new Armor("Leather Helmet", helm1, Armor.ArmorType.Head, 10));
516 LostHavenRPG.itemMap.get("Leather Helmet").addEffect(new Effect.Hitpoints(10));
517 LostHavenRPG.itemMap.put("Full Helm", new Armor("Full Helm", helm2, Armor.ArmorType.Head, 25));
518 LostHavenRPG.itemMap.get("Full Helm").addEffect(new Effect.Hitpoints(20));
519 LostHavenRPG.itemMap.get("Full Helm").addEffect(new Effect.MoveSpeed(0.9));
520 LostHavenRPG.itemMap.put("Helmet of Wilhemina", new Armor("Helmet of Wilhemina", helm1, Armor.ArmorType.Head, 30));
521 LostHavenRPG.itemMap.get("Helmet of Wilhemina").addEffect(new Effect.Hitpoints(30));
522 LostHavenRPG.itemMap.put("Poseidon", new Armor("Poseidon", helm2, Armor.ArmorType.Head, 35));
523 LostHavenRPG.itemMap.get("Poseidon").addEffect(new Effect.Hitpoints(30));
524 LostHavenRPG.itemMap.get("Poseidon").addEffect(new Effect.Damage(10));
525 LostHavenRPG.itemMap.get("Poseidon").addEffect(new Effect.MoveSpeed(0.95));
526 LostHavenRPG.itemMap.put("Mask of Cronus", new Armor("Mask of Cronus", helm2, Armor.ArmorType.Head, 40));
527 LostHavenRPG.itemMap.get("Mask of Cronus").addEffect(new Effect.Hitpoints(70));
528 LostHavenRPG.itemMap.get("Mask of Cronus").addEffect(new Effect.AttackSpeed(1.2));
529 LostHavenRPG.itemMap.get("Mask of Cronus").addEffect(new Effect.MoveSpeed(1.05));
530 LostHavenRPG.itemMap.put("Chainmail", new Armor("Chainmail", armor1, Armor.ArmorType.Body, 30));
531 LostHavenRPG.itemMap.get("Chainmail").addEffect(new Effect.Hitpoints(50));
532 LostHavenRPG.itemMap.put("Full Plate", new Armor("Full Plate", armor2, Armor.ArmorType.Body, 60));
533 LostHavenRPG.itemMap.get("Full Plate").addEffect(new Effect.Hitpoints(60));
534 LostHavenRPG.itemMap.get("Full Plate").addEffect(new Effect.MoveSpeed(0.9));
535 LostHavenRPG.itemMap.put("Menoetius", new Armor("Menoetius", armor1, Armor.ArmorType.Body, 60));
536 LostHavenRPG.itemMap.get("Menoetius").addEffect(new Effect.Hitpoints(120));
537 LostHavenRPG.itemMap.get("Menoetius").addEffect(new Effect.AttackSpeed(1.1));
538 LostHavenRPG.itemMap.put("Coat of Themis", new Armor("Coat of Themis", armor1, Armor.ArmorType.Body, 100));
539 LostHavenRPG.itemMap.get("Coat of Themis").addEffect(new Effect.Hitpoints(80));
540 LostHavenRPG.itemMap.get("Coat of Themis").addEffect(new Effect.MoveSpeed(1.1));
541 LostHavenRPG.itemMap.get("Coat of Themis").addEffect(new Effect.Damage(20));
542 LostHavenRPG.itemMap.put("Kingship", new Armor("Kingship", armor2, Armor.ArmorType.Body, 120));
543 LostHavenRPG.itemMap.get("Kingship").addEffect(new Effect.Hitpoints(200));
544 LostHavenRPG.itemMap.get("Kingship").addEffect(new Effect.MoveSpeed(1.2));
545 LostHavenRPG.itemMap.get("Kingship").addEffect(new Effect.Damage(40));
546 LostHavenRPG.itemMap.put("Cloth Gloves", new Armor("Cloth Gloves", gauntlets1, Armor.ArmorType.Hands, 5));
547 LostHavenRPG.itemMap.get("Cloth Gloves").addEffect(new Effect.Hitpoints(6));
548 LostHavenRPG.itemMap.put("Golden Fist", new Armor("Golden Fist", gauntlets1, Armor.ArmorType.Hands, 10));
549 LostHavenRPG.itemMap.get("Golden Fist").addEffect(new Effect.Hitpoints(6));
550 LostHavenRPG.itemMap.get("Golden Fist").addEffect(new Effect.AttackSpeed(1.1));
551 LostHavenRPG.itemMap.put("Gloves of Selene", new Armor("Gloves of Selene", gauntlets1, Armor.ArmorType.Hands, 15));
552 LostHavenRPG.itemMap.get("Gloves of Selene").addEffect(new Effect.Hitpoints(30));
553 LostHavenRPG.itemMap.put("Delta Force", new Armor("Delta Force", gauntlets2, Armor.ArmorType.Hands, 20));
554 LostHavenRPG.itemMap.get("Delta Force").addEffect(new Effect.Hitpoints(20));
555 LostHavenRPG.itemMap.get("Delta Force").addEffect(new Effect.MoveSpeed(1.05));
556 LostHavenRPG.itemMap.get("Delta Force").addEffect(new Effect.AttackSpeed(1.05));
557 LostHavenRPG.itemMap.put("Zeus", new Armor("Zeus", gauntlets2, Armor.ArmorType.Hands, 20));
558 LostHavenRPG.itemMap.get("Zeus").addEffect(new Effect.Hitpoints(50));
559 LostHavenRPG.itemMap.get("Zeus").addEffect(new Effect.MoveSpeed(1.1));
560 LostHavenRPG.itemMap.get("Zeus").addEffect(new Effect.AttackSpeed(1.3));
561 LostHavenRPG.itemMap.put("Cloth Boots", new Armor("Cloth Boots", boots1, Armor.ArmorType.Feet, 5));
562 LostHavenRPG.itemMap.get("Cloth Boots").addEffect(new Effect.Hitpoints(8));
563 LostHavenRPG.itemMap.put("Greaves", new Armor("Greaves", boots2, Armor.ArmorType.Feet, 20));
564 LostHavenRPG.itemMap.get("Greaves").addEffect(new Effect.Hitpoints(20));
565 LostHavenRPG.itemMap.get("Greaves").addEffect(new Effect.MoveSpeed(0.92));
566 LostHavenRPG.itemMap.put("Leather Boots", new Armor("Leather Boots", boots1, Armor.ArmorType.Feet, 15));
567 LostHavenRPG.itemMap.get("Leather Boots").addEffect(new Effect.Hitpoints(10));
568 LostHavenRPG.itemMap.get("Leather Boots").addEffect(new Effect.MoveSpeed(1.2));
569 LostHavenRPG.itemMap.put("Dragon's Scale", new Armor("Dragon's Scale", boots2, Armor.ArmorType.Feet, 30));
570 LostHavenRPG.itemMap.get("Dragon's Scale").addEffect(new Effect.Hitpoints(10));
571 LostHavenRPG.itemMap.get("Dragon's Scale").addEffect(new Effect.MoveSpeed(1.25));
572 LostHavenRPG.itemMap.get("Dragon's Scale").addEffect(new Effect.AttackSpeed(1.1));
573 LostHavenRPG.itemMap.put("Assassin's Step", new Armor("Assassin's Step", boots1, Armor.ArmorType.Feet, 20));
574 LostHavenRPG.itemMap.get("Assassin's Step").addEffect(new Effect.Hitpoints(30));
575 LostHavenRPG.itemMap.get("Assassin's Step").addEffect(new Effect.MoveSpeed(1.4));
576 LostHavenRPG.itemMap.get("Assassin's Step").addEffect(new Effect.AttackSpeed(1.3));
577 }
578
579 private void loadCreatures() {
580 Utils.loadCreatures(this.crMap, null);
581 ((Enemy)this.crMap.get(1)).addItemDrop(LostHavenRPG.itemMap.get("Cloth Boots"), 0.3);
582 ((Enemy)this.crMap.get(1)).addItemDrop(LostHavenRPG.itemMap.get("Leather Helmet"), 0.3);
583 ((Enemy)this.crMap.get(1)).addItemDrop(LostHavenRPG.itemMap.get("Chainmail"), 0.3);
584 ((Enemy)this.crMap.get(1)).addItemDrop(LostHavenRPG.itemMap.get("Cloth Gloves"), 0.3);
585 ((Enemy)this.crMap.get(1)).addItemDrop(LostHavenRPG.itemMap.get("Dirk"), 0.3);
586 ((Enemy)this.crMap.get(1)).addItemDrop(LostHavenRPG.itemMap.get("Long Sword"), 0.3);
587 ((Enemy)this.crMap.get(1)).addItemDrop(LostHavenRPG.itemMap.get("Warhammer"), 0.3);
588 ((Enemy)this.crMap.get(1)).addItemDrop(LostHavenRPG.itemMap.get("Greaves"), 0.15);
589 ((Enemy)this.crMap.get(1)).addItemDrop(LostHavenRPG.itemMap.get("Full Helm"), 0.15);
590 ((Enemy)this.crMap.get(1)).addItemDrop(LostHavenRPG.itemMap.get("Full Plate"), 0.15);
591 ((Enemy)this.crMap.get(1)).addItemDrop(LostHavenRPG.itemMap.get("Golden Fist"), 0.15);
592 ((Enemy)this.crMap.get(1)).addItemDrop(LostHavenRPG.itemMap.get("Ripper"), 0.15);
593 ((Enemy)this.crMap.get(1)).addItemDrop(LostHavenRPG.itemMap.get("War Sword"), 0.15);
594 ((Enemy)this.crMap.get(1)).addItemDrop(LostHavenRPG.itemMap.get("Destructive Maul"), 0.15);
595
596 ((Enemy)this.crMap.get(2)).addItemDrop(LostHavenRPG.itemMap.get("Greaves"), 0.3);
597 ((Enemy)this.crMap.get(2)).addItemDrop(LostHavenRPG.itemMap.get("Full Helm"), 0.3);
598 ((Enemy)this.crMap.get(2)).addItemDrop(LostHavenRPG.itemMap.get("Full Plate"), 0.3);
599 ((Enemy)this.crMap.get(2)).addItemDrop(LostHavenRPG.itemMap.get("Golden Fist"), 0.3);
600 ((Enemy)this.crMap.get(2)).addItemDrop(LostHavenRPG.itemMap.get("Ripper"), 0.3);
601 ((Enemy)this.crMap.get(2)).addItemDrop(LostHavenRPG.itemMap.get("War Sword"), 0.3);
602 ((Enemy)this.crMap.get(2)).addItemDrop(LostHavenRPG.itemMap.get("Destructive Maul"), 0.3);
603 ((Enemy)this.crMap.get(2)).addItemDrop(LostHavenRPG.itemMap.get("Leather Boots"), 0.15);
604 ((Enemy)this.crMap.get(2)).addItemDrop(LostHavenRPG.itemMap.get("Helmet of Wilhemina"), 0.15);
605 ((Enemy)this.crMap.get(2)).addItemDrop(LostHavenRPG.itemMap.get("Menoetius"), 0.15);
606 ((Enemy)this.crMap.get(2)).addItemDrop(LostHavenRPG.itemMap.get("Gloves of Selene"), 0.15);
607 ((Enemy)this.crMap.get(2)).addItemDrop(LostHavenRPG.itemMap.get("Assassin's Blade"), 0.15);
608 ((Enemy)this.crMap.get(2)).addItemDrop(LostHavenRPG.itemMap.get("Tears of Hamlet"), 0.15);
609 ((Enemy)this.crMap.get(2)).addItemDrop(LostHavenRPG.itemMap.get("Warrior's Might"), 0.15);
610
611 ((Enemy)this.crMap.get(4)).addItemDrop(LostHavenRPG.itemMap.get("Dragon's Scale"), 0.5);
612 ((Enemy)this.crMap.get(4)).addItemDrop(LostHavenRPG.itemMap.get("Poseidon"), 0.5);
613 ((Enemy)this.crMap.get(4)).addItemDrop(LostHavenRPG.itemMap.get("Coat of Themis"), 0.5);
614 ((Enemy)this.crMap.get(4)).addItemDrop(LostHavenRPG.itemMap.get("Delta Force"), 0.5);
615 ((Enemy)this.crMap.get(4)).addItemDrop(LostHavenRPG.itemMap.get("Wind Rider"), 0.5);
616 ((Enemy)this.crMap.get(4)).addItemDrop(LostHavenRPG.itemMap.get("Blade of Light"), 0.5);
617 ((Enemy)this.crMap.get(4)).addItemDrop(LostHavenRPG.itemMap.get("Ogre's Revenge"), 0.5);
618 ((Enemy)this.crMap.get(4)).addItemDrop(LostHavenRPG.itemMap.get("Assassin's Step"), 0.3);
619 ((Enemy)this.crMap.get(4)).addItemDrop(LostHavenRPG.itemMap.get("Mask of Cronus"), 0.3);
620 ((Enemy)this.crMap.get(4)).addItemDrop(LostHavenRPG.itemMap.get("Kingship"), 0.3);
621 ((Enemy)this.crMap.get(4)).addItemDrop(LostHavenRPG.itemMap.get("Zeus"), 0.3);
622 ((Enemy)this.crMap.get(4)).addItemDrop(LostHavenRPG.itemMap.get("Blood Seeker"), 0.3);
623 ((Enemy)this.crMap.get(4)).addItemDrop(LostHavenRPG.itemMap.get("Cursed Knight"), 0.3);
624 ((Enemy)this.crMap.get(4)).addItemDrop(LostHavenRPG.itemMap.get("Storm Breaker"), 0.3);
625
626 ((Enemy)this.crMap.get(6)).addItemDrop(LostHavenRPG.itemMap.get("Leather Boots"), 0.3);
627 ((Enemy)this.crMap.get(6)).addItemDrop(LostHavenRPG.itemMap.get("Helmet of Wilhemina"), 0.3);
628 ((Enemy)this.crMap.get(6)).addItemDrop(LostHavenRPG.itemMap.get("Menoetius"), 0.3);
629 ((Enemy)this.crMap.get(6)).addItemDrop(LostHavenRPG.itemMap.get("Gloves of Selene"), 0.3);
630 ((Enemy)this.crMap.get(6)).addItemDrop(LostHavenRPG.itemMap.get("Assassin's Blade"), 0.3);
631 ((Enemy)this.crMap.get(6)).addItemDrop(LostHavenRPG.itemMap.get("Tears of Hamlet"), 0.3);
632 ((Enemy)this.crMap.get(6)).addItemDrop(LostHavenRPG.itemMap.get("Warrior's Might"), 0.3);
633 ((Enemy)this.crMap.get(6)).addItemDrop(LostHavenRPG.itemMap.get("Dragon's Scale"), 0.15);
634 ((Enemy)this.crMap.get(6)).addItemDrop(LostHavenRPG.itemMap.get("Poseidon"), 0.15);
635 ((Enemy)this.crMap.get(6)).addItemDrop(LostHavenRPG.itemMap.get("Coat of Themis"), 0.15);
636 ((Enemy)this.crMap.get(6)).addItemDrop(LostHavenRPG.itemMap.get("Delta Force"), 0.15);
637 ((Enemy)this.crMap.get(6)).addItemDrop(LostHavenRPG.itemMap.get("Wind Rider"), 0.15);
638 ((Enemy)this.crMap.get(6)).addItemDrop(LostHavenRPG.itemMap.get("Blade of Light"), 0.15);
639 ((Enemy)this.crMap.get(6)).addItemDrop(LostHavenRPG.itemMap.get("Ogre's Revenge"), 0.15);
640
641 this.map = Map.load("finalMap.txt", null, this.imageMap, this.crMap);
642 (this.player = new Player("Japheth", this.crMap.get(3).xOffset, this.crMap.get(3).yOffset, 1, 0)).setModel(new Model(this.crMap.get(3).getModel()));
643 this.player.setLoc(new Point(2800, 2880));
644 this.player.setBound(this.crMap.get(3).getBound());
645 this.player.setSelectionBound(this.crMap.get(3).getSelectionBound());
646 this.player.strikeFrame = this.crMap.get(3).strikeFrame;
647 this.player.setAttack(8, 0, 40, 60);
648 this.player.setStats(8, 8, 8, 8);
649 this.map.addCreature(70, 72, this.player);
650 this.playerMapLoc = new Point(70, 72);
651 (this.npc = new NPC("Seer", this.crMap.get(5).xOffset, this.crMap.get(5).yOffset)).setModel(new Model(this.crMap.get(5).getModel()));
652 this.npc.setLoc(new Point(2800, 1600));
653 this.npc.setBound(this.crMap.get(5).getBound());
654 this.npc.setSelectionBound(this.crMap.get(5).getSelectionBound());
655 this.npc.getModel().direction = Direction.South;
656 this.npc.loadDialog("seerDialog.txt", this.m, 756);
657 this.map.addCreature(70, 40, this.npc);
658 (this.npc = new NPC("Wounded Resistance Fighter", this.crMap.get(0).xOffset, this.crMap.get(0).yOffset)).setModel(new Model(this.crMap.get(0).getModel()));
659 this.npc.setLoc(new Point(1152, 1403));
660 this.npc.setBound(this.crMap.get(0).getBound());
661 this.npc.setSelectionBound(this.crMap.get(0).getSelectionBound());
662 this.npc.getModel().direction = Direction.NorthEast;
663 this.npc.loadDialog("nullDialog.txt", this.m, 756);
664 this.map.addCreature(28, 35, this.npc);
665 (this.npc = new NPC("Captured Resistance Fighter", this.crMap.get(0).xOffset, this.crMap.get(0).yOffset)).setModel(new Model(this.crMap.get(0).getModel()));
666 this.npc.setLoc(new Point(2058, 1638));
667 this.npc.setBound(this.crMap.get(0).getBound());
668 this.npc.setSelectionBound(this.crMap.get(0).getSelectionBound());
669 this.npc.getModel().direction = Direction.North;
670 this.npc.loadDialog("nullDialog.txt", this.m, 756);
671 this.map.addCreature(51, 40, this.npc);
672 (this.npc = new NPC("Resistance Fighter", this.crMap.get(0).xOffset, this.crMap.get(0).yOffset)).setModel(new Model(this.crMap.get(0).getModel()));
673 this.npc.setLoc(new Point(3204, 1345));
674 this.npc.setBound(this.crMap.get(0).getBound());
675 this.npc.setSelectionBound(this.crMap.get(0).getSelectionBound());
676 this.npc.getModel().direction = Direction.South;
677 this.npc.loadDialog("nullDialog.txt", this.m, 756);
678 this.map.addCreature(80, 33, this.npc);
679 (this.npc = new NPC("Resistance Fighter", this.crMap.get(0).xOffset, this.crMap.get(0).yOffset)).setModel(new Model(this.crMap.get(0).getModel()));
680 this.npc.setLoc(new Point(2879, 1270));
681 this.npc.setBound(this.crMap.get(0).getBound());
682 this.npc.setSelectionBound(this.crMap.get(0).getSelectionBound());
683 this.npc.getModel().direction = Direction.South;
684 this.npc.loadDialog("nullDialog.txt", this.m, 756);
685 this.map.addCreature(71, 31, this.npc);
686 (this.npc = new NPC("Wayfarer", this.crMap.get(5).xOffset, this.crMap.get(5).yOffset)).setModel(new Model(this.crMap.get(5).getModel()));
687 this.npc.setLoc(new Point(2880, 2718));
688 this.npc.setBound(this.crMap.get(5).getBound());
689 this.npc.setSelectionBound(this.crMap.get(5).getSelectionBound());
690 this.npc.getModel().direction = Direction.South;
691 this.npc.loadDialog("wayfarerDialog.txt", this.m, 756);
692 this.map.addCreature(72, 67, this.npc);
693 }
694
695 private synchronized void handleGameEvents() {
696 switch (this.gameState) {
697 case Game: {
698 if (this.player.isTalking() && this.curDialog == null) {
699 this.curDialog = this.player.getNPCTarget().dialog;
700 this.gameState = GameState.GameDialog;
701 final boolean showCharacter = false;
702 this.showInventory = showCharacter;
703 this.showQuests = showCharacter;
704 this.showCharacter = showCharacter;
705 }
706 this.executeAI();
707 this.moveCreatures();
708 break;
709 }
710 }
711 }
712
713 private synchronized void render(final Graphics g) {
714 g.setColor(Color.black);
715 g.fillRect(0, 0, 800, 600);
716 switch (this.gameState) {
717 case Main: {
718 this.wndMain.draw(g);
719 break;
720 }
721 case LoadGame: {
722 this.drawLoadGame(g);
723 break;
724 }
725 case Credits: {
726 this.drawCredits(g);
727 break;
728 }
729 case Game: {
730 this.playerLoc = this.player.loc;
731 this.map.draw(g, this.playerLoc, this.bounds, this.passable);
732 this.drawStatDisplay(g);
733 break;
734 }
735 case GameDialog: {
736 this.playerLoc = this.player.loc;
737 this.map.draw(g, this.playerLoc, this.bounds, this.passable);
738 this.drawStatDisplay(g);
739 this.drawDialog(g);
740 break;
741 }
742 }
743 switch (this.auxState) {
744 case MsgBox: {
745 this.wndMessage.draw(g);
746 break;
747 }
748 }
749 if (this.showFps) {
750 this.drawDiagnostics(g);
751 }
752 }
753
754 public void showMessage(final String text) {
755 this.auxState = AuxState.MsgBox;
756 ((Label)this.wndMessage.getMember("label")).setText(text);
757 }
758
759 private void drawLoadGame(final Graphics g) {
760 final Font tempFont = new Font("Arial", 0, 12);
761 final FontMetrics metrics = g.getFontMetrics(tempFont);
762 g.setFont(tempFont);
763 g.setColor(Color.green);
764 g.drawString("There is not a whole lot here right now. You can click anywhere on the screen to get back to the main menu.", 0, metrics.getHeight());
765 }
766
767 private void drawStatDisplay(final Graphics g) {
768 g.setFont(this.guiFont12);
769 g.setColor(new Color(60, 60, 60));
770 final String hpString = "HP " + this.player.hitpoints + "/" + this.player.maxHitpoints;
771 final String mpString = "MP " + this.player.manapoints + "/" + this.player.maxManapoints;
772 final String xpString = "XP " + this.player.experience + "/" + this.player.getMaxExperience();
773 if (this.minimizedGui) {
774 this.miniGui.draw(g, 0, 600 - this.miniGui.getHeight());
775 g.drawString(this.player.name, 24, 578);
776 g.drawString(hpString, 110, 578);
777 g.drawString(xpString, 190, 578);
778 g.drawString("Level " + this.player.level, 24, 595);
779 g.drawString(mpString, 110, 595);
780 g.drawString("347", 227, 595);
781 } else {
782 this.fullGui.draw(g, 0, 600 - this.fullGui.getHeight());
783 this.hpBar.draw(g, 147, 503, 147 + this.hpBar.getWidth() * this.player.hitpoints / this.player.maxHitpoints, 503 + this.hpBar.getHeight(), 0, 0, this.hpBar.getWidth() * this.player.hitpoints / this.player.maxHitpoints, this.hpBar.getHeight());
784 this.mpBar.draw(g, 147, 537, 147 + this.mpBar.getWidth() * this.player.manapoints / this.player.maxManapoints, 537 + this.mpBar.getHeight(), 0, 0, this.mpBar.getWidth() * this.player.manapoints / this.player.maxManapoints, this.mpBar.getHeight());
785 this.xpBar.draw(g, 12, 572, 12 + this.xpBar.getWidth() * this.player.experience / this.player.getMaxExperience(), 572 + this.xpBar.getHeight(), 0, 0, this.xpBar.getWidth() * this.player.experience / this.player.getMaxExperience(), this.xpBar.getHeight());
786 g.drawString(this.player.name, 24, 515);
787 g.drawString("Level " + this.player.level, 24, 533);
788 g.drawString("Currency:", 24, 551);
789 g.drawString("347", 97, 551);
790 g.drawString(hpString, 147 + (this.hpBar.getWidth() - this.m.stringWidth(hpString)) / 2, 514);
791 g.drawString(mpString, 147 + (this.mpBar.getWidth() - this.m.stringWidth(mpString)) / 2, 548);
792 g.drawString(xpString, 12 + (this.xpBar.getWidth() - this.m.stringWidth(xpString)) / 2, 585);
793 }
794 this.fireIcon.draw(g, 580, 540);
795 this.iceIcon.draw(g, 650, 540);
796 this.windIcon.draw(g, 720, 540);
797 if (this.showCharacter) {
798 this.characterBg.draw(g, 0, 98);
799 g.setColor(new Color(120, 240, 120));
800 final DecimalFormat format = new DecimalFormat("0.00");
801 g.drawString("Strength: " + this.player.stats[StatType.Strength.ordinal()], 22, 128);
802 g.drawString("Dexterity: " + this.player.stats[StatType.Dexterity.ordinal()], 22, 143);
803 g.drawString("Constitution: " + this.player.stats[StatType.Constitution.ordinal()], 22, 158);
804 g.drawString("Intelligence: " + this.player.stats[StatType.Intelligence.ordinal()], 22, 173);
805 g.drawString("Remaining Stat Points: " + this.player.statPoints, 22, 188);
806 g.drawString("Damage: " + this.player.getDamage(), 22, 218);
807 g.drawString("Attack Speed: " + format.format(this.player.getAttackSpeed()), 22, 233);
808 g.drawString("Move Speed: " + format.format(this.player.moveSpeedMod), 22, 248);
809 g.drawString("Armor Rating: " + this.player.stats[StatType.Armor.ordinal()], 22, 263);
810 DynamicImage img;
811 if (this.player.statPoints == 0) {
812 img = this.darkPlus;
813 }
814 else {
815 img = this.plus;
816 }
817 img.draw(g, 178, 118);
818 img.draw(g, 178, 133);
819 img.draw(g, 178, 148);
820 img.draw(g, 178, 163);
821 g.setColor(new Color(120, 120, 240));
822 g.drawRect(105, 275, 40, 40);
823 g.drawRect(105, 330, 40, 60);
824 g.drawRect(105, 404, 40, 40);
825 g.drawRect(40, 285, 40, 60);
826 g.drawRect(40, 360, 40, 40);
827 if (this.player.weapon != null) {
828 this.player.weapon.getImg().draw(g, 40, 285);
829 }
830 if (this.player.armor[0] != null) {
831 this.player.armor[0].getImg().draw(g, 105, 275);
832 }
833 if (this.player.armor[1] != null) {
834 this.player.armor[1].getImg().draw(g, 40, 360);
835 }
836 if (this.player.armor[2] != null) {
837 this.player.armor[2].getImg().draw(g, 105, 330);
838 }
839 if (this.player.armor[3] != null) {
840 this.player.armor[3].getImg().draw(g, 105, 404);
841 }
842 }
843 if (this.showQuests) {
844 this.questsBg.draw(g, 600, 0);
845 }
846 if (this.showInventory) {
847 this.inventoryBg.draw(g, 600, 270);
848 g.setColor(new Color(30, 30, 60));
849 for (int i = 0; i < this.player.invSpace.length + 1; ++i) {
850 g.drawLine(620, 295 + 20 * i, 780, 295 + 20 * i);
851 }
852 for (int i = 0; i < this.player.invSpace[0].length + 1; ++i) {
853 g.drawLine(620 + 20 * i, 295, 620 + 20 * i, 495);
854 }
855 for (final Item cur : this.player.inventory) {
856 cur.getImg().draw(g, 620 + 20 * cur.invX, 295 + 20 * cur.invY);
857 }
858 }
859 }
860
861 private void drawDialog(final Graphics g) {
862 this.dialogBg.draw(g, 0, 450);
863 g.setFont(this.guiFont12);
864 g.setColor(new Color(0, 0, 0));
865 this.curDialog.text.draw(g, 22, 480);
866 int pos = 0;
867 if (this.curDialog.text.getLineCount() > 3) {
868 pos = 480 + this.m.getHeight() * (this.curDialog.text.getLineCount() + 1);
869 }
870 else {
871 pos = 480 + this.m.getHeight() * 4;
872 }
873 for (int i = 0; i < this.curDialog.getNumOptions(); ++i) {
874 this.curDialog.getOption(i).draw(g, 22, pos);
875 pos += this.m.getHeight() * this.curDialog.getOption(i).getLineCount();
876 }
877 }
878
879 private void drawCredits(final Graphics g) {
880 this.wndCredits.draw(g);
881 }
882
883 private void drawDiagnostics(final Graphics g) {
884 this.wndDiagnostics.draw(g);
885 g.setColor(Color.green);
886 g.setFont(this.fontTT);
887 g.drawString("Unthrottled FPS: " + this.lastFrameCount, 0, 15);
888 g.drawString("Monitor Refresh Rate: " + this.refreshRate, 0, 30);
889 g.drawString("Player Info", 0, 60);
890 g.drawString("Location " + this.player.loc.x + "," + this.player.loc.y + " (" + this.player.getSortZ() + " sort offset)", 0, 75);
891 g.drawString("Map Location: " + this.playerMapLoc.x + "," + this.playerMapLoc.y, 0, 90);
892 g.drawString("Equals itself: " + this.player.compareTo((MapObject)this.player), 0, 105);
893 g.drawString("Should be drawn: " + this.map.creatures.contains(this.player), 0, 120);
894 g.drawString("Dead: " + this.player.dead, 0, 135);
895 final Iterator<Creature> iter = this.map.creatures.iterator();
896 int lineCount = 1;
897 while (iter.hasNext()) {
898 final Creature cur = iter.next();
899 g.drawString(String.valueOf(cur.name) + " " + cur.loc.x / 40 + "," + cur.loc.y / 40, 280, lineCount * 15);
900 ++lineCount;
901 }
902 }
903
904 private int getDialogSelection(final MouseEvent e) {
905 final int x = e.getX();
906 final int y = e.getY();
907 if (x < 22 || 778 < x) {
908 return -1;
909 }
910 int curY;
911 if (this.curDialog.text.getLineCount() > 3) {
912 curY = 480 + this.m.getHeight() * this.curDialog.text.getLineCount();
913 }
914 else {
915 curY = 480 + this.m.getHeight() * 3 + 3;
916 }
917 for (int i = 0; i < this.curDialog.getNumOptions(); ++i) {
918 if (curY < y && y <= curY + this.m.getHeight() * this.curDialog.getOption(i).getLineCount()) {
919 return i;
920 }
921 curY += this.m.getHeight() * this.curDialog.getOption(i).getLineCount();
922 }
923 return -1;
924 }
925
926 private synchronized void detectMouseOver(final Graphics g) {
927 final Point e = MouseInfo.getPointerInfo().getLocation();
928 if (e == null) {
929 return;
930 }
931 g.setFont(this.guiFont12);
932 switch (this.gameState) {
933 case Main: {
934 if (this.selectedButton != null) {
935 this.selectedButton.color = this.color1;
936 }
937 if (this.wndMain.getMember("new game").isClicked(e.x, e.y)) {
938 this.selectedButton = (Button)this.wndMain.getMember("new game");
939 } else if (this.wndMain.getMember("load game").isClicked(e.x, e.y)) {
940 this.selectedButton = (Button)this.wndMain.getMember("load game");
941 } else if (this.wndMain.getMember("game info").isClicked(e.x, e.y)) {
942 this.selectedButton = (Button)this.wndMain.getMember("game info");
943 } else if (this.wndMain.getMember("credits").isClicked(e.x, e.y)) {
944 this.selectedButton = (Button)this.wndMain.getMember("credits");
945 } else if (this.wndMain.getMember("quit").isClicked(e.x, e.y)) {
946 this.selectedButton = (Button)this.wndMain.getMember("quit");
947 } else {
948 this.selectedButton = null;
949 }
950 if (this.selectedButton != null) {
951 this.selectedButton.color = this.color2;
952 break;
953 }
954 break;
955 }
956 case Game: {
957 if (this.showCharacter) {
958 if (20 <= e.x && e.x <= 105) {
959 if (117 <= e.y && e.y <= 131) {
960 this.drawDesc(g, this.descStrength, e.x, e.y, 169);
961 }
962 else if (132 <= e.y && e.y <= 146) {
963 this.drawDesc(g, this.descDexterity, e.x, e.y, 169);
964 }
965 else if (147 <= e.y && e.y <= 161) {
966 this.drawDesc(g, this.descConstitution, e.x, e.y, 169);
967 }
968 else if (162 <= e.y && e.y <= 176) {
969 this.drawDesc(g, this.descIntelligence, e.x, e.y, 169);
970 }
971 }
972 if (this.equipWeapon.contains(e) && this.player.weapon != null) {
973 this.player.weapon.drawDesc(g, e.x, e.y, this.guiFont12, this.m);
974 }
975 else if (this.equipHead.contains(e) && this.player.armor[0] != null) {
976 this.player.armor[0].drawDesc(g, e.x, e.y, this.guiFont12, this.m);
977 }
978 else if (this.equipHands.contains(e) && this.player.armor[1] != null) {
979 this.player.armor[1].drawDesc(g, e.x, e.y, this.guiFont12, this.m);
980 }
981 else if (this.equipBody.contains(e) && this.player.armor[2] != null) {
982 this.player.armor[2].drawDesc(g, e.x, e.y, this.guiFont12, this.m);
983 }
984 else if (this.equipFeet.contains(e) && this.player.armor[3] != null) {
985 this.player.armor[3].drawDesc(g, e.x, e.y, this.guiFont12, this.m);
986 }
987 }
988 if (this.showInventory) {
989 if (this.curItem == null) {
990 final int x = (e.x - 620) / 20;
991 final int y = (e.y - 295) / 20;
992 if (x >= 0 && x < this.player.invSpace[0].length && y >= 0 && y < this.player.invSpace.length && this.player.invSpace[y][x] != null) {
993 this.player.invSpace[y][x].drawDesc(g, e.x, e.y, this.guiFont12, this.m);
994 }
995 }
996 else {
997 final int x = e.x + this.offset.x;
998 final int y = e.y + this.offset.y;
999 if (610 <= x && x + 20 * this.curItem.imgWidth < 630 + 20 * this.player.invSpace[0].length && 285 <= y && y + 20 * this.curItem.imgHeight < 305 + 20 * this.player.invSpace.length) {
1000 if (this.player.itemFits(this.curItem, Math.round((x - 620) / 20.0f), Math.round((y - 295) / 20.0f))) {
1001 g.setColor(this.blueHaze);
1002 }
1003 else {
1004 g.setColor(this.redHaze);
1005 }
1006 g.fillRect(620 + Math.round((x - 620) / 20.0f) * 20, 295 + Math.round((y - 295) / 20.0f) * 20, 20 * this.curItem.imgWidth, 20 * this.curItem.imgHeight);
1007 }
1008 }
1009 }
1010 final Point mapPoint = new Point(this.playerLoc.x + e.x - 400, this.playerLoc.y + e.y - 300);
1011 final Iterator<Creature> iter = this.map.getCreaturesInVicinity(mapPoint, 2, 2).iterator();
1012 Creature bestTarget = null;
1013 while (iter.hasNext()) {
1014 final Creature cur = iter.next();
1015 if (cur == this.player) {
1016 continue;
1017 }
1018 if (!cur.getSelectionBound().contains(mapPoint, cur) || (bestTarget != null && cur.loc.y <= bestTarget.loc.y)) {
1019 continue;
1020 }
1021 bestTarget = cur;
1022 }
1023 if (bestTarget == null || bestTarget == this.player) {
1024 this.cursor = this.yellowCursor;
1025 break;
1026 }
1027 if (bestTarget.getClass() == Enemy.class) {
1028 this.cursor = this.redCursor;
1029 break;
1030 }
1031 if (bestTarget.getClass() == NPC.class) {
1032 this.cursor = this.greenCursor;
1033 break;
1034 }
1035 break;
1036 }
1037 }
1038 if (this.curItem != null) {
1039 this.curItem.getImg().draw(g, MouseInfo.getPointerInfo().getLocation().x + this.offset.x, MouseInfo.getPointerInfo().getLocation().y + this.offset.y);
1040 }
1041 }
1042
1043 private void drawDesc(final Graphics g, final WrappedString desc, final int x, int y, final int width) {
1044 y -= 3 + desc.getLineCount() * desc.getMetrics().getHeight();
1045 g.setColor(Color.black);
1046 g.fillRect(x, y, width, 3 + desc.getLineCount() * desc.getMetrics().getHeight());
1047 g.setColor(new Color(120, 240, 120));
1048 g.drawRect(x, y, width, 3 + desc.getLineCount() * desc.getMetrics().getHeight());
1049 for (int i = 0; i < desc.getLineCount(); ++i) {
1050 g.drawString(desc.getLine(i), x + 3, y - 3 + (i + 1) * desc.getMetrics().getHeight());
1051 }
1052 }
1053
1054 private void executeAI() {
1055 for (final Creature cr : this.map.creatureList) {
1056 cr.AI_move(this.player, this.map);
1057 }
1058 }
1059
1060 private void moveCreatures() {
1061 for (final Creature cr : this.map.creatureList) {
1062 final int xOld = cr.loc.x / 40;
1063 final int yOld = cr.loc.y / 40;
1064 this.map.getLoc(xOld, yOld).getCreatures().remove(cr);
1065 this.map.creatures.remove(cr);
1066 cr.move(this.map.getObjectsInVicinity(cr.loc, 2, 3), this.map);
1067 final int xNew = cr.loc.x / 40;
1068 final int yNew = cr.loc.y / 40;
1069 this.map.getLoc(xNew, yNew).getCreatures().add(cr);
1070 if (this.map.xLow <= xNew && xNew <= this.map.xHigh && this.map.yLow <= yNew && yNew <= this.map.yHigh) {
1071 this.map.creatures.add(cr);
1072 }
1073 }
1074 }
1075
1076 private synchronized void handleMouseInput(final MouseEvent e) {
1077 if (!this.started) {
1078 return;
1079 }
1080 this.selectText(null);
1081 switch (this.auxState) {
1082 case None: {
1083 switch (this.gameState) {
1084 case Main: {
1085 if (this.wndMain.getMember("new game").isClicked(e.getX(), e.getY())) {
1086 this.gameState = GameState.Game;
1087 break;
1088 }
1089 if (this.wndMain.getMember("load game").isClicked(e.getX(), e.getY()) || this.wndMain.getMember("game info").isClicked(e.getX(), e.getY())) {
1090 break;
1091 }
1092 if (this.wndMain.getMember("credits").isClicked(e.getX(), e.getY())) {
1093 this.gameState = GameState.Credits;
1094 break;
1095 }
1096 if (this.wndMain.getMember("quit").isClicked(e.getX(), e.getY())) {
1097 this.done = true;
1098 break;
1099 }
1100 break;
1101 }
1102 case Credits: {
1103 this.gameState = GameState.Main;
1104 break;
1105 }
1106 case Game: {
1107 Area curGui;
1108 if (this.minimizedGui) {
1109 curGui = this.miniBorder;
1110 this.miniBtn = this.miniBtn2;
1111 } else {
1112 curGui = this.fullBorder;
1113 this.miniBtn = this.miniBtn1;
1114 }
1115 if (e.getButton() == 1) {
1116 if (this.showCharacter) {
1117 if (this.player.statPoints > 0 && 178 <= e.getX() && e.getX() <= 188) {
1118 if (118 <= e.getY() && e.getY() <= 128) {
1119 final int[] stats = this.player.stats;
1120 final int ordinal = StatType.Strength.ordinal();
1121 ++stats[ordinal];
1122 final Player player = this.player;
1123 --player.statPoints;
1124 }
1125 else if (133 <= e.getY() && e.getY() <= 143) {
1126 final int[] stats2 = this.player.stats;
1127 final int ordinal2 = StatType.Dexterity.ordinal();
1128 ++stats2[ordinal2];
1129 final Player player2 = this.player;
1130 --player2.statPoints;
1131 }
1132 else if (148 <= e.getY() && e.getY() <= 158) {
1133 final int[] stats3 = this.player.stats;
1134 final int ordinal3 = StatType.Constitution.ordinal();
1135 ++stats3[ordinal3];
1136 final Player player3 = this.player;
1137 --player3.statPoints;
1138 }
1139 else if (163 <= e.getY() && e.getY() <= 173) {
1140 final int[] stats4 = this.player.stats;
1141 final int ordinal4 = StatType.Intelligence.ordinal();
1142 ++stats4[ordinal4];
1143 final Player player4 = this.player;
1144 --player4.statPoints;
1145 }
1146 this.player.propagateStatChanges();
1147 }
1148 if (this.equipWeapon.contains(e.getPoint())) {
1149 this.curItem = this.player.weapon;
1150 this.offset = new Point(40 - e.getX(), 285 - e.getY());
1151 this.equipNum = 4;
1152 }
1153 else if (this.equipHead.contains(e.getPoint())) {
1154 this.curItem = this.player.armor[0];
1155 this.offset = new Point(105 - e.getX(), 275 - e.getY());
1156 this.equipNum = 0;
1157 }
1158 else if (this.equipHands.contains(e.getPoint())) {
1159 this.curItem = this.player.armor[1];
1160 this.offset = new Point(40 - e.getX(), 360 - e.getY());
1161 this.equipNum = 1;
1162 }
1163 else if (this.equipBody.contains(e.getPoint())) {
1164 this.curItem = this.player.armor[2];
1165 this.offset = new Point(105 - e.getX(), 330 - e.getY());
1166 this.equipNum = 2;
1167 }
1168 else if (this.equipFeet.contains(e.getPoint())) {
1169 this.curItem = this.player.armor[3];
1170 this.offset = new Point(105 - e.getX(), 404 - e.getY());
1171 this.equipNum = 3;
1172 }
1173 this.equipped = true;
1174 }
1175 if (this.showInventory) {
1176 final int x = (e.getX() - 620) / 20;
1177 final int y = (e.getY() - 295) / 20;
1178 if (x >= 0 && x < this.player.invSpace[0].length && y >= 0 && y < this.player.invSpace.length && this.player.invSpace[y][x] != null) {
1179 this.curItem = this.player.invSpace[y][x];
1180 this.offset = new Point(620 + 20 * this.curItem.invX - e.getX(), 295 + 20 * this.curItem.invY - e.getY());
1181 this.equipped = false;
1182 }
1183 }
1184 if (!curGui.contains(e.getPoint())) {
1185 break;
1186 }
1187 if (this.miniBtn.contains(e.getPoint())) {
1188 this.minimizedGui = !this.minimizedGui;
1189 break;
1190 }
1191 if (this.iBtn.contains(e.getPoint())) {
1192 this.showInventory = !this.showInventory;
1193 break;
1194 }
1195 if (this.eBtn.contains(e.getPoint())) {
1196 this.showCharacter = !this.showCharacter;
1197 break;
1198 }
1199 if (this.qBtn.contains(e.getPoint())) {
1200 this.showQuests = !this.showQuests;
1201 break;
1202 }
1203 if (this.mainBtn.contains(e.getPoint())) {
1204 this.gameState = GameState.Main;
1205 break;
1206 }
1207 } else {
1208 if (e.getButton() != 3) {
1209 break;
1210 }
1211 if (curGui.contains(e.getPoint())) {
1212 return;
1213 }
1214 final Point target = new Point(this.playerLoc.x + e.getX() - 400, this.playerLoc.y + e.getY() - 300);
1215 final Iterator<Creature> iter = this.map.getCreaturesInVicinity(target, 2, 2).iterator();
1216 Creature bestTarget = null;
1217 final Creature oldTarget = this.player.enemyTarget;
1218 while (iter.hasNext()) {
1219 final Creature cur = iter.next();
1220 if (cur != this.player) {
1221 if (cur.dead) {
1222 continue;
1223 }
1224 if (!cur.getSelectionBound().contains(target, cur) || (bestTarget != null && cur.loc.y <= bestTarget.loc.y)) {
1225 continue;
1226 }
1227 bestTarget = cur;
1228 }
1229 }
1230 this.player.setEnemyTarget(bestTarget, this.map);
1231 if (bestTarget == null) {
1232 this.player.setTarget(target, this.map);
1233 }
1234 if (this.player.getModel().action == Action.Attacking && this.player.enemyTarget != oldTarget) {
1235 this.player.getModel().getCurrentAnimation().reset();
1236 this.player.getModel().action = Action.Walking;
1237 break;
1238 }
1239 }
1240 break;
1241 }
1242 case GameDialog: {
1243 final int selection = this.getDialogSelection(e);
1244 if (selection == -1) {
1245 break;
1246 }
1247 this.curDialog = this.player.getNPCTarget().processDialog(this.curDialog, selection, this.player);
1248 if (this.curDialog == null) {
1249 this.player.endDialog();
1250 this.gameState = GameState.Game;
1251 break;
1252 }
1253 break;
1254 }
1255 }
1256 break;
1257 }
1258 case MsgBox: {
1259 if (this.wndMessage.getMember("button").isClicked(e.getX(), e.getY())) {
1260 this.auxState = AuxState.None;
1261 break;
1262 }
1263 break;
1264 }
1265 }
1266 }
1267
1268 private synchronized void handleMouseRelease(final MouseEvent e) {
1269 if (this.curItem == null) {
1270 return;
1271 }
1272 final Rectangle item = new Rectangle(MouseInfo.getPointerInfo().getLocation().x + this.offset.x, MouseInfo.getPointerInfo().getLocation().y + this.offset.y, this.curItem.imgWidth * 20, this.curItem.imgHeight * 20);
1273 if (this.showCharacter && !this.equipped) {
1274 if (this.equipWeapon.intersects(item) && this.curItem.getClass() == Weapon.class) {
1275 this.player.drop(this.curItem);
1276 this.player.equipWeapon((Weapon)this.curItem);
1277 }
1278 else if (this.equipHead.intersects(item) && this.curItem.getClass() == Armor.class && ((Armor)this.curItem).getType() == Armor.ArmorType.Head) {
1279 this.player.drop(this.curItem);
1280 this.player.equipArmor(0, (Armor)this.curItem);
1281 }
1282 else if (this.equipHands.intersects(item) && this.curItem.getClass() == Armor.class && ((Armor)this.curItem).getType() == Armor.ArmorType.Hands) {
1283 this.player.drop(this.curItem);
1284 this.player.equipArmor(1, (Armor)this.curItem);
1285 }
1286 else if (this.equipBody.intersects(item) && this.curItem.getClass() == Armor.class && ((Armor)this.curItem).getType() == Armor.ArmorType.Body) {
1287 this.player.drop(this.curItem);
1288 this.player.equipArmor(2, (Armor)this.curItem);
1289 }
1290 else if (this.equipFeet.intersects(item) && this.curItem.getClass() == Armor.class && ((Armor)this.curItem).getType() == Armor.ArmorType.Feet) {
1291 this.player.drop(this.curItem);
1292 this.player.equipArmor(3, (Armor)this.curItem);
1293 }
1294 }
1295 if (this.showInventory) {
1296 final int x = e.getX() + this.offset.x;
1297 final int y = e.getY() + this.offset.y;
1298 if (610 <= x && x + 20 * this.curItem.imgWidth < 630 + 20 * this.player.invSpace[0].length && 285 <= y && y + 20 * this.curItem.imgHeight < 305 + 20 * this.player.invSpace.length) {
1299 final int xCoord = Math.round((x - 620) / 20.0f);
1300 final int yCoord = Math.round((y - 295) / 20.0f);
1301 if (this.equipped) {
1302 this.player.pickUp(this.curItem, xCoord, yCoord);
1303 if (this.equipNum == 4) {
1304 this.player.unequipWeapon((Weapon)this.curItem);
1305 }
1306 else {
1307 this.player.unequipArmor(this.equipNum, (Armor)this.curItem);
1308 }
1309 }
1310 else {
1311 this.player.moveItem(this.curItem, xCoord, yCoord);
1312 }
1313 }
1314 }
1315 boolean dropItem = true;
1316 if (this.showCharacter && this.areaCharacter.intersects(item)) {
1317 dropItem = false;
1318 }
1319 else if (this.showInventory && this.areaInventory.intersects(item)) {
1320 dropItem = false;
1321 }
1322 else if (this.showQuests && this.areaQuests.intersects(item)) {
1323 dropItem = false;
1324 }
1325 else if (this.minimizedGui) {
1326 if (this.miniBorder.intersects(item)) {
1327 dropItem = false;
1328 }
1329 }
1330 else if (this.fullBorder.intersects(item)) {
1331 dropItem = false;
1332 }
1333 if (dropItem) {
1334 if (this.equipped) {
1335 if (this.equipNum == 4) {
1336 this.player.unequipWeapon((Weapon)this.curItem);
1337 }
1338 else {
1339 this.player.unequipArmor(this.equipNum, (Armor)this.curItem);
1340 }
1341 }
1342 else {
1343 this.player.drop(this.curItem);
1344 }
1345 }
1346 this.curItem = null;
1347 }
1348
1349 private synchronized void handleKeyboardInput(final KeyEvent e) {
1350 if (this.selectedText != null) {
1351 this.selectedText.handleEvent(e);
1352 }
1353 else if (e.getKeyCode() == 27) {
1354 if (this.gameState == GameState.Game) {
1355 this.gameState = GameState.Main;
1356 }
1357 else {
1358 this.done = true;
1359 }
1360 }
1361 else if (e.getKeyCode() == 83) {
1362 this.showFps = !this.showFps;
1363 }
1364 else if (e.getKeyCode() == 90 && this.gameState == GameState.Game) {
1365 this.bounds = !this.bounds;
1366 }
1367 else if (e.getKeyCode() == 88 && this.gameState == GameState.Game) {
1368 this.passable = !this.passable;
1369 }
1370 }
1371
1372 @Override
1373 public void mousePressed(final MouseEvent e) {
1374 this.handleMouseInput(e);
1375 }
1376
1377 @Override
1378 public void mouseReleased(final MouseEvent e) {
1379 this.handleMouseRelease(e);
1380 }
1381
1382 @Override
1383 public void mouseEntered(final MouseEvent e) {
1384 }
1385
1386 @Override
1387 public void mouseExited(final MouseEvent e) {
1388 }
1389
1390 @Override
1391 public void mouseClicked(final MouseEvent e) {
1392 }
1393
1394 @Override
1395 public void keyTyped(final KeyEvent e) {
1396 }
1397
1398 @Override
1399 public synchronized void keyPressed(final KeyEvent e) {
1400 this.handleKeyboardInput(e);
1401 }
1402
1403 @Override
1404 public void keyReleased(final KeyEvent e) {
1405 }
1406
1407 private void selectText(final Textbox text) {
1408 if (this.selectedText != null) {
1409 this.selectedText.setSelected(false);
1410 }
1411 if ((this.selectedText = text) != null) {
1412 text.setSelected(true);
1413 }
1414 }
1415
1416 public static void main(final String[] args) {
1417 try {
1418 final PrintStream st = new PrintStream(new FileOutputStream("err.txt", true));
1419 System.setErr(st);
1420 System.setOut(st);
1421 System.out.println("-----[ Session started on " + Utils.dateString() + " ]-----");
1422 final GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
1423 final GraphicsDevice device = env.getDefaultScreenDevice();
1424 new LostHavenRPG(device);
1425 } catch (Exception e) {
1426 e.printStackTrace();
1427 }
1428 System.exit(0);
1429 }
1430
1431 public enum AuxState
1432 {
1433 None("None", 0),
1434 MsgBox("MsgBox", 1);
1435
1436 private AuxState(final String s, final int n) {
1437 }
1438 }
1439
1440 public enum GameState
1441 {
1442 Loading("Loading", 0),
1443 Main("Main", 1),
1444 CreateAccount("CreateAccount", 2),
1445 LoadGame("LoadGame", 3),
1446 Credits("Credits", 4),
1447 Game("Game", 5),
1448 GameDialog("GameDialog", 6);
1449
1450 private GameState(final String s, final int n) {
1451 }
1452 }
1453}
Note: See TracBrowser for help on using the repository browser.