Fixes code according to modern code style. Fixes a few expression bugs.

This commit is contained in:
Kamron Batman 2018-09-15 09:58:51 -07:00
parent 89eea25e5f
commit 970fd563b2
3324 changed files with 441118 additions and 433755 deletions

View file

@ -1,265 +1,265 @@
using System;
using Server.Engines.Craft;
using System.Collections.Generic;
using Server.Engines.ConPVP;
using Server.Engines.Craft;
namespace Server.Items
{
public enum PotionEffect
{
Nightsight,
CureLesser,
Cure,
CureGreater,
Agility,
AgilityGreater,
Strength,
StrengthGreater,
PoisonLesser,
Poison,
PoisonGreater,
PoisonDeadly,
Refresh,
RefreshTotal,
HealLesser,
Heal,
HealGreater,
ExplosionLesser,
Explosion,
ExplosionGreater,
Conflagration,
ConflagrationGreater,
MaskOfDeath, // Mask of Death is not available in OSI but does exist in cliloc files
MaskOfDeathGreater, // included in enumeration for compatibility if later enabled by OSI
ConfusionBlast,
ConfusionBlastGreater,
Invisibility,
Parasitic,
Darkglow,
}
public enum PotionEffect
{
Nightsight,
CureLesser,
Cure,
CureGreater,
Agility,
AgilityGreater,
Strength,
StrengthGreater,
PoisonLesser,
Poison,
PoisonGreater,
PoisonDeadly,
Refresh,
RefreshTotal,
HealLesser,
Heal,
HealGreater,
ExplosionLesser,
Explosion,
ExplosionGreater,
Conflagration,
ConflagrationGreater,
MaskOfDeath, // Mask of Death is not available in OSI but does exist in cliloc files
MaskOfDeathGreater, // included in enumeration for compatibility if later enabled by OSI
ConfusionBlast,
ConfusionBlastGreater,
Invisibility,
Parasitic,
Darkglow
}
public abstract class BasePotion : Item, ICraftable, ICommodity
{
private PotionEffect m_PotionEffect;
public abstract class BasePotion : Item, ICraftable, ICommodity
{
private PotionEffect m_PotionEffect;
public PotionEffect PotionEffect
{
get => m_PotionEffect;
set
{
m_PotionEffect = value;
InvalidateProperties();
}
}
public BasePotion(int itemID, PotionEffect effect) : base(itemID)
{
m_PotionEffect = effect;
int ICommodity.DescriptionNumber => LabelNumber;
bool ICommodity.IsDeedable => (Core.ML);
Stackable = Core.ML;
Weight = 1.0;
}
public override int LabelNumber => 1041314 + (int)m_PotionEffect;
public BasePotion(Serial serial) : base(serial)
{
}
public BasePotion( int itemID, PotionEffect effect ) : base( itemID )
{
m_PotionEffect = effect;
public PotionEffect PotionEffect
{
get => m_PotionEffect;
set
{
m_PotionEffect = value;
InvalidateProperties();
}
}
Stackable = Core.ML;
Weight = 1.0;
}
public override int LabelNumber => 1041314 + (int)m_PotionEffect;
public BasePotion( Serial serial ) : base( serial )
{
}
public virtual bool RequireFreeHand => true;
public virtual bool RequireFreeHand => true;
int ICommodity.DescriptionNumber => LabelNumber;
bool ICommodity.IsDeedable => Core.ML;
public static bool HasFreeHand( Mobile m )
{
Item handOne = m.FindItemOnLayer( Layer.OneHanded );
Item handTwo = m.FindItemOnLayer( Layer.TwoHanded );
#region ICraftable Members
if ( handTwo is BaseWeapon )
handOne = handTwo;
public int OnCraft(int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool,
CraftItem craftItem, int resHue)
{
if (craftSystem is DefAlchemy)
{
Container pack = from.Backpack;
if ( handTwo is BaseRanged ranged && ranged.Balanced )
return true;
if (pack != null)
{
if ((int)PotionEffect >= (int)PotionEffect.Invisibility)
return 1;
return ( handOne == null || handTwo == null );
}
List<PotionKeg> kegs = pack.FindItemsByType<PotionKeg>();
public override void OnDoubleClick( Mobile from )
{
if ( !Movable )
return;
for (int i = 0; i < kegs.Count; ++i)
{
PotionKeg keg = kegs[i];
if ( from.InRange( GetWorldLocation(), 1 ) )
{
if (!RequireFreeHand || HasFreeHand(from))
{
if (this is BaseExplosionPotion && Amount > 1)
{
BasePotion pot = (BasePotion)Activator.CreateInstance(GetType());
if (keg == null)
continue;
if (pot != null)
{
Amount--;
if (keg.Held <= 0 || keg.Held >= 100)
continue;
if (from.Backpack != null && !from.Backpack.Deleted)
{
from.Backpack.DropItem(pot);
}
else
{
pot.MoveToWorld(from.Location, from.Map);
}
pot.Drink( from );
}
}
else
{
Drink( from );
}
}
else
{
from.SendLocalizedMessage(502172); // You must have a free hand to drink a potion.
}
}
else
{
from.SendLocalizedMessage( 502138 ); // That is too far away for you to use
}
}
if (keg.Type != PotionEffect)
continue;
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
++keg.Held;
writer.Write( (int) 1 ); // version
Consume();
from.AddToBackpack(new Bottle());
writer.Write( (int) m_PotionEffect );
}
return -1; // signal placed in keg
}
}
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
return 1;
}
int version = reader.ReadInt();
#endregion
switch ( version )
{
case 1:
case 0:
{
m_PotionEffect = (PotionEffect)reader.ReadInt();
break;
}
}
public static bool HasFreeHand(Mobile m)
{
Item handOne = m.FindItemOnLayer(Layer.OneHanded);
Item handTwo = m.FindItemOnLayer(Layer.TwoHanded);
if ( version == 0 )
Stackable = Core.ML;
}
if (handTwo is BaseWeapon)
handOne = handTwo;
public abstract void Drink( Mobile from );
if (handTwo is BaseRanged ranged && ranged.Balanced)
return true;
public static void PlayDrinkEffect( Mobile m )
{
m.RevealingAction();
return handOne == null || handTwo == null;
}
m.PlaySound( 0x2D6 );
public override void OnDoubleClick(Mobile from)
{
if (!Movable)
return;
#region Dueling
if ( !Engines.ConPVP.DuelContext.IsFreeConsume( m ) )
m.AddToBackpack( new Bottle() );
#endregion
if (from.InRange(GetWorldLocation(), 1))
{
if (!RequireFreeHand || HasFreeHand(from))
{
if (this is BaseExplosionPotion && Amount > 1)
{
BasePotion pot = (BasePotion)Activator.CreateInstance(GetType());
if ( m.Body.IsHuman && !m.Mounted )
m.Animate( 34, 5, 1, true, false, 0 );
}
if (pot != null)
{
Amount--;
public static int EnhancePotions( Mobile m )
{
int EP = AosAttributes.GetValue( m, AosAttribute.EnhancePotions );
int skillBonus = m.Skills.Alchemy.Fixed / 330 * 10;
if (from.Backpack != null && !from.Backpack.Deleted)
from.Backpack.DropItem(pot);
else
pot.MoveToWorld(from.Location, from.Map);
pot.Drink(from);
}
}
else
{
Drink(from);
}
}
else
{
from.SendLocalizedMessage(502172); // You must have a free hand to drink a potion.
}
}
else
{
from.SendLocalizedMessage(502138); // That is too far away for you to use
}
}
if ( Core.ML && EP > 50 && m.AccessLevel <= AccessLevel.Player )
EP = 50;
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
return ( EP + skillBonus );
}
writer.Write(1); // version
public static TimeSpan Scale( Mobile m, TimeSpan v )
{
if ( !Core.AOS )
return v;
writer.Write((int)m_PotionEffect);
}
double scalar = 1.0 + ( 0.01 * EnhancePotions( m ) );
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
return TimeSpan.FromSeconds( v.TotalSeconds * scalar );
}
int version = reader.ReadInt();
public static double Scale( Mobile m, double v )
{
if ( !Core.AOS )
return v;
switch (version)
{
case 1:
case 0:
{
m_PotionEffect = (PotionEffect)reader.ReadInt();
break;
}
}
double scalar = 1.0 + ( 0.01 * EnhancePotions( m ) );
if (version == 0)
Stackable = Core.ML;
}
return v * scalar;
}
public abstract void Drink(Mobile from);
public static int Scale( Mobile m, int v )
{
if ( !Core.AOS )
return v;
public static void PlayDrinkEffect(Mobile m)
{
m.RevealingAction();
return AOS.Scale( v, 100 + EnhancePotions( m ) );
}
m.PlaySound(0x2D6);
public override bool StackWith( Mobile from, Item dropped, bool playSound )
{
return dropped is BasePotion potion && potion.m_PotionEffect == m_PotionEffect &&
base.StackWith(from, potion, playSound);
}
#region Dueling
#region ICraftable Members
if (!DuelContext.IsFreeConsume(m))
m.AddToBackpack(new Bottle());
public int OnCraft( int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool, CraftItem craftItem, int resHue )
{
if ( craftSystem is DefAlchemy )
{
Container pack = from.Backpack;
#endregion
if ( pack != null )
{
if ( (int) PotionEffect >= (int) PotionEffect.Invisibility )
return 1;
if (m.Body.IsHuman && !m.Mounted)
m.Animate(34, 5, 1, true, false, 0);
}
List<PotionKeg> kegs = pack.FindItemsByType<PotionKeg>();
public static int EnhancePotions(Mobile m)
{
int EP = AosAttributes.GetValue(m, AosAttribute.EnhancePotions);
int skillBonus = m.Skills.Alchemy.Fixed / 330 * 10;
for ( int i = 0; i < kegs.Count; ++i )
{
PotionKeg keg = kegs[i];
if (Core.ML && EP > 50 && m.AccessLevel <= AccessLevel.Player)
EP = 50;
if ( keg == null )
continue;
return EP + skillBonus;
}
if ( keg.Held <= 0 || keg.Held >= 100 )
continue;
public static TimeSpan Scale(Mobile m, TimeSpan v)
{
if (!Core.AOS)
return v;
if ( keg.Type != PotionEffect )
continue;
double scalar = 1.0 + 0.01 * EnhancePotions(m);
++keg.Held;
return TimeSpan.FromSeconds(v.TotalSeconds * scalar);
}
Consume();
from.AddToBackpack( new Bottle() );
public static double Scale(Mobile m, double v)
{
if (!Core.AOS)
return v;
return -1; // signal placed in keg
}
}
}
double scalar = 1.0 + 0.01 * EnhancePotions(m);
return 1;
}
return v * scalar;
}
#endregion
}
}
public static int Scale(Mobile m, int v)
{
if (!Core.AOS)
return v;
return AOS.Scale(v, 100 + EnhancePotions(m));
}
public override bool StackWith(Mobile from, Item dropped, bool playSound)
{
return dropped is BasePotion potion && potion.m_PotionEffect == m_PotionEffect &&
base.StackWith(from, potion, playSound);
}
}
}