@create $feature named The RPG-O-Meter Feature Object:The RPG-O-Meter Feature Object,rpg-o-meter
;;#12631.("help_msg") = "The RPG-O-Meter defines verbs which help track the usage of the RPG.  The @RPG-O-Meter verb displays a usage graph, and the _who's_gaming verb (which requires the Who's Feature, #22822,) shows who's currently in an RPG room."
;;#12631.("feature_verbs") = {"@meter", "_who's_gaming", "_who's_starred"}
"#12631.("key") => E_PERM (Permission denied)
;;#12631.("aliases") = {"The RPG-O-Meter Feature Object", "rpg-o-meter"}
;;#12631.("description") = "The RPG-O-Meter is a collection of verbs to help you watch how people are using the LambdaMOO RPG."
;;#12631.("object_size") = {5631, 1141286586}

@verb #12631:"@RPG-O-Meter @meter" none none none rxd
@program #12631:@RPG-O-Meter
"The @RPG-O-Meter (or @meter) verb is used to track usage in the RPG.";
"Ever wonder just how many people are using that big huge thing with the";
"monsters?  Well, this'll tell you, in some sense.  The @meter verb draws";
"a bar graph showing the .last_action property of players' voodoo dolls";
"against time (the last day, week, month, and three months.)";
"Whether this provides any useful information is up to you to decide.";
"Note that the verb may take quite a while to run, as it suspends for";
"10 seconds at a time, in an effort to reduce spam.";
sum = 0;
usage = this:usage();
labels = {"1 day    ", "1 week   ", "1 month  ", "3 months ", ">3 months"};
player:tell("Recent RPG usage");
player:tell("----------------");
for i in (usage)
  sum = sum + i;
  bar = "";
  for k in [1..i / 10]
    bar = bar + "#";
  endfor
  player:tell(((labels[i in usage] + ":") + (((i % 10) >= 5) ? bar + "=" | bar)) + ((((" (" + tostr(i)) + " [") + tostr((i * 100) / ($local.petitions_core.signature_threshold * 20))) + "%])"));
endfor
player:tell("----------------");
player:tell("Each hash mark represents 10 players whose .last_action property was set in the period shown.");
player:tell(((("There are currently " + tostr(sum)) + " active RPG players and about ") + tostr($local.petitions_core.signature_threshold * 20)) + " voting players on LambdaMOO.");
.

@verb #12631:"_who's_gaming" none none none rxd
@program #12631:_who's_gaming
"Indicate, in some vague sense, who's playing the RPG.  The only measure here is whether the player is in a child of the generic RPG room.  This verb requires #22822, the who's feature.";
where = args[1];
who = args[2];
no_one = "No one seems to be gaming.";
someone = iobjstr ? "%w %a gaming %l." | "%w %a gaming.";
if (where == player.location)
  where_name = "here";
else
  where_name = "in " + where.name;
endif
who_all = {};
gms = home = 0;
for thing in (iobjstr ? $set_utils:intersection(connected_players(), where.contents) | connected_players())
  $command_utils:suspend_if_needed(0);
  if (#46:is_rpg_room(thing.location))
    who_all = {@who_all, thing};
    if (thing.location == thing.home)
      home = home + 1;
    endif
    if (thing in $local.rpg.gms)
      gms = gms + 1;
    endif
  endif
endfor
who_all = setremove(who_all, who);
player:tell(#22822:("who's_substitute")(who_all ? someone | no_one, $list_utils:map_arg(#22822, "who's_title", who_all), where_name));
player:tell((gms ? tostr(gms) + ((gms == 1) ? " is a gamemaster" | " are gamemasters") | "") + (home ? (((gms ? ", and " | "") + tostr(home)) + ((home == 1) ? " is " | " are ")) + "at home." | (gms ? "." | "")));
.

@verb #12631:"usage" this none this rx
@program #12631:usage
tm = time();
dy = wk = mt = m3 = m6 = 0;
h = 3 * (m = 4 * (w = 7 * (d = (24 * 60) * 60)));
foo = children(#74);
for bar in (foo)
  $command_utils:suspend_if_needed(10);
  if (is_player(bar.character))
    t = tm - #24874:last_action(bar);
    if (t <= d)
      dy = dy + 1;
    elseif (t <= w)
      wk = wk + 1;
    elseif (t <= m)
      mt = mt + 1;
    elseif (t <= h)
      m3 = m3 + 1;
    else
      m6 = m6 + 1;
    endif
  endif
endfor
return {dy, wk, mt, m3, m6};
.

@verb #12631:"_who's_starred" this none this
@program #12631:_who's_starred
"Who's got silly cruft after their name?  Requires #22822.";
who_star = who_cruft = {};
alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
for foo in (connected_players())
  if (foo.name[length(foo.name)] == "*")
    who_star = {@who_star, foo};
  elseif (!index(alpha, foo.name[length(foo.name)]))
    who_cruft = {@who_cruft, foo};
  endif
endfor
if (who_star)
  player:tell(($string_utils:english_list($list_utils:map_arg(#22822, "who's_title", who_star)) + ((length(who_star) == 1) ? " is" | " are")) + " connected.");
else
  player:tell("No one is starred right now.");
endif
if (who_cruft)
  player:tell(((who_star ? "In addition" | "However") + ", ") + (((($string_utils:english_list($list_utils:map_arg(#22822, "who's_title", who_cruft)) + ((length(who_cruft) == 1) ? " has" | " have")) + " extra cruft after ") + ((length(who_cruft) == 1) ? who_cruft[1].pp | "their")) + ((length(who_cruft) == 1) ? " name." | " names.")));
endif
.

"***finished***