Avalanche Game prototype. Built with Rails.

mission.rb 1.1KB

    class Mission < ActiveRecord::Base belongs_to :owner, :class_name => "User" has_many :mission_agents, :dependent => :destroy has_many :mission_agent_steps, :through => :mission_agents accepts_nested_attributes_for :mission_agents, allow_destroy:true def validade_completion mission_completed = true self.mission_agents.each do |agent| if agent.get_invite != nil if agent.get_invite.status != 'Completed' mission_completed = false end end end if mission_completed self.status = "Completed" self.save end end def has_agent_been_assigned(user) # Dont assign the owner of a mission as one of its agents if user == self.owner return true end # Iterate thru all mission agents and check if user has been asigned self.mission_agents.each do |agent| if agent.user != user agent.mission_agent_invites.each do |invite| if invite.user == user return true end end else return true end end return false end end