public override Tuple<Item[],int> GenerateLootItem( Mobile creature )
		{
			Type type = m_InstrumentTypes[Utility.Random(m_InstrumentTypes.Length)];
			BaseInstrument instrument = Activator.CreateInstance( type ) as BaseInstrument;

			if ( instrument == null )
				throw new Exception( String.Format( "Type {0} is not BaseInstrument or could not be instantiated.", type ) );

			int value = 50;

			if ( m_SlayerChance > Utility.RandomDouble() )
			{
				if ( creature != null )
					instrument.Slayer = SlayerGroup.GetLootSlayerType( creature.GetType() );
				else
					instrument.Slayer = BaseRunicTool.GetRandomSlayer();

				value += 100;
			}

			if ( 0.08 > Utility.RandomDouble() ) // chance that this is low quality
			{
				instrument.Quality = InstrumentQuality.Low;
				value -= 50;
			}

			return new Tuple<Item[], int>( new Item[]{ instrument }, value );
		}
        public override Tuple <Item[], int> GenerateLootItem(Mobile creature)
        {
            Type           type       = m_InstrumentTypes[Utility.Random(m_InstrumentTypes.Length)];
            BaseInstrument instrument = Activator.CreateInstance(type) as BaseInstrument;

            if (instrument == null)
            {
                throw new Exception(String.Format("Type {0} is not BaseInstrument or could not be instantiated.", type));
            }

            int value = 50;

            if (m_SlayerChance > Utility.RandomDouble())
            {
                if (creature != null)
                {
                    instrument.Slayer = SlayerGroup.GetLootSlayerType(creature.GetType());
                }
                else
                {
                    instrument.Slayer = BaseRunicTool.GetRandomSlayer();
                }

                value += 100;
            }

            if (0.08 > Utility.RandomDouble())               // chance that this is low quality
            {
                instrument.Quality = InstrumentQuality.Low;
                value -= 50;
            }

            return(new Tuple <Item[], int>(new Item[] { instrument }, value));
        }
Esempio n. 3
0
        public bool Slays( Mobile m )
        {
            Type t = m.GetType();

            for ( int i = 0; i < m_Types.Length; ++i )
                if ( m_Types[i] == t )
                    return true;

            return false;
        }
Esempio n. 4
0
        public void OnHit( Mobile defender )
        {
            if ( m_TargetType == null )
            {
                m_TargetType = defender.GetType();

                // Odd but OSI recalculates when the target changes...
                int chivalry = (int) m_Owner.Skills.Chivalry.Value;
                m_DamageScalar = 10 + ( ( chivalry - 40 ) * 9 ) / 10;

                DeltaEnemies();
                UpdateBuffInfo();
            }
        }
Esempio n. 5
0
		public override void OnHit( Mobile attacker, Mobile defender, double damageBonus )
		{
			bool bonus = false;
			Type t = defender.GetType();

			for( int i = 0; i < SlayerVs.Length; i++ )
			{
				if ( t == SlayerVs[i] )
				{
					bonus = true;
					break;
				}
			}

			if ( bonus )
				base.OnHit( attacker, defender, damageBonus + 2.0 );
			else
				base.OnHit( attacker, defender, damageBonus );
		}
Esempio n. 6
0
        public static void Load()
        {
            if (m_Loaded)
            {
                return;
            }

            m_Loaded      = true;
            m_LoadingType = null;

            Console.Write("World: Loading...");

            Stopwatch watch = Stopwatch.StartNew();

            m_Loading = true;

            _addQueue    = new Queue <IEntity>();
            _deleteQueue = new Queue <IEntity>();

            int mobileCount = 0, itemCount = 0, guildCount = 0;

            object[] ctorArgs = new object[1];

            List <ItemEntry>   items   = new List <ItemEntry>();
            List <MobileEntry> mobiles = new List <MobileEntry>();
            List <GuildEntry>  guilds  = new List <GuildEntry>();

            if (File.Exists(MobileIndexPath) && File.Exists(MobileTypesPath))
            {
                using (FileStream idx = new FileStream(MobileIndexPath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    BinaryReader idxReader = new BinaryReader(idx);

                    using (FileStream tdb = new FileStream(MobileTypesPath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                        BinaryReader tdbReader = new BinaryReader(tdb);

                        List <object[]> types = ReadTypes(tdbReader);

                        mobileCount = idxReader.ReadInt32();

                        m_Mobiles = new Dictionary <Serial, Mobile>(mobileCount);

                        for (int i = 0; i < mobileCount; ++i)
                        {
                            int  typeID = idxReader.ReadInt32();
                            int  serial = idxReader.ReadInt32();
                            long pos    = idxReader.ReadInt64();
                            int  length = idxReader.ReadInt32();

                            object[] objs = types[typeID];

                            if (objs == null)
                            {
                                continue;
                            }

                            Mobile          m        = null;
                            ConstructorInfo ctor     = ( ConstructorInfo )objs[0];
                            string          typeName = ( string )objs[1];

                            try {
                                ctorArgs[0] = ( Serial )serial;
                                m           = ( Mobile )(ctor.Invoke(ctorArgs));
                            } catch {
                            }

                            if (m != null)
                            {
                                mobiles.Add(new MobileEntry(m, typeID, typeName, pos, length));
                                AddMobile(m);
                            }
                        }

                        tdbReader.Close();
                    }

                    idxReader.Close();
                }
            }
            else
            {
                m_Mobiles = new Dictionary <Serial, Mobile>();
            }

            if (File.Exists(ItemIndexPath) && File.Exists(ItemTypesPath))
            {
                using (FileStream idx = new FileStream(ItemIndexPath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    BinaryReader idxReader = new BinaryReader(idx);

                    using (FileStream tdb = new FileStream(ItemTypesPath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                        BinaryReader tdbReader = new BinaryReader(tdb);

                        List <object[]> types = ReadTypes(tdbReader);

                        itemCount = idxReader.ReadInt32();

                        m_Items = new Dictionary <Serial, Item>(itemCount);

                        for (int i = 0; i < itemCount; ++i)
                        {
                            int  typeID = idxReader.ReadInt32();
                            int  serial = idxReader.ReadInt32();
                            long pos    = idxReader.ReadInt64();
                            int  length = idxReader.ReadInt32();

                            object[] objs = types[typeID];

                            if (objs == null)
                            {
                                continue;
                            }

                            Item            item     = null;
                            ConstructorInfo ctor     = ( ConstructorInfo )objs[0];
                            string          typeName = ( string )objs[1];

                            try {
                                ctorArgs[0] = ( Serial )serial;
                                item        = ( Item )(ctor.Invoke(ctorArgs));
                            } catch {
                            }

                            if (item != null)
                            {
                                items.Add(new ItemEntry(item, typeID, typeName, pos, length));
                                AddItem(item);
                            }
                        }

                        tdbReader.Close();
                    }

                    idxReader.Close();
                }
            }
            else
            {
                m_Items = new Dictionary <Serial, Item>();
            }

            if (File.Exists(GuildIndexPath))
            {
                using (FileStream idx = new FileStream(GuildIndexPath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    BinaryReader idxReader = new BinaryReader(idx);

                    guildCount = idxReader.ReadInt32();

                    CreateGuildEventArgs createEventArgs = new CreateGuildEventArgs(-1);
                    for (int i = 0; i < guildCount; ++i)
                    {
                        idxReader.ReadInt32();                        //no typeid for guilds
                        int  id     = idxReader.ReadInt32();
                        long pos    = idxReader.ReadInt64();
                        int  length = idxReader.ReadInt32();

                        createEventArgs.Id = id;
                        EventSink.InvokeCreateGuild(createEventArgs);
                        BaseGuild guild = createEventArgs.Guild;
                        if (guild != null)
                        {
                            guilds.Add(new GuildEntry(guild, pos, length));
                        }
                    }

                    idxReader.Close();
                }
            }

            bool      failedMobiles = false, failedItems = false, failedGuilds = false;
            Type      failedType   = null;
            Serial    failedSerial = Serial.Zero;
            Exception failed       = null;
            int       failedTypeID = 0;

            if (File.Exists(MobileDataPath))
            {
                using (FileStream bin = new FileStream(MobileDataPath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < mobiles.Count; ++i)
                    {
                        MobileEntry entry = mobiles[i];
                        Mobile      m     = entry.Mobile;

                        if (m != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try {
                                m_LoadingType = entry.TypeName;
                                m.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on {0} *****", m.GetType()));
                                }
                            } catch (Exception e) {
                                mobiles.RemoveAt(i);

                                failed        = e;
                                failedMobiles = true;
                                failedType    = m.GetType();
                                failedTypeID  = entry.TypeID;
                                failedSerial  = m.Serial;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }
            }

            if (!failedMobiles && File.Exists(ItemDataPath))
            {
                using (FileStream bin = new FileStream(ItemDataPath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < items.Count; ++i)
                    {
                        ItemEntry entry = items[i];
                        Item      item  = entry.Item;

                        if (item != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try {
                                m_LoadingType = entry.TypeName;
                                item.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on {0} *****", item.GetType()));
                                }
                            } catch (Exception e) {
                                items.RemoveAt(i);

                                failed       = e;
                                failedItems  = true;
                                failedType   = item.GetType();
                                failedTypeID = entry.TypeID;
                                failedSerial = item.Serial;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }
            }

            m_LoadingType = null;

            if (!failedMobiles && !failedItems && File.Exists(GuildDataPath))
            {
                using (FileStream bin = new FileStream(GuildDataPath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < guilds.Count; ++i)
                    {
                        GuildEntry entry = guilds[i];
                        BaseGuild  g     = entry.Guild;

                        if (g != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try {
                                g.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on Guild {0} *****", g.Id));
                                }
                            } catch (Exception e) {
                                guilds.RemoveAt(i);

                                failed       = e;
                                failedGuilds = true;
                                failedType   = typeof(BaseGuild);
                                failedTypeID = g.Id;
                                failedSerial = g.Id;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }
            }

            if (failedItems || failedMobiles || failedGuilds)
            {
                Console.WriteLine("An error was encountered while loading a saved object");

                Console.WriteLine(" - Type: {0}", failedType);
                Console.WriteLine(" - Serial: {0}", failedSerial);

                if (!Core.Service)
                {
                    Console.WriteLine("Delete the object? (y/n)");

                    if (Console.ReadKey(true).Key == ConsoleKey.Y)
                    {
                        if (failedType != typeof(BaseGuild))
                        {
                            Console.WriteLine("Delete all objects of that type? (y/n)");

                            if (Console.ReadKey(true).Key == ConsoleKey.Y)
                            {
                                if (failedMobiles)
                                {
                                    for (int i = 0; i < mobiles.Count;)
                                    {
                                        if (mobiles[i].TypeID == failedTypeID)
                                        {
                                            mobiles.RemoveAt(i);
                                        }
                                        else
                                        {
                                            ++i;
                                        }
                                    }
                                }
                                else if (failedItems)
                                {
                                    for (int i = 0; i < items.Count;)
                                    {
                                        if (items[i].TypeID == failedTypeID)
                                        {
                                            items.RemoveAt(i);
                                        }
                                        else
                                        {
                                            ++i;
                                        }
                                    }
                                }
                            }
                        }

                        SaveIndex <MobileEntry>(mobiles, MobileIndexPath);
                        SaveIndex <ItemEntry>(items, ItemIndexPath);
                        SaveIndex <GuildEntry>(guilds, GuildIndexPath);
                    }

                    Console.WriteLine("After pressing return an exception will be thrown and the server will terminate.");
                    Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("An exception will be thrown and the server will terminate.");
                }

                throw new Exception(String.Format("Load failed (items={0}, mobiles={1}, guilds={2}, type={3}, serial={4})", failedItems, failedMobiles, failedGuilds, failedType, failedSerial), failed);
            }

            EventSink.InvokeWorldLoad();

            m_Loading = false;

            ProcessSafetyQueues();

            foreach (Item item in m_Items.Values)
            {
                if (item.Parent == null)
                {
                    item.UpdateTotals();
                }

                item.ClearProperties();
            }

            foreach (Mobile m in m_Mobiles.Values)
            {
                m.UpdateRegion();                 // Is this really needed?
                m.UpdateTotals();

                m.ClearProperties();
            }

            watch.Stop();

            Console.WriteLine("done ({1} items, {2} mobiles) ({0:F2} seconds)", watch.Elapsed.TotalSeconds, m_Items.Count, m_Mobiles.Count);
        }
Esempio n. 7
0
        public bool IsObjective( Mobile m )
        {
            if ( !m_TargetTypes.Any( t => t.IsAssignableFrom( m.GetType() ) ) )
                return false;

            if ( m_Targets.Contains( m ) )
                return false;

            return true;
        }
Esempio n. 8
0
 public static int GetSaveFlag(Mobile m)
 {
     return(ConversionTable.IndexOf(m.GetType()) + Offset);
 }
		public override void OnKill(Mobile killed, Mobile killer )
		{
			base.OnKill(killed, killer);

			// supports ignoring XmlPoints challenges
			if(m_ChallengeStatus)
			{
				m_ChallengeStatus = false;
				return;
			}

			if(killed == null || killer == null || killer == killed) return;
		    
			// check for within guild kills and ignore them
			if(SameGuild(killed,killer)) return;

			// this calculates the base faction level that will be gained/lost based upon the fame of the killed mob
			double value = (double)(killed.Fame/1000.0);
			if(value <= 0) value = 1;

			// calculates credits gained in a similar way
			int cval = (int)(killed.Fame*m_CreditScale);
			if(cval <= 0) cval = 1;

			Credits += cval;

			// prepare the group lists that will be checked for faction
			ArrayList glist = null;
			ArrayList dglist = null;

			// check to see whether this mob type has already been hashed into a group list
			if(GroupHash.Contains(killed.GetType()))
			{
				glist = (ArrayList)GroupHash[killed.GetType()];
			} 
			else
			{
				// otherwise look it up the slow way and prepare a hash entry for it at the same time
				// unless it is using dynamic faction
				glist = new ArrayList();
				foreach(Group g in KillGroups)
				{
					if(MatchType(g.Members, killed))
					{
						glist.Add(g);
					}
				}
				GroupHash.Add(killed.GetType(),glist);
			}

			// have to look up dynamic factions the exhaustive way
			// does this mob have dynamic faction assignments?
			ArrayList list = XmlAttach.FindAttachments(XmlAttach.MobileAttachments, killed, typeof(XmlDynamicFaction));
			if(list != null && list.Count > 0)
			{
				//if(XmlAttach.FindAttachment(XmlAttach.MobileAttachments, killed, typeof(XmlDynamicFaction)) != null)
				//{
				dglist = new ArrayList();
				foreach(Group g in KillGroups)
				{
					if(DynamicMatchType(g.Members, killed))
					{
						dglist.Add(g);
					}
				}
			}

			ArrayList alist = new ArrayList();
			if(glist != null && glist.Count > 0)
				alist.Add(glist);
			if(dglist != null && dglist.Count > 0)
				alist.Add(dglist);

			//  go through this with static and dynamic factions
			foreach(ArrayList al in alist)
			{
				foreach(Group g in al)
				{
					// tabulate the faction loss from target group allies
					if(g.Allies != null && g.Allies.Length > 0)
					{
						for(int i = 0; i< g.Allies.Length;i++)
						{
							Group ally = g.Allies[i];

							int facloss = 0;
							try
							{
								facloss = (int)(value*g.AllyLoss[i]);
							} 
							catch{}
							if(facloss <= 0) facloss = 1;
        
							int p = GetFactionLevel(ally.GroupType) - facloss;
							SetFactionLevel(ally.GroupType, p);
							if(verboseMobFactions)
								killer.SendMessage("lost {0} faction {1}", ally.GroupType,facloss);
						}
					}

					// tabulate the faction gain from target group opponents
					if(g.Opponents != null && g.Opponents.Length > 0)
					{
						for(int i = 0; i< g.Opponents.Length;i++)
						{
							Group opp = g.Opponents[i];

							int facgain = 0;
							try
							{
								facgain = (int)(value*g.OpponentGain[i]);
							} 
							catch {}
							if(facgain <= 0) facgain = 1;

							int p = GetFactionLevel(opp.GroupType) + facgain;
							SetFactionLevel(opp.GroupType, p);
							if(verboseMobFactions)
								killer.SendMessage("gained {0} faction {1}",opp.GroupType, facgain);
						}
					}
				}
			}

			m_EndTime = DateTime.Now + Refractory;
		}
		public override bool IgnoreYoungProtection( Mobile from )
		{
			if ( Completed )
				return false;

			IngredientInfo info = IngredientInfo.Get( this.Ingredient );
			Type fromType = from.GetType();

			for ( int i = 0; i < info.Creatures.Length; i++ )
			{
				if ( fromType == info.Creatures[i] )
					return true;
			}

			return false;
		}
Esempio n. 11
0
		public bool Slays( Mobile m )
		{
			Type t = m.GetType();

			for ( int i = 0; i < m_Types.Length; ++i )
			{
                if (m_Types[i].IsAssignableFrom(t))
					return true;
			}

			return false;
		}
		// this method returns a list of the group types that the mobile belongs to using the KillGroups master list
		public static ArrayList FindGroups(Mobile m)
		{
			if(m == null) return null;

			// see whether this mobile type is already in the hash table
			if(GroupTypeHash.Contains(m.GetType()))
			{
				// then get the list from there
				return (ArrayList)GroupTypeHash[m.GetType()];
			}

			ArrayList list = new ArrayList();

			foreach(Group g in KillGroups)
			{
				if(MatchType(g.Members, m))
				{
					list.Add(g.GroupType);
				}
			}
			GroupTypeHash.Add(m.GetType(),list);

			return list;
		}
Esempio n. 13
0
        public String GetPetKind(Mobile pet)
        {
            if (pet == null || pet.Deleted)
                return "";

            String petclass = pet.GetType().ToString();
            Regex rx = new Regex(@"^.*\.(?<pc>.*)$");
            Match m = rx.Match(petclass);

            return m.Groups["pc"].Value;
        }
Esempio n. 14
0
		public static int MobileNotoriety( Mobile source, Mobile target )
		{
			if( Core.AOS && (target.Blessed || (target is BaseVendor && ((BaseVendor)target).IsInvulnerable) || target is PlayerVendor || target is TownCrier) )
				return Notoriety.Invulnerable;

			if( target.AccessLevel > AccessLevel.Player )
				return Notoriety.CanBeAttacked;

			if( source.Player && !target.Player && source is PlayerMobile && target is BaseCreature )
			{
				BaseCreature bc = (BaseCreature)target;

				if( !bc.Summoned && !bc.Controlled && ((PlayerMobile)source).EnemyOfOneType == target.GetType() )
					return Notoriety.Enemy;
			}

			if( target.Kills >= 5 || (target.Body.IsMonster && IsSummoned( target as BaseCreature ) && !(target is BaseFamiliar) && !(target is Golem)) || (target is BaseCreature && (((BaseCreature)target).AlwaysMurderer || ((BaseCreature)target).IsAnimatedDead)) )
				return Notoriety.Murderer;

if ( target.Criminal )
 return Notoriety.Criminal;

// XmlPoints challenge mod
if(XmlPoints.AreTeamMembers(source,target))
                return Notoriety.Ally;
else
if(XmlPoints.AreChallengers(source,target))
                return Notoriety.Enemy;

			Guild sourceGuild = GetGuildFor( source.Guild as Guild, source );
			Guild targetGuild = GetGuildFor( target.Guild as Guild, target );

			if( sourceGuild != null && targetGuild != null )
			{
				if( sourceGuild == targetGuild || sourceGuild.IsAlly( targetGuild ) )
					return Notoriety.Ally;
				else if( sourceGuild.IsEnemy( targetGuild ) )
					return Notoriety.Enemy;
			}

			Faction srcFaction = Faction.Find( source, true, true );
			Faction trgFaction = Faction.Find( target, true, true );

			if( srcFaction != null && trgFaction != null && srcFaction != trgFaction && source.Map == Faction.Facet )
				return Notoriety.Enemy;

			if( SkillHandlers.Stealing.ClassicMode && target is PlayerMobile && ((PlayerMobile)target).PermaFlags.Contains( source ) )
				return Notoriety.CanBeAttacked;

			if( target is BaseCreature && ((BaseCreature)target).AlwaysAttackable )
				return Notoriety.CanBeAttacked;

			if( CheckHouseFlag( source, target, target.Location, target.Map ) )
				return Notoriety.CanBeAttacked;

			if( !(target is BaseCreature && ((BaseCreature)target).InitialInnocent) )
			{
				if( !target.Body.IsHuman && !target.Body.IsGhost && !IsPet( target as BaseCreature ) && !Server.Spells.Necromancy.TransformationSpell.UnderTransformation( target ) )
					return Notoriety.CanBeAttacked;
			}

			if( CheckAggressor( source.Aggressors, target ) )
				return Notoriety.CanBeAttacked;

			if( CheckAggressed( source.Aggressed, target ) )
				return Notoriety.CanBeAttacked;

			if( target is BaseCreature )
			{
				BaseCreature bc = (BaseCreature)target;

				if( bc.Controlled && bc.ControlOrder == OrderType.Guard && bc.ControlTarget == source )
					return Notoriety.CanBeAttacked;
			}

			if( source is BaseCreature )
			{
				BaseCreature bc = (BaseCreature)source;

				Mobile master = bc.GetMaster();
				if( master != null && CheckAggressor( master.Aggressors, target ) )
					return Notoriety.CanBeAttacked;
			}
			
			if ( PlayerGovernmentSystem.CheckIfBanned( source, target ) )
				return Notoriety.Enemy;

			if ( PlayerGovernmentSystem.CheckAtWarWith( source, target ) )
				return Notoriety.Enemy;

			if ( PlayerGovernmentSystem.CheckCityAlly( source, target ) )
				return Notoriety.Ally;

			return Notoriety.Innocent;
		}
Esempio n. 15
0
		public Item Mutate(Mobile from, Item item)
		{           

			if (item != null && !(item is BaseWand))
			{
				if (item is BaseWeapon && 1 > Utility.Random(100))
				{
					item.Delete();
					item = new FireHorn();
					return item;
				}

				if (item is BaseWeapon || item is BaseArmor || item is BaseJewel || item is BaseHat)
				{
					if (item is BaseWeapon)
					{
						var weapon = (BaseWeapon)item;

						if (55 > Utility.Random(100))
						{
							weapon.AccuracyLevel = (WeaponAccuracyLevel)GetRandomOldBonus();
						}

						if (45 > Utility.Random(100))
						{
							int damageLevel = GetRandomOldBonus();

							if (PseudoSeerStone.Instance != null && PseudoSeerStone.Instance._HighestDamageLevelSpawn < damageLevel)
							{
								if (damageLevel == 5 && PseudoSeerStone.ReplaceVanqWithSkillScrolls)
								{
									return PuzzleChest.CreateRandomSkillScroll();
								}
								int platAmount = PseudoSeerStone.PlatinumPerMissedDamageLevel *
												 (damageLevel - PseudoSeerStone.Instance._HighestDamageLevelSpawn);
								if (platAmount > 0)
								{
									return (new Platinum(platAmount));
								}
								damageLevel = PseudoSeerStone.Instance._HighestDamageLevelSpawn;
							}
							weapon.DamageLevel = (WeaponDamageLevel)damageLevel;
						}

						if (25 > Utility.Random(100))
						{
							weapon.DurabilityLevel = (WeaponDurabilityLevel)GetRandomOldBonus();
						}

						if (5 > Utility.Random(100))
						{
							weapon.Slayer = SlayerName.Silver;
						}

						if (1 > Utility.Random(1000) ||
							(weapon.AccuracyLevel == 0 && weapon.DamageLevel == 0 && weapon.DurabilityLevel == 0 &&
							 weapon.Slayer == SlayerName.None && 5 > Utility.Random(100)))
						{
							weapon.Slayer = from != null ? SlayerGroup.GetLootSlayerType(from.GetType()) : BaseRunicTool.GetRandomSlayer();
						}

						if (weapon.AccuracyLevel == 0 && weapon.DamageLevel == 0 && weapon.DurabilityLevel == 0 &&
							weapon.Slayer == SlayerName.None)
						{
							weapon.Identified = true;
						}
					}
					else if (item is BaseArmor)
					{
						var armor = (BaseArmor)item;

						if (55 > Utility.Random(100))
						{
							armor.ProtectionLevel = (ArmorProtectionLevel)GetRandomOldBonus();
						}

						if (25 > Utility.Random(100))
						{
							armor.Durability = (ArmorDurabilityLevel)GetRandomOldBonus();
						}

						if (armor.ProtectionLevel == 0 && armor.Durability == 0)
						{
							armor.Identified = true;
						}
					}
				}
				else if (item is BaseInstrument)
				{
					SlayerName slayer = from == null || from.EraAOS
											? BaseRunicTool.GetRandomSlayer()
											: SlayerGroup.GetLootSlayerType(from.GetType());

					var instr = (BaseInstrument)item;

					instr.Quality = InstrumentQuality.Regular;
					instr.Slayer = slayer;
				}
				else if (item is Spellbook) //Randomize spellbook
				{
					var book = item as Spellbook;

					if (MaxIntensity == 100 && MinIntensity / 1000.0 > Utility.RandomDouble())
					{
						book.LootType = LootType.Blessed;
					}

					if (MaxIntensity == 100 && MinIntensity >= 50 && (MinIntensity / 3000.0 > Utility.RandomDouble()))
					{
						book.Dyable = true;
					}

					int rnd = Utility.RandomMinMax(MinIntensity, MaxIntensity);
					var circle = (int)((rnd / 12.5) + 1.0);

					if (circle >= 8 && 0.33 > Utility.RandomDouble())
					{
						book.Content = ulong.MaxValue;
					}
					else
					{
						circle = Math.Min(circle, 8);

						//do we fill this circle?
						for (int i = 0; i < circle; i++)
						{
							if (Utility.RandomBool())
							{
								book.Content |= (ulong)Utility.Random(0x100) << (i * 8);
							}
						}
					}
				}

				if (item.Stackable)
				{
                    // Note: do not check hits max here if you want to multiply against gold
                    // the max hits have not been set when this function is called
                    // The inital loot is added to the BaseCreature before the attributes are set
                    // for the specific mob type
				    if (item is Gold)
				    {
				        item.Amount = (int) Math.Ceiling(Quantity.Roll() * DynamicSettingsController.GoldMulti);                        
				    }
				    else
				    {
                        item.Amount = Quantity.Roll();
				    }
				}
			}

			return item;
		}
Esempio n. 16
0
		public override bool IgnoreYoungProtection( Mobile from )
		{
			if ( Completed )
				return false;

			Type fromType = from.GetType();

			for ( int i = 0; i < m_Images.Length; i++ )
			{
				ImageTypeInfo info = ImageTypeInfo.Get( m_Images[i] );

				if ( info.Type == fromType )
					return true;
			}

			return false;
		}
Esempio n. 17
0
        private static void LoadEntities()
        {
            ItemEntry[]   itemEntries   = null;
            MobileEntry[] mobileEntries = null;
            GuildEntry[]  guildEntries  = null;
            RegionEntry[] regionEntries = null;

            if (File.Exists(mobIdxPath) && File.Exists(mobTdbPath))
            {
                log.Debug("loading mobile index");
                EntityType[] types = LoadTypes(mobTdbPath);
                mobileEntries = LoadMobileIndex(mobIdxPath, types);
            }
            else
            {
                m_Mobiles = new Hashtable();
            }

            if (File.Exists(itemIdxPath) && File.Exists(itemTdbPath))
            {
                log.Debug("loading item index");
                EntityType[] types = LoadTypes(itemTdbPath);
                itemEntries = LoadItemIndex(itemIdxPath, types);
            }
            else
            {
                m_Items = new Hashtable();
            }

            if (File.Exists(guildIdxPath))
            {
                log.Debug("loading guild index");

                using (FileStream idx = new FileStream(guildIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader idxReader = new BinaryReader(idx);

                    int count = idxReader.ReadInt32();
                    guildEntries = new GuildEntry[count];

                    CreateGuildEventArgs createEventArgs = new CreateGuildEventArgs(-1);
                    for (int i = 0; i < count; ++i)
                    {
                        idxReader.ReadInt32();                        //no typeid for guilds
                        int  id     = idxReader.ReadInt32();
                        long pos    = idxReader.ReadInt64();
                        int  length = idxReader.ReadInt32();

                        createEventArgs.Id = id;
                        BaseGuild guild = EventSink.InvokeCreateGuild(createEventArgs);                          //new Guild( id );
                        if (guild != null)
                        {
                            guildEntries[i] = new GuildEntry(guild, pos, length);
                        }
                    }

                    idxReader.Close();
                }
            }

            if (File.Exists(regionIdxPath))
            {
                log.Debug("loading region index");

                using (FileStream idx = new FileStream(regionIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader idxReader = new BinaryReader(idx);

                    int count = idxReader.ReadInt32();
                    regionEntries = new RegionEntry[count];

                    for (int i = 0; i < count; ++i)
                    {
                        idxReader.ReadInt32();                         /* typeID */
                        int  serial = idxReader.ReadInt32();
                        long pos    = idxReader.ReadInt64();
                        int  length = idxReader.ReadInt32();

                        Region r = Region.FindByUId(serial);

                        if (r != null)
                        {
                            regionEntries[i] = new RegionEntry(r, pos, length);
                            Region.AddRegion(r);
                        }
                    }

                    idxReader.Close();
                }
            }

            bool      failedMobiles = false, failedItems = false, failedGuilds = false, failedRegions = false;
            Type      failedType   = null;
            Serial    failedSerial = Serial.Zero;
            Exception failed       = null;
            int       failedTypeID = 0;

            if (File.Exists(mobBinPath))
            {
                log.Debug("loading mobiles");

                using (FileStream bin = new FileStream(mobBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < mobileEntries.Length; ++i)
                    {
                        MobileEntry entry = mobileEntries[i];
                        Mobile      m     = (Mobile)entry.Object;

                        if (m != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try
                            {
                                m_LoadingType = entry.TypeName;
                                m.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on {0} *****", m.GetType()));
                                }
                            }
                            catch (Exception e)
                            {
                                log.Error("failed to load mobile", e);
                                mobileEntries[i].Clear();

                                failed        = e;
                                failedMobiles = true;
                                failedType    = m.GetType();
                                failedTypeID  = entry.TypeID;
                                failedSerial  = m.Serial;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }

                if (!failedMobiles)
                {
                    mobileEntries = null;
                }
            }

            if (!failedMobiles && File.Exists(itemBinPath))
            {
                log.Debug("loading items");

                using (FileStream bin = new FileStream(itemBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < itemEntries.Length; ++i)
                    {
                        ItemEntry entry = itemEntries[i];
                        Item      item  = (Item)entry.Object;

                        if (item != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try
                            {
                                m_LoadingType = entry.TypeName;
                                item.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on {0} *****", item.GetType()));
                                }
                            }
                            catch (Exception e)
                            {
                                log.Fatal("failed to load item", e);
                                itemEntries[i].Clear();

                                failed       = e;
                                failedItems  = true;
                                failedType   = item.GetType();
                                failedTypeID = entry.TypeID;
                                failedSerial = item.Serial;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }

                if (!failedItems)
                {
                    itemEntries = null;
                }
            }

            if (!failedMobiles && !failedItems && File.Exists(guildBinPath))
            {
                log.Debug("loading guilds");

                using (FileStream bin = new FileStream(guildBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < guildEntries.Length; ++i)
                    {
                        GuildEntry entry = guildEntries[i];
                        BaseGuild  g     = (BaseGuild)entry.Object;

                        if (g != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try
                            {
                                g.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on Guild {0} *****", g.Id));
                                }
                            }
                            catch (Exception e)
                            {
                                log.Fatal("failed to load guild", e);
                                guildEntries[i].Clear();

                                failed       = e;
                                failedGuilds = true;
                                failedType   = typeof(BaseGuild);
                                failedTypeID = g.Id;
                                failedSerial = g.Id;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }

                if (!failedGuilds)
                {
                    guildEntries = null;
                }
            }

            if (!failedMobiles && !failedItems && File.Exists(regionBinPath))
            {
                log.Debug("loading regions");

                using (FileStream bin = new FileStream(regionBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < regionEntries.Length; ++i)
                    {
                        RegionEntry entry = regionEntries[i];
                        Region      r     = (Region)entry.Object;

                        if (r != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try
                            {
                                r.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on {0} *****", r.GetType()));
                                }
                            }
                            catch (Exception e)
                            {
                                log.Fatal("failed to load region", e);
                                regionEntries[i].Clear();

                                failed        = e;
                                failedRegions = true;
                                failedType    = r.GetType();
                                failedTypeID  = entry.TypeID;
                                failedSerial  = r.UId;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }

                if (!failedRegions)
                {
                    regionEntries = null;
                }
            }

            if (failedItems || failedMobiles || failedGuilds || failedRegions)
            {
                Console.WriteLine("An error was encountered while loading a saved object");

                Console.WriteLine(" - Type: {0}", failedType);
                Console.WriteLine(" - Serial: {0}", failedSerial);

                Console.WriteLine("Delete the object? (y/n)");

                if (Console.ReadLine() == "y")
                {
                    if (failedType != typeof(BaseGuild) && !failedType.IsSubclassOf(typeof(Region)))
                    {
                        Console.WriteLine("Delete all objects of that type? (y/n)");

                        if (Console.ReadLine() == "y")
                        {
                            if (failedMobiles)
                            {
                                for (int i = 0; i < mobileEntries.Length; ++i)
                                {
                                    if (mobileEntries[i].TypeID == failedTypeID)
                                    {
                                        mobileEntries[i].Clear();
                                    }
                                }
                            }
                            else if (failedItems)
                            {
                                for (int i = 0; i < itemEntries.Length; ++i)
                                {
                                    if (itemEntries[i].TypeID == failedTypeID)
                                    {
                                        itemEntries[i].Clear();
                                    }
                                }
                            }
                        }
                    }

                    if (mobileEntries != null)
                    {
                        SaveIndex(mobileEntries, mobIdxPath);
                    }
                    if (itemEntries != null)
                    {
                        SaveIndex(itemEntries, itemIdxPath);
                    }
                    if (guildEntries != null)
                    {
                        SaveIndex(guildEntries, guildIdxPath);
                    }
                    if (regionEntries != null)
                    {
                        SaveIndex(regionEntries, regionIdxPath);
                    }
                }

                Console.WriteLine("After pressing return an exception will be thrown and the server will terminate");
                Console.ReadLine();

                throw new Exception(String.Format("Load failed (items={0}, mobiles={1}, guilds={2}, regions={3}, type={4}, serial={5})", failedItems, failedMobiles, failedGuilds, failedRegions, failedType, failedSerial), failed);
            }
        }
Esempio n. 18
0
        public Item Mutate(Mobile from, int luckChance, Item item)
        {
            if (item != null)
            {
                if (item is BaseWeapon && 1 > Utility.Random(100))
                {
                    item.Delete();
                    item = new FireHorn();
                    return(item);
                }

                if (item is BaseWeapon || item is BaseArmor || item is BaseJewel || item is BaseHat)
                {
                    if (Core.AOS)
                    {
                        int bonusProps = GetBonusProperties();

                        if (bonusProps < MaxProps && LootPack.CheckLuck(luckChance))
                        {
                            ++bonusProps;
                        }

                        int props = 1 + bonusProps;

                        // Make sure we're not spawning items with 6 properties.
                        if (props > MaxProps)
                        {
                            props = MaxProps;
                        }

                        if (item is BaseWeapon weapon)
                        {
                            BaseRunicTool.ApplyAttributesTo(weapon, false, luckChance, props, MinIntensity, MaxIntensity);
                        }
                        else if (item is BaseArmor armor)
                        {
                            BaseRunicTool.ApplyAttributesTo(armor, false, luckChance, props, MinIntensity, MaxIntensity);
                        }
                        else if (item is BaseJewel jewel)
                        {
                            BaseRunicTool.ApplyAttributesTo(jewel, false, luckChance, props, MinIntensity, MaxIntensity);
                        }
                        else if (item is BaseHat hat)
                        {
                            BaseRunicTool.ApplyAttributesTo(hat, false, luckChance, props, MinIntensity, MaxIntensity);
                        }
                    }
                    else                     // not aos
                    {
                        if (item is BaseWeapon weapon)
                        {
                            if (80 > Utility.Random(100))
                            {
                                weapon.AccuracyLevel = (WeaponAccuracyLevel)GetRandomOldBonus();
                            }

                            if (60 > Utility.Random(100))
                            {
                                weapon.DamageLevel = (WeaponDamageLevel)GetRandomOldBonus();
                            }

                            if (40 > Utility.Random(100))
                            {
                                weapon.DurabilityLevel = (DurabilityLevel)GetRandomOldBonus();
                            }

                            if (5 > Utility.Random(100))
                            {
                                weapon.Slayer = SlayerName.Silver;
                            }

                            if (from != null && weapon.AccuracyLevel == 0 && weapon.DamageLevel == 0 && weapon.DurabilityLevel == 0 && weapon.Slayer == SlayerName.None && 5 > Utility.Random(100))
                            {
                                weapon.Slayer = SlayerGroup.GetLootSlayerType(from.GetType());
                            }
                        }
                        else if (item is BaseArmor armor)
                        {
                            if (80 > Utility.Random(100))
                            {
                                armor.ProtectionLevel = (ArmorProtectionLevel)GetRandomOldBonus();
                            }

                            if (40 > Utility.Random(100))
                            {
                                armor.Durability = (DurabilityLevel)GetRandomOldBonus();
                            }
                        }
                    }
                }
                else if (item is BaseInstrument instrument)
                {
                    SlayerName slayer;
                    if (Core.AOS)
                    {
                        slayer = BaseRunicTool.GetRandomSlayer();
                    }
                    else
                    {
                        slayer = SlayerGroup.GetLootSlayerType(from.GetType());
                    }

                    if (slayer == SlayerName.None)
                    {
                        item.Delete();
                        return(null);
                    }

                    BaseInstrument instr = instrument;

                    instr.Quality = ItemQuality.Normal;
                    instr.Slayer  = slayer;
                }

                if (item.Stackable)
                {
                    item.Amount = Quantity.Roll();
                }
            }

            return(item);
        }
Esempio n. 19
0
        public Item Mutate(Mobile from, int luckChance, Item item)
        {
            if (item != null)
            {
                if (item is BaseWeapon || item is BaseArmor || item is BaseJewel)
                {
                    if (Core.AOS)
                    {
                        int bonusProps = GetBonusProperties();
                        int min        = m_MinIntensity;
                        int max        = m_MaxIntensity;

                        if (bonusProps < m_MaxProps && LootPack.CheckLuck(luckChance))
                        {
                            ++bonusProps;
                        }

                        int props = 1 + bonusProps;

                        if (item is BaseWeapon)
                        {
                            BaseRunicTool.ApplyAttributesTo((BaseWeapon)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity);
                        }
                        else if (item is BaseArmor)
                        {
                            BaseRunicTool.ApplyAttributesTo((BaseArmor)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity);
                        }
                        else if (item is BaseJewel)
                        {
                            BaseRunicTool.ApplyAttributesTo((BaseJewel)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity);
                        }
                    }
                    else                     // not aos
                    {
                        if (item is BaseWeapon)
                        {
                            BaseWeapon weapon = (BaseWeapon)item;

                            if (80 > Utility.Random(100))
                            {
                                weapon.AccuracyLevel = (WeaponAccuracyLevel)GetRandomOldBonus();
                            }

                            if (60 > Utility.Random(100))
                            {
                                weapon.DamageLevel = (WeaponDamageLevel)GetRandomOldBonus();
                            }

                            if (40 > Utility.Random(100))
                            {
                                weapon.DurabilityLevel = (WeaponDurabilityLevel)GetRandomOldBonus();
                            }

                            if (20 > Utility.Random(100))
                            {
                                weapon.Slayer = SlayerName.Silver;
                            }

                            if (weapon.AccuracyLevel == 0 && weapon.DamageLevel == 0 && weapon.DurabilityLevel == 0 && 35 > Utility.Random(100))
                            {
                                switch (Utility.Random(25))
                                {
                                case 0:
                                {
                                    weapon.Slayer = SlayerName.Silver;
                                    break;
                                }

                                case 1:
                                {
                                    weapon.Slayer = SlayerName.OrcSlaying;
                                    break;
                                }

                                case 2:
                                {
                                    weapon.Slayer = SlayerName.TrollSlaughter;
                                    break;
                                }

                                case 3:
                                {
                                    weapon.Slayer = SlayerName.OgreTrashing;
                                    break;
                                }

                                case 4:
                                {
                                    weapon.Slayer = SlayerName.Repond;
                                    break;
                                }

                                case 5:
                                {
                                    weapon.Slayer = SlayerName.DragonSlaying;
                                    break;
                                }

                                case 6:
                                {
                                    weapon.Slayer = SlayerName.Terathan;
                                    break;
                                }

                                case 7:
                                {
                                    weapon.Slayer = SlayerName.LizardmanSlaughter;
                                    break;
                                }

                                case 8:
                                {
                                    weapon.Slayer = SlayerName.ReptilianDeath;
                                    break;
                                }

                                case 9:
                                {
                                    weapon.Slayer = SlayerName.DaemonDismissal;
                                    break;
                                }

                                case 10:
                                {
                                    weapon.Slayer = SlayerName.GargoylesFoe;
                                    break;
                                }

                                case 11:
                                {
                                    weapon.Slayer = SlayerName.BalronDamnation;
                                    break;
                                }

                                case 12:
                                {
                                    weapon.Slayer = SlayerName.Exorcism;
                                    break;
                                }

                                case 13:
                                {
                                    weapon.Slayer = SlayerName.Ophidian;
                                    break;
                                }

                                case 14:
                                {
                                    weapon.Slayer = SlayerName.SpidersDeath;
                                    break;
                                }

                                case 15:
                                {
                                    weapon.Slayer = SlayerName.ScorpionsBane;
                                    break;
                                }

                                case 16:
                                {
                                    weapon.Slayer = SlayerName.ArachnidDoom;
                                    break;
                                }

                                case 17:
                                {
                                    weapon.Slayer = SlayerName.FlameDousing;
                                    break;
                                }

                                case 18:
                                {
                                    weapon.Slayer = SlayerName.WaterDissipation;
                                    break;
                                }

                                case 19:
                                {
                                    weapon.Slayer = SlayerName.Vacuum;
                                    break;
                                }

                                case 20:
                                {
                                    weapon.Slayer = SlayerName.ElementalHealth;
                                    break;
                                }

                                case 21:
                                {
                                    weapon.Slayer = SlayerName.EarthShatter;
                                    break;
                                }

                                case 22:
                                {
                                    weapon.Slayer = SlayerName.BloodDrinking;
                                    break;
                                }

                                case 23:
                                {
                                    weapon.Slayer = SlayerName.SummerWind;
                                    break;
                                }

                                case 24:
                                {
                                    weapon.Slayer = SlayerName.ElementalBan;
                                    break;
                                }

                                case 25:
                                {
                                    weapon.Slayer = SlayerName.Fey;
                                    break;
                                }
                                }
                            }
                        }
                        else if (item is BaseArmor)
                        {
                            BaseArmor armor = (BaseArmor)item;

                            if (80 > Utility.Random(100))
                            {
                                armor.ProtectionLevel = (ArmorProtectionLevel)GetRandomOldBonus();
                            }

                            if (40 > Utility.Random(100))
                            {
                                armor.Durability = (ArmorDurabilityLevel)GetRandomOldBonus();
                            }
                        }
                        else if (item is BaseJewel)
                        {
                            BaseJewel jewel = (BaseJewel)item;

                            if (80 > Utility.Random(100))
                            {
                                jewel.Effect = (MagicEffect)Utility.Random(0, 11);
                                jewel.Uses   = Utility.Random(1, 10);
                            }
                        }
                    }
                }
                else if (item is BaseInstrument)
                {
                    SlayerName slayer = SlayerName.None;

                    if (Core.AOS)
                    {
                        slayer = BaseRunicTool.GetRandomSlayer();
                    }
                    else
                    {
                        slayer = SlayerGroup.GetLootSlayerType(from.GetType());
                    }

                    if (slayer == SlayerName.None)
                    {
                        item.Delete();
                        return(null);
                    }

                    BaseInstrument instr = (BaseInstrument)item;

                    instr.Quality = InstrumentQuality.Regular;
                    instr.Slayer  = slayer;
                }

                if (item.Stackable)
                {
                    item.Amount = m_Quantity.Roll();
                }
            }

            return(item);
        }
Esempio n. 20
0
 public static int GetSaveFlag(Mobile m)
 {
     return ConversionTable.IndexOf(m.GetType()) + Offset;
 }
Esempio n. 21
0
        public static void Load()
        {
            if (m_Loaded)
            {
                return;
            }

            m_Loaded      = true;
            m_LoadingType = null;

            Console.Write("World: Loading...");

            DateTime start = DateTime.Now;

            m_Loading    = true;
            m_DeleteList = new ArrayList();

            int mobileCount = 0, itemCount = 0, guildCount = 0, regionCount = 0;

            object[] ctorArgs  = new object[1];
            Type[]   ctorTypes = new Type[1] {
                typeof(Serial)
            };

            ArrayList items   = new ArrayList();
            ArrayList mobiles = new ArrayList();
            ArrayList guilds  = new ArrayList();
            ArrayList regions = new ArrayList();

            if (File.Exists(mobIdxPath) && File.Exists(mobTdbPath))
            {
                using (FileStream idx = new FileStream(mobIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader idxReader = new BinaryReader(idx);

                    using (FileStream tdb = new FileStream(mobTdbPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        BinaryReader tdbReader = new BinaryReader(tdb);

                        int count = tdbReader.ReadInt32();

                        ArrayList types = new ArrayList(count);

                        for (int i = 0; i < count; ++i)
                        {
                            string typeName = tdbReader.ReadString();

                            Type t = ScriptCompiler.FindTypeByFullName(typeName);

                            if (t == null)
                            {
                                Console.WriteLine("failed");
                                Console.WriteLine("Error: Type '{0}' was not found. Delete all of those types? (y/n)", typeName);

                                if (Console.ReadLine() == "y")
                                {
                                    types.Add(null);
                                    Console.Write("World: Loading...");
                                    continue;
                                }

                                Console.WriteLine("Types will not be deleted. An exception will be thrown when you press return");

                                throw new Exception(String.Format("Bad type '{0}'", typeName));
                            }

                            ConstructorInfo ctor = t.GetConstructor(ctorTypes);

                            if (ctor != null)
                            {
                                types.Add(new object[] { ctor, null });
                            }
                            else
                            {
                                throw new Exception(String.Format("Type '{0}' does not have a serialization constructor", t));
                            }
                        }

                        mobileCount = idxReader.ReadInt32();

                        m_Mobiles = new Hashtable(mobileCount);

                        for (int i = 0; i < mobileCount; ++i)
                        {
                            int  typeID = idxReader.ReadInt32();
                            int  serial = idxReader.ReadInt32();
                            long pos    = idxReader.ReadInt64();
                            int  length = idxReader.ReadInt32();

                            object[] objs = (object[])types[typeID];

                            if (objs == null)
                            {
                                continue;
                            }

                            Mobile          m        = null;
                            ConstructorInfo ctor     = (ConstructorInfo)objs[0];
                            string          typeName = (string)objs[1];

                            try
                            {
                                ctorArgs[0] = (Serial)serial;
                                m           = (Mobile)(ctor.Invoke(ctorArgs));
                            }
                            catch
                            {
                            }

                            if (m != null)
                            {
                                mobiles.Add(new MobileEntry(m, typeID, typeName, pos, length));
                                AddMobile(m);
                            }
                        }

                        tdbReader.Close();
                    }

                    idxReader.Close();
                }
            }
            else
            {
                m_Mobiles = new Hashtable();
            }

            if (File.Exists(itemIdxPath) && File.Exists(itemTdbPath))
            {
                using (FileStream idx = new FileStream(itemIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader idxReader = new BinaryReader(idx);

                    using (FileStream tdb = new FileStream(itemTdbPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        BinaryReader tdbReader = new BinaryReader(tdb);

                        int count = tdbReader.ReadInt32();

                        ArrayList types = new ArrayList(count);

                        for (int i = 0; i < count; ++i)
                        {
                            string typeName = tdbReader.ReadString();

                            Type t = ScriptCompiler.FindTypeByFullName(typeName);

                            if (t == null)
                            {
                                Console.WriteLine("failed");
                                Console.WriteLine("Error: Type '{0}' was not found. Delete all of those types? (y/n)", typeName);

                                if (Console.ReadLine() == "y")
                                {
                                    types.Add(null);
                                    Console.Write("World: Loading...");
                                    continue;
                                }

                                Console.WriteLine("Types will not be deleted. An exception will be thrown when you press return");

                                throw new Exception(String.Format("Bad type '{0}'", typeName));
                            }

                            ConstructorInfo ctor = t.GetConstructor(ctorTypes);

                            if (ctor != null)
                            {
                                types.Add(new object[] { ctor, typeName });
                            }
                            else
                            {
                                throw new Exception(String.Format("Type '{0}' does not have a serialization constructor", t));
                            }
                        }

                        itemCount = idxReader.ReadInt32();

                        m_Items = new Hashtable(itemCount);

                        for (int i = 0; i < itemCount; ++i)
                        {
                            int  typeID = idxReader.ReadInt32();
                            int  serial = idxReader.ReadInt32();
                            long pos    = idxReader.ReadInt64();
                            int  length = idxReader.ReadInt32();

                            object[] objs = (object[])types[typeID];

                            if (objs == null)
                            {
                                continue;
                            }

                            Item            item     = null;
                            ConstructorInfo ctor     = (ConstructorInfo)objs[0];
                            string          typeName = (string)objs[1];

                            try
                            {
                                ctorArgs[0] = (Serial)serial;
                                item        = (Item)(ctor.Invoke(ctorArgs));
                            }
                            catch
                            {
                            }

                            if (item != null)
                            {
                                items.Add(new ItemEntry(item, typeID, typeName, pos, length));
                                AddItem(item);
                            }
                        }

                        tdbReader.Close();
                    }

                    idxReader.Close();
                }
            }
            else
            {
                m_Items = new Hashtable();
            }

            if (File.Exists(guildIdxPath))
            {
                using (FileStream idx = new FileStream(guildIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader idxReader = new BinaryReader(idx);

                    guildCount = idxReader.ReadInt32();

                    CreateGuildEventArgs createEventArgs = new CreateGuildEventArgs(-1);
                    for (int i = 0; i < guildCount; ++i)
                    {
                        idxReader.ReadInt32();                        //no typeid for guilds
                        int  id     = idxReader.ReadInt32();
                        long pos    = idxReader.ReadInt64();
                        int  length = idxReader.ReadInt32();

                        createEventArgs.Id = id;
                        BaseGuild guild = EventSink.InvokeCreateGuild(createEventArgs);                          //new Guild( id );
                        if (guild != null)
                        {
                            guilds.Add(new GuildEntry(guild, pos, length));
                        }
                    }

                    idxReader.Close();
                }
            }

            if (File.Exists(regionIdxPath))
            {
                using (FileStream idx = new FileStream(regionIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader idxReader = new BinaryReader(idx);

                    regionCount = idxReader.ReadInt32();

                    for (int i = 0; i < regionCount; ++i)
                    {
                        int  typeID = idxReader.ReadInt32();
                        int  serial = idxReader.ReadInt32();
                        long pos    = idxReader.ReadInt64();
                        int  length = idxReader.ReadInt32();

                        Region r = Region.FindByUId(serial);

                        if (r != null)
                        {
                            regions.Add(new RegionEntry(r, pos, length));
                            Region.AddRegion(r);
                            regionCount++;
                        }
                    }

                    idxReader.Close();
                }
            }

            bool      failedMobiles = false, failedItems = false, failedGuilds = false, failedRegions = false;
            Type      failedType   = null;
            Serial    failedSerial = Serial.Zero;
            Exception failed       = null;
            int       failedTypeID = 0;

            if (File.Exists(mobBinPath))
            {
                using (FileStream bin = new FileStream(mobBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < mobiles.Count; ++i)
                    {
                        MobileEntry entry = (MobileEntry)mobiles[i];
                        Mobile      m     = (Mobile)entry.Object;

                        if (m != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try
                            {
                                m_LoadingType = entry.TypeName;
                                m.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on {0} *****", m.GetType()));
                                }
                            }
                            catch (Exception e)
                            {
                                mobiles.RemoveAt(i);

                                failed        = e;
                                failedMobiles = true;
                                failedType    = m.GetType();
                                failedTypeID  = entry.TypeID;
                                failedSerial  = m.Serial;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }
            }

            if (!failedMobiles && File.Exists(itemBinPath))
            {
                using (FileStream bin = new FileStream(itemBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < items.Count; ++i)
                    {
                        ItemEntry entry = (ItemEntry)items[i];
                        Item      item  = (Item)entry.Object;

                        if (item != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try
                            {
                                m_LoadingType = entry.TypeName;
                                item.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on {0} *****", item.GetType()));
                                }
                            }
                            catch (Exception e)
                            {
                                items.RemoveAt(i);

                                failed       = e;
                                failedItems  = true;
                                failedType   = item.GetType();
                                failedTypeID = entry.TypeID;
                                failedSerial = item.Serial;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }
            }

            m_LoadingType = null;

            if (!failedMobiles && !failedItems && File.Exists(guildBinPath))
            {
                using (FileStream bin = new FileStream(guildBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < guilds.Count; ++i)
                    {
                        GuildEntry entry = (GuildEntry)guilds[i];
                        BaseGuild  g     = (BaseGuild)entry.Object;

                        if (g != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try
                            {
                                g.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on Guild {0} *****", g.Id));
                                }
                            }
                            catch (Exception e)
                            {
                                guilds.RemoveAt(i);

                                failed       = e;
                                failedGuilds = true;
                                failedType   = typeof(BaseGuild);
                                failedTypeID = g.Id;
                                failedSerial = g.Id;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }
            }

            if (!failedMobiles && !failedItems && File.Exists(regionBinPath))
            {
                using (FileStream bin = new FileStream(regionBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < regions.Count; ++i)
                    {
                        RegionEntry entry = (RegionEntry)regions[i];
                        Region      r     = (Region)entry.Object;

                        if (r != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try
                            {
                                r.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on {0} *****", r.GetType()));
                                }
                            }
                            catch (Exception e)
                            {
                                regions.RemoveAt(i);

                                failed        = e;
                                failedRegions = true;
                                failedType    = r.GetType();
                                failedTypeID  = entry.TypeID;
                                failedSerial  = r.UId;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }
            }

            if (failedItems || failedMobiles || failedGuilds || failedRegions)
            {
                Console.WriteLine("An error was encountered while loading a saved object");

                Console.WriteLine(" - Type: {0}", failedType);
                Console.WriteLine(" - Serial: {0}", failedSerial);

                Console.WriteLine("Delete the object? (y/n)");

                if (Console.ReadLine() == "y")
                {
                    if (failedType != typeof(BaseGuild) && !failedType.IsSubclassOf(typeof(Region)))
                    {
                        Console.WriteLine("Delete all objects of that type? (y/n)");

                        if (Console.ReadLine() == "y")
                        {
                            if (failedMobiles)
                            {
                                for (int i = 0; i < mobiles.Count;)
                                {
                                    if (((MobileEntry)mobiles[i]).TypeID == failedTypeID)
                                    {
                                        mobiles.RemoveAt(i);
                                    }
                                    else
                                    {
                                        ++i;
                                    }
                                }
                            }
                            else if (failedItems)
                            {
                                for (int i = 0; i < items.Count;)
                                {
                                    if (((ItemEntry)items[i]).TypeID == failedTypeID)
                                    {
                                        items.RemoveAt(i);
                                    }
                                    else
                                    {
                                        ++i;
                                    }
                                }
                            }
                        }
                    }

                    SaveIndex(mobiles, mobIdxPath);
                    SaveIndex(items, itemIdxPath);
                    SaveIndex(guilds, guildIdxPath);
                    SaveIndex(regions, regionIdxPath);
                }

                Console.WriteLine("After pressing return an exception will be thrown and the server will terminate");
                Console.ReadLine();

                throw new Exception(String.Format("Load failed (items={0}, mobiles={1}, guilds={2}, regions={3}, type={4}, serial={5})", failedItems, failedMobiles, failedGuilds, failedRegions, failedType, failedSerial), failed);
            }

            EventSink.InvokeWorldLoad();

            m_Loading = false;

            for (int i = 0; i < m_DeleteList.Count; ++i)
            {
                object o = m_DeleteList[i];

                if (o is Item)
                {
                    ((Item)o).Delete();
                }
                else if (o is Mobile)
                {
                    ((Mobile)o).Delete();
                }
            }

            m_DeleteList.Clear();

            foreach (Item item in m_Items.Values)
            {
                if (item.Parent == null)
                {
                    item.UpdateTotals();
                }

                item.ClearProperties();
            }

            ArrayList list = new ArrayList(m_Mobiles.Values);

            foreach (Mobile m in list)
            {
                m.ForceRegionReEnter(true);
                m.UpdateTotals();

                m.ClearProperties();
            }

            Console.WriteLine("done ({1} items, {2} mobiles) ({0:F1} seconds)", (DateTime.Now - start).TotalSeconds, m_Items.Count, m_Mobiles.Count);
        }
Esempio n. 22
0
        public Item Mutate(Mobile from, int luckChance, Item item)
        {
            if (item != null)
            {
                if (item is BaseWeapon && 1 > Utility.Random(100))
                {
                    item.Delete();
                    item = new FireHorn();
                    return(item);
                }

                if (item is BaseWeapon || item is BaseArmor || item is BaseJewel || item is BaseHat)
                {
                    if (item is BaseWeapon)
                    {
                        BaseWeapon weapon = (BaseWeapon)item;

                        if (80 > Utility.Random(100))
                        {
                            weapon.AccuracyLevel = (WeaponAccuracyLevel)GetRandomOldBonus();
                        }

                        if (60 > Utility.Random(100))
                        {
                            weapon.DamageLevel = (WeaponDamageLevel)GetRandomOldBonus();
                        }

                        if (40 > Utility.Random(100))
                        {
                            weapon.DurabilityLevel = (WeaponDurabilityLevel)GetRandomOldBonus();
                        }

                        if (5 > Utility.Random(100))
                        {
                            weapon.Slayer = SlayerName.Silver;
                        }

                        if (from != null && weapon.AccuracyLevel == 0 && weapon.DamageLevel == 0 && weapon.DurabilityLevel == 0 &&
                            weapon.Slayer == SlayerName.None && 5 > Utility.Random(100))
                        {
                            weapon.Slayer = SlayerGroup.GetLootSlayerType(from.GetType());
                        }
                    }
                    else if (item is BaseArmor)
                    {
                        BaseArmor armor = (BaseArmor)item;

                        if (80 > Utility.Random(100))
                        {
                            armor.ProtectionLevel = (ArmorProtectionLevel)GetRandomOldBonus();
                        }

                        if (40 > Utility.Random(100))
                        {
                            armor.Durability = (ArmorDurabilityLevel)GetRandomOldBonus();
                        }
                    }
                }
                else if (item is BaseInstrument)
                {
                    SlayerName slayer = SlayerName.None;

                    slayer = SlayerGroup.GetLootSlayerType(from.GetType());

                    if (slayer == SlayerName.None)
                    {
                        item.Delete();
                        return(null);
                    }

                    BaseInstrument instr = (BaseInstrument)item;

                    instr.Quality = InstrumentQuality.Regular;
                    instr.Slayer  = slayer;
                }

                if (item.Stackable)
                {
                    item.Amount = m_Quantity.Roll();
                }
            }

            return(item);
        }
Esempio n. 23
0
		public static bool Slays( TalismanSlayerName name, Mobile m )
		{
			if ( name == TalismanSlayerName.None )
				return false;

			Type[] types = m_Table[ name ];
			
			if ( types == null || m == null )
				return false;

			Type type = m.GetType();
				
			for ( int i = 0; i < types.Length; i++ )
			{
				if ( types[ i ] == type )
					return true;
			}
			
			return false;
		}
Esempio n. 24
0
        public Item Mutate(Mobile from, int luckChance, Item item)
        {
            if (item != null && !(item is BaseWand))
            {
                if (item is BaseWeapon && 1 > Utility.Random(100))
                {
                    item.Delete();
                    item = new FireHorn();
                    return(item);
                }

                if (item is BaseWeapon || item is BaseArmor || item is BaseJewel || item is BaseHat)
                {
                    /*
                     * if ( Core.AOS )
                     * {
                     *      int bonusProps = GetBonusProperties();
                     *      int min = m_MinIntensity;
                     *      int max = m_MaxIntensity;
                     *
                     *      if ( bonusProps < m_MaxProps && LootPack.CheckLuck( luckChance ) )
                     ++bonusProps;
                     *
                     *      int props = 1 + bonusProps;
                     *
                     *      // Make sure we're not spawning items with 6 properties.
                     *      if ( props > m_MaxProps )
                     *              props = m_MaxProps;
                     *
                     *      if ( item is BaseWeapon )
                     *              BaseRunicTool.ApplyAttributesTo( (BaseWeapon)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity );
                     *      else if ( item is BaseArmor )
                     *              BaseRunicTool.ApplyAttributesTo( (BaseArmor)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity );
                     *      else if ( item is BaseJewel )
                     *              BaseRunicTool.ApplyAttributesTo( (BaseJewel)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity );
                     *      else if ( item is BaseHat )
                     *              BaseRunicTool.ApplyAttributesTo( (BaseHat)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity );
                     * }
                     * else // not aos
                     * { */
                    if (item is BaseWeapon)
                    {
                        BaseWeapon weapon = (BaseWeapon)item;

                        if (55 > Utility.Random(100))
                        {
                            weapon.AccuracyLevel = (WeaponAccuracyLevel)GetRandomOldBonus();
                        }

                        if (45 > Utility.Random(100))
                        {
                            weapon.DamageLevel = (WeaponDamageLevel)GetRandomOldBonus();
                        }

                        if (25 > Utility.Random(100))
                        {
                            weapon.DurabilityLevel = (WeaponDurabilityLevel)GetRandomOldBonus();
                        }

                        if (5 > Utility.Random(100))
                        {
                            weapon.Slayer = SlayerName.Silver;
                        }

                        if (1 > Utility.Random(1000) || (weapon.AccuracyLevel == 0 && weapon.DamageLevel == 0 && weapon.DurabilityLevel == 0 && weapon.Slayer == SlayerName.None && 5 > Utility.Random(100)))
                        {
                            if (from != null)
                            {
                                weapon.Slayer = SlayerGroup.GetLootSlayerType(from.GetType());
                            }
                            else
                            {
                                weapon.Slayer = BaseRunicTool.GetRandomSlayer();
                            }
                        }
                    }
                    else if (item is BaseArmor)
                    {
                        BaseArmor armor = (BaseArmor)item;

                        if (55 > Utility.Random(100))
                        {
                            armor.ProtectionLevel = (ArmorProtectionLevel)GetRandomOldBonus();
                        }

                        if (25 > Utility.Random(100))
                        {
                            armor.Durability = (ArmorDurabilityLevel)GetRandomOldBonus();
                        }
                    }
                    //}
                }
                else if (item is BaseInstrument)
                {
                    SlayerName slayer = SlayerName.None;

                    if (/*Core.AOS ||*/ from == null)
                    {
                        slayer = BaseRunicTool.GetRandomSlayer();
                    }
                    else
                    {
                        slayer = SlayerGroup.GetLootSlayerType(from.GetType());
                    }

/*
 *                                      if ( slayer == SlayerName.None )
 *                                      {
 *                                              item.Delete();
 *                                              return null;
 *                                      }
 */
                    BaseInstrument instr = (BaseInstrument)item;

                    instr.Quality = InstrumentQuality.Regular;
                    instr.Slayer  = slayer;
                }

                if (item.Stackable)
                {
                    item.Amount = m_Quantity.Roll();
                }
            }

            return(item);
        }
Esempio n. 25
0
        public override Tuple <Item[], int> GenerateLootItem(Mobile creature)
        {
            Type       type   = m_WeaponTypes[Utility.Random(m_WeaponTypes.Length)];
            BaseWeapon weapon = Activator.CreateInstance(type) as BaseWeapon;

            if (weapon == null)
            {
                throw new Exception(String.Format("Type {0} is not BaseWeapon or could not be instantiated.", type));
            }

            int value = 100;

            if (0.40 > Utility.RandomDouble())
            {
                int bonus = GetBonus();
                weapon.AccuracyLevel = (WeaponAccuracyLevel)bonus;
                value += 20 * bonus;
            }

            if (0.30 > Utility.RandomDouble())
            {
                int bonus = GetBonus();
                if (PseudoSeerStone.Instance != null && PseudoSeerStone.Instance._HighestDamageLevelSpawn < bonus)
                {
                    bonus = PseudoSeerStone.Instance._HighestDamageLevelSpawn;
                }
                weapon.DamageLevel = (WeaponDamageLevel)bonus;
                value += 20 * bonus;
            }

            if (0.25 > Utility.RandomDouble())
            {
                int bonus = GetBonus();
                weapon.DurabilityLevel = (WeaponDurabilityLevel)bonus;
                value += 20 * bonus;
            }

            if (GetBonus() > 2)
            {
                if (0.10 > Utility.RandomDouble())
                {
                    weapon.Slayer = SlayerName.Silver;
                    value        += 100;
                }

                if (0.01 > Utility.RandomDouble() || (weapon.AccuracyLevel == 0 && weapon.DamageLevel == 0 && weapon.DurabilityLevel == 0 && weapon.Slayer == SlayerName.None && 0.15 > Utility.RandomDouble()))
                {
                    if (creature != null)
                    {
                        weapon.Slayer = SlayerGroup.GetLootSlayerType(creature.GetType());
                    }
                    else
                    {
                        weapon.Slayer = BaseRunicTool.GetRandomSlayer();
                    }

                    value += 100;
                }
            }

            if (weapon.Hue == 0 && 0.01 > Utility.RandomDouble())
            {
                int bonus = GetBonus();

                if (bonus > 2 && 0.045 > Utility.RandomDouble())
                {
                    weapon.Hue = Math.Max(0, GetLowRareHue());
                    value     += 600;
                }
                else if (bonus > 3 && 0.005 > Utility.RandomDouble())
                {
                    weapon.Hue = Math.Max(0, GetHighRareHue());
                    value     += 1200;
                }
                else if (weapon.Resource != CraftResource.RegularWood && bonus == 5 && 0.001 > Utility.RandomDouble())
                {
                    weapon.Hue = Math.Max(0, GetVeryRareHue());
                    value     += 1550;
                }
            }

            return(new Tuple <Item[], int>(new Item[] { weapon }, value));
        }
		private static bool MatchType( ArrayList array, Mobile m)
		{
			if(array == null || m == null) return false;

			foreach( object o in array)
			{
				if(o is Type && ((Type)o == m.GetType() || ((Type)o).IsSubclassOf(m.GetType()))) return true;
			}
			return false;
		}
Esempio n. 27
0
		public int DamageBonus( Mobile to )
		{
			if ( to != null && to.GetType() == m_Type )
				return m_Amount;

			return 0;
		}
Esempio n. 28
0
		public static void HandleKill( PlayerMobile pm, Mobile mob )
		{
			MLQuestContext context = GetContext( pm );

			if ( context == null )
				return;

			List<MLQuestInstance> instances = context.QuestInstances;

			Type type = null;

			for ( int i = instances.Count - 1; i >= 0; --i )
			{
				MLQuestInstance instance = instances[i];

				if ( instance.ClaimReward )
					continue;

				/* A kill only counts for a single objective within a quest,
				 * but it can count for multiple quests. This is something not
				 * currently observable on OSI, so it is assumed behavior.
				 */
				foreach ( BaseObjectiveInstance objective in instance.Objectives )
				{
					if ( !objective.Expired && objective is KillObjectiveInstance )
					{
						KillObjectiveInstance kill = (KillObjectiveInstance)objective;

						if ( type == null )
							type = mob.GetType();

						if ( kill.AddKill( mob, type ) )
						{
							kill.CheckComplete();
							break;
						}
					}
				}
			}
		}
		public override void Damage(int amount, Mobile from)
		{
			if (Spells.Necromancy.EvilOmenSpell.TryEndEffect(this))
				amount = (int)(amount * 1.25);

			Mobile oath = Spells.Necromancy.BloodOathSpell.GetBloodOath(from);

			/* Per EA's UO Herald Pub48 (ML):
			 * ((resist spellsx10)/20 + 10=percentage of damage resisted)
			 */

			if (oath == this)
			{
				amount = (int)(amount * 1.1);

				if (amount > 35 && from is PlayerMobile)  /* capped @ 35, seems no expansion */
				{
					amount = 35;
				}

				if (Core.ML)
				{
					from.Damage((int)(amount * (1 - (((from.Skills.MagicResist.Value * .5) + 10) / 100))), this);
				}
				else
				{
					from.Damage(amount, this);
				}
			}

			if (from != null && Talisman is BaseTalisman)
			{
				BaseTalisman talisman = (BaseTalisman)Talisman;

				if (talisman.Protection != null && talisman.Protection.Type != null)
				{
					Type type = talisman.Protection.Type;

					if (type == from.GetType())
						amount *= 1 - (int)(((double)talisman.Protection.Amount) / 100);
				}
			}

			base.Damage(amount, from);
		}
Esempio n. 30
0
        public virtual bool IsObjective( Mobile mob )
        {
            if ( m_Creatures == null )
                return false;

            if ( m_Region != null && !m_Region.Contains( mob.Location ) )
                return false;

            for ( int i = 0; i < m_Creatures.Length; i++ )
            {
                Type creature = m_Creatures[i];

                if ( creature.IsAssignableFrom( mob.GetType() ) )
                    return true;
            }

            return false;
        }
Esempio n. 31
0
		public Item Mutate(Mobile from, int luckChance, Item item)
		{
			if (item != null)
			{
				if (item is BaseWeapon && 1 > Utility.Random(100))
				{
					item.Delete();
					item = new FireHorn();
					return item;
				}

				if (item is BaseWeapon || item is BaseArmor || item is BaseJewel || item is BaseHat)
				{
					if (Core.AOS)
					{
                        // Try to generate a new random item based on the creature killed
                        if (from is BaseCreature)
                        {
                            if (RandomItemGenerator.GenerateRandomItem(item, ((BaseCreature)from).LastKiller, (BaseCreature)from))
                                return item;
                        }

                        int bonusProps = GetBonusProperties();
						int min = m_MinIntensity;
						int max = m_MaxIntensity;

						if (bonusProps < m_MaxProps && LootPack.CheckLuck(luckChance))
						{
							++bonusProps;
						}

						int props = 1 + bonusProps;

						// Make sure we're not spawning items with 6 properties.
						if (props > m_MaxProps)
						{
							props = m_MaxProps;
						}

                        // Use the older style random generation
						if (item is BaseWeapon)
						{
							BaseRunicTool.ApplyAttributesTo((BaseWeapon)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity);
						}
						else if (item is BaseArmor)
						{
							BaseRunicTool.ApplyAttributesTo((BaseArmor)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity);
						}
						else if (item is BaseJewel)
						{
							BaseRunicTool.ApplyAttributesTo((BaseJewel)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity);
						}
						else if (item is BaseHat)
						{
							BaseRunicTool.ApplyAttributesTo((BaseHat)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity);
						}
					}
					else // not aos
					{
						if (item is BaseWeapon)
						{
							BaseWeapon weapon = (BaseWeapon)item;

							if (80 > Utility.Random(100))
							{
								weapon.AccuracyLevel = (WeaponAccuracyLevel)GetRandomOldBonus();
							}

							if (60 > Utility.Random(100))
							{
								weapon.DamageLevel = (WeaponDamageLevel)GetRandomOldBonus();
							}

							if (40 > Utility.Random(100))
							{
								weapon.DurabilityLevel = (WeaponDurabilityLevel)GetRandomOldBonus();
							}

							if (5 > Utility.Random(100))
							{
								weapon.Slayer = SlayerName.Silver;
							}

							if (from != null && weapon.AccuracyLevel == 0 && weapon.DamageLevel == 0 && weapon.DurabilityLevel == 0 &&
								weapon.Slayer == SlayerName.None && 5 > Utility.Random(100))
							{
								weapon.Slayer = SlayerGroup.GetLootSlayerType(from.GetType());
							}
						}
						else if (item is BaseArmor)
						{
							BaseArmor armor = (BaseArmor)item;

							if (80 > Utility.Random(100))
							{
								armor.ProtectionLevel = (ArmorProtectionLevel)GetRandomOldBonus();
							}

							if (40 > Utility.Random(100))
							{
								armor.Durability = (ArmorDurabilityLevel)GetRandomOldBonus();
							}
						}
					}
				}
				else if (item is BaseInstrument)
				{
					SlayerName slayer = SlayerName.None;

					if (Core.AOS)
					{
						slayer = BaseRunicTool.GetRandomSlayer();
					}
					else
					{
						slayer = SlayerGroup.GetLootSlayerType(from.GetType());
					}

					if (slayer == SlayerName.None)
					{
						item.Delete();
						return null;
					}

					BaseInstrument instr = (BaseInstrument)item;

					instr.Quality = InstrumentQuality.Regular;
					instr.Slayer = slayer;
				}

				if (item.Stackable)
				{
					item.Amount = m_Quantity.Roll();
				}
			}

			return item;
		}
Esempio n. 32
0
        public static string GetCorpseName( Mobile m )
        {
            Type t = m.GetType();

            object[] attrs = t.GetCustomAttributes( typeof( CorpseNameAttribute ), true );

            if ( attrs != null && attrs.Length > 0 )
            {
                CorpseNameAttribute attr = attrs[0] as CorpseNameAttribute;

                if ( attr != null )
                    return attr.Name;
            }

            return null;
        }
Esempio n. 33
0
        public Item Mutate(Mobile from, Item item)
        {
            if (item != null && !(item is BaseWand))
            {
                if (item is BaseWeapon && 1 > Utility.Random(100))
                {
                    item.Delete();
                    item = new FireHorn();
                    return(item);
                }

                if (item is BaseWeapon || item is BaseArmor || item is BaseJewel || item is BaseHat)
                {
                    if (item is BaseWeapon)
                    {
                        var weapon = (BaseWeapon)item;

                        if (55 > Utility.Random(100))
                        {
                            weapon.AccuracyLevel = (WeaponAccuracyLevel)GetRandomOldBonus();
                        }

                        if (45 > Utility.Random(100))
                        {
                            int damageLevel = GetRandomOldBonus();

                            if (PseudoSeerStone.Instance != null && PseudoSeerStone.Instance._HighestDamageLevelSpawn < damageLevel)
                            {
                                if (damageLevel == 5 && PseudoSeerStone.ReplaceVanqWithSkillScrolls)
                                {
                                    return(PuzzleChest.CreateRandomSkillScroll());
                                }
                                int platAmount = PseudoSeerStone.PlatinumPerMissedDamageLevel *
                                                 (damageLevel - PseudoSeerStone.Instance._HighestDamageLevelSpawn);
                                if (platAmount > 0)
                                {
                                    return(new Platinum(platAmount));
                                }
                                damageLevel = PseudoSeerStone.Instance._HighestDamageLevelSpawn;
                            }
                            weapon.DamageLevel = (WeaponDamageLevel)damageLevel;
                        }

                        if (25 > Utility.Random(100))
                        {
                            weapon.DurabilityLevel = (WeaponDurabilityLevel)GetRandomOldBonus();
                        }

                        if (5 > Utility.Random(100))
                        {
                            weapon.Slayer = SlayerName.Silver;
                        }

                        if (1 > Utility.Random(1000) ||
                            (weapon.AccuracyLevel == 0 && weapon.DamageLevel == 0 && weapon.DurabilityLevel == 0 &&
                             weapon.Slayer == SlayerName.None && 5 > Utility.Random(100)))
                        {
                            weapon.Slayer = from != null?SlayerGroup.GetLootSlayerType(from.GetType()) : BaseRunicTool.GetRandomSlayer();
                        }

                        if (weapon.AccuracyLevel == 0 && weapon.DamageLevel == 0 && weapon.DurabilityLevel == 0 &&
                            weapon.Slayer == SlayerName.None)
                        {
                            weapon.Identified = true;
                        }
                    }
                    else if (item is BaseArmor)
                    {
                        var armor = (BaseArmor)item;

                        if (55 > Utility.Random(100))
                        {
                            armor.ProtectionLevel = (ArmorProtectionLevel)GetRandomOldBonus();
                        }

                        if (25 > Utility.Random(100))
                        {
                            armor.Durability = (ArmorDurabilityLevel)GetRandomOldBonus();
                        }

                        if (armor.ProtectionLevel == 0 && armor.Durability == 0)
                        {
                            armor.Identified = true;
                        }
                    }
                }
                else if (item is BaseInstrument)
                {
                    SlayerName slayer = from == null || from.EraAOS
                                                                                        ? BaseRunicTool.GetRandomSlayer()
                                                                                        : SlayerGroup.GetLootSlayerType(from.GetType());

                    var instr = (BaseInstrument)item;

                    instr.Quality = InstrumentQuality.Regular;
                    instr.Slayer  = slayer;
                }
                else if (item is Spellbook)                 //Randomize spellbook
                {
                    var book = item as Spellbook;

                    if (MaxIntensity == 100 && MinIntensity / 1000.0 > Utility.RandomDouble())
                    {
                        book.LootType = LootType.Blessed;
                    }

                    if (MaxIntensity == 100 && MinIntensity >= 50 && (MinIntensity / 3000.0 > Utility.RandomDouble()))
                    {
                        book.Dyable = true;
                    }

                    int rnd    = Utility.RandomMinMax(MinIntensity, MaxIntensity);
                    var circle = (int)((rnd / 12.5) + 1.0);

                    if (circle >= 8 && 0.33 > Utility.RandomDouble())
                    {
                        book.Content = ulong.MaxValue;
                    }
                    else
                    {
                        circle = Math.Min(circle, 8);

                        //do we fill this circle?
                        for (int i = 0; i < circle; i++)
                        {
                            if (Utility.RandomBool())
                            {
                                book.Content |= (ulong)Utility.Random(0x100) << (i * 8);
                            }
                        }
                    }
                }

                if (item.Stackable)
                {
                    // Note: do not check hits max here if you want to multiply against gold
                    // the max hits have not been set when this function is called
                    // The inital loot is added to the BaseCreature before the attributes are set
                    // for the specific mob type
                    if (item is Gold)
                    {
                        item.Amount = (int)Math.Ceiling(Quantity.Roll() * DynamicSettingsController.GoldMulti);
                    }
                    else
                    {
                        item.Amount = Quantity.Roll();
                    }
                }
            }

            return(item);
        }
Esempio n. 34
0
        public Item Mutate(Mobile from, int luckChance, Item item)
        {
            if (item != null)
            {
                if (item is BaseWeapon && 1 > Utility.Random(100))
                {
                    item.Delete();
                    item = new FireHorn();
                    return(item);
                }

                if (item is BaseWeapon || item is BaseArmor || item is BaseJewel || item is BaseHat || item is BaseEarrings)
                {
                    if (Core.AOS)
                    {
                        int bonusProps = GetBonusProperties();
                        int min        = m_MinIntensity;
                        int max        = m_MaxIntensity;

                        if (bonusProps < m_MaxProps && LootPack.CheckLuck(luckChance))
                        {
                            ++bonusProps;
                        }

                        int props = 1 + bonusProps;

                        // Make sure we're not spawning items with too many properties.
                        if (props > m_MaxProps)
                        {
                            props = m_MaxProps;
                        }

                        if (item is BaseWeapon)
                        {
                            BaseRunicTool.ApplyAttributesTo((BaseWeapon)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity);
                        }
                        else if (item is BaseArmor)
                        {
                            BaseRunicTool.ApplyAttributesTo((BaseArmor)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity);
                        }
                        else if (item is BaseJewel)
                        {
                            BaseRunicTool.ApplyAttributesTo((BaseJewel)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity);
                        }
                        else if (item is BaseHat)
                        {
                            BaseRunicTool.ApplyAttributesTo((BaseHat)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity);
                        }
                        else if (item is BaseEarrings)
                        {
                            BaseRunicTool.ApplyAttributesTo((BaseEarrings)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity);
                        }

                        if (bonusProps >= 5 || item is BaseEarrings)  //Item is epic and should be cursed 95% chance
                        {
                            if (Utility.RandomDouble() > .05)
                            {
                                item.LootType = LootType.Cursed;
                            }
                        }
                    }
                    else                     // not aos
                    {
                        if (item is BaseWeapon)
                        {
                            BaseWeapon weapon = (BaseWeapon)item;

                            if (80 > Utility.Random(100))
                            {
                                weapon.AccuracyLevel = (WeaponAccuracyLevel)GetRandomOldBonus();
                            }

                            if (60 > Utility.Random(100))
                            {
                                weapon.DamageLevel = (WeaponDamageLevel)GetRandomOldBonus();
                            }

                            if (40 > Utility.Random(100))
                            {
                                weapon.DurabilityLevel = (WeaponDurabilityLevel)GetRandomOldBonus();
                            }

                            if (5 > Utility.Random(100))
                            {
                                weapon.Slayer = SlayerName.Silver;
                            }

                            if (from != null && weapon.AccuracyLevel == 0 && weapon.DamageLevel == 0 && weapon.DurabilityLevel == 0 && weapon.Slayer == SlayerName.None && 5 > Utility.Random(100))
                            {
                                weapon.Slayer = SlayerGroup.GetLootSlayerType(from.GetType());
                            }
                        }
                        else if (item is BaseArmor)
                        {
                            BaseArmor armor = (BaseArmor)item;

                            if (80 > Utility.Random(100))
                            {
                                armor.ProtectionLevel = (ArmorProtectionLevel)GetRandomOldBonus();
                            }

                            if (40 > Utility.Random(100))
                            {
                                armor.Durability = (ArmorDurabilityLevel)GetRandomOldBonus();
                            }
                        }
                    }
                }
                else if (item is BaseInstrument)
                {
                    SlayerName slayer = SlayerName.None;
                    if (Core.AOS)
                    {
                        slayer = BaseRunicTool.GetRandomSlayer();
                    }
                    else
                    {
                        slayer = SlayerGroup.GetLootSlayerType(from.GetType());
                    }

                    if (slayer == SlayerName.None)
                    {
                        item.Delete();
                        return(null);
                    }

                    BaseInstrument instr = (BaseInstrument)item;

                    instr.Quality = InstrumentQuality.Regular;
                    if (instr.Slayer == SlayerName.None)
                    {
                        instr.Slayer = slayer;
                    }
                    else
                    {
                        instr.Slayer2 = slayer;
                    }
                    if (instr.Slayer2 != SlayerName.None)
                    {
                        if (Utility.RandomDouble() > .05)
                        {
                            item.LootType = LootType.Cursed;
                        }
                    }
                }

                if (item.Stackable)
                {
                    item.Amount = m_Quantity.Roll();
                }
            }

            return(item);
        }
Esempio n. 35
0
		public static string GetBodyName( Mobile m )
		{
			Type t = m.GetType();

			object[] attrs = t.GetCustomAttributes( typeof( SleepingNameAttribute ), true );

			if ( attrs != null && attrs.Length > 0 )
			{
				SleepingNameAttribute attr = attrs[0] as SleepingNameAttribute;

				if ( attr != null )
					return attr.Name;
			}

			return m.Name;
		}
Esempio n. 36
0
        public static int MobileNotoriety( Mobile source, Mobile target )
        {
            if ( Core.AOS && (target.Blessed || (target is BaseVendor && ((BaseVendor)target).IsInvulnerable) || target is PlayerVendor || target is TownCrier) )
                return Notoriety.Invulnerable;

            if ( target.AccessLevel > AccessLevel.Player )
                return Notoriety.CanBeAttacked;

            // MODIFICATIONS FOR Capture the Flag / Double Dom games
            Server.Items.CTFTeam ft = Server.Items.CTFGame.FindTeamFor( source );
            if ( ft != null )
            {
                Server.Items.CTFTeam tt = Server.Items.CTFGame.FindTeamFor( target );
                if ( tt != null && ft.Game == tt.Game )
                    return ft == tt ? Notoriety.Ally : Notoriety.Enemy;
            }

            if ( source.Player && !target.Player && source is PlayerMobile && target is BaseCreature )
            {
                BaseCreature bc = (BaseCreature)target;

                if ( !bc.Summoned && !bc.Controled && ((PlayerMobile)source).EnemyOfOneType == target.GetType() )
                    return Notoriety.Enemy;
            }

            if ( target.Kills >= 5 || (target.Body.IsMonster && IsSummoned( target as BaseCreature ) && !(target is BaseFamiliar) && !(target is Golem)) || (target is BaseCreature && (((BaseCreature)target).AlwaysMurderer || ((BaseCreature)target).IsAnimatedDead)) )
                return Notoriety.Murderer;

            if ( target.Criminal )
                return Notoriety.Criminal;

            Guild sourceGuild = GetGuildFor( source.Guild as Guild, source );
            Guild targetGuild = GetGuildFor( target.Guild as Guild, target );

            if ( sourceGuild != null && targetGuild != null )
            {
                if ( sourceGuild == targetGuild || sourceGuild.IsAlly( targetGuild ) )
                    return Notoriety.Ally;
                else if ( sourceGuild.IsEnemy( targetGuild ) )
                    return Notoriety.Enemy;
            }

            Faction srcFaction = Faction.Find( source, true, true );
            Faction trgFaction = Faction.Find( target, true, true );

            if ( srcFaction != null && trgFaction != null && srcFaction != trgFaction && source.Map == Faction.Facet )
                return Notoriety.Enemy;

            if ( SkillHandlers.Stealing.ClassicMode && target is PlayerMobile && ((PlayerMobile)target).PermaFlags.Contains( source ) )
                return Notoriety.CanBeAttacked;

            if ( target is BaseCreature && ((BaseCreature)target).AlwaysAttackable )
                return Notoriety.CanBeAttacked;

            if ( CheckHouseFlag( source, target, target.Location, target.Map ) )
                return Notoriety.CanBeAttacked;

            if ( !(target is BaseCreature && ((BaseCreature)target).InitialInnocent) )
            {
                if ( !target.Body.IsHuman && !target.Body.IsGhost && !IsPet( target as BaseCreature ) && !Server.Spells.Necromancy.TransformationSpell.UnderTransformation( target ) )
                    return Notoriety.CanBeAttacked;
            }

            if ( CheckAggressor( source.Aggressors, target ) )
                return Notoriety.CanBeAttacked;

            if ( CheckAggressed( source.Aggressed, target ) )
                return Notoriety.CanBeAttacked;

            if ( target is BaseCreature )
            {
                BaseCreature bc = (BaseCreature)target;

                if ( bc.Controled && bc.ControlOrder == OrderType.Guard && bc.ControlTarget == source )
                    return Notoriety.CanBeAttacked;
            }

            if ( source is BaseCreature )
            {
                BaseCreature bc = (BaseCreature)source;

                Mobile master = bc.GetMaster();
                if( master != null && CheckAggressor( master.Aggressors, target ))
                    return Notoriety.CanBeAttacked;
            }

            //bounty system
            if ( BountyBoard.Attackable( source, target ) )
                return Notoriety.CanBeAttacked;
            //end bounty system

            return Notoriety.Innocent;
        }
Esempio n. 37
0
        public bool TurnIn(PlayerMobile player, Mobile vendor)
        {
            bool completed = false;

            if (player == null)
            {
                return(false);
            }
            if (player.Backpack == null)
            {
                return(false);
            }

            SocietyJobPlayerProgress jobProgress = Societies.GetSocietiesJobPlayerProgress(player, this);

            if (jobProgress == null)
            {
                return(false);
            }

            if (m_TurnInRequirementAmount >= 1)
            {
                bool turnInItem     = false;
                bool turnInCreature = false;

                double remainingNeeded = m_TurnInRequirementAmount - jobProgress.m_TurnedInAmount;
                int    amountTurnedIn  = 0;

                Queue m_Queue = new Queue();

                if (m_JobType == JobType.CraftItem || m_JobType == JobType.RetrieveFish || m_JobType == JobType.StealItem)
                {
                    turnInItem = true;

                    Item[] m_MatchingItems = player.Backpack.FindItemsByType(m_PrimaryType);

                    foreach (Item item in m_MatchingItems)
                    {
                        if (item == null)
                        {
                            continue;
                        }
                        if (m_CraftResourceRequired != CraftResource.None && item.Resource != m_CraftResourceRequired)
                        {
                            continue;
                        }
                        if (m_PrimaryJobModifier == JobModifierType.ExceptionalQuality && item.Quality != Quality.Exceptional)
                        {
                            continue;
                        }
                        if (m_SecondaryJobModifier == JobModifierType.ExceptionalQuality && item.Quality != Quality.Exceptional)
                        {
                            continue;
                        }

                        jobProgress.m_TurnedInAmount++;
                        amountTurnedIn++;
                        remainingNeeded--;

                        m_Queue.Enqueue(item);

                        if (remainingNeeded <= 0)
                        {
                            break;
                        }
                    }

                    while (m_Queue.Count > 0)
                    {
                        Item mobile = (Item)m_Queue.Dequeue();
                        mobile.Delete();
                    }
                }

                else if (m_JobType == JobType.TameCreature)
                {
                    turnInCreature = true;

                    for (int a = 0; a < player.AllFollowers.Count; a++)
                    {
                        Mobile follower = player.AllFollowers[a];

                        if (follower.GetType() != m_PrimaryType)
                        {
                            continue;
                        }
                        if (follower == null)
                        {
                            continue;
                        }
                        if (!follower.Alive || follower.IsDeadBondedFollower)
                        {
                            continue;
                        }
                        if (Utility.GetDistance(follower.Location, vendor.Location) >= 12)
                        {
                            continue;
                        }

                        jobProgress.m_TurnedInAmount++;
                        amountTurnedIn++;
                        remainingNeeded--;

                        m_Queue.Enqueue(follower);

                        if (remainingNeeded <= 0)
                        {
                            break;
                        }
                    }

                    while (m_Queue.Count > 0)
                    {
                        Mobile mobile = (Mobile)m_Queue.Dequeue();
                        mobile.Delete();
                    }
                }

                if (amountTurnedIn == 0)
                {
                    if (turnInCreature)
                    {
                        player.SendMessage("You do not have any of the required creatures nearby needed to complete that job.");
                    }

                    else if (turnInItem)
                    {
                        player.SendMessage("You do not have any of the required items neccessary to complete that job in your backpack.");
                    }

                    return(false);
                }

                else if (amountTurnedIn > 0 && remainingNeeded > 0)
                {
                    if (turnInCreature)
                    {
                        player.SendMessage("You turn in some of the creatures neccessary for this job but still require more to complete it fully.");
                    }

                    else if (turnInItem)
                    {
                        player.SendMessage("You turn in some of the items neccessary for this job but still require more to complete it fully.");
                    }

                    return(false);
                }

                else
                {
                    return(true);
                }
            }

            else if (jobProgress.m_ProgressAmount >= m_TargetNumber)
            {
                return(true);
            }

            return(completed);
        }
Esempio n. 38
0
        public Item Mutate(Mobile from, int luckChance, Item item)
        {
            if (item != null)
            {
                if (item is BaseWeapon && 1 > Utility.Random(100))
                {
                    item.Delete();
                    item = new FireHorn();
                    return(item);
                }

                if (item is BaseWeapon || item is BaseArmor || item is BaseJewel || item is BaseHat)
                {
                    if (Core.AOS)
                    {
                        int bonusProps = GetBonusProperties();
                        int min        = m_MinIntensity;
                        int max        = m_MaxIntensity;

                        if (bonusProps < m_MaxProps && LootPack.CheckLuck(luckChance))
                        {
                            ++bonusProps;
                        }

                        int props = 1 + bonusProps;

                        // Make sure we're not spawning items with 6 properties.
                        if (props > m_MaxProps)
                        {
                            props = m_MaxProps;
                        }

                        // Try to generate a new random item
                        if (from is BaseCreature)
                        {
                            if (RandomItemGenerator.GenerateRandomItem(item, ((BaseCreature)from).LastKiller, (BaseCreature)from))
                            {
                                return(item);
                            }
                        }
                        else if (RandomItemGenerator.GenerateRandomItem(item, null, null))
                        {
                            return(item);
                        }

                        // Otherwise use the older style random generation
                        if (item is BaseWeapon)
                        {
                            BaseRunicTool.ApplyAttributesTo((BaseWeapon)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity);
                        }
                        else if (item is BaseArmor)
                        {
                            BaseRunicTool.ApplyAttributesTo((BaseArmor)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity);
                        }
                        else if (item is BaseJewel)
                        {
                            BaseRunicTool.ApplyAttributesTo((BaseJewel)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity);
                        }
                        else if (item is BaseHat)
                        {
                            BaseRunicTool.ApplyAttributesTo((BaseHat)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity);
                        }
                    }
                    else                     // not aos
                    {
                        if (item is BaseWeapon)
                        {
                            BaseWeapon weapon = (BaseWeapon)item;

                            if (80 > Utility.Random(100))
                            {
                                weapon.AccuracyLevel = (WeaponAccuracyLevel)GetRandomOldBonus();
                            }

                            if (60 > Utility.Random(100))
                            {
                                weapon.DamageLevel = (WeaponDamageLevel)GetRandomOldBonus();
                            }

                            if (40 > Utility.Random(100))
                            {
                                weapon.DurabilityLevel = (WeaponDurabilityLevel)GetRandomOldBonus();
                            }

                            if (5 > Utility.Random(100))
                            {
                                weapon.Slayer = SlayerName.Silver;
                            }

                            if (from != null && weapon.AccuracyLevel == 0 && weapon.DamageLevel == 0 && weapon.DurabilityLevel == 0 &&
                                weapon.Slayer == SlayerName.None && 5 > Utility.Random(100))
                            {
                                weapon.Slayer = SlayerGroup.GetLootSlayerType(from.GetType());
                            }
                        }
                        else if (item is BaseArmor)
                        {
                            BaseArmor armor = (BaseArmor)item;

                            if (80 > Utility.Random(100))
                            {
                                armor.ProtectionLevel = (ArmorProtectionLevel)GetRandomOldBonus();
                            }

                            if (40 > Utility.Random(100))
                            {
                                armor.Durability = (ArmorDurabilityLevel)GetRandomOldBonus();
                            }
                        }
                    }
                }
                else if (item is BaseInstrument)
                {
                    SlayerName slayer = SlayerName.None;

                    if (Core.AOS)
                    {
                        slayer = BaseRunicTool.GetRandomSlayer();
                    }
                    else
                    {
                        slayer = SlayerGroup.GetLootSlayerType(from.GetType());
                    }

                    if (slayer == SlayerName.None)
                    {
                        item.Delete();
                        return(null);
                    }

                    BaseInstrument instr = (BaseInstrument)item;

                    instr.Quality = InstrumentQuality.Regular;
                    instr.Slayer  = slayer;
                }

                if (item.Stackable)
                {
                    item.Amount = m_Quantity.Roll();
                }
            }

            return(item);
        }
Esempio n. 39
0
        public Item Mutate(Mobile from, int luckChance, Item item)
        {
            if (item != null)
            {
                if (item is BaseWeapon && 1 > Utility.Random(100))
                {
                    item.Delete();
                    item = new FireHorn();
                    return(item);
                }

                if (item is BaseWeapon || item is BaseArmor || item is BaseJewel)
                {
                    if (Core.AOS)
                    {
                        int bonusProps = GetBonusProperties();

                        if (bonusProps < m_MaxProps && LootPack.CheckLuck(luckChance))
                        {
                            ++bonusProps;
                        }

                        int props = 1 + bonusProps;

                        if (item is BaseWeapon)
                        {
                            BaseRunicTool.ApplyAttributesTo((BaseWeapon)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity);
                        }
                        else if (item is BaseArmor)
                        {
                            BaseRunicTool.ApplyAttributesTo((BaseArmor)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity);
                        }
                        else if (item is BaseJewel)
                        {
                            BaseRunicTool.ApplyAttributesTo((BaseJewel)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity);
                        }
                    }
                    else                     // not aos
                    {
                        if (item is BaseWeapon)
                        {
                            BaseWeapon weapon = (BaseWeapon)item;

                            if (80 > Utility.Random(100))
                            {
                                weapon.AccuracyLevel = (WeaponAccuracyLevel)GetRandomOldBonus();
                            }

                            if (60 > Utility.Random(100))
                            {
                                weapon.DamageLevel = (WeaponDamageLevel)GetRandomOldBonus();
                            }

                            if (40 > Utility.Random(100))
                            {
                                weapon.DurabilityLevel = (WeaponDurabilityLevel)GetRandomOldBonus();
                            }

                            if (5 > Utility.Random(100))
                            {
                                weapon.Slayer = SlayerName.Silver;
                            }

                            if (weapon.AccuracyLevel == 0 && weapon.DamageLevel == 0 && weapon.DurabilityLevel == 0 && weapon.Slayer == SlayerName.None && 5 > Utility.Random(100))
                            {
                                weapon.Slayer = SlayerGroup.GetLootSlayerType(from.GetType());
                            }
                        }
                        else if (item is BaseArmor)
                        {
                            BaseArmor armor = (BaseArmor)item;

                            if (80 > Utility.Random(100))
                            {
                                armor.ProtectionLevel = (ArmorProtectionLevel)GetRandomOldBonus();
                            }

                            if (40 > Utility.Random(100))
                            {
                                armor.Durability = (ArmorDurabilityLevel)GetRandomOldBonus();
                            }
                        }
                    }
                }
                else if (item is BaseInstrument)
                {
                    SlayerName slayer = SlayerName.None;

                    if (Core.AOS)
                    {
                        slayer = BaseRunicTool.GetRandomSlayer();
                    }
                    else
                    {
                        slayer = SlayerGroup.GetLootSlayerType(from.GetType());
                    }

                    if (slayer == SlayerName.None)
                    {
                        item.Delete();
                        return(null);
                    }

                    BaseInstrument instr = (BaseInstrument)item;

                    instr.Quality = InstrumentQuality.Regular;
                    instr.Slayer  = slayer;
                }

                if (item.Stackable)
                {
                    item.Amount = m_Quantity.Roll();
                }
            }

            return(item);
        }
Esempio n. 40
0
        public int GetSubLevelFor(Mobile m)
        {
            Type[][] types = ChampionSpawnInfo.GetInfo(m_Type).SpawnTypes;
            Type t = m.GetType();

            for (int i = 0; i < types.GetLength(0); i++)
            {
                Type[] individualTypes = types[i];

                for (int j = 0; j < individualTypes.Length; j++)
                {
                    if (t == individualTypes[j])
                        return i;
                }
            }

            return -1;
        }
Esempio n. 41
0
		// note that this method will be called when attached to either a mobile or a weapon
		// when attached to a weapon, only that weapon will do additional damage
		// when attached to a mobile, any weapon the mobile wields will do additional damage
		public override void OnWeaponHit(Mobile attacker, Mobile defender, BaseWeapon weapon, int damageGiven)
		{
			if(m_Chance <= 0 || Utility.Random(100) > m_Chance)
				return;

			if(defender != null && attacker != null && m_EnemyType != null)
			{

				// is the defender the correct type?
				if(defender.GetType() == m_EnemyType || defender.GetType().IsSubclassOf(m_EnemyType))
				{
					defender.Damage( (int) (damageGiven*PercentIncrease/100), attacker );
				}
			}
		}
Esempio n. 42
0
        public override void Damage(int amount, Mobile from)
        {
            if (Spells.Necromancy.EvilOmenSpell.CheckEffect(this))
                amount = (int)(amount * 1.25);

            Mobile oath = Spells.Necromancy.BloodOathSpell.GetBloodOath(from);

            if (oath == this)
            {
                amount = (int)(amount * 1.1);
                from.Damage(amount, from);
            }

            #region GeNova: Mondain's Legacy
            if (from != null && Talisman is BaseTalisman)
            {
                BaseTalisman talisman = (BaseTalisman)Talisman;

                if (talisman.Protection != null && talisman.Protection.Type != null)
                {
                    Type type = talisman.Protection.Type;

                    if (type == from.GetType())
                        amount *= 1 - (int)(((double)talisman.Protection.Amount) / 100);
                }
            }
            #endregion

            base.Damage(amount, from);
        }
Esempio n. 43
0
		public static string GetCorpseName( Mobile m )
		{
			if ( m is BaseCreature )
			{
				BaseCreature bc = (BaseCreature)m;

				if ( bc.CorpseNameOverride != null )
					return bc.CorpseNameOverride;
			}

			Type t = m.GetType();

			object[] attrs = t.GetCustomAttributes( typeof( CorpseNameAttribute ), true );

			if ( attrs != null && attrs.Length > 0 )
			{
				CorpseNameAttribute attr = attrs[0] as CorpseNameAttribute;

				if ( attr != null )
					return attr.Name;
			}

			return null;
		}
Esempio n. 44
0
		public static int MobileNotoriety( Mobile source, Mobile target )
		{
			if( Core.AOS && (target.Blessed || (target is BaseVendor && ((BaseVendor)target).IsInvulnerable) || target is PlayerVendor || target is TownCrier) )
				return Notoriety.Invulnerable;

			if( target.AccessLevel > AccessLevel.Player )
				return Notoriety.CanBeAttacked;

			if( source.Player && !target.Player && source is PlayerMobile && target is BaseCreature )
			{
				BaseCreature bc = (BaseCreature)target;

				Mobile master = bc.GetMaster();

				if ( master != null && master.AccessLevel > AccessLevel.Player )
					return Notoriety.CanBeAttacked;

				master = bc.ControlMaster;

				if ( Core.ML && master != null )
				{
					if ( ( source == master && CheckAggressor( target.Aggressors, source ) ) || ( CheckAggressor( source.Aggressors, bc ) ) )
						return Notoriety.CanBeAttacked;
                    else if (bc is BaseEscortable || bc is BaseEscort)
                        return Notoriety.Innocent;
					else
						return MobileNotoriety( source, master );
				}

				if( !bc.Summoned && !bc.Controlled && ((PlayerMobile)source).EnemyOfOneType == target.GetType() )
					return Notoriety.Enemy;
			}

            if ( target.Kills >= 5 || ( target.Body.IsMonster && IsSummoned( target as BaseCreature ) && !( target is BaseFamiliar ) && !( target is ArcaneFey ) && !( target is Golem ) ) || ( target is BaseCreature && ( ( (BaseCreature)target ).AlwaysMurderer || ( (BaseCreature)target ).IsAnimatedDead ) ) )
				return Notoriety.Murderer;
				
			#region Mondain's Legacy
			if ( target is Gregorio )
			{
				Gregorio gregorio = (Gregorio) target;

				if ( Gregorio.IsMurderer( source ) )
					return Notoriety.Murderer;
				
				return Notoriety.Innocent;
			}
			else if ( source.Player && target is Engines.Quests.BaseEscort )
				return Notoriety.Innocent;
			#endregion

			if( target.Criminal )
				return Notoriety.Criminal;

			Guild sourceGuild = GetGuildFor( source.Guild as Guild, source );
			Guild targetGuild = GetGuildFor( target.Guild as Guild, target );

			if( sourceGuild != null && targetGuild != null )
			{
				if( sourceGuild == targetGuild || sourceGuild.IsAlly( targetGuild ) )
					return Notoriety.Ally;
				else if( sourceGuild.IsEnemy( targetGuild ) )
					return Notoriety.Enemy;
			}

			Faction srcFaction = Faction.Find( source, true, true );
			Faction trgFaction = Faction.Find( target, true, true );

			if( srcFaction != null && trgFaction != null && srcFaction != trgFaction && source.Map == Faction.Facet )
				return Notoriety.Enemy;

			if( SkillHandlers.Stealing.ClassicMode && target is PlayerMobile && ((PlayerMobile)target).PermaFlags.Contains( source ) )
				return Notoriety.CanBeAttacked;

			if( target is BaseCreature && ((BaseCreature)target).AlwaysAttackable )
				return Notoriety.CanBeAttacked;

			if( CheckHouseFlag( source, target, target.Location, target.Map ) )
				return Notoriety.CanBeAttacked;

			if( !(target is BaseCreature && ((BaseCreature)target).InitialInnocent) )   //If Target is NOT A baseCreature, OR it's a BC and the BC is initial innocent...
			{
				if( !target.Body.IsHuman && !target.Body.IsGhost && !IsPet( target as BaseCreature ) && !(target is PlayerMobile) || !Core.ML && !target.CanBeginAction( typeof( Server.Spells.Seventh.PolymorphSpell ) ) )
					return Notoriety.CanBeAttacked;
			}

			if( CheckAggressor( source.Aggressors, target ) )
				return Notoriety.CanBeAttacked;

			if( CheckAggressed( source.Aggressed, target ) )
				return Notoriety.CanBeAttacked;

			if( target is BaseCreature )
			{
				BaseCreature bc = (BaseCreature)target;

				if( bc.Controlled && bc.ControlOrder == OrderType.Guard && bc.ControlTarget == source )
					return Notoriety.CanBeAttacked;
			}

			if( source is BaseCreature )
			{
				BaseCreature bc = (BaseCreature)source;

				Mobile master = bc.GetMaster();
				if( master != null )
					if( CheckAggressor( master.Aggressors, target ) || MobileNotoriety( master, target ) == Notoriety.CanBeAttacked )
					return Notoriety.CanBeAttacked;
			}

			return Notoriety.Innocent;
		}
Esempio n. 45
0
        public Item Mutate( Mobile from, int luckChance, Item item )
        {
            if ( item != null )
            {
                /*if ( item is BaseWeapon && 1 > Utility.Random( 100 ) ) //No FireHorns
                {
                    item.Delete();
                    item = new FireHorn();
                    return item;
                }*/

                if ( item is BaseWeapon || item is BaseArmor || item is BaseJewel || item is BaseHat )
                {
                    if ( Core.AOS )
                    {
                        int bonusProps = GetBonusProperties();
                        int min = m_MinIntensity;
                        int max = m_MaxIntensity;

                        if ( bonusProps < m_MaxProps && LootPack.CheckLuck( luckChance ) )
                            ++bonusProps;

                        int props = 1 + bonusProps;

                        // Make sure we're not spawning items with 6 properties.
                        if ( props > m_MaxProps )
                            props = m_MaxProps;

                        if ( item is BaseWeapon )
                            BaseRunicTool.ApplyAttributesTo( (BaseWeapon)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity );
                        else if ( item is BaseArmor )
                            BaseRunicTool.ApplyAttributesTo( (BaseArmor)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity );
                        else if ( item is BaseJewel )
                            BaseRunicTool.ApplyAttributesTo( (BaseJewel)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity );
                        else if ( item is BaseHat )
                            BaseRunicTool.ApplyAttributesTo( (BaseHat)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity );
                    }
                    else // not aos
                    {
                        if ( item is BaseWeapon )
                        {
                            BaseWeapon weapon = (BaseWeapon)item;

                            if ( 80 > Utility.Random( 100 ) )
                                weapon.AccuracyLevel = (WeaponAccuracyLevel)GetRandomOldBonus();

                            if ( 60 > Utility.Random( 100 ) )
                                weapon.DamageLevel = (WeaponDamageLevel)GetRandomOldBonus();

                            if ( 40 > Utility.Random( 100 ) )
                                weapon.DurabilityLevel = (WeaponDurabilityLevel)GetRandomOldBonus();

                            if ( 5 > Utility.Random( 100 ) )
                                weapon.Slayer = SlayerName.Silver;
                            //No slayer weapons
                            /*if ( from != null && weapon.AccuracyLevel == 0 && weapon.DamageLevel == 0 && weapon.DurabilityLevel == 0 && weapon.Slayer == SlayerName.None && 5 > Utility.Random( 100 ) )
                                weapon.Slayer = SlayerGroup.GetLootSlayerType( from.GetType() );*/
                        }
                        else if ( item is BaseArmor )
                        {
                            BaseArmor armor = (BaseArmor)item;

                            if ( 80 > Utility.Random( 100 ) )
                                armor.ProtectionLevel = (ArmorProtectionLevel)GetRandomOldBonus();

                            if ( 40 > Utility.Random( 100 ) )
                                armor.Durability = (ArmorDurabilityLevel)GetRandomOldBonus();
                        }
                    }
                }
                else if ( item is BaseInstrument )
                {
                    SlayerName slayer = SlayerName.None;

                    if ( Core.AOS )
                        slayer = BaseRunicTool.GetRandomSlayer();
                    else
                        slayer = SlayerGroup.GetLootSlayerType( from.GetType() );

                    if ( slayer == SlayerName.None )
                    {
                        item.Delete();
                        return null;
                    }

                    BaseInstrument instr = (BaseInstrument)item;

                    instr.Quality = InstrumentQuality.Regular;
                    instr.Slayer = slayer;
                }

                if ( item.Stackable )
                    item.Amount = m_Quantity.Roll();
            }

            return item;
        }