///////////////////////////////////////////////////////////////////////////// // // File : weapon_attack_notify_melee.skrit // Author(s): Witness (Lisa Hui) // Purpose : centralizing notifications so that melee weapons can use multiple // custom attack skrits in a modular/plugin fashion // //---------------------------------------------------------------------------- // Version: 1.0 Date: August 30, 2004 //---------------------------------------------------------------------------- ////////////////////////////////////////////////////////////////////////////// property eWorldEvent msg_hit_begin$ = WE_REQ_ACTIVATE doc = ""; property eWorldEvent msg_hit$ = WE_REQ_CAST doc = ""; property eWorldEvent msg_hit_killed$ = WE_ENGAGED_HIT_KILLED doc = ""; property eWorldEvent msg_hit_end$ = WE_REQ_DEACTIVATE doc = ""; property eWorldEvent msg_die_begin$ = WE_TRIGGER_DEACTIVATE doc = "occurs in multiplayer only"; property eWorldEvent msg_die_end$ = WE_TRIGGER_ACTIVATE doc = "occurs in multiplayer only"; owner = GoSkritComponent; ////////////////////////////////////////////////////////////////////////////// // GLOBALS ////////////////////////////////////////////////////////////////////////////// Goid wielder$, target$; ////////////////////////////////////////////////////////////////////////////// // STATES ////////////////////////////////////////////////////////////////////////////// startup State Unequipped$ { #only(game) [[ event OnGoHandleMessage$( eWorldEvent e$, WorldMessage msg$ ) { if( e$ == WE_EQUIPPED ) { wielder$ = msg$.GetSendFrom(); if( !wielder$.IsValid ) { return; } GoDb.StartWatching( owner.goid, wielder$ ); SetState Equipped$; } } ]] } //all states leading to this state must check whether or not the user is valid before transitioning to this one State Equipped$ { event OnEnterState$ { target$ = wielder$.Go.Mind.EngagedObject; } event OnGoHandleCCMessage$( eWorldEvent e$, WorldMessage msg$ ) { //Report.ScreenF( "%s heard (CC: %s) %s", owner.Go.TemplateName, msg$.GetSendTo().Go.TemplateName, toString( e$ ) ); if ( e$ == WE_MCP_FACING_LOCKEDON ) { //if wielder is about to attack, the mind should have a valid engaged object for ProcessHitEngaged target$ = wielder$.Go.Mind.EngagedObject; if ( target$.IsValid ) { //apply any attack bonuses to be factored into the attack PostWorldMessage( msg_hit_begin$, wielder$, owner.Goid, 0.0 ); } } else if ( e$ == WE_ANIM_WEAPON_FIRE ) { if ( !target$.IsValid ) { //Report.screen("--> not targeted"); return; } SetState Damaging$; } else if ( e$ == WE_ANIM_DONE ) { //notify end of swing PostWorldMessage( WE_ANIM_DONE, owner.Goid, owner.Goid, 0.0 ); } else if ( e$ == WE_KILLED ) { if ( msg$.GetSendTo() == wielder$ ) { SetState Died$; } } } transition -> Unequipped$ : OnGoHandleMessage( WE_UNEQUIPPED ) = { GoDb.StopWatching( owner.goid, wielder$ ); } } State Damaging$ { event OnEnterState$ { if ( target$.IsValid ) { //testing only //target$.Go.Aspect.SetIsInvincible( true ); //listen to the target for damage message GoDb.StartWatching( owner.Goid, target$ ); } } event OnGoHandleCCMessage$( eWorldEvent e$, WorldMessage msg$ ) { //Report.ScreenF( "%s heard (CC: %s) %s", owner.Go.TemplateName, msg$.GetSendTo().Go.TemplateName, toString( e$ ) ); if ( e$ == WE_DAMAGED ) { //check if target damaged if ( msg$.GetSendTo() != target$ ) { return; } //check if wielder caused the damage //Report.screenf("---> damage data1 (%d: %s)", msg$.Data1, MakeGoid(msg$.Data1).Go.TemplateName); if ( MakeGoid(msg$.Data1) != wielder$ ) { //Report.screenf("---> damage source is not the wielder!!!"); return; } //apply weapon effects PostWorldMessage( msg_hit$, wielder$, owner.Goid, 0.0 ); SetState Equipped$; } else if ( e$ == WE_ENGAGED_MISSED ) { //attack missed if ( msg$.GetSendTo() == wielder$ ) { SetState Equipped$; } } else if ( e$ == WE_ENGAGED_HIT_KILLED ) { if ( msg$.GetSendTo() == wielder$ ) { PostWorldMessage( msg_hit_killed$, wielder$, owner.Goid, MakeInt( target$ ), 0.0 ); SetState Equipped$; } } else if ( e$ == WE_ANIM_DONE ) { if ( msg$.GetSendTo() == wielder$ ) { //shouldn't have needed to wait this long, but we did... //notify end of swing PostWorldMessage( WE_ANIM_DONE, owner.Goid, owner.Goid, 0.0 ); SetState Equipped$; } } else if ( e$ == WE_KILLED ) { if ( msg$.GetSendTo() == wielder$ ) { SetState Died$; } } } event OnExitState$ { if ( target$.IsValid ) { //testing only //target$.Go.Aspect.SetIsInvincible( false ); //don't need to listen to the target anymore GoDb.StopWatching( owner.Goid, target$ ); } //remove any attack bonuses applied to the attack PostWorldMessage( msg_hit_end$, wielder$, owner.Goid, 0.0 ); } } State Died$ { event OnEnterState$ { //Report.SScreenF( "%s - entering Died$ state (%s)", owner.Go.TemplateName, wielder$.Go.TemplateName ); this.CreateTimer( 1, 0.33 ); //wait a moment to see what sort of death drop settings are in effect } trigger OnGoHandleMessage$( WE_PLAYER_CHANGED ) { //the weapon was dropped on death if ( wielder$.IsValid ) { //Report.SScreenF( "%s - WE_DROPPED (%s)", owner.Go.TemplateName, wielder$.Go.TemplateName ); GoDb.StopWatching( owner.goid, wielder$ ); } SetState Unequipped$; } transition -> WaitForResurrection$ : OnTimer( 1 ) = { //Report.SScreenF( "%s - entering WaitForResurrection$ state (%s)", owner.Go.TemplateName, wielder$.Go.TemplateName ); } } //user died and is still wearing the item...we need to wait for the player to be resurrected State WaitForResurrection$ { event OnEnterState$ { //tell the weapon to suspend any remote effects PostWorldMessage( msg_die_begin$, wielder$, owner.Goid, 0.0 ); } event OnGoHandleCCMessage$( eWorldEvent, WorldMessage ) { if( IsAlive( wielder$.Go.LifeState ) ) { SetState Equipped$; } } event OnExitState$ { //tell the weapon to resume any remote effects PostWorldMessage( msg_die_end$, wielder$, owner.Goid, 0.0 ); } }