Group Defeat Loot (Yanfly YEP State Categories extension)

FBE Group Defeat Loot (YEP State Categories extension) v1.01
by FeatherBrain
​
Introduction
Extension for Yanfly's YEP State Categories plugin so enemies with the <Group Defeat> category leave loot at the end of battle.

Features
YEP State Categories contains a <Group Defeat> notetag. If all group members are afflicted by states that have this notetag, it is considered a lost battle.

However, by default, enemies that are in this "group defeat" category do not yield any loot (experience, gold, or items) when the battle ends.

This plugin extension modifies the Game_Troop functions related to experience, gold, and items so that enemies who are in a "Group Defeat" state at the end of battle DO yield experience, gold, and items, just as they would if they were in the regular "dead" state.

Plugin also supports Yanfly's Job Points plugin. Enemies in a "Group Defeat" state at the end of battle will reward Job Points appropriately.

Terms of Use
Free for any use. Credit "FeatherBrain Entertainment" if you want.

Compatibility
Requires YEP State Categories. Place this plugin beneath State Categories and Job Points (if using).
No known incompatibilities, please report any issues to this thread.

Update History
* v1.0 - initial release
* v1.01 - added support for Yanfly's Job Points plugin


JavaScript:
//=============================================================================
// FBE_GroupDefeatLoot.js
//=============================================================================
/*:
 * @plugindesc v1.01 Extension for Yanfly's YEP State Categories plugin so enemies with the <Group Defeat> category leave loot at the end of battle.
 *
 * @author FeatherBrain Entertainment
 *
 * @help
 *
 * Purpose/Use: 
 *
 * YEP State Categories contains a <Group Defeat> notetag. If all group members
 * are afflicted by states that have this notetag, it is considered a lost battle. 
 * However, by default, enemies that are in this "group defeat" category do not
 * yield any loot (experience, gold, or items) when the battle ends.
 *
 * This plugin extension modifies the Game_Troop functions related to experience,
 * gold, and items so that enemies who are in a "Group Defeat" state at the end 
 * of battle DO yield experience, gold, and items, just as they would if they 
 * were in the regular "dead" state.
 *
 * Plugin also supports Yanfly's Job Points plugin. Enemies in a "Group Defeat"
 * state at the end of battle will reward Job Points appropriately.
 *
 * TERMS OF USE
 * Free for any use. Credit FeatherBrain Entertainment if you want.
 *
 * COMPATIBILITY
 * Requires YEP State Categories. Place this plugin beneath State Categories 
 * and Job Points (if using).
 *
 * UPDATE HISTORY
 * v1.0 - initial release
 * v1.01 - added support for Yanfly's Job Points plugin
 * 
 */
//============================================================================
 

 (function() {


//-----------------------------------------------------------------------------
// Game_Unit
//
// The superclass of Game_Party and Game_Troop.

Game_Unit.prototype.groupDefeatMembers = function() {
    return this.members().filter(function(member) {
        return member.isGroupDefeatAffected();
    });
};


//-----------------------------------------------------------------------------
// Game_Troop
//
// The game object class for a troop and the battle-related data.


var FBE_Game_Troop_expTotal = Game_Troop.prototype.expTotal;
Game_Troop.prototype.expTotal = function() {
    var deadMemberExp = FBE_Game_Troop_expTotal.call(this);
    var groupDefeatExp = this.groupDefeatMembers().reduce(function(r, enemy) {
        return r + enemy.exp();
    }, 0);
    return deadMemberExp + groupDefeatExp;
};


var FBE_Game_Troop_goldTotal = Game_Troop.prototype.goldTotal;
Game_Troop.prototype.goldTotal = function() {
    var deadMemberGold = FBE_Game_Troop_goldTotal.call(this); 
    var groupDefeatGold = this.groupDefeatMembers().reduce(function(r, enemy) {
        return r + enemy.gold();
    }, 0) * this.goldRate();
    return deadMemberGold + groupDefeatGold;
};

var FBE_Game_Troop_makeDropItems = Game_Troop.prototype.makeDropItems;
Game_Troop.prototype.makeDropItems = function() {
    var deadMemberItems = FBE_Game_Troop_makeDropItems.call(this); 
    var groupDefeatItems = this.groupDefeatMembers().reduce(function(r, enemy) {
        return r.concat(enemy.makeDropItems());
    }, []);
    return groupDefeatItems.concat(deadMemberItems);
};

var FBE_Game_Troop_jpTotal = Game_Troop.prototype.jpTotal;
Game_Troop.prototype.jpTotal = function() {
    var deadMemberJP = FBE_Game_Troop_jpTotal.call(this);
    var groupDefeatJP = this.groupDefeatMembers().reduce(function(r, enemy) {
        return r + enemy.jp();
    }, 0);
    return deadMemberJP + groupDefeatJP;
};
    

 })();
This is a great addon, but I was wondering if you can make it work with YEP_JobPoints as well... It works great for everything else but that.
Thanks for letting me know. I haven't used that plugin, so I didn't notice. But I think I have it in my Yanfly collection, so I'll take a look later and see if I can figure out what's up. If Yanfly used a similar method for receiving job points as other loot it should be doable.


ETA: I tested this quickly with a new blank project, I think it's working with Job Points now, but please let me know if you have issues with it.

JavaScript:
//=============================================================================
// FBE_GroupDefeatLoot.js
//=============================================================================
/*:
 * @plugindesc v1.01 Extension for Yanfly's YEP State Categories plugin so enemies with the <Group Defeat> category leave loot at the end of battle.
 *
 * @author FeatherBrain Entertainment
 *
 * @help
 *
 * Purpose/Use:
 *
 * YEP State Categories contains a <Group Defeat> notetag. If all group members
 * are afflicted by states that have this notetag, it is considered a lost battle.
 * However, by default, enemies that are in this "group defeat" category do not
 * yield any loot (experience, gold, or items) when the battle ends.
 *
 * This plugin extension modifies the Game_Troop functions related to experience,
 * gold, and items so that enemies who are in a "Group Defeat" state at the end
 * of battle DO yield experience, gold, and items, just as they would if they
 * were in the regular "dead" state.
 *
 * Plugin also supports Yanfly's Job Points plugin. Enemies in a "Group Defeat"
 * state at the end of battle will reward Job Points appropriately.
 *
 * TERMS OF USE
 * Free for any use. Credit FeatherBrain Entertainment if you want.
 *
 * COMPATIBILITY
 * Requires YEP State Categories. Place this plugin beneath State Categories
 * and Job Points (if using).
 *
 * UPDATE HISTORY
 * v1.0 - initial release
 * v1.01 - added support for Yanfly's Job Points plugin
 *
 */
//============================================================================
 

 (function() {


//-----------------------------------------------------------------------------
// Game_Unit
//
// The superclass of Game_Party and Game_Troop.

Game_Unit.prototype.groupDefeatMembers = function() {
    return this.members().filter(function(member) {
        return member.isGroupDefeatAffected();
    });
};


//-----------------------------------------------------------------------------
// Game_Troop
//
// The game object class for a troop and the battle-related data.


var FBE_Game_Troop_expTotal = Game_Troop.prototype.expTotal;
Game_Troop.prototype.expTotal = function() {
    var deadMemberExp = FBE_Game_Troop_expTotal.call(this);
    var groupDefeatExp = this.groupDefeatMembers().reduce(function(r, enemy) {
        return r + enemy.exp();
    }, 0);
    return deadMemberExp + groupDefeatExp;
};


var FBE_Game_Troop_goldTotal = Game_Troop.prototype.goldTotal;
Game_Troop.prototype.goldTotal = function() {
    var deadMemberGold = FBE_Game_Troop_goldTotal.call(this);
    var groupDefeatGold = this.groupDefeatMembers().reduce(function(r, enemy) {
        return r + enemy.gold();
    }, 0) * this.goldRate();
    return deadMemberGold + groupDefeatGold;
};

var FBE_Game_Troop_makeDropItems = Game_Troop.prototype.makeDropItems;
Game_Troop.prototype.makeDropItems = function() {
    var deadMemberItems = FBE_Game_Troop_makeDropItems.call(this);
    var groupDefeatItems = this.groupDefeatMembers().reduce(function(r, enemy) {
        return r.concat(enemy.makeDropItems());
    }, []);
    return groupDefeatItems.concat(deadMemberItems);
};

var FBE_Game_Troop_jpTotal = Game_Troop.prototype.jpTotal;
Game_Troop.prototype.jpTotal = function() {
    var deadMemberJP = FBE_Game_Troop_jpTotal.call(this);
    var groupDefeatJP = this.groupDefeatMembers().reduce(function(r, enemy) {
        return r + enemy.jp();
    }, 0);
    return deadMemberJP + groupDefeatJP;
};
    

 })();
Works great! Thanks!

Original thread: https://forums.rpgmakerweb.com/threads/group-defeat-loot-yanfly-yep-state-categories-extension.127663/