|
||
|
|||||||
| Server Support on Windows Get (and give) support on general questions related to the RunUO server itself. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 (permalink) | |
|
Forum Novice
|
Quote:
Is there ANY way to fix this or stop this from happening? Thanks in Advance, -TalRave |
|
|
|
|
|
|
#4 (permalink) |
|
Forum Expert
Join Date: Oct 2003
Location: Minnesota... somewhere in the boonies
Age: 29
Posts: 1,171
|
Then the new books have problems with their Serialize/Deserialize methods... it would help if you posted the script for the new spellbook.
__________________
Signatures are tools of the devil... |
|
|
|
|
|
#6 (permalink) |
|
Forum Novice
|
Here's my spellbook script: (edit: this should probably be in script support, but I didn't know it would be the script in the beginning, so forgive me.. lol)
Code:
using System;
using System.Collections;
using Server;
using Server.Targeting;
using Server.Network;
using Server.Spells;
using Server.Scripts.Commands;
using Server.Engines.Craft;
namespace Server.Items
{
public enum SpellbookQuality
{
Low,
Regular,
Exceptional
}
public enum SpellbookType
{
Invalid = -1,
Regular,
Necromancer,
Paladin,
Ninja,
Samurai
}
public class Spellbook : Item, ICraftable
{
public static void Initialize()
{
EventSink.OpenSpellbookRequest += new OpenSpellbookRequestEventHandler( EventSink_OpenSpellbookRequest );
EventSink.CastSpellRequest += new CastSpellRequestEventHandler( EventSink_CastSpellRequest );
Commands.Register( "AllSpells", AccessLevel.GameMaster, new CommandEventHandler( AllSpells_OnCommand ) );
}
[Usage( "AllSpells" )]
[Description( "Completely fills a targeted spellbook with scrolls." )]
private static void AllSpells_OnCommand( CommandEventArgs e )
{
e.Mobile.BeginTarget( -1, false, TargetFlags.None, new TargetCallback( AllSpells_OnTarget ) );
e.Mobile.SendMessage( "Target the spellbook to fill." );
}
private static void AllSpells_OnTarget( Mobile from, object obj )
{
if ( obj is Spellbook )
{
Spellbook book = (Spellbook)obj;
if ( book.BookCount == 64 )
book.Content = ulong.MaxValue;
else
book.Content = (1ul << book.BookCount) - 1;
from.SendMessage( "The spellbook has been filled." );
CommandLogging.WriteLine( from, "{0} {1} filling spellbook {2}", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( book ) );
}
else
{
from.BeginTarget( -1, false, TargetFlags.None, new TargetCallback( AllSpells_OnTarget ) );
from.SendMessage( "That is not a spellbook. Try again." );
}
}
private static void EventSink_OpenSpellbookRequest( OpenSpellbookRequestEventArgs e )
{
Mobile from = e.Mobile;
if ( !Multis.DesignContext.Check( from ) )
return; // They are customizing
SpellbookType type;
switch ( e.Type )
{
default:
case 1: type = SpellbookType.Regular; break;
case 2: type = SpellbookType.Necromancer; break;
case 3: type = SpellbookType.Paladin; break;
case 4: type = SpellbookType.Ninja; break;
case 5: type = SpellbookType.Samurai; break;
}
Spellbook book = Spellbook.Find( from, -1, type );
if ( book != null )
book.DisplayTo( from );
}
private static void EventSink_CastSpellRequest( CastSpellRequestEventArgs e )
{
Mobile from = e.Mobile;
if ( !Multis.DesignContext.Check( from ) )
return; // They are customizing
Spellbook book = e.Spellbook as Spellbook;
int spellID = e.SpellID;
if ( book == null || !book.HasSpell( spellID ) )
book = Find( from, spellID );
if ( book != null && book.HasSpell( spellID ) )
{
Spell spell = SpellRegistry.NewSpell( spellID, from, null );
if ( spell != null )
spell.Cast();
else
from.SendLocalizedMessage( 502345 ); // This spell has been temporarily disabled.
}
else
{
from.SendLocalizedMessage( 500015 ); // You do not have that spell!
}
}
private static Hashtable m_Table = new Hashtable();
public static SpellbookType GetTypeForSpell( int spellID )
{
if ( spellID >= 0 && spellID < 64 )
return SpellbookType.Regular;
else if ( spellID >= 100 && spellID < 116 )
return SpellbookType.Necromancer;
else if ( spellID >= 200 && spellID < 210 )
return SpellbookType.Paladin;
else if( spellID >= 400 && spellID < 406 )
return SpellbookType.Samurai;
else if( spellID >= 500 && spellID < 508 )
return SpellbookType.Ninja;
return SpellbookType.Invalid;
}
public static Spellbook FindRegular( Mobile from )
{
return Find( from, -1, SpellbookType.Regular );
}
public static Spellbook FindNecromancer( Mobile from )
{
return Find( from, -1, SpellbookType.Necromancer );
}
public static Spellbook FindPaladin( Mobile from )
{
return Find( from, -1, SpellbookType.Paladin );
}
public static Spellbook FindSamurai( Mobile from )
{
return Find( from, -1, SpellbookType.Samurai );
}
public static Spellbook FindNinja( Mobile from )
{
return Find( from, -1, SpellbookType.Ninja );
}
public static Spellbook Find( Mobile from, int spellID )
{
return Find( from, spellID, GetTypeForSpell( spellID ) );
}
public static Spellbook Find( Mobile from, int spellID, SpellbookType type )
{
if ( from == null )
return null;
ArrayList list = (ArrayList)m_Table[from];
if ( from.Deleted )
{
m_Table.Remove( from );
return null;
}
bool searchAgain = false;
if ( list == null )
m_Table[from] = list = FindAllSpellbooks( from );
else
searchAgain = true;
Spellbook book = FindSpellbookInList( list, from, spellID, type );
if ( book == null && searchAgain )
{
m_Table[from] = list = FindAllSpellbooks( from );
book = FindSpellbookInList( list, from, spellID, type );
}
return book;
}
public static Spellbook FindSpellbookInList( ArrayList list, Mobile from, int spellID, SpellbookType type )
{
Container pack = from.Backpack;
for ( int i = list.Count - 1; i >= 0; --i )
{
if ( i >= list.Count )
continue;
Spellbook book = (Spellbook)list[i];
if ( !book.Deleted && (book.Parent == from || (pack != null && book.Parent == pack)) && ValidateSpellbook( book, spellID, type ) )
return book;
list.Remove( i );
}
return null;
}
public static ArrayList FindAllSpellbooks( Mobile from )
{
ArrayList list = new ArrayList();
Item item = from.FindItemOnLayer( Layer.OneHanded );
if ( item is Spellbook )
list.Add( item );
Container pack = from.Backpack;
if ( pack == null )
return list;
for ( int i = 0; i < pack.Items.Count; ++i )
{
item = (Item)pack.Items[i];
if ( item is Spellbook )
list.Add( item );
}
return list;
}
public static bool ValidateSpellbook( Spellbook book, int spellID, SpellbookType type )
{
return ( book.SpellbookType == type && ( spellID == -1 || book.HasSpell( spellID ) ) );
}
public virtual SpellbookType SpellbookType{ get{ return SpellbookType.Regular; } }
public virtual int BookOffset{ get{ return 0; } }
public virtual int BookCount{ get{ return 64; } }
private ulong m_Content;
private int m_Count;
//New Code
private AosAttributes m_AosAttributes;
private AosSkillBonuses m_AosSkillBonuses;
private Mobile m_Crafter;
private SpellbookQuality m_Quality;
//End New Code
public override bool AllowEquipedCast( Mobile from )
{
return true;
}
public override Item Dupe( int amount )
{
Spellbook book = new Spellbook();
book.Content = this.Content;
book.LootType = this.LootType;
return base.Dupe( book, amount );
}
public override bool OnDragDrop( Mobile from, Item dropped )
{
if ( dropped is SpellScroll && dropped.Amount == 1 )
{
SpellScroll scroll = (SpellScroll)dropped;
SpellbookType type = GetTypeForSpell( scroll.SpellID );
if ( type != this.SpellbookType )
{
return false;
}
else if ( HasSpell( scroll.SpellID ) )
{
from.SendLocalizedMessage( 500179 ); // That spell is already present in that spellbook.
return false;
}
else
{
int val = scroll.SpellID - BookOffset;
if ( val >= 0 && val < BookCount )
{
m_Content |= (ulong)1 << val;
++m_Count;
InvalidateProperties();
scroll.Delete();
from.Send( new PlaySound( 0x249, GetWorldLocation() ) );
return true;
}
return false;
}
}
else
{
return false;
}
}
[CommandProperty( AccessLevel.GameMaster )]
public ulong Content
{
get
{
return m_Content;
}
set
{
if ( m_Content != value )
{
m_Content = value;
m_Count = 0;
while ( value > 0 )
{
m_Count += (int)(value & 0x1);
value >>= 1;
}
InvalidateProperties();
}
}
}
[CommandProperty( AccessLevel.GameMaster )]
public int SpellCount
{
get
{
return m_Count;
}
}
//New Code
[CommandProperty( AccessLevel.GameMaster )]
public AosAttributes Attributes
{
get{ return m_AosAttributes; }
set{}
}
[CommandProperty( AccessLevel.GameMaster )]
public AosSkillBonuses SkillBonuses
{
get{ return m_AosSkillBonuses; }
set{}
}
[CommandProperty( AccessLevel.GameMaster )]
public Mobile Crafter
{
get{ return m_Crafter; }
set{ m_Crafter = value; InvalidateProperties(); }
}
[CommandProperty( AccessLevel.GameMaster )]
public SpellbookQuality Quality
{
get{ return m_Quality; }
set{ m_Quality = value; InvalidateProperties(); }
}
//End New Code
public virtual int ArtifactRarity{ get{ return 0; } }
[Constructable]
public Spellbook() : this( (ulong)0 )
{
}
[Constructable]
public Spellbook( ulong content ) : this( content, 0xEFA )
{
}
public Spellbook( ulong content, int itemID ) : base( itemID )
{
Weight = 3.0;
Layer = Layer.OneHanded;
LootType = LootType.Blessed;
//New Code
m_AosAttributes = new AosAttributes( this );
m_AosSkillBonuses = new AosSkillBonuses( this );
m_Quality = SpellbookQuality.Regular;
//End New Code
Content = content;
}
public bool HasSpell( int spellID )
{
spellID -= BookOffset;
return ( spellID >= 0 && spellID < BookCount && (m_Content & ((ulong)1 << spellID)) != 0 );
}
//New Code
public override void OnAdded( object parent )
{
if ( Core.AOS && parent is Mobile )
{
Mobile from = (Mobile)parent;
m_AosSkillBonuses.AddTo( from );
int strBonus = m_AosAttributes.BonusStr;
int dexBonus = m_AosAttributes.BonusDex;
int intBonus = m_AosAttributes.BonusInt;
if ( strBonus != 0 || dexBonus != 0 || intBonus != 0 )
{
string modName = this.Serial.ToString();
if ( strBonus != 0 )
from.AddStatMod( new StatMod( StatType.Str, modName + "Str", strBonus, TimeSpan.Zero ) );
if ( dexBonus != 0 )
from.AddStatMod( new StatMod( StatType.Dex, modName + "Dex", dexBonus, TimeSpan.Zero ) );
if ( intBonus != 0 )
from.AddStatMod( new StatMod( StatType.Int, modName + "Int", intBonus, TimeSpan.Zero ) );
}
from.CheckStatTimers();
}
}
public override void OnRemoved( object parent )
{
if ( Core.AOS && parent is Mobile )
{
Mobile from = (Mobile)parent;
m_AosSkillBonuses.Remove();
string modName = this.Serial.ToString();
from.RemoveStatMod( modName + "Str" );
from.RemoveStatMod( modName + "Dex" );
from.RemoveStatMod( modName + "Int" );
from.CheckStatTimers();
}
}
//End New Code
public Spellbook( Serial serial ) : base( serial )
{
}
private static readonly ClientVersion Version_400a = new ClientVersion( "4.0.0a" );
public void DisplayTo( Mobile to )
{
// The client must know about the spellbook or it will crash!
if ( Parent == null )
{
to.Send( this.WorldPacket );
}
else if ( Parent is Item )
{
// What will happen if the client doesn't know about our parent?
to.Send( new ContainerContentUpdate( this ) );
}
else if ( Parent is Mobile )
{
// What will happen if the client doesn't know about our parent?
to.Send( new EquipUpdate( this ) );
}
to.Send( new DisplaySpellbook( this ) );
if ( Core.AOS && to.NetState != null && to.NetState.Version != null && to.NetState.Version >= Version_400a )
to.Send( new NewSpellbookContent( this, ItemID, BookOffset + 1, m_Content ) );
else
to.Send( new SpellbookContent( m_Count, BookOffset + 1, m_Content, this ) );
}
public override bool DisplayLootType{ get{ return Core.AOS; } }
public override void GetProperties( ObjectPropertyList list )
{
base.GetProperties( list );
int props=0;
foreach( int i in Enum.GetValues(typeof( AosAttribute)) )
if ( this.Attributes[(AosAttribute)i] > 0 ) ++props;
m_AosSkillBonuses.GetProperties( list );
//New Code
int prop;
if ( (prop = ArtifactRarity) > 0 )
list.Add( 1061078, prop.ToString() ); // artifact rarity ~1_val~
if ( (prop = m_AosAttributes.WeaponDamage) != 0 )
list.Add( 1060401, prop.ToString() ); // damage increase ~1_val~%
if ( (prop = m_AosAttributes.DefendChance) != 0 )
list.Add( 1060408, prop.ToString() ); // defense chance increase ~1_val~%
if ( (prop = m_AosAttributes.BonusDex) != 0 )
list.Add( 1060409, prop.ToString() ); // dexterity bonus ~1_val~
if ( (prop = m_AosAttributes.EnhancePotions) != 0 )
list.Add( 1060411, prop.ToString() ); // enhance potions ~1_val~%
if ( (prop = m_AosAttributes.CastRecovery) != 0 )
list.Add( 1060412, prop.ToString() ); // faster cast recovery ~1_val~
if ( (prop = m_AosAttributes.CastSpeed) != 0 )
list.Add( 1060413, prop.ToString() ); // faster casting ~1_val~
if ( (prop = m_AosAttributes.AttackChance) != 0 )
list.Add( 1060415, prop.ToString() ); // hit chance increase ~1_val~%
if ( (prop = m_AosAttributes.BonusHits) != 0 )
list.Add( 1060431, prop.ToString() ); // hit point increase ~1_val~
if ( (prop = m_AosAttributes.BonusInt) != 0 )
list.Add( 1060432, prop.ToString() ); // intelligence bonus ~1_val~
if ( (prop = m_AosAttributes.LowerManaCost) != 0 )
list.Add( 1060433, prop.ToString() ); // lower mana cost ~1_val~%
if ( (prop = m_AosAttributes.LowerRegCost) != 0 )
list.Add( 1060434, prop.ToString() ); // lower reagent cost ~1_val~%
if ( (prop = m_AosAttributes.Luck) != 0 )
list.Add( 1060436, prop.ToString() ); // luck ~1_val~
if ( (prop = m_AosAttributes.BonusMana) != 0 )
list.Add( 1060439, prop.ToString() ); // mana increase ~1_val~
if ( (prop = m_AosAttributes.RegenMana) != 0 )
list.Add( 1060440, prop.ToString() ); // mana regeneration ~1_val~
if ( (prop = m_AosAttributes.NightSight) != 0 )
list.Add( 1060441 ); // night sight
if ( (prop = m_AosAttributes.ReflectPhysical) != 0 )
list.Add( 1060442, prop.ToString() ); // reflect physical damage ~1_val~%
if ( (prop = m_AosAttributes.RegenStam) != 0 )
list.Add( 1060443, prop.ToString() ); // stamina regeneration ~1_val~
if ( (prop = m_AosAttributes.RegenHits) != 0 )
list.Add( 1060444, prop.ToString() ); // hit point regeneration ~1_val~
if ( (prop = m_AosAttributes.SpellChanneling) != 0 )
list.Add( 1060482 ); // spell channeling
if ( (prop = m_AosAttributes.SpellDamage) != 0 )
list.Add( 1060483, prop.ToString() ); // spell damage increase ~1_val~%
if ( (prop = m_AosAttributes.BonusStam) != 0 )
list.Add( 1060484, prop.ToString() ); // stamina increase ~1_val~
if ( (prop = m_AosAttributes.BonusStr) != 0 )
list.Add( 1060485, prop.ToString() ); // strength bonus ~1_val~
if ( (prop = m_AosAttributes.WeaponSpeed) != 0 )
list.Add( 1060486, prop.ToString() ); // swing speed increase ~1_val~%
if ( m_Crafter != null )
list.Add( 1050043, m_Crafter.Name ); // crafted by ~1_NAME~
if ( m_Quality == SpellbookQuality.Exceptional )
list.Add( 1060636 ); // exceptional
list.Add( 1042886, m_Count.ToString() ); // ~1_NUMBERS_OF_SPELLS~ Spells
//End New Code
}
public override void OnSingleClick( Mobile from )
{
base.OnSingleClick( from );
this.LabelTo( from, 1042886, m_Count.ToString() );
}
public override void OnDoubleClick( Mobile from )
{
Container pack = from.Backpack;
if ( Parent == from || ( pack != null && Parent == pack ) )
DisplayTo( from );
else
from.SendLocalizedMessage( 500207 ); // The spellbook must be in your backpack (and not in a container within) to open.
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 2 ); // version
writer.Write( (int) m_Quality );
writer.Write( (Mobile) m_Crafter );
writer.Write( m_Content );
writer.Write( m_Count );
//New Code
m_AosAttributes.Serialize( writer );
m_AosSkillBonuses.Serialize( writer );
//End New Code
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
LootType = LootType.Blessed;
int version = reader.ReadInt();
switch ( version )
{
case 0:
{
m_Content = reader.ReadULong();
m_Count = reader.ReadInt();
m_AosAttributes = new AosAttributes( this );
m_AosSkillBonuses = new AosSkillBonuses( this );
break;
}
case 1:
{
m_AosAttributes = new AosAttributes( this, reader );
m_AosSkillBonuses = new AosSkillBonuses( this, reader );
if ( Core.AOS && Parent is Mobile )
m_AosSkillBonuses.AddTo( (Mobile)Parent );
int strBonus = m_AosAttributes.BonusStr;
int dexBonus = m_AosAttributes.BonusDex;
int intBonus = m_AosAttributes.BonusInt;
if ( Parent is Mobile && (strBonus != 0 || dexBonus != 0 || intBonus != 0) )
{
Mobile m = (Mobile)Parent;
string modName = Serial.ToString();
if ( strBonus != 0 )
m.AddStatMod( new StatMod( StatType.Str, modName + "Str", strBonus, TimeSpan.Zero ) );
if ( dexBonus != 0 )
m.AddStatMod( new StatMod( StatType.Dex, modName + "Dex", dexBonus, TimeSpan.Zero ) );
if ( intBonus != 0 )
m.AddStatMod( new StatMod( StatType.Int, modName + "Int", intBonus, TimeSpan.Zero ) );
}
if ( Parent is Mobile )
((Mobile)Parent).CheckStatTimers();
m_Content = reader.ReadULong();
m_Count = reader.ReadInt();
break;
}
case 2:
{
m_Quality = (SpellbookQuality)reader.ReadInt();
m_Crafter = reader.ReadMobile();
goto case 1;
}
}
}
public int OnCraft( int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool, CraftItem craftItem, int resHue )
{
Quality = (SpellbookQuality)quality;
if( Quality == SpellbookQuality.Exceptional )
{
BaseRunicTool.ApplyAttributesTo( this, Utility.Random( 0, 4), 1,6 );
}
if ( makersMark )
Crafter = from;
return quality;
}
}
}
|
|
|
|
|
|
#7 (permalink) |
|
Forum Expert
Join Date: Mar 2003
Location: where I belong
Posts: 1,786
|
That serialization and deserialization needs to completely rewritten. You have to serialize and deserialize in the exact same order. See if you can learn anything from the way the PlayerMobile class serializes.
And please post in code, not quotes.
__________________
"Misfortune shows those who are not really friends." -Aristotle "A multitude of words is no proof of a prudent mind." -Thales |
|
|
|
|
|
#8 (permalink) | |
|
Forum Novice
|
Quote:
and I edited it to be in code. It skipped my mind. |
|
|
|
|
|
|
#10 (permalink) |
|
Forum Novice
|
Okay its been a while and I still can't fix this problem. it's not just spellbooks, I've learned. its every kind of spellbook, be it necro, chivalry, etc.
And when I compare them to the original scripts, they are exactly the same aside from the spellbook.cs I posted in this thread. And, I don't understand scripting, so will someone help me with what the last comment meant? I tried looking for what they meant, but am in the dark. again, thanks in advance if you can help. |
|
|
|
|
|
#11 (permalink) | |
|
Account Terminated
|
Quote:
You need to follow Lysdexic's advice to fix your problem. I am not going to do it for you, your going to have to figure it out, I am only here for advice. |
|
|
|
|
|
|
#13 (permalink) | |
|
Forum Novice
|
Okay, I did what I could through reading that, now I get the error of :
Quote:
Code:
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
LootType = LootType.Blessed;
int version = reader.ReadInt();
switch ( version )
{
case 2:
{
m_Quality = (SpellbookQuality)reader.ReadInt();
m_Crafter = reader.ReadMobile();
goto case 1;
}
case 1:
{
Mobile m = (Mobile)Parent;
string modName = Serial.ToString();
if ( strBonus != 0 )
m.AddStatMod( new StatMod( StatType.Str, modName + "Str", strBonus, TimeSpan.Zero ) );
if ( dexBonus != 0 )
m.AddStatMod( new StatMod( StatType.Dex, modName + "Dex", dexBonus, TimeSpan.Zero ) );
if ( intBonus != 0 )
m.AddStatMod( new StatMod( StatType.Int, modName + "Int", intBonus, TimeSpan.Zero ) );
goto case 0;
}
case 0:
{
m_Content = reader.ReadULong();
m_Count = reader.ReadInt();
m_AosAttributes = new AosAttributes( this );
m_AosSkillBonuses = new AosSkillBonuses( this );
}
{
m_AosAttributes = new AosAttributes( this, reader );
m_AosSkillBonuses = new AosSkillBonuses( this, reader );
if ( Core.AOS && Parent is Mobile )
m_AosSkillBonuses.AddTo( (Mobile)Parent );
int strBonus = m_AosAttributes.BonusStr;
int dexBonus = m_AosAttributes.BonusDex;
int intBonus = m_AosAttributes.BonusInt;
if ( Parent is Mobile && (strBonus != 0 || dexBonus != 0 || intBonus != 0) )
if ( Parent is Mobile )
((Mobile)Parent).CheckStatTimers();
m_Content = reader.ReadULong();
m_Count = reader.ReadInt();
break;
}
}
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|