@Test
 public void shouldOnUpdateFbSyncUpdateUpdateFbSyncForPlayer() {
   PlayerProfile userProfile = setUpPlayerProfile();
   boolean expectedFbSync = true;
   underTest.updateFbSync(request, response, false, expectedFbSync, modelMap);
   verify(playerProfileService, times(1)).updateSyncFor(userProfile.getPlayerId(), expectedFbSync);
 }
 private PlayerProfile setupUpdateDisplayName(String displayName) {
   PlayerProfile userProfile = getUserProfile();
   when(lobbySessionCache.getActiveSession(request)).thenReturn(getLobbySession(userProfile));
   PlayerProfile finalUserProfile = getUserProfileWithDisplayName(displayName);
   when(lobbySessionCache.getActiveSession(request)).thenReturn(getLobbySession(finalUserProfile));
   when(playerProfileService.findByPlayerId(userProfile.getPlayerId()))
       .thenReturn(finalUserProfile);
   return finalUserProfile;
 }
 private PlayerProfile setupUpdateEmailAddress(String emailAddress) {
   PlayerProfile userProfile = getUserProfile();
   when(lobbySessionCache.getActiveSession(request)).thenReturn(getLobbySession(userProfile));
   PlayerProfile finalUserProfile = getUserProfileWithEmailAddress(emailAddress);
   when(lobbySessionCache.getActiveSession(request)).thenReturn(getLobbySession(finalUserProfile));
   when(playerProfileService.findByPlayerId(userProfile.getPlayerId()))
       .thenReturn(finalUserProfile);
   return finalUserProfile;
 }
  @Test
  public void shouldClearPlayerProfileCacheOnUpdateOfDisplayNameForUser() {
    final DisplayName expectedDisplayName = new DisplayName("Super Cool New Name");
    final PlayerProfile userProfile = setupUpdateDisplayName(expectedDisplayName.getDisplayName());

    underTest.updateDisplayName(
        request, response, false, expectedDisplayName, bindingResult, modelMap);

    verify(playerProfileCacheRemovalListener).playerUpdated(userProfile.getPlayerId());
  }
  @Test
  public void shouldClearPlayerProfileCacheOnUpdateEmailAddressForUser() {
    String expectedEmailAddress = "*****@*****.**";

    PlayerProfile expectedUserProfile = setupUpdateEmailAddress(expectedEmailAddress);
    underTest.updateCommunicationEmailAddress(
        request, response, false, new EmailAddress(expectedUserProfile), bindingResult, modelMap);

    verify(playerProfileCacheRemovalListener).playerUpdated(expectedUserProfile.getPlayerId());
  }
  @Test
  public void shouldUpdateDisplayNameForUser() {
    DisplayName expectedDisplayName = new DisplayName("Super Cool New Name");
    PlayerProfile userProfile = setupUpdateDisplayName(expectedDisplayName.getDisplayName());

    underTest.updateDisplayName(
        request, response, false, expectedDisplayName, bindingResult, modelMap);

    verify(playerProfileService)
        .updateDisplayName(userProfile.getPlayerId(), expectedDisplayName.getDisplayName());
  }
 @Test
 public void shouldOnPasswordUpdateReplacePlayerId() {
   PlayerProfile userProfile = setUpPlayerProfile();
   PasswordChangeRequest passwordChangeForm = setUpPasswordUpdate();
   when(bindingResult.hasErrors()).thenReturn(false);
   underTest.updatedPassword(
       request, response, false, passwordChangeForm, bindingResult, modelMap);
   PasswordChangeRequest expectedPasswordChangeForm =
       new PasswordChangeFormTestBuilder(passwordChangeForm)
           .withPlayerId(userProfile.getPlayerId())
           .build();
   verify(playerProfileService)
       .updatePassword(userProfile.getPlayerId(), expectedPasswordChangeForm);
 }
 private LobbySession getLobbySession(PlayerProfile userProfile) {
   return new LobbySession(
       BigDecimal.valueOf(3141592),
       userProfile.getPlayerId(),
       userProfile.getDisplayName(),
       "session",
       Partner.YAZINO,
       "anAvatarUrl",
       userProfile.getEmailAddress(),
       null,
       false,
       WEB,
       AuthProvider.YAZINO);
 }
Beispiel #9
0
  public void saveBestScore(PlayerProfile playerProfile, LevelProfile level, Score score) {
    Score compareScore = getLevelBestScore(playerProfile, level);
    if (compareScore != null && compareScore.getTotalScore() > score.getTotalScore()) return;
    int levelgroupID = playerProfile.getCurrentLevelGroup().id;

    // String deleteDetail = "delete from score_detail where player_id=" +
    // playerProfile.getId() + " and level_id=" + level.id +
    // " and level_group_id=" + levelgroupID;

    String deleteScore =
        "delete from score where player_id="
            + playerProfile.getId()
            + " and level_id="
            + level.id
            + " and level_group_id="
            + levelgroupID;

    String insertScore =
        "insert into score(player_id, level_group_id, level_id, score, compare_score,is_uploaded,server_score_id) values ("
            // todo+ ", " + FlyDBManager.SCORE_COLUMN_REACHEDDATE
            + playerProfile.getId()
            + ", "
            + levelgroupID
            + ", "
            + level.id
            + ","
            + score.getTotalScore()
            + ", '"
            + score.getCompareScore()
            + "',"
            + (score.isUploaded() ? "1" : "0")
            + ","
            + score.getServerScoreId()
            + ") ";

    // FlyDBManager.getInstance().openDatabase();
    // FlyDBManager.getInstance().execSQL(deleteDetail);
    FlyDBManager.getInstance().execSQL(deleteScore);
    FlyDBManager.getInstance().execSQL(insertScore);
    // for (ScoreDetail detail : score.getScoreDetails()) {
    // String insertDetail =
    // "insert into score_detail(player_id,level_id,score_detail,_value,level_group_id) values ("
    // + playerProfile.getId() + ", "
    // + level.id + ", '" + detail.getDetailName() + "', '"
    // + detail.getValue() + "'," +levelgroupID + ")";
    // FlyDBManager.getInstance().execSQL(insertDetail);
    // }

  }
Beispiel #10
0
  /**
   * return the best scores of all levels in one level group.
   *
   * @param playerProfile
   * @return
   */
  public Map<Integer, Score> getPlayerBestScores(
      PlayerProfile playerProfile, LevelGroup levelGroup) {
    String selectScore =
        "select level_id, score, compare_score, reached_date,is_uploaded,server_score_id from score where player_id ="
            + playerProfile.getId()
            + " and level_group_id="
            + levelGroup.id;
    Map<Integer, Score> bestScores = new HashMap<Integer, Score>();

    DatabaseCursor cursor = FlyDBManager.getInstance().selectData(selectScore);
    if (cursor != null && cursor.getCount() > 0) {

      while (cursor.next()) {
        int levelId = cursor.getInt(0);
        Score score = new Score();
        score.setTotalScore(cursor.getInt(1));
        score.setCompareScore(cursor.getString(2));
        // todo score.setReachedDate(cursor.getString(3));
        score.setIsUploaded(cursor.getInt(4) > 0);
        score.setServerScoreId(cursor.getInt(5));

        Gdx.app.log("ScoreManager", "LevelId: " + levelId);
        bestScores.put(levelId, score);
      }
      cursor.close();
    }

    return bestScores;
  }
  @Test
  public void shouldClearPlayerProfileCacheOnUpdateUserProfileInfoForUser() {
    String expectedAvatarUrl = "http://lol/avatar";
    String expectedGender = "M";
    String expectedCountry = "Brerea";
    DateTime expectedDateOfBirth = new DateTime(System.currentTimeMillis());

    PlayerProfile expectedUserProfile =
        setUpUserProfileInfo(
            expectedAvatarUrl, expectedGender, expectedCountry, expectedDateOfBirth);
    PlayerProfileSummary expectedUserProfileInfo =
        new PlayerProfileSummaryBuilder(expectedUserProfile).build();
    underTest.updateUserProfileInfo(
        request, response, false, expectedUserProfileInfo, bindingResult, modelMap);

    verify(playerProfileCacheRemovalListener).playerUpdated(expectedUserProfile.getPlayerId());
  }
  @Test
  public void shouldClearPlayerProfileCacheOnAvatarUpdate() throws Exception {
    final PlayerProfile playerProfile = setUpPlayerProfile();

    final MultipartFile multipartFile = mock(MultipartFile.class);
    final String expectedOriginalFilename = "WORD";
    final byte[] expectedBytes = expectedOriginalFilename.getBytes();

    when(multipartFile.getBytes()).thenReturn(expectedBytes);
    when(multipartFile.getOriginalFilename()).thenReturn(expectedOriginalFilename);

    when(avatarRepository.storeAvatar(expectedOriginalFilename, expectedBytes))
        .thenReturn(new Avatar("one", "two"));

    underTest.updateUserAvatar(request, response, true, multipartFile, modelMap);

    verify(playerProfileCacheRemovalListener).playerUpdated(playerProfile.getPlayerId());
  }
Beispiel #13
0
 /**
  * Calculate the time remaining until the ability's cooldown expires.
  *
  * @param ability AbilityType whose cooldown to check
  * @return the number of seconds remaining before the cooldown expires
  */
 public int calculateTimeRemaining(AbilityType ability) {
   long deactivatedTimestamp = profile.getAbilityDATS(ability) * Misc.TIME_CONVERSION_FACTOR;
   return (int)
       (((deactivatedTimestamp
                   + (PerksUtils.handleCooldownPerks(player, ability.getCooldown())
                       * Misc.TIME_CONVERSION_FACTOR))
               - System.currentTimeMillis())
           / Misc.TIME_CONVERSION_FACTOR);
 }
  @Test
  public void shouldUpdateAvatarUrl() throws Exception {
    PlayerProfile userProfile = setUpPlayerProfile();

    MultipartFile multipartFile = mock(MultipartFile.class);
    String expectedOriginalFilename = "WORD";
    byte[] expectedBytes = expectedOriginalFilename.getBytes();

    when(multipartFile.getBytes()).thenReturn(expectedBytes);
    when(multipartFile.getOriginalFilename()).thenReturn(expectedOriginalFilename);

    Avatar expectedAvatar = new Avatar("one", "two");
    when(avatarRepository.storeAvatar(expectedOriginalFilename, expectedBytes))
        .thenReturn(expectedAvatar);

    underTest.updateUserAvatar(request, response, false, multipartFile, modelMap);

    verify(playerProfileService).updateAvatar(userProfile.getPlayerId(), expectedAvatar);
  }
Beispiel #15
0
  /**
   * Check to see if an ability can be activated.
   *
   * @param skill The skill the ability is based on
   */
  public void checkAbilityActivation(SkillType skill) {
    ToolType tool = skill.getTool();
    AbilityType ability = skill.getAbility();

    setToolPreparationMode(tool, false);

    if (getAbilityMode(ability)) {
      return;
    }

    int timeRemaining = calculateTimeRemaining(ability);

    if (timeRemaining > 0) {
      /*
       * Axes and Woodcutting are odd because they share the same tool.
       * We show them the too tired message when they take action.
       */
      if (skill == SkillType.WOODCUTTING || skill == SkillType.AXES) {
        player.sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining));
      }

      return;
    }

    if (EventUtils.callPlayerAbilityActivateEvent(player, skill).isCancelled()) {
      return;
    }

    int ticks =
        PerksUtils.handleActivationPerks(
            player,
            2 + (getSkillLevel(skill) / AdvancedConfig.getInstance().getAbilityLength()),
            ability.getMaxLength());

    // Notify people that ability has been activated
    ParticleEffectUtils.playAbilityEnabledEffect(player);

    if (useChatNotifications()) {
      player.sendMessage(ability.getAbilityOn());
    }

    SkillUtils.sendSkillMessage(player, ability.getAbilityPlayer(player));

    // Enable the ability
    profile.setAbilityDATS(
        ability, System.currentTimeMillis() + (ticks * Misc.TIME_CONVERSION_FACTOR));
    setAbilityMode(ability, true);

    if (ability == AbilityType.SUPER_BREAKER || ability == AbilityType.GIGA_DRILL_BREAKER) {
      SkillUtils.handleAbilitySpeedIncrease(player);
    }

    new AbilityDisableTask(this, ability)
        .runTaskLater(mcMMO.p, ticks * Misc.TICK_CONVERSION_FACTOR);
  }
  private PlayerProfile setUpUserProfileInfo(
      final String avatarUrl,
      final String gender,
      final String country,
      final DateTime dateOfBirth) {

    PlayerProfile userProfile = getUserProfile();
    when(lobbySessionCache.getActiveSession(request)).thenReturn(getLobbySession(userProfile));
    PlayerProfile finalUserProfile =
        PlayerProfile.copy(userProfile)
            .withGender(Gender.getById(gender))
            .withCountry(country)
            .withDateOfBirth(dateOfBirth)
            .asProfile();

    when(lobbySessionCache.getActiveSession(request)).thenReturn(getLobbySession(finalUserProfile));
    when(playerProfileService.findByPlayerId(userProfile.getPlayerId()))
        .thenReturn(finalUserProfile);
    return finalUserProfile;
  }
Beispiel #17
0
  public McMMOPlayer(Player player, PlayerProfile profile) {
    String playerName = player.getName();
    UUID uuid = player.getUniqueId();

    this.player = player;
    playerMetadata = new FixedMetadataValue(mcMMO.p, playerName);
    this.profile = profile;

    if (profile.getUniqueId() == null) {
      profile.setUniqueId(uuid);
    }

    /*
     * I'm using this method because it makes code shorter and safer (we don't have to add all SkillTypes manually),
     * but I actually have no idea about the performance impact, if there is any.
     * If in the future someone wants to remove this, don't forget to also remove what is in the SkillType enum. - bm01
     */
    try {
      for (SkillType skillType : SkillType.values()) {
        skillManagers.put(
            skillType,
            skillType.getManagerClass().getConstructor(McMMOPlayer.class).newInstance(this));
      }
    } catch (Exception e) {
      e.printStackTrace();
      mcMMO.p.getPluginLoader().disablePlugin(mcMMO.p);
    }

    for (AbilityType abilityType : AbilityType.values()) {
      abilityMode.put(abilityType, false);
      abilityInformed.put(abilityType, true); // This is intended
    }

    for (ToolType toolType : ToolType.values()) {
      toolMode.put(toolType, false);
    }
  }
Beispiel #18
0
  public Score getLevelBestScore(PlayerProfile playerProfile, LevelProfile level) {
    int levelgroupID = playerProfile.getCurrentLevelGroup().id;
    String selectScore =
        "select score, compare_score, reached_date, is_uploaded, server_score_id from score where player_id ="
            + playerProfile.getId()
            + " and level_id="
            + level.id
            + " and level_group_id="
            + levelgroupID;
    Score score = null;

    DatabaseCursor cursor = FlyDBManager.getInstance().selectData(selectScore);
    if (cursor != null && cursor.getCount() > 0) {
      cursor.next();
      score = new Score();
      score.setTotalScore(cursor.getInt(0));
      score.setCompareScore(cursor.getString(1));
      // todo score.setReachedDate(cursor.getString(2));
      score.setIsUploaded(cursor.getInt(3) > 0);
      score.setServerScoreId(cursor.getInt(4));
      cursor.close();
    }
    return score;
  }
Beispiel #19
0
  /**
   * Check the XP of a skill.
   *
   * @param skillType The skill to check
   */
  private void checkXp(SkillType skillType, XPGainReason xpGainReason) {
    if (getSkillXpLevelRaw(skillType) < getXpToLevel(skillType)) {
      return;
    }

    int levelsGained = 0;
    float xpRemoved = 0;

    while (getSkillXpLevelRaw(skillType) >= getXpToLevel(skillType)) {
      if (hasReachedLevelCap(skillType)) {
        setSkillXpLevel(skillType, 0);
        break;
      }

      xpRemoved += profile.levelUp(skillType);
      levelsGained++;
    }

    if (!EventUtils.handleLevelChangeEvent(
        player, skillType, levelsGained, xpRemoved, true, xpGainReason)) {
      return;
    }

    if (Config.getInstance().getLevelUpSoundsEnabled()) {
      player.playSound(
          player.getLocation(),
          Sound.ENTITY_EXPERIENCE_ORB_PICKUP,
          Misc.LEVELUP_VOLUME,
          Misc.LEVELUP_PITCH);
    }

    player.sendMessage(
        LocaleLoader.getString(
            StringUtils.getCapitalized(skillType.toString()) + ".Skillup",
            levelsGained,
            getSkillLevel(skillType)));
  }
Beispiel #20
0
 public void setSkillXpLevel(SkillType skill, float xpLevel) {
   profile.setSkillXpLevel(skill, xpLevel);
 }
Beispiel #21
0
 public void saveBestScore(PlayerProfile playerProfile, Score score) {
   saveBestScore(playerProfile, playerProfile.getCurrentLevelProfile(), score);
 }
Beispiel #22
0
 public void removeXp(SkillType skill, int xp) {
   profile.removeXp(skill, xp);
 }
Beispiel #23
0
 public int getXpToLevel(SkillType skill) {
   return profile.getXpToLevel(skill);
 }
Beispiel #24
0
 public void modifySkill(SkillType skill, int level) {
   profile.modifySkill(skill, level);
 }
 private PlayerProfile setUpPlayerProfile() {
   PlayerProfile userProfile = getUserProfile();
   when(lobbySessionCache.getActiveSession(request)).thenReturn(getLobbySession(userProfile));
   when(playerProfileService.findByPlayerId(userProfile.getPlayerId())).thenReturn(userProfile);
   return userProfile;
 }
Beispiel #26
0
 public void addLevels(SkillType skill, int levels) {
   profile.addLevels(skill, levels);
 }
Beispiel #27
0
 public void addXp(SkillType skill, float xp) {
   profile.addXp(skill, xp);
 }
Beispiel #28
0
 public void setAbilityDATS(AbilityType ability, long DATS) {
   profile.setAbilityDATS(ability, DATS);
 }
Beispiel #29
0
 public void resetCooldowns() {
   profile.resetCooldowns();
 }
Beispiel #30
0
 public Score getLevelBestScore(PlayerProfile playerProfile) {
   return getLevelBestScore(playerProfile, playerProfile.getCurrentLevelProfile());
 }