///////////////////////////////////////////////////////////////////////////// // // File : subanim_manager.skrit // Author(s): Witness (Lisa Hui) // Purpose : override animation for a supported chore // History : v1.0 [September 10, 2004] // - sets quest bits cues for animation overrides and can // manage multiple overrides // // Note that this script does not (yet) check for the existence of the // specified overriding animation(s) before setting the quest bit(s). // //---------------------------------------------------------------------------- // Version: 1.0 Date: September 10, 2004 //---------------------------------------------------------------------------- ////////////////////////////////////////////////////////////////////////////// property string component$ = "subanim_override" doc = ""; owner = GoSkritComponent; startup State Listen$ { Goid override_attack$, override_fidget$, override_walk$; string notify_goids$; int notify_count$; void UpdateAnim$( Goid user$ ) { //make changes effective immediately //MCPManager.Flush( user$ ); Job action$ = user$.Go.Mind.GetFrontJob( JQ_ACTION ); if ( action$ != NULL ) { action$.RequestEnd(); if ( action$.JobAbstractType == JAT_FIDGET ) { //MCPManager.Flush( user$ ); MCPManager.MakeRequest( user$, PL_FIDGET, 0 ); } else { MCPManager.Flush( user$ ); } } } event OnEnterState$ { override_attack$ = Goid.InvalidGoid; override_fidget$ = Goid.InvalidGoid; override_walk$ = Goid.InvalidGoid; notify_goids$ = ""; notify_count$ = 0; } event OnGoHandleMessage$( eWorldEvent e$, WorldMessage msg$ ) { if ( e$ == WE_REQ_ACTIVATE ) { Goid override$ = msg$.SendFrom; Goid user$ = MakeGoid( msg$.Data1 ); if ( !override$.IsValid || !user$.IsValid ) { return; } if ( !override$.Go.HasComponent( component$ ) ) { return; } //if it is already in the notify list, ignore the activation request int override_goid$ = MakeInt( override$ ); int index$ = notify_count$ - 1; int notify_goid$; while ( index$ > 0 ) { notify_goid$ = StringTool.GetDelimitedInt( notify_goids$, index$, ' ', 0 ); if ( notify_goid$ == override_goid$ ) { return; } index$ -= 1; } //add this goid to the notify list StringTool.AppendF( notify_goids$, " %d", override_goid$ ); notify_count$ += 1; //override attack anim? int anim_attack$ = override$.Go.GetComponentInt( component$, "anim_attack" ); if ( anim_attack$ < 0 ) { GoDb.SSetQuestInt( user$, "chore", "attack", anim_attack$ ); GoDb.SSetQuestInt( user$, "chore", "attack_min", user$.Go.Aspect.AspectHandle.Blender.GetSubAnimIndex( CHORE_ATTACK, override$.Go.GetComponentInt( component$, "anim_attack_min" ) ) ); if ( anim_attack$ < -1 ) { GoDb.SSetQuestInt( user$, "chore", "attack_max", user$.Go.Aspect.AspectHandle.Blender.GetSubAnimIndex( CHORE_ATTACK, override$.Go.GetComponentInt( component$, "anim_attack_max" ) ) ); } override_attack$ = override$; } //override attack fidget anim? int anim_attack_fidget$ = override$.Go.GetComponentInt( component$, "anim_attack_fidget" ); if ( anim_attack_fidget$ > -1 ) { GoDb.SSetQuestInt( user$, "chore", "attack_fidget", user$.Go.Aspect.AspectHandle.Blender.GetSubAnimIndex( CHORE_ATTACK, anim_attack_fidget$ ) ); } //override fidget anim? int anim_fidget$ = override$.Go.GetComponentInt( component$, "anim_fidget" ); if ( anim_fidget$ < 0 ) { GoDb.SSetQuestInt( user$, "chore", "fidget", anim_fidget$ ); GoDb.SSetQuestInt( user$, "chore", "fidget_min", user$.Go.Aspect.AspectHandle.Blender.GetSubAnimIndex( CHORE_FIDGET, override$.Go.GetComponentInt( component$, "anim_fidget_min" ) ) ); if ( anim_fidget$ < -1 ) { GoDb.SSetQuestInt( user$, "chore", "fidget_max", user$.Go.Aspect.AspectHandle.Blender.GetSubAnimIndex( CHORE_FIDGET, override$.Go.GetComponentInt( component$, "anim_fidget_max" ) ) ); } override_fidget$ = override$; //report.screenf("subanim_manager - overriding fidget %d-%d",user$.Go.Aspect.AspectHandle.Blender.GetSubAnimIndex( CHORE_FIDGET, override$.Go.GetComponentInt( component$, "anim_fidget_min" ) ), user$.Go.Aspect.AspectHandle.Blender.GetSubAnimIndex( CHORE_FIDGET, override$.Go.GetComponentInt( component$, "anim_fidget_max" ) )); } //override walk/run anim? int anim_walk$ = override$.Go.GetComponentInt( component$, "anim_walk" ); if ( anim_walk$ < 0 ) { GoDb.SSetQuestInt( user$, "chore", "walk", anim_walk$ ); GoDb.SSetQuestInt( user$, "chore", "walk_min", user$.Go.Aspect.AspectHandle.Blender.GetSubAnimIndex( CHORE_WALK, override$.Go.GetComponentInt( component$, "anim_walk_min" ) ) ); if ( anim_walk$ < -1 ) { GoDb.SSetQuestInt( user$, "chore", "walk_max", user$.Go.Aspect.AspectHandle.Blender.GetSubAnimIndex( CHORE_WALK, override$.Go.GetComponentInt( component$, "anim_walk_max" ) ) ); } override_walk$ = override$; } UpdateAnim$( user$ ); } else if ( e$ == WE_REQ_DEACTIVATE ) { //report.screen("subanim_manager - WE_REQ_DEACTIVATE"); Goid override$ = msg$.SendFrom; Goid user$ = MakeGoid( msg$.Data1 ); if ( !override$.IsValid || !user$.IsValid ) { return; } //report.screen("subanim_manager - WE_REQ_DEACTIVATE - remove from sync list"); //remove from sync list string new_notify_list$ = ""; int override_goid$ = MakeInt( override$ ); int index$ = notify_count$ - 1; int notify_goid$; while ( index$ > 0 ) { notify_goid$ = StringTool.GetDelimitedInt( notify_goids$, index$, ' ', 0 ); if ( notify_goid$ != override_goid$ ) { StringTool.AppendF( new_notify_list$, " %d", notify_goid$ ); } else { notify_count$ -= 1; } index$ -= 1; } notify_goids$ = new_notify_list$; //process new sync list if there was a related override int resync$ = 0; string resync_check$ = ""; if ( override_attack$ == override$ ) { //report.screen("subanim_manager - WE_REQ_DEACTIVATE - found attack override"); override_attack$ = Goid.InvalidGoid; resync$ += 1; } if ( override_fidget$ == override$ ) { //report.screen("subanim_manager - WE_REQ_DEACTIVATE - found fidget override"); override_fidget$ = Goid.InvalidGoid; resync$ += 1; } if ( override_walk$ == override$ ) { //report.screen("subanim_manager - WE_REQ_DEACTIVATE - found walk override"); override_walk$ = Goid.InvalidGoid; resync$ += 1; } if ( resync$ > 0 ) { //report.screenf("subanim_manager - WE_REQ_DEACTIVATE - notify_count$ %d", notify_count$); //order is important, the latest notify goids override earlier goids Goid notify$; int anim_attack$, anim_fidget$, anim_walk$; index$ = notify_count$ - 1; while ( index$ > 0 ) { notify$ = MakeGoid( StringTool.GetDelimitedInt( notify_goids$, index$, ' ', 0 ) ); if ( notify$.IsValid ) { if ( !override_attack$.IsValid ) { anim_attack$ = notify$.Go.GetComponentInt( component$, "anim_attack", 0 ); if ( anim_attack$ < 0 ) { GoDb.SSetQuestInt( user$, "chore", "attack", anim_attack$ ); GoDb.SSetQuestInt( user$, "chore", "attack_min", user$.Go.Aspect.AspectHandle.Blender.GetSubAnimIndex( CHORE_ATTACK, notify$.Go.GetComponentInt( component$, "anim_attack_min", 0 ) ) ); if ( anim_attack$ < -1 ) { GoDb.SSetQuestInt( user$, "chore", "attack_max", user$.Go.Aspect.AspectHandle.Blender.GetSubAnimIndex( CHORE_ATTACK, notify$.Go.GetComponentInt( component$, "anim_attack_max", 0 ) ) ); } override_attack$ = notify$; resync$ -= 1; //report.screenf("subanim_manager - WE_REQ_DEACTIVATE - substituting attack override: %d", makeint(notify$)); } } if ( !override_fidget$.IsValid ) { anim_fidget$ = notify$.Go.GetComponentInt( component$, "anim_fidget", 0 ); if ( anim_fidget$ < 0 ) { GoDb.SSetQuestInt( user$, "chore", "fidget", anim_fidget$ ); GoDb.SSetQuestInt( user$, "chore", "fidget_min", user$.Go.Aspect.AspectHandle.Blender.GetSubAnimIndex( CHORE_FIDGET, notify$.Go.GetComponentInt( component$, "anim_fidget_min", 0 ) ) ); if ( anim_fidget$ < -1 ) { GoDb.SSetQuestInt( user$, "chore", "fidget_max", user$.Go.Aspect.AspectHandle.Blender.GetSubAnimIndex( CHORE_FIDGET, notify$.Go.GetComponentInt( component$, "anim_fidget_max", 0 ) ) ); } override_attack$ = notify$; resync$ -= 1; } } if ( !override_walk$.IsValid ) { anim_walk$ = notify$.Go.GetComponentInt( component$, "anim_walk", 0 ); if ( anim_walk$ < 0 ) { GoDb.SSetQuestInt( user$, "chore", "walk", anim_walk$ ); GoDb.SSetQuestInt( user$, "chore", "walk_min", user$.Go.Aspect.AspectHandle.Blender.GetSubAnimIndex( CHORE_WALK, notify$.Go.GetComponentInt( component$, "anim_walk_min", 0 ) ) ); if ( anim_walk$ < -1 ) { GoDb.SSetQuestInt( user$, "chore", "walk_max", user$.Go.Aspect.AspectHandle.Blender.GetSubAnimIndex( CHORE_WALK, notify$.Go.GetComponentInt( component$, "anim_walk_max", 0 ) ) ); } override_walk$ = notify$; resync$ -= 1; } } if ( resync$ < 1 ) { //break; UpdateAnim$( user$ ); return; } } index$ -= 1; } //report.screen("subanim_manager - WE_REQ_DEACTIVATE - no more overrides, reset..."); //if there are no overrides for a chore, reset the associated questbit //if ( resync$ > 0 ) { if ( !override_attack$.IsValid ) { GoDb.SSetQuestInt( user$, "chore", "attack", 0 ); //report.screen("subanim_manager - WE_REQ_DEACTIVATE - default attack"); } if ( !override_fidget$.IsValid ) { GoDb.SSetQuestInt( user$, "chore", "fidget", 0 ); //report.screen("subanim_manager - WE_REQ_DEACTIVATE - default fidget"); } if ( !override_walk$.IsValid ) { GoDb.SSetQuestInt( user$, "chore", "walk", 0 ); //report.screen("subanim_manager - WE_REQ_DEACTIVATE - default walk"); } //} UpdateAnim$( user$ ); } } } }