@Test public void testBagUnwear() { ScriptManager manager = ScriptManager.getInstance(); User user = UserManager.getInstance().createDefaultUser(); User expectUser = UserManager.getInstance().createDefaultUser(); WeaponPojo weapon = new WeaponPojo(); weapon.setAddAttack(10); weapon.setAddDefend(20); weapon.setAddAgility(30); weapon.setAddLuck(40); weapon.setAddBlood(50); weapon.setAddBloodPercent(60); weapon.setAddThew(70); weapon.setAddDamage(80); weapon.setAddSkin(90); user.getBag().removeOtherPropDatas(Bag.BAG_WEAR_COUNT); user.getBag().addOtherPropDatas(weapon.toPropData(30, WeaponColor.WHITE)); user.getBag().wearPropData(Bag.BAG_WEAR_COUNT, PropDataEquipIndex.WEAPON.index()); // default power = 2980 assertTrue(user.getPower() > 0); assertEquals(expectUser.getAttack() + weapon.getAddAttack(), user.getAttack()); assertEquals(expectUser.getDefend() + weapon.getAddDefend(), user.getDefend()); assertEquals(expectUser.getAgility() + weapon.getAddAgility(), user.getAgility()); assertEquals(expectUser.getLuck() + weapon.getAddLuck(), user.getLuck()); assertEquals( (int) ((expectUser.getBlood() + weapon.getAddBlood()) * (1.0 + weapon.getAddBloodPercent() / 100.0)), user.getBlood()); assertEquals(expectUser.getTkew() + weapon.getAddThew() + 6, user.getTkew()); assertEquals(expectUser.getDamage() + weapon.getAddDamage(), user.getDamage()); assertEquals(expectUser.getSkin() + weapon.getAddSkin(), user.getSkin()); user.getBag().wearPropData(PropDataEquipIndex.WEAPON.index(), Bag.BAG_WEAR_COUNT); assertEquals(expectUser.getAttack(), user.getAttack()); assertEquals(expectUser.getDefend(), user.getDefend()); assertEquals(expectUser.getAgility(), user.getAgility()); assertEquals(expectUser.getLuck(), user.getLuck()); assertEquals(expectUser.getTkew(), user.getTkew()); assertEquals(expectUser.getDamage(), user.getDamage()); assertEquals(expectUser.getSkin(), user.getSkin()); }
@Test public void testRoleAttackWithoutFeedback() throws Exception { UserManager manager = UserManager.getInstance(); manager.removeUser("test001"); manager.removeUser("test002"); User user1 = manager.createDefaultUser(); user1.set_id(new UserId("test001")); // user1.setSessionKey(SessionKey.createSessionKeyFromRandomString()); user1.setUsername("test001"); for (int i = 0; i < 1; i++) { user1.addTool(makeBuffTool(i)); } user1.setBag(makeBag(user1, 3)); User user2 = manager.createDefaultUser(); user2.set_id(new UserId("test002")); // user2.setSessionKey(SessionKey.createSessionKeyFromRandomString()); user2.setUsername("test002"); for (int i = 0; i < 1; i++) { user2.addTool(makeBuffTool(i)); } user2.setBag(makeBag(user2, 3)); manager.saveUser(user1, true); manager.saveUserBag(user1, true); manager.saveUser(user2, true); manager.saveUserBag(user2, true); SessionManager sessionManager = new SessionManager(); IoSession session1 = createNiceMock(IoSession.class); sessionManager.registerSession(session1, user1); IoSession session2 = createNiceMock(IoSession.class); sessionManager.registerSession(session2, user2); BattleManager battleManager = BattleManager.getInstance(); battleManager.clearAllBattles(); // Create two single room RoomManager roomManager = RoomManager.getInstance(); roomManager.assignRoom(user1, RoomType.SINGLE_ROOM); roomManager.assignRoom(user2, RoomType.SINGLE_ROOM); // User1 and User2 press "ready start" roomManager.readyStart(user1.getSessionKey(), true); roomManager.readyStart(user2.getSessionKey(), true); Collection<Battle> battles = battleManager.findAllBattles(); // Thread.sleep(Long.MAX_VALUE); assertEquals(1, battles.size()); Battle battle = battles.iterator().next(); // Change the battleMap ArrayList<BattleBitSetMap> battleMaps = BattleDataLoader4Bitmap.getBattleMapList(); BattleBitSetMap map03 = null; for (BattleBitSetMap bm : battleMaps) { if (bm.getMapId().equals("0")) { map03 = bm; break; } } assertNotNull(map03); TestUtil.setPrivateFieldValue("battleMap", battle, map03); HashMap<SessionKey, BattleUser> battleUserMap = battle.getBattleUserMap(); assertEquals(2, battleUserMap.size()); BattleUser bUser1 = battleUserMap.get(user1.getSessionKey()); BattleUser bUser2 = battleUserMap.get(user2.getSessionKey()); assertEquals(user1.getSessionKey(), bUser1.getUserSessionKey()); assertEquals(user1.getBlood(), bUser1.getBlood()); assertEquals(user1.getTkew(), bUser1.getThew()); Jedis jedis = JedisFactory.getJedis(); // User1 and User2 are stage ready. // Test roundStart final ArrayList<Message> msgList = new ArrayList<Message>(); MessageQueue queue = createMock(MessageQueue.class); queue.sessionWrite(anyObject(SessionKey.class), anyObject()); expectLastCall() .andAnswer( new IAnswer<Object>() { public Object answer() throws Throwable { Object msg = getCurrentArguments()[1]; msgList.add((Message) msg); return null; } }) .anyTimes(); TestUtil.setPrivateFieldValue("messageQueue", GameContext.getInstance(), queue); replay(queue); battleManager.stageReady(user1.getSessionKey()); battleManager.stageReady(user2.getSessionKey()); // System.out.println(msgList); // Check if roundStart is called assertEquals(2, msgList.size()); BseRoundStart roundStart = (BseRoundStart) msgList.get(0); assertNotNull(roundStart.getUserId(0)); assertNotNull(roundStart.getUserId(1)); // userPos: (990, 37), angle: 93, power: 83, dir: 1 // Role Attack msgList.clear(); BceRoleAttack.Builder bceRoleAttack = BceRoleAttack.newBuilder(); bceRoleAttack.setAngle(150000); bceRoleAttack.setAtkAngle(bceRoleAttack.getAngle()); bceRoleAttack.setDirection(RoleDirection.RIGHT.ordinal()); bceRoleAttack.setPower(30); int userx = 1380; int usery = 697; bceRoleAttack.setUserx(userx); bceRoleAttack.setUsery(usery); bUser1.setPosX(userx); bUser1.setPosY(usery); bUser2.setPosX(userx); bUser2.setPosY(usery); battleManager.roleAttack(bUser1.getUserSessionKey(), bceRoleAttack.build()); // System.out.println(msgList); // 2 roleAttack messages, 2 roundStart messages. long timeOut = System.currentTimeMillis() + 10000; Message xinqi = null; while (System.currentTimeMillis() < timeOut) { int size = msgList.size(); for (int i = 0; i < size; i++) { Object xm = msgList.get(i); if (xm instanceof BseAskRoundOver) { xinqi = (Message) xm; break; } } Thread.sleep(200); } assertTrue(xinqi != null); verify(queue); // Clean system. jedis.del(battle.getBattleSessionKey().toString()); jedis.del(user1.getSessionKey().toString()); jedis.del(user2.getSessionKey().toString()); }