@Override public void execute(Mob mob, String input) { String bagString = getLastWord(input); Item bag = mob.getInventory().get(bagString); if (bag == null) { bag = mob.getRoom().getInventory().get(bagString); } if (bag == null) { mob.out("There is no bag to put stuff into"); return; } if (!bag.isContainer()) { mob.out("You can not put things into " + bag.getName()); return; } String target = getFirstWord(input); Item anItem = mob.getInventory().get(target); if (anItem == null) { mob.out("Can not put " + target + " it is not here!"); return; } if (anItem == bag) { mob.out("You can not put something into itself"); return; } Bag aBag = (Bag) bag; if (bag instanceof Chest) { if (((Chest) bag).getState() != DoorState.OPEN) { mob.out("That item is not open"); return; } } aBag.getInventory().add(anItem); mob.getInventory().remove(anItem); mob.out("You put an " + anItem.getName() + " into a " + bag.getName()); }
@Override public void execute(Mob mob, String input) { Player player = mob.getPlayer(); if (player == null) { LOGGER.warn("A none player called Who command"); return; } player.getData().setTitle(input); player.out("Setting your title to " + input); }
/** Move without alerting others to your presence as you enter in the same room as them */ @Override public void execute(Mob mob, String input) { Ability sneak = mob.getLearned().getAbility(SNEAK); if (sneak == null || sneak.isNull()) { mob.out("You have no knowledge of sneak"); return; } if (mob.isSneaking()) { mob.out("You are already sneaking around"); } if (sneak.isSuccessful(mob)) { mob.out(new Msg(mob, "<S-You/NAME> successfully start to sneak")); mob.getMobStatus().setSneaking(60); // 1 minute of sneaking around. } }
@Test public void testUnhide() { Mob player1Mob = TestHelper.makeDefaultPlayerMob("player1"); // Teach rescue to player Ability ability = new Ability("hide", 100); player1Mob.getLearned().add(ability); World.add(new BaseSkill("hide")); Race human = new Race(); World.getInstance().addToWorld(human); // have test resource file to load in a mob sheep and mob player // test files. Mob sheepMob = new Mob(); sheepMob.setNameAndId("sheep"); sheepMob.setAlias("sheep"); sheepMob.setHp("2d10+50"); Room whiteRoom = new Room(); whiteRoom.add(sheepMob); whiteRoom.add(player1Mob); Command hide = new Hide(); hide.execute(player1Mob, player1Mob.getAlias()); assertEquals("player should be hidden", true, player1Mob.isHidden()); Command unhide = new Unhide(); unhide.execute(player1Mob, player1Mob.getAlias()); assertEquals("player should be unhidden", false, player1Mob.isHidden()); Command kill = new Kill(); assertEquals("Check sheep name", "sheep", sheepMob.getName()); assertNotNull("Check sheep exists in the room", whiteRoom.getMob(sheepMob.getName())); assertEquals("Check sheep is in the room", sheepMob, whiteRoom.getMob(sheepMob.getName())); World.getInstance(); // Starts time. // kill.execute(player1Mob, sheepMob.getName()); kill.execute(sheepMob, player1Mob.getName()); // Check they are targeting each other. assertEquals("sheep should not target player1", player1Mob, sheepMob.getFight().getTarget()); }
@Test public void testStander() { Race human = new Race(); World.getInstance().addToWorld(human); // have test resource file to load in a mob sheep and mob player // test files. Mob sheepMob = new Mob(); sheepMob.setNameAndId("sheep"); sheepMob.setAlias("sheep"); sheepMob.setHp("500"); sheepMob.setMv("500"); sheepMob.setBehaviour("Stander"); BaseBehaviour baseBehaviour = BehaviourFactory.create("Stander"); baseBehaviour.setMob(sheepMob); baseBehaviour.setParameter(100); sheepMob.addTickable(baseBehaviour); WorldTime.addTickable(sheepMob); Room whiteRoom = new Room(); whiteRoom.add(sheepMob); sheepMob.setRoom(whiteRoom); Mob player1Mob = TestHelper.makeDefaultPlayerMob("player1"); whiteRoom.add(player1Mob); player1Mob.setRoom(whiteRoom); Tackle.setTackled(player1Mob, sheepMob); sheepMob.getMobStatus().clear(); baseBehaviour.tick(); baseBehaviour.tick(); baseBehaviour.tick(); assertEquals("sheep should be standing", MobState.STAND, sheepMob.getState()); assertEquals("sheep should be standing", false, sheepMob.getFight().isGroundFighting()); }
public static Mob makeDefaultPlayerMob(String name) { Mob mob = new Mob(); Player player = new Player(); player.setMob(mob); mob.setNameAndId(name); mob.setAlias(name); mob.setPlayer(player); int[] defaultAttributes = {10, 10, 10, 10, 10}; player.setAttributes(defaultAttributes); mob.setId(name); mob.setBrief(name); mob.setName(name); PlayerData data = player.getData(); data.setLearns(100); data.setPracs(100); mob.setPlayer(player); player.setMob(mob); player.getData().setAlignment(new Attribute("Alignment", 1000)); mob.setHeight(6); data.setTotalXp(0); data.setRemort(0); data.setPracs(0); mob.setLevel(1); data.setAge(16 + (int) (Math.random() * 5)); mob.setHp("100"); mob.setMv("100"); mob.setMana(new MobMana(true)); data.setThirst(500); data.setHunger(500); mob.setWimpy(10); return mob; }
public static void equipWand(Mob mob) { mob.getEquipment().add(makeWand()); }
public static void inveDagger(Mob player1Mob) { player1Mob.getInventory().add(makeDagger()); }
/** * id: dagger-001 alias: dagger short: dagger look: dagger skill: piercing type: weapon SHARP * damage: 3d2+1 wear: PRIMARY SECONDARY weight: 1 cost: 2 rent: 1 affects: * * @param player1Mob */ public static void equipDagger(Mob player1Mob) { player1Mob.getEquipment().add(makeDagger()); }