/** * Loot item from a dead body * * @param Targ Target Inventory * @param Index Item Index */ public void Take(ItemList Targ, int Index) { // Add item to character inventory // unequip item if (Targ.ITEM_NAME.elementAt(Index).indexOf("<Eq>") != -1) { Targ.ItemEffect(Index, this); } this.INVENTORY.addItem( Targ.ITEM_NAME.elementAt(Index), Targ.ITEM_PRICE.elementAt(Index), 1, Targ.ITEM_IMAGE.elementAt(Index), Targ.ITEM_TAG.elementAt(Index), Targ.STATS.elementAt(Index)); // Remove item from target inven Targ.removeItem(Index, 1); }
/** * do damage to character * * @param Dmg Amount of Damage */ public void Damage(int Dmg, int Type) { // If character is already dead then dont do damage if (ISDEAD) return; // Do damage if (Type == 1) { // DAMAGE FROM PHYSICAL ATTACK if (STATS.ARMOR > Dmg) return; HEALTH = HEALTH - Dmg + STATS.ARMOR; } else if (Type == 2) { // DAMAGE FROM MAGIC ATTACK if (STATS.MAGIC_RESIST > Dmg) return; HEALTH = HEALTH - Dmg + STATS.MAGIC_RESIST; } // If an Npc then run and hide if (NAI != null) { NAI.State = "alarmed"; } // Death condition if (HEALTH <= 0) { // If player is dead if (this.CLASS.equals("Player")) { HEALTH = 0; // Quit game JOptionPane.showMessageDialog(null, "You are dead"); X = 100; Y = 100; Opify(50); HEALTH = (int) MAX_HEALTH; } else { // If other character // set Death stats ISDEAD = true; HEALTH = 0; // display death CLASS = Cl + " (Dead)"; // Rot effect for (int i = 0; i < imgCHARAC.getWidth(); i++) { for (int j = 0; j < imgCHARAC.getHeight(); j++) { imgCHARAC.setRGB(i, j, imgCHARAC.getRGB(i, j) * (int) Math.pow(3, 3)); } } // Make inventory open to looting INVENTORY.OPEN_INVEN = true; } } }
/** * Sell an item to a shopkeeper * * @param Targ Target Inventory * @param Index Item Index */ public void Sell(ItemList Targ, int Index) { // Un-equip item if (INVENTORY.ITEM_NAME.elementAt(Index).indexOf("<Eq>") != -1) { INVENTORY.ItemEffect(Index, this); } // Give the target this item Targ.addItem( this.INVENTORY.ITEM_NAME.elementAt(Index), this.INVENTORY.ITEM_PRICE.elementAt(Index), 1, this.INVENTORY.ITEM_IMAGE.elementAt(Index), this.INVENTORY.ITEM_TAG.elementAt(Index), this.INVENTORY.STATS.elementAt(Index)); // Get payment from target this.GOLD += this.INVENTORY.ITEM_PRICE.elementAt(Index); // Remove item from the character inventory this.INVENTORY.removeItem(Index, 1); }
/** * Buy an item from a shopkeeper * * @param Targ Target Inventory * @param Index Item Index */ public void Buy(ItemList Targ, int Index) { // If item is too expensive if (Targ.ITEM_PRICE.elementAt(Index) > this.GOLD) { JOptionPane.showMessageDialog(null, "Too rich for your blood"); return; } // add Item to character inventory this.INVENTORY.addItem( Targ.ITEM_NAME.elementAt(Index), Targ.ITEM_PRICE.elementAt(Index), 1, Targ.ITEM_IMAGE.elementAt(Index), Targ.ITEM_TAG.elementAt(Index), Targ.STATS.elementAt(Index)); // remove Gold this.GOLD -= Targ.ITEM_PRICE.elementAt(Index); // remove item from target inventory Targ.removeItem(Index, 1); }
/** * Constructor to create a character * * @param x X Position * @param y Y Position * @param w Width of Image * @param h Height of Image * @param FileN Name of image file * @param S Max number of frames */ public GameCharacter( double x, double y, double w, double h, String FileN, int S, int Ty, String c) { // Set position and size X = x; Y = y; W = w; H = h; BASIC_PROCESS = new ProgressBar(new Font("Arial", 36, 36), this); BASIC_EFFECTS = new ProgressBar(new Font("Arial", 36, 36), this); // Add magic attacks // Fireball for (int i = 0; i < FIREBALL.length; i++) { FIREBALL[i] = new MagicAttack(-500, -500, 39, 41, "Fireball.png", 3, 1, 2, "Fireball"); FIREBALL[i].STATS.setStats(new String[] {"Damage=10", "Points=10"}); FIREBALL[i].CASTER = this; } // Shock for (int i = 0; i < SHOCK.length; i++) { SHOCK[i] = new MagicAttack(-500, -500, 39, 41, "Shock.png", 2, 1, 0, "Shock"); SHOCK[i].STATS.setStats(new String[] {"Damage=20", "Points=15"}); SHOCK[i].CASTER = this; } // Darkness for (int i = 0; i < DARKNESS.length; i++) { DARKNESS[i] = new MagicAttack(-500, -500, 165, 164, "Darkness.png", 3, 1, 2, "Darkness"); DARKNESS[i].STATS.setStats(new String[] {"Damage=100", "Points=50"}); DARKNESS[i].CASTER = this; } // Life Drain for (int i = 0; i < LIFE_DRAIN.length; i++) { LIFE_DRAIN[i] = new MagicAttack(-500, -500, 32, 32, "Life Drain.png", 7, 1, 0, "Life Drain"); LIFE_DRAIN[i].STATS.setStats(new String[] {"Damage=50", "Points=25"}); LIFE_DRAIN[i].CASTER = this; } // Get Image try { if (isJar()) { // Character imgCHARAC = getImage("/Graphics/Character/", FileN); // Blood int BloodType = (int) Math.round(Math.random() * 3) + 1; imgBLOOD = getImage("/Graphics/Effects/", "Dead" + BloodType + ".png"); // Quest imgQStart = getImage("/Graphics/Effects/", "Quest_Start.png"); imgQEnd = getImage("/Graphics/Effects/", "Quest_Complete.png"); } else { // Character imgCHARAC = ImageIO.read(Paths.get(DIRECT + FileN).toFile()); // Blood int BloodType = (int) Math.round(Math.random() * 3) + 1; imgBLOOD = ImageIO.read(Paths.get(DIRECT2 + "Dead" + BloodType + ".png").toFile()); // Quest imgQStart = ImageIO.read(Paths.get(DIRECT2 + "Quest_Start.png").toFile()); imgQEnd = ImageIO.read(Paths.get(DIRECT2 + "Quest_Complete.png").toFile()); } } catch (Exception e) { } // Max number of frames SIZE = S; // Sprite type TYPE = Ty; // Assign class CLASS = c; Cl = c; // Add items and attacks according to class if (CLASS.equals("Player")) { // Add items INVENTORY.addItem( "Health Potion", 25, 1, "Health Pot.png", "Potion", new String[] {"Points=50"}); INVENTORY.addItem( "Rusted Dagger", 20, 1, "Dagger_4.png", "Meele", new String[] {"Damage=10", "Attack Speed=1"}); INVENTORY.addItem( "Wooden Staff", 20, 1, "Staff_1.png", "Meele", new String[] {"Damage=5", "Attack Speed=1"}); // Equip items INVENTORY.ItemEffect(1, this); // MEELE_WEAPON=null; // Assign Magic SPELL_LIST.add(FIREBALL); // Inventory type INVENTORY.Type = "Player"; } else if (CLASS.equals("Citizen")) { // Add items INVENTORY.addItem( "Health Potion", 25, 1, "Health Pot.png", "Potion", new String[] {"Points=50"}); // Add Ai NAI = new NPCAI(this); // Add Gold this.GOLD = (int) Math.round(Math.random() * 15 + 5); INVENTORY.Type = "Friendly"; } else if (CLASS.equals("Blacksmith")) { // Add items INVENTORY.addItem( "Silver Dagger", 250, 1, "Dagger_3.png", "Meele", new String[] {"Damage=10", "Attack Speed=1"}); INVENTORY.addItem( "Steel Dagger", 450, 1, "Dagger_5.png", "Meele", new String[] {"Damage=35", "Attack Speed=1"}); // INVENTORY.addItem("Assassin blade", 750,1, "Dagger_6.png","Meele",new // String[]{"Damage=45","Attack Speed=1"}); // INVENTORY.addItem("Serpent Dagger", 5000,1, "Dagger_2.png","Meele",new // String[]{"Damage=50","Attack Speed=1"}); // INVENTORY.addItem("Dagger of Time", 5050,1, "Dagger_1.png","Meele",new // String[]{"Damage=75","Attack Speed=1"}); INVENTORY.addItem( "Steel Sword", 450, 1, "Sword_1.png", "Meele", new String[] {"Damage=30", "Attack Speed=0.65"}); INVENTORY.addItem( "Iron Sword", 50, 1, "Sword_2.png", "Meele", new String[] {"Damage=15", "Attack Speed=0.65"}); INVENTORY.addItem( "Silver Sword", 100, 1, "Sword_5.png", "Meele", new String[] {"Damage=20", "Attack Speed=0.5"}); // INVENTORY.addItem("Iron Scimitar", 150,1, "Sword_7.png","Meele",new // String[]{"Damage=15","Attack Speed=0.75"}); // INVENTORY.addItem("Steel Scimitar", 500,1, "Sword_4.png","Meele",new // String[]{"Damage=50","Attack Speed=0.75"}); // INVENTORY.addItem("Steel Katana", 450,1, "Sword_6.png","Meele",new // String[]{"Damage=40","Attack Speed=0.95"}); // INVENTORY.addItem("Butcher's Sword", 5000,1, "Sword_3.png","Meele",new // String[]{"Damage=100","Attack Speed=0.55"}); // INVENTORY.addItem("Blood Thirster", 6000,1, "Sword_8.png","Meele",new // String[]{"Damage=200","Attack Speed=0.75"}); INVENTORY.addItem( "Iron Hammer", 150, 1, "Hammer_1.png", "Meele", new String[] {"Damage=40", "Attack Speed=0.15"}); // INVENTORY.addItem("Steel Hammer", 450,1, "Hammer_0.png","Meele",new // String[]{"Damage=60","Attack Speed=0.15"}); // INVENTORY.addItem("Iron Mace", 50,1, "Mace_1.png","Meele",new String[]{"Damage=15","Attack // Speed=0.5"}); INVENTORY.addItem("Steel Helmet", 250, 1, "Head_1.png", "H_armor", new String[] {"Armor=20"}); INVENTORY.addItem("Iron Helmet", 150, 1, "Head_2.png", "H_armor", new String[] {"Armor=5"}); // INVENTORY.addItem("Iron Horn Helmet", 350,1, "Head_6.png","H_armor",new // String[]{"Armor=50","Magic Resist=0"}); // INVENTORY.addItem("Steel Horn Helmet", 500,1, "Head_7.png","H_armor",new // String[]{"Armor=80","Magic Resist=0"}); // INVENTORY.addItem("Skysteel Helmet", 4000,1, "Head_4.png","H_armor",new // String[]{"Armor=60","Magic Resist=25"}); INVENTORY.addItem( "Iron Cuirass", 250, 1, "Chest_4.png", "C_armor", new String[] {"Armor=20"}); INVENTORY.addItem( "Steel Cuirass", 350, 1, "Chest_1.png", "C_armor", new String[] {"Armor=30"}); // INVENTORY.addItem("Scale Cuirass", 550,1, "Chest_3.png","C_armor",new // String[]{"Armor=50"}); // INVENTORY.addItem("Dark metal Cuirass", 750,1, "Chest_6.png","C_armor",new // String[]{"Armor=70"}); // INVENTORY.addItem("Master Cuirass", 3050,1, "Chest_5.png","C_armor",new // String[]{"Armor=80","Magic Resist=25"}); // INVENTORY.addItem("Legendary Cuirass", 3050,1, "Chest_2.png","C_armor",new // String[]{"Armor=100","Magic Resist=100"}); INVENTORY.addItem( "Wooden Shield", 50, 1, "Shield_1.png", "Shield", new String[] {"Armor=5", "Magic Resist=0"}); // Add AI NAI = new NPCAI(this); // Identify as trader INVENTORY.Type = "Trader"; // Set Stats STATS.setStats(new String[] {"Level = 5 "}); MAX_HEALTH = 200; HEALTH = (int) MAX_HEALTH; } else if (CLASS.equals("Alchemist")) { // Add Items INVENTORY.addItem( "Health Potion", 25, 50, "Health Pot.png", "Potion", new String[] {"Points=50"}); INVENTORY.addItem( "Mana Potion", 20, 50, "Mana Pot.png", "Potion", new String[] {"Points=50"}); INVENTORY.addItem( "Speed Potion", 10, 50, "Speed Pot.png", "Potion", new String[] {"Points=5"}); // INVENTORY.addItem("Invisib Potion", 50, 10, "Invisibility Pot.png","Potion",new // String[]{"Points=5"}); // Add AI NAI = new NPCAI(this); // Identify as trader INVENTORY.Type = "Trader"; } else if (CLASS.equals("Inn Keeper")) { // Add Items INVENTORY.addItem("Roasted Fish", 15, 10, "Fish.png", "Food", new String[] {"Points=5"}); INVENTORY.addItem("Apple", 15, 10, "Apple.png", "Food", new String[] {"Points=2"}); // Add AI NAI = new NPCAI(this); // Identify as trader INVENTORY.Type = "Trader"; } else if (CLASS.equals("Mage")) { INVENTORY.addItem( "Leather Cap", 250, 1, "Head_8.png", "H_armor", new String[] {"Armor=5", "Magic Resist=25"}); INVENTORY.addItem( "Dark Leather Cap", 300, 1, "Head_9.png", "H_armor", new String[] {"Armor=5", "Magic Resist=50"}); // INVENTORY.addItem("Jesters Cap", 500,1, "Head_5.png","H_armor",new // String[]{"Armor=10","Magic Resist=90"}); // INVENTORY.addItem("Skull Helmet", 5000,1, "Head_3.png","H_armor",new // String[]{"Armor=100","Magic Resist=100"}); INVENTORY.addItem( "Shock Spell Stone", 250, 1, "Stone_1.png", "SpellStoner", new String[] {"Damage=" + SHOCK[0].STATS.DAMAGE}); // INVENTORY.addItem("Darkness Spell Stone", 500,1, "Stone_1.png","SpellStoner",new // String[]{"Damage="+DARKNESS[0].STATS.DAMAGE}); INVENTORY.addItem( "Life Drain Spell Stone", 300, 1, "Stone_1.png", "SpellStoner", new String[] {"Damage=" + LIFE_DRAIN[0].STATS.DAMAGE}); // Add AI NAI = new NPCAI(this); // Identify as trader INVENTORY.Type = "Trader"; } else if (CLASS.equals("Skeleton")) { // Add items INVENTORY.addItem( "Bone Club", 5, 1, "Mace_2.png", "Meele", new String[] {"Damage=5", "Attack Speed=1"}); // Add Gold this.GOLD = (int) Math.round(Math.random() * 10 + 2); // Use Item INVENTORY.ItemEffect(0, this); // Add AI EAI = new EnemyAI(this); } else if (CLASS.equals("Skeleton Chieftan")) { // Add Item INVENTORY.addItem( "Iron Sword", 50, 1, "Sword_2.png", "Meele", new String[] {"Damage=15", "Attack Speed=0.65"}); INVENTORY.addItem( "Health Potion", 25, 1, "Health Pot.png", "Potion", new String[] {"Points=50"}); // Add Gold this.GOLD = (int) Math.round(Math.random() * 50 + 25); // Use Item INVENTORY.ItemEffect(0, this); // Assign Stats STATS.LEVEL = 3; HEALTH = 250; MAX_HEALTH = 250; // Opify Opify(1 / 1.25); // Add AI EAI = new EnemyAI(this); } else if (CLASS.equals("Shaman")) { // Add items INVENTORY.addItem( "Health Potion", 25, 1, "Health Pot.png", "Potion", new String[] {"Points=50"}); // Add Ai NAI = new NPCAI(this); } else if (CLASS.equals("Dark Elf")) { // Add items INVENTORY.addItem( "Rusted Dagger", 20, 1, "Dagger_4.png", "Meele", new String[] {"Damage=10", "Attack Speed=1"}); INVENTORY.addItem("Iron Helmet", 150, 1, "Head_2.png", "H_armor", new String[] {"Armor=5"}); // Assign Stats STATS.LEVEL = 2; HEALTH = 150; MAX_HEALTH = 150; // Add Gold this.GOLD = (int) Math.round(Math.random() * 15 + 2); // Use Item INVENTORY.ItemEffect(0, this); INVENTORY.ItemEffect(1, this); // Add Ai EAI = new EnemyAI(this); } else if (CLASS.equals("Prisoner")) { INVENTORY.addItem("Key", 0, 1, "Key.png", "Key", new String[] {}); // NAI= new NPCAI(this); } }