// Class: NameRandomizer
// File: NameRandomizer.cs
// By: SHAMBAMPOW
// Inspired by: Nockar (and his Script Support question)
// Date: 7/21/2012
// Purpose: Use this to apply a random prefix to valid items.
// Example: Rather than "Katana", it would show "Zues's Magical Katana"
// RunUO: 2.1+ (below versions would probably just require minor edits to command system usage)
// Methods: GiveRandomName( item ) and PotentiallyGiveRandomName( item, chance )
// Commands: [RandomName and [RandomPrefix
using System;
using Server;
using Server.Items;
namespace Server.Items
{
public class NameRandomizer
{
public const double RandomChanceToApplyNamePrefixes = 0.005; // 0.5%
#region RandomizeName Command
public static void Initialize()
{
Server.Commands.CommandSystem.Register( "RandomName", AccessLevel.GameMaster, new Server.Commands.CommandEventHandler( RandomizeName_OnCommand ) );
Server.Commands.CommandSystem.Register( "RandomPrefix", AccessLevel.GameMaster, new Server.Commands.CommandEventHandler( AddRandomNamePrefix_OnCommand ) );
}
[Usage( "RandomName" )]
[Description( "Apply a random name prefix to an armor, weapon, clothing, jewel, talisman, quiver, or instrument - using the LabelNumber of that item." )]
public static void RandomizeName_OnCommand( Server.Commands.CommandEventArgs e )
{
bool userandomname = false;
Mobile from = e.Mobile;
from.LocalOverheadMessage( Server.Network.MessageType.Regular, 0x1150, true, "Target the item you wish to randomize the name of...");
from.Target = new RandomizeNameTarget( userandomname );
}
[Usage( "RandomPrefix" )]
[Description( "Applies a random name prefix to an armor, weapon, clothing, jewel, talisman, quiver, or instrument - using the current name of that item." )]
public static void AddRandomNamePrefix_OnCommand( Server.Commands.CommandEventArgs e )
{
bool userandomname = true;
Mobile from = e.Mobile;
from.LocalOverheadMessage( Server.Network.MessageType.Regular, 0x1150, true, "Target the item you wish to randomize the name of...");
from.Target = new RandomizeNameTarget( userandomname );
}
private class RandomizeNameTarget : Server.Targeting.Target
{
private bool UseCurrentName;
public RandomizeNameTarget( bool useCurrentName ) : base( -1, true, Server.Targeting.TargetFlags.None )
{
UseCurrentName = useCurrentName;
}
protected override void OnTarget( Mobile from, object o )
{
if( o is Item )
{
if( o is BaseWeapon || o is BaseArmor || o is BaseJewel || o is BaseClothing || o is BaseTalisman || o is BaseQuiver || o is BaseInstrument )
{
NameRandomizer.GiveRandomName( (Item)o, !UseCurrentName );
if( !UseCurrentName )
from.SendMessage( "You randomize the entire name." );
else from.SendMessage( "You randomize the name prefix." );
}
else
{
from.SendMessage( "Valid targets include weapons, armor, jewelry, clothing, talismans, quivers, and instruments." );
}
}
}
}
#endregion
private static string[] names = new string[]{ "", "Zeus", "Plato", "Zenon", "Zoro", "Hercules", "Ramses", "Ramos", "Thor", "Hercules", "Mars", "Fabio", "Cupid", "Jude", "Pluto", "Hermes",
"Aphrodite", "Apollo", "Ares", "Artemis", "Athena", "Demeter", "Dionysus", "Hades", "Hephaestus", "Hera", "Hestia", "Poseidon", "Zeus", "Aether",
"Ananke", "Erebus", "Gaia", "Hemera", "Chaos", "Chronos", "Nesoi", "Nyx", "Uranus", "Ourea", "Phanes", "Pontus", "Tartarus", "Thalassa", "Hyperion",
"Lapetus", "Coeus", "Crius", "Cronos", "Mnemosyne", "Oceanus", "Phoebe", "Rhea", "Tethys", "Theia", "Themis", "Asteria", "Astraeus", "Atlas", "Aura",
"Dione", "Eos", "Epimetheus", "Eurybia", "Eurynome", "Helios", "Clymene", "Lelantos", "Leto", "Menoetius", "Metis", "Ophion", "Pallas", "Perses",
"Prometheus", "Selene", "Styx", "Janus", "Jupiter", "Saturn", "Genius", "Mercury", "Apollo", "Mars", "Vulcan", "Neptune", "Sol", "Orcus", "Liber",
"Tellus", "Ceres", "Juno", "Luna", "Diana", "Minerva", "Venus", "Vesta", "Feronia", "Minerva", "Novensides", "Pales", "Salus", "Fortune", "Fons",
"Fides", "Ops", "Flora", "Vediovis", "Summanus", "Larunda", "Terminus", "Quirinus", "Vortumnus", "Lares", "Diana", "Luncina" };
private static string[] adjectives = new string[] { "", "Glorious", "Tremendous", "Treasured", "Fabled", "Lost", "Adorned", "Missing", "Sacred", "Mighty", "Mystical", "Magic",
"Crippled", "Ruined", "Valued", "Glorious", "Fabulous", "Wonderful", "Wonderous", "Telling", "Spiritual", "Valuable", "Worthy", "Worthless",
"Forgotten", "Misplaced", "Reclaimed", "Powerful", "Feared", "Horrific", "Famed", "Esteemed", "Noble", "Holy", "Mystifying", "Boasted", "Honored",
"Precious" };
/* Example usage of GiveRandomName( Item item ):
* NameRandomizer.GiveRandomName( newlyconstructeditem ); // Gives a random name 100% of the time
*/
public static void GiveRandomName( Item item, bool useLabelNumberOnly )
{
if( item == null || item.Deleted ) return; // null check
if( !( item is BaseArmor || item is BaseJewel || item is BaseWeapon || item is BaseClothing || item is BaseTalisman || item is BaseQuiver || item is BaseInstrument ) )
return; // this prevents things like scrolls, gems, etc from being renamed in the lootpack.
string currentName = NameRandomizer.GetNameString( item, useLabelNumberOnly); // returns weapons current name (Name property if it exist, else the string translation of the item's LabelNumber)
string personName = NameRandomizer.GetRandomPersonName();
string adjective = NameRandomizer.GetRandomAdjective();
if( ( personName + adjective ).Equals( "" ) )
{
if( Utility.RandomBool() )
{
personName = names[Utility.RandomMinMax( 1, names.Length )];
}
else
{
adjective = adjectives[Utility.RandomMinMax( 1, adjectives.Length )];
}
}
item.Name = String.Format( "{0}{1}{2}", String.Format( "{0}{1}", personName, String.IsNullOrEmpty( personName ) ? "" : "'s " ), String.Format( "{0}{1}", adjective, String.IsNullOrEmpty( adjective ) ? "" : " " ), currentName ); // add a 's and a space if the name isn't empty
}
/* Example usage of GiveRandomName( Item item ):
* NameRandomizer.GiveRandomName( newlyconstructeditem ); // Gives a random name 100% of the time
*/
public static void GiveRandomName( Item item )
{
NameRandomizer.GiveRandomName( item, true );
}
// private classes, cannot be called from outside - used only within GiveRandomName.
private static string GetRandomPersonName()
{
return names[Utility.Random( names.Length )];
}
// private classes, cannot be called from outside - used only within GiveRandomName.
private static string GetRandomAdjective()
{
return adjectives[Utility.Random( adjectives.Length )];
}
/* Example usage of PotentiallyRandomizeName( Item item ):
* NameRandomizer.PotentiallyRandomizeName( newlyconstructeditem ); // Gives a random name 0.05% of the time.
*/
public static void PotentiallyRandomizeName( Item item )
{
NameRandomizer.PotentiallyRandomizeName( item, RandomChanceToApplyNamePrefixes ); // default 0.5% chance
}
public static void PotentiallyRandomizeName( Item item, double chance )
{
NameRandomizer.PotentiallyRandomizeName( item, chance, true );
}
//Example usage of PotentiallyRandomizeName( Item item, double chance ):
//NameRandomizer.PotentiallyRandomizeName( newlyconstructeditem, 0.01 ); // Gives a random name 1% of the time.
public static void PotentiallyRandomizeName( Item item, double chance, bool useLabelNumber )
{
if( Utility.RandomDouble() < chance )
{
NameRandomizer.GiveRandomName( item, useLabelNumber );
}
}
private static string GetNameString( Item item )
{
return NameRandomizer.GetNameString( item, false );
}
// UseOnlyLabelNumber means that it will get the name strictly based upon either a) the overridden LabelNumber (artifacts, etc) or b) the item's current ItemID.
private static string GetNameString(Item item, bool useOnlyLabelNumber)
{
string name = (useOnlyLabelNumber ? null : item.Name);
/*if ( item != null && name == null )
name = Server.Localize.Localizer.Get( item.LabelNumber );*/
return name;
}
}
}