|
Forum Novice
Join Date: Mar 2006
Location: upstate NY
Age: 36
Posts: 488
|
Converting to 1.0
Im trying to convert this to 1.0, i got it to compile but now when I try to add a song I get a crash???
Code:
Server Crash Report
===================
RunUO Version 1.0.0, Build 36918
Operating System: Microsoft Windows NT 5.1.2600.0
.NET Framework: 1.1.4322.2032
Time: 5/29/2007 2:42:13 PM
Mobiles: 4551
Items: 200068
Clients:
- Count: 1
Exception:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Server.Items.MusicBox.PlayListGump.Target(MusicBoxTrack target)
at Server.Items.MusicBox.InternalTarget.OnTarget(Mobile from, Object o)
at Server.Targeting.Target.Invoke(Mobile from, Object targeted)
at Server.Network.PacketHandlers.TargetResponse(NetState state, PacketReader pvSrc)
at Server.Network.MessagePump.HandleReceive(NetState ns)
at Server.Network.MessagePump.Slice()
at Server.Core.Main(String[] args)
MusicBox.cs
Code:
using System;
using System.Collections;
using Server;
using Server.Targeting;
using Server.Gumps;
using Server.ContextMenus;
using Server.Network;
using Server.Mobiles;
using Server.Items;
using Server.Scripts.Commands;
namespace Server.Items.MusicBox
{
[Flipable(0x2AF9, 0x2AFD)]
public class MusicBox : Item
{
public static void Initialize()
{
Server.Commands.Register("AddAllSongs", AccessLevel.GameMaster, new
CommandEventHandler(AddAllSongs_OnCommand));
}
[Usage("AddAllSongs")]
[Description("Adds all songs to the MusicBox.")]
public static void AddAllSongs_OnCommand(CommandEventArgs e)
{
e.Mobile.SendMessage("Target the MusicBox.");
e.Mobile.Target = new InternalTarget();
}
public class InternalTarget : Target
{
public InternalTarget()
: base(1, false, TargetFlags.None)
{
}
protected override void OnTarget(Mobile from, object o)
{
if (o is MusicBox)
{
from.SendMessage("All Tracks were added to the Music Box!");
((MusicBox)o).AddAllTracks();
}
else
from.SendMessage("That is not a Music Box!");
}
}
public const int SONGS = 51;
[Constructable]
public MusicBox()
: base(0x2AF9)
{
Name = "MusicBox: Stopped";
Weight = 3.0;
m_HasTrack = new bool[SONGS];
for (int x = 0; x < SONGS; x++)
{
m_HasTrack[x] = false;
}
}
public MusicBox(Serial serial)
: base(serial)
{
}
public override void GetContextMenuEntries( Mobile from, ArrayList list )
{
base.GetContextMenuEntries( from, list );
list.Add(new PlayListEntry(from, this));
}
bool playing;
public override void OnDoubleClick(Mobile from)
{
if (from.AccessLevel < AccessLevel.GameMaster)
{
if (playing)
{
StopMusic(from);
Name = "MusicBox: Stopped";
}
else
{
PlayMusic(from);
Name = "MusicBox: Playing";
}
}
else
{
IPooledEnumerable eable = from.Map.GetMobilesInRange(from.Location, m_Range);
ArrayList list = new ArrayList();
foreach (Mobile mob in eable)
{
if (playing)
StopMusic(mob);
else
PlayMusic(mob);
}
eable.Free();
if (playing)
Name = "MusicBox: Stopped";
else
Name = "MusicBox: Playing";
}
playing = !playing;
}
private static int[] m_Locals = new int[] { 1075131, 1075132, 1075133, 1075134, 1075135, 1075136,
1075137,
1075138, 1075139, 1075140, 1075142, 1075143, 1075144, 1075145, 1075146, 1075147, 1075148,
1075149,
1075150, 1075151, 1075152, 1075154, 1075155, 1075156, 1075157, 1075158, 1075159, 1075160,
1075163,
1075164, 1075165, 1075166, 1075167, 1075168, 1075170, 1075171, 1075172, 1075173, 1075174,
1075175,
1075176, 1075177, 1075178, 1075179, 1075180, 1075181, 1075182, 1075183, 1075184, 1075185, 1075186
};
private static MusicName[] m_Songs = new MusicName[] {
MusicName.OldUlt02,MusicName.Serpents,MusicName.Britain1,
MusicName.Britain2,MusicName.Bucsden,MusicName.Jhelom,MusicName.LBCastle,MusicName.Magincia,MusicName.Minoc,
MusicName.Ocllo,MusicName.Samlethe,MusicName.Skarabra,MusicName.Trinsic,MusicName.Vesper,MusicName.Wind,
MusicName.Yew,MusicName.Cave01,MusicName.Dungeon9,MusicName.Sailing,MusicName.Tavern01,MusicName.Tavern02,
MusicName.Tavern03,MusicName.Tavern04,MusicName.Combat1,MusicName.Combat3,MusicName.Death,MusicName.Victory,
MusicName.BTCastle,MusicName.Nujelm,MusicName.Dungeon2,MusicName.Cove,MusicName.Moonglow,MusicName.Zento,
MusicName.TokunoDungeon,MusicName.Linelle
};
public static int[] Locals
{
get { return m_Locals; }
}
public static MusicName[] Songs
{
get { return m_Songs; }
}
private bool[] m_HasTrack;
public bool[] HasTrack
{
get { return m_HasTrack; }
set { m_HasTrack = value; }
}
public void AddTrack(MusicBoxTrack track)
{
for (int x = 0; x < MusicBox.SONGS; x++)
{
if (track.Song == MusicBox.Songs[x])
{
m_HasTrack[x] = true;
}
}
}
public void AddAllTracks()
{
for (int x = 0; x < MusicBox.SONGS; x++)
{
m_HasTrack[x] = true;
}
}
private int m_Range = 10;
[CommandProperty(AccessLevel.GameMaster)]
public int Range
{
get { return m_Range; }
set { m_Range = value; }
}
private MusicName m_Music = MusicName.Invalid;
[CommandProperty(AccessLevel.GameMaster)]
public MusicName Music
{
get { return m_Music; }
set { m_Music = value; InvalidateProperties(); }
}
public virtual void PlayMusic(Mobile m)
{
if (m_Music != MusicName.Invalid && m.NetState != null)
m.Send( Network.PlayMusic.GetInstance(m_Music));
}
public virtual void StopMusic(Mobile m)
{
if (m_Music != MusicName.Invalid && m.NetState != null)
m.Send(Network.PlayMusic.InvalidInstance);
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write((int)0); // version
writer.Write((int)m_Range);
writer.Write((int)m_Music);
for (int x = 0; x < SONGS; x++)
{
writer.Write((bool)m_HasTrack[x]);
}
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
m_Range = reader.ReadInt();
m_Music = (MusicName)reader.ReadInt();
m_HasTrack = new bool[SONGS];
for (int x = 0; x < SONGS; x++)
{
m_HasTrack[x] = reader.ReadBool();
}
Name = "MusicBox: Stopped";
}
}
public class PlayListEntry : ContextMenuEntry
{
private Mobile m_From;
private MusicBox m_Box;
public PlayListEntry(Mobile from, MusicBox box)
: base(10003, 1)
{
m_From = from;
m_Box = box;
}
public override void OnClick()
{
m_From.SendGump(new PlayListGump(m_From, m_Box));
}
}
public class PlayListGump : Gump
{
private MusicBox m_Box;
private Mobile m_From;
public PlayListGump(Mobile from, MusicBox box)
: base(30, 30)
{
from.CloseGump(typeof(PlayListGump));
m_Box = box;
m_From = from;
AddBackground(0, 0, 600, 480, 9400);
AddPage(0);
AddHtmlLocalized(250, 10, 180, 20, 1075130, 2124, false, false);
int Xpos = 26, Ypos = 42;
int z = 0;
for (int x = 0; x < 3; x++)
{
for (int y = 0; y < 17; y++)
{
bool has = (box.HasTrack[z]);
AddSongEntry(Xpos, Ypos, MusicBox.Locals[z], has ? 177 : 547, z + 100, has);
Ypos += 20;
z++;
}
Xpos += 200;
Ypos = 42;
}
AddLabel(250, 460, 2124, "Add Songs");
AddButton(220, 460, 1210, 1210, 99, GumpButtonType.Reply, 0);
}
private void AddSongEntry(int x, int y, int local, int color, int song, bool active)
{
AddHtmlLocalized(x, y, 180, 20, local, color, false, false);
if (active) AddButton(x - 20, y, 1210, 1210, song, GumpButtonType.Reply, 0);
}
public override void OnResponse(NetState sender, RelayInfo info)
{
if (info.ButtonID == 99)
{
m_From.Target = new InternalTarget(this);
}
else if (info.ButtonID > 99)
{
m_Box.Music = MusicBox.Songs[info.ButtonID - 100];
m_From.SendMessage("Now active:");
m_From.SendLocalizedMessage(MusicBox.Locals[info.ButtonID - 100]);
}
else
return;
}
public void Target(MusicBoxTrack target)
{
for (int x = 0; x < MusicBox.SONGS; x++)
{
if (target.Song == MusicBox.Songs[x])
{
if (!m_Box.HasTrack[x])
{
m_Box.HasTrack[x] = true;
target.Delete();
m_From.SendMessage("Song successfully added.");
}
else
m_From.SendMessage("That song is already added.");
}
}
}
public class InternalTarget : Target
{
private PlayListGump m_Owner;
public InternalTarget(PlayListGump owner)
: base(1, false, TargetFlags.None)
{
m_Owner = owner;
}
protected override void OnTarget(Mobile from, object o)
{
if (o is MusicBoxTrack)
{
m_Owner.Target((MusicBoxTrack)o);
}
else
from.SendMessage("That is not a Song Track!");
}
}
}
}
Any help would be great, thanks....
__________________
|