////////////////////////////////////////////////////////////////////////////// // // File : aura.skrit // Author(s): Witness (Lisa Hui) // Purpose : basic aura active state detection // // Versions : v2.0 [November 13, 2004] // - adds a check manager that replaces the spellbook as the // activator // - simplified state code // // v1.0 [August 8, 2004] // - moved aura attribute management into separate components // //---------------------------------------------------------------------------- // Version: 2.0 Date: November 13, 2004 //---------------------------------------------------------------------------- ////////////////////////////////////////////////////////////////////////////// property string aura_manager$ = "aura_enchant" doc = "the template of the object that will manages target visuals and ancillary effects"; property string aura_component$ = "aura_enchant" doc = "the (skrit) component that drives the manager"; property string check_state$ = "aura_check" doc = "name of the generic state to add to the actor"; property string check_manager$ = "aura_check" doc = "template name for the omni to be associated with the aura-checking generic state"; property string check_component$ = "aura_spellbook" doc = "name of the check component in the check manager"; property int enchantments$ = 0 doc = "number of enchantments to apply to the source or target while in active state"; property bool enchant_scales$ = false doc = ""; owner = GoSkritComponent; ////////////////////////////////////////////////////////////////////////////// // GLOBALS ////////////////////////////////////////////////////////////////////////////// Goid caster$, spellbook$; //void debug$ (string msg$) { // report.screenf("%s (%d)> %s", owner.Go.TemplateName, MakeInt(owner.Goid), msg$); //} trigger OnGoPreload$ { if ( aura_manager$ != "" ) { GoDb.PreloadCloneSource ( owner.Go, aura_manager$ ); } } ////////////////////////////////////////////////////////////////////////////// // STATES ////////////////////////////////////////////////////////////////////////////// startup State Init$ { event OnEnterState$ { caster$ = Goid.InvalidGoid; spellbook$ = Goid.InvalidGoid; if ( IsInGame( WorldState.CurrentState ) ) { SetState Unequipped$; } } trigger OnGoHandleMessage$( WE_WORLD_STATE_TRANSITION_DONE ) { if ( IsInGame( WorldState.CurrentState ) ) { SetState Unequipped$; } } } State Unequipped$ { transition -> Unequipped$ : OnGoHandleMessage( WE_PLAYER_CHANGED ); //OnTimer( 1 ); event OnEnterState$ { //debug$( "Unequipped$ - OnEnterState$" ); //update spellbook goid Go parent$ = owner.Go.Parent; if ( parent$ != NULL ) { if ( !parent$.IsSpellbook() ) { return; } if ( parent$.Goid == spellbook$ ) { //sanity check return; } if ( spellbook$.IsValid ) { //shouldn't happen due to equip order, but just in case... GoDb.StopWatching( owner.Goid, spellbook$ ); } spellbook$ = parent$.Goid; if ( spellbook$.IsValid ) { GoDb.StartWatching( owner.Goid, spellbook$ ); SetState Equipped$; return; } } else if ( spellbook$.IsValid ) { GoDb.StopWatching( owner.Goid, spellbook$ ); spellbook$ = Goid.InvalidGoid; } } //trigger OnGoHandleMessage$( WE_PLAYER_CHANGED ) { // //if timer delay is 0.0, might as well just use a setstate call instead... // this.CreateTimer( 1, 0.0 ); //} } State Equipped$ { transition -> Equipped$ : OnGoHandleCCMessage( WE_PLAYER_CHANGED ); event OnEnterState$ { //debug$( "Equipped$ - OnEnterState$" ); if ( !spellbook$.IsValid ) { caster$ = Goid.InvalidGoid; SetState Unequipped$; return; } //update caster goid Go parent$ = spellbook$.Go.Parent; if ( parent$ != NULL ) { if ( parent$.Goid == caster$ ) { //sanity check return; } caster$ = parent$.Goid; if ( !parent$.HasMind() ) { return; } if ( !parent$.HasActor() ) { return; } if ( !parent$.Actor.HasGenericState( check_state$ ) ) { //create the check manager GoCloneReq req$ = MakeGoCloneReq( caster$, check_manager$ ); req$.Omni = true; Goid check_manager$ = GoDb.SCloneGo( req$ ); check_manager$.Go.SetComponentString( check_component$, "check_state", check_state$ ); //activate the check manager PostWorldMessage( WE_REQ_ACTIVATE, caster$, check_manager$, 0 ); //add the check state parent$.Actor.SAddGenericState( check_state$, "", 0.0, caster$, check_manager$, 1.0 ); } } else if ( caster$.IsValid ) { caster$ = Goid.InvalidGoid; } } trigger OnGoHandleMessage$( WE_REQ_ACTIVATE ) { if ( !spellbook$.IsValid ) { //shouldn't ever happen... caster$ = Goid.InvalidGoid; SetState Unequipped$; return; } if ( !caster$.IsValid ) { //shouldn't ever happen... return; } SetState Active$; } } State Active$ { Goid manager$; event OnEnterState$ { //debug$( "Active$ - OnEnterState$" ); //create the manager GoCloneReq req$ = MakeGoCloneReq( spellbook$, aura_manager$ ); req$.Omni = true; manager$ = GoDb.SCloneGo( req$ ); //configure the manager manager$.Go.SetComponentInt( aura_component$, "enchant_source", enchantments$ ); manager$.Go.SetComponentBool( aura_component$, "enchant_source_scales", enchant_scales$ ); //activate the manager PostWorldMessage( WE_TRIGGER_ACTIVATE, owner.Goid, manager$, MakeInt( caster$ ), 0 ); //set the state info string description$; owner.Go.Common.GetScreenName( description$ ); caster$.Go.Actor.SAddGenericState( owner.Go.Magic.StateName, description$, 0.0, caster$, manager$, owner.Go.Magic.GetMagicLevel( caster$.Go ) ); } event OnExitState$ { if ( caster$.IsValid ) { caster$.Go.Actor.SRemoveGenericState( owner.Go.Magic.StateName ); } if ( manager$.IsValid ) { PostWorldMessage( WE_TRIGGER_DEACTIVATE, owner.Goid, manager$, 0 ); } } transition -> Equipped$ : OnGoHandleMessage( WE_REQ_DEACTIVATE );// = { // debug$( "Active$ - heard WE_REQ_DEACTIVATE" ); //} transition -> Equipped$ : OnGoHandleMessage( WE_PLAYER_CHANGED ); }