Go Back   RunUO - Ultima Online Emulation > RunUO > Custom Script Releases

Custom Script Releases This forum is where you can release your custom scripts for other users to use.

Please note: By releasing your scripts here you are submitting them to the public and as such agree to make them public domain. The RunUO Team has made its software GPL for you to use and enjoy you should do the same for anything based off of RunUO.

Reply
 
Thread Tools Display Modes
Old 06-30-2006, 11:03 PM   #1 (permalink)
Forum Expert
 
Lucid Nagual's Avatar
 
Join Date: Nov 2004
Location: Beyond the Gates of Hell
Age: 36
Posts: 3,509
Wink [RunUO 2.0 RC1] Lucid's <<_Advanced Archery_>>

~Lucid's Advanced Archery~
Version [3.0.1] (e)
Next release #: v[3].0.1 (f)

.................................................. .................................................. ........
........:|| Created by: Lucid Nagual & Rift ||:.........
.................................................. .................................................. ........


Installation Instructions:
Open AOS.cs and make the following changes:
Code:
[Under] else if( obj is Spellbook ) { AosAttributes attrs = ((Spellbook)obj).Attributes; if ( attrs != null ) value += attrs[attribute]; }
[Add] //--<<Advanced Archery Edit>>-----------[Start] else if ( obj is BaseQuiver ) { AosAttributes attrs = ((BaseQuiver)obj).Attributes;
if( attrs != null ) value += attrs[attribute]; } //--<<Advanced Archery Edit>>-----------[End]
Thanks To:
  • Dracana - Coding the BaseQuiver.
  • Snicker - For helping me fix weight reduction (percentage) for the BaseQuiver.
  • Kenko - For the container/layer fix in the BaseQuiver.
  • LordHogFred - For adding skill level to arrow damage in BaseRanged.
  • And to everyone else that has downloaded this script and reported bugs and crashes. I would also like to thank those who have voted on this system and have given me good feedback and PMs. Many thanks.
Special Thanks:
  • To Alien for advice on how to use Central Memory with the bows and how to get the Invalidate Properties to work.
  • To Rift for his help and contribution to this project. This system would have never been completed without his help and insight, MANY THANKS!!!
Contents:
  • New arrows and bolts: Poison, explosive, armor piercing, freeze and lightning.
  • New bow stringers: linen cloth, cotton, silk, horse hair,hemp and angel hair.
  • Venom arrow dipping tubs: to apply damage attributes.
  • Quivers: Ultimate and elven quivers. Has 30% weight reduction, attributes, is dyable and adds owner's name when worn.
  • Uses Central Memory for bow memory storage.
  • Custom BaseRanged and other distro modifications.
How to Set Ammo Type on Bows:

Double-click the bow and target the ammo of choice, or bow stringer.


Types Of Arrows:
  • Normal
  • Poison
  • Explosive
  • Armor Piercing
  • Freeze
  • Lightning
Types Of Bolts:
  • Normal
  • Poison
  • Explosive
  • Armor Piercing
  • Freeze
  • Lightning
Types Of Dip Tubs:
  • Normal
  • Poison
  • Explosive
  • Armor Piercing
  • Freeze
  • Lightning
Types Of Bow Stringers:
  • Linen Cloth (Very Weak)
  • Cotton (Weak)
  • Silk (Sturdy)
  • Horse Hair (Strong)
  • Hemp (Dependable)
  • Angel Hair (Indestructable)
Strengths Of Strings (pounds per pull):
  • Forty
  • Sixty
  • Eighty
  • Hundred
Attached Files
File Type: zip Advanced Archery [3].0.1 (e).zip (89.5 KB, 664 views)
__________________
Leader of the Anti-OSI Movement. Inventing a new game experience in an EA Games-free environment.

Don Juan Matus "The basic difference between an ordinary man and a warrior is that a warrior takes everything as a challenge, while an ordinary man takes everything as a blessing or as a curse."


My Customs:

Last edited by Lucid Nagual; 04-30-2007 at 10:04 PM.
Lucid Nagual is offline   Reply With Quote
Old 06-30-2006, 11:04 PM   #2 (permalink)
Forum Expert
 
Lucid Nagual's Avatar
 
Join Date: Nov 2004
Location: Beyond the Gates of Hell
Age: 36
Posts: 3,509
Exclamation Current Updates

!Updates:
Updated v[1].0.2b:
  • -Added the elven quiver
  • -Added crossbows & bolts
  • -Added new bows
  • -Added two new types of arrows and bolts
  • -Added random damage & random levels of poison (for poison arrows)
  • -Fixed the drag and drop issue
  • -Fixed the dip tub charge issue


Updated v[1].0.3:
  • -Fixed skill mod issue. Thanks Drac!
  • -Fixed BaseRanged.cs warning.
  • -Parcially fixed the weight issue. Needs more work, but at least weight won't go negative when ammo is emptied.

Updated v[1]0.4:
  • -Added new bows.

Updated v[2].0.1:
  • -Changed BaseRanged.cs to CBaseRanged.cs for an easier install.
  • -Fixed serialization in all Bows for an easier install.
  • -Fixed bug with the Dip Tubs. Doesn't crash when targeting mobiles.
  • -Bolts are now functional thanks to blkdrac.

Updated v[2].0.2:
  • -Fixed Internal Map/Item issue.....thx to Lumberman and Ray.

Updated v[2].0.2b:
  • -Fixed a couple of warnings, thanks Greystar.
Updated v[2].0.2c:
  • -Fixed the ArcheryButtAddon, thanks Greystar.

Updated v[2].0.3:
  • -Added the BaseQuiver. Thanks Dracana!
  • -Changed layer to middletorso so cloaks can be worn. Thanks Dracana!
  • -Added lower reagent cost attribute. Thanks Dracana!

Updated v[2].0.3 (b):
  • Improved the CBaseRanged. Wasn't pulling arrows from backpack and quiver proper.
Updated v[3].0.1 (a):
Sweet Jesus!!! It's finally done
  • -Fixed serilization issues by converting the CBaseRanged to a BaseRangedModule (Central Memory). The CBaseRanged is no longer needed.
  • -Added bow stringers! Now all bows use different types of strings. Weak strings don't last as long as strong ones. The better the string the more likely you can get a PERFECT HIT (damage bonus). The different strings are: horse hair, linen thread, angel hair, hemp, silk and cotton. Only Master Fletchers can apply the strings.
  • -Added pounds per pull. Now the ppp will determine how high of damage you create on a PERFECT HIT. The pounds per pull can only be adjusted (added) when a string is changed. The pounds per pull is determined by the level of the Master Fletcher.
  • -Fixed all bugs in the BaseQuiver. The quiver now allows one bow to be carried just like OSI. The quiver also allows dip tubs to be carried as well. And added the fix for the layer/container issue. Thanks Kenko!
  • -Fixed unstrung bow issue.
__________________
Leader of the Anti-OSI Movement. Inventing a new game experience in an EA Games-free environment.

Don Juan Matus "The basic difference between an ordinary man and a warrior is that a warrior takes everything as a challenge, while an ordinary man takes everything as a blessing or as a curse."


My Customs:

Last edited by Lucid Nagual; 11-21-2006 at 10:05 PM.
Lucid Nagual is offline   Reply With Quote
Old 07-01-2006, 12:30 AM   #3 (permalink)
Forum Novice
 
Join Date: May 2004
Location: Canada
Age: 35
Posts: 158
Default

hiya love the system, but everytime i use the bow i can't fire, any idea's btw i download the other package that someone had updated it for u and worked great until the crash then redownloaded the CBaseRanged.cs and know can't fire any of the bow can't wait to use this again
dragonlady is offline   Reply With Quote
Old 07-01-2006, 03:31 AM   #4 (permalink)
 
Join Date: Nov 2003
Posts: 34
Send a message via ICQ to psycomantis
Default

could it be you forgot to include the "newer" arrows and bolts ? they all got these "dupe" lines incompatible to 2.0

i think there is a typo in ElvencompositelongBow - some scripts cant find it.. shouldnt it be Elvencompositelongbow ?

and this also happened to me :
Code:
Spellbook.cs:
CS1502: Line 808: The best oberloaded method match for 'Server.Items.BaseRunicTool.ApplyAttributesTo<Server.Items.Baseweapon, bool, int, int, int, int>' hase some invalid arguments
CS1503: Line 808: Argument '1': cannot convert from 'Server.Items.Spellbook to 'Server.Items.Baseweapon'

LootPack.cs
CS1502: Line 667: The best oberloaded method match for 'Server.Items.BaseRunicTool.ApplyAttributesTo<Server.Items.Baseweapon, bool, int, int, int, int>' hase some invalid arguments
CS1503: Line 667: Argument '1': cannot convert from 'Server.Items.Basehat' to 'Server.Items.Baseweapon'

ill help you out on testing if you like - Got Runuo2.0 rev 64 http://xmlspawner.15.forumer.com/ind...?showtopic=580
and currently installed scripts is :
-Xmlspawner2 latest
-Xmlsockets latest
-XmlCustomattacks latest
- Custom Vehicles

got nothin to lose here- started working on this just a few days ago and the world is empty + since i really want your script badly ill do anything ^^

*EDIT1 hope you dont mind if i keep posting in this post so i dont uselessly enlarge your thread

just keep it comeing ill test whatever you'll throw at us

Last edited by psycomantis; 07-01-2006 at 09:22 AM.
psycomantis is offline   Reply With Quote
Old 07-01-2006, 09:08 AM   #5 (permalink)
Forum Expert
 
Lucid Nagual's Avatar
 
Join Date: Nov 2004
Location: Beyond the Gates of Hell
Age: 36
Posts: 3,509
Smile

I still have to do some testing. But fixed the quivers and part of the CBaseRanged. And crap how did I skip the new arrows? Guess need to update again.
__________________
Leader of the Anti-OSI Movement. Inventing a new game experience in an EA Games-free environment.

Don Juan Matus "The basic difference between an ordinary man and a warrior is that a warrior takes everything as a challenge, while an ordinary man takes everything as a blessing or as a curse."


My Customs:
Lucid Nagual is offline   Reply With Quote
Old 07-01-2006, 09:36 AM   #6 (permalink)
Forum Novice
 
Nam01's Avatar
 
Join Date: Mar 2005
Posts: 126
Default Thanks

Thanks for updating this lucid
Nam01 is offline   Reply With Quote
Old 07-01-2006, 09:46 AM   #7 (permalink)
Forum Expert
 
Lucid Nagual's Avatar
 
Join Date: Nov 2004
Location: Beyond the Gates of Hell
Age: 36
Posts: 3,509
Exclamation Update:

Gimme sec......

Checking to see if it compiles...........

OK try these updates. The quivers might crash when adding an illegal item. But I'm not sure.

I gotta get a few hours sleep before I have to goto a family gathering.
Attached Files
File Type: zip [2.0]Lucid Nagual's Advanced Archery Beta2.zip (48.8 KB, 145 views)
__________________
Leader of the Anti-OSI Movement. Inventing a new game experience in an EA Games-free environment.

Don Juan Matus "The basic difference between an ordinary man and a warrior is that a warrior takes everything as a challenge, while an ordinary man takes everything as a blessing or as a curse."


My Customs:
Lucid Nagual is offline   Reply With Quote
Old 07-01-2006, 01:59 PM   #8 (permalink)
 
Join Date: Nov 2003
Posts: 34
Send a message via ICQ to psycomantis
Default

okay well.. there was still a load of files with conversion errors but i listed the fixed ones as attachments


yet after fixing them all i get this again :
Code:
Spellbook.cs:
CS1502: Line 808: The best oberloaded method match for 'Server.Items.BaseRunicTool.ApplyAttributesTo<Server.Items.Baseweapon, bool, int, int, int, int>' hase some invalid arguments
CS1503: Line 808: Argument '1': cannot convert from 'Server.Items.Spellbook to 'Server.Items.Baseweapon'

LootPack.cs
CS1502: Line 667: The best oberloaded method match for 'Server.Items.BaseRunicTool.ApplyAttributesTo<Server.Items.Baseweapon, bool, int, int, int, int>' hase some invalid arguments
CS1503: Line 667: Argument '1': cannot convert from 'Server.Items.Basehat' to 'Server.Items.Baseweapon'
any idea bout this anyone ? well for now i hope i save you some time with these fixed ones here


*EDIT i got around this error by adding :
Code:
using System.Collections.Generic
instead of

Code:
using System.Collections;
at the Top of BaseRunicTool.cs

now i'm stuck with this :

Code:
Errors:

+ Items/Skill Items/Tools/BaseRunicTool.cs:
CS0246: Line 202: The type or namcespace name 'BitArray' could not be found (are you missing a using directive or an assembly reference?)
Attached Files
File Type: cs ElvenCompositeLongbow.cs (5.4 KB, 61 views)
File Type: cs ArmorPiercingDipTub.cs (4.8 KB, 58 views)
File Type: cs ExplosiveDipTub.cs (4.8 KB, 54 views)
File Type: cs FreezeDipTub.cs (4.7 KB, 52 views)
File Type: cs LightningDipTub.cs (4.8 KB, 54 views)
File Type: cs PoisonDipTub.cs (4.7 KB, 57 views)
File Type: cs Bow.cs (5.5 KB, 60 views)

Last edited by psycomantis; 07-01-2006 at 02:43 PM.
psycomantis is offline   Reply With Quote
Old 07-01-2006, 02:44 PM   #9 (permalink)
Forum Novice
 
Join Date: May 2004
Location: Canada
Age: 35
Posts: 158
Default

After Installing this i went from this error

RunUO - [www.runuo.com] Version 2.0, Build 2357.32527
Core: Running on .NET Framework Version 2.0.50727
Scripts: Compiling C# scripts...failed (8 errors, 1 warnings)
Warnings:
+ Items/Custom Script/Custom Commands/ShardInfo.cs:
CS0105: Line 13: The using directive for 'Server.Network' appeared previousl
y in this namespace
Errors:
+ Items/Custom Script/Custom Wepond/ML_Artifacts_and_Weapons/Artifacts/Craftabl
e/FaerieFire.cs:
CS0246: Line 6: The type or namespace name 'ElvenCompositeLongbow' could not
be found (are you missing a using directive or an assembly reference?)
+ Items/Custom Script/Custom Wepond/ML_Artifacts_and_Weapons/Artifacts/WildFire
Bow.cs:
CS0246: Line 7: The type or namespace name 'ElvenCompositeLongbow' could not
be found (are you missing a using directive or an assembly reference?)
+ Items/Custom Script/Custom Wepond/ML_Artifacts_and_Weapons/ML Weapons/Ranged/
Longbow/BarbedLongbow.cs:
CS0246: Line 8: The type or namespace name 'ElvenCompositeLongbow' could not
be found (are you missing a using directive or an assembly reference?)
+ Items/Custom Script/Custom Wepond/ML_Artifacts_and_Weapons/ML Weapons/Ranged/
Longbow/FrozenLongbow.cs:
CS0246: Line 8: The type or namespace name 'ElvenCompositeLongbow' could not
be found (are you missing a using directive or an assembly reference?)
+ Items/Custom Script/Custom Wepond/ML_Artifacts_and_Weapons/ML Weapons/Ranged/
Longbow/LongbowOfMight.cs:
CS0246: Line 8: The type or namespace name 'ElvenCompositeLongbow' could not
be found (are you missing a using directive or an assembly reference?)
+ Items/Custom Script/Custom Wepond/ML_Artifacts_and_Weapons/ML Weapons/Ranged/
Longbow/SlayerLongbow.cs:
CS0246: Line 8: The type or namespace name 'ElvenCompositeLongbow' could not
be found (are you missing a using directive or an assembly reference?)
+ Items/Weapons/ML Weapons/Artifacts/BlightGrippedLongbow.cs:
CS0246: Line 6: The type or namespace name 'ElvenCompositeLongbow' could not
be found (are you missing a using directive or an assembly reference?)
+ Items/Weapons/ML Weapons/Artifacts/SilvanisFeywoodBow.cs:
CS0246: Line 7: The type or namespace name 'ElvenCompositeLongbow' could not
be found (are you missing a using directive or an assembly reference?)
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.

Then Fixing Thoses Error, I also get these error now, also fixed them now im stuck on these error's

RunUO - [www.runuo.com] Version 2.0, Build 2357.32527
Core: Running on .NET Framework Version 2.0.50727
Scripts: Compiling C# scripts...failed (2 errors, 12 warnings)
Warnings:
+ Items/Custom Script/Custom Commands/ShardInfo.cs:
CS0105: Line 13: The using directive for 'Server.Network' appeared previousl
y in this namespace
+ Items/Custom Script/Custom Crafting/Publisher/Publisher/Publisher.cs:
CS0108: Line 18: 'Server.Mobiles.Publisher.PlaySound' hides inherited member
'Server.Mobile.PlaySound(int)'. Use the new keyword if hiding was intended.
+ Items/Custom Script/Custom Quest/VampireQuest/VampQuestItems/Drac Required it
ems/DraculasTeleporter.cs:
CS0114: Line 21: 'Server.Items.DraculasTeleporter.Location' hides inherited
member 'Server.Item.Location'. To make the current member override that implemen
tation, add the override keyword. Otherwise add the new keyword.
CS0108: Line 28: 'Server.Items.DraculasTeleporter.Map' hides inherited membe
r 'Server.Item.Map'. Use the new keyword if hiding was intended.
+ Tamingmoded scripts/BaseCreature.cs:
CS1717: Line 3129: Assignment made to same variable; did you mean to assign
something else?
+ Items/Custom Script/Custom Armor/Other/SkelHelml.cs:
CS0162: Line 72: Unreachable code detected
+ Items/Custom Script/Custom Commands/FindhouseSys.cs:
CS0168: Line 137: The variable 'online' is declared but never used
+ Items/Custom Script/Custom Monster/TrainingElemental/TrainingElemental.cs:
CS0429: Line 78: Unreachable expression code detected
CS0162: Line 79: Unreachable code detected
+ Items/Custom Script/Custom Quest/ElainQuest/Mobiles/Andora.cs:
CS0219: Line 34: The variable 'hairHue' is assigned but its value is never u
sed
+ Items/Custom Script/Custom Quest/ElainQuest/Mobiles/ErikSullivan.cs:
CS0219: Line 35: The variable 'hairHue' is assigned but its value is never u
sed
+ Items/Custom Script/Custom Quest/SpellcrafterQuest/SpellcrafterQuest/Balto.cs
:
CS0219: Line 31: The variable 'hairHue' is assigned but its value is never u
sed
+ Items/Custom Script/Custom Quest/SpellcrafterQuest/SpellcrafterQuest/Gallin.c
s:
CS0219: Line 31: The variable 'hairHue' is assigned but its value is never u
sed
+ Items/Custom Script/Custom Quest/SpellcrafterQuest/SpellcrafterQuest/SCAppren
.cs:
CS0219: Line 49: The variable 'hairHue' is assigned but its value is never u
sed
Errors:
+ Items/Skill Items/Magical/Spellbook.cs:
CS1502: Line 808: The best overloaded method match for 'Server.Items.BaseRun
icTool.ApplyAttributesTo(Server.Items.BaseWeapon, bool, int, int, int, int)' has
some invalid arguments
CS1503: Line 808: Argument '1': cannot convert from 'Server.Items.Spellbook'
to 'Server.Items.BaseWeapon'
+ Misc/LootPack.cs:
CS1502: Line 638: The best overloaded method match for 'Server.Items.BaseRun
icTool.ApplyAttributesTo(Server.Items.BaseWeapon, bool, int, int, int, int)' has
some invalid arguments
CS1503: Line 638: Argument '1': cannot convert from 'Server.Items.BaseHat' t
o 'Server.Items.BaseWeapon'
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.
dragonlady is offline   Reply With Quote
Old 07-01-2006, 04:05 PM   #10 (permalink)
Forum Expert
 
Lucid Nagual's Avatar
 
Join Date: Nov 2004
Location: Beyond the Gates of Hell
Age: 36
Posts: 3,509
Question

Do you two have some kind of update I don't know about? I don't get these errors.

Update:
I just opened the BaseRunicTool.cs form the RC1 package and it is the same one that I provided you with.

The only thing I changed was:
Code:
if ( weapon is BaseRanged )
To this:
Code:
if ( weapon is CBaseRanged )
Post your BaseRunicTool.cs.
__________________
Leader of the Anti-OSI Movement. Inventing a new game experience in an EA Games-free environment.

Don Juan Matus "The basic difference between an ordinary man and a warrior is that a warrior takes everything as a challenge, while an ordinary man takes everything as a blessing or as a curse."


My Customs:

Last edited by Lucid Nagual; 07-01-2006 at 04:31 PM.
Lucid Nagual is offline   Reply With Quote
Old 07-01-2006, 05:18 PM   #11 (permalink)
Forum Novice
 
Join Date: May 2004
Location: Canada
Age: 35
Posts: 158
Default

I don't think so hun, but if i did i dont remember but here is the script ur asking for
Attached Files
File Type: cs BaseRunicTool.cs (24.9 KB, 71 views)
dragonlady is offline   Reply With Quote
Old 07-01-2006, 05:31 PM   #12 (permalink)
Forum Expert
 
Lucid Nagual's Avatar
 
Join Date: Nov 2004
Location: Beyond the Gates of Hell
Age: 36
Posts: 3,509
Question dragonlady

OK this is do to some modification in spellbook and lootpack that you two have. This has nothing to do with Advanced Archery. If you post the spellbook and lootpack I can try and look into the reasons why this happened. What system has the spellbook modification that you have?
__________________
Leader of the Anti-OSI Movement. Inventing a new game experience in an EA Games-free environment.

Don Juan Matus "The basic difference between an ordinary man and a warrior is that a warrior takes everything as a challenge, while an ordinary man takes everything as a blessing or as a curse."


My Customs:
Lucid Nagual is offline   Reply With Quote
Old 07-01-2006, 05:38 PM   #13 (permalink)
Forum Novice
 
Join Date: May 2004
Location: Canada
Age: 35
Posts: 158
Default

only other system i can think of that i placed in was the spell crafter but i dont think that has anything to do with it or the taming bods, other than that my server is clean of any other scripts that r craftable but here r the script's u ask for anyhow tks for all ur help
Attached Files
File Type: cs Spellbook.cs (21.4 KB, 47 views)
File Type: cs LootPack.cs (31.1 KB, 48 views)
dragonlady is offline   Reply With Quote
Old 07-01-2006, 06:04 PM   #14 (permalink)
 
Join Date: Nov 2003
Posts: 34
Send a message via ICQ to psycomantis
Default

no dragonlady these 2 specific erros you posted are because your Baserunictool.cs doesnt contain:


Code:
using System.Collections.Generic;
right at the top!


i fixed this in the version i posted above -> as a result you will get this error

Code:
Errors:
Items/Skill Items/Tools/BaseRunicTool.cs:
CS0246: Line 206: The type or namespace name 'BitArray' could not be found (are you missing a using directive or an assembly reference?
wich i think is better than having 2 errors in not even related scripts....

but i couldnt get around this in any way yet

but here as wanted my baseranged.cs -wich is basicly same as yours lucid just with the change mentioned above




Code:

using System;
using System.Collections.Generic;




namespace Server.Items
{
	public abstract class BaseRunicTool : BaseTool
	{
		private CraftResource m_Resource;

		[CommandProperty( AccessLevel.GameMaster )]
		public CraftResource Resource
		{
			get{ return m_Resource; }
			set{ m_Resource = value; Hue = CraftResources.GetHue( m_Resource ); InvalidateProperties(); }
		}

		public BaseRunicTool( CraftResource resource, int itemID ) : base( itemID )
		{
			m_Resource = resource;
		}

		public BaseRunicTool( CraftResource resource, int uses, int itemID ) : base( uses, itemID )
		{
			m_Resource = resource;
		}

		public BaseRunicTool( Serial serial ) : base( serial )
		{
		}

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 0 ); // version
			writer.Write( (int) m_Resource );
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );

			int version = reader.ReadInt();

			switch ( version )
			{
				case 0:
				{
					m_Resource = (CraftResource)reader.ReadInt();
					break;
				}
			}
		}

		private static bool m_IsRunicTool;
		private static int m_LuckChance;

		private static int Scale( int min, int max, int low, int high )
		{
			int percent;

			if ( m_IsRunicTool )
			{
				percent = Utility.RandomMinMax( min, max );
			}
			else
			{
				// Behold, the worst system ever!
				int v = Utility.RandomMinMax( 0, 10000 );

				v = (int) Math.Sqrt( v );
				v = 100 - v;

				if ( LootPack.CheckLuck( m_LuckChance ) )
					v += 10; // TODO: is this right? who knows

				if ( v < min )
					v = min;
				else if ( v > max )
					v = max;

				percent = v;
			}

			int scaledBy = Math.Abs( high - low ) + 1;

			if ( scaledBy != 0 )
				scaledBy = 10000 / scaledBy;

			percent *= (10000 + scaledBy);

			return low + (((high - low) * percent) / 1000001);
		}

		private static void ApplyAttribute( AosAttributes attrs, int min, int max, AosAttribute attr, int low, int high )
		{
			ApplyAttribute( attrs, min, max, attr, low, high, 1 );
		}

		private static void ApplyAttribute( AosAttributes attrs, int min, int max, AosAttribute attr, int low, int high, int scale )
		{
			if ( attr == AosAttribute.CastSpeed )
				attrs[attr] += Scale( min, max, low / scale, high / scale ) * scale;
			else
				attrs[attr] = Scale( min, max, low / scale, high / scale ) * scale;

			if ( attr == AosAttribute.SpellChanneling )
				attrs[AosAttribute.CastSpeed] -= 1;
		}

		private static void ApplyAttribute( AosArmorAttributes attrs, int min, int max, AosArmorAttribute attr, int low, int high )
		{
			attrs[attr] = Scale( min, max, low, high );
		}

		private static void ApplyAttribute( AosArmorAttributes attrs, int min, int max, AosArmorAttribute attr, int low, int high, int scale )
		{
			attrs[attr] = Scale( min, max, low / scale, high / scale ) * scale;
		}

		private static void ApplyAttribute( AosWeaponAttributes attrs, int min, int max, AosWeaponAttribute attr, int low, int high )
		{
			attrs[attr] = Scale( min, max, low, high );
		}

		private static void ApplyAttribute( AosWeaponAttributes attrs, int min, int max, AosWeaponAttribute attr, int low, int high, int scale )
		{
			attrs[attr] = Scale( min, max, low / scale, high / scale ) * scale;
		}

		private static void ApplyAttribute( AosElementAttributes attrs, int min, int max, AosElementAttribute attr, int low, int high )
		{
			attrs[attr] = Scale( min, max, low, high );
		}

		private static void ApplyAttribute( AosElementAttributes attrs, int min, int max, AosElementAttribute attr, int low, int high, int scale )
		{
			attrs[attr] = Scale( min, max, low / scale, high / scale ) * scale;
		}

		private static SkillName[] m_PossibleBonusSkills = new SkillName[]
			{
				SkillName.Swords,
				SkillName.Fencing,
				SkillName.Macing,
				SkillName.Archery,
				SkillName.Wrestling,
				SkillName.Parry,
				SkillName.Tactics,
				SkillName.Anatomy,
				SkillName.Healing,
				SkillName.Magery,
				SkillName.Meditation,
				SkillName.EvalInt,
				SkillName.MagicResist,
				SkillName.AnimalTaming,
				SkillName.AnimalLore,
				SkillName.Veterinary,
				SkillName.Musicianship,
				SkillName.Provocation,
				SkillName.Discordance,
				SkillName.Peacemaking,
				SkillName.Chivalry,
				SkillName.Focus,
				SkillName.Necromancy,
				SkillName.Stealing,
				SkillName.Stealth,
				SkillName.SpiritSpeak 
			};

		private static void ApplySkillBonus( AosSkillBonuses attrs, int min, int max, int index, int low, int high )
		{
			SkillName sk, check;
			double bonus;
			bool found;

			do
			{
				found = false;
				sk = m_PossibleBonusSkills[Utility.Random( m_PossibleBonusSkills.Length )];

				for ( int i = 0; !found && i < 5; ++i )
					found = ( attrs.GetValues( i, out check, out bonus ) && check == sk );
			} while ( found );

			attrs.SetValues( index, sk, Scale( min, max, low, high ) );
		}

		private static void ApplyResistance( BaseArmor ar, int min, int max, ResistanceType res, int low, int high )
		{
			switch ( res )
			{
				case ResistanceType.Physical: ar.PhysicalBonus += Scale( min, max, low, high ); break;
				case ResistanceType.Fire: ar.FireBonus += Scale( min, max, low, high ); break;
				case ResistanceType.Cold: ar.ColdBonus += Scale( min, max, low, high ); break;
				case ResistanceType.Poison: ar.PoisonBonus += Scale( min, max, low, high ); break;
				case ResistanceType.Energy: ar.EnergyBonus += Scale( min, max, low, high ); break;
			}
		}

		private const int MaxProperties = 32;
		private static BitArray m_Props = new BitArray( MaxProperties );
		private static int[] m_Possible = new int[MaxProperties];

		public static int GetUniqueRandom( int count )
		{
			int avail = 0;

			for ( int i = 0; i < count; ++i )
			{
				if ( !m_Props[i] )
					m_Possible[avail++] = i;
			}

			if ( avail == 0 )
				return -1;

			int v = m_Possible[Utility.Random( avail )];

			m_Props.Set( v, true );

			return v;
		}

		public void ApplyAttributesTo( BaseWeapon weapon )
		{
			CraftResourceInfo resInfo = CraftResources.GetInfo( m_Resource );

			if ( resInfo == null )
				return;

			CraftAttributeInfo attrs = resInfo.AttributeInfo;

			if ( attrs == null )
				return;

			int attributeCount = Utility.RandomMinMax( attrs.RunicMinAttributes, attrs.RunicMaxAttributes );
			int min = attrs.RunicMinIntensity;
			int max = attrs.RunicMaxIntensity;

			ApplyAttributesTo( weapon, true, 0, attributeCount, min, max );
		}

		public static void ApplyAttributesTo( BaseWeapon weapon, int attributeCount, int min, int max )
		{
			ApplyAttributesTo( weapon, false, 0, attributeCount, min, max );
		}

		public static void ApplyAttributesTo( BaseWeapon weapon, bool isRunicTool, int luckChance, int attributeCount, int min, int max )
		{
			m_IsRunicTool = isRunicTool;
			m_LuckChance = luckChance;

			AosAttributes primary = weapon.Attributes;
			AosWeaponAttributes secondary = weapon.WeaponAttributes;

			m_Props.SetAll( false );

			if ( weapon is CBaseRanged )
				m_Props.Set( 2, true ); // ranged weapons cannot be ubws or mageweapon

			for ( int i = 0; i < attributeCount; ++i )
			{
				int random = GetUniqueRandom( 24 );

				if ( random == -1 )
					break;

				switch ( random )
				{
					case 0:
					{
						switch ( Utility.Random( 5 ) )
						{
							case 0: ApplyAttribute( secondary, min, max, AosWeaponAttribute.HitPhysicalArea,2, 50, 2 ); break;
							case 1: ApplyAttribute( secondary, min, max, AosWeaponAttribute.HitFireArea,	2, 50, 2 ); break;
							case 2: ApplyAttribute( secondary, min, max, AosWeaponAttribute.HitColdArea,	2, 50, 2 ); break;
							case 3: ApplyAttribute( secondary, min, max, AosWeaponAttribute.HitPoisonArea,	2, 50, 2 ); break;
							case 4: ApplyAttribute( secondary, min, max, AosWeaponAttribute.HitEnergyArea,	2, 50, 2 ); break;
						}

						break;
					}
					case 1:
					{
						switch ( Utility.Random( 4 ) )
						{
							case 0: ApplyAttribute( secondary, min, max, AosWeaponAttribute.HitMagicArrow,	2, 50, 2 ); break;
							case 1: ApplyAttribute( secondary, min, max, AosWeaponAttribute.HitHarm,		2, 50, 2 ); break;
							case 2: ApplyAttribute( secondary, min, max, AosWeaponAttribute.HitFireball,	2, 50, 2 ); break;
							case 3: ApplyAttribute( secondary, min, max, AosWeaponAttribute.HitLightning,	2, 50, 2 ); break;
						}

						break;
					}
					case 2:
					{
						switch ( Utility.Random( 2 ) )
						{
							case 0: ApplyAttribute( secondary, min, max, AosWeaponAttribute.UseBestSkill,	1, 1 ); break;
							case 1: ApplyAttribute( secondary, min, max, AosWeaponAttribute.MageWeapon,		1, 10 ); break;
						}

						break;
					}
					case  3: ApplyAttribute( primary,	min, max, AosAttribute.WeaponDamage,				1, 50 ); break;
					case  4: ApplyAttribute( primary,	min, max, AosAttribute.DefendChance,				1, 15 ); break;
					case  5: ApplyAttribute( primary,	min, max, AosAttribute.CastSpeed,					1, 1 ); break;
					case  6: ApplyAttribute( primary,	min, max, AosAttribute.AttackChance,				1, 15 ); break;
					case  7: ApplyAttribute( primary,	min, max, AosAttribute.Luck,						1, 100 ); break;
					case  8: ApplyAttribute( primary,	min, max, AosAttribute.WeaponSpeed,					5, 30, 5 ); break;
					case  9: ApplyAttribute( primary,	min, max, AosAttribute.SpellChanneling,				1, 1 ); break;
					case 10: ApplyAttribute( secondary, min, max, AosWeaponAttribute.HitDispel,				2, 50, 2 ); break;
					case 11: ApplyAttribute( secondary,	min, max, AosWeaponAttribute.HitLeechHits,			2, 50, 2 ); break;
					case 12: ApplyAttribute( secondary,	min, max, AosWeaponAttribute.HitLowerAttack,		2, 50, 2 ); break;
					case 13: ApplyAttribute( secondary,	min, max, AosWeaponAttribute.HitLowerDefend,		2, 50, 2 ); break;
					case 14: ApplyAttribute( secondary,	min, max, AosWeaponAttribute.HitLeechMana,			2, 50, 2 ); break;
					case 15: ApplyAttribute( secondary,	min, max, AosWeaponAttribute.HitLeechStam,			2, 50, 2 ); break;
					case 16: ApplyAttribute( secondary,	min, max, AosWeaponAttribute.LowerStatReq,			10, 100, 10 ); break;
					case 17: ApplyAttribute( secondary,	min, max, AosWeaponAttribute.ResistPhysicalBonus,	1, 15 ); break;
					case 18: ApplyAttribute( secondary,	min, max, AosWeaponAttribute.ResistFireBonus,		1, 15 ); break;
					case 19: ApplyAttribute( secondary,	min, max, AosWeaponAttribute.ResistColdBonus,		1, 15 ); break;
					case 20: ApplyAttribute( secondary,	min, max, AosWeaponAttribute.ResistPoisonBonus,		1, 15 ); break;
					case 21: ApplyAttribute( secondary,	min, max, AosWeaponAttribute.ResistEnergyBonus,		1, 15 ); break;
					case 22: ApplyAttribute( secondary, min, max, AosWeaponAttribute.DurabilityBonus,		10, 100, 10 ); break;
					case 23: weapon.Slayer = GetRandomSlayer(); break;
				}
			}
		}

		public static SlayerName GetRandomSlayer()
		{
			// TODO: Check random algorithm on OSI

			SlayerGroup[] groups = SlayerGroup.Groups;

			if ( groups.Length == 0 )
				return SlayerName.None;

			SlayerGroup group = groups[Utility.Random( groups.Length -1 )]; //-1 To Exclude the Fey Slayer which appears ONLY on a certain artifact.
			SlayerEntry entry;

			if ( 10 > Utility.Random( 100 ) ) // 10% chance to do super slayer
			{
				entry = group.Super;
			}
			else
			{
				SlayerEntry[] entries = group.Entries;

				if ( entries.Length == 0 )
					return SlayerName.None;

				entry = entries[Utility.Random( entries.Length )];
			}

			return entry.Name;
		}

		public void ApplyAttributesTo( BaseArmor armor )
		{
			CraftResourceInfo resInfo = CraftResources.GetInfo( m_Resource );

			if ( resInfo == null )
				return;

			CraftAttributeInfo attrs = resInfo.AttributeInfo;

			if ( attrs == null )
				return;

			int attributeCount = Utility.RandomMinMax( attrs.RunicMinAttributes, attrs.RunicMaxAttributes );
			int min = attrs.RunicMinIntensity;
			int max = attrs.RunicMaxIntensity;

			ApplyAttributesTo( armor, true, 0, attributeCount, min, max );
		}

		public static void ApplyAttributesTo( BaseArmor armor, int attributeCount, int min, int max )
		{
			ApplyAttributesTo( armor, false, 0, attributeCount, min, max );
		}

		public static void ApplyAttributesTo( BaseArmor armor, bool isRunicTool, int luckChance, int attributeCount, int min, int max )
		{
			m_IsRunicTool = isRunicTool;
			m_LuckChance = luckChance;

			AosAttributes primary = armor.Attributes;
			AosArmorAttributes secondary = armor.ArmorAttributes;

			m_Props.SetAll( false );

			bool isShield = ( armor is BaseShield );
			int baseCount = ( isShield ? 7 : 20 );
			int baseOffset = ( isShield ? 0 : 4 );

			if ( !isShield && armor.MeditationAllowance == ArmorMeditationAllowance.All )
				m_Props.Set( 3, true ); // remove mage armor from possible properties

			for ( int i = 0; i < attributeCount; ++i )
			{
				int random = GetUniqueRandom( baseCount );

				if ( random == -1 )
					break;

				random += baseOffset;

				switch ( random )
				{
						/* Begin Sheilds */
					case  0: ApplyAttribute( primary,	min, max, AosAttribute.SpellChanneling,			1, 1 ); break;
					case  1: ApplyAttribute( primary,	min, max, AosAttribute.DefendChance,			1, 15 ); break;
					case  2: ApplyAttribute( primary,	min, max, AosAttribute.AttackChance,			1, 15 ); break;
					case  3: ApplyAttribute( primary,	min, max, AosAttribute.CastSpeed,				1, 1 ); break;
						/* Begin Armor */
					case  4: ApplyAttribute( secondary,	min, max, AosArmorAttribute.LowerStatReq,		10, 100, 10 ); break;
					case  5: ApplyAttribute( secondary,	min, max, AosArmorAttribute.SelfRepair,			1, 5 ); break;
					case  6: ApplyAttribute( secondary,	min, max, AosArmorAttribute.DurabilityBonus,	10, 100, 10 ); break;
						/* End Shields */
					case  7: ApplyAttribute( secondary,	min, max, AosArmorAttribute.MageArmor,			1, 1 ); break;
					case  8: ApplyAttribute( primary,	min, max, AosAttribute.RegenHits,				1, 2 ); break;
					case  9: ApplyAttribute( primary,	min, max, AosAttribute.RegenStam,				1, 3 ); break;
					case 10: ApplyAttribute( primary,	min, max, AosAttribute.RegenMana,				1, 2 ); break;
					case 11: ApplyAttribute( primary,	min, max, AosAttribute.NightSight,				1, 1 ); break;
					case 12: ApplyAttribute( primary,	min, max, AosAttribute.BonusHits,				1, 5 ); break;
					case 13: ApplyAttribute( primary,	min, max, AosAttribute.BonusStam,				1, 8 ); break;
					case 14: ApplyAttribute( primary,	min, max, AosAttribute.BonusMana,				1, 8 ); break;
					case 15: ApplyAttribute( primary,	min, max, AosAttribute.LowerManaCost,			1, 8 ); break;
					case 16: ApplyAttribute( primary,	min, max, AosAttribute.LowerRegCost,			1, 20 ); break;
					case 17: ApplyAttribute( primary,	min, max, AosAttribute.Luck,					1, 100 ); break;
					case 18: ApplyAttribute( primary,	min, max, AosAttribute.ReflectPhysical,			1, 15 ); break;
					case 19: ApplyResistance( armor,	min, max, ResistanceType.Physical,				1, 15 ); break;
					case 20: ApplyResistance( armor,	min, max, ResistanceType.Fire,					1, 15 ); break;
					case 21: ApplyResistance( armor,	min, max, ResistanceType.Cold,					1, 15 ); break;
					case 22: ApplyResistance( armor,	min, max, ResistanceType.Poison,				1, 15 ); break;
					case 23: ApplyResistance( armor,	min, max, ResistanceType.Energy,				1, 15 ); break;
						/* End Armor */
				}
			}
		}

		public void ApplyAttributesTo( BaseJewel jewelry )
		{
			CraftResourceInfo resInfo = CraftResources.GetInfo( m_Resource );

			if ( resInfo == null )
				return;

			CraftAttributeInfo attrs = resInfo.AttributeInfo;

			if ( attrs == null )
				return;

			int attributeCount = Utility.RandomMinMax( attrs.RunicMinAttributes, attrs.RunicMaxAttributes );
			int min = attrs.RunicMinIntensity;
			int max = attrs.RunicMaxIntensity;

			ApplyAttributesTo( jewelry, true, 0, attributeCount, min, max );
		}
		
		public static void ApplyAttributesTo( BaseJewel jewelry, int attributeCount, int min, int max )
		{
			ApplyAttributesTo( jewelry, false, 0, attributeCount, min, max );
		}

		public static void ApplyAttributesTo( BaseJewel jewelry, bool isRunicTool, int luckChance, int attributeCount, int min, int max )
		{
			m_IsRunicTool = isRunicTool;
			m_LuckChance = luckChance;

			AosAttributes primary = jewelry.Attributes;
			AosElementAttributes resists = jewelry.Resistances;
			AosSkillBonuses skills = jewelry.SkillBonuses;

			m_Props.SetAll( false );

			for ( int i = 0; i < attributeCount; ++i )
			{
				int random = GetUniqueRandom( 24 );

				if ( random == -1 )
					break;

				switch ( random )
				{
					case  0: ApplyAttribute( resists,	min, max, AosElementAttribute.Physical,			1, 15 ); break;
					case  1: ApplyAttribute( resists,	min, max, AosElementAttribute.Fire,				1, 15 ); break;
					case  2: ApplyAttribute( resists,	min, max, AosElementAttribute.Cold,				1, 15 ); break;
					case  3: ApplyAttribute( resists,	min, max, AosElementAttribute.Poison,			1, 15 ); break;
					case  4: ApplyAttribute( resists,	min, max, AosElementAttribute.Energy,			1, 15 ); break;
					case  5: ApplyAttribute( primary,	min, max, AosAttribute.WeaponDamage,			1, 25 ); break;
					case  6: ApplyAttribute( primary,	min, max, AosAttribute.DefendChance,			1, 15 ); break;
					case  7: ApplyAttribute( primary,	min, max, AosAttribute.AttackChance,			1, 15 ); break;
					case  8: ApplyAttribute( primary,	min, max, AosAttribute.BonusStr,				1, 8 ); break;
					case  9: ApplyAttribute( primary,	min, max, AosAttribute.BonusDex,				1, 8 ); break;
					case 10: ApplyAttribute( primary,	min, max, AosAttribute.BonusInt,				1, 8 ); break;
					case 11: ApplyAttribute( primary,	min, max, AosAttribute.EnhancePotions,			5, 25, 5 ); break;
					case 12: ApplyAttribute( primary,	min, max, AosAttribute.CastSpeed,				1, 1 ); break;
					case 13: ApplyAttribute( primary,	min, max, AosAttribute.CastRecovery,			1, 3 ); break;
					case 14: ApplyAttribute( primary,	min, max, AosAttribute.LowerManaCost,			1, 8 ); break;
					case 15: ApplyAttribute( primary,	min, max, AosAttribute.LowerRegCost,			1, 20 ); break;
					case 16: ApplyAttribute( primary,	min, max, AosAttribute.Luck,					1, 100 ); break;
					case 17: ApplyAttribute( primary,	min, max, AosAttribute.SpellDamage,				1, 12 ); break;
					case 18: ApplyAttribute( primary,	min, max, AosAttribute.NightSight,				1, 1 ); break;
					case 19: ApplySkillBonus( skills,	min, max, 0,									1, 15 ); break;
					case 20: ApplySkillBonus( skills,	min, max, 1,									1, 15 ); break;
					case 21: ApplySkillBonus( skills,	min, max, 2,									1, 15 ); break;
					case 22: ApplySkillBonus( skills,	min, max, 3,									1, 15 ); break;
					case 23: ApplySkillBonus( skills,	min, max, 4,									1, 15 ); break;
				}
			}
		}
	}
}