Class: Lich::DragonRealms::CharacterValidator

Inherits:
Object
  • Object
show all
Defined in:
documented/dragonrealms/commons/common-validation.rb

Overview

Validates characters in the DragonRealms game. This class handles the validation of characters, sending messages, and managing their states.

Examples:

Creating a character validator

validator = Lich::DragonRealms::CharacterValidator.new(true, false, true, "Hero")

Instance Method Summary collapse

Constructor Details

#initialize(announce, sleep, greet, name) ⇒ CharacterValidator

Initializes a new CharacterValidator instance.

Examples:

validator = CharacterValidator.new(true, false, true, "Hero")

Parameters:

  • announce (Boolean)

    Whether to announce the character’s presence.

  • sleep (Boolean)

    Whether the character is sleeping.

  • greet (Boolean)

    Whether to greet the character.

  • name (String)

    The name of the character.



16
17
18
19
20
21
22
23
24
25
26
# File 'documented/dragonrealms/commons/common-validation.rb', line 16

def initialize(announce, sleep, greet, name)
  waitrt?
  fput('sleep') if sleep

  @lnet = (Script.running + Script.hidden).find { |val| val.name == 'lnet' }
  @validated_characters = []
  @greet = greet
  @name = name

  @lnet.unique_buffer.push("chat #{@name} is up and running in room #{Room.current.id}! Whisper me 'help' for more details.") if announce
end

Instance Method Details

#confirm(character) ⇒ void

This method returns an undefined value.

Confirms a character’s validation and optionally greets them.

Examples:

validator.confirm("Hero")

Parameters:

  • character (String)

    The name of the character to confirm.



56
57
58
59
60
61
62
63
64
65
# File 'documented/dragonrealms/commons/common-validation.rb', line 56

def confirm(character)
  return if valid?(character)

  echo "Successfully validated: #{character}"
  @validated_characters << character

  return unless @greet

  put "whisper #{character} Hi! I'm your friendly neighborhood #{@name}. Whisper me 'help' for more details. Don't worry, I've memorized your name so you won't see this message again."
end

#in_game?(character) ⇒ Boolean

Checks if a character is currently in the game.

Examples:

validator.in_game?("Hero")

Parameters:

  • character (String)

    The name of the character to check.

Returns:

  • (Boolean)

    Returns true if the character is in the game, false otherwise.



117
118
119
# File 'documented/dragonrealms/commons/common-validation.rb', line 117

def in_game?(character)
  DRC.bput("find #{character}", 'There are no adventurers in the realms that match the names specified', "^  #{character}.$") == "  #{character}."
end

#send_bankbot_balance(character, balance) ⇒ void

This method returns an undefined value.

Sends the current bank balance to a specified character.

Examples:

validator.send_bankbot_balance("Hero", 100)

Parameters:

  • character (String)

    The name of the character to send the balance to.

  • balance (Numeric)

    The current balance to send.



82
83
84
85
86
# File 'documented/dragonrealms/commons/common-validation.rb', line 82

def send_bankbot_balance(character, balance)
  message = "Current Balance: #{balance}"
  echo "Attempting to DM #{character} with message: #{message}"
  @lnet.unique_buffer.push("chat to #{character} #{message}")
end

#send_bankbot_help(character, messages) ⇒ void

This method returns an undefined value.

Sends help messages to a specified character.

Examples:

validator.send_bankbot_help("Hero", ["Help message 1", "Help message 2"])

Parameters:

  • character (String)

    The name of the character to send help messages to.

  • messages (Array<String>)

    An array of messages to send.



105
106
107
108
109
110
# File 'documented/dragonrealms/commons/common-validation.rb', line 105

def send_bankbot_help(character, messages)
  messages.each do |message|
    echo "Attempting to DM #{character} with message: #{message}"
    @lnet.unique_buffer.push("chat to #{character} #{message}")
  end
end

#send_bankbot_location(character) ⇒ void

This method returns an undefined value.

Sends the current location to a specified character.

Examples:

validator.send_bankbot_location("Hero")

Parameters:

  • character (String)

    The name of the character to send the location to.



93
94
95
96
97
# File 'documented/dragonrealms/commons/common-validation.rb', line 93

def send_bankbot_location(character)
  message = "Current Location: #{Room.current.id}"
  echo "Attempting to DM #{character} with message: #{message}"
  @lnet.unique_buffer.push("chat to #{character} #{message}")
end

#send_slack_token(character) ⇒ void

This method returns an undefined value.

Sends the Slack token to a specified character.

Examples:

validator.send_slack_token("Hero")

Parameters:

  • character (String)

    The name of the character to send the token to.



33
34
35
36
37
# File 'documented/dragonrealms/commons/common-validation.rb', line 33

def send_slack_token(character)
  message = "slack_token: #{UserVars.slack_token || 'Not Found'}"
  echo "Attempting to DM #{character} with message: #{message}"
  @lnet.unique_buffer.push("chat to #{character} #{message}")
end

#valid?(character) ⇒ Boolean

Checks if a character is validated.

Examples:

validator.valid?("Hero")

Parameters:

  • character (String)

    The name of the character to check.

Returns:

  • (Boolean)

    Returns true if the character is validated, false otherwise.



72
73
74
# File 'documented/dragonrealms/commons/common-validation.rb', line 72

def valid?(character)
  @validated_characters.include?(character)
end

#validate(character) ⇒ void

This method returns an undefined value.

Validates a character’s existence.

Examples:

validator.validate("Hero")

Parameters:

  • character (String)

    The name of the character to validate.



44
45
46
47
48
49
# File 'documented/dragonrealms/commons/common-validation.rb', line 44

def validate(character)
  return if valid?(character)

  echo "Attempting to validate: #{character}"
  @lnet.unique_buffer.push("who #{character}")
end