znmud-0.0.1/benchmark/
znmud-0.0.1/cmd/
znmud-0.0.1/cmd/emotes/
znmud-0.0.1/cmd/objects/
znmud-0.0.1/cmd/tiny/
znmud-0.0.1/doc/
znmud-0.0.1/farts/
znmud-0.0.1/lib/
znmud-0.0.1/lib/combat/
znmud-0.0.1/lib/core/bodytypes/
znmud-0.0.1/lib/engine/
znmud-0.0.1/lib/farts/
znmud-0.0.1/logs/
#
# file::    cmd_look.rb
#

# This source code copyright (C) 2009 Craig Smith
# All rights reserved.
#
# Released under the terms of the TeensyMUD Public License
# See LICENSE file for additional information.
#

module Cmd
  bindtextdomain("cmd")

  # Look command displays the contents of a room
  def cmd_look(args)
    if @position == :sleeping
	sendto _("All you see is dreams...")
	return
    end
    look_inside = false
    in_keyword = _("in")
    place = get_object(location)
    if args=~/#{in_keyword}\s+(.*)/i
    	look_inside = true
	args= $1
    end
    case args
    when nil, ""
	add_event(id,location,:describe)
	if cansee? :dark
		place.objects.each do |x|
		      add_event(id,x.id,:describe)
		end
		place.people(id).each do |x|
		     if x.has_attribute? :invisible
		         add_event(id,x.id,:describe) if cansee? :invisible
		     else
		         add_event(id,x.id,:describe)
		     end
		end
		add_event(id,location,:describe_exits)
	else
		add_event(id,id,:show, _("Something is moving around here.")) if place.people(id).size > 0
	end
    else
	if cansee? :dark
		# First look for object by that name
		objs = place.find_objects(args)
		case objs.size
		when 0
			# No objects found, look for ppl
			ppl = peopleinroom(args)
			case ppl.size
			when 0
				# Check inventory
				objs = find_inv(args)
				case objs.size
				when 0
					sendto("You do not see that here.")
				when 1
					o = objs[0]
					if look_inside
						if o.has_val? :fountain
							sendto _("It is filled with %{liquid}." % {:liquid => get_object(o.has_val?(:fountain)).name})
						elsif o.kind_of? Container
							add_event(id,o.id,:describe_contents)
						else
							sendto _("You can not look inside that.")
						end
						return
					end
					if o.desc.size > 0
						add_event(o.id,id,:show,"#{o.desc}")
					elsif o.is_a? BodyPart
						has_something = false
						if o.worn.size > 0
							has_something = true
							o.worn.each do |loc, w|
								wobj = get_object(w)
								sendto _("%{obj} on its %{part}." % {:obj => wobj.shortname, :part => loc})
							end
						end
						if o.wield
							has_something = true
							wobj = get_object(o.wield)
							sendto _("It is still weilding %{obj}." % {:obj => wobj.shortname})
						end
						if get_object(o.owner)
							sendto _("It is the %{part} of %{owner}." % {:part => o.name, :owner => get_object(o.owner).shortname }) if not has_something
						else
							sendto _("It's a severed %{part}." % {:part => o.name})
						end
					else
						sendto _("You see nothing special.")
					end
				else
					sendto _("Which one?")
				end
			when 1
				player = ppl[0]
				if player.has_attribute? :invisible
					if not cansee? :invisible
						sendto _("You do not see that here.")
						return
					end
				end
				msg = String.new
				msg << "#{player.desc}\n" if player.desc.size > 0
				# If admin (or perhaps a thief) can see inventory
				if world.is_admin? id and player.contents.size > 0
					msg << _("Carrying...\n")
					player.contents.each do |oid|
						msg << get_object(oid).shortname << "\n"
					end
				end
				# Describe body clothes and condition
				if player.body
				   if player.body.wearing.size > 0
					player.body.wearing.each do |oid|
						o = get_object(oid)
						msg << _("Wearing %{what} on %{where}\n" % {:what => o.shortname, :where => o.val["worn"]})
					end
				   else
					msg << _("You see nothing special.\n")
				   end
				   weapons = player.body.wielding?
				   if weapons.size > 0
				   	weapon = get_object(weapons[0])
				   	wmsg = _("%{pronoun} is wielding %{weapon}" % {:pronoun => player.pronoun.ucfirst, :weapon => weapon.shortname})
					if weapons.size == 2
						weapon = get_object(weapons[1])
						wmsg << _(" and %{weapon}" % {:weapon => weapon.shortname})
					end
					msg << wmsg << "\n"
				   end
				   if player.body.severed
					player.body.severed.each do |bid|
						part = get_object(bid)
						msg << _("%{pronoun} has a severed %{part}.\n" % {:pronoun => pronoun.ucfirst, :part => part.name})
					end
				   end
				end # EndIf palyer.body
				if world.is_admin? id
					msg << _("Health: %{hp}/%{maxhp}\n" % {:hp => player.health, :maxhp => player.stats[:maxhp]})
					msg << _("Infected.\n") if player.has_attribute? :infected
					msg << _("Infection percent: %{per}\%\n" % {:per => player.stats[:infection]}) if player.stats[:infection] > 0
				else

					msg << player.describe_health(true) << "\n"
				end
				msg << _("%{pronoun} is glowing with a brilliant aura!" % {:pronoun => pronoun.ucfirst}) if world.can_build? player.id
				sendto(msg)
			else
				sendto _("Which one?")
			end
		when 1  # Only one object matched...good
			o = objs[0]
			if look_inside
				if o.has_val? :fountain
					sendto _("It is filled with %{liquid}." % {:liquid => get_object(o.has_val?(:fountain)).name})
				elsif o.kind_of? Container
					add_event(id,o.id,:describe_contents)
				else
					sendto _("You can not look inside that.")
				end
				return
			end
			if o.desc.size > 0
				add_event(o.id,id,:show,"#{o.desc}")
			else
				sendto _("You see nothing special.")
			end
		else
			sendto _("You need to be more specific on which object you want to examine")
		end
	else
		sendto _("You don't see that.")
	end
    end
  end

end