Feature - Implemented Add "avatar potion" as an item_type()

zarqon

Well-known member
There are more and more of these, and they are not something I particularly care about. However, for any kind of item management script, there is presently no way to detect whether something is an avatar potion (for the purpose of ignoring it) outside of hardcoding a long (and growing) list.

Fortunately, a fairly straightforward solution is at hand! Presently, avatar potions have no results from item_type(). Solution: have them return "avatar potion".

This will enable scripters to do:

PHP:
if (item_type(myitem) == "avatar potion")
   completely_ignore(myitem);
 
Code:
boolean is_avatar_potion( item it )
{
    effect e = effect_modifier( it, "Effect" );
    if ( e == $effect[ none ] )
	return false;
    string avatar = string_modifier( e, "Avatar" );
    return avatar != "";
}
Which is not to say that this is a bad idea, but "there is presently no way to detect whether something is an avatar potion other than hardcoding a long list" is clearly false.
 
Indeed! That bit of cleverness shall manage nicely, thank you.

Philosophically, I would like to see item_type() have a meaningful return value for as many items as possible, but for the purposes of this particular feature request, my needs have been addressed.
 
I'm sure you realized this, but that function doesn't really have to make intermediate results; I just did it that way to make it clear to people who might have been surprised with this:

Code:
boolean is_avatar_potion( item it )
{
    return it.effect_modifier( "Effect" ).string_modifier( "Avatar" ) != "";
}
 
This relevant code sample is in my logout script so I'll share.

Code:
void avatar_potion() {
	if(!can_interact()) return;
	// Check if there is an Avatar potion currently in affect
	if(have_effect($effect[Juiced and Jacked]) > 0) {
		print("Won't imbibe an Avatar Potion because you already have the head of a pumpkin.", "blue");
		return;
	}		
	foreach ef in my_effects()
		if(string_modifier(ef, "Avatar") != "") {
			print("Won't imbibe an Avatar Potion because you already look like a "+string_modifier(ef, "Avatar").to_monster()+".", "blue");
			return;
		}

	// Some avatars are too lame to use
	boolean lame(item it) {
		return $items[blob of acid, flayed mind, kobold kibble, Fitspiration™ poster, giant tube of black lipstick, punk patch, artisanal hand-squeezed wheatgrass juice, steampunk potion, 
		Gearhead Goo, Enchanted Plunger, Enchanted Flyswatter, Missing Eye Simulation Device, Gnollish Crossdress]
			contains it;
	}

	item random_avatar() {
		item [int] avatars;
		int cheapest_price() {
			sort avatars by price(value);
			foreach x,av in avatars if(price(av) > 0) return price(av);
			return 0;
		}
		
		foreach it in $items[]
			if(string_modifier(to_effect(string_modifier(it, "Effect")), "Avatar") != "" && (can_interact() || available_amount(it) > 0) && !lame(it))
				avatars[ count(avatars) ] = it;
		if(count(avatars) == 0)
			return $item[none];
		int min_price = cheapest_price() * 1.3; // Let's include everything up to 30% above minimum price... which will be 130 meat if can_interact() although slightly higher in hardcore.
		item [int] short_list;
		foreach x,av in avatars
			if(price(av) <= min_price)
				short_list[ count(short_list) ] = av;
		if(count(short_list) == 1)
			return short_list[0];
		return short_list[ random(count(short_list)) ];
	}

	item choice = random_avatar();
	if(retrieve_item(1, choice))
		use(1, choice);
}
 
While you're all here, perhaps I can ask if there are similarly clever ways of detecting the following types of items:

1. Items that lead to fights
2. Items that grant skills
 
And to answer Zarqon's questing, no to fights, but:

> ash $item[Trash, a Memoir].string_modifier("Skill")

Returned: Garbage Nova
 
As a note for anyone else watching or trying to use this on 'stable' mafia, that was added on 2015-10-20 by Veracity in r16391.
 
Back
Top