diff --git a/sku.0/sys.server/compiled/game/script/ai/ai.java b/sku.0/sys.server/compiled/game/script/ai/ai.java old mode 100644 new mode 100755 index 49cfb4c9f..cc3b5c045 --- a/sku.0/sys.server/compiled/game/script/ai/ai.java +++ b/sku.0/sys.server/compiled/game/script/ai/ai.java @@ -51,12 +51,12 @@ public class ai extends script.base_script public ai() { } - public static final boolean LOGGING_ON = false; + //public static final boolean LOGGING_ON = false; public static final String LOGGING_CATEGORY = "ai_script"; public static final String MENU_FILE = "pet/pet_menu"; - public static final float CORPSE_CLEANUP_DELAY = 300.0f; + //public static final float CORPSE_CLEANUP_DELAY = 300.0f; public static final String CREATURE_TABLE = "datatables/mob/creatures.iff"; - public static final string_id SID_NOTIFY_STALKED = new string_id("skl_use", "notify_stalked"); + //public static final string_id SID_NOTIFY_STALKED = new string_id("skl_use", "notify_stalked"); public static final string_id SID_CANT_MILK = new string_id("skl_use", "milk_cant"); public static final string_id SID_MILK_NOT_HIDDEN = new string_id("skl_use", "milk_not_hidden"); public static final string_id SID_MILK_BEGIN = new string_id("skl_use", "milk_begin"); @@ -66,7 +66,7 @@ public class ai extends script.base_script public static final string_id SID_MILK_SUCCESS = new string_id("skl_use", "milk_success"); public static final string_id SID_BEING_MILKED = new string_id("skl_use", "being_milked"); public static final string_id SID_CANT_MILK_MOUNTED = new string_id("skl_use", "milk_mounted"); - public static final string_id SID_CANT_MILK_COMBAT = new string_id("skl_use", "milk_combat"); + //public static final string_id SID_CANT_MILK_COMBAT = new string_id("skl_use", "milk_combat"); public static final string_id SID_CANT_MILK_INV_FULL = new string_id("skl_use", "milk_inventory_full"); public static final string_id SID_ALREADY_RECRUITED = new string_id("collection", "already_recruited"); public static final string_id SID_ENEMY_RECRUIT = new string_id("collection", "enemy_recruit"); @@ -106,7 +106,6 @@ public class ai extends script.base_script { aiSetHomeLocation(self, loc); } - float ai_yaw = getYaw(self); setWantSawAttackTriggers(self, aiIsAssist(self) || aiIsGuard(self)); if (!hasObjVar(self, "ai.defaultCalmBehavior")) { @@ -114,6 +113,7 @@ public class ai extends script.base_script } if (!hasObjVar(self, "ai.yaw")) { + float ai_yaw = getYaw(self); setObjVar(self, "ai.yaw", ai_yaw); } ai_lib.resetAi(); @@ -200,23 +200,17 @@ public class ai extends script.base_script } removeObjVar(npc, "ai.threat"); ai_lib.setMood(npc, ai_lib.MOOD_CALM); - if (!hasObjVar(npc, "ai.rangedOnly")) - { - } messageTo(npc, "redoYaw", null, 30, false); if (ai_lib.isFollowing(npc)) { - LOGC(aiLoggingEnabled(npc), "debug_ai", "ai::doDefaultCalmBehavior() npc(" + npc + ") FOLLOWING"); obj_id target = ai_lib.getFollowTarget(npc); + LOGC(aiLoggingEnabled(npc), "debug_ai", "ai::doDefaultCalmBehavior() npc(" + npc + ") IS FOLLOWING " + target.toString()); if (isIdValid(target) && exists(target) && !ai_lib.isAiDead(target) && isInWorld(target)) { ai_lib.resumeFollow(npc); return; } - else - { - removeObjVar(npc, "ai.persistantFollowing"); - } + removeObjVar(npc, "ai.persistantFollowing"); } if (hasObjVar(npc, "ai.inFormation")) { @@ -270,53 +264,44 @@ public class ai extends script.base_script { case ai_lib.BEHAVIOR_STOP: case ai_lib.BEHAVIOR_SENTINEL: - LOGC(aiLoggingEnabled(npc), "debug_ai", "ai::doDefaultCalmBehavior() npc(" + npc + getName(npc) + ") BEHAVIOR_STOP"); - stop(npc); - break; - default: + LOGC(aiLoggingEnabled(npc), "debug_ai", "ai::doDefaultCalmBehavior() npc(" + npc + getName(npc) + ") BEHAVIOR_STOP"); + stop(npc); + break; case ai_lib.BEHAVIOR_LOITER: case ai_lib.BEHAVIOR_WANDER: - if (pet_lib.isPet(npc) || beast_lib.isBeast(npc)) - { - aiSetHomeLocation(npc, getLocation(npc)); - } - final float collisionRadius = getObjectCollisionRadius(npc); - float minDistance = 0.0f; - float maxDistance = 0.0f; - if (hasObjVar(npc, "ai.loiterMinRange")) - { - minDistance = getFloatObjVar(npc, "ai.loiterMinRange"); - maxDistance = getFloatObjVar(npc, "ai.loiterMaxRange"); - } - else - { - final float cellDistanceModifier = !isIdValid(getLocation(npc).cell) ? 3.0f : 1.0f; - maxDistance = Math.min(128.0f, collisionRadius * 7.0f * cellDistanceModifier); - minDistance = 0.0f; - } - final float minDelay = Math.min(Math.max(8.0f, collisionRadius * 2.0f), 16.0f); - final float maxDelay = Math.min(Math.max(8.0f, collisionRadius * 4.0f), 16.0f); - loiterLocation(npc, aiGetHomeLocation(npc), minDistance, maxDistance, minDelay, maxDelay); - break; + default: + if (pet_lib.isPet(npc) || beast_lib.isBeast(npc)) + { + aiSetHomeLocation(npc, getLocation(npc)); + } + final float collisionRadius = getObjectCollisionRadius(npc); + float minDistance; + float maxDistance; + if (hasObjVar(npc, "ai.loiterMinRange")) + { + minDistance = getFloatObjVar(npc, "ai.loiterMinRange"); + maxDistance = getFloatObjVar(npc, "ai.loiterMaxRange"); + } + else + { + final float cellDistanceModifier = !isIdValid(getLocation(npc).cell) ? 3.0f : 1.0f; + maxDistance = Math.min(128.0f, collisionRadius * 7.0f * cellDistanceModifier); + minDistance = 0.0f; + } + final float minDelay = Math.min(Math.max(8.0f, collisionRadius * 2.0f), 16.0f); + final float maxDelay = Math.min(Math.max(8.0f, collisionRadius * 4.0f), 16.0f); + loiterLocation(npc, aiGetHomeLocation(npc), minDistance, maxDistance, minDelay, maxDelay); + break; } } public int OnFollowMoving(obj_id self, obj_id target) throws InterruptedException { - if (ai_lib.isInCombat(self)) - { - return SCRIPT_CONTINUE; - } - if (ai_lib.isAiDead(self)) - { - return SCRIPT_CONTINUE; - } - if (getPosture(self) != POSTURE_UPRIGHT) + if (!ai_lib.isInCombat(self) && !ai_lib.isAiDead(self) && getPosture(self) != POSTURE_UPRIGHT) { stop(self); removeObjVar(self, "ai.combat.moveMode"); posture.stand(self); messageTo(self, "resumeDefaultCalmBehavior", null, 2, false); - return SCRIPT_CONTINUE; } return SCRIPT_CONTINUE; } @@ -331,26 +316,17 @@ public class ai extends script.base_script } public int OnExitedCombat(obj_id self) throws InterruptedException { - if (utils.hasScriptVar(self, "sentAllyDistressCall")) - { - utils.removeScriptVar(self, "sentAllyDistressCall"); - } + utils.removeScriptVar(self, "sentAllyDistressCall"); return SCRIPT_CONTINUE; } public int OnFollowWaiting(obj_id self, obj_id target) throws InterruptedException { - if (!target.isLoaded() || !exists(target)) - { - return SCRIPT_CONTINUE; - } - if (hasObjVar(target, "gm")) - { - return SCRIPT_CONTINUE; - } - if (ai_lib.isInCombat(self)) + /* + if (!target.isLoaded() || !exists(target) || hasObjVar(target, "gm") || ai_lib.isInCombat(self)) { return SCRIPT_CONTINUE; } + */ if (!isIdValid(target) || ai_lib.isAiDead(target)) { ai_lib.aiStopFollowing(self); @@ -448,7 +424,7 @@ public class ai extends script.base_script final boolean breacherIsAPlayer = isPlayer(breacher); if (volumeName.equals(ai_lib.ALERT_VOLUME_NAME)) { - if (isPlayer(breacher) && !ai_lib.isMonster(self)) + if (breacherIsAPlayer && !ai_lib.isMonster(self)) { ai_lib.greet(self, breacher); } @@ -462,7 +438,7 @@ public class ai extends script.base_script } else { - if (isPlayer(breacher)) + if (breacherIsAPlayer) { final int factionStatus = factions.getFactionStatus(self, breacher); if (factionStatus == factions.STATUS_ENEMY) @@ -567,9 +543,7 @@ public class ai extends script.base_script } else { - obj_id selfStoryTellerId = getObjIdObjVar(self, "storytellerid"); - obj_id breacherStoryTellerId = utils.getObjIdScriptVar(breacher, "storytellerid"); - if (selfStoryTellerId != breacherStoryTellerId) + if (getObjIdObjVar(self, "storytellerid") != utils.getObjIdScriptVar(breacher, "storytellerid")) { LOGC(aiLoggingEnabled(self), "debug_ai", "ai::OnTriggerVolumeEntered(" + volumeName + ") Player breacher is a NOT a member of my Story (but he is a member of another Story)"); aggro = false; @@ -590,10 +564,7 @@ public class ai extends script.base_script } else { - if (scout.isScentMasked(breacher, self)) - { - } - else + if (!scout.isScentMasked(breacher, self)) { if (isIncapacitated(breacher)) { @@ -793,9 +764,7 @@ public class ai extends script.base_script } public int snareEffectOff(obj_id self, dictionary params) throws InterruptedException { - string_id strFlyText = new string_id("combat_effects", "no_snare"); - color colFlyText = colors.TOMATO; - showFlyText(self, strFlyText, 1.0f, colFlyText); + showFlyText(self, new string_id("combat_effects", "no_snare"), 1.0f, colors.TOMATO); return SCRIPT_CONTINUE; } public int OnDefenderCombatAction(obj_id self, obj_id attacker, obj_id weapon, int combatResult) throws InterruptedException @@ -862,19 +831,13 @@ public class ai extends script.base_script { assistDefender = true; } - for (int i = 0; i < attackers.length; ++i) - { - final obj_id attacker = attackers[i]; - if (isIdValid(attacker)) - { - if (assistDefender || hasAttributeAttained(attacker, attrib.THUG) || (ai_lib.isMonster(attacker) && (!pet_lib.isPet(attacker)))) - { + for (final obj_id attacker : attackers) { + if (isIdValid(attacker)) { + if (assistDefender || hasAttributeAttained(attacker, attrib.THUG) || (ai_lib.isMonster(attacker) && (!pet_lib.isPet(attacker)))) { debugSpeakMsgc(aiLoggingEnabled(self), self, "OnSawAttackGuard() attacking(" + attacker + ")"); ai_combat_assist.assist(self, attacker); break; - } - else if (ai_lib.isSameSocialGroup(self, attacker)) - { + } else if (ai_lib.isSameSocialGroup(self, attacker)) { debugSpeakMsgc(aiLoggingEnabled(self), self, "OnSawAttack() attacking(" + defender + ")"); ai_combat_assist.assist(self, defender); break; @@ -884,51 +847,31 @@ public class ai extends script.base_script } else { - for (int i = 0; i < attackers.length; ++i) - { - final obj_id attacker = attackers[i]; - if (isIdValid(attacker)) - { - if (hasObjVar(self, "storytellerid")) - { - if (!utils.hasScriptVar(defender, "storytellerid") && !utils.hasScriptVar(attacker, "storytellerid")) - { + for (final obj_id attacker : attackers) { + if (isIdValid(attacker)) { + if (hasObjVar(self, "storytellerid")) { + if (!utils.hasScriptVar(defender, "storytellerid") && !utils.hasScriptVar(attacker, "storytellerid")) { debugSpeakMsgc(aiLoggingEnabled(self), self, "OnSawAttack() not attacking(" + defender + ") or (" + attacker + ") as they are not a part of my story"); break; - } - else if (hasObjVar(defender, "storytellerid") && utils.hasScriptVar(attacker, "storytellerid")) - { - obj_id attackerStorytellerId = utils.getObjIdScriptVar(attacker, "storytellerid"); - obj_id defenderStorytellerId = getObjIdObjVar(defender, "storytellerid"); - obj_id myStorytellerId = getObjIdObjVar(self, "storytellerid"); - if (myStorytellerId == defenderStorytellerId && ai_lib.isSameSocialGroup(self, defender)) - { + } else if (hasObjVar(defender, "storytellerid") && utils.hasScriptVar(attacker, "storytellerid")) { + if (getObjIdObjVar(self, "storytellerid") == getObjIdObjVar(defender, "storytellerid") && ai_lib.isSameSocialGroup(self, defender)) { debugSpeakMsgc(aiLoggingEnabled(self), self, "OnSawAttack() attacking(" + attacker + ")"); ai_combat_assist.assist(self, defender); break; } - } - else if (utils.hasScriptVar(defender, "storytellerid") && hasObjVar(attacker, "storytellerid")) - { - obj_id attackerStorytellerId = getObjIdObjVar(attacker, "storytellerid"); - obj_id defenderStorytellerId = utils.getObjIdScriptVar(defender, "storytellerid"); - obj_id myStorytellerId = getObjIdObjVar(self, "storytellerid"); - if (myStorytellerId == attackerStorytellerId && ai_lib.isSameSocialGroup(self, attacker)) - { + } else if (utils.hasScriptVar(defender, "storytellerid") && hasObjVar(attacker, "storytellerid")) { + if (getObjIdObjVar(self, "storytellerid") == getObjIdObjVar(attacker, "storytellerid") && ai_lib.isSameSocialGroup(self, attacker)) { debugSpeakMsgc(aiLoggingEnabled(self), self, "OnSawAttack() attacking(" + defender + ")"); ai_combat_assist.assist(self, attacker); break; } } } - if (ai_lib.isSameSocialGroup(self, defender)) - { + if (ai_lib.isSameSocialGroup(self, defender)) { debugSpeakMsgc(aiLoggingEnabled(self), self, "OnSawAttack() attacking(" + attacker + ")"); ai_combat_assist.assist(self, attacker); break; - } - else if (ai_lib.isSameSocialGroup(self, attacker)) - { + } else if (ai_lib.isSameSocialGroup(self, attacker)) { debugSpeakMsgc(aiLoggingEnabled(self), self, "OnSawAttack() attacking(" + defender + ")"); ai_combat_assist.assist(self, defender); break; @@ -960,9 +903,7 @@ public class ai extends script.base_script } if (getObjIdObjVar(defender, "poi.baseObject") == myPOI) { - int curHP = getHitpoints(defender); - int maxHP = getMaxHitpoints(defender); - if (curHP >= maxHP) + if (getHitpoints(defender) >= getMaxHitpoints(defender)) { return true; } @@ -1036,9 +977,8 @@ public class ai extends script.base_script obj_id[] haters = getHateList(self); if (haters.length > 0) { - for (int i = 0; i < haters.length; i++) - { - removeHateTarget(haters[i], self); + for (obj_id hater : haters) { + removeHateTarget(hater, self); } } destroyObject(self); @@ -1263,12 +1203,9 @@ public class ai extends script.base_script } public int disableAI(obj_id self, dictionary params) throws InterruptedException { - String[] scriptList = getScriptList(self); - for (int i = 0; i < scriptList.length; i++) - { - if (scriptList[i].startsWith("ai.")) - { - detachScript(self, scriptList[i]); + for (String script : getScriptList(self)) { + if (script.startsWith("ai.")) { + detachScript(self, script); } } stop(self); @@ -1303,6 +1240,14 @@ public class ai extends script.base_script public int handleAddMaster(obj_id self, dictionary params) throws InterruptedException { obj_id pet = params.getObjId("pet"); + if (!isIdValid(pet)) + { + return SCRIPT_CONTINUE; + } + if ((pet != self)) + { + return SCRIPT_CONTINUE; + } obj_id controlDevice = params.getObjId("controlDevice"); if (!isIdValid(controlDevice)) { @@ -1312,21 +1257,12 @@ public class ai extends script.base_script { return SCRIPT_CONTINUE; } - if (!isIdValid(pet)) - { - return SCRIPT_CONTINUE; - } - if ((pet != self)) - { - return SCRIPT_CONTINUE; - } obj_id master = params.getObjId("master"); if (!isIdValid(master)) { return SCRIPT_CONTINUE; } - int petType = pet_lib.getPetType(self); - if (pet_lib.hasMaxPets(master, petType, pet) && callable.hasCallableCD(self)) + if (pet_lib.hasMaxPets(master, pet_lib.getPetType(self), pet) && callable.hasCallableCD(self)) { destroyObject(self); return SCRIPT_CONTINUE; @@ -1337,10 +1273,7 @@ public class ai extends script.base_script setOwner(utils.getInventoryContainer(self), master); attachScript(self, "ai.pet"); setObjVar(pet, "ai.pet.masterName", getEncodedName(master)); - if (utils.hasScriptVar(self, "petBeingInitialized")) - { - utils.removeScriptVar(self, "petBeingInitialized"); - } + utils.removeScriptVar(self, "petBeingInitialized"); } if (!ai_lib.isMonster(self)) { @@ -1351,24 +1284,22 @@ public class ai extends script.base_script } public int handleRemoveMaster(obj_id self, dictionary params) throws InterruptedException { + if (!pet_lib.hasMaster(self)) + { + return SCRIPT_CONTINUE; + } obj_id pet = params.getObjId("pet"); if (pet != self || !isIdValid(pet)) { return SCRIPT_CONTINUE; } - if (!pet_lib.hasMaster(self)) - { - return SCRIPT_CONTINUE; - } - obj_id master = getMaster(self); - params.put("master", master); + params.put("master", getMaster(self)); final String creatureName = getCreatureName(self); if (creatureName != null) { params.put("ai.creatureName", creatureName); } - obj_id group = getGroupObject(pet); - queueCommand(pet, (1188179258), group, "", COMMAND_PRIORITY_DEFAULT); + queueCommand(pet, (1188179258), getGroupObject(pet), "", COMMAND_PRIORITY_DEFAULT); removeObjVar(pet, "ai.pet.masterName"); ai_lib.aiStopFollowing(pet); stop(pet); @@ -1400,19 +1331,19 @@ public class ai extends script.base_script switch (rand(1, 3)) { case 1: - stop(self); - ai_lib.doAction(self, "ashamed"); - break; + stop(self); + ai_lib.doAction(self, "ashamed"); + break; case 2: - stop(self); - ai_lib.doAction(self, "vocalize"); - break; + stop(self); + ai_lib.doAction(self, "vocalize"); + break; case 3: - if (getBehavior(self) <= BEHAVIOR_CALM) - { - doDefaultCalmBehavior(self); - } - break; + if (getBehavior(self) <= BEHAVIOR_CALM) + { + doDefaultCalmBehavior(self); + } + break; } messageTo(self, "handleWailingPet", null, 15, false); return SCRIPT_CONTINUE; @@ -1425,33 +1356,16 @@ public class ai extends script.base_script } return SCRIPT_CONTINUE; } - public boolean crossPortalBreach(obj_id npc, obj_id breacher) throws InterruptedException - { - obj_id myCell = getLocation(npc).cell; - obj_id yourCell = getLocation(breacher).cell; - if (isIdValid(myCell) == isIdValid(yourCell)) - { - if (!canSee(npc, breacher)) - { - return true; - } - else - { - return false; - } - } - return true; + public boolean crossPortalBreach(obj_id npc, obj_id breacher) throws InterruptedException { + return isIdValid(getLocation(npc).cell) != isIdValid(getLocation(breacher).cell) || !canSee(npc, breacher); } public void manageCrossPortalBreach(obj_id npc, obj_id breacher) throws InterruptedException { - if (!isPlayer(breacher)) - { - return; + if (isPlayer(breacher)) { + dictionary params = new dictionary(); + params.put("breacher", breacher); + messageTo(npc, "handleMonitorMovement", params, 5, false); } - dictionary params = new dictionary(); - params.put("breacher", breacher); - messageTo(npc, "handleMonitorMovement", params, 5, false); - return; } public int handleMonitorMovement(obj_id self, dictionary params) throws InterruptedException { @@ -1461,36 +1375,24 @@ public class ai extends script.base_script return SCRIPT_CONTINUE; } obj_id breacher = params.getObjId("breacher"); - if (!isIdValid(breacher) || !exists(breacher) || !isInWorld(breacher)) + if (!isIdValid(breacher) || !exists(breacher) || !isInWorld(breacher) || ai_lib.isAiDead(breacher)) { return SCRIPT_CONTINUE; } - if (ai_lib.isAiDead(breacher)) + if (utils.getElementPositionInArray(getTriggerVolumeContents(self, ai_lib.ALERT_VOLUME_NAME), breacher) == -1) { return SCRIPT_CONTINUE; } - obj_id[] myContents = getTriggerVolumeContents(self, ai_lib.ALERT_VOLUME_NAME); - if (utils.getElementPositionInArray(myContents, breacher) == -1) - { - return SCRIPT_CONTINUE; - } - obj_id myCell = getLocation(self).cell; obj_id yourCell = getLocation(breacher).cell; - if (!isIdValid(yourCell)) - { - return SCRIPT_CONTINUE; + if (isIdValid(yourCell)) { + if (yourCell != getLocation(self).cell) { + messageTo(self, "handleMonitorMovement", params, 3, false); + } else if (ai_lib.isInCombat(self)) { + messageTo(self, "handleMonitorMovement", params, 3, false); + } else { + startCombat(self, breacher); + } } - if (yourCell != myCell) - { - messageTo(self, "handleMonitorMovement", params, 3, false); - return SCRIPT_CONTINUE; - } - if (ai_lib.isInCombat(self)) - { - messageTo(self, "handleMonitorMovement", params, 3, false); - return SCRIPT_CONTINUE; - } - startCombat(self, breacher); return SCRIPT_CONTINUE; } public int OnAboutToBeTransferred(obj_id self, obj_id destContainer, obj_id transferer) throws InterruptedException @@ -1513,8 +1415,7 @@ public class ai extends script.base_script return SCRIPT_CONTINUE; } boolean wontEnter = false; - int niche = ai_lib.aiGetNiche(self); - if (niche == NICHE_VEHICLE) + if (ai_lib.aiGetNiche(self) == NICHE_VEHICLE) { wontEnter = true; } @@ -1602,13 +1503,11 @@ public class ai extends script.base_script { return SCRIPT_CONTINUE; } - int niche = ai_lib.aiGetNiche(self); - if (niche != NICHE_NPC) + if (ai_lib.aiGetNiche(self) != NICHE_NPC) { return SCRIPT_CONTINUE; } - String npcType = getCreatureName(self); - if (npcType.equals("darth_vader")) + if (getCreatureName(self).equals("darth_vader")) { return SCRIPT_CONTINUE; } @@ -1687,7 +1586,7 @@ public class ai extends script.base_script setAnimationMood(self, "bored"); } } - if (skillMod < 50) + else if (skillMod < 50) { if (rand(1, 2) == 1) { @@ -1759,8 +1658,7 @@ public class ai extends script.base_script { return SCRIPT_CONTINUE; } - obj_id entertainer = utils.getObjIdScriptVar(self, "ai.listeningTo"); - if (entertainer != player) + if (utils.getObjIdScriptVar(self, "ai.listeningTo") != player) { return SCRIPT_CONTINUE; } @@ -1779,17 +1677,17 @@ public class ai extends script.base_script switch (rand(1, 4)) { case 1: - doAnimationAction(self, "hold_nose"); - break; + doAnimationAction(self, "hold_nose"); + break; case 2: - doAnimationAction(self, "cover_ears_mocking"); - break; + doAnimationAction(self, "cover_ears_mocking"); + break; case 3: - doAnimationAction(self, "point_away"); - break; + doAnimationAction(self, "point_away"); + break; case 4: - doAnimationAction(self, "shake_head_no"); - break; + doAnimationAction(self, "shake_head_no"); + break; } } else if (skillMod < 40) @@ -1797,17 +1695,17 @@ public class ai extends script.base_script switch (rand(1, 4)) { case 1: - doAnimationAction(self, "shake_head_no"); - break; + doAnimationAction(self, "shake_head_no"); + break; case 2: - doAnimationAction(self, "applause_polite"); - break; + doAnimationAction(self, "applause_polite"); + break; case 3: - doAnimationAction(self, "yes"); - break; + doAnimationAction(self, "yes"); + break; case 4: - doAnimationAction(self, "snap_finger1"); - break; + doAnimationAction(self, "snap_finger1"); + break; } } else if (skillMod < 60) @@ -1815,35 +1713,35 @@ public class ai extends script.base_script switch (rand(1, 4)) { case 1: - doAnimationAction(self, "snap_finger1"); - break; + doAnimationAction(self, "snap_finger1"); + break; case 2: - doAnimationAction(self, "applause_polite"); - break; + doAnimationAction(self, "applause_polite"); + break; case 3: - doAnimationAction(self, "yes"); - break; + doAnimationAction(self, "yes"); + break; case 4: - doAnimationAction(self, "applause_excited"); - break; + doAnimationAction(self, "applause_excited"); + break; } } else { - switch (rand(1, 3)) + switch (rand(1, 4)) { case 1: - doAnimationAction(self, "applause_excited"); - break; + doAnimationAction(self, "applause_excited"); + break; case 2: - doAnimationAction(self, "clap_rousing"); - break; + doAnimationAction(self, "clap_rousing"); + break; case 3: - doAnimationAction(self, "implore"); - break; + doAnimationAction(self, "implore"); + break; case 4: - doAnimationAction(self, "applause_polite"); - break; + doAnimationAction(self, "applause_polite"); + break; } } utils.removeScriptVar(self, "ai.oldEntertainerSkillMod"); @@ -1895,10 +1793,9 @@ public class ai extends script.base_script while (keys.hasMoreElements()) { String key = (String)keys.nextElement(); - int mod = params.getInt(key); if (!key.equals("prefix")) { - utils.setScriptVar(self, "trapmod." + key, mod); + utils.setScriptVar(self, "trapmod." + key, params.getInt(key)); } } utils.setScriptVar(self, "trapmod.enable", 1); @@ -1906,17 +1803,15 @@ public class ai extends script.base_script String prefix = params.getString("prefix"); showFlyText(self, new string_id("trap/trap", prefix + "_on"), 1.2f, colors.ORANGERED); obj_id[] players = getPlayerCreaturesInRange(self, 50.f); - for (int i = 0; i < players.length; i++) - { - playClientEffectLoc(players[i], "clienteffect/combat_trap_" + prefix + ".cef", getLocation(self), 0f); + for (obj_id player : players) { + playClientEffectLoc(player, "clienteffect/combat_trap_" + prefix + ".cef", getLocation(self), 0f); } return SCRIPT_CONTINUE; } public int removeModTrap(obj_id self, dictionary params) throws InterruptedException { utils.removeScriptVar(self, "trapmod"); - String prefix = params.getString("prefix"); - showFlyText(self, new string_id("trap/trap", prefix + "_off"), 1.2f, colors.ORANGERED); + showFlyText(self, new string_id("trap/trap", params.getString("prefix") + "_off"), 1.2f, colors.ORANGERED); return SCRIPT_CONTINUE; } public int OnObjectMenuRequest(obj_id self, obj_id player, menu_info mi) throws InterruptedException @@ -1991,13 +1886,11 @@ public class ai extends script.base_script { return SCRIPT_CONTINUE; } - obj_id player = params.getObjId("player"); - attemptMilk(player, self); + attemptMilk(params.getObjId("player"), self); return SCRIPT_CONTINUE; } public void attemptMilk(obj_id player, obj_id self) throws InterruptedException { - obj_id playerCurrentMount = getMountId(player); obj_id pInv = utils.getInventoryContainer(player); if (!isValidId(pInv) || !exists(pInv)) { @@ -2008,7 +1901,7 @@ public class ai extends script.base_script sendSystemMessage(self, SID_CANT_MILK_INV_FULL); return; } - if (isIdValid(playerCurrentMount)) + if (isIdValid(getMountId(player))) { sendSystemMessage(player, SID_CANT_MILK_MOUNTED); return; @@ -2048,8 +1941,7 @@ public class ai extends script.base_script } if (milkStunModified > 0) { - int randStunRoll = rand(1, 100); - if (randStunRoll < milkStunModified) + if (rand(1, 100) < milkStunModified) { CustomerServiceLog("milking_and_lair_search", "handleMilking: Player: " + getName(player) + " OID: " + player + " has successfully stunned creature " + self + ". The creature will stand still for a few seconds."); messageTo(self, "milkingCreatureStunned", null, 0, false); @@ -2076,12 +1968,7 @@ public class ai extends script.base_script sendSystemMessage(player, SID_CANT_MILK_THE_DEAD); return SCRIPT_CONTINUE; } - if (params == null) - { - return SCRIPT_CONTINUE; - } - obj_id playerCurrentMount = getMountId(player); - if (isIdValid(playerCurrentMount)) + if (isIdValid(getMountId(player))) { sendSystemMessage(player, SID_CANT_MILK_MOUNTED); return SCRIPT_CONTINUE; @@ -2107,7 +1994,6 @@ public class ai extends script.base_script boolean shortenAttempts = false; float milkQuantityModified = 0.0f; float milkExceptionalModified = 0.0f; - float milkStunModified = 0.0f; if (buff.hasBuff(player, "creature_milking_buff") || buff.hasBuff(player, "drink_starshine_surprise")) { if (buff.hasBuff(player, "creature_milking_buff")) @@ -2166,12 +2052,6 @@ public class ai extends script.base_script return SCRIPT_CONTINUE; } String rsrcMapTable = "datatables/creature_resource/resource_scene_map.iff"; - if (rsrcMapTable == null || rsrcMapTable.equals("")) - { - blog("ai.handleMilking: cannot get resource map table data"); - CustomerServiceLog("milking_and_lair_search", "handleMilking: Player: " + getName(player) + " OID: " + player + " attempted to milk but could not retrieve resource map table data to receive the milk resources while milking " + self + " " + getName(self)); - return SCRIPT_CONTINUE; - } String correctedPlanetName = dataTableGetString(rsrcMapTable, sceneName, 1); if (correctedPlanetName == null || correctedPlanetName.equals("")) { @@ -2242,44 +2122,41 @@ public class ai extends script.base_script { return SCRIPT_CONTINUE; } - int actionCode = params.getInt("actionCode"); obj_id target = params.getObjId("actionTarget"); - switch (actionCode) + switch (params.getInt("actionCode")) { case gcw.AC_ATTACK: - if (isIdValid(target)) - { - startCombat(self, target); - } - break; + if (isIdValid(target)) + { + startCombat(self, target); + } + break; case gcw.AC_SCAN: - int scanInterests = params.getInt("scanInterests"); - if (scanInterests == 0) - { - gcw.assignScanInterests(self); - } - else - { - utils.setScriptVar(self, gcw.SCRIPTVAR_SCAN_INTEREST, scanInterests); - } - gcw.harass(self, target); - break; + int scanInterests = params.getInt("scanInterests"); + if (scanInterests == 0) + { + gcw.assignScanInterests(self); + } + else + { + utils.setScriptVar(self, gcw.SCRIPTVAR_SCAN_INTEREST, scanInterests); + } + gcw.harass(self, target); + break; default: - break; + break; } return SCRIPT_CONTINUE; } public int playDelayedClientEffect(obj_id self, dictionary params) throws InterruptedException { - String clientEffect = params.getString("effect"); obj_id target = params.getObjId("target"); - playClientEffectObj(target, clientEffect, target, ""); + playClientEffectObj(target, params.getString("effect"), target, ""); return SCRIPT_CONTINUE; } public int clearScriptVar(obj_id self, dictionary params) throws InterruptedException { - String scriptVarName = params.getString("name"); - utils.removeScriptVar(self, scriptVarName); + utils.removeScriptVar(self, params.getString("name")); return SCRIPT_CONTINUE; } public int OnInvulnerableChanged(obj_id self, boolean invulnerable) throws InterruptedException @@ -2335,32 +2212,23 @@ public class ai extends script.base_script { return SCRIPT_CONTINUE; } - String itemName = getStaticItemName(item); - if (!itemName.equals("col_meatlump_recruit_manual_02_01")) + if (!getStaticItemName(item).equals("col_meatlump_recruit_manual_02_01")) { return SCRIPT_CONTINUE; } String mobName = getCreatureName(self); String socialMeatlump = dataTableGetString(CREATURE_TABLE, mobName, "socialGroup"); - if (socialMeatlump.startsWith("meatlump") || socialMeatlump.endsWith("meatlump")) + if (socialMeatlump != null && (socialMeatlump.startsWith("meatlump") || socialMeatlump.endsWith("meatlump"))) { - if (!ai_lib.isNpc(self)) - { - return SCRIPT_CONTINUE; - } - else + if (ai_lib.isNpc(self)) { sendSystemMessage(giver, SID_ALREADY_RECRUITED); } return SCRIPT_CONTINUE; } - if ((toLower(socialMeatlump)).equals("rebel") || (toLower(socialMeatlump)).equals("rebel")) + if (socialMeatlump != null && ((toLower(socialMeatlump)).equals("rebel") || (toLower(socialMeatlump)).equals("rebel"))) { - if (!ai_lib.isNpc(self)) - { - return SCRIPT_CONTINUE; - } - else + if (ai_lib.isNpc(self)) { sendSystemMessage(giver, SID_NO_RECRUIT_REB_IMP); } @@ -2388,8 +2256,7 @@ public class ai extends script.base_script { return SCRIPT_CONTINUE; } - int attackRoll = rand(1, 100); - if (attackRoll <= 10) + if (rand(1, 100) <= 10) { chat.chat(self, SID_NPC_MEATLUMP_SPEAK); float searchSize = 12.0f; @@ -2444,18 +2311,12 @@ public class ai extends script.base_script } public int removeMeatlumpRecruitmentScriptVar(obj_id self, dictionary params) throws InterruptedException { - if (utils.hasScriptVar(self, "collection.recruited")) - { - utils.removeScriptVar(self, "collection.recruited"); - } + utils.removeScriptVar(self, "collection.recruited"); return SCRIPT_CONTINUE; } public int removeMeatlumpInvestigatorScriptVar(obj_id self, dictionary params) throws InterruptedException { - if (utils.hasScriptVar(self, "collection.investigator")) - { - utils.removeScriptVar(self, "collection.investigator"); - } + utils.removeScriptVar(self, "collection.investigator"); return SCRIPT_CONTINUE; } public int milkingCreatureStunned(obj_id self, dictionary params) throws InterruptedException @@ -2487,10 +2348,7 @@ public class ai extends script.base_script } public boolean blog(String msg) throws InterruptedException { - if (LOGGING_ON && !msg.equals("")) - { - LOG(LOGGING_CATEGORY, msg); - } + LOG(LOGGING_CATEGORY, msg); return true; } } diff --git a/sku.0/sys.server/compiled/game/script/library/utils.java b/sku.0/sys.server/compiled/game/script/library/utils.java old mode 100644 new mode 100755 index f94f70adb..28419bac8 --- a/sku.0/sys.server/compiled/game/script/library/utils.java +++ b/sku.0/sys.server/compiled/game/script/library/utils.java @@ -1,38 +1,9 @@ package script.library; import script.*; -import script.base_class.*; -import script.combat_engine.*; -import java.util.Arrays; -import java.util.Hashtable; -import java.util.Vector; -import script.base_script; -import java.util.Arrays; -import java.lang.System; -import java.lang.Math; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import script.script_entry; -import script.library.player_structure; -import script.library.healing; -import script.library.ai_lib; -import script.library.pclib; -import script.library.armor; -import script.library.chat; -import script.library.performance; -import script.library.trial; -import script.library.cloninglib; -import script.library.static_item; +import java.io.*; +import java.util.*; public class utils extends script.base_script { @@ -55,7 +26,7 @@ public class utils extends script.base_script public static final String TIP_IN_AMMOUNT = TIP + ".tip_in_ammount"; public static final String TIP_IN_THACK = TIP + ".tip_in_timeHack"; public static final String TIP_OUT_THACK = TIP + ".tip_out_timeHack"; - public static final String TRIAL_STRUCTURE = FREE_TRIAL + ".trial_structure"; + //public static final String TRIAL_STRUCTURE = FREE_TRIAL + ".trial_structure"; public static final int TIP_NUM_MAX = 25; public static final int TIP_AMT_MAX = 100000; public static final String NO_TRADE_SCRIPT = "item.special.nomove"; @@ -71,10 +42,10 @@ public class utils extends script.base_script waypoint_colors.purple, waypoint_colors.white }; - public static final string_id SID_SECONDS = new string_id("spam", "seconds"); - public static final string_id SID_MINUTES = new string_id("spam", "minutes"); - public static final string_id SID_HOURS = new string_id("spam", "hours"); - public static final string_id SID_DAYS = new string_id("spam", "days"); + //public static final string_id SID_SECONDS = new string_id("spam", "seconds"); + //public static final string_id SID_MINUTES = new string_id("spam", "minutes"); + //public static final string_id SID_HOURS = new string_id("spam", "hours"); + //public static final string_id SID_DAYS = new string_id("spam", "days"); public static final string_id SID_OUT_OF_RANGE = new string_id("spam", "out_of_range"); public static final int COMMANDO = 1; public static final int SMUGGLER = 2; @@ -86,21 +57,21 @@ public class utils extends script.base_script public static final int TRADER = 8; public static final int ENTERTAINER = 9; public static final String LIFEDAY_OWNER = "lifeday.owner"; - public static final String XMAS_RECEIVED_V1 = "gift.xmas05"; - public static final String XMAS_RECEIVED_V2 = "gift.xmas05v2"; + //public static final String XMAS_RECEIVED_V1 = "gift.xmas05"; + //public static final String XMAS_RECEIVED_V2 = "gift.xmas05v2"; public static final String XMAS_RECEIVED_VI1 = "gift.xmas06"; - public static final String XMAS_RECEIVED_VI2 = "gift.xmas06v2"; - public static final String XMAS_RECEIVED_VII1 = "gift.xmas07"; - public static final String XMAS_RECEIVED_VII2 = "gift.xmas07v2"; + //public static final String XMAS_RECEIVED_VI2 = "gift.xmas06v2"; + //public static final String XMAS_RECEIVED_VII1 = "gift.xmas07"; + //public static final String XMAS_RECEIVED_VII2 = "gift.xmas07v2"; public static final String XMAS_NOT_RECEIVED_TUTORIAL = "gift.xmas06_inTutorialFail"; - public static final String XMAS_RECEIVED_VIII1 = "gift.xmas08"; - public static final String XMAS_RECEIVED_VIII2 = "gift.xmas08v2"; + //public static final String XMAS_RECEIVED_VIII1 = "gift.xmas08"; + //public static final String XMAS_RECEIVED_VIII2 = "gift.xmas08v2"; public static final String XMAS_RECEIVED_IX_01 = "gift.xmas09"; - public static final String EMPIRE_DAY_RECEIVED_VI = "gift.empire08"; + //public static final String EMPIRE_DAY_RECEIVED_VI = "gift.empire08"; public static final string_id GIFT_GRANTED = new string_id("system_msg", "gift_granted"); public static final string_id GIFT_GRANTED_SUB = new string_id("system_msg", "gift_granted_sub"); - public static final int HOUSE_CURRENT = 0; - public static final int HOUSE_HISTORY = 1; + //public static final int HOUSE_CURRENT = 0; + //public static final int HOUSE_HISTORY = 1; public static final int HOUSE_MAX = 2; public static final obj_id OBJ_ID_BIO_LINK_PENDING = obj_id.getObjId(1); public static final String VENDOR_SCRIPT = "terminal.vendor"; @@ -2877,7 +2848,7 @@ public class utils extends script.base_script int[] tempVal = new int[count]; for (int i = 0; i < count; ++i) { - tempVal[i] = (((Integer)val.get(i))).intValue(); + tempVal[i] = (Integer) val.get(i); } result = setLocalVar(target, path, tempVal); } @@ -2887,7 +2858,7 @@ public class utils extends script.base_script boolean[] tempVal = new boolean[count]; for (int i = 0; i < count; ++i) { - tempVal[i] = (((Boolean)val.get(i))).booleanValue(); + tempVal[i] = (Boolean) val.get(i); } result = setLocalVar(target, path, tempVal); } @@ -3620,15 +3591,7 @@ public class utils extends script.base_script } public static boolean setScriptVar(obj_id target, String path, Vector val) throws InterruptedException { - if (!isIdValid(target)) - { - return false; - } - if ((path == null) || (path.equals(""))) - { - return false; - } - if (val == null || val.isEmpty()) + if (!isIdValid(target) || path == null || path.equals("") || val == null || val.isEmpty()) { return false; } @@ -3644,7 +3607,7 @@ public class utils extends script.base_script int[] tempVal = new int[count]; for (int i = 0; i < count; ++i) { - tempVal[i] = (((Integer)val.get(i))).intValue(); + tempVal[i] = (Integer) val.get(i); } result = setScriptVar(target, path, tempVal); } @@ -3654,7 +3617,7 @@ public class utils extends script.base_script boolean[] tempVal = new boolean[count]; for (int i = 0; i < count; ++i) { - tempVal[i] = (((Boolean)val.get(i))).booleanValue(); + tempVal[i] = (Boolean) val.get(i); } result = setScriptVar(target, path, tempVal); } @@ -3664,7 +3627,7 @@ public class utils extends script.base_script float[] tempVal = new float[count]; for (int i = 0; i < count; ++i) { - tempVal[i] = (((Float)val.get(i))).intValue(); + tempVal[i] = ((Float)val.get(i)).intValue(); } result = setScriptVar(target, path, tempVal); } @@ -3702,16 +3665,11 @@ public class utils extends script.base_script } public static boolean setScriptVar(obj_id target, String path, dictionary val) throws InterruptedException { - if (!isIdValid(target)) + if (!isIdValid(target) || path == null || path.equals("")) { return false; } - if ((path == null) || (path.equals(""))) - { - return false; - } - deltadictionary dd = target.getScriptVars(); - dd.put(path, val); + target.getScriptVars().put(path, val); return true; } public static boolean hasScriptVar(obj_id target, String path) throws InterruptedException @@ -3742,184 +3700,145 @@ public class utils extends script.base_script } public static boolean removeScriptVar(obj_id target, String path) throws InterruptedException { - if ((target == null) || (target == obj_id.NULL_ID)) + if (target == null || target == obj_id.NULL_ID || path == null || path.equals("")) { return false; } - if ((path == null) || (path.equals(""))) - { - return false; - } - deltadictionary dd = target.getScriptVars(); - dd.remove(path); + target.getScriptVars().remove(path); return true; } public static boolean removeScriptVarTree(obj_id target, String path) throws InterruptedException { - if ((target == null) || (target == obj_id.NULL_ID)) + if (target == null || target == obj_id.NULL_ID || path == null || path.equals("")) { return false; } - if ((path == null) || (path.equals(""))) - { - return false; - } - deltadictionary dd = target.getScriptVars(); - Enumeration keys = dd.keys(); + Enumeration keys = target.getScriptVars().keys(); while (keys.hasMoreElements()) { String key = (String)(keys.nextElement()); if (key.equals(path) || key.startsWith(path + ".")) { - dd.remove(key); + target.getScriptVars().remove(key); } } return true; } public static int getIntScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getInt(path); + return target.getScriptVars().getInt(path); } public static int[] getIntArrayScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getIntArray(path); + return target.getScriptVars().getIntArray(path); } public static float getFloatScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getFloat(path); + return target.getScriptVars().getFloat(path); } public static float[] getFloatArrayScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getFloatArray(path); + return target.getScriptVars().getFloatArray(path); } public static long getLongScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getLong(path); + return target.getScriptVars().getLong(path); } public static long[] getLongArrayScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getLongArray(path); + return target.getScriptVars().getLongArray(path); } public static double getDoubleScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getDouble(path); + return target.getScriptVars().getDouble(path); } public static double[] getDoubleArrayScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getDoubleArray(path); + return target.getScriptVars().getDoubleArray(path); } public static String getStringScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getString(path); + return target.getScriptVars().getString(path); } public static String[] getStringArrayScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getStringArray(path); + return target.getScriptVars().getStringArray(path); } public static String[][] getStringArrayArrayScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getStringArrayArray(path); + return target.getScriptVars().getStringArrayArray(path); } public static transform[] getTransformArrayScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getTransformArray(path); + return target.getScriptVars().getTransformArray(path); } public static transform getTransformScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getTransform(path); + return target.getScriptVars().getTransform(path); } public static boolean getBooleanScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getBoolean(path); + return target.getScriptVars().getBoolean(path); } public static boolean[] getBooleanArrayScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getBooleanArray(path); + return target.getScriptVars().getBooleanArray(path); } public static location getLocationScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getLocation(path); + return target.getScriptVars().getLocation(path); } public static location[] getLocationArrayScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getLocationArray(path); + return target.getScriptVars().getLocationArray(path); } public static obj_id getObjIdScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getObjId(path); + return target.getScriptVars().getObjId(path); } public static obj_id[] getObjIdArrayScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getObjIdArray(path); + return target.getScriptVars().getObjIdArray(path); } public static Vector getResizeableObjIdArrayScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getResizeableObjIdArray(path); + return target.getScriptVars().getResizeableObjIdArray(path); } public static Vector getResizeableLocationArrayScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getResizeableLocationArray(path); + return target.getScriptVars().getResizeableLocationArray(path); } public static Vector getResizeableIntArrayScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getResizeableIntArray(path); + return target.getScriptVars().getResizeableIntArray(path); } public static Vector getResizeableFloatArrayScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getResizeableFloatArray(path); + return target.getScriptVars().getResizeableFloatArray(path); } public static Vector getResizeableStringArrayScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getResizeableStringArray(path); + return target.getScriptVars().getResizeableStringArray(path); } public static Vector getResizeableTransformArrayScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getResizeableTransformArray(path); + return target.getScriptVars().getResizeableTransformArray(path); } public static Vector getResizeableVectorArrayScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getResizeableVectorArray(path); + return target.getScriptVars().getResizeableVectorArray(path); } public static string_id getStringIdScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getStringId(path); + return target.getScriptVars().getStringId(path); } public static string_id[] getStringIdArrayScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getStringIdArray(path); + return target.getScriptVars().getStringIdArray(path); } public static dictionary getDictionaryScriptVar(obj_id target, String path) throws InterruptedException { - deltadictionary dd = target.getScriptVars(); - return dd.getDictionary(path); + return target.getScriptVars().getDictionary(path); } public static boolean emptyContainer(obj_id target) throws InterruptedException { @@ -3932,9 +3851,8 @@ public class utils extends script.base_script { return false; } - for (int i = 0; i < contents.length; i++) - { - destroyObject(contents[i]); + for (obj_id content : contents) { + destroyObject(content); } return true; } @@ -3949,12 +3867,9 @@ public class utils extends script.base_script { return false; } - for (int i = 0; i < contents.length; i++) - { - obj_id contentsItem = contents[i]; - if (!utils.hasScriptVar(contentsItem, "storytellerLoot")) - { - destroyObject(contentsItem); + for (obj_id content : contents) { + if (!utils.hasScriptVar(content, "storytellerLoot")) { + destroyObject(content); } } return true; @@ -3981,8 +3896,7 @@ public class utils extends script.base_script locHeading.x = locStart.x + locHeading.x; locHeading.z = locStart.z + locHeading.z; locHeading.y = locStart.y + locHeading.y; - float fltAngle = thetaDegrees(locStart, locHeading); - return fltAngle; + return thetaDegrees(locStart, locHeading); } public static float thetaDegrees(location direction) throws InterruptedException { @@ -4003,17 +3917,10 @@ public class utils extends script.base_script return 0; } int intCount = 0; - for (int intI = 0; intI < objObjects.length; intI++) - { - String strString = getStringObjVar(objObjects[intI], strObjVar); - if (strString != null) - { - int intIndex = strString.indexOf(strSubString); - if (intIndex > -1) - { - intCount = intCount + 1; - } - } + for (obj_id objObject : objObjects) { + String strString = getStringObjVar(objObject, strObjVar); + if (strString != null && strString.contains(strSubString)) + intCount++; } return intCount; } @@ -4131,8 +4038,7 @@ public class utils extends script.base_script } public static obj_id cloneObject(obj_id template, obj_id container) throws InterruptedException { - String templateName = getTemplateName(template); - obj_id clone = createObject(templateName, container, ""); + obj_id clone = createObject(getTemplateName(template), container, ""); if (!isIdValid(clone)) { return null; @@ -4142,8 +4048,7 @@ public class utils extends script.base_script } public static obj_id cloneObject(obj_id template, location loc) throws InterruptedException { - String templateName = getTemplateName(template); - obj_id clone = createObject(templateName, loc); + obj_id clone = createObject(getTemplateName(template), loc); if (!isIdValid(clone)) { return null; @@ -4170,7 +4075,7 @@ public class utils extends script.base_script } public static boolean copyObjVar(obj_id target, String basePath, obj_var ov) throws InterruptedException { - if (!isIdValid(target)) + if (!isIdValid(target) || ov == null) { return false; } @@ -4178,92 +4083,71 @@ public class utils extends script.base_script { basePath = ""; } - if (ov == null) - { - return false; - } - String name = ov.getName(); - String path = basePath + name; + String path = basePath + ov.getName(); Object dta = ov.getData(); if (dta instanceof Integer) { - int val = ov.getIntData(); - return setObjVar(target, path, val); + return setObjVar(target, path, ov.getIntData()); } else if (dta instanceof int[]) { - int[] val = ov.getIntArrayData(); - return setObjVar(target, path, val); + return setObjVar(target, path, ov.getIntArrayData()); } else if (dta instanceof Float) { - float val = ov.getFloatData(); - return setObjVar(target, path, val); + return setObjVar(target, path, ov.getFloatData()); } else if (dta instanceof float[]) { - float[] val = ov.getFloatArrayData(); - return setObjVar(target, path, val); + return setObjVar(target, path, ov.getFloatArrayData()); } else if (dta instanceof Boolean) { - boolean val = ov.getBooleanData(); - return setObjVar(target, path, val); + return setObjVar(target, path, ov.getBooleanData()); } else if (dta instanceof Boolean[]) { - boolean[] val = ov.getBooleanArrayData(); - return setObjVar(target, path, val); + return setObjVar(target, path, ov.getBooleanArrayData()); } else if (dta instanceof String) { - String val = ov.getStringData(); - return setObjVar(target, path, val); + return setObjVar(target, path, ov.getStringData()); } else if (dta instanceof String[]) { - String[] val = ov.getStringArrayData(); - return setObjVar(target, path, val); + return setObjVar(target, path, ov.getStringArrayData()); } else if (dta instanceof obj_id) { - obj_id val = ov.getObjIdData(); - return setObjVar(target, path, val); + return setObjVar(target, path, ov.getObjIdData()); } else if (dta instanceof obj_id[]) { - obj_id[] val = ov.getObjIdArrayData(); - return setObjVar(target, path, val); + return setObjVar(target, path, ov.getObjIdArrayData()); } else if (dta instanceof location) { - location val = ov.getLocationData(); - return setObjVar(target, path, val); + return setObjVar(target, path, ov.getLocationData()); } else if (dta instanceof location[]) { - location[] val = ov.getLocationArrayData(); - return setObjVar(target, path, val); + return setObjVar(target, path, ov.getLocationArrayData()); } else if (dta instanceof string_id) { - string_id val = ov.getStringIdData(); - return setObjVar(target, path, val); + return setObjVar(target, path, ov.getStringIdData()); } else if (dta instanceof string_id[]) { - string_id[] val = ov.getStringIdArrayData(); - return setObjVar(target, path, val); + return setObjVar(target, path, ov.getStringIdArrayData()); } else if (dta instanceof attrib_mod) { - attrib_mod val = ov.getAttribModData(); - return setObjVar(target, path, val); + return setObjVar(target, path, ov.getAttribModData()); } else if (dta instanceof attrib_mod[]) { - attrib_mod[] val = ov.getAttribModArrayData(); - return setObjVar(target, path, val); + return setObjVar(target, path, ov.getAttribModArrayData()); } return false; } @@ -4298,7 +4182,7 @@ public class utils extends script.base_script { rootName = ""; } - else if (rootName != null && rootName.length() > 0) + else if (rootName.length() > 0) { if (!Character.isLetterOrDigit(rootName.charAt(0))) { @@ -4312,7 +4196,7 @@ public class utils extends script.base_script Enumeration keys = dict.keys(); while (keys.hasMoreElements()) { - String key = null; + String key; try { key = (String)keys.nextElement(); @@ -4324,11 +4208,11 @@ public class utils extends script.base_script Object data = dict.get(key); if (data instanceof Integer) { - setObjVar(object, rootName + key, (((Integer)data)).intValue()); + setObjVar(object, rootName + key, ((Integer)data).intValue()); } else if (data instanceof Float) { - setObjVar(object, rootName + key, (((Float)data)).floatValue()); + setObjVar(object, rootName + key, ((Float)data).floatValue()); } else if (data instanceof String) { @@ -4346,9 +4230,6 @@ public class utils extends script.base_script { saveDictionaryAsObjVar(object, rootName + key, (dictionary)data); } - else - { - } } return true; } @@ -4358,40 +4239,21 @@ public class utils extends script.base_script { return null; } - String strTestString = toLower(strSearchString); - final String[] FACTION_SEARCH_STRINGS = - { - factions.FACTION_IMPERIAL, - factions.FACTION_REBEL - }; - for (int intI = 0; intI < FACTION_SEARCH_STRINGS.length; intI++) - { - int intIndex = strTestString.indexOf(toLower(FACTION_SEARCH_STRINGS[intI])); - if (intIndex > -1) - { - return FACTION_SEARCH_STRINGS[intI]; - } - } + if(toLower(strSearchString).contains(toLower(factions.FACTION_IMPERIAL))) + return factions.FACTION_IMPERIAL; + else if(toLower(strSearchString).contains(toLower(factions.FACTION_REBEL))) + return factions.FACTION_REBEL; return null; } public static boolean setBatchObjVar(obj_id target, String base_path, Object[] array) throws InterruptedException { - if (!isIdValid(target)) + if (!isIdValid(target) || base_path == null || base_path.equals("") || array == null || array.length == 0) { return false; } - if ((base_path == null) || (base_path.equals(""))) - { - return false; - } - if ((array == null) || (array.length == 0)) - { - return false; - } - if (hasObjVar(target, base_path)) - { - removeObjVar(target, base_path); - } + + removeObjVar(target, base_path); + int BatchSize = 10; boolean litmus = true; int n = 0; @@ -4411,22 +4273,13 @@ public class utils extends script.base_script } public static void removeBatchObjVar(obj_id target, String base_path) throws InterruptedException { - if (!isIdValid(target)) + if (!isIdValid(target) || base_path == null || base_path.equals("") || !hasObjVar(target, base_path)) { return; } - if ((base_path == null) || (base_path.equals(""))) - { - return; - } - if (!hasObjVar(target, base_path)) - { - return; - } - if (hasObjVar(target, base_path)) - { - removeObjVar(target, base_path); - } + + removeObjVar(target, base_path); + obj_var_list list = getObjVarList(target, null); if (list == null) { @@ -4445,22 +4298,13 @@ public class utils extends script.base_script } public static boolean setBatchObjVar(obj_id target, String base_path, int[] array) throws InterruptedException { - if (!isIdValid(target)) + if (!isIdValid(target) || (base_path == null) || (base_path.equals("")) || (array == null) || (array.length == 0)) { return false; } - if ((base_path == null) || (base_path.equals(""))) - { - return false; - } - if ((array == null) || (array.length == 0)) - { - return false; - } - if (hasObjVar(target, base_path)) - { - removeObjVar(target, base_path); - } + + removeObjVar(target, base_path); + int BatchSize = 10; boolean litmus = true; int n = 0; @@ -4480,22 +4324,13 @@ public class utils extends script.base_script } public static boolean setResizeableBatchObjVar(obj_id target, String base_path, Vector vector) throws InterruptedException { - if (!isIdValid(target)) + if (!isIdValid(target) || (base_path == null) || (base_path.equals("")) || (vector == null) || (vector.size() == 0)) { return false; } - if ((base_path == null) || (base_path.equals(""))) - { - return false; - } - if ((vector == null) || (vector.size() == 0)) - { - return false; - } - if (hasObjVar(target, base_path)) - { - removeObjVar(target, base_path); - } + + removeObjVar(target, base_path); + int BatchSize = 10; boolean litmus = true; int n = 0; @@ -4515,15 +4350,7 @@ public class utils extends script.base_script } public static boolean setObjectArrayObjVar(obj_id target, String path, Vector vec) throws InterruptedException { - if (!isIdValid(target)) - { - return false; - } - if ((path == null) || (path.equals(""))) - { - return false; - } - if ((vec == null) || (vec.size() == 0)) + if (!isIdValid(target) || (path == null) || (path.equals("")) || (vec == null) || (vec.size() == 0)) { return false; } @@ -4531,40 +4358,30 @@ public class utils extends script.base_script Object test = vec.elementAt(0); if (test instanceof String) { - String[] tmp = new String[size]; - vec.toArray(tmp); - return setObjVar(target, path, tmp); + return setObjVar(target, path, vec.toArray(new String[size])); } else if (test instanceof string_id) { - string_id[] tmp = new string_id[size]; - vec.toArray(tmp); - return setObjVar(target, path, tmp); + return setObjVar(target, path, vec.toArray(new string_id[size])); } else if (test instanceof obj_id) { - obj_id[] tmp = new obj_id[size]; - vec.toArray(tmp); - return setObjVar(target, path, tmp); + return setObjVar(target, path, vec.toArray(new obj_id[size])); } else if (test instanceof attrib_mod) { - attrib_mod[] tmp = new attrib_mod[size]; - vec.toArray(tmp); - return setObjVar(target, path, tmp); + return setObjVar(target, path, vec.toArray(new attrib_mod[size])); } else if (test instanceof location) { - location[] tmp = new location[size]; - vec.toArray(tmp); - return setObjVar(target, path, tmp); + return setObjVar(target, path, vec.toArray(new location[size])); } else if (test instanceof Integer) { int[] tmp = new int[size]; for (int i = 0; i < vec.size(); i++) { - tmp[i] = (((Integer)(vec.get(i)))).intValue(); + tmp[i] = (Integer) (vec.get(i)); } return setObjVar(target, path, tmp); } @@ -4572,15 +4389,7 @@ public class utils extends script.base_script } public static String[] getStringBatchObjVar(obj_id target, String base_path) throws InterruptedException { - if (!isIdValid(target)) - { - return null; - } - if ((base_path == null) || (base_path.equals(""))) - { - return null; - } - if (!hasObjVar(target, base_path)) + if (!isIdValid(target) || (base_path == null) || (base_path.equals("")) || !hasObjVar(target, base_path)) { return null; } @@ -4614,15 +4423,7 @@ public class utils extends script.base_script } public static Vector getResizeableStringBatchObjVar(obj_id target, String base_path) throws InterruptedException { - if (!isIdValid(target)) - { - return null; - } - if ((base_path == null) || (base_path.equals(""))) - { - return null; - } - if (!hasObjVar(target, base_path)) + if (!isIdValid(target) || (base_path == null) || (base_path.equals("")) || !hasObjVar(target, base_path)) { return null; } @@ -4806,7 +4607,7 @@ public class utils extends script.base_script _ret = new int[ret.size()]; for (int _i = 0; _i < ret.size(); ++_i) { - _ret[_i] = ((Integer)ret.get(_i)).intValue(); + _ret[_i] = (Integer) ret.get(_i); } } return _ret; @@ -5056,17 +4857,16 @@ public class utils extends script.base_script return null; } int cnt = getIntScriptVar(target, base_path); - deltadictionary dd = target.getScriptVars(); Vector ret = new Vector(); for (int i = 0; i < cnt; i++) { - Vector tmp = dd.getResizeableObjIdArray(base_path + "." + i); + Vector tmp = target.getScriptVars().getResizeableObjIdArray(base_path + "." + i); if ((tmp != null) && (tmp.size() > 0)) { ret.addAll(tmp); } } - if ((ret != null) && (ret.size() > 0)) + if ((ret.size() > 0)) { return ret; } @@ -5096,11 +4896,10 @@ public class utils extends script.base_script return null; } int cnt = getIntScriptVar(target, base_path); - deltadictionary dd = target.getScriptVars(); Vector ret = new Vector(); for (int i = 0; i < cnt; i++) { - Vector tmp = dd.getResizeableStringArray(base_path + "." + i); + Vector tmp = target.getScriptVars().getResizeableStringArray(base_path + "." + i); if ((tmp != null) && (tmp.size() > 0)) { ret.addAll(tmp); @@ -5136,11 +4935,10 @@ public class utils extends script.base_script return null; } int cnt = getIntScriptVar(target, base_path); - deltadictionary dd = target.getScriptVars(); Vector ret = new Vector(); for (int i = 0; i < cnt; i++) { - Vector tmp = dd.getResizeableLocationArray(base_path + "." + i); + Vector tmp = target.getScriptVars().getResizeableLocationArray(base_path + "." + i); if ((tmp != null) && (tmp.size() > 0)) { ret.addAll(tmp); @@ -5167,11 +4965,10 @@ public class utils extends script.base_script return null; } int cnt = getIntScriptVar(target, base_path); - deltadictionary dd = target.getScriptVars(); Vector ret = new Vector(); for (int i = 0; i < cnt; i++) { - Vector tmp = dd.getResizeableIntArray(base_path + "." + i); + Vector tmp = target.getScriptVars().getResizeableIntArray(base_path + "." + i); if ((tmp != null) && (tmp.size() > 0)) { ret.addAll(tmp); @@ -5197,14 +4994,10 @@ public class utils extends script.base_script Vector ret = getResizeableIntBatchScriptVar(target, base_path); if ((ret != null) && (ret.size() > 0)) { - int[] _ret = new int[0]; - if (ret != null) + int[] _ret = new int[ret.size()]; + for (int _i = 0; _i < ret.size(); ++_i) { - _ret = new int[ret.size()]; - for (int _i = 0; _i < ret.size(); ++_i) - { - _ret[_i] = ((Integer)ret.get(_i)).intValue(); - } + _ret[_i] = (Integer) ret.get(_i); } return _ret; } @@ -5298,55 +5091,39 @@ public class utils extends script.base_script } public static boolean checkConfigFlag(String strSection, String strConfigSetting) throws InterruptedException { - String strTest = getConfigSetting(strSection, strConfigSetting); - if (strTest != null) - { - strTest = toLower(strTest); - if (strTest.equals("true")) - { - return true; - } - if (strTest.equals("1")) - { - return true; - } - return false; - } - else - { - return false; - } + String strTest = toLower(getConfigSetting(strSection, strConfigSetting)); + return (strTest != null && (strTest.equals("true") || strTest.equals("1"))); } public static boolean checkServerSpawnLimits() throws InterruptedException { + final int intNumPlayers = getNumPlayers(); + // nobody is playing... spawn away Merrill... + if(intNumPlayers <= 0) return true; final int intServerSpawnLimit = getServerSpawnLimit(); final int intNumCreatures = utils.getNumCreaturesForSpawnLimit(); - final int intNumPlayers = getNumPlayers(); - if (intNumPlayers > 0) + + if (intServerSpawnLimit > 0) { - if (intServerSpawnLimit > 0) + if (intNumCreatures > intServerSpawnLimit) { - if (intNumCreatures > intServerSpawnLimit) + return false; + } + } + else + { + if (intNumPlayers < 200000) + { + if (intNumCreatures > 5000) { return false; } } - else + else { - if (intNumPlayers < 200000) + float fltRatio = (float)(intNumCreatures / intNumPlayers); + if (fltRatio > 10) { - if (intNumCreatures > 5000) - { - return false; - } - } - else - { - float fltRatio = (float)(intNumCreatures / intNumPlayers); - if (fltRatio > 10) - { - return false; - } + return false; } } } @@ -5430,11 +5207,7 @@ public class utils extends script.base_script time_str += ", "; } } - if (time_str != null && !time_str.equals("")) - { - return time_str; - } - return ""; + return time_str; } public static String formatTime(int seconds) throws InterruptedException { @@ -5442,7 +5215,10 @@ public class utils extends script.base_script { return ""; } + int[] convert_time = player_structure.convertSecondsTime(seconds); + if(convert_time == null) return ""; + int idx = 0; for (int i = 0; i < convert_time.length; i++) { @@ -5465,11 +5241,7 @@ public class utils extends script.base_script time_str += ":"; } } - if (time_str != null && !time_str.equals("")) - { - return time_str; - } - return ""; + return time_str; } public static String formatTime(float fTime) throws InterruptedException { @@ -5605,7 +5377,7 @@ public class utils extends script.base_script tmp.add(array[i]); } } - if ((tmp == null) || (tmp.size() == 0)) + if (tmp.size() == 0) { return null; } @@ -5656,17 +5428,18 @@ public class utils extends script.base_script { if (strObjVar == null) { - LOG("DESIGNER_FATAL", "Null objVar paseed into addListener"); + LOG("DESIGNER_FATAL", "Null objVar passed into addListener"); return; } if (!isIdValid(objTarget)) { - LOG("DESIGNER_FATAL", "Null owner paseed into addListener"); + LOG("DESIGNER_FATAL", "Null owner passed into addListener"); return; } if (!isIdValid(objListener)) { - LOG("DESIGNER_FATAL", "Null listener paseed into addListener"); + LOG("DESIGNER_FATAL", "Null listener passed into addListener"); + return; } dictionary dctParams = new dictionary(); dctParams.put("objListener", objListener); @@ -5678,17 +5451,18 @@ public class utils extends script.base_script { if (strObjVar == null) { - LOG("DESIGNER_FATAL", "Null objVar paseed into removeListener"); + LOG("DESIGNER_FATAL", "Null objVar passed into removeListener"); return; } if (!isIdValid(objTarget)) { - LOG("DESIGNER_FATAL", "Null target paseed into removeListener"); + LOG("DESIGNER_FATAL", "Null target passed into removeListener"); return; } if (!isIdValid(objListener)) { - LOG("DESIGNER_FATAL", "Null listener paseed into removeListeer"); + LOG("DESIGNER_FATAL", "Null listener passed into removeListener"); + // no return here as we need to let this remove any null listeners anyway. } dictionary dctParams = new dictionary(); dctParams.put("objListener", objListener); @@ -5700,17 +5474,18 @@ public class utils extends script.base_script { if (strObjVar == null) { - LOG("DESIGNER_FATAL", "Null objVar paseed into messageListeners"); + LOG("DESIGNER_FATAL", "Null objVar passed into messageListeners"); return; } if (!isIdValid(objOwner)) { - LOG("DESIGNER_FATAL", "Null owner paseed into messageListeners"); + LOG("DESIGNER_FATAL", "Null owner passed into messageListeners"); return; } if (strMessageName == null) { - LOG("DESIGNER_FATAL", "Null messageName paseed into messageListeners"); + LOG("DESIGNER_FATAL", "Null messageName passed into messageListeners"); + return; } if (hasObjVar(objOwner, strObjVar)) { @@ -5728,18 +5503,15 @@ public class utils extends script.base_script { if (isTheater(strLairType)) { - int intIndex = strLairType.indexOf("medium"); - if (intIndex > 0) + if (strLairType.contains("medium")) { return 40; } - intIndex = strLairType.indexOf("small"); - if (intIndex > 0) + if (strLairType.contains("small")) { return 24; } - intIndex = strLairType.indexOf("large"); - if (intIndex > 0) + if (strLairType.contains("large")) { return 72; } @@ -5749,16 +5521,7 @@ public class utils extends script.base_script } public static boolean isTheater(String strLairType) throws InterruptedException { - if (strLairType == null) - { - return false; - } - int intIndex = strLairType.indexOf("theater"); - if (intIndex > 0) - { - return true; - } - return false; + return strLairType != null && strLairType.contains("theater"); } public static boolean isAppropriateName(String name) throws InterruptedException { @@ -5782,11 +5545,7 @@ public class utils extends script.base_script } public static boolean setNonProfaneName(obj_id target, String name) throws InterruptedException { - if (!isIdValid(target) || name == null || name.equals("")) - { - return false; - } - if (!isAppropriateName(name)) + if (!isIdValid(target) || name == null || name.equals("") || !isAppropriateName(name)) { return false; } @@ -5822,11 +5581,9 @@ public class utils extends script.base_script { return; } - for (int i = 0; i < objects.length; i++) - { - if (isIdValid(objects[i])) - { - destroyObject(objects[i]); + for (obj_id object : objects) { + if (isIdValid(object)) { + destroyObject(object); } } } @@ -5836,17 +5593,16 @@ public class utils extends script.base_script { return null; } - String filename = null; String fullPath = getTemplateName(target); if (fullPath != null && !fullPath.equals("")) { String[] tmp = split(fullPath, '/'); if (tmp != null && tmp.length > 0) { - filename = tmp[tmp.length - 1]; + return tmp[tmp.length - 1]; } } - return filename; + return null; } public static int getFirstNonValidIdIndex(obj_id[] ids) throws InterruptedException { @@ -5880,17 +5636,11 @@ public class utils extends script.base_script } public static void moneyInMetric(obj_id objTransferer, String strAccount, int intAmount) throws InterruptedException { - int intTime = getGameTime(); - String strSpam = "moneyIn;" + intTime + ";" + objTransferer + ";" + strAccount + ";" + intAmount; - logBalance(strSpam); - return; + logBalance("moneyIn;" + getGameTime() + ";" + objTransferer + ";" + strAccount + ";" + intAmount); } public static void moneyOutMetric(obj_id objTransferer, String strAccount, int intAmount) throws InterruptedException { - int intTime = getGameTime(); - String strSpam = "moneyOut;" + intTime + ";" + objTransferer + ";" + strAccount + ";" + intAmount; - logBalance(strSpam); - return; + logBalance("moneyOut;" + getGameTime() + ";" + objTransferer + ";" + strAccount + ";" + intAmount); } public static int getValidAttributeIndex(String[] array) throws InterruptedException { @@ -6064,25 +5814,14 @@ public class utils extends script.base_script { return getStringCardinalDirection(locTest1, locTest2, false); } - public static boolean isContainer(obj_id target) throws InterruptedException - { - if (isIdValid(target)) - { - return (getContainerType(target) != 0); - } - return false; + public static boolean isContainer(obj_id target) throws InterruptedException { + return isIdValid(target) && (getContainerType(target) != 0); } - public static boolean noIncapDrainAttributes(obj_id target, int actionCost, int mindCost) throws InterruptedException - { - if (!isIdValid(target) || actionCost < 0) - { + public static boolean noIncapDrainAttributes(obj_id target, int actionCost, int mindCost) throws InterruptedException { + if (!isIdValid(target) || actionCost < 0) { return false; } - if (getAttrib(target, ACTION) < actionCost) - { - return false; - } - return drainAttributes(target, actionCost, 0); + return getAttrib(target, ACTION) >= actionCost && drainAttributes(target, actionCost, 0); } public static int getUnbuffedWoundedMaxAttrib(obj_id target, int attrib) throws InterruptedException { @@ -6090,8 +5829,7 @@ public class utils extends script.base_script { return -1; } - int unmodmax = getUnmodifiedMaxAttrib(target, attrib); - return unmodmax; + return getUnmodifiedMaxAttrib(target, attrib); } public static boolean validatePlayerHairStyle(obj_id player) throws InterruptedException { @@ -6099,14 +5837,13 @@ public class utils extends script.base_script { return false; } - String hair_table = "datatables/customization/hair_assets_skill_mods.iff"; obj_id hair = getObjectInSlot(player, "hair"); if (!isIdValid(hair)) { return false; } - String hair_template = getTemplateName(hair); - int idx = dataTableSearchColumnForString(hair_template, "SERVER_TEMPLATE", hair_table); + String hair_table = "datatables/customization/hair_assets_skill_mods.iff"; + int idx = dataTableSearchColumnForString(getTemplateName(hair), "SERVER_TEMPLATE", hair_table); if (idx < 0) { return false; @@ -6119,8 +5856,7 @@ public class utils extends script.base_script String player_template = getTemplateName(player); if (!player_template.equals(required_template)) { - int new_hair_idx = dataTableSearchColumnForString(player_template, "SERVER_PLAYER_TEMPLATE", hair_table); - String new_hair_template = dataTableGetString(hair_table, new_hair_idx, "SERVER_TEMPLATE"); + String new_hair_template = dataTableGetString(hair_table, dataTableSearchColumnForString(player_template, "SERVER_PLAYER_TEMPLATE", hair_table), "SERVER_TEMPLATE"); if (new_hair_template == null) { CustomerServiceLog("imageDesigner", getFirstName(player) + "(" + player + ") has an invalid hairstyle, but a replacement cannot be found!"); @@ -6141,10 +5877,10 @@ public class utils extends script.base_script { for (int intI = 0; intI < strScripts.length; intI++) { - strTest = strTest + strScripts[intI]; + strTest += strScripts[intI]; if (intI < strScripts.length - 1) { - strTest = strTest + ","; + strTest += ","; } } } @@ -6152,7 +5888,6 @@ public class utils extends script.base_script } public static String[] getUsableScriptList(obj_id objObject) throws InterruptedException { - String strTest = ""; String[] strScripts = getScriptList(objObject); debugSpeakMsg(objObject, "script list is " + strScripts.length); if (strScripts.length > 0) @@ -6162,7 +5897,7 @@ public class utils extends script.base_script for (int intI = 0; intI < strScripts.length; intI++) { String script = strScripts[intI]; - if (script.indexOf("script.") > -1) + if (script.contains("script.")) { script = script.substring(7); debugSpeakMsg(objObject, "setting array to " + script); @@ -6175,8 +5910,7 @@ public class utils extends script.base_script } public static String[] unpackScriptString(String strScripts) throws InterruptedException { - String[] strTest = split(strScripts, ','); - return strTest; + return split(strScripts, ','); } public static boolean isEquipped(obj_id item) throws InterruptedException { @@ -6252,58 +5986,35 @@ public class utils extends script.base_script } } } - if (attackable_targets.size() < 1) - { - return null; - } - else + if (attackable_targets.size() >= 1) { obj_id[] _attackable_targets = new obj_id[0]; - if (attackable_targets != null) - { - _attackable_targets = new obj_id[attackable_targets.size()]; - attackable_targets.toArray(_attackable_targets); - } + _attackable_targets = new obj_id[attackable_targets.size()]; + attackable_targets.toArray(_attackable_targets); return _attackable_targets; } + return null; } public static obj_id getTrapDroidId(obj_id player) throws InterruptedException { - obj_id dataPad = getPlayerDatapad(player); - Vector data = getResizeableContents(dataPad); - for (int i = 0; i < data.size(); i++) - { - if (callable.hasCDCallable(((obj_id)data.get(i))) && hasObjVar(((obj_id)data.get(i)), "module_data.trap_bonus")) - { - return ((obj_id)data.get(i)); + Vector data = getResizeableContents(getPlayerDatapad(player)); + if(data == null) return null; + for (Object aData : data) { + if (callable.hasCDCallable(((obj_id) aData)) && hasObjVar(((obj_id) aData), "module_data.trap_bonus")) { + return ((obj_id) aData); } } return null; } public static int getTimeLeft(obj_id player, String toCheckFor, int timePenalty) throws InterruptedException { - int currentTime = getGameTime(); int timeCalled = utils.getIntScriptVar(player, toCheckFor); - if (timeCalled < 1) - { - return -1; - } - int timeDone = timeCalled + timePenalty; - int timeLeft = timeDone - currentTime; - return timeLeft; + return timeCalled < 1 ? -1 : timeCalled + timePenalty - getGameTime(); } public static int getTimeLeft(obj_id player, String toCheckFor, String modifiedTime) throws InterruptedException { - int currentTime = getGameTime(); int timeCalled = utils.getIntScriptVar(player, toCheckFor); - if (timeCalled < 1) - { - return -1; - } - int timePenalty = utils.getIntScriptVar(player, modifiedTime); - int timeDone = timeCalled + timePenalty; - int timeLeft = timeDone - currentTime; - return timeLeft; + return timeCalled < 1 ? -1 : timeCalled + utils.getIntScriptVar(player, modifiedTime) - getGameTime(); } public static boolean isFreeTrial(obj_id player) throws InterruptedException { @@ -6336,7 +6047,6 @@ public class utils extends script.base_script try { int intReturn = script_entry.callMessageHandlers(strNotificationName, objTarget, dctParams); - return; } catch(Throwable err) { @@ -6350,7 +6060,6 @@ public class utils extends script.base_script try { script_entry.runScripts(strTrigger, params); - return; } catch(Throwable err) { @@ -6361,13 +6070,9 @@ public class utils extends script.base_script } public static String getCellName(obj_id building, obj_id cell) throws InterruptedException { - String[] cellNames = getCellNames(building); - for (int i = 0; i < cellNames.length; i++) - { - String cellName = cellNames[i]; + for (String cellName : getCellNames(building)) { obj_id thisCell = getCellId(building, cellName); - if (thisCell == cell) - { + if (thisCell == cell) { return cellName; } } @@ -6407,16 +6112,12 @@ public class utils extends script.base_script if (isIdValid(mount)) { pet_lib.doDismountNow(rider, false); - String name = getTemplateName(mount); if (vehicle.isJetPackVehicle(mount)) { - string_id jetDismount = new string_id("pet/pet_menu", "jetpack_dismount"); - sendSystemMessage(rider, jetDismount); - obj_id petControlDevice = callable.getCallableCD(mount); - vehicle.storeVehicle(petControlDevice, rider); + sendSystemMessage(rider, new string_id("pet/pet_menu", "jetpack_dismount")); + vehicle.storeVehicle(callable.getCallableCD(mount), rider); } } - return; } public static location getLocationFromTransform(transform trTest) throws InterruptedException { @@ -6431,8 +6132,7 @@ public class utils extends script.base_script { if (hasObjVar(item, prefix + "classRequired")) { - String requiredClasses = getStringObjVar(item, prefix + "classRequired"); - java.util.StringTokenizer st = new java.util.StringTokenizer(requiredClasses, ","); + java.util.StringTokenizer st = new java.util.StringTokenizer(getStringObjVar(item, prefix + "classRequired"), ","); String requiredText = ""; boolean qualifies = false; while (st.hasMoreTokens()) @@ -6470,14 +6170,10 @@ public class utils extends script.base_script public static boolean testItemClassRequirements(obj_id player, String requiredClasses, boolean silent) throws InterruptedException { java.util.StringTokenizer st = new java.util.StringTokenizer(requiredClasses, ","); - String requiredText = ""; while (st.hasMoreTokens()) { - String classId = st.nextToken(); - if (isProfession(player, stringToInt(classId))) - { + if (isProfession(player, stringToInt(st.nextToken()))) return true; - } } if (!silent) { @@ -6485,14 +6181,8 @@ public class utils extends script.base_script } return false; } - public static boolean testItemClassRequirements(obj_id player, obj_id thing, boolean silent, String prefix) throws InterruptedException - { - if (!hasObjVar(thing, prefix + "classRequired")) - { - return true; - } - String requiredClasses = getStringObjVar(thing, prefix + "classRequired"); - return testItemClassRequirements(player, requiredClasses, silent); + public static boolean testItemClassRequirements(obj_id player, obj_id thing, boolean silent, String prefix) throws InterruptedException { + return !hasObjVar(thing, prefix + "classRequired") || testItemClassRequirements(player, getStringObjVar(thing, prefix + "classRequired"), silent); } public static boolean testItemLevelRequirements(obj_id player, obj_id thing, boolean silent, String prefix) throws InterruptedException { @@ -6523,8 +6213,7 @@ public class utils extends script.base_script { if (!silent) { - prose_package pp = prose.getPackage(new string_id("spam", "abilityrequired"), "@cmd_n:" + toLower(commandRequired)); - sendSystemMessageProse(player, pp); + sendSystemMessageProse(player, prose.getPackage(new string_id("spam", "abilityrequired"), "@cmd_n:" + toLower(commandRequired))); } return false; } @@ -6541,8 +6230,7 @@ public class utils extends script.base_script { if (!silent) { - prose_package pp = prose.getPackage(new string_id("spam", "skill_required"), "@skl_n:" + toLower(skillRequired)); - sendSystemMessageProse(player, pp); + sendSystemMessageProse(player, prose.getPackage(new string_id("spam", "skill_required"), "@skl_n:" + toLower(skillRequired))); } return false; } @@ -6664,14 +6352,7 @@ public class utils extends script.base_script } public static boolean isAntiDecay(obj_id item) throws InterruptedException { - if (isIdValid(item) && hasObjVar(item, "antidecay")) - { - return true; - } - else - { - return false; - } + return isIdValid(item) && hasObjVar(item, "antidecay"); } public static boolean makeAntiDecay(obj_id item) throws InterruptedException { @@ -6681,39 +6362,22 @@ public class utils extends script.base_script attachScript(item, "systems.veteran_reward.antidecay_examine"); return true; } - else - { - return false; - } + return false; } public static boolean removeAntiDecay(obj_id item) throws InterruptedException { if (isIdValid(item)) { - if (hasObjVar(item, "antidecay")) - { - removeObjVar(item, "antidecay"); - } + removeObjVar(item, "antidecay"); return true; } - else - { - return false; - } + return false; } public static boolean validItemForAntiDecay(obj_id item) throws InterruptedException { if (isIdValid(item)) { - if (jedi.isLightsaber(item)) - { - return true; - } - if (isGameObjectTypeOf(item, GOT_armor_psg)) - { - return false; - } - if (cloninglib.isDamagedOnCloneGOT(getGameObjectType(item)) || isGameObjectTypeOf(item, GOT_weapon)) + if (jedi.isLightsaber(item) || cloninglib.isDamagedOnCloneGOT(getGameObjectType(item)) || isGameObjectTypeOf(item, GOT_weapon)) { return true; } @@ -6751,14 +6415,7 @@ public class utils extends script.base_script { return false; } - if (hasSkill(player, "social_language_wookiee_comprehend")) - { - return false; - } - else - { - return true; - } + return !hasSkill(player, "social_language_wookiee_comprehend"); } public static void emoteWookieeConfusion(obj_id player, obj_id npc) throws InterruptedException { @@ -6771,33 +6428,29 @@ public class utils extends script.base_script { return; } - String[] pairs = split(objVarList, ','); - for (int i = 0; i < pairs.length; i++) - { - String[] objVarToSet = split(pairs[i], '='); + for (String pair : split(objVarList, ',')) { + String[] objVarToSet = split(pair, '='); String objVarValue = objVarToSet[1]; String[] objVarNameAndType = split(objVarToSet[0], ':'); String objVarType = objVarNameAndType[0]; String objVarName = objVarNameAndType[1]; - if (objVarType.equals("string")) - { - setObjVar(object, objVarName, objVarValue); - } - else if (objVarType.equals("int")) - { - setObjVar(object, objVarName, utils.stringToInt(objVarValue)); - } - else if (objVarType.equals("float")) - { - setObjVar(object, objVarName, utils.stringToFloat(objVarValue)); - } - else if (objVarType.equals("boolean") || objVarType.equals("bool")) - { - setObjVar(object, objVarName, utils.stringToInt(objVarValue)); - } - else - { - setObjVar(object, objVarName, objVarValue); + switch (objVarType) { + case "string": + setObjVar(object, objVarName, objVarValue); + break; + case "int": + setObjVar(object, objVarName, utils.stringToInt(objVarValue)); + break; + case "float": + setObjVar(object, objVarName, utils.stringToFloat(objVarValue)); + break; + case "boolean": + case "bool": + setObjVar(object, objVarName, utils.stringToInt(objVarValue)); + break; + default: + setObjVar(object, objVarName, objVarValue); + break; } } } @@ -6807,33 +6460,29 @@ public class utils extends script.base_script { return; } - String[] pairs = split(objVarList, ','); - for (int i = 0; i < pairs.length; i++) - { - String[] objVarToSet = split(pairs[i], '='); + for (String pair : split(objVarList, ',')) { + String[] objVarToSet = split(pair, '='); String objVarValue = objVarToSet[1]; String[] objVarNameAndType = split(objVarToSet[0], ';'); String objVarType = objVarNameAndType[0]; String objVarName = objVarNameAndType[1]; - if (objVarType.equals("string")) - { - setObjVar(object, objVarName, objVarValue); - } - else if (objVarType.equals("int")) - { - setObjVar(object, objVarName, utils.stringToInt(objVarValue)); - } - else if (objVarType.equals("float")) - { - setObjVar(object, objVarName, utils.stringToFloat(objVarValue)); - } - else if (objVarType.equals("boolean") || objVarType.equals("bool")) - { - setObjVar(object, objVarName, utils.stringToInt(objVarValue)); - } - else - { - setObjVar(object, objVarName, objVarValue); + switch (objVarType) { + case "string": + setObjVar(object, objVarName, objVarValue); + break; + case "int": + setObjVar(object, objVarName, utils.stringToInt(objVarValue)); + break; + case "float": + setObjVar(object, objVarName, utils.stringToFloat(objVarValue)); + break; + case "boolean": + case "bool": + setObjVar(object, objVarName, utils.stringToInt(objVarValue)); + break; + default: + setObjVar(object, objVarName, objVarValue); + break; } } } @@ -6845,9 +6494,7 @@ public class utils extends script.base_script setObjVar(subject, "recordLoc", recordLoc); return true; } - location verifyLoc = getLocationObjVar(subject, "recordLoc"); - location here = getLocation(getTopMostContainer(subject)); - float distanceDifference = getDistance(verifyLoc, here); + float distanceDifference = getDistance(getLocationObjVar(subject, "recordLoc"), getLocation(getTopMostContainer(subject))); if (distanceDifference > distance || distanceDifference == -1f) { destroyObject(subject); @@ -6862,9 +6509,7 @@ public class utils extends script.base_script setObjVar(subject, "recordLoc", recordLoc); return true; } - location verifyLoc = getLocationObjVar(subject, "recordLoc"); - location here = getLocation(getTopMostContainer(subject)); - float distanceDifference = getDistance(verifyLoc, here); + float distanceDifference = getDistance(getLocationObjVar(subject, "recordLoc"), getLocation(getTopMostContainer(subject))); if (distanceDifference > distance || distanceDifference == -1f) { destroyObject(subject); @@ -6949,7 +6594,6 @@ public class utils extends script.base_script { return false; } - String classTemplate = getSkillTemplate(player); String professionName = ""; switch (profession) { @@ -6983,11 +6627,8 @@ public class utils extends script.base_script default: break; } - if (classTemplate != null && classTemplate.startsWith(professionName)) - { - return true; - } - return false; + String classTemplate = getSkillTemplate(player); + return classTemplate != null && classTemplate.startsWith(professionName); } public static int getPlayerProfession(obj_id player) throws InterruptedException { @@ -7051,8 +6692,7 @@ public class utils extends script.base_script { ByteArrayInputStream byteInput = new ByteArrayInputStream(source); ObjectInputStream ois = new ObjectInputStream(byteInput); - Object result = ois.readObject(); - return result; + return ois.readObject(); } catch(ClassNotFoundException x) { @@ -7094,8 +6734,7 @@ public class utils extends script.base_script { if (player_structure.isBuilding(getTopMostContainer(ownerContainer))) { - location loc = getLocation(oldItem); - newItem = createObject(newTemplateName, loc); + newItem = createObject(newTemplateName, getLocation(oldItem)); if (isIdValid(newItem)) { if (isObjectPersisted(oldItem) && !isObjectPersisted(newItem)) @@ -7105,7 +6744,7 @@ public class utils extends script.base_script } CustomerServiceLog("replaceSnowflakeItem: ", "Old Item (" + oldItem + ") is contained in a building (" + getTopMostContainer(ownerContainer) + ")"); CustomerServiceLog("replaceSnowflakeItem: ", "New Item (" + newItem + ") was created in building (" + getTopMostContainer(ownerContainer) + ")"); - CustomerServiceLog("replaceSnowflakeItem: ", "New Item (" + newItem + ")s location is in a building (" + getTopMostContainer(ownerContainer) + ") is x = " + loc.x + " y = " + loc.y + " z = " + loc.z + "and cell = " + getCellName(getTopMostContainer(ownerContainer), loc.cell)); + CustomerServiceLog("replaceSnowflakeItem: ", "New Item (" + newItem + ")s location is in a building (" + getTopMostContainer(ownerContainer) + ")"); } } else @@ -7137,7 +6776,7 @@ public class utils extends script.base_script if (strItemTemplate.equals(oldTemplates[j])) { String newTemplate = dataTableGetString("datatables/item/snowflake_item_swaps.iff", j, "NEW_TEMPLATE"); - if (newTemplate != null || !newTemplate.equals("")) + if (newTemplate != null && !newTemplate.equals("")) { replaceSnowflakeItem(objContents[i], newTemplate); } @@ -7146,56 +6785,22 @@ public class utils extends script.base_script } } } - return; } public static boolean isVendorObject(obj_id object) throws InterruptedException { - if (hasScript(object, VENDOR_SCRIPT)) - { - return true; - } - return false; + return hasScript(object, VENDOR_SCRIPT); } public static boolean isBazaarObject(obj_id object) throws InterruptedException { - if (hasScript(object, BAZAAR_SCRIPT)) - { - return true; - } - return false; + return hasScript(object, BAZAAR_SCRIPT); } - public static boolean isInVendor(obj_id item) throws InterruptedException - { + public static boolean isInVendor(obj_id item) throws InterruptedException { obj_id ownerContainer = getContainedBy(item); - if (!isIdValid(ownerContainer)) - { - return false; - } - obj_id parentContainer = getContainedBy(ownerContainer); - if (hasObjVar(parentContainer, "vendor")) - { - return true; - } - else - { - return false; - } + return isIdValid(ownerContainer) && hasObjVar(getContainedBy(ownerContainer), "vendor"); } - public static boolean isInBazaar(obj_id item) throws InterruptedException - { + public static boolean isInBazaar(obj_id item) throws InterruptedException { obj_id ownerContainer = getContainedBy(item); - if (!isIdValid(ownerContainer)) - { - return false; - } - if (hasScript(ownerContainer, "terminal.bazaar")) - { - return true; - } - else - { - return false; - } + return isIdValid(ownerContainer) && hasScript(ownerContainer, "terminal.bazaar"); } public static boolean outOfRange(obj_id self, obj_id player, float distance, boolean message) throws InterruptedException { @@ -7217,19 +6822,16 @@ public class utils extends script.base_script } public static float roundFloatByDecimal(float number) throws InterruptedException { - float tempNumber = number * 100; - int result = (int)Math.round(tempNumber); - float finalResult = (float)result / 100; - return finalResult; + return (float) Math.round(number * 100) / 100; } public static void housePackingDecreaseIncrease(obj_id objPlayer, int change) throws InterruptedException { + int[] housePacking; if (change > 0) { - int[] housePacking = new int[utils.HOUSE_MAX]; if (!hasObjVar(objPlayer, "housePackup")) { - setObjVar(objPlayer, "housePackup", housePacking); + setObjVar(objPlayer, "housePackup", new int[utils.HOUSE_MAX]); } housePacking = getIntArrayObjVar(objPlayer, "housePackup"); if (housePacking.length != utils.HOUSE_MAX) @@ -7245,7 +6847,7 @@ public class utils extends script.base_script int resetTime = getGameTime() + player_structure.TIME_TO_NEXT_PACKUP; setObjVar(objPlayer, "maxHousePackupTimer", resetTime); } - else + else { int dailyHousePacking = getIntObjVar(objPlayer, "dailyHousePackup"); dailyHousePacking++; @@ -7277,9 +6879,8 @@ public class utils extends script.base_script } } } - else + else { - int[] housePacking = new int[utils.HOUSE_MAX]; housePacking = getIntArrayObjVar(objPlayer, "housePackup"); if (housePacking.length != utils.HOUSE_MAX) { @@ -7330,19 +6931,13 @@ public class utils extends script.base_script { return false; } - for (int n = 0; n < contents.length; n++) - { - int got = getGameObjectType(contents[n]); - if (isGameObjectTypeOf(got, GOT_resource_container)) - { - obj_id resourceCrate = contents[n]; - if (isIdValid(resourceCrate)) - { - obj_id resourceId = getResourceContainerResourceType(resourceCrate); - if (isIdValid(resourceId)) - { - if (isResourceDerivedFrom(resourceId, resource)) - { + for (obj_id content : contents) { + int got = getGameObjectType(content); + if (isGameObjectTypeOf(got, GOT_resource_container)) { + if (isIdValid(content)) { + obj_id resourceId = getResourceContainerResourceType(content); + if (isIdValid(resourceId)) { + if (isResourceDerivedFrom(resourceId, resource)) { return true; } } @@ -7351,29 +6946,23 @@ public class utils extends script.base_script } return false; } - public static obj_id[] validateObjIdArray(obj_id[] source) throws InterruptedException + public static obj_id[] validateObjIdArray(obj_id[] objIds) throws InterruptedException { Vector target = new Vector(); target.setSize(0); - for (int i = 0; i < source.length; i++) - { - if (isIdValid(source[i]) && exists(source[i])) - { - addElement(target, source[i]); + for (obj_id objId : objIds) { + if (isIdValid(objId) && exists(objId)) { + addElement(target, objId); } } - if (target != null) - { - source = new obj_id[target.size()]; - target.toArray(source); + objIds = new obj_id[target.size()]; + target.toArray(objIds); - } - return source; + return objIds; } public static obj_id[] getPlayersInBuildoutRow(obj_id player) throws InterruptedException { - location loc = getLocation(player); - return getPlayersInBuildoutRow(loc.area, locations.getBuildoutAreaRow(player)); + return getPlayersInBuildoutRow(getLocation(player).area, locations.getBuildoutAreaRow(player)); } public static obj_id[] getPlayersInBuildoutDimensions(String scene, float x1, float x2, float z1, float z2) throws InterruptedException { @@ -7399,7 +6988,7 @@ public class utils extends script.base_script } utils.addElement(playersInArea, allPlayers[i]); } - if (playersInArea == null || playersInArea.size() == 0) + if (playersInArea.size() == 0) { return null; } @@ -7413,67 +7002,29 @@ public class utils extends script.base_script } public static dictionary getCoordinatesInBuildoutRow(String scene, int buildout_row) throws InterruptedException { - String datatable = "datatables/buildout/areas_" + scene + ".iff"; - dictionary data = dataTableGetRow(datatable, buildout_row); - return data; + return dataTableGetRow("datatables/buildout/areas_" + scene + ".iff", buildout_row); } public static obj_id[] getPlayersInBuildoutRow(String scene, int buildout_row) throws InterruptedException { - String datatable = "datatables/buildout/areas_" + scene + ".iff"; - dictionary data = dataTableGetRow(datatable, buildout_row); + dictionary data = dataTableGetRow("datatables/buildout/areas_" + scene + ".iff", buildout_row); return getPlayersInBuildoutDimensions(scene, data.getFloat("x1"), data.getFloat("x2"), data.getFloat("z1"), data.getFloat("z2")); } public static obj_id[] getPlayersInBuildoutArea(String scene, String buildout_area) throws InterruptedException { - String datatable = "datatables/buildout/areas_" + scene + ".iff"; - int rowNum = dataTableSearchColumnForString(buildout_area, 0, datatable); + int rowNum = dataTableSearchColumnForString(buildout_area, 0, "datatables/buildout/areas_" + scene + ".iff"); if (rowNum == -1) { return null; } return getPlayersInBuildoutRow(scene, rowNum); } - public static obj_id[] getAllNpcInBuildoutArea(obj_id baseObject) throws InterruptedException - { - location loc = getLocation(baseObject); - int buildout_area = locations.getBuildoutAreaRow(baseObject); - obj_id[] allObjects = getAllObjectsInBuildoutArea(loc.area, buildout_area); - if (allObjects == null || allObjects.length == 0) - { - return null; - } - Vector allNpc = new Vector(); - allNpc.setSize(0); - for (int i = 0; i < allObjects.length; i++) - { - if (!isMob(allObjects[i])) - { - continue; - } - allNpc.add(allObjects[i]); - } - if (allNpc == null || allNpc.size() == 0) - { - return null; - } - if (allNpc != null) - { - allObjects = new obj_id[allNpc.size()]; - allNpc.toArray(allObjects); - - } - return allObjects; - } public static obj_id[] getAllObjectsInBuildoutArea(obj_id baseObject) throws InterruptedException { - location loc = getLocation(baseObject); - int buildout_row = locations.getBuildoutAreaRow(baseObject); - return getAllObjectsInBuildoutArea(loc.area, buildout_row); + return getAllObjectsInBuildoutArea(getLocation(baseObject).area, locations.getBuildoutAreaRow(baseObject)); } public static obj_id[] getAllObjectsInBuildoutArea(String scene, int buildout_row) throws InterruptedException { - String datatable = "datatables/buildout/areas_" + scene + ".iff"; - dictionary data = dataTableGetRow(datatable, buildout_row); + dictionary data = dataTableGetRow("datatables/buildout/areas_" + scene + ".iff", buildout_row); float x1 = data.getFloat("x1"); float x2 = data.getFloat("x2"); float z1 = data.getFloat("z1"); @@ -7499,16 +7050,13 @@ public class utils extends script.base_script } objectsInArea.add(allObjects[i]); } - if (objectsInArea == null || objectsInArea.size() == 0) + if (objectsInArea.size() == 0) { return null; } obj_id[] _objectsInArea = new obj_id[0]; - if (objectsInArea != null) - { - _objectsInArea = new obj_id[objectsInArea.size()]; - objectsInArea.toArray(_objectsInArea); - } + _objectsInArea = new obj_id[objectsInArea.size()]; + objectsInArea.toArray(_objectsInArea); return _objectsInArea; } public static Vector shuffleArray(Vector list) throws InterruptedException @@ -7561,7 +7109,6 @@ public class utils extends script.base_script CustomerServiceLog("grantGift", getFirstName(player) + "(" + player + ") did not have an inventory container. Didn't receive Christmas '06 gift, but not blocked from future attempt."); return false; } - obj_id giftSelf = static_item.createNewItemFunction("item_lifeday_gift_self_01_02", inv); obj_id giftOther = static_item.createNewItemFunction("item_lifeday_gift_other_01_02", inv); setObjVar(giftOther, LIFEDAY_OWNER, player); utils.sendMail(GIFT_GRANTED_SUB, GIFT_GRANTED, player, "System"); @@ -7633,11 +7180,8 @@ public class utils extends script.base_script String updateObjvar = utils.CTS_OBJVAR_HISTORY + ".1"; if (!hasObjVar(player, updateObjvar)) { - if ((ctsOjbvars == null) && !retrievedCtsOjbvars) - { - ctsOjbvars = getCharacterRetroactiveCtsObjvars(player); - retrievedCtsOjbvars = true; - } + ctsOjbvars = getCharacterRetroactiveCtsObjvars(player); + retrievedCtsOjbvars = true; if ((ctsOjbvars != null) && (ctsOjbvars.length > 0)) { utils.updateRespecCTSObjvars(player, ctsOjbvars); @@ -7651,7 +7195,6 @@ public class utils extends script.base_script if ((ctsOjbvars == null) && !retrievedCtsOjbvars) { ctsOjbvars = getCharacterRetroactiveCtsObjvars(player); - retrievedCtsOjbvars = true; } if ((ctsOjbvars != null) && (ctsOjbvars.length > 0)) { @@ -7828,12 +7371,10 @@ public class utils extends script.base_script HashSet abilitiesCurrentNoDupes = new HashSet(); for (int i = 0; i < abilitiesCurrent.size(); ++i) { - abilitiesCurrentNoDupes.add(new Integer(((Integer)abilitiesCurrent.get(i)).intValue())); + abilitiesCurrentNoDupes.add(new Integer((Integer) abilitiesCurrent.get(i))); } - Iterator abilitiesIterator = abilitiesCurrentNoDupes.iterator(); - while (abilitiesIterator.hasNext()) - { - Integer ability = (Integer)abilitiesIterator.next(); + for (Object abilitiesCurrentNoDupe : abilitiesCurrentNoDupes) { + Integer ability = (Integer) abilitiesCurrentNoDupe; abilities.add(ability); } if (abilities.size() != abilitiesCurrentNoDupes.size()) @@ -7845,21 +7386,21 @@ public class utils extends script.base_script { int[] abilitiesNew = new int[abilities.size()]; Iterator abilitiesIterator = abilities.iterator(); - String strAbilitiesNew = new String(); + String strAbilitiesNew = ""; int i = 0; while (abilitiesIterator.hasNext() && (i < abilitiesNew.length)) { Integer ability = (Integer)abilitiesIterator.next(); - abilitiesNew[i] = ability.intValue(); + abilitiesNew[i] = ability; strAbilitiesNew += "" + abilitiesNew[i] + ", "; ++i; } - String strAbilitiesCurrent = new String(); + String strAbilitiesCurrent = ""; if ((abilitiesCurrent != null) && (abilitiesCurrent.size() > 0)) { for (int j = 0; j < abilitiesCurrent.size(); ++j) { - strAbilitiesCurrent += "" + ((Integer)abilitiesCurrent.get(j)).intValue() + ", "; + strAbilitiesCurrent += "" + (Integer) abilitiesCurrent.get(j) + ", "; } } CustomerServiceLog("CharacterTransferRetroactiveHistory", "changing " + beast_lib.PLAYER_KNOWN_SKILLS_LIST + " objvar for " + player + " from (" + strAbilitiesCurrent + ") to (" + strAbilitiesNew + ")"); @@ -7985,7 +7526,7 @@ public class utils extends script.base_script { left = 1; } - if (text.indexOf(":") < 0) + if (!text.contains(":")) { return text; } diff --git a/sku.0/sys.server/compiled/game/script/obj_id.java b/sku.0/sys.server/compiled/game/script/obj_id.java old mode 100644 new mode 100755 index a54b3a1eb..1d885026a --- a/sku.0/sys.server/compiled/game/script/obj_id.java +++ b/sku.0/sys.server/compiled/game/script/obj_id.java @@ -264,22 +264,12 @@ public final class obj_id implements Comparable, Serializable public boolean hasScriptDictionary(Object key) { - boolean result = false; - if (scriptDictionary != null) - { - result = scriptDictionary.containsKey(key); - } - return result; + return scriptDictionary != null && scriptDictionary.containsKey(key); } public boolean hasScriptVar(Object key) { - boolean result = false; - if (scriptVars != null) - { - result = scriptVars.hasKey(key); - } - return result; + return scriptVars != null && scriptVars.hasKey(key); } /**