Browse files

1/19/2009 - giwo

	Added onDropItemOnItem( iDropped, cDropper, iDroppedOn ) JS Event to handle dropping an item on another item.
  • Loading branch information...
1 parent 694e6e4 commit fbce95cead99adf912054b73b4f257aee3de120b giwo committed Jan 19, 2009
Showing with 94 additions and 4 deletions.
  1. +3 −0 source/Changelog.txt
  2. +46 −2 source/cPlayerAction.cpp
  3. +41 −0 source/cScript.cpp
  4. +4 −2 source/cScript.h
View
3 source/Changelog.txt
@@ -1,3 +1,6 @@
+1/19/2009 - giwo
+ Added onDropItemOnItem( iDropped, cDropper, iDroppedOn ) JS Event to handle dropping an item on another item.
+
1/18/2009 - giwo
Moved the magic scroll handling from cPlayerAction.cpp out to JavaScript (items/magicscroll.js)
Fixed a bug with the JS Method Char.CastSpell() where it never returned a value to the calling script.
View
48 source/cPlayerAction.cpp
@@ -1107,10 +1107,54 @@ void DropOnItem( CSocket *mSock, SERIAL item, SERIAL dest, SI16 x, SI16 y, SI08
if( !ValidateObject( nItem ) )
return;
- UI16 targTrig = nItem->GetScriptTrigger();
+ bool executeCont = true;
+ UI16 targTrig = nItem->GetScriptTrigger();
cScript *toExecute = JSMapping->GetScript( targTrig );
if( toExecute != NULL )
- toExecute->OnDrop( nItem, mChar );
+ {
+ UI08 rVal = toExecute->OnDropItemOnItem( nItem, mChar, nCont ); // returns 1 if we should bounce it
+ switch( rVal )
+ {
+ case 0: // no such event
+ default:
+ executeCont = true;
+ break;
+ case 1: // bounce, no code
+ if( mSock->PickupSpot() == PL_OTHERPACK || mSock->PickupSpot() == PL_GROUND )
+ Weight->subtractItemWeight( mChar, nItem );
+ Bounce( mSock, nItem );
+ return; // stack not deleted, as we're bouncing
+ case 2: // don't bounce, use code
+ executeCont = false;
+ break;
+ case 3: // don't bounce, don't use code
+ executeCont = true;
+ break;
+ }
+ }
+ if( executeCont )
+ {
+ targTrig = nCont->GetScriptTrigger();
+ toExecute = JSMapping->GetScript( targTrig );
+ if( toExecute != NULL )
+ {
+ UI08 rVal = toExecute->OnDropItemOnItem( nItem, mChar, nCont ); // returns 1 if we should bounce it
+ switch( rVal )
+ {
+ case 2: // don't bounce, use code
+ case 0: // no such event
+ default:
+ break;
+ case 1: // bounce, no code
+ if( mSock->PickupSpot() == PL_OTHERPACK || mSock->PickupSpot() == PL_GROUND )
+ Weight->subtractItemWeight( mChar, nItem );
+ Bounce( mSock, nItem );
+ return; // stack not deleted, as we're bouncing
+ case 3: // don't bounce, don't use code
+ return;
+ }
+ }
+ }
bool stackDeleted = false;
CTile& tile = Map->SeekTile( nItem->GetID() );
View
41 source/cScript.cpp
@@ -657,6 +657,47 @@ bool cScript::OnDrop( CItem *item, CChar *dropper )
return ( retVal == JS_TRUE );
}
+UI08 cScript::OnDropItemOnItem( CItem *item, CChar *dropper, CItem *dest )
+{
+ if( !ValidateObject( item ) || !ValidateObject( dropper ) || !ValidateObject( dest ) )
+ return 0;
+ if( !ExistAndVerify( seOnDropItemOnItem, "onDropItemOnItem" ) )
+ return 0;
+
+ jsval params[2], rval;
+ JSObject *charObj = JSEngine->AcquireObject( IUE_CHAR, dropper, runTime );
+ JSObject *itemObj = JSEngine->AcquireObject( IUE_ITEM, item, runTime );
+ JSObject *destObj = JSEngine->AcquireObject( IUE_ITEM, dest, runTime );
+
+ params[0] = OBJECT_TO_JSVAL( itemObj );
+ params[1] = OBJECT_TO_JSVAL( charObj );
+ params[2] = OBJECT_TO_JSVAL( destObj );
+ JSBool retVal = JS_CallFunctionName( targContext, targObject, "onDropItemOnItem", 2, params, &rval );
+ if( retVal == JS_FALSE )
+ SetEventExists( seOnDropItemOnItem, false );
+
+ UI08 funcRetVal = 0;
+ if( !( JSVAL_IS_NULL( rval ) ) ) // They returned some sort of value
+ {
+ if( JSVAL_IS_INT( rval ) )
+ {
+ // script returns
+ // 0 == bounce
+ // 1 == don't bounce, use code
+ // 2 == don't bounce, don't use code
+ // Our func returns values 1 higher
+ funcRetVal = static_cast< UI08 >(JSVAL_TO_INT( rval ) + 1);
+ if( funcRetVal < 1 || funcRetVal > 3 )
+ funcRetVal = 2; // don't bounce, use code
+ }
+ else
+ funcRetVal = 2; // don't bounce, use code
+ }
+ else
+ funcRetVal = 2; // don't bounce, use code
+ return funcRetVal;
+}
+
// Replaced this with new function, this one didn't work for some reason
/*bool cScript::OnPickup( CItem *item, CChar *pickerUpper )
{
View
6 source/cScript.h
@@ -87,7 +87,8 @@ enum ScriptEvent
seOnCombatDamageCalc,
seOnDamage,
seOnGumpPress,
- seOnGumpInput
+ seOnGumpInput,
+ seOnDropItemOnItem
};
struct SEGump
@@ -219,7 +220,8 @@ class cScript
bool OnSpellLoss( CItem *book, const UI08 spellNum );
bool OnSkillCheck( CChar *myChar, const UI08 skill, const UI16 lowSkill, const UI16 highSkill );
// MACTEP: 041802: Support for new event
- UI08 OnDropItemOnNpc( CChar *srcChar, CChar *targChar, CItem *i);
+ UI08 OnDropItemOnNpc( CChar *srcChar, CChar *targChar, CItem *i );
+ UI08 OnDropItemOnItem( CItem *item, CChar *dropper, CItem *dest );
bool AreaObjFunc( char *funcName, CBaseObject *srcObject, CBaseObject *tmpObject, CSocket *s );
bool CallParticularEvent( const char *eventToCall, jsval *params, SI32 numParams );

0 comments on commit fbce95c

Please sign in to comment.