From 54db22252e106580a856b44e9ee8315bde5643bd Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Sun, 23 Oct 2016 04:16:40 +0200 Subject: [PATCH] Added support for single target damage abilities --- scripts/commands/combat/meleeHit.js | 7 -- .../commands/combat/rangedShotlightRifle.js | 7 -- scripts/commands/combat/rangedShotpistol.js | 7 -- scripts/commands/combat/rangedShotrifle.js | 7 -- src/resources/combat/AttackInfoLight.java | 50 -------------- src/resources/commands/CombatCommand.java | 9 +++ src/services/combat/CombatManager.java | 65 ++++++++++--------- src/services/commands/CommandService.java | 2 + 8 files changed, 44 insertions(+), 110 deletions(-) delete mode 100644 scripts/commands/combat/meleeHit.js delete mode 100644 scripts/commands/combat/rangedShotlightRifle.js delete mode 100644 scripts/commands/combat/rangedShotpistol.js delete mode 100644 scripts/commands/combat/rangedShotrifle.js delete mode 100644 src/resources/combat/AttackInfoLight.java diff --git a/scripts/commands/combat/meleeHit.js b/scripts/commands/combat/meleeHit.js deleted file mode 100644 index cc849b9e..00000000 --- a/scripts/commands/combat/meleeHit.js +++ /dev/null @@ -1,7 +0,0 @@ -function canPerform(source, target, command) { - return (Java.type("resources.combat.CombatStatus")).SUCCESS; -} - -function doCombat(source, target, command) { - return 0; -} diff --git a/scripts/commands/combat/rangedShotlightRifle.js b/scripts/commands/combat/rangedShotlightRifle.js deleted file mode 100644 index cc849b9e..00000000 --- a/scripts/commands/combat/rangedShotlightRifle.js +++ /dev/null @@ -1,7 +0,0 @@ -function canPerform(source, target, command) { - return (Java.type("resources.combat.CombatStatus")).SUCCESS; -} - -function doCombat(source, target, command) { - return 0; -} diff --git a/scripts/commands/combat/rangedShotpistol.js b/scripts/commands/combat/rangedShotpistol.js deleted file mode 100644 index cc849b9e..00000000 --- a/scripts/commands/combat/rangedShotpistol.js +++ /dev/null @@ -1,7 +0,0 @@ -function canPerform(source, target, command) { - return (Java.type("resources.combat.CombatStatus")).SUCCESS; -} - -function doCombat(source, target, command) { - return 0; -} diff --git a/scripts/commands/combat/rangedShotrifle.js b/scripts/commands/combat/rangedShotrifle.js deleted file mode 100644 index cc849b9e..00000000 --- a/scripts/commands/combat/rangedShotrifle.js +++ /dev/null @@ -1,7 +0,0 @@ -function canPerform(source, target, command) { - return (Java.type("resources.combat.CombatStatus")).SUCCESS; -} - -function doCombat(source, target, command) { - return 0; -} diff --git a/src/resources/combat/AttackInfoLight.java b/src/resources/combat/AttackInfoLight.java deleted file mode 100644 index 7e71569e..00000000 --- a/src/resources/combat/AttackInfoLight.java +++ /dev/null @@ -1,50 +0,0 @@ -/************************************************************************************ - * Copyright (c) 2015 /// Project SWG /// www.projectswg.com * - * * - * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on * - * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. * - * Our goal is to create an emulator which will provide a server for players to * - * continue playing a game similar to the one they used to play. We are basing * - * it on the final publish of the game prior to end-game events. * - * * - * This file is part of Holocore. * - * * - * -------------------------------------------------------------------------------- * - * * - * Holocore is free software: you can redistribute it and/or modify * - * it under the terms of the GNU Affero General Public License as * - * published by the Free Software Foundation, either version 3 of the * - * License, or (at your option) any later version. * - * * - * Holocore is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Affero General Public License for more details. * - * * - * You should have received a copy of the GNU Affero General Public License * - * along with Holocore. If not, see . * - * * - ***********************************************************************************/ -package resources.combat; - -public class AttackInfoLight { - - private int damage; - - public AttackInfoLight() { - this(0); - } - - public AttackInfoLight(int damage) { - setDamage(damage); - } - - public int getDamage() { - return damage; - } - - public void setDamage(int damage) { - this.damage = damage; - } - -} diff --git a/src/resources/commands/CombatCommand.java b/src/resources/commands/CombatCommand.java index 28e9eebc..9c69eba2 100644 --- a/src/resources/commands/CombatCommand.java +++ b/src/resources/commands/CombatCommand.java @@ -49,6 +49,7 @@ public class CombatCommand extends Command { private boolean pvpOnly; private int attackRolls; private float percentAddFromWeapon; + private int addedDamage; public CombatCommand(String name) { super(name); @@ -155,5 +156,13 @@ public class CombatCommand extends Command { public void setPercentAddFromWeapon(float percentAddFromWeapon) { this.percentAddFromWeapon = percentAddFromWeapon; } + + public int getAddedDamage() { + return addedDamage; + } + + public void setAddedDamage(int addedDamage) { + this.addedDamage = addedDamage; + } } diff --git a/src/services/combat/CombatManager.java b/src/services/combat/CombatManager.java index 29b73ae4..4cd68189 100644 --- a/src/services/combat/CombatManager.java +++ b/src/services/combat/CombatManager.java @@ -50,7 +50,6 @@ import java.util.concurrent.Future; import resources.Posture; import resources.PvpFaction; import resources.PvpFlag; -import resources.combat.AttackInfoLight; import resources.combat.AttackType; import resources.combat.CombatStatus; import resources.combat.HitLocation; @@ -217,22 +216,12 @@ public class CombatManager extends Manager { CombatStatus status = canPerform(cci.getSource(), cci.getTarget(), c); if (!handleStatus(cci.getSource(), status)) return; - Object res = Scripts.invoke("commands/combat/"+c.getName(), "doCombat", cci.getSource(), cci.getTarget(), c); - if (res == null) { - handleStatus(cci.getSource(), CombatStatus.UNKNOWN); - return; - } + updateCombatList(cci.getSource()); if (cci.getTarget() instanceof CreatureObject) updateCombatList((CreatureObject) cci.getTarget()); - if (res instanceof Number) - doCombat(cci.getSource(), cci.getTarget(), new AttackInfoLight(((Number) res).intValue()), c); - else if (res instanceof AttackInfoLight) - doCombat(cci.getSource(), cci.getTarget(), (AttackInfoLight) res, c); - else { - Log.w(this, "Unknown return from combat script: " + res); - return; - } + + doCombat(cci.getSource(), cci.getTarget(), c); } private void updateCombatList(CreatureObject creature) { @@ -249,7 +238,7 @@ public class CombatManager extends Manager { combat.updateLastCombat(); } - private void doCombat(CreatureObject source, SWGObject target, AttackInfoLight info, CombatCommand command) { + private void doCombat(CreatureObject source, SWGObject target, CombatCommand command) { CombatAction action = new CombatAction(source.getObjectId()); String anim = command.getRandomAnimation(source.getEquippedWeapon().getType()); action.setActionCrc(CRC.getCrc(anim)); @@ -258,15 +247,25 @@ public class CombatManager extends Manager { action.setCommandCrc(command.getCrc()); action.setTrail(TrailLocation.WEAPON); action.setUseLocation(false); - if (target instanceof CreatureObject) { - if (command.getAttackType() == AttackType.SINGLE_TARGET) - doCombatSingle(source, (CreatureObject) target, info, command); - action.addDefender((CreatureObject) target, true, (byte) 0, HitLocation.HIT_LOCATION_BODY, (short) info.getDamage()); + + for(int i = 0; i < command.getAttackRolls(); i++) { + int damage = 0; + + damage += calculateWeaponDamage(source, command); + damage += command.getAddedDamage(); + addSelfBuff(source, command); + + if (target instanceof CreatureObject) { + if (command.getAttackType() == AttackType.SINGLE_TARGET) + doCombatSingle(source, (CreatureObject) target, damage, command); + action.addDefender((CreatureObject) target, true, (byte) 0, HitLocation.HIT_LOCATION_BODY, (short) damage); + } } + source.sendObserversAndSelf(action); } - private void doCombatSingle(CreatureObject source, CreatureObject target, AttackInfoLight info, CombatCommand command) { + private void doCombatSingle(CreatureObject source, CreatureObject target, int damage, CombatCommand command) { if (!source.isInCombat()) enterCombat(source); if (!target.isInCombat()) @@ -274,12 +273,20 @@ public class CombatManager extends Manager { target.addDefender(source); source.addDefender(target); - addWeaponDamage(source, command, info); + addTargetBuff(source, command); - if (target.getHealth() <= info.getDamage()) + if (target.getHealth() <= damage) doCreatureDeath(target, source); else - target.modifyHealth(-info.getDamage()); + target.modifyHealth(-damage); + } + + private void addTargetBuff(CreatureObject target, CombatCommand command) { + + } + + private void addSelfBuff(CreatureObject creature, CombatCommand command) { + } private void enterCombat(CreatureObject creature) { @@ -491,10 +498,7 @@ public class CombatManager extends Manager { } if (status != CombatStatus.SUCCESS) return status; - status = Scripts.invoke("commands/combat/"+c.getName(), "canPerform", source, target, c); - if (status == null) { - return CombatStatus.UNKNOWN; - } + return status; } @@ -512,15 +516,12 @@ public class CombatManager extends Manager { return CombatStatus.SUCCESS; } - private void addWeaponDamage(CreatureObject source, CombatCommand command, AttackInfoLight info) { - int abilityDamage = info.getDamage(); + private int calculateWeaponDamage(CreatureObject source, CombatCommand command) { WeaponObject weapon = source.getEquippedWeapon(); int minDamage = weapon.getMinDamage(); int weaponDamage = random.nextInt((weapon.getMaxDamage() - minDamage) + 1) + minDamage; - weaponDamage *= command.getPercentAddFromWeapon(); - - info.setDamage(abilityDamage + weaponDamage); + return (int) (weaponDamage * command.getPercentAddFromWeapon()); } private void showFlyText(TangibleObject obj, String text, Scale scale, Color c, ShowFlyText.Flag ... flags) { diff --git a/src/services/commands/CommandService.java b/src/services/commands/CommandService.java index ef7a20be..33249d41 100644 --- a/src/services/commands/CommandService.java +++ b/src/services/commands/CommandService.java @@ -416,6 +416,7 @@ public class CommandService extends Service { int attackRolls = combatCommands.getColumnFromName("attack_rolls"); int animDefault = combatCommands.getColumnFromName("animDefault"); int percentAddFromWeapon = combatCommands.getColumnFromName("percentAddFromWeapon"); + int addedDamage = combatCommands.getColumnFromName("addedDamage"); // animDefault anim_unarmed anim_onehandmelee anim_twohandmelee anim_polearm // anim_pistol anim_lightRifle anim_carbine anim_rifle anim_heavyweapon // anim_thrown anim_onehandlightsaber anim_twohandlightsaber anim_polearmlightsaber @@ -438,6 +439,7 @@ public class CommandService extends Service { cc.setAttackRolls((int) cmdRow[attackRolls]); cc.setDefaultAnimation(getAnimationList((String) cmdRow[animDefault])); cc.setPercentAddFromWeapon((float) cmdRow[percentAddFromWeapon]); + cc.setAddedDamage((int) cmdRow[addedDamage]); cc.setAnimations(WeaponType.UNARMED, getAnimationList((String) cmdRow[animDefault+1])); cc.setAnimations(WeaponType.ONE_HANDED_MELEE, getAnimationList((String) cmdRow[animDefault+2])); cc.setAnimations(WeaponType.TWO_HANDED_MELEE, getAnimationList((String) cmdRow[animDefault+3]));