include library.hue; include ai.ai_combat; const string NPC_DATATABLE = "datatables/npc_customization/npc.iff"; const string CREATURE_TABLE = "datatables/mob/creatures.iff"; const string STORMTROOPER = "datatables/npc_customization/clothing/stormtrooper.iff"; void dressNpc( obj_id npc, string clothesTable ) { dressNpc( npc, clothesTable, false ); } void dressNpc (obj_id npc, string clothesTable, boolean override) { if ( !override && !isClothesWearing( npc ) ) { hue.randomizeObject(npc); return; } clothesTable = "datatables/npc_customization/clothing/" + clothesTable + ".iff"; int columns = dataTableGetNumColumns (clothesTable); //Just in case there's a typo or some other problem, this makes sure there won't be any naked NPC's if (columns == 0) { clothesTable = "datatables/npc_customization/townperson_male_clothes.iff"; columns = dataTableGetNumColumns (clothesTable); } PROFILER_START("dressup.dressNpc.loop." + clothesTable + "." + columns); // This while loop checks to see how many columns worth of clothes the clothesTable // has and loops through until a character is dressed with everything appropriate // (boots, pants, shirt, dress, armor, gloves, helmet, etc.) depending on the type int intX = 1; while ( intX <= columns ) { PROFILER_START("dataTableGetStringColumnNoDefaults"); string[] clothesList = dataTableGetStringColumnNoDefaults( clothesTable, intX-1); PROFILER_STOP("dataTableGetStringColumnNoDefaults"); PROFILER_START("innerLoop"); int clothesNum = rand(0, clothesList.length -1 ); string clothes = clothesList[ clothesNum ]; int columnNum = intX-1; if (clothes == null) debugServerConsoleMsg(npc, "LIBRARY.CREATE DRESSNPC ERROR: row was " + clothesNum + " and column was " + columnNum); else if (clothes == "") debugServerConsoleMsg(npc, "LIBRARY.CREATE DRESSNPC ERROR: row was " + clothesNum + " and column was " + columnNum); else { PROFILER_START("createObject"); obj_id newClothes = createObject (clothes, npc, ""); PROFILER_STOP("createObject"); if ( newClothes == null ) debugServerConsoleMsg(npc, "LIBRARY.CREATE DRESSNPC ERROR: unable to create " + clothes + " for npc " + getName(npc) + " objid: " + npc ); else setSpecificHue(newClothes, intX, clothesNum, clothesTable); } intX = intX + 3; PROFILER_STOP("innerLoop"); } PROFILER_STOP("dressup.dressNpc.loop." + clothesTable + "." + columns); PROFILER_START("dressup.dressNpc.conclude" + clothesTable); if (clothesTable != STORMTROOPER) { PROFILER_START("giveHair"); giveHair (npc); PROFILER_STOP("giveHair"); //debugSpeakMsg (npc, "randomizing"); PROFILER_START("hue.randomizeObject"); hue.randomizeObject (npc); PROFILER_STOP("hue.randomizeObject"); } else { int designation = rand (1,5); string StName = "TK-"; switch (designation) { case 1: StName = "TK-"; break; case 2: StName = "GK-"; break; case 3: StName = "RK-"; break; case 4: StName = "LK-"; break; case 5: StName = "VK-"; break; } setName (npc, StName + rand(1,820)); } PROFILER_STOP("dressup.dressNpc.conclude" + clothesTable); } void equipNpcWeapon( obj_id npc, string weaponTable ) { if ( weaponTable.equals( "none" ) ) return; obj_id npcInventory = getObjectInSlot(npc, "inventory"); if ( npcInventory==null ) return; weaponTable = "datatables/npc_customization/weapon/" + weaponTable + ".iff"; PROFILER_START("dressup.equipNpcWeapon." + weaponTable); string primaryWeaponTemplateName = chooseRandomWeapon( weaponTable, 0 ); if ( primaryWeaponTemplateName != null ) primaryWeaponTemplateName = "object/weapon/" + primaryWeaponTemplateName; string secondaryWeaponTemplateName = chooseRandomWeapon( weaponTable, 1 ); if ( secondaryWeaponTemplateName != null ) secondaryWeaponTemplateName = "object/weapon/" + secondaryWeaponTemplateName; string grenadeWeaponTemplateName = chooseRandomWeapon( weaponTable, 2 ); if ( grenadeWeaponTemplateName != null ) grenadeWeaponTemplateName = "object/weapon/" + grenadeWeaponTemplateName; if ( grenadeWeaponTemplateName != null ) { setObjVar( npc, "ai.grenadeType", grenadeWeaponTemplateName );//no need to actually create it here. } if ( secondaryWeaponTemplateName != null ) { obj_id secondaryWeapon = createObject( secondaryWeaponTemplateName, npcInventory, ""); //debugSpeakMsg (npc, "Secondary is " + secondaryWeapon); setWeaponDamage( npc, secondaryWeapon ); } if ( primaryWeaponTemplateName != null ) { obj_id primaryWeapon = createObject( primaryWeaponTemplateName, npcInventory, ""); //debugSpeakMsg (npc, "Primary weapon is " + primaryWeapon); setWeaponDamage( npc, primaryWeapon ); } // mbogue - I am not sure if this is really needed here //aiEquipPrimaryWeapon(npc); PROFILER_STOP("dressup.equipNpcWeapon." + weaponTable); } string chooseRandomWeapon( string weaponTable, int columnNumber ) { if ( (dataTableGetNumColumns(weaponTable)-1) < columnNumber ) return null; string[] weaponList = dataTableGetStringColumnNoDefaults( weaponTable, columnNumber ); if ( weaponList != null ) { if ( weaponList.length < 1 ) return null; else return weaponList[ rand( 0, (weaponList.length-1)) ]; } else return null; } void hueClothes( obj_id newClothes, string clothes ) { custom_var[] allVars = getAllCustomVars(newClothes); if ( allVars == null ) return; PROFILER_START("dressup.hueClothes.loop." + allVars.length); for ( int i = 0; i < allVars.length; i++ ) { custom_var cv = allVars[i]; if ( cv.isPalColor() ) { ranged_int_custom_var ri = (ranged_int_custom_var)cv; int min = ri.getMinRangeInclusive(); int max = ri.getMaxRangeInclusive(); int randVal = rand(min, max); if (max > 128) { max = max - 128; } ri.setValue(randVal); } } PROFILER_STOP("dressup.hueClothes.loop." + allVars.length); } void setSpecificHue ( obj_id newClothes, int col, int row, string datatable ) { PROFILER_START("dressup.setSpecificHue"); //custom_var[] allVars = getAllCustomVars(newClothes); int minColor = dataTableGetInt ( datatable, row, col); if (minColor == 0) { hueClothes (newClothes, datatable); } else { int maxColor = dataTableGetInt ( datatable, row, col+1); hue.setColor (newClothes, 1, minColor); hue.setColor (newClothes, 2, maxColor); } PROFILER_STOP("dressup.setSpecificHue"); return; } void setWeaponDamage( obj_id npc, obj_id weapon ) { if ( npc == null ) return; if ( weapon == null ) return; dictionary creatureDict = utils.dataTableGetRow( CREATURE_TABLE, getCreatureName(npc)); if ( creatureDict == null ) return; int intMaxDamage = creatureDict.getInt("maxDamage"); int intMinDamage = creatureDict.getInt("minDamage"); float fltWeaponSpeed = (float)creatureDict.getInt("attackSpeed"); setWeaponAttackSpeed(weapon, fltWeaponSpeed); setWeaponMaxDamage( weapon, intMaxDamage); setWeaponMinDamage( weapon, intMinDamage); weapons.setWeaponData(weapon); } boolean isClothesWearing( obj_id npc ) { string tempName = getTemplateName (npc); if ( tempName.indexOf ("wookiee") != -1 ) return false;//wookiee's dont wear clothes else if ( tempName.indexOf ("ithorian") != -1 ) return false;//Chadra Fans already have clothes else if ( tempName.indexOf ("chadra") != -1 ) return false;//Chadra Fans already have clothes else if ( tempName.indexOf ("gungan") != -1 ) return false;//Gungans have clothes already ?!? return true;//everything else wears clothes } void giveHair (obj_id npc) { PROFILER_START("dressup.giveHair"); if ( npc==null ) { PROFILER_STOP("dressup.giveHair"); return; } string template = getTemplateName (npc); string hair_table = "datatables/npc_customization/all_hair.iff"; // Fixup the template name for vendors. int vendor_idx = template.indexOf( "/vendor" ); if ( vendor_idx > -1 ) template = template.substring( 0, vendor_idx ) + template.substring( vendor_idx+7 ); if (!dataTableHasColumn (hair_table, template)) { PROFILER_STOP("dressup.giveHair"); return; } string[] hairList = dataTableGetStringColumnNoDefaults(hair_table, template); if (hairList == null) { PROFILER_STOP("dressup.giveHair"); return; } else if (hairList.length < 1) { PROFILER_STOP("dressup.giveHair"); return; } int hairChoice = rand(0, hairList.length -1 ); string hair = hairList[hairChoice]; obj_id setHair = createObject (hair, npc, ""); hueClothes (setHair, hair); PROFILER_STOP("dressup.giveHair"); return; } boolean setFactionRecruiter(obj_id npc, string faction) { // Turns any npc into a faction recruiter of the specified faction. // Faction must appear exactly as it does in the faction datatable. if (npc == null || npc == obj_id.NULL_ID) { return false; } if (faction == null) { return false; } setObjVar(npc, "faction_recruiter.faction", faction); attachScript(npc, "npc.faction_recruiter.faction_recruiter"); return true; }