Package games.stendhal.server.entity.creature

Source Code of games.stendhal.server.entity.creature.DeathMatchCreature

/* $Id: DeathMatchCreature.java,v 1.29 2010/12/04 14:30:06 nhnb Exp $ */
/***************************************************************************
*                   (C) Copyright 2003-2010 - Stendhal                    *
***************************************************************************
***************************************************************************
*                                                                         *
*   This program 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 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
***************************************************************************/
package games.stendhal.server.entity.creature;

import games.stendhal.server.core.engine.SingletonRepository;
import games.stendhal.server.entity.player.Player;
import games.stendhal.server.maps.deathmatch.DeathmatchState;

/**
* <p>A creature that will give no XP to killers.
* <p>It calculates the DM score (points) due to the DM starter.
* <p>All players who did damage get the kill attributed.
*
* @author hendrik
*/
public class DeathMatchCreature extends Creature {

  private int points;
 
  // save only the name to enable GC of the player object
  private String playerName;

  /**
   * DeathCreature.
   *
   * @param copy
   *            creature to wrap
   */
  public DeathMatchCreature(final Creature copy) {
    super(copy);
  }

  /**
   * Only this player gets a points reward.
   *
   * @param player
   *            Player to reward
   */
  public void setPlayerToReward(final Player player) {
    this.playerName = player.getName();
  }
   
  @Override
  public Creature getNewInstance() {
    return new DeathMatchCreature(this);
  }

  @Override
  protected void rewardKillers(final int oldXP) {
   
    for (final String killerName : playersToReward) {
      final Player killer = SingletonRepository.getRuleProcessor().getPlayer(killerName);
      // check logout
      if (killer == null) {
        continue;
      }
     
      int damageDone = damageReceived.getCount(killer);
      if (damageDone == 0) {
        continue;
      }
      // set the DM points score only for the player who started the DM
      if (killerName.equals(playerName)) {
        points = (int) (killer.getLevel()
          * ((float) damageDone / (float) totalDamageReceived));
        final DeathmatchState deathmatchState = DeathmatchState.createFromQuestString(killer.getQuest("deathmatch"));
        deathmatchState.addPoints(points);
        killer.setQuest("deathmatch", deathmatchState.toQuestString());
      }
     
      // For some quests etc., it is required that the player kills a
      // certain creature without the help of others.
      // Find out if the player killed this RPEntity on his own, but
      // don't overwrite solo with shared.
      final String killedName = getName();
     
      if (killedName != null) {
        if (damageDone == totalDamageReceived) {
          killer.setSoloKill(killedName);
        } else {
          killer.setSharedKill(killedName);
        }
      }
     
      killer.notifyWorldAboutChanges();
     
    }
   
  }
 
  /**
   * Calculates the deathmatch points for this kill.
   *
   * @return number of points to reward
   */
  public int getDMPoints() {
    return points;
  }

}
TOP

Related Classes of games.stendhal.server.entity.creature.DeathMatchCreature

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.