/*
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
 *
 * Copyright (c) 2015 - 2025 CCBlueX
 *
 * LiquidBounce 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.
 *
 * LiquidBounce 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 LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
 */
package net.ccbluex.liquidbounce.features.module.modules.exploit

import net.ccbluex.liquidbounce.config.types.NamedChoice
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.ClientModule
import net.ccbluex.liquidbounce.utils.entity.exactPosition
import net.ccbluex.liquidbounce.utils.math.component1
import net.ccbluex.liquidbounce.utils.math.component2
import net.ccbluex.liquidbounce.utils.math.component3
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket

/**
 * Damage module
 *
 * Deals the specified amount of damage to yourself.
 */

object ModuleDamage : ClientModule("Damage", Category.EXPLOIT, disableActivation = true) {

    private val mode by enumChoice("Mode", DamageModeEnum.NCP)
    private val damage by int("Damage", 1, 0..20, "HP")

    override fun onEnabled() {
        damage(mode)
    }

    /**
     * Damage client player
     */
    fun damage(mode: DamageModeEnum) = mode.run()

    enum class DamageModeEnum(override val choiceName: String, val run: () -> Unit) : NamedChoice {
        NCP(
            "NCP",
            {
                val (x, y, z) = player.exactPosition

                repeat(65 * damage) {
                    network.sendPacket(PlayerMoveC2SPacket.PositionAndOnGround(
                        x,
                        y + 0.049,
                        z,
                        false,
                        player.horizontalCollision))
                    network.sendPacket(PlayerMoveC2SPacket.PositionAndOnGround(
                        x,
                        y,
                        z,
                        false,
                        player.horizontalCollision
                    ))
                }
                network.sendPacket(PlayerMoveC2SPacket.PositionAndOnGround(
                    x,
                    y,
                    z,
                    true,
                    player.horizontalCollision
                ))
            }
        ),
        AAC(
            "AAC",
            {
                player.velocity.y = 5.0 * damage
            }
        ),

        /**
         * @anticheat Verus
         * @anticheatVersion b3896
         * @testedOn eu.loyisa.cn
         * @note it gives you ~2 flags for damage
         */
        Verus(
            "Verus",
            {
                network.sendPacket(PlayerMoveC2SPacket.PositionAndOnGround(player.x, player.y, player.z, false,
                    player.horizontalCollision))
                network.sendPacket(PlayerMoveC2SPacket.PositionAndOnGround(player.x, player.y + 3.25, player.z, false,
                    player.horizontalCollision))
                network.sendPacket(PlayerMoveC2SPacket.PositionAndOnGround(player.x, player.y, player.z, false,
                    player.horizontalCollision))
                network.sendPacket(PlayerMoveC2SPacket.PositionAndOnGround(player.x, player.y, player.z, true,
                    player.horizontalCollision))
            }
        )
    }

}
