////////////////////////////////////////////////////////////////////////////// // // File : weapon_cast_skin.skrit // Author(s): Witness (Lisa Hui) // Purpose : skins this object with the texture specified in weapon_cast // History : v1.1 [November 8, 2004] // - listens to the item in the slot so that the gloves don't // desync if the casting gauntlets were deleted without deleting // these gloves first // // v1.0 [October 29, 2004] // //---------------------------------------------------------------------------- // Version: 1.1 Date: November 8, 2004 //---------------------------------------------------------------------------- ////////////////////////////////////////////////////////////////////////////// property string component_name$ = "weapon_cast"; property string component_property$ = "texture"; property eEquipSlot slot$ = ES_WEAPON_HAND; property string texture$ = ""; owner = GoSkritComponent; ////////////////////////////////////////////////////////////////////////////// // GLOBALS ////////////////////////////////////////////////////////////////////////////// #include "k_inc_notify" Goid parent$, weapon$; //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$); //} ////////////////////////////////////////////////////////////////////////////// // STATES ////////////////////////////////////////////////////////////////////////////// startup State Init$ { #only(game) [[ event OnEnterState$ { // debug$("Init$", "OnEnterState$"); if ( owner.Go.Parent != NULL ) { owner.Go.Aspect.SSetIsVisible( false ); } SetState Unequipped$; } ]] } State Unequipped$ { trigger OnGoHandleMessage$( WE_EQUIPPED ) { if ( owner.Go.Parent != NULL ) { parent$ = owner.Go.Parent.Goid; SetState Equipped$; } } } State Equipped$ { event OnEnterState$ { // debug$("Equipped$", "OnEnterState$"); //begin watching chest slot for changes if ( owner.Go.Gui.EquipSlot != ES_CHEST ) { // debug$("Equipped$", "StartEquipWatch$"); StartEquipWatch$( parent$.Go, owner.Goid, ES_CHEST ); } //create and equip the visual, if necessary Go equipped$ = parent$.Go.Inventory.GetEquipped( slot$ ); if ( equipped$ != NULL ) { if ( equipped$.HasComponent( component_name$ ) ) { texture$ = equipped$.GetComponentString( component_name$, component_property$ ); owner.Go.Aspect.SSetCurrentAspectTexture( 0, texture$ ); weapon$ = equipped$.Goid; GoDb.StartWatching( owner.Goid, weapon$ ); return; } } //hide the weapon mesh/ground model // debug$("Equipped$", "component texture could not be determined"); GoDb.SMarkForDeletion( owner.Go ); } event OnGoHandleMessage$( eWorldEvent e$, WorldMessage msg$ ) { if ( e$ == WE_EQUIPPED ) { Go sender$ = msg$.SendFrom.Go; if ( sender$.HasGui() ) { if ( sender$.Gui.EquipSlot == ES_CHEST ) { owner.Go.Aspect.SSetCurrentAspectTexture( 0, texture$ ); } } } else if ( e$ == WE_UNEQUIPPED ) { Go sender$ = msg$.SendFrom.Go; if ( sender$.HasGui() ) { if ( sender$.Gui.EquipSlot == ES_CHEST ) { owner.Go.Aspect.SSetCurrentAspectTexture( 0, texture$ ); return; } } if ( owner.Go.Gui.EquipSlot != ES_CHEST ) { StopEquipWatch$( parent$.Go, owner.Goid, ES_CHEST ); } SetState Unequipped$; } } event OnExitState$ { if ( weapon$.IsValid ) { GoDb.StopWatching( owner.Goid, weapon$ ); } } trigger OnGoHandleCCMessage$( WE_UNEQUIPPED ) { //something went wrong, the gauntlets were unequipped without first unequipping this //so, unequip and delete ourselves if ( parent$.IsValid ) { if ( owner.Go.Gui.EquipSlot != ES_CHEST ) { StopEquipWatch$( parent$.Go, owner.Goid, ES_CHEST ); } } SetState Exiting$; } trigger OnGoHandleCCMessage$( WE_DESTRUCTED ) { //something went wrong, the gauntlets were unequipped without first unequipping this //so, unequip and delete ourselves if ( parent$.IsValid ) { if ( owner.Go.Gui.EquipSlot != ES_CHEST ) { StopEquipWatch$( parent$.Go, owner.Goid, ES_CHEST ); } } SetState Exiting$; } } State Exiting$ { event OnEnterState$ { GoDb.SMarkForDeletion( owner.Goid ); } }