~nromdotcom/gemif

775749454decc742ce61c063ad7001fe61b08a2f — Norm MacLennan 1 year, 2 days ago f0b44e2
Add not_condition to exits
M README.md => README.md +3 -3
@@ 143,9 143,9 @@ Each exit contains:
* `exit_description`: a description of the exit (the text of the exit link)
* `desination_id`: the id of the room this exit takes you to
* `exit_id`: a unique id for the exit, I recommend a GUID
* `set_condition`: conditional tag to attach to the game state if the user takes this exit
* `if_condition`: conditional tag the user must posses to use this exit

* `set_condition`: condition tag to attach to the game state if the user takes this exit
* `if_condition`: condition tag the user must posses to use this exit
* `not_condition`: conditoin tag to the user must NOT posses to use this exit
### Conditions

Conditions are simple tags attached to the user's state. Condition usage will

M pkg/gamemanager/gamemanager.go => pkg/gamemanager/gamemanager.go +11 -2
@@ 82,7 82,13 @@ func (gm *GameManager) UseExit(gameState GameState, exitID string) (GameState, e
	for _, e := range currentRoom.Exits {
		if e.ID == exitID {
			if e.IfCondition != "" && !gameState.ConditionMet(e.IfCondition) {
				fmt.Printf("Cant use exit! %s\n", e.ID)
				fmt.Printf("Cant use exit %s due to not meeting condition\n", e.ID)

				continue
			}

			if e.NotCondition != "" && gameState.ConditionMet(e.NotCondition) {
				fmt.Printf("Can't use exit %s due to meeting condition\n", e.ID)

				continue
			}


@@ 158,7 164,10 @@ func (gm *GameManager) ConstructSpeculativeStates(gameState GameState, currentRo
	speculativeStates := make([]SpeculativeState, len(currentRoom.Exits))

	for i, e := range currentRoom.Exits {
		if e.IfCondition != "" && !isInSlice(gameState.Conditions, e.IfCondition) {
		if e.IfCondition != "" && !gameState.ConditionMet(e.IfCondition) {
			continue
		}
		if e.NotCondition != "" && gameState.ConditionMet(e.NotCondition) {
			continue
		}


M pkg/gamemanager/room.go => pkg/gamemanager/room.go +1 -0
@@ 15,4 15,5 @@ type Exit struct {
	Destination  string `yaml:"destination_id" json:"destination_id" binding:"uuid"`
	SetCondition string `yaml:"set_condition,omitempty" json:"set_condition"`
	IfCondition  string `yaml:"if_condition,omitempty" json:"if_condition"`
	NotCondition string `yaml:"not_condition,omitempty" json:"not_condition"`
}

M stories/compiled/conditions.yml => stories/compiled/conditions.yml +1 -0
@@ 21,6 21,7 @@ rooms:
    exit_description: Oh, there's the key!
    destination_id: inside
    set_condition: has_key
    not_condition: has_key
  - exit_id: leave
    exit_description: Alright, let's get out of here.
    destination_id: outside

M stories/src/conditions/conditions.gemif => stories/src/conditions/conditions.gemif +1 -0
@@ 6,6 6,7 @@ exits:
  exit_description: Oh, there's the key!
  destination_id: inside
  set_condition: has_key
  not_condition: has_key
- exit_id: leave
  exit_description: Alright, let's get out of here.
  destination_id: outside