|
||
|
|||||||
| Script Support Get support for modifying RunUO Scripts, or writing your own! |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Join Date: Dec 2003
Posts: 1,069
|
Code:
using System;
using System.Collections;
using Server.Items;
using Server.Mobiles;
using Server.Gumps;
namespace Server
{
public class FightSys
{
private static int Mobiles;
private static ArrayList MobilesArray;
public virtual void BaseDeserialize( GenericReader reader )
{
int version = reader.ReadEncodedInt();
int Mobiles = reader.ReadInt();
ArrayList MobilesArray = reader.ReadMobileList();
ChildDeserialize( reader );
}
public virtual void ChildDeserialize( GenericReader reader )
{
int version = reader.ReadEncodedInt();
}
public virtual void BaseSerialize( GenericWriter writer )
{
writer.WriteEncodedInt( (int) 0 ); // version
writer.Write( (int) Mobiles );
writer.WriteMobileList( MobilesArray );
ChildSerialize( writer );
}
public virtual void ChildSerialize( GenericWriter writer )
{
writer.WriteEncodedInt( (int) 0 ); // version
}
public static void FightListCheckAdd(Mobile o)
{
if ( o is PlayerMobile )
{
bool Found = false;
PlayerMobile m = (PlayerMobile) o;
if ( MobilesArray == null )
MobilesArray = new ArrayList();
foreach( PlayerMobile pm in MobilesArray )
{
if ( m == pm )
Found = true;
}
if ( !Found )
{
m.CloseGump( typeof( FightUnregGump ) );
m.CloseGump( typeof( FightGump ) );
m.CloseGump( typeof( FightRegGump ) );
m.SendGump( new FightRegGump() );
}
else
{
m.SendMessage( "You are already on the roster." );
}
}
}
public static void FightListAdd(Mobile o)
{
if ( o is PlayerMobile )
{
PlayerMobile m = (PlayerMobile) o;
m.SendMessage( "You have been added to the roster." );
Mobiles += 1;
MobilesArray.Add(m);
m.CloseGump( typeof( FightUnregGump ) );
m.CloseGump( typeof( FightGump ) );
m.SendGump( new FightGump( MobilesArray ) );
}
}
public static void FightListCheckRemove(Mobile o)
{
if ( o is PlayerMobile )
{
bool Found = false;
PlayerMobile m = (PlayerMobile) o;
if ( MobilesArray == null )
MobilesArray = new ArrayList();
foreach( PlayerMobile pm in MobilesArray )
{
if ( m == pm )
Found = true;
}
if ( Found )
{
m.CloseGump( typeof( FightUnregGump ) );
m.CloseGump( typeof( FightGump ) );
m.CloseGump( typeof( FightRegGump ) );
m.SendGump( new FightUnregGump() );
}
else
{
m.SendMessage( "You are not on the roster." );
}
}
}
public static void FightListRemove(Mobile o)
{
if ( o is PlayerMobile )
{
PlayerMobile m = (PlayerMobile) o;
m.CloseGump( typeof( FightRegGump ) );
m.CloseGump( typeof( FightGump ) );
m.SendMessage( "You have been removed from the roster." );
Mobiles -= 1;
MobilesArray.Remove(m);
}
}
public static void FightListList(Mobile o)
{
if ( o is PlayerMobile )
{
PlayerMobile m = (PlayerMobile) o;
if ( MobilesArray != null && Mobiles > 0 )
{
m.CloseGump( typeof( FightGump ) );
m.SendGump( new FightGump( MobilesArray ) );
}
else
{
m.SendMessage( "The roster is empty." );
}
}
}
}
}
![]()
__________________
HI! |
|
|
|
|
|
#2 (permalink) |
|
Master of the Internet
Join Date: Aug 2003
Posts: 5,688
|
where do you call the BaseSerialize and BaseDeserialize methods from? They wont get called automatically.
You can make a placeholder item like a fightstone and have it call your FightSys ser/deser methods in the placeholders serialize/deserialize methods. Note, your BaseSerialize and BaseDeserialize methods are not currently defined as static, so you will either have to create an instance of your FightSys class and reference that in your placeholder item, or change them to static methods in order to access them.
__________________
The first line of the first rule in the forum rules and guidelines "Be respectful of others. " For questions, information, and support for XmlSpawner and its addons, visit the XmlSpawner Support Forum |
|
|
|
|
|
#3 (permalink) |
|
Join Date: Dec 2003
Posts: 1,069
|
so... is there a way to call them without using a placeholder item? Or can I call them from the FightBroker Mobile that I have?
I just assumed that world saves and loads automatically called the BaseSerialize and BaseDeserialize methods. ![]() Well... I made them static.... Then I tried calling them from the FightBroker with no luck... Code:
using System;
using System.Collections;
using Server.Items;
using Server.Mobiles;
using Server.Gumps;
namespace Server
{
public class FightSys
{
private static int Mobiles;
private static ArrayList MobilesArray;
public static void BaseDeserialize( GenericReader reader )
{
int version = reader.ReadEncodedInt();
int Mobiles = reader.ReadInt();
ArrayList MobilesArray = reader.ReadMobileList();
}
public static void BaseSerialize( GenericWriter writer )
{
writer.WriteEncodedInt( (int) 0 ); // version
writer.Write( (int) Mobiles );
writer.WriteMobileList( MobilesArray );
}
public static void FightListCheckAdd(Mobile o)
{
if ( o is PlayerMobile )
{
bool Found = false;
PlayerMobile m = (PlayerMobile) o;
if ( MobilesArray == null )
MobilesArray = new ArrayList();
foreach( PlayerMobile pm in MobilesArray )
{
if ( m == pm )
Found = true;
}
if ( !Found )
{
m.CloseGump( typeof( FightUnregGump ) );
m.CloseGump( typeof( FightGump ) );
m.CloseGump( typeof( FightRegGump ) );
m.SendGump( new FightRegGump() );
}
else
{
m.SendMessage( "You are already on the roster." );
}
}
}
public static void FightListAdd(Mobile o)
{
if ( o is PlayerMobile )
{
PlayerMobile m = (PlayerMobile) o;
m.SendMessage( "You have been added to the roster." );
Mobiles += 1;
MobilesArray.Add(m);
m.CloseGump( typeof( FightUnregGump ) );
m.CloseGump( typeof( FightGump ) );
m.SendGump( new FightGump( MobilesArray ) );
}
}
public static void FightListCheckRemove(Mobile o)
{
if ( o is PlayerMobile )
{
bool Found = false;
PlayerMobile m = (PlayerMobile) o;
if ( MobilesArray == null )
MobilesArray = new ArrayList();
foreach( PlayerMobile pm in MobilesArray )
{
if ( m == pm )
Found = true;
}
if ( Found )
{
m.CloseGump( typeof( FightUnregGump ) );
m.CloseGump( typeof( FightGump ) );
m.CloseGump( typeof( FightRegGump ) );
m.SendGump( new FightUnregGump() );
}
else
{
m.SendMessage( "You are not on the roster." );
}
}
}
public static void FightListRemove(Mobile o)
{
if ( o is PlayerMobile )
{
PlayerMobile m = (PlayerMobile) o;
m.CloseGump( typeof( FightRegGump ) );
m.CloseGump( typeof( FightGump ) );
m.SendMessage( "You have been removed from the roster." );
Mobiles -= 1;
MobilesArray.Remove(m);
}
}
public static void FightListList(Mobile o)
{
if ( o is PlayerMobile )
{
PlayerMobile m = (PlayerMobile) o;
if ( MobilesArray != null && Mobiles > 0 )
{
m.CloseGump( typeof( FightGump ) );
m.SendGump( new FightGump( MobilesArray ) );
}
else
{
m.SendMessage( "The roster is empty." );
}
}
}
}
}
Code:
using Server.Misc;
using Server.Network;
using Server.Spells;
namespace Server.Mobiles
{
[CorpseName( "Broker's Corpse" )]
public class FightBroker : Mobile
{
private TimeSpan RegTime;
[Constructable]
public FightBroker()
{
Name = NameList.RandomName( "male" );
Title = "the Fight Broker";
Body = 0x190;
Hue = Utility.RandomSkinHue();
CantWalk = true;
AddItem( new Shoes() ) ;
AddItem( new LongPants( Utility.RandomNondyedHue() ) );
AddItem( new FancyShirt( Utility.RandomNondyedHue() ) );
Item hair = new Item( Utility.RandomList( 0x203B, 0x203C, 0x203D, 0x2044, 0x2045, 0x2047, 0x2049, 0x204A ) );
hair.Hue = Utility.RandomHairHue();
hair.Layer = Layer.Hair;
hair.Movable = false;
AddItem( hair );
Blessed = true;
}
public FightBroker( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 1 );
FightSys.BaseSerialize( writer );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
switch( version )
{
case 1: break;
case 0:
int Mobiles = reader.ReadInt();
ArrayList MobilesArray = reader.ReadMobileList();
break;
}
FightSys.BaseDeserialize( reader );
}
public override void GetContextMenuEntries( Mobile from, ArrayList list )
{
base.GetContextMenuEntries( from, list );
list.Add( new ContextRosAdd( from ) );
list.Add( new ContextRosRemove( from ) );
list.Add( new ContextRosView( from ) );
if ( from.AccessLevel >= AccessLevel.GameMaster )
{}
}
public class ContextRosAdd : ContextMenuEntry
{
private Mobile m;
public ContextRosAdd( Mobile from ) : base( 5042, 3 )
{
m = from;
}
public override void OnClick()
{
FightSys.FightListCheckAdd(m);
}
}
public class ContextRosRemove : ContextMenuEntry
{
private Mobile m;
public ContextRosRemove( Mobile from ) : base( 5043, 3 )
{
m = from;
}
public override void OnClick()
{
FightSys.FightListCheckRemove(m);
}
}
public class ContextRosView : ContextMenuEntry
{
private Mobile m;
public ContextRosView( Mobile from ) : base( 6121, 3 )
{
m = from;
}
public override void OnClick()
{
FightSys.FightListList(m);
}
}
}
}
__________________
HI! |
|
|
|
|
|
#4 (permalink) |
|
Master of the Internet
Join Date: Aug 2003
Posts: 5,688
|
well, you can do it from your mobile, but if you have more than one instance of them it will serialize/deserialize your FightSys information on each one of them - kind of inefficient. Also, you will have to actually have an instance of one of them in order for them to ser/deser.
The answer to your other question is no - world saves and loads do not automatically call ser/deser methods that you may have defined in your custom classes. They will only be automatically called if they are derived from classes that already ser/deser during saves/loads such as items and mobiles. Just for general information, it is possible to add your own world save/load handlers and do it yourself but that is a major job and would make no sense to attempt in this case.
__________________
The first line of the first rule in the forum rules and guidelines "Be respectful of others. " For questions, information, and support for XmlSpawner and its addons, visit the XmlSpawner Support Forum |
|
|
|
|
|
#5 (permalink) |
|
Join Date: Dec 2003
Posts: 1,069
|
So... I should just have an item that holds the list and all the mobiles can access? Would I need to change the way they access it or should it just work the way I have it? Also... does the item have to be constructable and be constructed in the world?
__________________
HI! |
|
|
|
|
|
#6 (permalink) |
|
Master of the Internet
Join Date: Aug 2003
Posts: 5,688
|
yes, it will have to be constructable and you will have to make an instance of it in the world, but you only need one.
It should work just the way that you were doing it in your mobile.
__________________
The first line of the first rule in the forum rules and guidelines "Be respectful of others. " For questions, information, and support for XmlSpawner and its addons, visit the XmlSpawner Support Forum |
|
|
|
|
|
#7 (permalink) |
|
Join Date: Dec 2003
Posts: 1,069
|
Thanks for the info ArteGordon. Works great.
I still wish I could create a class with serialization without having to make an item placeholder for it. I know I can have the item invisible and/or in the internal map but that kind of defeats the purpose. ![]()
__________________
HI! |
|
|
|
|
|
#8 (permalink) |
|
Master of the Internet
Join Date: Aug 2003
Posts: 5,688
|
It is possible, but it would take a bit of effort, and it would not end up in the standard item or mobile serialization stream. It would basically be your own custom ser/deser. A fun exercise, but for stuff like this just slapping down an item as a ser/deser hook is definitely the way to go.
__________________
The first line of the first rule in the forum rules and guidelines "Be respectful of others. " For questions, information, and support for XmlSpawner and its addons, visit the XmlSpawner Support Forum |
|
|
|
|
|
#10 (permalink) |
|
Master of the Internet
Join Date: Aug 2003
Posts: 5,688
|
yes, you could do something like that. Throw this into your custom class
Code:
public static void Configure()
{
EventSink.WorldLoad += new WorldLoadEventHandler( Load );
EventSink.WorldSave += new WorldSaveEventHandler( Save );
}
Code:
public static void Save( WorldSaveEventArgs e )
{
// write out your data
}
public static void Load()
{
// read in your data
}
__________________
The first line of the first rule in the forum rules and guidelines "Be respectful of others. " For questions, information, and support for XmlSpawner and its addons, visit the XmlSpawner Support Forum |
|
|
|
|
|
#11 (permalink) |
|
Master of the Internet
Join Date: Aug 2003
Posts: 5,688
|
now, given that you already have nice little binary reader/writer compatible ser/deser routines defined in your custom class you could also just do a binary load/save with some code like this in your Save handler
BinaryFileWriter writer = new BinaryFileWriter( filePath, true ); then just call your BaseSerialize method with the writer. and in your Load handler FileStream fs = new FileStream( filePath, (FileMode) 3, (FileAccess) 1, (FileShare) 1 ); BinaryFileReader reader = new BinaryFileReader( new BinaryReader( fs ) ); then just call your BaseDeserialize method with the reader.
__________________
The first line of the first rule in the forum rules and guidelines "Be respectful of others. " For questions, information, and support for XmlSpawner and its addons, visit the XmlSpawner Support Forum |
|
|
|
|
|
#12 (permalink) |
|
Join Date: Dec 2003
Posts: 1,069
|
Sweet! Now I wish I was at home so I could test it.
One question... if I save to new files in the Saves folder will it make the automatic backups with the new files or do I need to add them to the backup script somehow? ![]()
__________________
HI! |
|
|
|
|
|
#13 (permalink) |
|
Master of the Internet
Join Date: Aug 2003
Posts: 5,688
|
yes, it will automatically back them up.
__________________
The first line of the first rule in the forum rules and guidelines "Be respectful of others. " For questions, information, and support for XmlSpawner and its addons, visit the XmlSpawner Support Forum |
|
|
|
|
|
#15 (permalink) |
|
Join Date: Dec 2003
Posts: 1,069
|
Alright... so I DID start on it tonight. hehe anyway.. Here is the code I have now (Thanks again, ArteGordon, for all the pointers!):
Code:
using System;
using System.Collections;
using System.IO;
using Server;
using Server.Mobiles;
using Server.Gumps;
namespace Server
{
public class FightList
{
private static int Mobiles;
private static ArrayList MobilesArray;
public static void Configure()
{
EventSink.WorldLoad += new WorldLoadEventHandler( Load );
EventSink.WorldSave += new WorldSaveEventHandler( Save );
}
public static void Save( WorldSaveEventArgs e )
{
if ( !Directory.Exists( "Saves/CustomArrays" ) )
Directory.CreateDirectory( "Saves/CustomArrays" );
string filePath = Path.Combine( Core.BaseDirectory, "Saves/CustomArrays/FightList.bin" );
BinaryFileWriter writer = new BinaryFileWriter( filePath, true );
BaseSerialize( writer );
}
public static void Load()
{
string filePath = Path.Combine( Core.BaseDirectory, "Saves/CustomArrays/FightList.bin" );
if ( !File.Exists( filePath ) )
return;
FileStream fs = new FileStream( filePath, (FileMode) 3, (FileAccess) 1, (FileShare) 1 );
BinaryFileReader reader = new BinaryFileReader( new BinaryReader( fs ) );
BaseDeserialize( reader );
}
public static void BaseDeserialize( GenericReader reader )
{
int version = reader.ReadEncodedInt();
int Mobiles = reader.ReadInt();
ArrayList MobilesArray = reader.ReadMobileList();
}
public static void BaseSerialize( GenericWriter writer )
{
writer.WriteEncodedInt( (int) 0 ); // version
writer.Write( (int) Mobiles );
if ( MobilesArray == null )
MobilesArray = new ArrayList();
writer.WriteMobileList( MobilesArray );
}
public static void FightListCheckAdd(Mobile o)
{
if ( o is PlayerMobile )
{
bool Found = false;
PlayerMobile m = (PlayerMobile) o;
if ( MobilesArray == null )
MobilesArray = new ArrayList();
foreach( PlayerMobile pm in MobilesArray )
{
if ( m == pm )
Found = true;
}
if ( !Found )
{
m.CloseGump( typeof( FightUnregGump ) );
m.CloseGump( typeof( FightGump ) );
m.CloseGump( typeof( FightRegGump ) );
m.SendGump( new FightRegGump() );
}
else
{
m.SendMessage( "You are already on the roster." );
}
}
}
public static void FightListAdd(Mobile o)
{
if ( o is PlayerMobile )
{
PlayerMobile m = (PlayerMobile) o;
m.SendMessage( "You have been added to the roster." );
Mobiles += 1;
MobilesArray.Add(m);
m.CloseGump( typeof( FightUnregGump ) );
m.CloseGump( typeof( FightGump ) );
m.SendGump( new FightGump( MobilesArray ) );
}
}
public static void FightListCheckRemove(Mobile o)
{
if ( o is PlayerMobile )
{
bool Found = false;
PlayerMobile m = (PlayerMobile) o;
if ( MobilesArray == null )
MobilesArray = new ArrayList();
foreach( PlayerMobile pm in MobilesArray )
{
if ( m == pm )
Found = true;
}
if ( Found )
{
m.CloseGump( typeof( FightUnregGump ) );
m.CloseGump( typeof( FightGump ) );
m.CloseGump( typeof( FightRegGump ) );
m.SendGump( new FightUnregGump() );
}
else
{
m.SendMessage( "You are not on the roster." );
}
}
}
public static void FightListRemove(Mobile o)
{
if ( o is PlayerMobile )
{
PlayerMobile m = (PlayerMobile) o;
m.CloseGump( typeof( FightRegGump ) );
m.CloseGump( typeof( FightGump ) );
m.SendMessage( "You have been removed from the roster." );
Mobiles -= 1;
MobilesArray.Remove(m);
}
}
public static void FightListList(Mobile o)
{
if ( o is PlayerMobile )
{
PlayerMobile m = (PlayerMobile) o;
if ( MobilesArray != null && Mobiles > 0 )
{
m.CloseGump( typeof( FightGump ) );
m.SendGump( new FightGump( MobilesArray ) );
}
else
{
m.SendMessage( "The roster is empty." );
}
}
}
}
}
__________________
HI! |
|
|
|
|
|
#16 (permalink) |
|
Master of the Internet
Join Date: Aug 2003
Posts: 5,688
|
have you checked to make sure that you actually have mobiles in your array that you are saving, and/or that the mobiles array is empy immediately upon deser because your ser/deser code looks fine.
__________________
The first line of the first rule in the forum rules and guidelines "Be respectful of others. " For questions, information, and support for XmlSpawner and its addons, visit the XmlSpawner Support Forum |
|
|
|
|
|
#17 (permalink) |
|
P3'c Orion Aviator
Join Date: Sep 2004
Age: 30
Posts: 1,272
|
You gave me this info one time, (and thanks for it) so im going to give it back to you :"P
try putting debug messages of it telling you what it is doing on the Load() method, because It looks correct to me, And writing to files is something Im actually quite good at :"P -Jamie |
|
|
|
|
|
#18 (permalink) |
|
Join Date: Dec 2003
Posts: 1,069
|
Yep, I made sure I had mobiles in the array, and even watched the file to make sure it changed in size when there was a mobile present which it did... I found the problem though... I always wondered why you redeclare vars in the deserialize.
![]() Code:
public static void BaseDeserialize( GenericReader reader )
{
int version = reader.ReadEncodedInt();
int Mobiles = reader.ReadInt();
ArrayList MobilesArray = reader.ReadMobileList();
}
Code:
public static void BaseDeserialize( GenericReader reader )
{
int version = reader.ReadEncodedInt();
Mobiles = reader.ReadInt();
MobilesArray = reader.ReadMobileList();
}
Now to get working on the GM controls for this puppy! ![]()
__________________
HI! |
|
|
|
|
|
#19 (permalink) |
|
Master of the Internet
Join Date: Aug 2003
Posts: 5,688
|
hehe good one. I missed that.
Well, I did say that it would be a fun exercise so it looks like you are going to have some fun. Good luck!
__________________
The first line of the first rule in the forum rules and guidelines "Be respectful of others. " For questions, information, and support for XmlSpawner and its addons, visit the XmlSpawner Support Forum |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|