do

local SeraphimBuffField = SWeapons.SeraphimBuffField

local CBFP_oldXSL0001 = XSL0001
XSL0001 = Class(CBFP_oldXSL0001) {

    BuffFields = {

        # this section is specific to the buff field functions in the CBFP.

        RegenField = Class(SeraphimBuffField) {

            OnCreate = function(self)
                # adding the buff we'll use in this buff field
                if not Buffs['SeraphimACURegenAura'] then
                    local Owner = self:GetOwner()
                    local bp = Owner:GetBlueprint().Enhancements['RegenAura']
                    BuffBlueprint {
                        Name = 'SeraphimACURegenAura',
                        DisplayName = 'SeraphimACURegenAura',
                        BuffType = 'COMMANDERAURA',
                        Stacks = 'REPLACE',
                        Duration = -1,
                        Affects = {
                            RegenPercent = {
                                Add = 0,
                                Mult = bp.RegenPerSecond or 0.1,
                                Ceil = bp.RegenCeiling,
                                Floor = bp.RegenFloor,
                            },
                        },
                    }
                end
                SeraphimBuffField.OnCreate(self)
            end,
        },

        AdvancedRegenField = Class(SeraphimBuffField) {

            OnCreate = function(self)
                # adding the buff we'll use in this buff field
                if not Buffs['SeraphimAdvancedACURegenAura'] then
                    local Owner = self:GetOwner()
                    local bp = Owner:GetBlueprint().Enhancements['AdvancedRegenAura']
                    BuffBlueprint {
                        Name = 'SeraphimAdvancedACURegenAura',
                        DisplayName = 'SeraphimAdvancedACURegenAura',
                        BuffType = 'COMMANDERAURA',
                        Stacks = 'REPLACE',
                        Duration = -1,
                        Affects = {
                            RegenPercent = {
                                Add = 0,
                                Mult = bp.RegenPerSecond or 0.1,
                                Ceil = bp.RegenCeiling,
                                Floor = bp.RegenFloor,
                            },
                            MaxHealth = {
                                Add = 0,
                                Mult = bp.MaxHealthFactor or 1.0,
                                DoNoFill = true,
                            },                        
                        },
                    }
                end
                SeraphimBuffField.OnCreate(self)
            end,

            OnPreUnitEntersField = function(self, unit)
                SeraphimBuffField.OnPreUnitEntersField(self, unit)
                return (unit:GetHealth() / unit:GetMaxHealth())
            end,

            OnUnitEntersField = function(self, unit, OnPreUnitEntersFieldData)
                SeraphimBuffField.OnUnitEntersField(self, unit, OnPreUnitEntersFieldData)
                unit:SetHealth(unit, (OnPreUnitEntersFieldData * unit:GetMaxHealth()))
            end,

            OnPreUnitLeavesField = function(self, unit, OnPreUnitEntersFieldData, OnUnitEntersFieldData)
                SeraphimBuffField.OnPreUnitLeavesField(self, unit, OnPreUnitEntersFieldData, OnUnitEntersFieldData)
                return (unit:GetHealth() / unit:GetMaxHealth())
            end,

            OnUnitLeavesField = function(self, unit, OnPreUnitEntersFieldData, OnUnitEntersFieldData, OnPreUnitLeavesField)
                SeraphimBuffField.OnUnitLeavesField(self, unit, OnPreUnitEntersFieldData, OnUnitEntersFieldData, OnPreUnitLeavesField)
                unit:SetHealth(unit, (OnPreUnitLeavesField * unit:GetMaxHealth()))
            end,
        },
    },

    CreateEnhancement = function(self, enh)
        local bp = self:GetBlueprint().Enhancements[enh]
        
        # Regenerative Aura
        # added by brute51 - enhanced this whole section
        if enh == 'RegenAura' then
            SWalkingLandUnit.CreateEnhancement(self, enh) # moved from top to here else this happens twice for some other enhancements
            self:GetBuffFieldByName('SeraphimACURegenBuffField'):Enable()
                        
        elseif enh == 'RegenAuraRemove' then
            SWalkingLandUnit.CreateEnhancement(self, enh) # moved from top to here else this happens twice for some other enhancements
            self:GetBuffFieldByName('SeraphimACURegenBuffField'):Disable()

        elseif enh == 'AdvancedRegenAura' then
            SWalkingLandUnit.CreateEnhancement(self, enh) # moved from top to here else this happens twice for some other enhancements
            self:GetBuffFieldByName('SeraphimACURegenBuffField'):Disable()
            self:GetBuffFieldByName('SeraphimAdvancedACURegenBuffField'):Enable()
            
        elseif enh == 'AdvancedRegenAuraRemove' then
            SWalkingLandUnit.CreateEnhancement(self, enh) # moved from top to here else this happens twice for some other enhancements
            self:GetBuffFieldByName('SeraphimAdvancedACURegenBuffField'):Disable()

        #Blast Attack
        elseif enh == 'BlastAttackRemove' then
            SWalkingLandUnit.CreateEnhancement(self, enh) # moved from top to here else this happens twice for some other enhancements
            local wep = self:GetWeaponByLabel('ChronotronCannon')
            wep:AddDamageRadiusMod(-self:GetBlueprint().Enhancements['BlastAttack'].NewDamageRadius) # unlimited AOE bug fix by brute51 [117]
            wep:AddDamageMod(-self:GetBlueprint().Enhancements['BlastAttack'].AdditionalDamage)

        else
            CBFP_oldXSL0001.CreateEnhancement(self, enh)
        end
    end,
}

TypeClass = XSL0001

end