-
Notifications
You must be signed in to change notification settings - Fork 0
/
InspectableLocationExt.scala
53 lines (44 loc) · 1.76 KB
/
InspectableLocationExt.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package io.github.scalaquest.core.model.behaviorBased.commons.groundBehaviors.impl
import io.github.scalaquest.core.model.behaviorBased.BehaviorBasedModel
import io.github.scalaquest.core.model.behaviorBased.commons.actioning.CommonActions.Inspect
import io.github.scalaquest.core.model.behaviorBased.commons.pushing.CommonMessagesExt
import io.github.scalaquest.core.model.behaviorBased.commons.reactions.CommonReactionsExt
import io.github.scalaquest.core.model.behaviorBased.simple.impl.StateUtilsExt
/**
* The trait makes possible to mix into a [[BehaviorBasedModel]] the InspectableLocation behavior
* for the Ground.
*/
trait InspectableLocationExt
extends BehaviorBasedModel
with StateUtilsExt
with CommonMessagesExt
with CommonReactionsExt {
/**
* A [[GroundBehavior]] that enables the possibility to know the items present into the current
* [[Room]].
*/
abstract class InspectableLocation extends GroundBehavior
/**
* A standard implementation for [[InspectableLocation]].
*
* @param onInspectExtra
* [[Reaction]] to be executed when the player successfully inspected the room. It can be
* omitted.
*/
case class SimpleInspectableLocation(onInspectExtra: Option[Reaction] = None)
extends InspectableLocation {
override def triggers: GroundTriggers = { case (Inspect, _) => inspectLocation }
private def inspectLocation: Reaction =
_.applyReactions(
Reactions.inspectLocation,
onInspectExtra.getOrElse(Reactions.empty)
)
}
/**
* Companion object for [[InspectableLocation]]. Shortcut for the standard implementation.
*/
object InspectableLocation {
def apply(onInspectExtra: Option[Reaction] = None): InspectableLocation =
SimpleInspectableLocation(onInspectExtra)
}
}