@create #9338 named generic openable/closable RPG container:generic openable/closable RPG container
@prop #43001."opened" 1 r
@prop #43001."close_msg" "You close %d." rc
@prop #43001."oclose_msg" "%n closes %d." rc
@prop #43001."oopen_msg" "%n opens %d." rc
@prop #43001."open_msg" "You open %d." rc
@prop #43001."oopen_fail_msg" "" rc
@prop #43001."open_fail_msg" "It is locked." rc
@prop #43001."empty_msg" "It is empty." rc
"#43001.("open_key") => E_PERM (Permission denied)
@prop #43001."trusted" {} rc
;;#43001.("store_action") = "store"
;;#43001.("manufactured") = 749532345
;;#43001.("worth") = -1
;;#43001.("condition") = 100
;;#43001.("odrop_failed_msg") = "%<tries> to drop %t but fails!"
;;#43001.("odrop_succeeded_msg") = "%<drops> %t."
;;#43001.("otake_succeeded_msg") = "%<picks> up %t."
"#43001.("key") => E_PERM (Permission denied)
;;#43001.("aliases") = {"generic openable/closable RPG container"}
;;#43001.("object_size") = {8333, 1141286565}

@verb #43001:"close_msg oclose_msg oopen_msg open_msg oopen_fail_msg open_fail_msg empty_msg" this none this rx
@program #43001:close_msg
return (msg = this.(verb)) ? $string_utils:pronoun_sub(msg, @args) | "";
.

@verb #43001:"open" this none none rxd
@program #43001:open
"Copied from generic container (#8):open by Nosredna (#2487) Mon Oct  4 00:16:25 1993 PDT";
if (this:opened())
  player:tell("It's already open.");
elseif (this:is_openable_by(callers() ? caller_perms() | player))
  this:set_opened(1);
  player:tell(this:open_msg());
  if (msg = this:oopen_msg(player, this))
    player.location:announce(msg);
  endif
else
  player:tell(this:open_fail_msg());
  if (msg = this:oopen_fail_msg(player, this))
    player.location:announce(msg);
  endif
endif
.

@verb #43001:"close" this none none rxd
@program #43001:close
"Copied from generic container (#8):close by Nosredna (#2487) Mon Oct  4 00:17:11 1993 PDT";
if (!this:opened())
  player:tell("It's already closed.");
else
  this:set_opened(0);
  player:tell(this:close_msg());
  if (msg = this:oclose_msg())
    player.location:announce(msg);
  endif
endif
.

@verb #43001:"is_openable_by" this none this
@program #43001:is_openable_by
"Copied from generic container (#8):is_openable_by by Nosredna (#2487) Sat Oct  9 19:20:53 1993 PDT";
return (this.open_key == 0) || $lock_utils:eval_key(this.open_key, args[1]);
.

@verb #43001:"look_self" this none this
@program #43001:look_self
player:tell_lines((desc = this:description()) ? desc | "You see nothing special.");
if (this.opened)
  this:tell_contents();
endif
.

@verb #43001:"tell_contents" this none this
@program #43001:tell_contents
"Copied from generic container (#8):tell_contents by Nosredna (#2487) Mon Oct  4 00:32:17 1993 PDT";
if (this.contents)
  player:tell("Contents:");
  for thing in (this.contents)
    player:tell("  ", thing:title());
  endfor
elseif (msg = this:empty_msg())
  player:tell(msg);
endif
.

@verb #43001:"description" this none this rx
@program #43001:description
"Need to know if it is opened or closed.";
if (msg = this.description)
  open_msg = this.opened ? "" | " It is closed.";
  return (typeof(msg) == LIST) ? {@msg, open_msg} | (msg + open_msg);
endif
.

@verb #43001:"pu*t ins*ert st*ore ca*che" any in this rx
@program #43001:put
"Prevent transfer if container is not opened";
if (!this:opened())
  player:tell(this.name, " is closed.");
  return 0;
endif
pass(@args);
.

@verb #43001:"re*move ex*tract rec*over ge*t ta*ke" any from this rx
@program #43001:remove
"Prevent transfer if container is not opened";
if (!this:opened())
  player:tell(this.name, " is closed.");
  return 0;
endif
pass(@args);
.

@verb #43001:"acceptable" this none this
@program #43001:acceptable
"Allow $local.rpg.equipment only if the container is open.";
return pass(@args) && this:opened();
.

@verb #43001:"@lock_for_open" this with any
@program #43001:@lock_for_open
"Copied from generic container (#8):@lock_for_open by Nosredna (#2487) Sun Oct 17 18:32:59 1993 PDT";
if (caller != this.owner)
  player:tell(E_PERM);
  return;
endif
key = $lock_utils:parse_keyexp(iobjstr, player);
if (typeof(key) == STR)
  player:tell("That key expression is malformed:");
  player:tell("  ", key);
else
  res = this.open_key = key;
  if (typeof(res) == ERR)
    player:tell(res, ".");
  else
    player:tell("Locked opening of ", this.name, " with this key:");
    player:tell("  ", $lock_utils:unparse_key(key));
  endif
endif
.

@verb #43001:"set_opened" this none this
@program #43001:set_opened
if (!$perm_utils:controls(caller.owner, this))
  return E_PERM;
endif
this.opened = opened = !(!args[1]);
return opened;
.

@verb #43001:"opened" this none this
@program #43001:opened
return this.(verb);
.

@verb #43001:"exitfunc" this none this
@program #43001:exitfunc
{thing} = args;
if (!(rpg = $local.rpg):trusted_efunc())
  return E_PERM;
elseif (this:is_openable_by(caller_perms()) || (thing.owner == caller_perms()))
  return pass(thing);
elseif ($recycler:valid(thing))
  "thanks to Dred for a patch on some invalid obj problems";
  su = $string_utils;
  rpg:log_error((((((((((((((("Object moved by container: " + su:nn(thing)) + " moved by ") + su:nn(this)) + " Container Location: ") + su:nn(this.location)) + " from: ") + su:nn(thing.location)) + " Player: ") + su:nn(player)) + " Locale: ") + su:nn(player.location)) + " Callers: ") + toliteral(callers(1))) + " ") + ctime());
  thing:moveto(this);
endif
return 0;
.

"***finished***