package ru.dbotthepony.mc.otm.android.feature

import net.minecraft.world.entity.ai.attributes.AttributeModifier
import net.minecraft.world.entity.ai.attributes.Attributes
import ru.dbotthepony.mc.otm.android.AndroidFeature
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.registry.AndroidFeatures
import java.util.*

class LimbOverclockingFeature(android: MatteryPlayerCapability) : AndroidFeature(AndroidFeatures.LIMB_OVERCLOCKING, android) {
	override fun applyModifiers() {
		val speed = ply.getAttribute(Attributes.MOVEMENT_SPEED)

		if (speed != null) {
			speed.removePermanentModifier(MODIFIER_ID)
			speed.addPermanentModifier(AttributeModifier(MODIFIER_ID, type.displayName.toString(), (level + 1) * 0.08, AttributeModifier.Operation.MULTIPLY_TOTAL))
		}

		val attackSpeed = ply.getAttribute(Attributes.ATTACK_SPEED)

		if (attackSpeed != null) {
			attackSpeed.removePermanentModifier(MODIFIER_ID)
			attackSpeed.addPermanentModifier(AttributeModifier(MODIFIER_ID, type.displayName.toString(), (level + 1) * 0.06, AttributeModifier.Operation.MULTIPLY_TOTAL))
		}
	}

	override fun removeModifiers() {
		ply.getAttribute(Attributes.MOVEMENT_SPEED)?.removePermanentModifier(MODIFIER_ID)
		ply.getAttribute(Attributes.ATTACK_SPEED)?.removePermanentModifier(MODIFIER_ID)
	}

	companion object {
		private val MODIFIER_ID = UUID.fromString("4a3fae46-e57b-4e20-857d-f5c2b2c8f2f2")
	}
}
