RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Druidic Spells Final-all 16 spells - updated 6th Jan 04

Status
Not open for further replies.

Voran

Wanderer
You need to use the already posted modification to SpellRegistry.cs
[code:1]using System;

namespace Server.Spells
{
public class SpellRegistry
{
private static Type[] m_Types = new Type[500];
private static int m_Count;

public static Type[] Types
{
get
{
m_Count = -1;
return m_Types;
}
}

public static int Count
{
get
{
if ( m_Count == -1 )
{
m_Count = 0;

for ( int i = 0; i < 64; ++i )
{
if ( m_Types != null )
++m_Count;
}
}

return m_Count;
}
}

public static void Register( int spellID, Type type )
{
if ( spellID < 0 || spellID >= m_Types.Length )
return;

if ( m_Types[spellID] == null )
++m_Count;

m_Types[spellID] = type;
}

private static object[] m_Params = new object[2];

public static Spell NewSpell( int spellID, Mobile caster, Item scroll )
{
if ( spellID < 0 || spellID >= m_Types.Length )
return null;

Type t = m_Types[spellID];

if ( t == null )
return null;

m_Params[0] = caster;
m_Params[1] = scroll;

return (Spell)Activator.CreateInstance( t, m_Params );
}

private static string[] m_CircleNames = new string[]
{
"First",
"Second",
"Third",
"Fourth",
"Fifth",
"Sixth",
"Seventh",
"Eighth",
"Necromancy",
"Chivalry"
};

public static Spell NewSpell( string name, Mobile caster, Item scroll )
{
for ( int i = 0; i < m_CircleNames.Length; ++i )
{
Type t = ScriptCompiler.FindTypeByFullName( String.Format( "Server.Spells.{0}.{1}", m_CircleNames, name ) );

if ( t != null )
{
m_Params[0] = caster;
m_Params[1] = scroll;

try
{
return (Spell)Activator.CreateInstance( t, m_Params );
}
catch
{
}
}
}

return null;
}
}
}
[/code:1]
 

Etalicus

Sorceror
i got a small question
i got your system and i like and so do the players i tied it to our class system but im having issues with the scrolls
[code:1]////////////////////////////////////////////Set Up for Classes
public override void OnDoubleClick( Mobile from )
{
if ( !IsChildOf( from.Backpack ) )
{
from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it.
}

else if ( ((PlayerMobile)from).Classe != ClasseType.Druid )
{
from.SendMessage( "You don't seem to understand this Scroll." );
}
////////////////////////////////////////////[/code:1]

it keep you from casting the scroll unless your part of the class but i cant seem to fig the proper return so it will cast if you are the proper class
 

Horde_Pil

Wanderer
ok,

i know this script(that i am giving here) is no big deal, but i just figured someone else might want it.. i am working the bugs out of it, and yes it does work.. only have a problem with some of the spells actually finishing the casting, thats about it and i know it sux but i just started editing this thing and its my first mod to an AI so no flames..

DruidAI.cs

[code:1]
using System;
using System.Collections;
using Server.Targeting;
using Server.Network;
using Server.Mobiles;
using Server.Items;
using Server.Spells;
using Server.Spells.First;
using Server.Spells.Second;
using Server.Spells.Third;
using Server.Spells.Fourth;
using Server.Spells.Fifth;
using Server.Spells.Sixth;
using Server.Spells.Seventh;
using Server.Spells.Druid;
using Server.Misc;
using Server.Regions;
using Server.SkillHandlers;

namespace Server.Mobiles
{
public class DruidAI : BaseAI
{
private DateTime m_NextCastTime;

public DruidAI( BaseCreature m ) : base( m )
{
}

public override bool Think()
{
if ( m_Mobile.Deleted )
return false;

Target targ = m_Mobile.Target;

if ( targ != null )
{
ProcessTarget( targ );

return true;
}
else
{
return base.Think();
}
}

public virtual bool SmartAI
{
get{ return ( m_Mobile is BaseVendor || m_Mobile is BaseEscortable ); }
}

private const double HealChance = 0.10; // 10% chance to heal at gm AnimalLore
private const double TeleportChance = 0.05; // 5% chance to teleport at gm AnimalLore
private const double DispelChance = 0.75; // 75% chance to dispel at gm AnimalLore

public virtual double ScaleByAnimalLore( double v )
{
return m_Mobile.Skills[SkillName.AnimalLore].Value * v * 0.01;
}

public override bool DoActionWander()
{
if ( AquireFocusMob( m_Mobile.RangePerception, m_Mobile.FightMode, false, false, true ) )
{
m_Mobile.DebugSay( "I am going to attack {0}", m_Mobile.FocusMob.Name );

m_Mobile.Combatant = m_Mobile.FocusMob;
Action = ActionType.Combat;
m_NextCastTime = DateTime.Now;
}
else if ( SmartAI && m_Mobile.Mana < m_Mobile.ManaMax )
{
m_Mobile.DebugSay( "I am going to meditate" );

m_Mobile.UseSkill( SkillName.Meditation );
}
else
{
m_Mobile.DebugSay( "I am wandering" );

m_Mobile.Warmode = false;

base.DoActionWander();

if ( m_Mobile.Poisoned )
{
new CureSpell( m_Mobile, null ).Cast();
}
else if ( !m_Mobile.Summoned && (SmartAI || (ScaleByAnimalLore( HealChance ) > Utility.RandomDouble())) )
{
if ( m_Mobile.Hits < (m_Mobile.HitsMax - 50) )
{
if ( !new RestorativeSoilSpell( m_Mobile, null ).Cast() )
new SpringOfLifeSpell( m_Mobile, null ).Cast();
}
else if ( m_Mobile.Hits < (m_Mobile.HitsMax - 10) )
{
new SpringOfLifeSpell( m_Mobile, null ).Cast();
}
}
}

return true;
}

public void RunTo( Mobile m )
{
if ( !SmartAI )
{
if ( !MoveTo( m, true, m_Mobile.RangeFight ) )
OnFailedMove();

return;
}

if ( m.Paralyzed || m.Frozen )
{
if ( m_Mobile.InRange( m, 1 ) )
RunFrom( m );
else if ( !m_Mobile.InRange( m, m_Mobile.RangeFight > 2 ? m_Mobile.RangeFight : 2 ) && !MoveTo( m, true, 1 ) )
OnFailedMove();
}
else
{
if ( !m_Mobile.InRange( m, m_Mobile.RangeFight ) )
{
if ( !MoveTo( m, true, 1 ) )
OnFailedMove();
}
else if ( m_Mobile.InRange( m, m_Mobile.RangeFight - 1 ) )
{
RunFrom( m );
}
}
}

public void RunFrom( Mobile m )
{
Run( (m_Mobile.GetDirectionTo( m ) - 4) & Direction.Mask );
}

public void OnFailedMove()
{
if ( !m_Mobile.DisallowAllMoves && (SmartAI ? Utility.Random( 4 ) == 0 : ScaleByAnimalLore( TeleportChance ) > Utility.RandomDouble()) )
{
if ( m_Mobile.Target != null )
m_Mobile.Target.Cancel( m_Mobile, TargetCancelType.Canceled );

new TeleportSpell( m_Mobile, null ).Cast();

m_Mobile.DebugSay( "I am stuck, I'm going to try teleporting away" );
}
else if ( AquireFocusMob( m_Mobile.RangePerception, m_Mobile.FightMode, false, false, true ) )
{
m_Mobile.DebugSay( "My move is blocked, so I am going to attack {0}", m_Mobile.FocusMob.Name );

m_Mobile.Combatant = m_Mobile.FocusMob;
Action = ActionType.Combat;
}
else
{
m_Mobile.DebugSay( "I am stuck" );
}
}

public void Run( Direction d )
{
if ( (m_Mobile.Spell != null && m_Mobile.Spell.IsCasting) || m_Mobile.Paralyzed || m_Mobile.Frozen || m_Mobile.DisallowAllMoves )
return;

m_Mobile.Direction = d | Direction.Running;

if ( !DoMove( m_Mobile.Direction ) )
OnFailedMove();
}

public virtual Spell GetRandomDamageSpell()
{
int maxCircle = (int)((m_Mobile.Skills[SkillName.AnimalLore].Value + 20.0) / (100.0 / 7.0));

if ( maxCircle < 1 )
maxCircle = 1;

switch ( Utility.Random( maxCircle*2 ) )
{
case 0: case 1: return new PackOfBeastSpell( m_Mobile, null );
case 2: case 3: return new SwarmOfInsectsSpell( m_Mobile, null );
case 4: case 5: return new GraspingRootsSpell( m_Mobile, null );
case 6: case 7: return new TreefellowSpell( m_Mobile, null );
case 8: case 9: return new StoneCircleSpell( m_Mobile, null );
case 10: return new BlendWithForestSpell( m_Mobile, null );
case 11: return new StoneCircleSpell( m_Mobile, null );
default: return new VolcanicEruptionSpell( m_Mobile, null );
}
}

public virtual Spell DoDispel( Mobile toDispel )
{
if ( !SmartAI )
{
if ( ScaleByAnimalLore( DispelChance ) > Utility.RandomDouble() )
return new DispelSpell( m_Mobile, null );

return ChooseSpell( toDispel );
}

Spell spell = null;

if ( !m_Mobile.Summoned && Utility.Random( 0, 4 + (m_Mobile.Hits == 0 ? m_Mobile.HitsMax : (m_Mobile.HitsMax / m_Mobile.Hits)) ) >= 3 )
{
if ( m_Mobile.Hits < (m_Mobile.HitsMax - 50) )
spell = new RestorativeSoilSpell( m_Mobile, null );
else if ( m_Mobile.Hits < (m_Mobile.HitsMax - 20) )
spell = new SpringOfLifeSpell( m_Mobile, null );
}

if ( spell == null )
{
if ( !m_Mobile.DisallowAllMoves && Utility.Random( (int)m_Mobile.GetDistanceToSqrt( toDispel ) ) == 0 )
spell = new TeleportSpell( m_Mobile, null );
else if ( Utility.Random( 3 ) == 0 && !m_Mobile.InRange( toDispel, 3 ) && !toDispel.Paralyzed && !toDispel.Frozen )
spell = new ParalyzeSpell( m_Mobile, null );
else
spell = new DispelSpell( m_Mobile, null );
}

return spell;
}

public virtual Spell ChooseSpell( Mobile c )
{
if ( !SmartAI )
{
if ( !m_Mobile.Summoned && ScaleByAnimalLore( HealChance ) > Utility.RandomDouble() )
{
if ( m_Mobile.Hits < (m_Mobile.HitsMax - 50) )
return new RestorativeSoilSpell( m_Mobile, null );
else if ( m_Mobile.Hits < (m_Mobile.HitsMax - 10) )
return new SpringOfLifeSpell( m_Mobile, null );
}

return GetRandomDamageSpell();
}

Spell spell = null;

int healChance = (m_Mobile.Hits == 0 ? m_Mobile.HitsMax : (m_Mobile.HitsMax / m_Mobile.Hits));

if ( m_Mobile.Summoned )
healChance = 0;

switch ( Utility.Random( 4 + healChance ) )
{
default:
case 0: // Heal ourself
{
if ( !m_Mobile.Summoned )
{
if ( m_Mobile.Hits < (m_Mobile.HitsMax - 50) )
spell = new GreaterHealSpell( m_Mobile, null );
else if ( m_Mobile.Hits < (m_Mobile.HitsMax - 10) )
spell = new HealSpell( m_Mobile, null );
}

break;
}
case 1: // Poison them
{
if ( !c.Poisoned )
spell = new PoisonSpell( m_Mobile, null );

break;
}
case 2: // Deal some damage
{
spell = GetRandomDamageSpell();

break;
}
case 3: // Set up a combo
{
if ( m_Mobile.Mana < 40 && m_Mobile.Mana > 15 )
{
if ( c.Paralyzed && !c.Poisoned )
{
m_Mobile.DebugSay( "I am going to meditate" );

m_Mobile.UseSkill( SkillName.Meditation );
}
else if ( !c.Poisoned )
{
spell = new ParalyzeSpell( m_Mobile, null );
}
}
else if ( m_Mobile.Mana > 60 )
{
if ( Utility.Random( 2 ) == 0 && !c.Paralyzed && !c.Frozen && !c.Poisoned )
{
m_Combo = 0;
spell = new ParalyzeSpell( m_Mobile, null );
}
else
{
m_Combo = 1;
spell = new ExplosionSpell( m_Mobile, null );
}
}

break;
}
}

return spell;
}

protected int m_Combo = -1;

public virtual Spell DoCombo( Mobile c )
{
Spell spell = null;

if ( m_Combo == 0 )
{
spell = new ExplosionSpell( m_Mobile, null );
++m_Combo; // Move to next spell
}
else if ( m_Combo == 1 )
{
spell = new WeakenSpell( m_Mobile, null );
++m_Combo; // Move to next spell
}
else if ( m_Combo == 2 )
{
if ( !c.Poisoned )
spell = new PoisonSpell( m_Mobile, null );

++m_Combo; // Move to next spell
}

if ( m_Combo == 3 && spell == null )
{
switch ( Utility.Random( 3 ) )
{
default:
case 0:
{
if ( c.Int < c.Dex )
spell = new FeeblemindSpell( m_Mobile, null );
else
spell = new ClumsySpell( m_Mobile, null );

++m_Combo; // Move to next spell

break;
}
case 1:
{
spell = new EnergyBoltSpell( m_Mobile, null );
m_Combo = -1; // Reset combo state
break;
}
case 2:
{
spell = new FlameStrikeSpell( m_Mobile, null );
m_Combo = -1; // Reset combo state
break;
}
}
}
else if ( m_Combo == 4 && spell == null )
{
spell = new MindBlastSpell( m_Mobile, null );
m_Combo = -1;
}

return spell;
}

public override bool DoActionCombat()
{
Mobile c = m_Mobile.Combatant;
m_Mobile.Warmode = true;

if ( c == null || c.Deleted || !c.Alive || !m_Mobile.CanSee( c ) || !m_Mobile.CanBeHarmful( c, false ) || c.Map != m_Mobile.Map )
{
// Our combatant is deleted, dead, hidden, or we cannot hurt them
// Try to find another combatant

if ( AquireFocusMob( m_Mobile.RangePerception, m_Mobile.FightMode, false, false, true ) )
{
m_Mobile.DebugSay( "Something happened to my combatant, so I am going to fight {0}", m_Mobile.FocusMob.Name );

m_Mobile.Combatant = c = m_Mobile.FocusMob;
m_Mobile.FocusMob = null;
}
else
{
m_Mobile.DebugSay( "Something happened to my combatant, and nothing is around. I am on guard." );
Action = ActionType.Guard;
return true;
}
}

if ( !m_Mobile.InLOS( c ) )
{
if ( AquireFocusMob( m_Mobile.RangePerception, m_Mobile.FightMode, false, false, true ) )
{
m_Mobile.Combatant = c = m_Mobile.FocusMob;
m_Mobile.FocusMob = null;
}
}

if ( SmartAI && !m_Mobile.StunReady && m_Mobile.Skills[SkillName.Wrestling].Value >= 80.0 && m_Mobile.Skills[SkillName.Anatomy].Value >= 80.0 )
EventSink.InvokeStunRequest( new StunRequestEventArgs( m_Mobile ) );

if ( !m_Mobile.InRange( c, m_Mobile.RangePerception ) )
{
// They are somewhat far away, can we find something else?

if ( AquireFocusMob( m_Mobile.RangePerception, m_Mobile.FightMode, false, false, true ) )
{
m_Mobile.Combatant = m_Mobile.FocusMob;
m_Mobile.FocusMob = null;
}
else if ( !m_Mobile.InRange( c, m_Mobile.RangePerception * 3 ) )
{
m_Mobile.Combatant = null;
}

c = m_Mobile.Combatant;

if ( c == null )
{
m_Mobile.DebugSay( "My combatant has fled, so I am on guard" );
Action = ActionType.Guard;

return true;
}
}

if ( !m_Mobile.Controled && !m_Mobile.Summoned )
{
if ( m_Mobile.Hits < m_Mobile.HitsMax * 20/100 )
{
// We are low on health, should we flee?

bool flee = false;

if ( m_Mobile.Hits < c.Hits )
{
// We are more hurt than them

int diff = c.Hits - m_Mobile.Hits;

flee = ( Utility.Random( 0, 100 ) > (10 + diff) ); // (10 + diff)% chance to flee
}
else
{
flee = Utility.Random( 0, 100 ) > 10; // 10% chance to flee
}

if ( flee )
{
m_Mobile.DebugSay( "I am going to flee from {0}", c.Name );
Action = ActionType.Flee;
return true;
}
}
}

if ( m_Mobile.Spell == null && DateTime.Now > m_NextCastTime && m_Mobile.InRange( c, 12 ) )
{
// We are ready to cast a spell

Spell spell = null;
Mobile toDispel = FindDispelTarget( true );

if ( m_Mobile.Poisoned ) // Top cast priority is cure
{
spell = new CureSpell( m_Mobile, null );
}
else if ( toDispel != null ) // Something dispellable is attacking us
{
spell = DoDispel( toDispel );
}
else if ( SmartAI && m_Combo != -1 ) // We are doing a spell combo
{
spell = DoCombo( c );
}
else if ( SmartAI && (c.Spell is HealSpell || c.Spell is GreaterHealSpell) && !c.Poisoned ) // They have a heal spell out
{
spell = new PoisonSpell( m_Mobile, null );
}
else
{
spell = ChooseSpell( c );
}

// Now we have a spell picked
// Move first before casting

if ( SmartAI && toDispel != null )
{
if ( m_Mobile.InRange( toDispel, 10 ) )
RunFrom( toDispel );
else if ( !m_Mobile.InRange( toDispel, 12 ) )
RunTo( toDispel );
}
else
{
RunTo( c );
}

if ( spell != null && spell.Cast() )
{
TimeSpan delay;

if ( SmartAI || ( spell is DispelSpell ) )
{
delay = TimeSpan.FromSeconds( m_Mobile.ActiveSpeed );
}
else
{
double del = ScaleByAnimalLore( 3.0 );
double min = 6.0 - (del * 0.75);
double max = 6.0 - (del * 1.25);

delay = TimeSpan.FromSeconds( min + ((max - min) * Utility.RandomDouble()) );
}

m_NextCastTime = DateTime.Now + delay;
}
}
else if ( m_Mobile.Spell == null || !m_Mobile.Spell.IsCasting )
{
RunTo( c );
}

return true;
}

public override bool DoActionGuard()
{
if ( AquireFocusMob( m_Mobile.RangePerception, m_Mobile.FightMode, false, false, true ) )
{
m_Mobile.DebugSay( "I am going to attack {0}", m_Mobile.FocusMob.Name );
m_Mobile.Combatant = m_Mobile.FocusMob;
Action = ActionType.Combat;
}
else
{
if ( m_Mobile.Poisoned )
{
new CureSpell( m_Mobile, null ).Cast();
}
else if ( !m_Mobile.Summoned && (SmartAI || (ScaleByAnimalLore( HealChance ) > Utility.RandomDouble())) )
{
if ( m_Mobile.Hits < (m_Mobile.HitsMax - 50) )
{
if ( !new GreaterHealSpell( m_Mobile, null ).Cast() )
new HealSpell( m_Mobile, null ).Cast();
}
else if ( m_Mobile.Hits < (m_Mobile.HitsMax - 10) )
{
new HealSpell( m_Mobile, null ).Cast();
}
else
{
base.DoActionGuard();
}
}
else
{
base.DoActionGuard();
}
}

return true;
}

public override bool DoActionFlee()
{
Mobile c = m_Mobile.Combatant;

if ( (m_Mobile.Mana > 20 || m_Mobile.Mana == m_Mobile.ManaMax) && m_Mobile.Hits > (m_Mobile.HitsMax / 2) )
{
m_Mobile.DebugSay( "I am stronger now, my guard is up" );
Action = ActionType.Guard;
}
else if ( AquireFocusMob( m_Mobile.RangePerception, m_Mobile.FightMode, false, false, true ) )
{
m_Mobile.DebugSay( "I am scared of {0}", m_Mobile.FocusMob.Name );

RunFrom( m_Mobile.FocusMob );
m_Mobile.FocusMob = null;

if ( m_Mobile.Poisoned && Utility.Random( 0, 5 ) == 0 )
new CureSpell( m_Mobile, null ).Cast();
}
else
{
m_Mobile.DebugSay( "Area seems clear, but my guard is up" );

Action = ActionType.Guard;
m_Mobile.Warmode = true;
}

return true;
}

public Mobile FindDispelTarget( bool activeOnly )
{
if ( m_Mobile.Deleted || m_Mobile.Int < 95 || CanDispel( m_Mobile ) || m_Mobile.AutoDispel )
return null;

if ( activeOnly )
{
ArrayList aggressed = m_Mobile.Aggressed;
ArrayList aggressors = m_Mobile.Aggressors;

Mobile active = null;
double activePrio = 0.0;

Mobile comb = m_Mobile.Combatant;

if ( comb != null && !comb.Deleted && m_Mobile.InRange( comb, 12 ) && CanDispel( comb ) )
{
active = comb;
activePrio = m_Mobile.GetDistanceToSqrt( comb );

if ( activePrio <= 2 )
return active;
}

for ( int i = 0; i < aggressed.Count; ++i )
{
AggressorInfo info = (AggressorInfo)aggressed;
Mobile m = (Mobile)info.Defender;

if ( m != comb && m.Combatant == m_Mobile && m_Mobile.InRange( m, 12 ) && CanDispel( m ) )
{
double prio = m_Mobile.GetDistanceToSqrt( m );

if ( active == null || prio < activePrio )
{
active = m;
activePrio = prio;

if ( activePrio <= 2 )
return active;
}
}
}

for ( int i = 0; i < aggressors.Count; ++i )
{
AggressorInfo info = (AggressorInfo)aggressors;
Mobile m = (Mobile)info.Attacker;

if ( m != comb && m.Combatant == m_Mobile && m_Mobile.InRange( m, 12 ) && CanDispel( m ) )
{
double prio = m_Mobile.GetDistanceToSqrt( m );

if ( active == null || prio < activePrio )
{
active = m;
activePrio = prio;

if ( activePrio <= 2 )
return active;
}
}
}

return active;
}
else
{
Map map = m_Mobile.Map;

if ( map != null )
{
Mobile active = null, inactive = null;
double actPrio = 0.0, inactPrio = 0.0;

Mobile comb = m_Mobile.Combatant;

if ( comb != null && !comb.Deleted && CanDispel( comb ) )
{
active = inactive = comb;
actPrio = inactPrio = m_Mobile.GetDistanceToSqrt( comb );
}

foreach ( Mobile m in m_Mobile.GetMobilesInRange( 12 ) )
{
if ( m != m_Mobile && CanDispel( m ) )
{
double prio = m_Mobile.GetDistanceToSqrt( m );

if ( !activeOnly && (inactive == null || prio < inactPrio) )
{
inactive = m;
inactPrio = prio;
}

if ( (m_Mobile.Combatant == m || m.Combatant == m_Mobile) && (active == null || prio < actPrio) )
{
active = m;
actPrio = prio;
}
}
}

return active != null ? active : inactive;
}
}

return null;
}

public bool CanDispel( Mobile m )
{
return ( m is BaseCreature && ((BaseCreature)m).Summoned && m_Mobile.CanBeHarmful( m, false ) && !((BaseCreature)m).IsAnimatedDead );
}

private static int[] m_Offsets = new int[]
{
-1, -1,
-1, 0,
-1, 1,
0, -1,
0, 1,
1, -1,
1, 0,
1, 1,

-2, -2,
-2, -1,
-2, 0,
-2, 1,
-2, 2,
-1, -2,
-1, 2,
0, -2,
0, 2,
1, -2,
1, 2,
2, -2,
2, -1,
2, 0,
2, 1,
2, 2
};

private void ProcessTarget( Target targ )
{
bool isDispel = ( targ is DispelSpell.InternalTarget );
bool isParalyze = ( targ is ParalyzeSpell.InternalTarget );
bool isTeleport = ( targ is TeleportSpell.InternalTarget );
bool teleportAway = false;

Mobile toTarget;

if ( isDispel )
{
toTarget = FindDispelTarget( false );

if ( !SmartAI && toTarget != null )
RunTo( toTarget );
else if ( toTarget != null && m_Mobile.InRange( toTarget, 10 ) )
RunFrom( toTarget );
}
else if ( SmartAI && (isParalyze || isTeleport) )
{
toTarget = FindDispelTarget( true );

if ( toTarget == null )
{
toTarget = m_Mobile.Combatant;

if ( toTarget != null )
RunTo( toTarget );
}
else if ( m_Mobile.InRange( toTarget, 10 ) )
{
RunFrom( toTarget );
teleportAway = true;
}
else
{
teleportAway = true;
}
}
else
{
toTarget = m_Mobile.Combatant;

if ( toTarget != null )
RunTo( toTarget );
}

if ( (targ.Flags & TargetFlags.Harmful) != 0 && toTarget != null )
{
if ( (targ.Range == -1 || m_Mobile.InRange( toTarget, targ.Range )) && m_Mobile.CanSee( toTarget ) && m_Mobile.InLOS( toTarget ) )
{
targ.Invoke( m_Mobile, toTarget );
}
else if ( isDispel )
{
targ.Cancel( m_Mobile, TargetCancelType.Canceled );
}
}
else if ( (targ.Flags & TargetFlags.Beneficial) != 0 )
{
targ.Invoke( m_Mobile, m_Mobile );
}
else if ( isTeleport && toTarget != null )
{
Map map = m_Mobile.Map;

if ( map == null )
{
targ.Cancel( m_Mobile, TargetCancelType.Canceled );
return;
}

int px, py;

if ( teleportAway )
{
int rx = m_Mobile.X - toTarget.X;
int ry = m_Mobile.Y - toTarget.Y;

double d = m_Mobile.GetDistanceToSqrt( toTarget );

px = toTarget.X + (int)(rx * (10 / d));
py = toTarget.Y + (int)(ry * (10 / d));
}
else
{
px = toTarget.X;
py = toTarget.Y;
}

for ( int i = 0; i < m_Offsets.Length; i += 2 )
{
int x = m_Offsets, y = m_Offsets[i + 1];

Point3D p = new Point3D( px + x, py + y, 0 );

LandTarget lt = new LandTarget( p, map );

if ( (targ.Range == -1 || m_Mobile.InRange( p, targ.Range )) && m_Mobile.InLOS( lt ) && map.CanSpawnMobile( px + x, py + y, lt.Z ) && !SpellHelper.CheckMulti( p, map ) )
{
targ.Invoke( m_Mobile, lt );
return;
}
}

int teleRange = targ.Range;

if ( teleRange < 0 )
teleRange = 12;

for ( int i = 0; i < 10; ++i )
{
Point3D randomPoint = new Point3D( m_Mobile.X - teleRange + Utility.Random( teleRange * 2 + 1 ), m_Mobile.Y - teleRange + Utility.Random( teleRange * 2 + 1 ), 0 );

LandTarget lt = new LandTarget( randomPoint, map );

if ( m_Mobile.InLOS( lt ) && map.CanSpawnMobile( lt.X, lt.Y, lt.Z ) && !SpellHelper.CheckMulti( randomPoint, map ) )
{
targ.Invoke( m_Mobile, new LandTarget( randomPoint, map ) );
return;
}
}

targ.Cancel( m_Mobile, TargetCancelType.Canceled );
}
else
{
targ.Cancel( m_Mobile, TargetCancelType.Canceled );
}
}
}
}
[/code:1]
 

Dramakus

Wanderer
Here is my Initializer.cs snidbit on druid.

[code:1] // Druid Spells
Register( 301, typeof( Druid.SheildOfEarthSpell ) );
Register( 302, typeof( Druid.HollowReedSpell ) );
Register( 303, typeof( Druid.PackOfBeastSpell ) );
Register( 304, typeof( Druid.SpringOfLifeSpell ) );
Register( 305, typeof( Druid.GraspingRootsSpell ) );
Register( 306, typeof( Druid.BlendWithForestSpell ) );
Register( 307, typeof( Druid.SwarmOfInsectsSpell ) );
Register( 308, typeof( Druid.VolcanicEruptionSpell ) );
Register( 309, typeof( Druid.TreefellowSpell ) );
Register( 310, typeof( Druid.StoneCircleSpell ) );
Register( 311, typeof( Druid.EnchantedGroveSpell ) );
Register( 312, typeof( Druid.LureStoneSpell ) );
Register( 313, typeof( Druid.NaturesPassageSpell ) );
Register( 314, typeof( Druid.MushroomGatewaySpell ) );
Register( 315, typeof( Druid.RestorativeSoilSpell ) );
Register( 316, typeof( Druid.FireflySpell ) );[/code:1]


[code:1]Heres my spellregistry.cs

using System;

namespace Server.Spells
{
public class SpellRegistry
{
private static Type[] m_Types = new Type[500];
private static int m_Count;

public static Type[] Types
{
get
{
m_Count = -1;
return m_Types;
}
}

public static int Count
{
get
{
if ( m_Count == -1 )
{
m_Count = 0;

for ( int i = 0; i < 64; ++i )
{
if ( m_Types != null )
++m_Count;
}
}

return m_Count;
}
}

public static void Register( int spellID, Type type )
{
if ( spellID < 0 || spellID >= m_Types.Length )
return;

if ( m_Types[spellID] == null )
++m_Count;

m_Types[spellID] = type;
}

private static object[] m_Params = new object[2];

public static Spell NewSpell( int spellID, Mobile caster, Item scroll )
{
if ( spellID < 0 || spellID >= m_Types.Length )
return null;

Type t = m_Types[spellID];

if ( t == null )
return null;

m_Params[0] = caster;
m_Params[1] = scroll;

return (Spell)Activator.CreateInstance( t, m_Params );
}

private static string[] m_CircleNames = new string[]
{
"First",
"Second",
"Third",
"Fourth",
"Fifth",
"Sixth",
"Seventh",
"Eighth",
"Necromancy",
"Chivalry"
};

public static Spell NewSpell( string name, Mobile caster, Item scroll )
{
for ( int i = 0; i < m_CircleNames.Length; ++i )
{
Type t = ScriptCompiler.FindTypeByFullName( String.Format( "Server.Spells.{0}.{1}", m_CircleNames, name ) );

if ( t != null )
{
m_Params[0] = caster;
m_Params[1] = scroll;

try
{
return (Spell)Activator.CreateInstance( t, m_Params );
}
catch
{
}
}
}

return null;
}
}
}[/code:1]

and i have the druid spellbook registered. even if i use the fill spellbook command it shows up as full but when i open it its completely blank.
 

habitat85

Wanderer
Dont know why every post I posted in the last couple days got deleted but...

I cant get the [allspells to work on this and dropping scrolls on the book isnt working either.
 

habitat85

Wanderer
Yes, Im not using the one that was with the old scripts because I cant find those but I did edit the spellbook.cs
Heres my spellbook.cs, Maybe I did something wrong

[code:1]using System;
using System.Collections;
using Server;
using Server.Targeting;
using Server.Network;
using Server.Spells;
using Server.Scripts.Commands;

namespace Server.Items
{
public enum SpellbookType
{
Invalid = -1,
Regular,
Necromancer,
Paladin,
Druidic
}

public class Spellbook : Item
{
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.Druidic; 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 >= 301 && spellID < 317 )
return SpellbookType.Paladin;

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 FindDruid( Mobile from )
{
return Find( from, -1, SpellbookType.Druidic );
}

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;

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;

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;

public override bool AllowEquipedCast( Mobile from )
{
return true;
}

public override Item Dupe( int amount )
{
Spellbook book = new Spellbook();

book.Content = this.Content;

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;
}
}

[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;

Content = content;
}

public bool HasSpell( int spellID )
{
spellID -= BookOffset;

return ( spellID >= 0 && spellID < BookCount && (m_Content & ((ulong)1 << spellID)) != 0 );
}

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 false; } }

public override void GetProperties( ObjectPropertyList list )
{
base.GetProperties( list );

list.Add( 1042886, m_Count.ToString() ); // ~1_NUMBERS_OF_SPELLS~ Spells
}

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) 0 ); // version

writer.Write( m_Content );
writer.Write( m_Count );
}

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();

break;
}
}
}
}
}[/code:1]
 
Well i got it to work.. WooHOoo! but one problem, My druid spell book says that i have 0-16 spells but it still shows allt he spells there. EX. if my Druid book has 0 spells. It still has all the spells listed for you to cast.. not like its a problem but could you remove the -0 spells- even though i really ahve all the spells.
 

Zdravo

Wanderer
hello,
I have this error message : 'Server.Spells.Reagent' does not contain definition for :
- PetrafiedWood
- SpringWater
- DestroyingAngel

I must to add in Reagent.cs but how ? :eek:

thank :)

edit : LoL I found :eek:
 
Is there any type of vendor that has all the Regs.. and the druid book ? ANy script? Becasue i saw one a second ago.. but ( SBDruid) it doesn't Create in my shard..
 

Voran

Wanderer
Sorry, my bad: dridvendor, not druid. It's one of the scripts from the original druidspells package. if you have the SBDruid, you logically must have DruidVendor
 
Status
Not open for further replies.
Top