/** * temp method for npc interactions * * @param command * @param index */ private static void interact(String[] command, int index) { Scene curScene = DungeonMaster.player.scene; int npcIndex = -1; String npcName = ""; boolean found = false; NPC testNpc = new NPC(null, npcName, null, curScene, null); if (command[index + 1].equals("to")) index++; if (command[index + 1].equals("with")) index++; for (int i = 1; i < command.length - index; i++) { npcName += command[index + i]; npcIndex = curScene.findActor(npcName); if (npcIndex != -1) { if (curScene.actors[npcIndex].getClass().equals(testNpc.getClass())) { NPC realNpc = (NPC) curScene.actors[npcIndex]; realNpc.talk.run(); } else { System.out.println("System: You can't talk to that"); if (DungeonMaster.help) System.out.println("Help: That actor isn't a NPC"); } break; } else { npcName += " "; } if ((i == 3 || i == command.length - index - 1) && npcIndex != -1) { System.out.println("System: NPC not found"); if (DungeonMaster.help) System.out.println("Help: Given NPC not found in current scene"); } } testNpc = null; }
private static void give(String[] command, int index) { Item item = null; Objects object = null; String name = ""; boolean done = false; for (int i = index; i < command.length - 1; i++) { name += command[i + 1]; if (item == null) { item = DungeonMaster.player.invenFind(name); if (item != null) { name = ""; if (command.length > i) if (command[i + 1].equals("in")) i++; } } if (object == null) { int objectIndex = DungeonMaster.player.scene.findObject(name); if (objectIndex != -1) { object = DungeonMaster.player.scene.objects[objectIndex]; name = ""; } } if (object != null && item != null) { done = true; break; } } if (done) { object.invenAdd(item); DungeonMaster.player.invenRemov(item); System.out.println( "System: " + item.niceName + " is now in " + object.niceName + "'s inventory."); NPC testNpc = new NPC(null, "", null, DungeonMaster.outside, null); if (object.getClass() == testNpc.getClass()) System.out.println(object.niceName + ": Thank you."); } else System.out.println("System: Actor or Item not found"); }