////////////////////////////////////////////////////////////////////////////// // // File : weapon_cast.skrit // Author(s): Witness (Lisa Hui) // Purpose : handles the visuals for equippables that trigger spell casting // History : v3.1 [November 7, 2004] // - sfx is now restarted when the user is loaded into a frustum // after being unloaded from all frustums // - split Equipped and Unequipped$ back into two states // // v3.0 [November 5, 2004] // - adds a property variable for hiding the weapon mesh // - moves glove spawning to another skrit component...that is no // longer a function of weapon_cast (never logically belonged) // // v2.3 [October 29, 2004] // - fixes problem whereby looped casting (job) doesn't update charge // count by ending the job when we_trigger_deactivate is detected // // v2.2 [October 17, 2004] // v2.1 [August 10, 2004] // v2.0 [July 19, 2004] // v1.0 [July 7, 2004] // //---------------------------------------------------------------------------- // Version: 3.0 Date: November 5, 2004 //---------------------------------------------------------------------------- ////////////////////////////////////////////////////////////////////////////// property string effect_script$ = "" doc = "Name of SiegeFX script to run while charges_curr$ > 0"; property string effect_params$ = "" doc = "Name of SiegeFX script to run while charges_curr$ > 0"; property bool hide$ = false doc = "Hide this weapon when equipped"; property string texture$ = "" doc = "Weapon texture (automatically set)"; property string spell$ = "" doc = "Template name of the spell to be cast"; owner = GoSkritComponent; ////////////////////////////////////////////////////////////////////////////// // GLOBALS ////////////////////////////////////////////////////////////////////////////// Goid parent$; //void debug$(string state$, string msg$) { // if ( state$ != "" ) { // StringTool.AssignF( msg$, "(%s) %s", state$, msg$ ); // } // report.screenf("%s (%d)> %s", owner.Go.TemplateName, MakeInt(owner.Goid), msg$); //} trigger OnGoPreload$ { if ( spell$ != "" ) { GoDb.PreloadCloneSource( owner.Go, spell$ ); } } ////////////////////////////////////////////////////////////////////////////// // STATES ////////////////////////////////////////////////////////////////////////////// startup State Init$ { #only(game) [[ event OnEnterState$ { if ( IsInGame( WorldState.CurrentState ) ) { if ( owner.Go.IsEquipped() ) { SetState Equipped$; return; } SetState Unequipped$; } } trigger OnGoHandleMessage$( WE_WORLD_STATE_TRANSITION_DONE ) { if ( owner.Go.IsEquipped() ) { SetState Equipped$; return; } SetState Unequipped$; } ]] } State Unequipped$ { event OnEnterState$ { if ( owner.Go.IsEquipped() ) { SetState Equipped$; return; } } transition -> Equipped$ : OnGoHandleMessage( WE_EQUIPPED ); } State Equipped$ { SFxSID sfx_id$ = 0; bool sfx_on$ = false; bool unloaded$ = false; event OnEnterState$ { parent$ = owner.Go.Parent.Goid; if ( !parent$.IsValid ) { return; } //hide the weapon mesh/ground model if ( hide$ ) { // debug$("Equipped$", "set invisible"); owner.Go.Aspect.SSetIsVisible( false ); if ( texture$ != "" ) { owner.Go.Aspect.SSetCurrentAspectTexture( 0, "b_t_alpha" ); } } //play sfx if ( effect_script$ != "" ) { if ( owner.Go.HasComponent( "charges" ) ) { if ( owner.Go.GetComponentInt( "charges", "charges_curr", 1 ) > 0 ) { sfx_id$ = SiegeFx.SRunMpScript( effect_script$, parent$, owner.Goid, effect_params$, owner.goid, WE_EQUIPPED ); sfx_on$ = true; } } else { sfx_id$ = SiegeFx.SRunScript( effect_script$, parent$, owner.Goid, effect_params$, owner.goid, WE_EQUIPPED ); sfx_on$ = true; } } GoDb.StartWatching( owner.Goid, parent$ ); } trigger OnGoHandleMessage$( WE_TRIGGER_ACTIVATE ) { //charges has been restored/regenerated while still equipped on the character //turn sfx on if ( !sfx_on$ ) { if ( effect_script$ != "" ) { if ( parent$.IsValid ) { sfx_id$ = SiegeFx.SRunMpScript( effect_script$, parent$, owner.Goid, effect_params$, owner.goid, WE_EQUIPPED ); sfx_on$ = true; } } } } trigger OnGoHandleMessage$( WE_TRIGGER_DEACTIVATE ) { //ran out of charges //turn sfx off if ( sfx_on$ ) { SiegeFx.SStopScript( sfx_id$ ); sfx_on$ = false; } if ( parent$.IsValid ) { //stop the casting job if it still running (probably looped) Job currentAction$ = parent$.Go.Mind.GetFrontJob( JQ_ACTION ); if ( currentAction$ != NULL ) { if ( currentAction$.JobAbstractType == JAT_CAST ) { currentAction$.RequestEnd(); } } } } trigger OnGoHandleCCMessage$( WE_FRUSTUM_MEMBERSHIP_CHANGED ) { if( unloaded$ ) { // debug$( "Equipped$", "reloaded character...previously fell off frustum"); //reapply sfx if necessary if ( sfx_on$ ) { sfx_id$ = SiegeFx.SRunMpScript( effect_script$, parent$, owner.Goid, effect_params$, owner.goid, WE_EQUIPPED ); } } unloaded$ = !parent$.Go.IsInAnyWorldFrustum(); } event OnExitState$ { //turn sfx off if ( sfx_on$ ) { SiegeFx.SStopScript( sfx_id$ ); sfx_on$ = false; } //show the weapon mesh/ground model if ( hide$ ) { if ( texture$ != "" ) { owner.Go.Aspect.SSetCurrentAspectTexture( 0, texture$ ); } } if ( parent$.IsValid ) { GoDb.StopWatching( owner.Goid, parent$ ); } } transition -> Unequipped$ : OnGoHandleMessage( WE_UNEQUIPPED ); }