/**********************************************************
RunUO AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on May-15-2012 07:15:28pm
Filepath: scripts\Engines\worldchat\WorldChat.cs
Lines of code: 66

Description: 

***********************************************************/


using System;
using Server;
using System.Reflection;
using Server.Items;
using Server.Targeting;
using Server.Mobiles;
using Server.Gumps;
using Server.Network;


namespace Server.Commands
{
	public class WorldChat
	{
		public static void Initialize()
		{
			CommandSystem.Register( "c", AccessLevel.Player, new CommandEventHandler( WorldChat_OnCommand ) );
			CommandSystem.Register( "chat", AccessLevel.Player, new CommandEventHandler( WorldChat_OnCommand ) );
		}

		[Usage( "chat" )]
		[Description( "world chat" )]
		private static void WorldChat_OnCommand( CommandEventArgs e )
		{		
			PlayerMobile pm = e.Mobile as PlayerMobile;
			
			bool chatting=true;
			
			if ( e.Length <= 0 )
			{
				chatting=false;
				pm.SendMessage("usage: \"[c [string]\" to chat");
				pm.SendMessage("usage: \"[c @off\" to turn off chat");
				pm.SendMessage("usage: \"[c @on\" to turn on chat");
			}
			else if( e.Length == 1)
			{				
				chatting=false;
				switch(e.GetString(0))
				{
					case "@off":
					{
						pm.WorldChatEnabled=false; 
						pm.SendMessage("Chat has been turned off");
					} break;
					case "@on":
					{
						pm.WorldChatEnabled=true; 
						pm.SendMessage("Chat has been turned on");
					}break;
					
					default: chatting=true;break;
				}
			}
			
			if(chatting && pm.WorldChatEnabled)
			{
				string chatmsg = e.ArgString;
			
			
				foreach ( NetState state in NetState.Instances )
				{
					Mobile m = state.Mobile;
					
					if(m is PlayerMobile)
					{
						if(((PlayerMobile)m).WorldChatEnabled)
						{							
							m.SendMessage( 284, "{0}[{1}]: {2}",(pm.AccessLevel>AccessLevel.Player) ? "*" : "",pm.Name,chatmsg);
						}
					}						
				}
			
			}
					
		}
		

		
	}
}



