1 /*
2  * Copyright (c) 2021 ScalaQuest Team.
3  *
4  * This file is part of ScalaQuest, and is distributed under the terms of the MIT License as
5  * described in the file LICENSE in the ScalaQuest distribution's top directory.
6  */
7 
8 package io.github.scalaquest.core.model.behaviorBased.commons.groundBehaviors.impl
9 
10 import io.github.scalaquest.core.model.behaviorBased.BehaviorBasedModel
11 import io.github.scalaquest.core.model.behaviorBased.commons.actioning.CActions.Inspect
12 import io.github.scalaquest.core.model.behaviorBased.commons.pushing.CMessagesExt
13 import io.github.scalaquest.core.model.behaviorBased.commons.reactions.CReactionsExt
14 import io.github.scalaquest.core.model.behaviorBased.simple.impl.StateUtilsExt
15 
16 /**
17  * The trait makes possible to mix into a [[BehaviorBasedModel]] the <b>InspectableLocation
18  * GroundBehavior</b>.
19  */
20 trait InspectableLocationExt
21   extends BehaviorBasedModel
22   with CMessagesExt
23   with CReactionsExt
24   with StateUtilsExt {
25 
26   /**
27    * A <b>GroundBehavior</b> that enables the possibility to describe the location.
28    */
29   abstract class InspectableLocation extends GroundBehavior {
30 
31     /**
32      * A <b>Reaction</b> that communicates to the user a description of the current location.
33      * @return
34      *   A <b>Reaction</b> that communicates to the user a description of the current location.
35      */
36     def inspectLocation: Reaction
37   }
38 
39   /**
40    * A standard implementation for <b>InspectableLocation</b>.
41    * @param onInspectExtra
42    *   <b>Reaction</b> to be executed when the player successfully inspect the location. It can be
43    *   omitted.
44    */
45   case class SimpleInspectableLocation(onInspectExtra: Reaction = Reaction.empty)
46     extends InspectableLocation {
47 
48     override def triggers: GroundTriggers = { case (Inspect, _) => inspectLocation }
49 
50     override def inspectLocation: Reaction =
51       for {
52         s1 <- Reaction.empty
53         _ <- CReactions.addMessage(
54           CMessages.Inspected(s1.location, s1.locationItems, s1.location.neighbors(s1))
55         )
56         s2 <- onInspectExtra
57       } yield s2
58   }
59 
60   /**
61    * Companion object for <b>InspectableLocation</b>.
62    */
63   object InspectableLocation {
64 
65     /**
66      * Shortcut for the standard implementation.
67      * @param onInspectExtra
68      *   <b>Reaction</b> to be executed when the player successfully inspect the location. It can be
69      *   omitted.
70      * @return
71      *   the instance of <b>InspectableLocation</b>.
72      */
73     def apply(onInspectExtra: Reaction = Reaction.empty): InspectableLocation =
74       SimpleInspectableLocation(onInspectExtra)
75   }
76 }
Line Stmt Id Pos Tree Symbol Tests Code
48 290 1781 - 1796 Select io.github.scalaquest.core.model.behaviorBased.commons.groundBehaviors.impl.InspectableLocationExt.SimpleInspectableLocation.inspectLocation SimpleInspectableLocation.this.inspectLocation
48 291 1758 - 1758 Apply io.github.scalaquest.core.model.behaviorBased.commons.groundBehaviors.impl.InspectableLocationExt.SimpleInspectableLocation.$anonfun.<init> new $anonfun()
52 292 1871 - 1885 Select io.github.scalaquest.core.model.behaviorBased.simple.impl.ReactionUtilsExt.Reaction.empty InspectableLocationExt.this.Reaction.empty
52 301 1851 - 2065 Apply io.github.scalaquest.core.model.behaviorBased.simple.impl.ReactionUtilsExt.EnhancedReaction.flatMap InspectableLocationExt.this.EnhancedReaction(InspectableLocationExt.this.Reaction.empty).flatMap(((s1: InspectableLocationExt.this.S) => InspectableLocationExt.this.EnhancedReaction(InspectableLocationExt.this.CReactions.addMessage(InspectableLocationExt.this.CMessages.Inspected.apply(s1.location, InspectableLocationExt.this.StateUtils(s1).locationItems, s1.location.neighbors(s1)))).flatMap(((x$1: InspectableLocationExt.this.S) => (x$1: InspectableLocationExt.this.S @unchecked) match { case _ => InspectableLocationExt.this.EnhancedReaction(SimpleInspectableLocation.this.onInspectExtra).map(((s2: InspectableLocationExt.this.S) => s2)) }))))
53 297 1899 - 2019 Apply io.github.scalaquest.core.model.behaviorBased.commons.reactions.CReactionsExt.CReactions.addMessage InspectableLocationExt.this.CReactions.addMessage(InspectableLocationExt.this.CMessages.Inspected.apply(s1.location, InspectableLocationExt.this.StateUtils(s1).locationItems, s1.location.neighbors(s1)))
53 300 1894 - 2065 Apply io.github.scalaquest.core.model.behaviorBased.simple.impl.ReactionUtilsExt.EnhancedReaction.flatMap InspectableLocationExt.this.EnhancedReaction(InspectableLocationExt.this.CReactions.addMessage(InspectableLocationExt.this.CMessages.Inspected.apply(s1.location, InspectableLocationExt.this.StateUtils(s1).locationItems, s1.location.neighbors(s1)))).flatMap(((x$1: InspectableLocationExt.this.S) => (x$1: InspectableLocationExt.this.S @unchecked) match { case _ => InspectableLocationExt.this.EnhancedReaction(SimpleInspectableLocation.this.onInspectExtra).map(((s2: InspectableLocationExt.this.S) => s2)) }))
54 293 1952 - 1963 Select io.github.scalaquest.core.model.Model.State.location s1.location
54 294 1965 - 1981 Select io.github.scalaquest.core.model.behaviorBased.simple.impl.StateUtilsExt.StateUtils.locationItems InspectableLocationExt.this.StateUtils(s1).locationItems
54 295 1983 - 2008 Apply io.github.scalaquest.core.model.Model.Room.neighbors s1.location.neighbors(s1)
54 296 1932 - 2009 Apply io.github.scalaquest.core.model.behaviorBased.commons.pushing.CMessagesExt.CMessages.Inspected.apply InspectableLocationExt.this.CMessages.Inspected.apply(s1.location, InspectableLocationExt.this.StateUtils(s1).locationItems, s1.location.neighbors(s1))
56 298 2034 - 2048 Select io.github.scalaquest.core.model.behaviorBased.commons.groundBehaviors.impl.InspectableLocationExt.SimpleInspectableLocation.onInspectExtra SimpleInspectableLocation.this.onInspectExtra
56 299 2028 - 2065 Apply io.github.scalaquest.core.model.behaviorBased.simple.impl.ReactionUtilsExt.EnhancedReaction.map InspectableLocationExt.this.EnhancedReaction(SimpleInspectableLocation.this.onInspectExtra).map(((s2: InspectableLocationExt.this.S) => s2))
74 302 2536 - 2577 Apply io.github.scalaquest.core.model.behaviorBased.commons.groundBehaviors.impl.InspectableLocationExt.SimpleInspectableLocation.apply InspectableLocationExt.this.SimpleInspectableLocation.apply(onInspectExtra)