Skip to content
Snippets Groups Projects
Commit ae1f5b77 authored by diegval's avatar diegval
Browse files

Feature: Hay distintas probabilidades para cada evento

parent 30e90f86
No related branches found
No related tags found
1 merge request!65Feature:
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetSelector">
<selectionStates>
<SelectionState runConfigName="MainActivity">
<option name="selectionMode" value="DROPDOWN" />
</SelectionState>
</selectionStates>
</component>
</project>
\ No newline at end of file
......@@ -15,8 +15,7 @@ object GeneradorDeEventos {
private var eventos = ArrayList<Evento>()
private fun crearEvento(): Evento {
val tipo = TipoEvento.entries.random()
val factory = EventoFactorySelector.obtenerFactory(tipo)
val factory = EventoFactorySelector.obtenerFactory()
return factory.generarEvento()
}
......
......@@ -11,5 +11,5 @@ class EventoCombate(
override var finalizado: Boolean,
var ataque: Int,
val imagenAtaque : Int,
val acciones: MutableList<Efecto>
val acciones: MutableList<Efecto>,
) : Evento(descripcion, dificultad, opciones, imagen, resistenciaMax, resistenciaMax, finalizado)
\ No newline at end of file
......@@ -4,7 +4,9 @@ import com.example.ellegadodepintia.exploradoresDePintia.model.TipoEvento
object EventoFactorySelector {
fun obtenerFactory(tipo: TipoEvento): EventoFactory {
fun obtenerFactory(): EventoFactory {
val tipo = seleccionarTipoEventoConProbabilidades()
return when (tipo) {
TipoEvento.Reliquia -> ReliquiaFactory()
TipoEvento.Combate -> CombateFactory()
......@@ -13,4 +15,23 @@ object EventoFactorySelector {
TipoEvento.Riesgo -> RiesgoFactory()
}
}
private fun seleccionarTipoEventoConProbabilidades(): TipoEvento {
val probabilidades = mapOf(
TipoEvento.Reliquia to 0.3,
TipoEvento.Tienda to 0.1,
TipoEvento.Riesgo to 0.3,
TipoEvento.Trampa to 0.1,
TipoEvento.Combate to 0.2
)
val acumulado = probabilidades.entries.fold(mutableListOf<Pair<Double, TipoEvento>>()) { acc, entry ->
val sumaAcumulada = acc.lastOrNull()?.first ?: 0.0
acc.add(Pair(sumaAcumulada + entry.value, entry.key))
acc
}
val random = Math.random()
return acumulado.first { random <= it.first }.second
}
}
......@@ -19,7 +19,7 @@ class RiesgoFactory : EventoFactory {
EfectoRiesgo(
ObjetoEquipable(
nombre = "Espada de Hierro",
descripcion = "Una espada de hierro sencilla y confiable perfecta para un aventurero novato.",
descripcion = "Una espada de hierro sencilla y confiable perfecta para un aventurero novato. Otorga 1 de daño extra",
efecto = EfectoEquipableAumento(1, Atributo.Ataque),
imagen = R.drawable.asi_objeto_espadadefault
),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment