package catchemrpg.drawers;
import _api.alienfactory.javamappy.Block;
import catchemrpg.base.*;
import catchemrpg.enums.Direction;
import catchemrpg.enums.WindowState;
import catchemrpg.functions.MouseInputMap;
import catchemrpg.gameobjects.Monster;
import catchemrpg.gameobjects.MonsterTypeMatchup;
import catchemrpg.gameobjects.NPCMonster;
import catchemrpg.gameobjects.MapMeta;
import catchemrpg.persistency.CharacterFileIO;
import catchemrpg.threads.MapThread;
import java.awt.Color;
import java.awt.Graphics2D;
/**
*
* @author Toby Pinder (Gigitrix)
*/
public class GameMap
{
static Block wallBlock = null;
static Block npcBlock = null;
static int pressedMonster = 0;
/**
* This method draws one frame of the map. Must be called in the fashion
* var=GameMap.draw(var) else it isn't saved.
* @param gfx the graphics object
* @return The graphics object
*/
public static Graphics2D draw(Graphics2D gfx)
{
// Pressed Monster: Which submenu is currently active.
//make the map
//Draw game layers using drawBackground, as we don't use any of the foreground slots.
try
{
MapThread.currentMapMain.draw(gfx, true, 0, 0, BaseVars.MAPWIDTH, BaseVars.MAPHEIGHT);
MapThread.currentMapMainNPCs.drawBackground(gfx, true, 0, 0, BaseVars.MAPWIDTH, BaseVars.MAPHEIGHT); //only one layer needed for chars
} catch (Exception ex)
{
ex.printStackTrace();
} finally
{
//make the char
gfx.drawImage(MapThread.charImg, BaseVars.MAPTILEOFFSETX * BaseVars.MAPTILEWIDTH, BaseVars.MAPTILEOFFSETY * BaseVars.MAPTILEHEIGHT, null);
}
//move the character
moveCharacter();
//detect if saving
if (BaseVars.keyboardInput.S)
{
CharacterFileIO cfio = new CharacterFileIO();
cfio.saveProperties();
}
//checkmouse inputs
getLastClick();
//draw chatwindow
gfx = EventLog.draw(gfx);
//now draw the stats panel.
gfx.setColor(Color.BLACK);
gfx.fillRect(500, 0, 300, 600);
int offset = 0; //a value for the y offset of the drawing.
gfx.setColor(Color.WHITE);
gfx.drawString(BaseVars.lang.ui$statistics, 625, 15);
for (Monster monster : CharacterData.monsterList)
{
//increase offset
offset = offset + 20;
//draw the background layer.
if (offset % 40 == 0)
{
gfx.setColor(BaseVars.GREY2);
}
else
{
gfx.setColor(BaseVars.GREY1);
}
gfx.fillRect(503, offset - 1, 250, 20);
//HP:
gfx.setColor(Color.WHITE);
gfx.drawString(monster.NAME + ":", 505, 15 + offset);
//Draw Health Bar
float percentBar = ((float) monster.HP / (float) monster.HPmax);
gfx.setColor(Color.RED);
gfx.fillRect(650, offset, 100, 18);
gfx.setColor(Color.GREEN);
gfx.fillRect(650, offset, (int) (percentBar * 100), 18);
//Draw Happiness Bar
gfx.setColor(Color.YELLOW);
gfx.fillRect(750, offset, 18, 18);
gfx.setColor(Color.MAGENTA);
percentBar = ((float) monster.happiness / (float) 1000);
gfx.fillRect(750, offset + 18 - (int) (percentBar * 18), 18, (int) (percentBar * 18));
//Draw Attachment Bar
gfx.setColor(Color.CYAN);
gfx.fillRect(768, offset, 18, 18);
gfx.setColor(Color.BLUE);
percentBar = ((float) monster.attachment / (float) 1000);
gfx.fillRect(768, offset + 18 - (int) (percentBar * 18), 18, (int) (percentBar * 18));
}
gfx = drawMonsterData(gfx);
return gfx;
}
/**
* Identify if the player needs to move, and move them in the direction specified
*/
private static void moveCharacter()
{
Direction moveDir = Direction.none;
//identified movement, now do it.
//try to detect movement from keyBoardInput
if (BaseVars.keyboardInput.DOWN)
{
moveDir = Direction.down;
}
else if (BaseVars.keyboardInput.LEFT)
{
moveDir = Direction.left;
}
else if (BaseVars.keyboardInput.UP)
{
moveDir = Direction.up;
}
else if (BaseVars.keyboardInput.RIGHT)
{
moveDir = Direction.right;
}
else
{
}
int wall = 0;
int npcs = 0;
if (MapThread.DelayAfterMove <= 0)
{
switch (moveDir)
{
case down:
//change char orientation
MapThread.charImg = MapThread.playerDownImage;
//get the block that an NPC or char could be on.
wallBlock = MapThread.currentMapMain.getLayer().getBlock(MapMeta.xPos, MapMeta.yPos + 1);
npcBlock = MapThread.currentMapMainNPCs.getLayer().getBlock(MapMeta.xPos, MapMeta.yPos + 1);
//difficult bit here gets the collision stuff from the map, and checks it to see if you are allowed.
wall = wallBlock.getUserData(1);
npcs = npcBlock.getUserData(1);
if (wall == 1 || npcs == 1)
{
moveDir = Direction.none;
}
else
{
//free to move
MapThread.DelayAfterMove = MapThread.DELAYAFTERMOVEMAX;
try
{
MapMeta.yPos++;
} catch (java.lang.IllegalArgumentException e)
{
System.err.println("User Too low. Map not configured correctly. ");
System.err.println("Map: " + MapMeta.filePath);
System.exit(-1);//quit w/o error code, but not normal (0)
}
}
break;
case left:
//change char orientation
MapThread.charImg = MapThread.playerLeftImage;
//get the block that an NPC or char could be on.
wallBlock = MapThread.currentMapMain.getLayer().getBlock(MapMeta.xPos - 1, MapMeta.yPos);
npcBlock = MapThread.currentMapMainNPCs.getLayer().getBlock(MapMeta.xPos - 1, MapMeta.yPos);
//difficult bit here gets the collision stuff from the map, and checks it to see if you are allowed.
wall = wallBlock.getUserData(1);
npcs = npcBlock.getUserData(1);
if (wall == 1 || npcs == 1)
{
moveDir = Direction.none;
}
else
{
//free to move
MapThread.DelayAfterMove = MapThread.DELAYAFTERMOVEMAX;
try
{
MapMeta.xPos--;
} catch (java.lang.IllegalArgumentException e)
{
System.err.println("User Too far left. Map not configured correctly. ");
System.err.println("Map: " + MapMeta.filePath);
System.exit(-1);//quit w/o error code, but not normal (0)
}
}
break;
case up:
//change char orientation
MapThread.charImg = MapThread.playerUpImage;
//get the block that an NPC or char could be on
wallBlock = MapThread.currentMapMain.getLayer().getBlock(MapMeta.xPos, MapMeta.yPos - 1);
npcBlock = MapThread.currentMapMainNPCs.getLayer().getBlock(MapMeta.xPos, MapMeta.yPos - 1);
//difficult bit here gets the collision stuff from the map, and checks it to see if you are allowed.
wall = wallBlock.getUserData(1);
npcs = npcBlock.getUserData(1);
if (wall == 1 || npcs == 1)
{
moveDir = Direction.none;
}
else
{
//free to move
MapThread.DelayAfterMove = MapThread.DELAYAFTERMOVEMAX;
try
{
MapMeta.yPos--;
} catch (java.lang.IllegalArgumentException e)
{
System.err.println("User Too high. Map not configured correctly. ");
System.err.println("Map: " + MapMeta.filePath);
System.exit(-1);//quit w/o error code, but not normal (0)
}
}
break;
case right:
//change char orientation
MapThread.charImg = MapThread.playerRightImage;
//get the block that an NPC or char could be on
wallBlock = MapThread.currentMapMain.getLayer().getBlock(MapMeta.xPos + 1, MapMeta.yPos);
npcBlock = MapThread.currentMapMainNPCs.getLayer().getBlock(MapMeta.xPos + 1, MapMeta.yPos);
//difficult bit here gets the collision stuff from the map, and checks it to see if you are allowed.
wall = wallBlock.getUserData(1);
npcs = npcBlock.getUserData(1);
if (wall == 1 || npcs == 1)
{
moveDir = Direction.none;
}
else
{
//free to move
MapThread.DelayAfterMove = MapThread.DELAYAFTERMOVEMAX;
try
{
MapMeta.xPos++;
} catch (java.lang.IllegalArgumentException e)
{
System.err.println("User Too far right. Map not configured correctly. ");
System.err.println("Map: " + MapMeta.filePath);
System.exit(-1);//quit w/o error code, but not normal (0)
}
}
break;
}
if (moveDir != Direction.none)
{
MapThread.currentMapMain.setBlockX(MapMeta.xPos-BaseVars.MAPTILEOFFSETX);
MapThread.currentMapMainNPCs.setBlockX(MapMeta.xPos-BaseVars.MAPTILEOFFSETX);
MapThread.currentMapMain.setBlockY(MapMeta.yPos-BaseVars.MAPTILEOFFSETY);
MapThread.currentMapMainNPCs.setBlockY(MapMeta.yPos-BaseVars.MAPTILEOFFSETY);
}
if (npcs == 1)
{
//check userdata 2 of the current tile.
int mode = npcBlock.getUserData(2);
switch (mode)
{
case 1:
//if this value is equal to 1, then the character wishes to talk.
int textID = npcBlock.getUserData(3);
EventLog.append(BaseVars.lang.mapSpeech.get(textID));
break;
case 2:
int battleID = npcBlock.getUserData(3);
battleAdd(battleID);
}
}
}
///moved. Add a delay factor so you don't move too fast.
if (MapThread.DelayAfterMove > 0)
{
MapThread.DelayAfterMove--;
}
}
/**
* Draws the stats for one creature, as selected by the mouse
* @param gfx The graphics context to draw on
* @return A drawn on graphics context.
*/
private static Graphics2D drawMonsterData(Graphics2D gfx)
{
//draw the stats for one creature, as selected by the mouse.
if (pressedMonster != 0)
{
//display stats. Don't forget language keys.
gfx.setColor(BaseVars.GREY2);
gfx.fillRect(530, 135, 240, 220);
gfx.setColor(Color.WHITE);
gfx.drawString(BaseVars.lang.ui$name + ": ", 535, 150);
gfx.drawString("" + CharacterData.monsterList[pressedMonster - 1].NAME, 615, 150);
gfx.drawString(BaseVars.lang.ui$category + ": ", 535, 165);
gfx.drawString("" + CharacterData.monsterList[pressedMonster - 1].CATEGORY1 + "/" + CharacterData.monsterList[pressedMonster - 1].CATEGORY2, 615, 165);
gfx.drawString(BaseVars.lang.ui$type + ": ", 535, 180);
gfx.drawString("" + MonsterTypeMatchup.typeToString(CharacterData.monsterList[pressedMonster - 1].TYPE), 615, 180);
gfx.drawString(BaseVars.lang.ui$HP + ": ", 535, 195);
gfx.drawString("" + CharacterData.monsterList[pressedMonster - 1].HP + "/" + CharacterData.monsterList[pressedMonster - 1].HPmax, 615, 195);
gfx.drawString(BaseVars.lang.ui$att + ": ", 535, 210);
gfx.drawString("" + CharacterData.monsterList[pressedMonster - 1].att, 615, 210);
gfx.drawString(BaseVars.lang.ui$def + ": ", 535, 225);
gfx.drawString("" + CharacterData.monsterList[pressedMonster - 1].def, 615, 225);
gfx.drawString(BaseVars.lang.ui$critical + " %: ", 535, 240);
gfx.drawString(CharacterData.monsterList[pressedMonster - 1].critPercent + "%", 615, 240);
gfx.drawString(BaseVars.lang.ui$evade + " %: ", 535, 255);
gfx.drawString(CharacterData.monsterList[pressedMonster - 1].evadePercent + "%", 615, 255);
gfx.drawString(BaseVars.lang.ui$block + " %: ", 535, 270);
gfx.drawString(CharacterData.monsterList[pressedMonster - 1].blockPercent + "%", 615, 270);
gfx.drawString(BaseVars.lang.ui$happiness + ": ", 535, 285);
gfx.drawString(CharacterData.monsterList[pressedMonster - 1].happiness + "/1000", 615, 285);
gfx.drawString(BaseVars.lang.ui$attachment + ": ", 535, 300);
gfx.drawString(CharacterData.monsterList[pressedMonster - 1].attachment + "/1000", 615, 300);
gfx.drawString(BaseVars.lang.ui$exp + ": ", 535, 315);
gfx.drawString(CharacterData.monsterList[pressedMonster - 1].exp + "", 615, 315);
gfx.drawString(BaseVars.lang.ui$kills + ": ", 535, 330);
gfx.drawString(CharacterData.monsterList[pressedMonster - 1].killCount + "", 615, 330);
gfx.drawString(BaseVars.lang.ui$deaths + ": ", 535, 345);
gfx.drawString(CharacterData.monsterList[pressedMonster - 1].deathCount + "", 615, 345);
}
return gfx;
}
/**
* Deal with clicks on the right pane.
*/
private static void getLastClick()
{
//if we have a new click....
if (MouseInputMap.dealtWith == false)
{
//we have a new click. Check regions for the
//user has clicked in the menu panel.
for (int i = 0; i < 5; i++)
{
if (MouseInputMap.clickX > 500 && MouseInputMap.clickY >= 15 + (20 * i) && MouseInputMap.clickY <= 35 + (20 * i))
{
pressedMonster = i + 1;
}
}
MouseInputMap.dealtWith = true;
}
}
/**
* Start the battle with index battleID. Note that battles are indexed based
* on filePath and battleID
* @param battleID the index of the battle to start.
*/
private static void battleAdd(int battleID)
{
BaseVars.aiTeam = NPCMonster.MonsterLookup(MapMeta.filePath, battleID);
BaseVars.state = WindowState.battle;
}
}