////////////////////////////////////////////////////////////////////////////// // // File : k_inc_notify.skrit // Author(s): Witness (Lisa Hui) // Purpose : utility functions for notifying registered listener GOs when // job_equip.skrit or job_get.skrit handles an equip // History : v1.1 [November 13, 2004] // - changed component name check from "character" to "player_custom" // // v1.0 [November 6, 2004] // // Note that any goid that wants to be notified about other equip slot // activities in this manner must check the message sender goid to // determine that the WE_(UN)EQUIPPED message is a notification rather // that an actual equip event for the recipient // //---------------------------------------------------------------------------- // Version: 1.0 Date: November 6, 2004 //---------------------------------------------------------------------------- ////////////////////////////////////////////////////////////////////////////// void NotifyEquipWatchers$( Go user$, Goid equipped$, eWorldEvent e$ ) { if ( !user$.HasComponent( "player_custom" ) ) { return; } eEquipSlot es$ = equipped$.Go.Gui.EquipSlot; if ( es$ < 0 || es$ > 5 ) { return; } //report.screenf("NotifyEquipWatchers$ - %s", equipped$.Go.TemplateName); string notify_type$; if ( es$ == ES_CHEST ) { notify_type$ = "chest"; } else if ( es$ == ES_FEET ) { notify_type$ = "feet"; } else if ( es$ == ES_FOREARMS ) { notify_type$ = "forearms"; } else if ( es$ == ES_HEAD ) { notify_type$ = "head"; } else if ( es$ == ES_WEAPON_HAND ) { notify_type$ = "melee"; } else if ( es$ == ES_SHIELD_HAND ) { if ( equipped$.Go.IsRangedWeapon() ) { notify_type$ = "ranged"; } else { notify_type$ = "shield"; } } else { //notify_type$ = ""; return; } string notify_list$ = user$.GetComponentString( "player_custom", MakeStringF( "notify_equip_%s", notify_type$ ) ); //report.screenf("NotifyEquipWatchers$ - notify list (%s)", notify_list$); if ( notify_list$ != "" ) { int index$ = StringTool.GetNumDelimitedValues( notify_list$, ',' ) - 2; while ( index$ > -1 ) { Goid recipient$ = MakeGoid( StringTool.GetDelimitedInt( notify_list$, index$, ',', 0 ) ); if ( recipient$.IsValid ) { //report.screenf("NotifyEquipWatchers$ - notifying %s (%d)", recipient$.Go.TemplateName, MakeInt(recipient$)); PostWorldMessage( e$, equipped$, recipient$, 0 ); } index$ -= 1; } } } void StartEquipWatch$( Go user$, Goid watcher$, eEquipSlot es$ ) { if ( !user$.HasComponent( "player_custom" ) ) { return; } if ( es$ < 0 || es$ > 5 ) { return; } string notify_type$; if ( es$ == ES_CHEST ) { notify_type$ = "chest"; } else if ( es$ == ES_FEET ) { notify_type$ = "feet"; } else if ( es$ == ES_FOREARMS ) { notify_type$ = "forearms"; } else if ( es$ == ES_HEAD ) { notify_type$ = "head"; } else if ( es$ == ES_WEAPON_HAND ) { notify_type$ = "melee"; } else if ( es$ == ES_SHIELD_HAND ) { if ( watcher$.Go.IsRangedWeapon() ) { notify_type$ = "ranged"; } else { notify_type$ = "shield"; } } else { //notify_type$ = ""; return; } //report.screenf("StartEquipWatch$ - notify type %s", notify_type$); notify_type$ = MakeStringF( "notify_equip_%s", notify_type$ ); int goid$ = MakeInt( watcher$ ); string notify_list$ = user$.GetComponentString( "player_custom", notify_type$ ); if ( notify_list$ != "" ) { int index$ = StringTool.GetNumDelimitedValues( notify_list$, ',' ) - 2; while ( index$ > -1 ) { if ( goid$ == StringTool.GetDelimitedInt( notify_list$, index$, ',', 0 ) ) { //already on the list return; } index$ -= 1; } } //report.screenf("StartEquipWatch$ - notify %s (%d)", watcher$.Go.TemplateName, MakeInt(watcher$)); //add to the list StringTool.AppendF( notify_list$, "%d,", goid$ ); user$.SetComponentString( "player_custom", notify_type$, notify_list$ ); } void StopEquipWatch$( Go user$, Goid watcher$, eEquipSlot es$ ) { if ( !user$.HasComponent( "player_custom" ) ) { return; } if ( es$ < 0 || es$ > 5 ) { return; } string notify_type$; if ( es$ == ES_CHEST ) { notify_type$ = "chest"; } else if ( es$ == ES_FEET ) { notify_type$ = "feet"; } else if ( es$ == ES_FOREARMS ) { notify_type$ = "forearms"; } else if ( es$ == ES_HEAD ) { notify_type$ = "head"; } else if ( es$ == ES_WEAPON_HAND ) { notify_type$ = "melee"; } else if ( es$ == ES_SHIELD_HAND ) { if ( watcher$.Go.IsRangedWeapon() ) { notify_type$ = "ranged"; } else { notify_type$ = "shield"; } } else { //notify_type$ = ""; return; } notify_type$ = MakeStringF( "notify_equip_%s", notify_type$ ); string notify_list_new$ = ""; string notify_list$ = user$.GetComponentString( "player_custom", notify_type$ ); if ( notify_list$ != "" ) { int goid$ = MakeInt( watcher$ ); int index$ = StringTool.GetNumDelimitedValues( notify_list$, ',' ) - 2; while ( index$ > -1 ) { int watcher$ = StringTool.GetDelimitedInt( notify_list$, index$, ',', 0 ); if ( goid$ != watcher$ ) { StringTool.AppendF( notify_list_new$, "%d,", watcher$ ); } index$ -= 1; } } //update the list user$.SetComponentString( "player_custom", notify_type$, notify_list_new$ ); } bool IsWatchedSlot$( Go user$, Goid item$ ) { if ( !user$.HasComponent( "player_custom" ) ) { return false; } eEquipSlot es$ = item$.Go.Gui.EquipSlot; if ( es$ < 0 || es$ > 5 ) { return false; } string notify_type$; if ( es$ == ES_CHEST ) { notify_type$ = "chest"; } else if ( es$ == ES_FEET ) { notify_type$ = "feet"; } else if ( es$ == ES_FOREARMS ) { notify_type$ = "forearms"; } else if ( es$ == ES_HEAD ) { notify_type$ = "head"; } else if ( es$ == ES_WEAPON_HAND ) { notify_type$ = "melee"; } else if ( es$ == ES_SHIELD_HAND ) { if ( item$.Go.IsRangedWeapon() ) { notify_type$ = "ranged"; } else { notify_type$ = "shield"; } } else { //notify_type$ = ""; return false; } return ( user$.GetComponentString( "player_custom", MakeStringF( "notify_equip_%s", notify_type$ ) ) != "" ); }