siran
Sorceror
First of all, all scripts compile and there is no crash. If I attack a creature (doesn't matter what kind, I'm currently testing with a Mongbat), the creature fights and does damage to me but my character just stands there, in war mode, doing nothing. Changing weapons makes no difference, but if I have no weapon (wrestling with fists) then I do fight back.
One little curve, if I save the game while in war mode against a combatant, when I reboot the server my character DOES fight back with his weapon. But the next combatant he again does not.
Here are the relevant sections of my BaseWeapon script, and when I add attacker.SendMessage lines and defender.SendMessage lines in the OnHit, CheckHit, and OnSwing methods, only the defender messages appear when the problem is happening. After a save & reboot, both attacker & defender messages appear until the combatant is dead then for the next combatant only defneder messages appear again.
One little curve, if I save the game while in war mode against a combatant, when I reboot the server my character DOES fight back with his weapon. But the next combatant he again does not.
Here are the relevant sections of my BaseWeapon script, and when I add attacker.SendMessage lines and defender.SendMessage lines in the OnHit, CheckHit, and OnSwing methods, only the defender messages appear when the problem is happening. After a save & reboot, both attacker & defender messages appear until the combatant is dead then for the next combatant only defneder messages appear again.
Code:
public virtual bool CheckHit( Mobile attacker, Mobile defender )
{
BaseWeapon atkWeapon = attacker.Weapon as BaseWeapon;
BaseWeapon defWeapon = defender.Weapon as BaseWeapon;
Skill atkSkill = attacker.Skills[atkWeapon.Skill];
Skill defSkill = defender.Skills[defWeapon.Skill];
double atkValue = atkWeapon.GetAttackSkillValue( attacker, defender );
double defValue = defWeapon.GetDefendSkillValue( attacker, defender );
// byron 7/10/14 - *********************************************************************
double attackerMagerySkill = attacker.Skills[SkillName.Magery].Base;
double attackerAxeFightingSkill = attacker.Skills[SkillName.AxeFighting].Base;
double attackerFencingSkill = attacker.Skills[SkillName.Fencing].Base;
double attackerJoustingSkill = attacker.Skills[SkillName.Jousting].Base;
double attackerKnifeFightingSkill = attacker.Skills[SkillName.KnifeFighting].Base;
double attackerMacingSkill = attacker.Skills[SkillName.Macing].Base;
double attackerMacingClubSkill = attacker.Skills[SkillName.Club].Base;
double attackerMacingFlailSkill = attacker.Skills[SkillName.Flail].Base;
double attackerMacingHammerSkill = attacker.Skills[SkillName.Hammer].Base;
double attackerPoleArmSkill = attacker.Skills[SkillName.PoleArm].Base;
double attackerSpearFightingSkill = attacker.Skills[SkillName.SpearFighting].Base;
double attackerSwordsmanshipSkill = attacker.Skills[SkillName.Swords].Base;
double attackerTwoHandedSwordsSkill = attacker.Skills[SkillName.TwoHandedSwords].Base;
double attackerQuarterStaffSkill = attacker.Skills[SkillName.QuarterStaff].Base;
atkValue = attacker.Skills[SkillName.Wrestling].Base;
atkSkill = attacker.Skills[SkillName.Wrestling];
if (atkWeapon is BaseAxe)
{
atkValue = attackerAxeFightingSkill;
atkSkill = attacker.Skills[SkillName.AxeFighting];
}
else if (atkWeapon is BaseRapier)
{
atkValue = attackerFencingSkill;
atkSkill = attacker.Skills[SkillName.Fencing];
}
else if (atkWeapon is BaseKnife)
{
atkValue = attackerKnifeFightingSkill;
atkSkill = attacker.Skills[SkillName.KnifeFighting];
}
else if (atkWeapon is BaseSword)
{
atkValue = attackerSwordsmanshipSkill;
atkSkill = attacker.Skills[SkillName.Swords];
if (atkWeapon is BaseTwoHandedSword)
{
atkValue = attackerTwoHandedSwordsSkill;
atkSkill = attacker.Skills[SkillName.TwoHandedSwords];
}
}
else if (atkWeapon is BaseMace)
{
atkValue = attackerMacingSkill;
atkSkill = attacker.Skills[SkillName.Macing];
if (atkWeapon is BaseClub)
{
atkValue = attackerMacingClubSkill;
atkSkill = attacker.Skills[SkillName.Club];
}
else if (atkWeapon is BaseFlail)
{
atkValue = attackerMacingFlailSkill;
atkSkill = attacker.Skills[SkillName.Flail];
}
else if (atkWeapon is BaseHammer)
{
atkValue = attackerMacingHammerSkill;
atkSkill = attacker.Skills[SkillName.Hammer];
}
}
else if (atkWeapon is BasePoleArm)
{
atkValue = attackerPoleArmSkill;
atkSkill = attacker.Skills[SkillName.PoleArm];
if (atkWeapon is BaseSpear)
{
atkValue = attackerSpearFightingSkill;
atkSkill = attacker.Skills[SkillName.SpearFighting];
}
else if (atkWeapon is BaseLance)
{
atkValue = attackerJoustingSkill;
atkSkill = attacker.Skills[SkillName.Jousting];
}
}
else if (atkWeapon is BaseQuarterStaff)
{
atkValue = attackerQuarterStaffSkill;
atkSkill = attacker.Skills[SkillName.QuarterStaff];
}
// Apply Skill Modifiers
if (m_AosWeaponAttributes.UseBestSkill != 0)
{
atkValue = attackerAxeFightingSkill;
atkSkill = attacker.Skills[SkillName.AxeFighting];
if (attackerFencingSkill > atkValue)
{
atkValue = attackerFencingSkill;
atkSkill = attacker.Skills[SkillName.Fencing];
}
else if (attackerJoustingSkill > atkValue)
{
atkValue = attackerJoustingSkill;
atkSkill = attacker.Skills[SkillName.Jousting];
}
else if (attackerKnifeFightingSkill > atkValue)
{
atkValue = attackerKnifeFightingSkill;
atkSkill = attacker.Skills[SkillName.KnifeFighting];
}
else if (attackerMacingSkill > atkValue)
{
atkValue = attackerMacingSkill;
atkSkill = attacker.Skills[SkillName.Macing];
}
else if (attackerMacingClubSkill > atkValue)
{
atkValue = attackerMacingClubSkill;
atkSkill = attacker.Skills[SkillName.Club];
}
else if (attackerMacingFlailSkill > atkValue)
{
atkValue = attackerMacingFlailSkill;
atkSkill = attacker.Skills[SkillName.Flail];
}
else if (attackerMacingHammerSkill > atkValue)
{
atkValue = attackerMacingHammerSkill;
atkSkill = attacker.Skills[SkillName.Hammer];
}
else if (attackerPoleArmSkill > atkValue)
{
atkValue = attackerPoleArmSkill;
atkSkill = attacker.Skills[SkillName.PoleArm];
}
else if (attackerSpearFightingSkill > atkValue)
{
atkValue = attackerSpearFightingSkill;
atkSkill = attacker.Skills[SkillName.SpearFighting];
}
else if (attackerSwordsmanshipSkill > atkValue)
{
atkValue = attackerSwordsmanshipSkill;
atkSkill = attacker.Skills[SkillName.Swords];
}
else if (attackerTwoHandedSwordsSkill > atkValue)
{
atkValue = attackerTwoHandedSwordsSkill;
atkSkill = attacker.Skills[SkillName.TwoHandedSwords];
}
else if (attackerQuarterStaffSkill > atkValue)
{
atkValue = attackerQuarterStaffSkill;
atkSkill = attacker.Skills[SkillName.QuarterStaff];
}
}
else if (m_AosWeaponAttributes.MageWeapon != 0)
{
if (attackerMagerySkill > atkValue)
{
atkValue = attackerMagerySkill;
atkSkill = attacker.Skills[SkillName.Magery];
}
}
atkValue *= GetMountModifier (attacker, defender);
// Defender
double defenderMagerySkill = defender.Skills[SkillName.Magery].Base;
double defenderAxeFightingSkill = defender.Skills[SkillName.AxeFighting].Base;
double defenderFencingSkill = defender.Skills[SkillName.Fencing].Base;
double defenderJoustingSkill = defender.Skills[SkillName.Jousting].Base;
double defenderKnifeFightingSkill = defender.Skills[SkillName.KnifeFighting].Base;
double defenderMacingSkill = defender.Skills[SkillName.Macing].Base;
double defenderMacingClubSkill = defender.Skills[SkillName.Club].Base;
double defenderMacingFlailSkill = defender.Skills[SkillName.Flail].Base;
double defenderMacingHammerSkill = defender.Skills[SkillName.Hammer].Base;
double defenderPoleArmSkill = defender.Skills[SkillName.PoleArm].Base;
double defenderSpearFightingSkill = defender.Skills[SkillName.SpearFighting].Base;
double defenderSwordsmanshipSkill = defender.Skills[SkillName.Swords].Base;
double defenderTwoHandedSwordsSkill = defender.Skills[SkillName.TwoHandedSwords].Base;
double defenderQuarterStaffSkill = defender.Skills[SkillName.QuarterStaff].Base;
defValue = defender.Skills[SkillName.Wrestling].Base;
if (defWeapon is BaseAxe)
defValue = defenderAxeFightingSkill;
else if (defWeapon is BaseRapier)
defValue = defenderFencingSkill;
else if (defWeapon is BaseKnife)
defValue = defenderKnifeFightingSkill;
else if (defWeapon is BaseSword)
{
defValue = defenderSwordsmanshipSkill;
if (defWeapon is BaseTwoHandedSword)
defValue = defenderTwoHandedSwordsSkill;
}
else if (defWeapon is BaseMace)
{
defValue = defenderMacingSkill;
if (defWeapon is BaseClub)
defValue = defenderMacingClubSkill;
else if (defWeapon is BaseFlail)
defValue = defenderMacingFlailSkill;
else if (defWeapon is BaseHammer)
defValue = defenderMacingHammerSkill;
}
else if (defWeapon is BasePoleArm)
{
defValue = defenderPoleArmSkill;
if (defWeapon is BaseSpear)
defValue = defenderSpearFightingSkill;
else if (defWeapon is BaseLance)
defValue = defenderJoustingSkill;
}
else if (defWeapon is BaseQuarterStaff)
{
defValue = defenderQuarterStaffSkill;
}
if (m_AosWeaponAttributes.UseBestSkill != 0)
{
defValue = defenderAxeFightingSkill;
if (defenderFencingSkill > defValue)
{
defValue = defenderFencingSkill;
}
else if (defenderJoustingSkill > defValue)
{
defValue = defenderJoustingSkill;
}
else if (defenderKnifeFightingSkill > defValue)
{
defValue = defenderKnifeFightingSkill;
}
else if (defenderMacingSkill > defValue)
{
defValue = defenderMacingSkill;
}
else if (defenderMacingClubSkill > defValue)
{
defValue = defenderMacingClubSkill;
}
else if (defenderMacingFlailSkill > defValue)
{
defValue = defenderMacingFlailSkill;
}
else if (defenderMacingHammerSkill > defValue)
{
defValue = defenderMacingHammerSkill;
}
else if (defenderPoleArmSkill > defValue)
{
defValue = defenderPoleArmSkill;
}
else if (defenderSpearFightingSkill > defValue)
{
defValue = defenderSpearFightingSkill;
}
else if (defenderSwordsmanshipSkill > defValue)
{
defValue = defenderSwordsmanshipSkill;
}
else if (defenderTwoHandedSwordsSkill > defValue)
{
defValue = defenderTwoHandedSwordsSkill;
}
else if (defenderQuarterStaffSkill > defValue)
{
defValue = defenderQuarterStaffSkill;
}
}
else if (m_AosWeaponAttributes.MageWeapon != 0)
{
if (defenderMagerySkill > defValue)
{
defValue = defenderMagerySkill;
}
}
defValue *= GetMountModifier (defender, attacker);
//**************************************************************************************
double ourValue, theirValue;
int bonus = GetHitChanceBonus();
if ( Core.AOS )
{
if ( atkValue <= -20.0 )
atkValue = -19.9;
if ( defValue <= -20.0 )
defValue = -19.9;
bonus += AosAttributes.GetValue( attacker, AosAttribute.AttackChance );
if ( Spells.Chivalry.DivineFurySpell.UnderEffect( attacker ) )
bonus += 10; // attacker gets 10% bonus when they're under divine fury
if ( CheckAnimal( attacker, typeof( GreyWolf ) ) || CheckAnimal( attacker, typeof( BakeKitsune ) ) )
bonus += 20; // attacker gets 20% bonus when under Wolf or Bake Kitsune form
if ( HitLower.IsUnderAttackEffect( attacker ) )
bonus -= 25; // Under Hit Lower Attack effect -> 25% malus
WeaponAbility ability = WeaponAbility.GetCurrentAbility( attacker );
if ( ability != null )
bonus += ability.AccuracyBonus;
SpecialMove move = SpecialMove.GetCurrentMove( attacker );
if ( move != null )
bonus += move.GetAccuracyBonus( attacker );
// Max Hit Chance Increase = 45%
if ( bonus > 45 )
bonus = 45;
ourValue = (atkValue + 20.0) * (100 + bonus);
bonus = AosAttributes.GetValue( defender, AosAttribute.DefendChance );
if ( Spells.Chivalry.DivineFurySpell.UnderEffect( defender ) )
bonus -= 20; // defender loses 20% bonus when they're under divine fury
if ( HitLower.IsUnderDefenseEffect( defender ) )
bonus -= 25; // Under Hit Lower Defense effect -> 25% malus
int blockBonus = 0;
if ( Block.GetBonus( defender, ref blockBonus ) )
bonus += blockBonus;
int surpriseMalus = 0;
if ( SurpriseAttack.GetMalus( defender, ref surpriseMalus ) )
bonus -= surpriseMalus;
int discordanceEffect = 0;
// Defender loses -0/-28% if under the effect of Discordance.
if ( SkillHandlers.Discordance.GetEffect( attacker, ref discordanceEffect ) )
bonus -= discordanceEffect;
// Defense Chance Increase = 45%
if ( bonus > 45 )
bonus = 45;
theirValue = (defValue + 20.0) * (100 + bonus);
bonus = 0;
}
else
{
if ( atkValue <= -50.0 )
atkValue = -49.9;
if ( defValue <= -50.0 )
defValue = -49.9;
ourValue = (atkValue + 50.0);
theirValue = (defValue + 50.0);
}
double chance = ourValue / (theirValue * 2.0);
chance *= 1.0 + ((double)bonus / 100);
if ( Core.AOS && chance < 0.02 )
chance = 0.02;
return attacker.CheckSkill( atkSkill.SkillName, chance );
}
public virtual TimeSpan GetDelay( Mobile m )
{
double speed = this.Speed;
if ( speed == 0 )
return TimeSpan.FromHours( 1.0 );
double delayInSeconds;
if ( Core.SE )
{
/*
* This is likely true for Core.AOS as well... both guides report the same
* formula, and both are wrong.
* The old formula left in for AOS for legacy & because we aren't quite 100%
* Sure that AOS has THIS formula
*/
int bonus = AosAttributes.GetValue( m, AosAttribute.WeaponSpeed );
if ( Spells.Chivalry.DivineFurySpell.UnderEffect( m ) )
bonus += 10;
// Bonus granted by successful use of Honorable Execution.
bonus += HonorableExecution.GetSwingBonus( m );
if( DualWield.Registry.Contains( m ) )
bonus += ((DualWield.DualWieldTimer)DualWield.Registry[m]).BonusSwingSpeed;
if( Feint.Registry.Contains( m ) )
bonus -= ((Feint.FeintTimer)Feint.Registry[m]).SwingSpeedReduction;
TransformContext context = TransformationSpellHelper.GetContext( m );
if( context != null && context.Spell is ReaperFormSpell )
bonus += ((ReaperFormSpell)context.Spell).SwingSpeedBonus;
int discordanceEffect = 0;
// Discordance gives a malus of -0/-28% to swing speed.
if ( SkillHandlers.Discordance.GetEffect( m, ref discordanceEffect ) )
bonus -= discordanceEffect;
if( EssenceOfWindSpell.IsDebuffed( m ) )
bonus -= EssenceOfWindSpell.GetSSIMalus( m );
if ( bonus > 60 )
bonus = 60;
double ticks;
if ( Core.ML )
{
int stamTicks = m.Stam / 30;
ticks = speed * 4;
ticks = Math.Floor( ( ticks - stamTicks ) * ( 100.0 / ( 100 + bonus ) ) );
}
else
{
speed = Math.Floor( speed * ( bonus + 100.0 ) / 100.0 );
if ( speed <= 0 )
speed = 1;
ticks = Math.Floor( ( 80000.0 / ( ( m.Stam + 100 ) * speed ) ) - 2 );
}
// Swing speed currently capped at one swing every 1.25 seconds (5 ticks).
if ( ticks < 5 )
ticks = 5;
delayInSeconds = ticks * 0.25;
}
else if ( Core.AOS )
{
int v = (m.Stam + 100) * (int) speed;
int bonus = AosAttributes.GetValue( m, AosAttribute.WeaponSpeed );
if ( Spells.Chivalry.DivineFurySpell.UnderEffect( m ) )
bonus += 10;
int discordanceEffect = 0;
// Discordance gives a malus of -0/-28% to swing speed.
if ( SkillHandlers.Discordance.GetEffect( m, ref discordanceEffect ) )
bonus -= discordanceEffect;
v += AOS.Scale( v, bonus );
if ( v <= 0 )
v = 1;
delayInSeconds = Math.Floor( 40000.0 / v ) * 0.5;
// Maximum swing rate capped at one swing per second
// OSI dev said that it has and is supposed to be 1.25
if ( delayInSeconds < 1.25 )
delayInSeconds = 1.25;
}
else
{
int v = (m.Stam + 100) * (int) speed;
if ( v <= 0 )
v = 1;
delayInSeconds = 15000.0 / v;
}
return TimeSpan.FromSeconds( delayInSeconds );
}
public virtual void OnBeforeSwing( Mobile attacker, Mobile defender )
{
WeaponAbility a = WeaponAbility.GetCurrentAbility( attacker );
if( a != null && !a.OnBeforeSwing( attacker, defender ) )
WeaponAbility.ClearCurrentAbility( attacker );
SpecialMove move = SpecialMove.GetCurrentMove( attacker );
if( move != null && !move.OnBeforeSwing( attacker, defender ) )
SpecialMove.ClearCurrentMove( attacker );
}
public virtual TimeSpan OnSwing( Mobile attacker, Mobile defender )
{
return OnSwing( attacker, defender, 1.0 );
}
public virtual TimeSpan OnSwing( Mobile attacker, Mobile defender, double damageBonus )
{
bool canSwing = true;
if ( Core.AOS )
{
canSwing = ( !attacker.Paralyzed && !attacker.Frozen );
if ( canSwing )
{
Spell sp = attacker.Spell as Spell;
canSwing = ( sp == null || !sp.IsCasting || !sp.BlocksMovement );
}
if ( canSwing )
{
PlayerMobile p = attacker as PlayerMobile;
canSwing = ( p == null || p.PeacedUntil <= DateTime.UtcNow );
}
}
#region Dueling
if ( attacker is PlayerMobile )
{
PlayerMobile pm = (PlayerMobile)attacker;
if ( pm.DuelContext != null && !pm.DuelContext.CheckItemEquip( attacker, this ) )
canSwing = false;
}
#endregion
if ( canSwing && attacker.HarmfulCheck( defender ) )
{
attacker.DisruptiveAction();
if ( attacker.NetState != null )
attacker.Send( new Swing( 0, attacker, defender ) );
if ( attacker is BaseCreature )
{
BaseCreature bc = (BaseCreature)attacker;
WeaponAbility ab = bc.GetWeaponAbility();
if ( ab != null )
{
if ( bc.WeaponAbilityChance > Utility.RandomDouble() )
WeaponAbility.SetCurrentAbility( bc, ab );
else
WeaponAbility.ClearCurrentAbility( bc );
}
}
if ( CheckHit( attacker, defender ) )
OnHit( attacker, defender, damageBonus );
else
OnMiss( attacker, defender );
}
return GetDelay( attacker );
}