Stat Gain

Here you can post threads requesting help on the official POL Ultima Online Emulator Core 095. Note: Core 095 is no longer officially supported.
Post Reply
Exar Kun
Novice Poster
Posts: 42
Joined: Wed Apr 19, 2006 12:29 pm

Stat Gain

Post by Exar Kun »

I got a hold of a server where Stat Gain was not tied to skill gain. I'm trying to tie it back in. I'd appreciate any help I can get.

Right now, when my CheckSkill runs, a succesful skill check earns a Raw Stat Point.

Code: Select all

if ( rawMaxSkill > possibleNewRawSkill )
				AwardRawSkill ( character, attribute, 1 );
				StatIncrease ( character, attribute );
			endif
Here's the StatIncrease function (yes, I understand I should put in a function to handle the repetitive code, but I'm just trying to get the whole thing working right now):

Code: Select all

function StatIncrease ( character, attribute )

case ( attribute )

	"Alchemy":

	"Anatomy":

	"Detecthidden":

	"Leadership":

	"Invocation":

	"Magery":

	"Magicresistance":

	"Meditation":

	"Necromancy":

	"Tactics":

	"Tracking":

	"Veterinary":

		var currentInt := GetObjProperty ( character, "int" );
		var rawCurrentInt := BaseToRaw ( currentInt * 10 );

		rawCurrentInt := ( rawCurrentInt + 1 );

		var newCurrentInt := RawToBase ( rawCurrentInt );

		newCurrentInt := ( newCurrentInt / 10 );
		SetObjProperty ( character, "int", newCurrentInt );

		var unmod_Int := CInt ( GetAttributeBaseValue ( character, "Intelligence" ) / 10 );

			if ( ( CInt ( newCurrentInt ) ) > unmod_Int )

				var charMaxStat := GetObjProperty ( character, "maxint" );
				var rawMaxStat := BaseToRaw ( charMaxStat );

				rawMaxStat := ( rawMaxStat + 1 );

				var currentRawStat := BaseToRaw ( currentInt * 10 );
				var possibleNewRawStat := ( currentRawStat + 1);

					if ( rawMaxStat > possibleNewRawStat )
						SetAttributeBaseValue ( character, "Intelligence", unmod_Int * 10 + 10 );
						RecalcVitals ( character );
					endif

			endif

	"Archery":

	"Fencing":

	"Lockpicking":

	"Stealing":

	"Stealth":

	"Parry":

	"Tinkering":

	"Tailoring":

	"Cartography":

	"Hiding":

	"Musicianship":

	"Poisoning":

	"Inscription":

		var currentDex := GetObjProperty ( character, "dex" );
		var rawCurrentDex := BaseToRaw ( currentDex * 10 );

		rawCurrentDex := ( rawCurrentDex + 1 );

		var newCurrentDex := RawToBase ( rawCurrentDex );

		newCurrentDex := ( newCurrentDex / 10 );
		SetObjProperty ( character, "dex", newCurrentDex );

		var unmod_Dex := CInt ( GetAttributeBaseValue ( character, "Dexterity" ) / 10 );

			if ( ( CInt ( newCurrentDex ) ) > unmod_Dex )

				var charMaxStat := GetObjProperty ( character, "maxdex" );
				var rawMaxStat := BaseToRaw ( charMaxStat );

				rawMaxStat := ( rawMaxStat + 1 );

				var currentRawStat := BaseToRaw ( currentDex * 10 );
				var possibleNewRawStat := ( currentRawStat + 1);

					if ( rawMaxStat > possibleNewRawStat )
						SetAttributeBaseValue ( character, "Dexterity", unmod_Dex * 10 + 10 );
						RecalcVitals ( character );
					endif
			endif


	"Lumberjacking":

	"Mining":

	"Wrestling":

	"Blacksmithy":

	"Carpentry":

	"Fishing":

	"Macefighting":

	"Swordsmanship":

	"Camping":

	"Druidry":

		var currentStr := GetObjProperty ( character, "str" );
		var rawCurrentStr := BaseToRaw ( currentStr * 10 );

		rawCurrentStr := ( rawCurrentStr + 1 );

		var newCurrentStr := RawToBase ( rawCurrentStr );

		newCurrentStr := ( newCurrentStr / 10 );
		SetObjProperty ( character, "str", newCurrentStr );

		var unmod_Str := CInt ( GetAttributeBaseValue ( character, "Strength" ) / 10 );

			if ( ( CInt ( newCurrentStr ) ) > unmod_Str )

				var charMaxStat := GetObjProperty ( character, "maxstr" );
				var rawMaxStat := BaseToRaw ( charMaxStat );

				rawMaxStat := ( rawMaxStat + 1 );

				var currentRawStat := BaseToRaw ( currentStr * 10 );
				var possibleNewRawStat := ( currentRawStat + 1);

					if ( rawMaxStat > possibleNewRawStat )
						AwardRawStat ( character, "str", 1 )
						SetAttributeBaseValue ( character, "Strength", unmod_Str * 10 + 10 );
						RecalcVitals ( character );
					endif
			endif

	"Cooking":

	"Healing":

	"Peacemaking":

	"Provocation":

	"Taming":

		return;

	default:

		DohEth ( character );

endcase

endfunction
So now AwardRawStat:

Code: Select all

function AwardRawStat ( character, statID, rawStatPoints )

var calcRawStat, rawElem;

	if ( !rawStatPoints )
		return;
	endif

	if ( character.npctemplate )
		rawElem := npcRawSkill.FindElement ( character.serial );

			if ( !rawElem )
				rawElem := npcRawSkill.CreateElement ( character.serial );
			endif

		calcRawStat := rawElem.GetProp ( "raw" + statID ) + rawStatPoints;

			if ( !calcRawStat )
				calcRawStat := rawStatPoints;
			endif

		rawElem.SetProp ( "raw" + statID, calcRawStat );
		SetBaseStatFromRaw ( character, statID, calcRawStat );
	else
		calcRawStat := GetObjProperty ( character, "raw" + statID ) + rawStatPoints;

			if ( !calcRawStat )
				calcRawStat := rawStatPoints;
			endif

		SetBaseStatFromRaw ( character, statID, calcRawStat );
		SetObjProperty ( character, "raw" + statID, calcRawStat );
	endif

endfunction
SetBaseStatFromRaw:

Code: Select all

function SetBaseStatFromRaw ( character, statID, rawStat )

var calc_Base_Stat := RawToBase ( rawStat );

	if ( calc_Base_Stat == GetAttributeBaseValue ( character, statID ) )
		return;
	else
		SetAttributeBaseValue ( character, statID, calc_Base_Stat );
	endif

endfunction
GetRawStat:

Code: Select all

function GetRawStat ( character, statID )

var rawStat, rawElem;

	if ( character.npctemplate )
		rawElem := npcRawSkill.FindElement ( character.serial );
		rawStat := rawElem.GetProp ( "raw" + statID );
	else
		rawStat := GetObjProperty ( character, "raw" + statID );
	endif

	if ( !rawStat )
		return 0;
	else
		return rawStat;
	endif

endfunction
SetRawStat:

Code: Select all

function SetRawStat ( character, statID, rawStatPoints )

var rawElem;

	if ( rawStatPoints )

			if ( character.npctemplate )
				rawElem := npcRawSkill.FindElement ( character.serial );

					if ( !rawElem )
						npcRawSkill.CreateElement ( character.serial );
					endif

				rawElem.SetProp ( "raw" + statID, rawStatPoints );
			else
				SetObjProperty ( character, "raw" + statID, rawStatPoints );
			endif

		SetBaseStatFromRaw ( character, statID, rawStatPoints );
	endif

endfunction
Basically, I ripped off the old AwardRawSkill functions and changed the variable names. I don't think I can display a 0.1 gain for a Stat (STR, DEX, INT), so am I handling this correctly? I think I'm stretched to my coding limits on this one.

I'd appreciate any help. Thanks.
Firedancer
Grandmaster Poster
Posts: 104
Joined: Fri Feb 03, 2006 6:32 am

Re: Stat Gain

Post by Firedancer »

As to your question: You asume correctly, stats are integer values, you can't set them to e.g. 0.1 - but of course you could keep an internal value, e.g. in a cprop, which could hold a more accurate value.
(And you can then take that value for your maths and maybe even for display)

Ps: As to the topic as a whole, I'm a bit lazy to read all that code, not knowing what to look for. What exactly is it doing now? Finding a problem is one thing, but I doubt you'll find someone willing to test your scripts for you. I bet if you could tell us, as to what it's doing differently than you expect, then you'd find people more willing to look up the issue for you...
Exar Kun
Novice Poster
Posts: 42
Joined: Wed Apr 19, 2006 12:29 pm

Post by Exar Kun »

Right, I have added two props per stat to characters on creation. One prop is the raw value of the stat, the other is the decimal value including the tenths place.

I'm not looking for a test, I think the actual coding is solid until the calculation of the raw stat. I guess I need to add the raw value up, convert it to it's decimal equivalent, then do a check to see if it rouned the corner to the next integer, then set the actual stat to that integer value.

I had to step away from it for a while to re-gain perspective. I was getting tunnel-vision.
Post Reply