All pastes #157591 Raw Edit

Something

public text v1 · immutable
·published 2006-09-01 17:28 UTC
rendered paste body
/** PVP PART */
    public void increasePvpKills()
    {
        // Add karma to attacker and increase its PK counter
        setPvpKills(getPvpKills() + 1);

        // Send a Server->Client UserInfo packet to attacker with its Karma and PK Counter
        sendPacket(new UserInfo(this));
        
        //Send a quick announce for PVP...
        String killer = getName();
        String target = getTarget();
        String text = "[PVP] "+killer+" killed "+target;
        Announcements.getInstance().announceToAll(text); 
    }
/** PK PART */
    public void increasePkKillsAndKarma(int targLVL)
    {
        int baseKarma = Config.KARMA_MIN_KARMA;
        int newKarma = baseKarma;
        int karmaLimit = Config.KARMA_MAX_KARMA;

        int pkLVL = getLevel();
        int pkPKCount = getPkKills();

        int lvlDiffMulti = 0;
        int pkCountMulti = 0;

        // Check if the attacker has a PK counter greater than 0
        if (pkPKCount > 0) pkCountMulti = pkPKCount / 2;
        else pkCountMulti = 1;
        if (pkCountMulti < 1) pkCountMulti = 1;

        // Calculate the level difference Multiplier between attacker and killed L2PcInstance
        if (pkLVL > targLVL) lvlDiffMulti = pkLVL / targLVL;
        else lvlDiffMulti = 1;
        if (lvlDiffMulti < 1) lvlDiffMulti = 1;

        // Calculate the new Karma of the attacker : newKarma = baseKarma*pkCountMulti*lvlDiffMulti
        newKarma *= pkCountMulti;
        newKarma *= lvlDiffMulti;

        // Make sure newKarma is less than karmaLimit and higher than baseKarma
        if (newKarma < baseKarma) newKarma = baseKarma;
        if (newKarma > karmaLimit) newKarma = karmaLimit;

        // Fix to prevent overflow (=> karma has a  max value of 2 147 483 647)
        if (getKarma() > (Integer.MAX_VALUE - newKarma)) newKarma = Integer.MAX_VALUE - getKarma();

        // Add karma to attacker and increase its PK counter
        setPkKills(getPkKills() + 1);
        setKarma(getKarma() + newKarma);

        // Send a Server->Client UserInfo packet to attacker with its Karma and PK Counter
        sendPacket(new UserInfo(this));

        //Send a quick announce for PK...
        String killer = getName();
        String target = getTarget();
        String text = "[PK] "+killer+" killed "+target;
        Announcements.getInstance().announceToAll(text); 
    }