diff --git a/lib/aethyr/core/actions/commands/look.rb b/lib/aethyr/core/actions/commands/look.rb index c3b17950349447d74c0db04daf88be814af4996e..d36700d57eac70d314b06fc285926dafe84fd8b9 100644 --- a/lib/aethyr/core/actions/commands/look.rb +++ b/lib/aethyr/core/actions/commands/look.rb @@ -1,4 +1,5 @@ require "aethyr/core/actions/command_action" +require 'aethyr/core/attributes/blind' module Aethyr module Core @@ -12,8 +13,19 @@ module Aethyr def action event = @data room = $manager.get_object(@player.container) - if @player.blind? - @player.output "You cannot see while you are blind." + + # TODO : remove this next line + Blind.new(@player) + + blind_data = { :can_look => true } + @player.broadcast_from(:pre_look, blind_data) + + if not blind_data[:can_look] + if blind_data[:reason].nil? + @player.output "You cannot see while you are blind." + else + @player.output blind_data[:reason] + end else if event[:at] object = room if event[:at] == "here" diff --git a/lib/aethyr/core/attributes/blind.rb b/lib/aethyr/core/attributes/blind.rb new file mode 100644 index 0000000000000000000000000000000000000000..466a485396dcce66613a71b4ca6e27668fff2184 --- /dev/null +++ b/lib/aethyr/core/attributes/blind.rb @@ -0,0 +1,19 @@ +require 'aethyr/core/objects/attributes/attribute' +require 'aethyr/core/objects/living' + +class Blind < Attribute + def initialize(attach_to) + if not attach_to.is_a? LivingObject + raise ArgumentError.new "Can only attach the Blind attribute to LivingObjects" + end + + super(attach_to) + + @attached_to.subscribe(self) + end + + def pre_look(data) + data[:can_look] = false + data[:reason] = "You cannot see while you are blind" + end +end diff --git a/lib/aethyr/core/objects/attributes/attribute.rb b/lib/aethyr/core/objects/attributes/attribute.rb new file mode 100644 index 0000000000000000000000000000000000000000..4ee1f6808548c49edd5f0e9282553d1164b4183d --- /dev/null +++ b/lib/aethyr/core/objects/attributes/attribute.rb @@ -0,0 +1,13 @@ +class Attribute + + attr_reader :attached_to + + def initialize(attach_to) + if not attach_to.is_a? GameObject + raise ArgumentError.new "Can only attach attributes to game objects" + end + + @attached_to = attach_to + @attached_to.attach_attribute(self) + end +end diff --git a/lib/aethyr/core/objects/attributes/blind.rb b/lib/aethyr/core/objects/attributes/blind.rb new file mode 100644 index 0000000000000000000000000000000000000000..e61002012531874b70525d66edfc0622623fe11b --- /dev/null +++ b/lib/aethyr/core/objects/attributes/blind.rb @@ -0,0 +1,18 @@ +require 'aethyr/core/attributes/attribute' +require 'aethyr/core/objects/living' + +class Blind < Attribute + def initialize(attach_to) + if not attach_to.is_a? LivingObject + raise ArgumentError.new "Can only attach the Blind attribute to LivingObjects" + end + + super(attach_to) + + @attached_to.subscribe(self) + end + + def pre_look(data) + data[:can_look] = false + end +end diff --git a/lib/aethyr/core/objects/game_object.rb b/lib/aethyr/core/objects/game_object.rb index b2fafb918e3fcdbe96ae331a6f3dfe2d6f363de8..f736542ee9ea1a34afe7504949aa5c3619ff978b 100644 --- a/lib/aethyr/core/objects/game_object.rb +++ b/lib/aethyr/core/objects/game_object.rb @@ -28,6 +28,7 @@ class GameObject < Publisher @name = name #Alternate names for the object @alt_names = alt_names + @attributes = Hash.new #The short description of the object @short_desc = short_desc #The long, detailed description of the object @@ -70,6 +71,29 @@ class GameObject < Publisher @admin = false end + def attributes + @attributes.clone + end + + def attach_attribute(attribute) + @attributes[attribute.class] = attribute + end + + def detach_attribute(attribute) + if attribute.is_a? Class + @attributes.delete(attribute) + else + attribute_to_detach = @attributes[attribute.class] + if attribute == attribute_to_detach + @attributes.delete(attribute.class) + end + end + end + + def broadcast_from(event, *args) + broadcast(event, *args) + end + def flags Hash.new @info.flags end diff --git a/lib/aethyr/core/objects/player.rb b/lib/aethyr/core/objects/player.rb index ec39655e49adb42535ece8fc0fc1c6b14cfb8ed9..ab2b0a3096bfeff73a3bbbd726ed5312d2d95ae6 100644 --- a/lib/aethyr/core/objects/player.rb +++ b/lib/aethyr/core/objects/player.rb @@ -56,7 +56,6 @@ class Player < LivingObject @word_wrap = 120 @page_height = nil @deaf = false - @blind = false @reply_to = nil @prompt_shown = false @layout = :basic @@ -124,10 +123,6 @@ class Player < LivingObject @deaf end - def blind? - @blind - end - #Sets balance def balance= val #was = @balance diff --git a/lib/aethyr/core/objects/traits/lexicon.rb b/lib/aethyr/core/objects/traits/lexicon.rb new file mode 100644 index 0000000000000000000000000000000000000000..aa572432b12bb36f7c64a79f3a2c7e60c34b1528 --- /dev/null +++ b/lib/aethyr/core/objects/traits/lexicon.rb @@ -0,0 +1,80 @@ +module Lexicon + Genders = Struct(:male, :female, :neuter, keyword_init: true) + Plurality = Struct(:singular, :plural, keyword_init: true) + Subjectivity = Struct(:subjective, :objective, :reflective, keyword_init: true) + Posessiveness = Struct(:posessive, :nonposessive) + Determiners = Struct(:articles, :demonstratives, :posessive, :quantifier, keyword_init: true) + Parts = Struct(:adjective, :pronoun, :noun, :verb, :adverb, :conjunction, :interjection, :preposition, keyword_init: true) + Directness = Struct(:direct, :indirect, keyword_init: true) + GramaticalPerson = Struct(:first_person, :second_person, :third_person, :fourth_person) + + GramaticalPerson.new( + first_person: Subjectivity.new( + subjective: Plurality.new( + singular: 'I', + plural: 'we' + ), + objective: Plurality.new( + singular: 'me', + plural: 'us' + ), + reflexive: Plurality.new( + singular: 'myself', + plural: 'ourselves' + ) + ) + ) + + module Gender + MASCULIN = :masculin + FEMANINE = :femanine + NEUTER = :neuter + end + + module Plurality + PLURAL = :plural + SINGULAR = :singular + NONE = :none + end + + module GramaticalPerson + FIRST_PERSON = :first_person + SECOND_PERSON = :second_person + THIRD_PERSON = :third_person + FOURTH_PERSON = :fourth_person + end + + module Subjectivity + OBJECTIVE = :objective + SUBJECTIVE = :subjective + end + + module Reference + REFLECTIVE = :reflective + POSSESSIVE = :possessive + INTERROGATIVE = :interrogative + INDEFINITE = :indefinite + end + + Vocab = Struct.new(:word, :gender, :plurality, :gramatical_person, :subjectivity, keyword_init: true) + + def construct_lexicon(vocabulary) + end + + construct_lexicon([Vocab.new(word: 'I', plurality: Plurality::SINGULAR, gramatical_person: GramaticalPerson::FIRST_PERSON, +end + +# interrogative pronounds:who, what, why, where, when, whatever +# indefinate pronounds: anything, anybody, anyone, something, somebody, someone, nothing, nobody, none, no one +# someone, something +# direct-reflexive-pronoun: himself +# indirect-reflective-pronoun: me + +# reflexive pronouns: myself, yourself, himself, herself, itself, ourselves, yourselves, themselves. +# possessive adjective/determiner: my, your, his, her, its, our, their +# possessive pronoun: mine, yours, his, hers, its, ours, theirs +# objective pronoun: me, us, you, him, her, it, them, and whom +# subjective pronoun: I, you, we, he, she, it, they, and who + +# Determiners: this, the, my +# Determiners: articles (definite: the, indefinite: a/an), demonstratives(this, that), possessive determines (my, their), quantifiers (many, all, no. every). diff --git a/lib/aethyr/core/registry.rb b/lib/aethyr/core/registry.rb index f1220254f1ad5c1bfc8509d84ad5eab1b3954278..f0969383af4e1243c6a9990764c88847acde210d 100644 --- a/lib/aethyr/core/registry.rb +++ b/lib/aethyr/core/registry.rb @@ -16,7 +16,7 @@ module Aethyr def self.handle(manager) @@handlers.each do |handler| - manager.subscribe(handler) + manager.subscribe(handler, on: :object_added) end nil end