////////////////////////////////////////////////////////////////////////////// // // File : k_inc_equip_limit.skrit // Author(s): Witness (Lisa Hui) // Purpose : checks the armor type of the item in the specified slot and // kicks itself, the item in the slot or both into inventory // //---------------------------------------------------------------------------- // Version: 1.0 Date: October 30, 2004 //---------------------------------------------------------------------------- ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // ES<->INT<-STR ////////////////////////////////////////////////////////////////////////////// int EquipSlotStrToInt$( string es$ ) { if ( StringTool.SameNoCase( es$, "es_c", 4 ) ) { return 3; } if ( StringTool.SameNoCase( es$, "es_fe", 5 ) ) { return 2; } if ( StringTool.SameNoCase( es$, "es_h", 4 ) ) { return 4; } if ( StringTool.SameNoCase( es$, "es_fo", 5 ) ) { return 5; } return 13; } int EquipSlotToInt$( eEquipSlot es$ ) { /*if ( es$ == es_feet ) { return 2; } if ( es$ == es_chest ) { return 3; } if ( es$ == es_head ) { return 4; } if ( es$ == es_forearms ) { return 5; } return 13;*/ return StringTool.GetDelimitedInt( MakeStringF("%d ", es$ ), 0, ' ', 13 ); } eEquipSlot IntToEquipSlot$( int es$ ) { if ( es$ == 2 ) { return ES_FEET; } if ( es$ == 3 ) { return ES_CHEST; } if ( es$ == 4 ) { return ES_HEAD; } if ( es$ == 5 ) { return ES_FOREARMS; } return ES_NONE; } ////////////////////////////////////////////////////////////////////////////// // MERGE LIMITS ////////////////////////////////////////////////////////////////////////////// string merged_limit$; void MergeExclusiveExclude$( string limit_exclusive$, string limit_exclude$ ) { //To merge an exclusive set with an exclusion set... //1. start with the exclusive set as the foundation //2. loop through the exclusive set to find matches from // the exclusions and eliminate them from the list //= smaller exclusive set int count_exclusive$ = StringTool.GetNumDelimitedValues( limit_exclusive$, ',' ) - 1; int count_exclude$ = StringTool.GetNumDelimitedValues( limit_exclude$, ',' ) - 1; limit_exclude$ = StringTool.Mid( limit_exclude$, 1 ); merged_limit$ = ""; while ( count_exclusive$ > -1 ) { int count$ = count_exclude$; string compare$ = StringTool.GetDelimitedString( limit_exclusive$, count_exclusive$, ',', "" ); if ( compare$ != "" ) { while ( count$ > -1 ) { if ( StringTool.SameNoCase( compare$, StringTool.GetDelimitedString( limit_exclude$, count$, ',', "" ) ) ) { break; } count$ -= 1; } if ( count$ == -1 ) { StringTool.AppendF( merged_limit$, ",%s", compare$ ); } } count_exclusive$ -= 1; } //report.screenf("MergeExclusiveExclude$ - %s", merged_limit$); if ( StringTool.Left( merged_limit$, 1 ) == "," ) { merged_limit$ = StringTool.Mid( merged_limit$, 1 ); } } void MergeExclusives$( string limitA$, string limitB$ ) { //To merge two exclusive sets... //1. start with the first exclusive set as the foundation //2. use nested whiles to find the smallest intersecting set //= smaller exclusive set int countA$ = StringTool.GetNumDelimitedValues( limitA$, ',' ) - 1; int countB$ = StringTool.GetNumDelimitedValues( limitB$, ',' ) - 1; merged_limit$ = ""; while ( countA$ > -1 ) { string compare$ = StringTool.GetDelimitedString( limitA$, countA$, ',', "" ); if ( compare$ != "" ) { int count$ = countB$; while ( count$ > -1 ) { if ( StringTool.SameNoCase( compare$, StringTool.GetDelimitedString( limitB$, count$, ',', "" ) ) ) { StringTool.AppendF( merged_limit$, ",%s", compare$ ); break; } count$ -= 1; } } countA$ -= 1; } //report.screenf("MergeExclusives$ - %s", merged_limit$); if ( StringTool.Left( merged_limit$, 1 ) == "," ) { merged_limit$ = StringTool.Mid( merged_limit$, 1 ); } } void MergeExcludes$( string limitA$, string limitB$ ) { //To merge two exclusion sets... //1. start with the first set of exclusions as the foundation //2. append the second set to the first //= bigger exclusion set int count$ = StringTool.GetNumDelimitedValues( limitA$, ',' ) + StringTool.GetNumDelimitedValues( limitB$, ',' ) - 2; string limit$ = MakeStringF( "%s,%s", limitA$, limitB$ ); if ( count$ > -1 ) { merged_limit$ = StringTool.GetDelimitedString( limit$, 0, ',', "" ); count$ -= 1; int count_merged$ = 1; while ( count$ > 0 ) { string compare$ = StringTool.GetDelimitedString( limit$, count$, ',', "" ); int index$ = 0; while ( index$ < count_merged$ ) { if ( StringTool.SameNoCase( compare$, StringTool.GetDelimitedString( merged_limit$, index$, ',', "" ) ) ) { break; } index$ += 1; } if ( index$ == count_merged$ ) { //not found StringTool.AppendF( merged_limit$, ",%s", compare$ ); count_merged$ += 1; } count$ -= 1; } } //report.screenf("MergeExcludes$ - %s", merged_limit$); if ( StringTool.Left( merged_limit$, 1 ) == "," ) { merged_limit$ = StringTool.Mid( merged_limit$, 1 ); } } void MergeLimits$( string limitA$, string limitB$ ) { if ( limitA$ == "" ) { merged_limit$ = limitB$; return; } if ( limitB$ == "" ) { merged_limit$ = limitA$; return; } bool excludeA$ = ( StringTool.Left( limitA$, 1 ) == "!" ); bool excludeB$ = ( StringTool.Left( limitB$, 1 ) == "!" ); //determine what sort of merge is needed and call the appropriate function if ( excludeA$ && excludeB$ ) { MergeExcludes$( limitA$, limitB$ ); } else if ( !excludeA$ && excludeB$ ) { MergeExclusiveExclude$( limitA$, limitB$ ); } else if ( excludeA$ && !excludeB$ ) { MergeExclusiveExclude$( limitB$, limitA$ ); } else { MergeExclusives$( limitA$, limitB$ ); } } ////////////////////////////////////////////////////////////////////////////// // ADD/REMOVE LIMITS ////////////////////////////////////////////////////////////////////////////// bool containsLimit$( string haystack$, string needle$ ) { int count$ = StringTool.GetNumDelimitedValues( haystack$, ';' ) - 2; string limit$; while ( count$ > -1 ) { limit$ = StringTool.GetDelimitedString( haystack$, count$, ';', "" ); if ( limit$ != "" ) { if ( StringTool.SameNoCase( needle$, limit$ ) ) { return true; } } count$ -= 1; } return false; } void AddLimit$( Goid user$, string property$, string limit$ ) { if ( !user$.Go.HasComponent( "player_custom" ) ) { return; } if ( limit$ != "" ) { string limit_sum$ = MakeStringF( "limit_%s_sum", property$ ); string summary$ = user$.Go.GetComponentString( "player_custom", limit_sum$ ); if ( containsLimit$( summary$, limit$ ) ) { return; } user$.Go.SetComponentString( "player_custom", limit_sum$, MakeStringF( "%s%s;", summary$, limit$ ) ); string limit_set$ = MakeStringF( "limit_%s_set", property$ ); string set$ = user$.Go.GetComponentString( "player_custom", limit_set$ ); MergeLimits$( set$, limit$ ); user$.Go.SetComponentString( "player_custom", limit_set$, merged_limit$ ); } } void RemoveLimit$( Goid user$, string property$, string limit$ ) { if ( !user$.Go.HasComponent( "player_custom" ) ) { return; } if ( limit$ != "" ) { string limit_sum$ = MakeStringF( "limit_%s_sum", property$ ); string summary$ = user$.Go.GetComponentString( "player_custom", limit_sum$ ); int count$ = StringTool.GetNumDelimitedValues( summary$, ';' ) - 2; string limitations$ = ""; string lmt_merge$ = ""; string lmt$; while ( count$ > -1 ) { lmt$ = StringTool.GetDelimitedString( summary$, count$, ';', "" ); if ( lmt$ != "" ) { if ( !StringTool.SameNoCase( limit$, lmt$ ) ) { StringTool.AppendF( limitations$, "%s;", lmt$ ); MergeLimits$( lmt_merge$, lmt$ ); lmt_merge$ = merged_limit$; } } count$ -= 1; } user$.Go.SetComponentString( "player_custom", limit_sum$, limitations$ ); user$.Go.SetComponentString( "player_custom", MakeStringF( "limit_%s_set", property$ ), lmt_merge$ ); } } void ResetLimits$( Goid user$, string property$ ) { if ( !user$.Go.HasComponent( "player_custom" ) ) { return; } user$.Go.SetComponentString( "player_custom", MakeStringF( "limit_%s_sum", property$ ), "" ); user$.Go.SetComponentString( "player_custom", MakeStringF( "limit_%s_set", property$ ), "" ); } ////////////////////////////////////////////////////////////////////////////// // ARMOR EQUIP LIMITS ////////////////////////////////////////////////////////////////////////////// bool IsLimitableSlot$( eEquipSlot es$ ) { //m_Job$.GoalSlot == ES_CHEST || m_Job$.GoalSlot == ES_HEAD || //m_Job$.GoalSlot == ES_FEET || m_Job$.GoalSlot == ES_FOREARMS //take advantage of the fact that skrit allows enums to be //evaluated like integers with respect to operators... return !( es$ < 2 || es$ > 5 ); } void AddArmorLimit$( Goid user$, eEquipSlot es$, string limit$ ) { string slot$ = "es_chest"; if ( es$ != ES_CHEST ) { if ( es$ == ES_FEET ) { slot$ = "es_feet"; } else if ( es$ == ES_FOREARMS ) { slot$ = "es_forearms"; } else if ( es$ == ES_HEAD ) { slot$ == "es_head"; } } AddLimit$( user$, slot$, limit$ ); } void RemoveArmorLimit$( Goid user$, eEquipSlot es$, string limit$ ) { string slot$ = "es_chest"; if ( es$ != ES_CHEST ) { if ( es$ == ES_FEET ) { slot$ = "es_feet"; } else if ( es$ == ES_FOREARMS ) { slot$ = "es_forearms"; } else if ( es$ == ES_HEAD ) { slot$ == "es_head"; } } RemoveLimit$( user$, slot$, limit$ ); } bool IsArmorAllowed$( Goid user$, Goid item$ ) { if ( !user$.Go.HasComponent( "player_custom" ) ) { return true; } string armor_type$ = ContentDb.GetTemplateString( MakeStringF( "%s:defend:armor_type", item$.Go.TemplateName ) ); eEquipSlot es$ = item$.Go.Gui.EquipSlot; string slot$ = "es_chest"; if ( es$ != ES_CHEST ) { if ( es$ == ES_FEET ) { slot$ = "es_feet"; } else if ( es$ == ES_FOREARMS ) { slot$ = "es_forearms"; } else if ( es$ == ES_HEAD ) { slot$ == "es_head"; } } string limits$ = user$.Go.GetComponentString( "player_custom", MakeStringF( "limit_%s_set", slot$ ) ); //report.screenf("IsArmorAllowed$ - [%s] - %s", MakeStringF( "limit_%s_set", slot$ ), limits$); if ( limits$ != "" ) { if ( StringTool.Left( limits$, 1 ) == "!" ) { //report.screenf("IsArmorAllowed$ - exclusion set"); //exclusion set limits$ = StringTool.Mid( limits$, 1 ); int index$ = StringTool.GetNumDelimitedValues( limits$, ',' ) - 1; string excluded$; while ( index$ > -1 ) { excluded$ = StringTool.GetDelimitedString( limits$, index$, ',', "" ); if ( excluded$ != "" ) { if ( StringTool.SameNoCase( excluded$, armor_type$ ) ) { return false; } } index$ -= 1; } } else { //report.screenf("IsArmorAllowed$ - exclusive set"); //exclusive set int index$ = StringTool.GetNumDelimitedValues( limits$, ',' ) - 1; bool found$ = false; string exclusive$; while ( index$ > -1 ) { exclusive$ = StringTool.GetDelimitedString( limits$, index$, ',', "" ); if ( exclusive$ != "" ) { if ( StringTool.SameNoCase( exclusive$, armor_type$ ) ) { return true; } } index$ -= 1; } return false; } } return true; }