/************ TwoWayRadios.cs v.0 ******************************************* * * (C) 2010, Lokai * * Description: These are communication devices that are designed to be * placed anywhere and used to transmit everything heard by one radio * to the matching one. If both are 'On', they will transmit any speech * to anyone within range of the matching radio. * Usage: They can be given as gifts or sold in shops, but the Bag should be * given, not the individual radios. The bag will produce matching radios * when opened for the first time. If a GameMaster chooses to make the bag * reusable, then it will produce new matching radios each time it is * opened when empty. The radios are then double-clicked to turn them On * or Off. Speech is automatically transmitted to everyone within range * of the matching radio. Range is determined by the Volume level. * ***************************************************************************/ /*************************************************************************** * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * ***************************************************************************/ using System; using Server; using Server.Mobiles; namespace Server.Items { public enum VolumeLevel { Muted = 1, Soft = 3, Medium = 5, Loud = 7, Blasting = 9 } public class TwoWayRadio : Item { private bool m_On; public bool On { get { return m_On; } set { m_On = value; } } private VolumeLevel m_Volume; [CommandProperty(AccessLevel.Player)] public VolumeLevel Volume { get { return m_Volume; } set { m_Volume = value; } } private TwoWayRadio m_Mate; public TwoWayRadio Mate { get { return m_Mate; } set { m_Mate = value; } } [Constructable] public TwoWayRadio() : base(0xE2E) { Weight = 4.0; m_On = false; m_Volume = VolumeLevel.Muted; } public override void OnSpeech(SpeechEventArgs e) { if (m_Mate.On && this.On) { IPooledEnumerable hearers = m_Mate.GetMobilesInRange((int)Volume); foreach (Mobile hearer in hearers) { hearer.SendMessage("YOU HEAR {0}: {1}", e.Mobile.Name, e.Speech); } } base.OnSpeech(e); } public override void OnDoubleClick(Mobile from) { m_On = !m_On; } public TwoWayRadio(Serial serial) : base(serial) { } public override void Serialize(GenericWriter writer) { base.Serialize(writer); writer.WriteEncodedInt((int)0); // version writer.Write(m_Mate); } public override void Deserialize(GenericReader reader) { base.Deserialize(reader); int version = reader.ReadEncodedInt(); m_Mate = reader.ReadItem() as TwoWayRadio; m_On = false; } } public class TwoWayRadioBag : Bag { public override string DefaultName { get { return "a Bag of Two-Way Radios"; } } private bool m_Reusable; [CommandProperty(AccessLevel.GameMaster)] public bool Reusable { get { return m_Reusable; } set { m_Reusable = value; } } private bool m_Used; [CommandProperty(AccessLevel.GameMaster)] public bool Used { get { return m_Used; } set { m_Used = value; } } [CommandProperty(AccessLevel.Player)] public bool IsUsed { get { return m_Used; } } [Constructable] public TwoWayRadioBag() : base() { Movable = true; Hue = Utility.RandomRedHue(); m_Used = false; m_Reusable = false; } public override void OnDoubleClick(Mobile from) { if (Items.Count == 0 && (m_Reusable || !m_Used)) { TwoWayRadio radioA = new TwoWayRadio(); TwoWayRadio radioB = new TwoWayRadio(); radioA.Mate = radioB; radioB.Mate = radioA; DropItem(radioA); DropItem(radioB); m_Used = true; } base.OnDoubleClick(from); } public TwoWayRadioBag(Serial serial) : base(serial) { } public override void Serialize(GenericWriter writer) { base.Serialize(writer); writer.Write((int)0); // version writer.Write((bool)m_Used); } public override void Deserialize(GenericReader reader) { base.Deserialize(reader); int version = reader.ReadInt(); m_Used = reader.ReadBool(); } } }