All Downloads are FREE. Search and download functionalities are using the official Maven repository.

walkmc.behavior.BehaviorTalk.kt Maven / Gradle / Ivy

package walkmc.behavior

import net.minecraft.server.*
import walkmc.collections.*
import walkmc.extensions.*
import walkmc.interfaces.*

/**
 * An abstract implementation of [Behavior] that's have the responsability
 * to talks with near players.
 */
abstract class AbstractBehaviorTalk(
	owner: EntityInsentient,
	var radius: Double = 5.0,
	var delay: Int = 100,
	var options: IndexList = IndexList()
) : Behavior(owner) {
	
	abstract override fun updateTask()
	
	override fun shouldExecute() = options.isNotEmpty() && owner.findNearbyPlayer(radius) != null
	
	override fun canContinueExecuting() = owner.ticksLived % delay == 0
	
	fun talk(message: String) {
		for (player in owner.localization.getNearbyPlayers(radius, radius, radius)) {
			player.log(message)
		}
	}
	
	fun addOption(message: String) = options.add(message)
	
	fun removeOption(index: Int) = options.removeAt(index)
}

/**
 * An implementation of [AbstractBehaviorTalk] that's have the responsability
 * to talks with near players in a sequential order.
 */
open class BehaviorOrderedTalk(
	owner: EntityInsentient,
	radius: Double = 5.0,
	delay: Int = 100,
	options: IndexList = IndexList()
) : AbstractBehaviorTalk(owner, radius, delay, options) {
	
	override fun updateTask() = talk(options.toNextOrFirst())
	
}

/**
 * An implementation of [AbstractBehaviorTalk] that's have the responsability
 * to talks with near players in a sequential order.
 */
open class BehaviorRandomTalk(
	owner: EntityInsentient,
	radius: Double = 5.0,
	delay: Int = 100,
	options: IndexList = IndexList()
) : AbstractBehaviorTalk(owner, radius, delay, options) {
	
	override fun updateTask() = talk(options.random())
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy