/*
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
 *
 * Copyright (c) 2015 - 2026 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.list.Tagged
import net.ccbluex.liquidbounce.features.module.ClientModule
import net.ccbluex.liquidbounce.features.module.ModuleCategories
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.protocol.game.ServerboundMovePlayerPacket

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

object ModuleDamage : ClientModule("Damage", ModuleCategories.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 tag: String, val run: () -> Unit) : Tagged {
        NCP(
            "NCP",
            {
                val (x, y, z) = player.position()

                repeat(65 * damage) {
                    network.send(
                        ServerboundMovePlayerPacket.Pos(
                        x,
                        y + 0.049,
                        z,
                        false,
                        player.horizontalCollision))
                    network.send(
                        ServerboundMovePlayerPacket.Pos(
                        x,
                        y,
                        z,
                        false,
                        player.horizontalCollision
                    ))
                }
                network.send(
                    ServerboundMovePlayerPacket.Pos(
                    x,
                    y,
                    z,
                    true,
                    player.horizontalCollision
                ))
            }
        ),
        AAC(
            "AAC",
            {
                player.deltaMovement.y = 5.0 * damage
            }
        ),

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

}
