///////////////////////////////////////////////////////////////////////////// // // File : equip_joint.skrit // Author(s): Witness (Lisa Hui) // Purpose : this item creates and equips an instance of other equippables // that are to be worn when this item is equipped // History : v1.0 [November 6, 2004] // - sets quest bits cues for animation overrides // // //---------------------------------------------------------------------------- // Version: 1.0 Date: November 6, 2004 //---------------------------------------------------------------------------- ////////////////////////////////////////////////////////////////////////////// property string chest_template$ doc = "name of the template to preload for cloning"; property string chest_pcontent$ doc = "pcontent string for cloning (should include the template name entered for template$)"; property string head_template$ doc = "name of the template to preload for cloning"; property string head_pcontent$ doc = "pcontent string for cloning (should include the template name entered for template$)"; property string forearms_template$ doc = "name of the template to preload for cloning"; property string forearms_pcontent$ doc = "pcontent string for cloning (should include the template name entered for template$)"; property string feet_template$ doc = "name of the template to preload for cloning"; property string feet_pcontent$ doc = "pcontent string for cloning (should include the template name entered for template$)"; property string melee_template$ doc = "name of the template to preload for cloning"; property string melee_pcontent$ doc = "pcontent string for cloning (should include the template name entered for template$)"; property string template$ = "" doc = "name of the template to preload for cloning"; property string pcontent$ = "" doc = "pcontent string for cloning (should include the template name entered for template$)"; owner = GoSkritComponent; ////////////////////////////////////////////////////////////////////////////// // GLOBALS ////////////////////////////////////////////////////////////////////////////// #include "k_inc_block" #include "k_inc_pcontent" Goid parent$, equip_chest$, equip_feet$, equip_forearms$, equip_head$, equip_melee$; //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$); //} trigger OnGoPreload$ { if ( chest_template$ != "" ) { GoDb.PreloadCloneSource( owner.Go, chest_template$ ); } if ( feet_template$ != "" ) { GoDb.PreloadCloneSource( owner.Go, feet_template$ ); } if ( forearms_template$ != "" ) { GoDb.PreloadCloneSource( owner.Go, forearms_template$ ); } if ( head_template$ != "" ) { GoDb.PreloadCloneSource( owner.Go, head_template$ ); } if ( melee_template$ != "" ) { GoDb.PreloadCloneSource( owner.Go, melee_template$ ); } } ////////////////////////////////////////////////////////////////////////////// // STATES ////////////////////////////////////////////////////////////////////////////// startup State Init$ { event OnEnterState$ { if ( IsInGame( WorldState.CurrentState ) ) { SetState Listen$; } } transition -> Listen$ : OnGoHandleMessage( WE_WORLD_STATE_TRANSITION_DONE ); } State Listen$ { Goid CloneEquip$( string item$ ) { //create GoCloneReq req$ = MakeGoCloneReq( item$ ); Goid equipping$ = GoDb.SCloneGo( req$ ); //equip eEquipSlot slot$ = equipping$.Go.Gui.EquipSlot; parent$.Go.Inventory.RSAutoEquip( slot$, equipping$, AO_REFLEX ); UIInventoryManager.RSPaperDollHandleItem( parent$, slot$, equipping$ ); //debug$( "CloneEquip$", MakeStringF("equipping %s in slot %d", equipping$.Go.TemplateName, slot$) ); return equipping$; } void CloneUnequip$( Go item$ ) { if ( item$.IsEquipped() ) { parent$.Go.Inventory.RSUnequip( item$.Gui.EquipSlot, AO_REFLEX ); //debug$("CloneUnequip$", "unequipping item"); } //debug$("CloneUnequip$", "deleting item"); GoDb.SMarkGoAndChildrenForDeletion( item$ ); } trigger OnGoHandleMessage$( WE_EQUIPPED ) { //debug$("Listen$", "WE_EQUIPPED"); //wait until everything else is equipped before examining //the target slot this.CreateTimer( 1, 0.0 ); } bool equip_up$; string pick_up$; trigger OnTimer$( 1 ) { if ( owner.Go.Parent == NULL ) { return; } parent$ = owner.Go.Parent.Goid; if ( !parent$.IsValid ) { return; } equip_up$ = false; pick_up$ = ""; Go equipped$; if ( chest_template$ != "" ) { equipped$ = parent$.Go.Inventory.GetEquipped( ES_CHEST ); if ( equipped$ == NULL ) { equip_chest$ = CloneEquip$( chest_pcontent$ ); } else if ( !MatchPContentString$( equipped$, chest_pcontent$ ) ) { StringTool.AssignF( pick_up$, "%d,", MakeInt( equipped$.Goid ) ); parent$.Go.Inventory.RSRemove( equipped$, true ); equipped$.Aspect.SSetIsVisible( false ); equip_chest$ = CloneEquip$( chest_pcontent$ ); } else { equip_chest$ = equipped$.Goid; } } if ( feet_template$ != "" ) { equipped$ = parent$.Go.Inventory.GetEquipped( ES_FEET ); if ( equipped$ == NULL ) { equip_feet$ = CloneEquip$( feet_pcontent$ ); } else if ( !MatchPContentString$( equipped$, feet_pcontent$ ) ) { StringTool.AppendF( pick_up$, "%d,", MakeInt( equipped$.Goid ) ); parent$.Go.Inventory.RSRemove( equipped$, true ); equipped$.Aspect.SSetIsVisible( false ); equip_feet$ = CloneEquip$( feet_pcontent$ ); } else { equip_feet$ = equipped$.Goid; } } if ( forearms_template$ != "" ) { equipped$ = parent$.Go.Inventory.GetEquipped( ES_FOREARMS ); if ( equipped$ == NULL ) { equip_forearms$ = CloneEquip$( forearms_pcontent$ ); } else if ( !MatchPContentString$( equipped$, forearms_pcontent$ ) ) { StringTool.AppendF( pick_up$, "%d,", MakeInt( equipped$.Goid ) ); parent$.Go.Inventory.RSRemove( equipped$, true ); equipped$.Aspect.SSetIsVisible( false ); equip_forearms$ = CloneEquip$( forearms_pcontent$ ); } else { equip_forearms$ = equipped$.Goid; } } if ( head_template$ != "" ) { equipped$ = parent$.Go.Inventory.GetEquipped( ES_HEAD ); if ( equipped$ == NULL ) { equip_head$ = CloneEquip$( head_pcontent$ ); } else if ( !MatchPContentString$( equipped$, head_pcontent$ ) ) { StringTool.AppendF( pick_up$, "%d,", MakeInt( equipped$.Goid ) ); parent$.Go.Inventory.RSRemove( equipped$, true ); equipped$.Aspect.SSetIsVisible( false ); equip_head$ = CloneEquip$( head_pcontent$ ); } else { equip_head$ = equipped$.Goid; } } if ( melee_template$ != "" ) { equipped$ = parent$.Go.Inventory.GetEquipped( ES_WEAPON_HAND ); if ( equipped$ == NULL ) { equip_melee$ = CloneEquip$( melee_pcontent$ ); } else if ( !MatchPContentString$( equipped$, melee_pcontent$ ) ) { StringTool.AppendF( pick_up$, "%d,", MakeInt( equipped$.Goid ) ); parent$.Go.Inventory.RSRemove( equipped$, true ); equipped$.Aspect.SSetIsVisible( false ); equip_melee$ = CloneEquip$( melee_pcontent$ ); } else { equip_melee$ = equipped$.Goid; } } if ( pick_up$ != "" ) { this.CreateTimer( 2, 0.1 ); return; } } trigger OnGoHandleMessage$( WE_UNEQUIPPED ) { //debug$("Listen$", "WE_UNEQUIPPED"); if ( pick_up$ != "" ) { equip_up$ = true; } if ( equip_chest$.IsValid ) { CloneUnequip$( equip_chest$.Go ); } if ( equip_feet$.IsValid ) { CloneUnequip$( equip_feet$.Go ); } if ( equip_forearms$.IsValid ) { CloneUnequip$( equip_forearms$.Go ); } if ( equip_head$.IsValid ) { CloneUnequip$( equip_head$.Go ); } if ( equip_melee$.IsValid ) { CloneUnequip$( equip_melee$.Go ); } } trigger OnTimer$( 2 ) { int index$ = StringTool.GetNumDelimitedValues( pick_up$, ',' ) - 2; if ( !equip_up$ ) { while ( index$ > -1 ) { Goid item$ = MakeGoid( StringTool.GetDelimitedInt( pick_up$, index$, ',', 0 ) ); if ( item$.IsValid ) { parent$.Go.Inventory.RSAdd( item$.Go, IL_MAIN, AO_HUMAN, true ); } index$ -= 1; } } else { while ( index$ > -1 ) { Goid item$ = MakeGoid( StringTool.GetDelimitedInt( pick_up$, index$, ',', 0 ) ); if ( item$.IsValid ) { parent$.Go.Inventory.RSAutoEquip( item$.Go.Gui.EquipSlot, item$, AO_REFLEX ); } index$ -= 1; } } } }