<commit_before>module Intent
	# Learn a new Skill or Class
	class Learn < Action

		attr_reader :learning

		def initialize(entity, learn)
			super entity, {encumbrance: false, status_tick: false, unhide: false}
			@learning = learn
			@learning = Entity::Status.source_from(@learning.id) if @learning.is_a? Entity::StatusType
			calculate_prerequisites
		end

		def take_action
			@learning.stateful = @entity
			@learning.effects.each do |effect|
				effect.unserialise if effect.respond_to? :unserialise
			end
		end

		def broadcast_results
			@entity.broadcast_self BroadcastScope::SELF
			text = "You have learnt #{@learning.name}."
			text = "You have become #{@learning.a_or_an} #{@learning.name}." if @learning.family == :class
			message_ent = Entity::Message.new({characters: [@entity.id], message: text, type: MessageType::SKILL_LEARNT})
			message_ent.save
			if @learning.family == :class
				notify = Array.new
				@entity.location.characters.each do |char|
					notify << char.id unless char == @entity
				end

				message_class = Entity::Message.new({characters: notify, type: MessageType::CLASS_LEARNT, message: "#{@entity.name} has become a #{@learning.name}!"}) unless notify.count == 0
				message_class.save
			end
		end

		private

		def calculate_prerequisites
			@cp_cost = 0
			i = 0
			@learning.effects.each do |effect|
				if effect.respond_to? :learn_intent_callback
					debug effect
					add_cost "learn_#{i}", effect.method(:learn_intent_callback)<commit_msg>Resolved ND-19 Learning a Class sometimes raises an exception<commit_after>module Intent
	# Learn a new Skill or Class
	class Learn < Action

		attr_reader :learning

		def initialize(entity, learn)
			super entity, {encumbrance: false, status_tick: false, unhide: false}
			@learning = learn
			@learning = Entity::Status.source_from(@learning.id) if @learning.is_a? Entity::StatusType
			calculate_prerequisites
		end

		def take_action
			@learning.stateful = @entity
			@learning.effects.each do |effect|
				effect.unserialise if effect.respond_to? :unserialise
			end
		end

		def broadcast_results
			@entity.broadcast_self BroadcastScope::SELF
			text = "You have learnt #{@learning.name}."
			text = "You have become #{@learning.a_or_an} #{@learning.name}." if @learning.family == :class
			message_ent = Entity::Message.new({characters: [@entity.id], message: text, type: MessageType::SKILL_LEARNT})
			message_ent.save
			if @learning.family == :class
				notify = Array.new
				@entity.location.characters.each do |char|
					notify << char.id unless char == @entity
				end

				unless notify.count == 0
					message_class = Entity::Message.new({characters: notify, type: MessageType::CLASS_LEARNT, message: "#{@entity.name} has become a #{@learning.name}!"})
					message_class.save
				end
			end
		end

		private

		def calculate_prerequisites
			@cp_cost = 0
			i = 0
			@learning.effects.each do |effect|
				if effect.respond_to? :learn_intent_callback
					debug effect
					add_cost "learn_#{i}", effect.method(:learn_intent_callback)
{'fraction_non_alphanumeric': 0.1118766404199475, 'fraction_numerical': 0.0026246719160104987, 'mean_word_length': 4.0563847429519075, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '207151', 'n_tokens_mistral': 1144, 'n_tokens_neox': 947, 'n_words': 250}