content: /**
   * This file is part of Aion-Lightning <aion-lightning.org>.
   *
   *  Aion-Lightning is free software: you can redistribute it and/or modify
   *  it under the terms of the GNU General Public License as published by
   *  the Free Software Foundation, either version 3 of the License, or
   *  (at your option) any later version.
   *
   *  Aion-Lightning is distributed in the hope that it will be useful,
   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *  GNU General Public License for more details. *
   *  You should have received a copy of the GNU General Public License
   *  along with Aion-Lightning.
   *  If not, see <http://www.gnu.org/licenses/>.
   */
  package instance.pvparenas;
  
  import com.aionemu.gameserver.instance.handlers.InstanceID;
  import com.aionemu.gameserver.model.gameobjects.player.Player;
  import com.aionemu.gameserver.model.instance.playerreward.InstancePlayerReward;
  import com.aionemu.gameserver.model.instance.playerreward.PvPArenaPlayerReward;
  import com.aionemu.gameserver.world.WorldMapInstance;
  
  /**
   * @author xTz
   */
  @InstanceID(300550000)
  public class ArenaOfGloryInstance extends PvPArenaInstance {
  
  	@Override
  	public void onInstanceCreate(WorldMapInstance instance) {
  		killBonus = 1000;
  		deathFine = -200;
  		super.onInstanceCreate(instance);
  	}
  
  	@Override
  	protected void reward() {
  		int totalPoints = instanceReward.getTotalPoints();
  		int size = instanceReward.getInstanceRewards().size();
  		// 100 * (rate * size) * (playerScore / playersScore)
  		float totalScoreAP = (59.952f * size) * 100;
  		float totalScoreGP = (1.0f * size) * 100;
  		// to do other formula
  		float rankingRate = 0;
  		if (size > 1) {
  			rankingRate = (0.077f * (4 - size));
  		}
  		float totalRankingAP = 30800 - 30800 * rankingRate;
  		float totalRankingGP = 800 - 800 * rankingRate;
  		for (InstancePlayerReward playerReward : instanceReward.getInstanceRewards()) {
  			PvPArenaPlayerReward reward = (PvPArenaPlayerReward) playerReward;
  			if (!reward.isRewarded()) {
  				float playerRate = 1;
  				Player player = instance.getPlayer(playerReward.getOwner());
  				if (player != null) {
  					playerRate = player.getRates().getGloryRewardRate();
  				}
  				int score = reward.getScorePoints();
  				float scoreRate = ((float) score / (float) totalPoints);
  				int rank = instanceReward.getRank(score);
  				float percent = reward.getParticipation();
  				float generalRate = 0.167f + rank * 0.227f;
  				int basicAP = 100;
  				int basicGP = 100;
  				float rankingAP = totalRankingAP;
  				float rankingGP = totalRankingGP;
  				if (rank > 0) {
  					rankingAP = rankingAP - rankingAP * generalRate;
  					rankingGP = rankingGP - rankingGP * generalRate;
  				}
  				int scoreAP = (int) (totalScoreAP * scoreRate);
  				int scoreGP = (int) (totalScoreGP * scoreRate);
  				basicAP *= percent;
  				rankingAP *= percent;
  				rankingAP *= playerRate;
  				reward.setBasicAP(basicAP);
  				reward.setRankingAP((int) rankingAP);
  				reward.setScoreAP(scoreAP);
  				basicGP *= percent;
  				rankingGP *= percent;
  				rankingGP *= playerRate;
  				reward.setBasicGP(basicGP);
  				reward.setRankingGP((int) rankingGP);
  				reward.setScoreGP(scoreGP);
  				switch (rank) {
  					case 0:
  						reward.setGloriousInsignia(1);
  						reward.setMithrilMedal(5);
  						break;
  					case 1:
  						reward.setGloriousInsignia(1);
  						reward.setplatinumMedal(3);
  						break;
  					case 2:
  						reward.setplatinumMedal(3);
  						break;
  					case 3:
  						reward.setLifeSerum(1);
  						break;
  				}
  			}
  		}
  		super.reward();
  	}
  }
  