Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 46.98 KB | None | 0 0
  1. package script;
  2.  
  3. import script.location;
  4. import script.obj_id;
  5. import script.library.combat_consts;
  6. import script.library.utils;
  7. import script.base_class;
  8. import java.util.Hashtable;
  9.  
  10. public class combat_engine
  11. {
  12.     /**
  13.      * Combat constants
  14.      */
  15.  
  16.     private static Hashtable m_CombatDataCache = new Hashtable();
  17.     private static Hashtable m_BuffDataCache = new Hashtable();
  18.  
  19.     public static final int OUT_OF_RANGE = Integer.MIN_VALUE;
  20.     private static float MAX_MELEE_TARGET_RANGE         = -1.0f;
  21.     private static float DEFAULT_MAX_MELEE_TARGET_RANGE = 24.0f;
  22.  
  23.     private static float MAX_COMBAT_RANGE               = -1.0f;
  24.  
  25.     // get methods for config setting variables
  26.     public static float getMaxMeleeTargetRange() throws InterruptedException
  27.     {
  28.         if (MAX_MELEE_TARGET_RANGE > 0)
  29.             return MAX_MELEE_TARGET_RANGE;
  30.  
  31.         float error = utils.stringToFloat("");
  32.         float tmp = utils.stringToFloat(base_class.getConfigSetting("GameServer", "maxMeleeTargetRange"));
  33.  
  34.         if (tmp == error)
  35.             MAX_MELEE_TARGET_RANGE = DEFAULT_MAX_MELEE_TARGET_RANGE;
  36.         else
  37.             MAX_MELEE_TARGET_RANGE = tmp;
  38.  
  39.         return MAX_MELEE_TARGET_RANGE;
  40.     }
  41.  
  42.     public static float getMaxCombatRange() throws InterruptedException
  43.     {
  44.         if (MAX_COMBAT_RANGE < 0)
  45.         {
  46.             MAX_COMBAT_RANGE = utils.stringToFloat(base_class.getConfigSetting("GameServer", "maxCombatRange"));
  47.         }
  48.  
  49.         return MAX_COMBAT_RANGE;
  50.     }
  51.  
  52.     /*********************************************************************/
  53.  
  54.         public static combat_data getCombatData(String actionName)
  55.         {
  56.             if(m_CombatDataCache.containsKey(actionName))
  57.             {
  58.                 return combat_data.clone((combat_data)m_CombatDataCache.get(actionName));
  59.             }
  60.  
  61.             combat_data dat = loadCombatData(actionName);
  62.             if(dat != null)
  63.             {
  64.                 m_CombatDataCache.put(actionName, dat);
  65.             }
  66.             else
  67.             {
  68.                 return null;
  69.             }
  70.  
  71.             return combat_data.clone(dat);
  72.         }
  73.  
  74.         private static combat_data loadCombatData(String actionName)
  75.         {
  76.             combat_data dat = new combat_data();
  77.             dictionary d = base_class.dataTableGetRow("datatables/combat/combat_data.iff", actionName);
  78.             dictionary dc = base_class.dataTableGetRow("datatables/command/command_table.iff", actionName);
  79.             if(d == null || dc == null)
  80.             {
  81.                 return null;
  82.             }
  83.  
  84.             dat.actionName                      = actionName;
  85.             dat.minInvisLevelRequired           = d.getInt("minInvisLevelRequired");
  86.             dat.commandType                     = d.getInt("commandType");
  87.             dat.validTarget                     = d.getInt("validTarget");
  88.             dat.hitType                         = d.getInt("hitType");
  89.             dat.effectOnTarget                  = d.getString("effectOnTarget");
  90.             dat.setCombatTarget                 = d.getInt("setCombatTarget");
  91.             dat.delayAttackEggTemplate          = d.getString("delayAttackEggTemplate");
  92.             dat.delayAttackParticle             = d.getString("delayAttackParticle");
  93.             dat.initialDelayAttackInterval      = d.getFloat("initialDelayAttackInterval");
  94.             dat.delayAttackInterval             = d.getFloat("delayAttackInterval");
  95.             dat.delayAttackEggPosition          = d.getInt("delayAttackEggPosition");
  96.             dat.delayAttackLoops                = d.getInt("delayAttackLoops");
  97.             dat.validEggTarget                  = d.getInt("validEggTarget");
  98.             dat.attackType                      = d.getInt("attackType");
  99.             dat.coneLength                      = d.getFloat("coneLength");
  100.             dat.coneWidth                       = d.getFloat("coneWidth");
  101.             dat.minRange                        = d.getFloat("minRange");
  102.             dat.maxRange                        = d.getFloat("maxRange");
  103.             dat.addedDamage                     = d.getInt("addedDamage");
  104.             dat.percentAddFromWeapon            = d.getFloat("percentAddFromWeapon");
  105.             dat.hateDamageModifier              = d.getFloat("hateDamageModifier");
  106.             dat.maxHate                         = d.getInt("maxHate");
  107.             dat.hateAdd                         = d.getInt("hateAdd");
  108.             dat.hateAddTime                     = d.getInt("hateAddTime");
  109.             dat.hateReduce                      = d.getInt("hateReduce");
  110.             dat.actionCost                      = d.getFloat("actionCost");
  111.             dat.vigorCost                       = d.getFloat("vigorCost");
  112.             dat.scaleByDefenderWeaponSpeed              = d.getFloat("scaleByDefenderWeaponSpeed");
  113.             dat.dotType                         = d.getString("dotType");
  114.             dat.dotIntensity                    = d.getInt("dotIntensity");
  115.             dat.dotDuration                     = d.getInt("dotDuration");
  116.             dat.buffNameTarget                  = d.getString("buffNameTarget");
  117.             dat.buffStrengthTarget              = d.getFloat("buffStrengthTarget");
  118.             dat.buffDurationTarget              = d.getFloat("buffDurationTarget");
  119.             dat.buffNameSelf                    = d.getString("buffNameSelf");
  120.             dat.buffStrengthSelf                = d.getFloat("buffStrengthSelf");
  121.             dat.buffDurationSelf                = d.getFloat("buffDurationSelf");
  122.             dat.canBePunishing                  = d.getInt("canBePunishing");
  123.             dat.increaseCritical                = d.getFloat("increaseCritical");
  124.             dat.increaseStrikethrough           = d.getFloat("increaseStrikethrough");
  125.             dat.reduceGlancing                  = d.getFloat("reduceGlancing");
  126.             dat.reduceParry                     = d.getFloat("reduceParry");
  127.             dat.reduceBlock                     = d.getFloat("reduceBlock");
  128.             dat.reduceDodge                     = d.getFloat("reduceDodge");
  129.             dat.overloadWeapon                  = d.getInt("overloadWeapon");
  130.             dat.overloadWeaponMinDamage         = d.getInt("minDamage");
  131.             dat.overloadWeaponMaxDamage         = d.getInt("maxDamage");
  132.             dat.overloadWeaponMinRange          = d.getFloat("minRange"); // this is shared with the command's min range
  133.             dat.overloadWeaponMaxRange          = d.getFloat("maxRangeOverloaded"); // this is shared with the command's max range
  134.             dat.overloadWeaponType              = d.getInt("weaponType");
  135.             dat.overloadWeaponCategory          = d.getInt("weaponCategory");
  136.             dat.overloadWeaponDamageType        = d.getInt("damageType");
  137.             dat.overloadWeaponElementalType     = d.getInt("elementalType");
  138.             dat.overloadWeaponElementalValue    = d.getInt("elementalValue");
  139.             dat.overloadWeaponAttackSpeed       = d.getFloat("attackSpeed");
  140.             dat.overloadWeaponDamageRadius      = d.getFloat("damageRadius");
  141.             dat.specialLine                     = d.getString("specialLine");
  142.             dat.animDefault                     = d.getString("animDefault");
  143.             dat.intRightFoot                    = d.getInt("intRightFoot");
  144.             dat.intLeftFoot                     = d.getInt("intLeftFoot");
  145.             dat.intRightHand                    = d.getInt("intRightHand");
  146.             dat.intLeftHand                     = d.getInt("intLeftHand");
  147.             dat.intWeapon                       = d.getInt("intWeapon");
  148.             dat.anim_unarmed                    = d.getString("anim_unarmed");
  149.             dat.anim_onehandmelee               = d.getString("anim_onehandmelee");
  150.             dat.anim_twohandmelee               = d.getString("anim_twohandmelee");
  151.             dat.anim_polearm                    = d.getString("anim_polearm");
  152.             dat.anim_pistol                     = d.getString("anim_pistol");
  153.             dat.anim_lightRifle                 = d.getString("anim_lightRifle");
  154.             dat.anim_carbine                    = d.getString("anim_carbine");
  155.             dat.anim_rifle                      = d.getString("anim_rifle");
  156.             dat.anim_heavyweapon                = d.getString("anim_heavyweapon");
  157.             dat.anim_thrown                     = d.getString("anim_thrown");
  158.             dat.anim_onehandlightsaber          = d.getString("anim_onehandlightsaber");
  159.             dat.anim_twohandlightsaber          = d.getString("anim_twohandlightsaber");
  160.             dat.anim_polearmlightsaber          = d.getString("anim_polearmlightsaber");
  161.             dat.validWeapon                     = dc.getInt("validWeapon");
  162.             dat.invalidWeapon                   = dc.getInt("invalidWeapon");
  163.             dat.cooldownGroup                   = dc.getString("cooldownGroup");
  164.             dat.warmupTime                      = dc.getFloat("warmupTime");
  165.             dat.executeTime                     = dc.getFloat("executeTime");
  166.             dat.cooldownTime                    = dc.getFloat("cooldownTime");
  167.             dat.attribute                       = d.getInt("healAttrib");
  168.             dat.bypassArmor                     = d.getFloat("bypassArmor");
  169.             dat.convertDamageToHealth           = d.getFloat("convertDamageToHealth");
  170.             dat.ignore_distance                 = d.getInt("ignore_distance");
  171.             dat.pvp_only                        = d.getInt("pvp_only");
  172.             dat.attack_rolls                    = d.getInt("attack_rolls");
  173.             dat.flatActionDamage                = d.getInt("flatActionDamage");
  174.  
  175.             dat.performanceSpamStrId            = new string_id("cbt_spam", d.getString("performance_spam"));
  176.             dat.hitSpam                         = d.getInt("hit_spam");
  177.  
  178.             return dat;
  179.         }
  180.  
  181.  
  182.         //Returns combat data in dictionary form. Need to to preserve data through delayed attacks.
  183.         public static dictionary getCombatDataDictionary(String actionName)
  184.         {
  185.             return (getCombatDataDictionary(getCombatData(actionName)));
  186.         }
  187.  
  188.         public static dictionary getCombatDataDictionary(combat_data actionData)
  189.         {
  190.             dictionary dict = new dictionary();
  191.  
  192.             dict.put("actionName", actionData.actionName);
  193.             dict.put("minInvisLevelRequired", actionData.minInvisLevelRequired);
  194.             dict.put("commandType", actionData.commandType);
  195.             dict.put("validTarget", actionData.validTarget);
  196.             dict.put("hitType", actionData.hitType);
  197.             dict.put("effectOnTarget", actionData.effectOnTarget);
  198.             dict.put("setCombatTarget", actionData.setCombatTarget);
  199.             dict.put("delayAttackEggTemplate", actionData.delayAttackEggTemplate);
  200.             dict.put("delayAttackParticle", actionData.delayAttackParticle);
  201.             dict.put("initialDelayAttackInterval", actionData.initialDelayAttackInterval);
  202.             dict.put("delayAttackInterval", actionData.delayAttackInterval);
  203.             dict.put("delayAttackEggPosition", actionData.delayAttackEggPosition);
  204.             dict.put("delayAttackLoops", actionData.delayAttackLoops);
  205.             dict.put("validEggTarget", actionData.validEggTarget);
  206.             dict.put("attackType", actionData.attackType);
  207.             dict.put("coneLength", actionData.coneLength);
  208.             dict.put("coneWidth", actionData.coneWidth);
  209.             dict.put("minRange", actionData.minRange);
  210.             dict.put("maxRange", actionData.maxRange);
  211.             dict.put("addedDamage", actionData.addedDamage);
  212.             dict.put("percentAddFromWeapon", actionData.percentAddFromWeapon);
  213.             dict.put("hateDamageModifier", actionData.hateDamageModifier);
  214.             dict.put("maxHate", actionData.maxHate);
  215.             dict.put("hateAdd", actionData.hateAdd);
  216.             dict.put("hateAddTime", actionData.hateAddTime);
  217.             dict.put("hateReduce", actionData.hateReduce);
  218.             dict.put("actionCost", actionData.actionCost);
  219.             dict.put("vigorCost", actionData.vigorCost);
  220.             dict.put("scaleByDefenderWeaponSpeed", actionData.scaleByDefenderWeaponSpeed);
  221.             dict.put("dotType", actionData.dotType);
  222.             dict.put("dotIntensity", actionData.dotIntensity);
  223.             dict.put("dotDuration", actionData.dotDuration);
  224.             dict.put("buffNameTarget", actionData.buffNameTarget);
  225.             dict.put("buffStrengthTarget", actionData.buffStrengthTarget);
  226.             dict.put("buffDurationTarget", actionData.buffDurationTarget);
  227.             dict.put("buffNameSelf", actionData.buffNameSelf);
  228.             dict.put("buffStrengthSelf", actionData.buffStrengthSelf);
  229.             dict.put("buffDurationSelf", actionData.buffDurationSelf);
  230.             dict.put("canBePunishing", actionData.canBePunishing);
  231.             dict.put("increaseCritical", actionData.increaseCritical);
  232.             dict.put("increaseStrikethrough", actionData.increaseStrikethrough);
  233.             dict.put("reduceGlancing", actionData.reduceGlancing);
  234.             dict.put("reduceParry", actionData.reduceParry);
  235.             dict.put("reduceBlock", actionData.reduceBlock);
  236.             dict.put("reduceDodge", actionData.reduceDodge);
  237.             dict.put("overloadWeapon", actionData.overloadWeapon);
  238.             dict.put("overloadWeaponMinDamage", actionData.overloadWeaponMinDamage);
  239.             dict.put("overloadWeaponMaxDamage", actionData.overloadWeaponMaxDamage);
  240.             dict.put("overloadWeaponMinRange", actionData.overloadWeaponMinRange);
  241.             dict.put("overloadWeaponMaxRange", actionData.overloadWeaponMaxRange);
  242.             dict.put("overloadWeaponType", actionData.overloadWeaponType);
  243.             dict.put("overloadWeaponCategory", actionData.overloadWeaponCategory);
  244.             dict.put("overloadWeaponDamageType", actionData.overloadWeaponDamageType);
  245.             dict.put("overloadWeaponElementalType", actionData.overloadWeaponElementalType);
  246.             dict.put("overloadWeaponElementalValue", actionData.overloadWeaponElementalValue);
  247.             dict.put("overloadWeaponAttackSpeed", actionData.overloadWeaponAttackSpeed);
  248.             dict.put("overloadWeaponDamageRadius", actionData.overloadWeaponDamageRadius);
  249.             dict.put("specialLine", actionData.specialLine);
  250.             dict.put("animDefault", actionData.animDefault);
  251.             dict.put("intRightFoot", actionData.intRightFoot);
  252.             dict.put("intLeftFoot", actionData.intLeftFoot);
  253.             dict.put("intRightHand", actionData.intRightHand);
  254.             dict.put("intLeftHand", actionData.intLeftHand);
  255.             dict.put("intWeapon", actionData.intWeapon);
  256.             dict.put("anim_unarmed", actionData.anim_unarmed);
  257.             dict.put("anim_onehandmelee", actionData.anim_onehandmelee);
  258.             dict.put("anim_twohandmelee", actionData.anim_twohandmelee);
  259.             dict.put("anim_polearm", actionData.anim_polearm);
  260.             dict.put("anim_pistol", actionData.anim_pistol);
  261.             dict.put("anim_lightRifle", actionData.anim_lightRifle);
  262.             dict.put("anim_carbine", actionData.anim_carbine);
  263.             dict.put("anim_rifle", actionData.anim_rifle);
  264.             dict.put("anim_heavyweapon", actionData.anim_heavyweapon);
  265.             dict.put("anim_thrown", actionData.anim_thrown);
  266.             dict.put("anim_onehandlightsaber", actionData.anim_onehandlightsaber);
  267.             dict.put("anim_twohandlightsaber", actionData.anim_twohandlightsaber);
  268.             dict.put("anim_polearmlightsaber", actionData.anim_polearmlightsaber);
  269.             dict.put("validWeapon", actionData.validWeapon);
  270.             dict.put("invalidWeapon", actionData.invalidWeapon);
  271.             dict.put("cooldownGroup", actionData.cooldownGroup);
  272.             dict.put("warmupTime", actionData.warmupTime);
  273.             dict.put("executeTime", actionData.executeTime);
  274.             dict.put("cooldownTime", actionData.cooldownTime);
  275.             dict.put("attribute", actionData.attribute);
  276.             dict.put("bypassArmor", actionData.bypassArmor);
  277.             dict.put("convertDamageToHealth", actionData.convertDamageToHealth);
  278.             dict.put("ignore_distance", actionData.ignore_distance);
  279.             dict.put("pvp_only", actionData.pvp_only);
  280.             dict.put("attack_rolls", actionData.attack_rolls);
  281.             dict.put("flatActionDamage", actionData.flatActionDamage);
  282.             dict.put("performanceSpamStrId", actionData.performanceSpamStrId);
  283.             dict.put("hitSpam", actionData.hitSpam);
  284.  
  285.             return dict;
  286.         }
  287.  
  288.         public static combat_data getCombatDataFromDictionary(dictionary dict)
  289.         {
  290.                 combat_data dat = new combat_data();
  291.  
  292.                 dat.actionName                      = dict.getString("actionName");
  293.                 dat.minInvisLevelRequired           = dict.getInt("minInvisLevelRequired");
  294.                 dat.commandType                     = dict.getInt("commandType");
  295.                 dat.validTarget                     = dict.getInt("validTarget");
  296.                 dat.hitType                         = dict.getInt("hitType");
  297.                 dat.effectOnTarget                  = dict.getString("effectOnTarget");
  298.                 dat.setCombatTarget                 = dict.getInt("setCombatTarget");
  299.                 dat.delayAttackEggTemplate          = dict.getString("delayAttackEggTemplate");
  300.                 dat.delayAttackParticle             = dict.getString("delayAttackParticle");
  301.                 dat.initialDelayAttackInterval      = dict.getFloat("initialDelayAttackInterval");
  302.                 dat.delayAttackInterval             = dict.getFloat("delayAttackInterval");
  303.                 dat.delayAttackEggPosition          = dict.getInt("delayAttackEggPosition");
  304.                 dat.delayAttackLoops                = dict.getInt("delayAttackLoops");
  305.                 dat.validEggTarget                  = dict.getInt("validEggTarget");
  306.                 dat.attackType                      = dict.getInt("attackType");
  307.                 dat.coneLength                      = dict.getFloat("coneLength");
  308.                 dat.coneWidth                       = dict.getFloat("coneWidth");
  309.                 dat.minRange                        = dict.getFloat("minRange");
  310.                 dat.maxRange                        = dict.getFloat("maxRange");
  311.                 dat.addedDamage                     = dict.getInt("addedDamage");
  312.                 dat.percentAddFromWeapon            = dict.getFloat("percentAddFromWeapon");
  313.                 dat.hateDamageModifier              = dict.getFloat("hateDamageModifier");
  314.                 dat.maxHate                         = dict.getInt("maxHate");
  315.                 dat.hateAdd                         = dict.getInt("hateAdd");
  316.                 dat.hateAddTime                     = dict.getInt("hateAddTime");
  317.                 dat.hateReduce                      = dict.getInt("hateReduce");
  318.                 dat.actionCost                      = dict.getFloat("actionCost");
  319.                 dat.vigorCost                       = dict.getFloat("vigorCost");
  320.                 dat.scaleByDefenderWeaponSpeed      = dict.getFloat("scaleByDefenderWeaponSpeed");
  321.                 dat.dotType                         = dict.getString("dotType");
  322.                 dat.dotIntensity                    = dict.getInt("dotIntensity");
  323.                 dat.dotDuration                     = dict.getInt("dotDuration");
  324.                 dat.buffNameTarget                  = dict.getString("buffNameTarget");
  325.                 dat.buffStrengthTarget              = dict.getFloat("buffStrengthTarget");
  326.                 dat.buffDurationTarget              = dict.getFloat("buffDurationTarget");
  327.                 dat.buffNameSelf                    = dict.getString("buffNameSelf");
  328.                 dat.buffStrengthSelf                = dict.getFloat("buffStrengthSelf");
  329.                 dat.buffDurationSelf                = dict.getFloat("buffDurationSelf");
  330.                 dat.canBePunishing                  = dict.getInt("canBePunishing");
  331.                 dat.increaseCritical                = dict.getFloat("increaseCritical");
  332.                 dat.increaseStrikethrough           = dict.getFloat("increaseStrikethrough");
  333.                 dat.reduceGlancing                  = dict.getFloat("reduceGlancing");
  334.                 dat.reduceParry                     = dict.getFloat("reduceParry");
  335.                 dat.reduceBlock                     = dict.getFloat("reduceBlock");
  336.                 dat.reduceDodge                     = dict.getFloat("reduceDodge");
  337.                 dat.overloadWeapon                  = dict.getInt("overloadWeapon");
  338.                 dat.overloadWeaponMinDamage         = dict.getInt("overloadWeaponMinDamage");
  339.                 dat.overloadWeaponMaxDamage         = dict.getInt("overloadWeaponMaxDamage");
  340.                 dat.overloadWeaponMinRange          = dict.getFloat("overloadWeaponMinRange"); // this is shared with the command's min range
  341.                 dat.overloadWeaponMaxRange          = dict.getFloat("overloadWeaponMaxRange"); // this is shared with the command's max range
  342.                 dat.overloadWeaponType              = dict.getInt("overloadWeaponType");
  343.                 dat.overloadWeaponCategory          = dict.getInt("overloadWeaponCategory");
  344.                 dat.overloadWeaponDamageType        = dict.getInt("overloadWeaponDamageType");
  345.                 dat.overloadWeaponElementalType     = dict.getInt("overloadWeaponElementalType");
  346.                 dat.overloadWeaponElementalValue    = dict.getInt("overloadWeaponElementalValue");
  347.                 dat.overloadWeaponAttackSpeed       = dict.getFloat("overloadWeaponAttackSpeed");
  348.                 dat.overloadWeaponDamageRadius      = dict.getFloat("overloadWeaponDamageRadius");
  349.                 dat.specialLine                     = dict.getString("specialLine");
  350.                 dat.animDefault                     = dict.getString("animDefault");
  351.                 dat.intRightFoot                    = dict.getInt("intRightFoot");
  352.                 dat.intLeftFoot                     = dict.getInt("intLeftFoot");
  353.                 dat.intRightHand                    = dict.getInt("intRightHand");
  354.                 dat.intLeftHand                     = dict.getInt("intLeftHand");
  355.                 dat.intWeapon                       = dict.getInt("intWeapon");
  356.                 dat.anim_unarmed                    = dict.getString("anim_unarmed");
  357.                 dat.anim_onehandmelee               = dict.getString("anim_onehandmelee");
  358.                 dat.anim_twohandmelee               = dict.getString("anim_twohandmelee");
  359.                 dat.anim_polearm                    = dict.getString("anim_polearm");
  360.                 dat.anim_pistol                     = dict.getString("anim_pistol");
  361.                 dat.anim_lightRifle                 = dict.getString("anim_lightRifle");
  362.                 dat.anim_carbine                    = dict.getString("anim_carbine");
  363.                 dat.anim_rifle                      = dict.getString("anim_rifle");
  364.                 dat.anim_heavyweapon                = dict.getString("anim_heavyweapon");
  365.                 dat.anim_thrown                     = dict.getString("anim_thrown");
  366.                 dat.anim_onehandlightsaber          = dict.getString("anim_onehandlightsaber");
  367.                 dat.anim_twohandlightsaber          = dict.getString("anim_twohandlightsaber");
  368.                 dat.anim_polearmlightsaber          = dict.getString("anim_polearmlightsaber");
  369.                 dat.validWeapon                     = dict.getInt("validWeapon");
  370.                 dat.invalidWeapon                   = dict.getInt("invalidWeapon");
  371.                 dat.cooldownGroup                   = dict.getString("cooldownGroup");
  372.                 dat.warmupTime                      = dict.getFloat("warmupTime");
  373.                 dat.executeTime                     = dict.getFloat("executeTime");
  374.                 dat.cooldownTime                    = dict.getFloat("cooldownTime");
  375.                 dat.attribute                       = dict.getInt("healAttrib");
  376.                 dat.bypassArmor                     = dict.getFloat("bypassArmor");
  377.                 dat.convertDamageToHealth           = dict.getFloat("convertDamageToHealth");
  378.                 dat.ignore_distance                 = dict.getInt("ignore_distance");
  379.                 dat.pvp_only                        = dict.getInt("pvp_only");
  380.                 dat.attack_rolls                    = dict.getInt("attack_rolls");
  381.                 dat.flatActionDamage                = dict.getInt("flatActionDamage");
  382.                 dat.performanceSpamStrId            = dict.getStringId("performanceSpamStrId");
  383.                 dat.hitSpam                         = dict.getInt("hitSpam");
  384.  
  385.                 return dat;
  386.         }
  387.  
  388.  
  389.         /*********************************************************************/
  390.  
  391.         /**
  392.          * Support classes
  393.          */
  394.  
  395.         public static class combat_data implements java.lang.Cloneable
  396.         {
  397.             public static combat_data clone(combat_data template)
  398.             {
  399.                 try
  400.                 {
  401.                     combat_data cd = (combat_data)template.clone();
  402.                     return cd;
  403.                 }
  404.                 catch(java.lang.CloneNotSupportedException exc)
  405.                 {
  406.                     return null;
  407.                 }
  408.             }
  409.  
  410.             public String   actionName                      = "";
  411.             public int      minInvisLevelRequired           = -1;
  412.             public int      commandType                     = 2; // special attack
  413.             public int      validTarget                     = 0; // standard
  414.             public int      hitType                         = -1; // ATTACK
  415.             public String   effectOnTarget                  = "";
  416.             public int      setCombatTarget                 = 1;
  417.             public String   delayAttackEggTemplate          = "object/tangible/space/content_infrastructure/generic_egg_small.iff";
  418.             public String   delayAttackParticle             = "";
  419.             public float    initialDelayAttackInterval      = -1.0f;
  420.             public float    delayAttackInterval             = 3.0f;
  421.             public int      delayAttackLoops                = 1;
  422.             public int      delayAttackEggPosition          = 2; // TargetedObject
  423.             public int      validEggTarget                  = 0; // standard
  424.             public int      attackType                      = 1; // single target
  425.             public float    coneLength                      = 0;
  426.             public float    coneWidth                       = 0;
  427.             public float    minRange                        = 0;
  428.             public float    maxRange                        = 0;
  429.             public int      addedDamage                     = 0;
  430.             public float    percentAddFromWeapon            = 1.0f;
  431.             public float    hateDamageModifier              = 1.0f;
  432.             public int      maxHate                         = 0;
  433.             public int      hateAdd                         = 0;
  434.             public int      hateAddTime                     = 0;
  435.             public int      hateReduce                      = 0;
  436.             public float    actionCost                      = 0;
  437.             public float    vigorCost                       = 0;
  438.             public float    scaleByDefenderWeaponSpeed              = 0;
  439.             public String   dotType                         = "";
  440.             public int      dotIntensity                    = 0;
  441.             public int      dotDuration                     = 0;
  442.             public String   buffNameTarget                  = "";
  443.             public float    buffStrengthTarget              = 0;
  444.             public float    buffDurationTarget              = 0;
  445.             public String   buffNameSelf                    = "";
  446.             public float    buffStrengthSelf                = 0;
  447.             public float    buffDurationSelf                = 0;
  448.             public int      canBePunishing                  = 1;
  449.             public float    increaseCritical                = 0.0f;
  450.             public float    increaseStrikethrough           = 0.0f;
  451.             public float    reduceGlancing                  = 0.0f;
  452.             public float    reduceParry                     = 0.0f;
  453.             public float    reduceBlock                     = 0.0f;
  454.             public float    reduceDodge                     = 0.0f;
  455.             public int      overloadWeapon                  = 0;
  456.             public int      overloadWeaponMinDamage         = 0;
  457.             public int      overloadWeaponMaxDamage         = 0;
  458.             public float    overloadWeaponMinRange          = 0;
  459.             public float    overloadWeaponMaxRange          = 0;
  460.             public int      overloadWeaponType              = 2;
  461.             public int      overloadWeaponCategory          = -1; // ranged
  462.             public int      overloadWeaponDamageType        = 1; // kinetic
  463.             public int      overloadWeaponElementalType     = 1; // kinetic?
  464.             public int      overloadWeaponElementalValue    = 0;
  465.             public float    overloadWeaponAttackSpeed       = 1.0f;
  466.             public float    overloadWeaponDamageRadius      = 0;
  467.             public String   specialLine                     = "";
  468.             public location targetLoc                       = new location();
  469.             public float    bypassArmor                     = 0;
  470.             public int      intLeftFoot                     = 0;
  471.             public int      intRightFoot                    = 0;
  472.             public int      intRightHand                    = 0;
  473.             public int      intLeftHand                     = 0;
  474.             public int      intWeapon                       = 0;
  475.             public String   animDefault                     = "";
  476.             public String   anim_unarmed                    = "";
  477.             public String   anim_onehandmelee               = "";
  478.             public String   anim_twohandmelee               = "";
  479.             public String   anim_polearm                    = "";
  480.             public String   anim_pistol                     = "";
  481.             public String   anim_lightRifle                 = "";
  482.             public String   anim_carbine                    = "";
  483.             public String   anim_rifle                      = "";
  484.             public String   anim_heavyweapon                = "";
  485.             public String   anim_thrown                     = "";
  486.             public String   anim_onehandlightsaber          = "";
  487.             public String   anim_twohandlightsaber          = "";
  488.             public String   anim_polearmlightsaber          = "";
  489.             public int      delayAttackLoopsDone            = 0;
  490.             public int      validWeapon                     = 30; // ALL=30
  491.             public int      invalidWeapon                   = 0;
  492.             public String   cooldownGroup                   = "";
  493.             public float    warmupTime                      = 0;
  494.             public float    executeTime                     = 0;
  495.             public float    cooldownTime                    = 0;
  496.             public int      attribute                       = 0;
  497.             public String   params                          = "";
  498.             public string_id performanceSpamStrId           = new string_id("", "");
  499.             public int      hitSpam                         = 0;
  500.             public float    convertDamageToHealth           = 0.0f;
  501.             public int      ignore_distance                 = 0;
  502.             public int      pvp_only                        = 0;
  503.             public int      attack_rolls                    = 1;
  504.             public int      flatActionDamage                = 0;
  505.     }
  506.  
  507.     public static class attack_roll_result
  508.     {
  509.         public int baseRoll = 0;
  510.         public int finalRoll = 0;
  511.     }
  512.  
  513.     public static class hit_result
  514.     {
  515.         public boolean success = false;
  516.         public int     baseRoll = 0;
  517.         public int     finalRoll = 0;
  518.         public float   attackVal = 0.0f;
  519.         public boolean canSee = true;
  520.         public int     hitLocation = 0;
  521.         public int     damage = 0;
  522.         public int     damageType = 0;      // base damage type, set to 0 to use the attacker's weapon's damage type
  523.         public int     rawDamage = 0;       // base amount of actual damage (not counting bleed or crit, does include blocked damage)
  524.         public int     elementalDamage = 0; // Amount of secondary damage done
  525.         public int     elementalDamageType = 0; // Type of elemental damage, set to 0 to use the attacker's weapon's damage type
  526.         public int     bleedDamage = 0;     // bleed damage amount
  527.         public int     critDamage = 0;      // critical damage bonus
  528.         public int     blockedDamage = 0;   // damage amount blocked by armor
  529.         public obj_id  blockingArmor = null;// id of the armor piece that blocked the damage
  530.         public int     bleedingChance = 0;
  531.         public boolean proc = false;
  532.         public boolean critical = false;    // does extra damage
  533.         public boolean strikethrough = false;// bypasses armor
  534.         public float strikethroughAmmount = 0.0f; // Ammount of armor to bypass
  535.         public boolean glancing = false;    // Damage reduction by skill comparison
  536.         public boolean dodge = false;       // Negates damage
  537.         public boolean parry = false;       // Negates melee damage
  538.         public boolean crushing = false;    // Damage increase by skill comparison
  539.         public boolean miss = false;        // Failed attack roll
  540.         public boolean evadeResult = false; // Chance to avoid AE damage
  541.         public float evadeAmmount = 0.0f;   // % of damage avoided
  542.         public boolean blockResult = false; // Chance to soak damage
  543.         public int block = 0;               // Ammount of damage mitigated on a block
  544.     }
  545.  
  546.     public static class combatant_data
  547.     {
  548.         public obj_id   id;                 // the combatant's id
  549.         public location pos;                // where the combatant is in local coordinates
  550.         public location worldPos;           // where the combatant is in world-space coordinates
  551.         public float    radius;             // the bounding-radius of the combatant
  552.         public boolean  isCreature;         // flag that the combatant is a creature
  553.         public int      posture;            // the combatant's posture (if it is a creature)
  554.         public int      locomotion;         // the combatant's locomotion (if it is a creature)
  555.         public int      scriptMod = 0;      // generic param that will be added to the combatant's roll
  556.     }
  557.  
  558.     public static class attacker_data extends combatant_data
  559.     {
  560.         public int weaponSkillMod;      // the skill mod for the weapon being used by the combatant
  561.         public int aims;                // number of aims the attacker is taking
  562.         public float critChance             = 0.0f;
  563.         public float pvpCrit                = 0.0f;
  564.         public float npcCrit                = 0.0f;
  565.         public float droidCrit              = 0.0f;
  566.         public float creatureCrit           = 0.0f;
  567.         public float hitChance              = 0.0f;
  568.         public float strikethroughChance    = 0.0f;
  569.         public float reduceParry            = 0.0f;
  570.         public float reduceBlock            = 0.0f;
  571.         public float reduceDodge            = 0.0f;
  572.         public float reduceGlancing         = 0.0f;
  573.         public float reduceEvade            = 0.0f;
  574.     }
  575.  
  576.     public static class defender_data extends combatant_data
  577.     {
  578.         public int combatSkeleton;          // combat skeleton id of the defender
  579.         public int[] hitLocationChances;    // chances to hit a particular area
  580.         public int cover;                   // the amount of cover the defender has
  581.         public float reduceCritical         = 0.0f;
  582.         public float increaseMiss           = 0.0f;
  583.         public float reduceStrikethrough    = 0.0f;
  584.         public float reducePunishing        = 0.0f;
  585.         public float glancingChance         = 0.0f;
  586.         public float parryChance            = 0.0f;
  587.         public float dodgeChance            = 0.0f;
  588.         public float evadeChance            = 0.0f;
  589.         public float blockChance            = 0.0f;
  590.     }
  591.  
  592.     public static class weapon_data
  593.     {
  594.         public obj_id      id;                  // weapon's network id
  595.         public string_id   weaponName = null;   // weapon's name
  596.         public int         minDamage;           // minimum damage done
  597.         public int         maxDamage;           // maximum damage done
  598.         public int         weaponType;          // weapon type (rifle, pistol, etc)
  599.         public int     weaponCategory;  // category
  600.         public int         attackType;          // attack type (melee, ranged, etc)
  601.         public int         damageType;          // base damage type (kinetic or energy)
  602.         public int         elementalType;       // bonus elemental damage type (acid, cold, etc.)
  603.         public int         elementalValue;      // bonus elemental damage amount
  604.         public float       attackSpeed;         // the weapon's intrisic firing rate
  605.         public float       woundChance;         // base % chance for a wound to occur on a successful attack
  606.         public int         accuracy;            // accuracy modifier for the weapon
  607.         public float       minRange;            // range where the min range mod is set
  608.         public float       maxRange;            // range past which the weapon cannot hit (always read from the template)
  609.         public float       damageRadius;        // damage radius for area-effect weapons
  610.         public int         attackCost;          // weapon special move cost
  611.         public int         hvyWeaponType;       // stores an integer (as listed in heavyweapons.scriptlib::TYPE_*) denoting which heavy weapon
  612.         public float       hvyWeaponAeDamageMod;// a value determining the amount of damage AOE targets take based on how much damage the combat target took
  613.         public boolean     isDisabled;          // flag that the weapon is disabled due to damage
  614.     }
  615.  
  616.     public static class effect_data
  617.     {
  618.         public int     posture = base_class.POSTURE_NONE;    // End posture after attack
  619.         public int[]   states;                               // Array of states to be applied with attack
  620.         public float[] durations;                            // Array of duration of states, must match states length
  621.         public int     stateChance = 0;                      // Chance for each state to be applied
  622.     }
  623.  
  624.     // Buff data
  625.  
  626.     public static buff_data getBuffData(int buffNameCrc)
  627.     {
  628.         if(m_BuffDataCache.containsKey("" + buffNameCrc))
  629.         {
  630.             return buff_data.clone((buff_data)m_BuffDataCache.get("" + buffNameCrc));
  631.         }
  632.  
  633.         buff_data dat = loadBuffData(buffNameCrc);
  634.  
  635.         if(dat != null)
  636.         {
  637.             m_BuffDataCache.put("" + buffNameCrc, dat);
  638.         }
  639.         else
  640.         {
  641.             return null;
  642.         }
  643.  
  644.         return buff_data.clone(dat);
  645.     }
  646.  
  647.     private static buff_data loadBuffData(int buffNameCrc)
  648.     {
  649.         buff_data dat = new buff_data();
  650.  
  651.         int row = base_class.dataTableSearchColumnForInt(buffNameCrc, "NAME", "datatables/buff/buff.iff");
  652.  
  653.         if(row == -1)
  654.         {
  655.             return null;
  656.         }
  657.  
  658.         dictionary d = base_class.dataTableGetRow("datatables/buff/buff.iff", row);
  659.  
  660.         if(d == null)
  661.         {
  662.             return null;
  663.         }
  664.  
  665.         dat.buffName                        = d.getString("NAME");
  666.         dat.buffGroup1                      = d.getString("GROUP1");
  667.         dat.buffGroup1Crc                   = base_class.getStringCrc(dat.buffGroup1);
  668.         dat.buffGroup2                      = d.getString("GROUP2");
  669.         dat.buffGroup2Crc                   = base_class.getStringCrc(dat.buffGroup2);
  670.         dat.blockGroup                      = d.getString("BLOCK");
  671.         dat.blockGroupCrc                   = base_class.getStringCrc(dat.blockGroup);
  672.         dat.priority                        = d.getInt("PRIORITY");
  673.         dat.icon                            = d.getString("ICON");
  674.         dat.duration                        = d.getFloat("DURATION");
  675.         dat.effect1Param                    = d.getString("EFFECT1_PARAM");
  676.         dat.effect1Value                    = d.getFloat("EFFECT1_VALUE");
  677.         dat.effect2Param                    = d.getString("EFFECT2_PARAM");
  678.         dat.effect2Value                    = d.getFloat("EFFECT2_VALUE");
  679.         dat.effect3Param                    = d.getString("EFFECT3_PARAM");
  680.         dat.effect3Value                    = d.getFloat("EFFECT3_VALUE");
  681.         dat.effect4Param                    = d.getString("EFFECT4_PARAM");
  682.         dat.effect4Value                    = d.getFloat("EFFECT4_VALUE");
  683.         dat.effect5Param                    = d.getString("EFFECT5_PARAM");
  684.         dat.effect5Value                    = d.getFloat("EFFECT5_VALUE");
  685.         dat.buffState                       = d.getInt("STATE");
  686.         dat.callback                        = d.getString("CALLBACK");
  687.         dat.particle                        = d.getString("PARTICLE");
  688.         dat.particleHardpoint               = d.getString("PARTICLE_HARDPOINT");
  689.         dat.visible                         = d.getInt("VISIBLE");
  690.         dat.debuff                          = d.getInt("DEBUFF");
  691.         dat.stanceParticle                  = d.getString("STANCE_PARTICLE");
  692.         dat.dispellPlayer                   = d.getInt("DISPELL_PLAYER");
  693.         dat.removeOnDeath                   = d.getInt("REMOVE_ON_DEATH");
  694.         dat.playerRemovable                 = d.getInt("PLAYER_REMOVABLE");
  695.         dat.isCelestial                     = d.getInt("IS_CELESTIAL");
  696.         dat.maxStacks                       = d.getInt("MAX_STACKS");
  697.         dat.isPersistant                    = d.getInt("IS_PERSISTENT");
  698.         dat.displayOrder                    = d.getInt("DISPLAY_ORDER");
  699.         dat.removeOnRespec                  = d.getInt("REMOVE_ON_RESPEC");
  700.         dat.aiRemoveOnCombatEnd             = d.getInt("AI_REMOVE_ON_COMBAT_END");
  701.         dat.decayOnPvpDeath                 = d.getInt("DECAY_ON_PVP_DEATH");
  702.  
  703.         return dat;
  704.     }
  705.  
  706.     public static class buff_data implements java.lang.Cloneable
  707.     {
  708.         public static buff_data clone(buff_data template)
  709.         {
  710.             try
  711.             {
  712.                 buff_data cd = (buff_data)template.clone();
  713.                 return cd;
  714.             }
  715.             catch(java.lang.CloneNotSupportedException exc)
  716.             {
  717.                 return null;
  718.             }
  719.         }
  720.  
  721.         public String   buffName                        = "";
  722.         public String   buffGroup1                      = "";
  723.         public int      buffGroup1Crc                   = 0;
  724.         public String   buffGroup2                      = "";
  725.         public int      buffGroup2Crc                   = 0;
  726.         public String   blockGroup                      = "";
  727.         public int      blockGroupCrc                   = 0;
  728.         public int      priority                        = 0;
  729.         public String   icon                            = "";
  730.         public float    duration                        = 0.0f;
  731.         public String   effect1Param                    = "";
  732.         public float    effect1Value                    = 0.0f;
  733.         public String   effect2Param                    = "";
  734.         public float    effect2Value                    = 0.0f;
  735.         public String   effect3Param                    = "";
  736.         public float    effect3Value                    = 0.0f;
  737.         public String   effect4Param                    = "";
  738.         public float    effect4Value                    = 0.0f;
  739.         public String   effect5Param                    = "";
  740.         public float    effect5Value                    = 0.0f;
  741.         public int      buffState                       = 0;
  742.         public String   callback                        = "";
  743.         public String   particle                        = "";
  744.         public String   particleHardpoint               = "";
  745.         public int      visible                         = 1;
  746.         public int      debuff                          = 0;
  747.         public String   stanceParticle                  = "";
  748.         public int      dispellPlayer                   = 1;
  749.         public int      removeOnDeath                   = 1;
  750.         public int      playerRemovable                 = 1;
  751.         public int      isCelestial                     = 0;
  752.         public int      maxStacks                       = 1;
  753.         public int      isPersistant                    = 1;
  754.         public int      displayOrder                    = 0;
  755.         public int      removeOnRespec                  = 1;
  756.         public int      aiRemoveOnCombatEnd             = 1;
  757.         public int      decayOnPvpDeath                 = 1;
  758.     }
  759.  
  760.  
  761.     /*********************************************************************/
  762.  
  763.     /**
  764.      * Main combat functions.
  765.      */
  766.  
  767.     /**
  768.      * Determines if a given attacker hits his opponent.
  769.      *
  770.      * @param attacker      the attacker's data
  771.      * @param defender      the defender's data
  772.      * @param weapon        the attacker's weapon's data
  773.      *
  774.      * @return result of attack
  775.      */
  776.     public static hit_result calculateHit(attacker_data attacker, defender_data defender, weapon_data weapon)
  777.     {
  778.         hit_result result = new hit_result();
  779.  
  780.         // determine the attacker's and defender's rolls
  781.         attack_roll_result attackRoll = getAttackRoll(attacker, defender, weapon);
  782.         if (attackRoll.baseRoll == OUT_OF_RANGE)
  783.         {
  784. //          System.err.println("OUT OF RANGE");
  785.             return result;
  786.         }
  787.  
  788.         int defenseRoll = getDefenseRoll(attacker, defender, weapon);
  789.  
  790.         // determine if the attack was successful
  791.         float attackVal = attackRoll.baseRoll - defenseRoll;
  792.         result.attackVal = attackVal;
  793.         attackVal /= combat_consts.toHitScale;
  794.  
  795.         float stepDir = 0.0f;
  796.         if (attackVal > stepDir) stepDir = 1.0f;
  797.         else if (attackVal < stepDir) stepDir = -1.0f;
  798.  
  799.         float toHitChance = combat_consts.baseToHit;
  800.         int maxStep = (int)Math.ceil((combat_consts.baseToHit - combat_consts.minToHit)/combat_consts.toHitStep);
  801.         for (int i = 1; i < maxStep; i++)
  802.         {
  803.             if ((attackVal * stepDir) > i)
  804.             {
  805.                 toHitChance += stepDir * combat_consts.toHitStep;
  806.                 attackVal -= stepDir * i;
  807.             }
  808.             else
  809.             {
  810.                 toHitChance += (attackVal/i) * combat_consts.toHitStep;
  811.                 break;
  812.             }
  813.         }
  814.  
  815.         if (toHitChance > combat_consts.maxToHit) toHitChance = combat_consts.maxToHit;
  816.         if (toHitChance < combat_consts.minToHit) toHitChance = combat_consts.minToHit;
  817.  
  818.         if (random.rand(1.0f, 100.0f) < toHitChance)
  819.         {
  820.             // Shouldn't need LOS check here as checks are done at defender list creation
  821.             //// verify that the attacker can see the defender
  822.             //if (!base_class.canSee(attacker.id, defender.id))
  823.             //{
  824.             //  result.canSee = false;
  825.             //}
  826.             //else
  827.             {
  828.                 result.success = true;
  829.                 // determine hit location and base damage
  830.                 result.hitLocation = getHitLocation(defender);
  831.                 result.damage = getDamage(weapon, result.attackVal);
  832.             }
  833.         }
  834.  
  835.         result.baseRoll = attackRoll.baseRoll;
  836.         result.finalRoll = attackRoll.finalRoll;
  837.         return result;
  838.     }   // calculateHit()
  839.  
  840.     /*********************************************************************/
  841.  
  842.     /**
  843.      * Support functions.
  844.      */
  845.  
  846.     /**
  847.      * Determines the attack roll.
  848.      *
  849.      * @param attacker      the attacker's data
  850.      * @param defender      the defender's data
  851.      * @param weapon        the attacker's weapon's data
  852.      *
  853.      * @return the attack roll, along with the unmodified base attack roll
  854.      */
  855.     public static attack_roll_result getAttackRoll(attacker_data attacker, defender_data defender, weapon_data weapon)
  856.     {
  857.         if (attacker == null || defender == null || weapon == null)
  858.         {
  859.             System.err.println("WARNING: null data passed to getAttackRoll: " + attacker + "; " + defender + "; " + weapon);
  860.             return null;
  861.         }
  862.         if (attacker.id == null || defender.id == null || weapon.id == null)
  863.         {
  864.             System.err.println("WARNING: null id passed to getAttackRoll: " + attacker.id + "; " + defender.id + "; " + weapon.id);
  865.             return null;
  866.         }
  867.         if (attacker.pos == null || attacker.worldPos == null || defender.pos == null || defender.worldPos == null)
  868.         {
  869.             System.err.println("WARNING: null pos passed to getAttackRoll: " + attacker.pos + "; " + attacker.worldPos +
  870.                 "; " + defender.pos + "; " + defender.worldPos);
  871.             return null;
  872.         }
  873.  
  874.         attack_roll_result result = new attack_roll_result();
  875.  
  876.         int skillMod = 0;
  877.         int aimsMod = 0;
  878.         int attitudeMod = 0;
  879.         int locomotionMod = 0;
  880.  
  881.         // adjust for distance between attacker and defender, and auto fail if the
  882.         // attacker is out of range
  883.         float dist = attacker.worldPos.distance(defender.worldPos) - (attacker.radius + defender.radius);
  884.         // check for object interpenetration
  885.         if ( dist < 0 )
  886.             dist = 0;
  887.         // TODO: COMBAT_UPGRADE: Add Accuracy
  888. //      System.out.println("***Java combat_engine: attacker_rad = " + attacker.radius + ", defender_rad = " + defender.radius);
  889. //      System.out.println("***Java combat_engine: base dist = " + attacker.worldPos.distance(defender.worldPos) + ", adjusted dist = " + dist + ", rangeMod = " + rangeMod);
  890.  
  891.         // adjust for weapon skills
  892.         skillMod = attacker.weaponSkillMod;
  893.  
  894.         // adjust for aims
  895.         if (attacker.aims > 0) // modified by dan to work with new aim skill mods
  896.         {
  897.             if(attacker.aims>3)
  898.             {
  899.                 attacker.aims=3;
  900.             }
  901.             String strAimMod = getWeaponStringType(weapon.weaponType);
  902.             strAimMod.concat("_aim");
  903.             int intBaseAimMod = base_class.getSkillStatisticModifier(attacker.id, "aim");
  904.             aimsMod = attacker.aims * (base_class.getSkillStatisticModifier(attacker.id, strAimMod)+intBaseAimMod);
  905.  
  906.         /*
  907.             if (aimIndex < combat_consts.aimAttackMods.length)
  908.                 aimsMod = combat_consts.aimAttackMods[attacker.aims - 1];
  909.             else
  910.                 System.err.println("ERROR: Java combat_engine getAttackRoll - too many aims (" + attacker.aims + ")");
  911.         */ // Potentiall depracated functions above. we're using  straight multiply now
  912.         }
  913.  
  914.         // adjust for attacker locomotion
  915.         if (attacker.isCreature)
  916.         {
  917.             if ( weapon.attackType >= 0 && weapon.attackType < combat_consts.locomotionAttackMod.length )
  918.             {
  919.                 if (attacker.locomotion >= 0 && attacker.locomotion < combat_consts.locomotionAttackMod[weapon.attackType].length)
  920.                 {
  921.                     locomotionMod = combat_consts.locomotionAttackMod[weapon.attackType][attacker.locomotion];
  922.                     // adjust locomotion mod for weapon type
  923.                     if (weapon.weaponType >= 0 && weapon.weaponType < combat_consts.weaponTypeAttackLocomotionMultipliers.length)
  924.                     {
  925.                         locomotionMod = (int)(locomotionMod * combat_consts.weaponTypeAttackLocomotionMultipliers[weapon.weaponType]);
  926.                         locomotionMod = locomotionMod + getPostureModForWeapon(attacker.id, attacker.posture,weapon.weaponType);
  927.                     }
  928.  
  929.  
  930.                 }
  931.                 else
  932.                     System.err.println("ERROR: Java combat_engine getAttackRoll - invalid locomotion " + attacker.locomotion);
  933.             }
  934.             else
  935.                 System.err.println("ERROR: Java combat_engine getAttackRoll - invalid weapon attack type " + weapon.attackType);
  936.         }
  937.         if(isLocomotionMoving(attacker.locomotion)) // added by dan to support new locomotion skill modss
  938.         {
  939.             String strLocomotionAttackMod = getWeaponStringType(weapon.weaponType);
  940.             strLocomotionAttackMod.concat("_hit_while_moving");
  941.             locomotionMod = locomotionMod - base_class.getSkillStatisticModifier(attacker.id, strLocomotionAttackMod); // bonus to attacker if they have the skill against moving targets
  942.             if(locomotionMod<0)
  943.             {
  944.                 locomotionMod = 0;
  945.             }
  946.         }
  947.  
  948.         // roll the attack number
  949.         //result.baseRoll = random.rand(1, 250);
  950.         //result.finalRoll = result.baseRoll + skillMod + aimsMod + attitudeMod + locomotionMod + rangeMod + attacker.scriptMod;
  951.         result.baseRoll = skillMod + attacker.scriptMod;
  952.         result.finalRoll = result.baseRoll + aimsMod + attitudeMod + locomotionMod;
  953.  
  954.         return result;
  955.     }   // getAttackRoll()
  956.  
  957.     /**
  958.      * Determines the defense roll.
  959.      *
  960.      * @param attacker      the attacker's data
  961.      * @param defender      the defender's data
  962.      * @param weapon        the attacker's weapon's data
  963.      *
  964.      * @return the defense roll
  965.      */
  966.     public static int getDefenseRoll(attacker_data attacker, defender_data defender, weapon_data weapon)
  967.     {
  968.         //int baseRoll = combat_consts.toHitNumber;
  969.         int locomotionMod = 0;
  970.         int coverMod = 0;
  971.  
  972.         // adjust for defender locomotion
  973.         if (defender.isCreature)
  974.         {
  975.             if ( weapon.attackType >= 0 && weapon.attackType < combat_consts.locomotionDefenseMod.length )
  976.             {
  977.                 if (defender.locomotion >= 0 && defender.locomotion < combat_consts.locomotionDefenseMod[weapon.attackType].length)
  978.                     locomotionMod = combat_consts.locomotionDefenseMod[weapon.attackType][defender.locomotion];
  979.                 else
  980.                     System.err.println("ERROR: Java combat_engine getDefenseRoll - invalid locomotion " + defender.locomotion);
  981.             }
  982.             else
  983.                 System.err.println("ERROR: Java combat_engine getDefenseRoll - invalid weapon attack type " + weapon.attackType);
  984.         }
  985.  
  986.         // adjust for defender cover
  987.         coverMod = defender.cover;
  988.  
  989.         //int baseRoll = random.rand(25, 175);
  990.         //int defenseRoll = baseRoll + locomotionMod + coverMod + defender.scriptMod;
  991.         int baseRoll = defender.scriptMod;
  992.         int defenseRoll = baseRoll + locomotionMod + coverMod;
  993.  
  994.         return baseRoll;
  995.     }   // getDefenseRoll()
  996.  
  997.     /**
  998.      * Determines where a defender got hit.
  999.      *
  1000.      * @param defender      the object that was being attacked
  1001.      *
  1002.      * @return the hit location
  1003.      */
  1004.     public static int getHitLocation(defender_data defender)
  1005.     {
  1006.         if (defender.combatSkeleton == 0 || defender.hitLocationChances == null)
  1007.             return 0;
  1008.  
  1009.         int randNum = random.rand(1, 100);
  1010.  
  1011.         for (int i = 0; i < defender.hitLocationChances.length; ++i)
  1012.         {
  1013.             if (randNum <= defender.hitLocationChances[i])
  1014.                 return i;
  1015.             randNum -= defender.hitLocationChances[i];
  1016.         }
  1017.         // we should never get here
  1018.         System.err.println("WARNING Java combat_engine.getHitLocation, defender hit location chances != 100");
  1019.         return 0;
  1020.     }   // getHitLocation()
  1021.  
  1022.     /**
  1023.      * Determines the base amount of damage a weapon does.
  1024.      *
  1025.      * @param weapon        the weapon
  1026.      *
  1027.      * @return the amount of damage
  1028.      */
  1029.     public static int getDamage(weapon_data weapon)
  1030.     {
  1031.         return getDamage(weapon, 0);
  1032.     }
  1033.  
  1034.     public static int getDamage(weapon_data weapon, float attackVal)
  1035.     {
  1036.         int damage = 0;
  1037.         switch ( weapon.damageType )
  1038.         {
  1039.             case base_class.DAMAGE_KINETIC :
  1040.             case base_class.DAMAGE_ENERGY :
  1041.             case base_class.DAMAGE_BLAST :
  1042.             case base_class.DAMAGE_STUN :
  1043.             case base_class.DAMAGE_RESTRAINT :
  1044.             case base_class.DAMAGE_ELEMENTAL_HEAT :
  1045.             case base_class.DAMAGE_ELEMENTAL_COLD :
  1046.             case base_class.DAMAGE_ELEMENTAL_ACID :
  1047.             case base_class.DAMAGE_ELEMENTAL_ELECTRICAL :
  1048.             case base_class.DAMAGE_ENVIRONMENTAL_HEAT :
  1049.             case base_class.DAMAGE_ENVIRONMENTAL_COLD :
  1050.             case base_class.DAMAGE_ENVIRONMENTAL_ACID :
  1051.             case base_class.DAMAGE_ENVIRONMENTAL_ELECTRICAL :
  1052.                 {
  1053.                     float dist = 0.5f + (attackVal / combat_consts.damageScale);
  1054.                     //damage = random.distributedRand(weapon.minDamage, weapon.maxDamage, dist);
  1055.                     // TEMP HACK - Test with fixed damage results based on attackval
  1056.                     if (dist < 0f) dist = 0f;
  1057.                     if (dist > 1f) dist = 1f;
  1058.                     damage = (int)(weapon.minDamage + ((weapon.maxDamage - weapon.minDamage) * dist));
  1059.                 }
  1060.                 break;
  1061.             default:
  1062.                 System.err.println("ERROR Java combat_engine.getDamage weapon has unknown damage type " + weapon.damageType);
  1063.                 break;
  1064.         }
  1065.         return damage;
  1066.     }   // getDamage()
  1067.  
  1068.     private static String getWeaponStringType(int intWeaponType)
  1069.     {// written by Dan R. Do not blame steve :)
  1070.         switch(intWeaponType)
  1071.         {
  1072.             case base_class.WEAPON_TYPE_RIFLE : return "rifle";
  1073.             case base_class.WEAPON_TYPE_LIGHT_RIFLE : return "carbine";
  1074.             case base_class.WEAPON_TYPE_PISTOL : return "pistol";
  1075.             case base_class.WEAPON_TYPE_HEAVY : return "heavyWeapon";
  1076.             case base_class.WEAPON_TYPE_1HAND_MELEE : return "1handMelee";
  1077.             case base_class.WEAPON_TYPE_2HAND_MELEE: return "2handeMelee";
  1078.             case base_class.WEAPON_TYPE_UNARMED: return "unarmed";
  1079.             case base_class.WEAPON_TYPE_POLEARM: return "polearm";
  1080.             case base_class.WEAPON_TYPE_THROWN: return "thrown";
  1081.         }
  1082.         return "";
  1083.     }
  1084.     private static boolean isLocomotionMoving(int intLocomotion)
  1085.     {   // written by Dan R.
  1086.         switch(intLocomotion)
  1087.         {
  1088.             case base_class.LOCOMOTION_SNEAKING     : return true;
  1089.             case base_class.LOCOMOTION_WALKING          : return true;
  1090.             case base_class.LOCOMOTION_RUNNING          : return true;
  1091.             case base_class.LOCOMOTION_CRAWLING     : return true;
  1092.             case base_class.LOCOMOTION_CLIMBING     : return true;
  1093.             case base_class.LOCOMOTION_FLYING       : return true;
  1094.             case base_class.LOCOMOTION_DRIVING_VEHICLE  : return true;
  1095.             case base_class.LOCOMOTION_RIDING_CREATURE  : return true;
  1096.         }
  1097.         return false;
  1098.     }
  1099.     private static int getPostureModForWeapon(obj_id objPlayer, int intPosture, int intWeaponType)
  1100.     {// dans function again, don't blame steve.
  1101.         switch (intPosture)
  1102.         {
  1103.             case base_class.POSTURE_CROUCHED: return base_class.getSkillStatisticModifier(objPlayer, getWeaponStringType(intWeaponType)+"_kneeling");
  1104.             case base_class.POSTURE_PRONE: return base_class.getSkillStatisticModifier(objPlayer, getWeaponStringType(intWeaponType)+"_prone");
  1105.             case base_class.POSTURE_UPRIGHT: return base_class.getSkillStatisticModifier(objPlayer, getWeaponStringType(intWeaponType)+"_standing");
  1106.  
  1107.         }
  1108.         return 0;
  1109.     }
  1110. }   // class combat_engine
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement