Added support for combat command ranges

This commit is contained in:
Mads Boddum
2016-10-23 07:35:01 +02:00
parent 2ee2946966
commit d58733995c
6 changed files with 74 additions and 54 deletions
+19 -1
View File
@@ -50,6 +50,8 @@ public class CombatCommand extends Command {
private int attackRolls;
private float percentAddFromWeapon;
private int addedDamage;
private String buffNameTarget;
private String buffNameSelf;
public CombatCommand(String name) {
super(name);
@@ -164,5 +166,21 @@ public class CombatCommand extends Command {
public void setAddedDamage(int addedDamage) {
this.addedDamage = addedDamage;
}
public String getBuffNameTarget() {
return buffNameTarget;
}
public void setBuffNameTarget(String buffNameTarget) {
this.buffNameTarget = buffNameTarget;
}
public String getBuffNameSelf() {
return buffNameSelf;
}
public void setBuffNameSelf(String buffNameSelf) {
this.buffNameSelf = buffNameSelf;
}
}
+3 -3
View File
@@ -50,7 +50,7 @@ public class Command {
private boolean callOnTarget;
// command group
// disabled
private int maxRange;
private float maxRange;
private int godLevel;
// display group
private boolean combatCommand;
@@ -94,8 +94,8 @@ public class Command {
public void setTargetType(int targetType) { this.targetType = targetType; }
public boolean isCallOnTarget() { return callOnTarget; }
public void setCallOnTarget(boolean callOnTarget) { this.callOnTarget = callOnTarget; }
public int getMaxRange() { return maxRange; }
public void setMaxRange(int maxRange) { this.maxRange = maxRange; }
public float getMaxRange() { return maxRange; }
public void setMaxRange(float maxRange) { this.maxRange = maxRange; }
public int getGodLevel() { return godLevel; }
public void setGodLevel(int godLevel) { this.godLevel = godLevel; }
public boolean isCombatCommand() { return combatCommand; }
@@ -794,20 +794,16 @@ public class CreatureObject extends TangibleObject {
public boolean isEnemy(TangibleObject otherObject) {
boolean enemy = super.isEnemy(otherObject);
if(enemy) {
// If these are both creatures, there's a chance both of them are players!
if (this instanceof CreatureObject && otherObject instanceof CreatureObject) {
CreatureObject thisCreature = (CreatureObject) this;
CreatureObject otherCreature = (CreatureObject) otherObject;
if (enemy && otherObject instanceof CreatureObject) {
PvpStatus ourStatus = getPvpStatus();
PvpStatus theirStatus = otherObject.getPvpStatus();
// If they're both players, both of them might be special force
if (thisCreature.isPlayer() && otherCreature.isPlayer()) {
// They are enemies if they're both players and members of the special force!
return getPvpStatus() == PvpStatus.SPECIALFORCES && otherObject.getPvpStatus() == PvpStatus.SPECIALFORCES;
}
if (isPlayer() && ((CreatureObject) otherObject).isPlayer()) {
// They are enemies if both players are SF
return ourStatus == PvpStatus.SPECIALFORCES && theirStatus == PvpStatus.SPECIALFORCES;
}
}
return enemy;
}
@@ -257,14 +257,12 @@ public class TangibleObject extends SWGObject {
// They CAN be enemies if they're not from the same faction and neither of them are neutral
PvpFaction otherFaction = otherObject.getPvpFaction();
if (otherFaction != PvpFaction.NEUTRAL && getPvpFaction() != otherFaction) {
if (getPvpStatus() != PvpStatus.ONLEAVE && otherObject.getPvpStatus() != PvpStatus.ONLEAVE) {
// Both objects are not players. In this case, both just need to be combatants.
return true;
}
if (hasPvpFlag(PvpFlag.ATTACKABLE) || otherObject.hasPvpFlag(PvpFlag.ATTACKABLE)) {
return true;
} else {
return otherFaction != PvpFaction.NEUTRAL && getPvpFaction() != otherFaction
&& getPvpStatus() != PvpStatus.ONLEAVE && otherObject.getPvpStatus() != PvpStatus.ONLEAVE;
}
return false;
}
public String getCurrentCity() {
+33 -32
View File
@@ -239,6 +239,9 @@ public class CombatManager extends Manager {
}
private void doCombat(CreatureObject source, SWGObject target, CombatCommand command) {
// TODO HitType checking. This will for instance prevent buff commands from behaving as a single target combat command
addBuff(source, source, command.getBuffNameSelf()); // Add self buff if present
CombatAction action = new CombatAction(source.getObjectId());
String anim = command.getRandomAnimation(source.getEquippedWeapon().getType());
action.setActionCrc(CRC.getCrc(anim));
@@ -253,7 +256,6 @@ public class CombatManager extends Manager {
damage += calculateWeaponDamage(source, command);
damage += command.getAddedDamage();
addSelfBuff(source, command);
if (target instanceof CreatureObject) {
if (command.getAttackType() == AttackType.SINGLE_TARGET)
@@ -273,7 +275,7 @@ public class CombatManager extends Manager {
target.addDefender(source);
source.addDefender(target);
addTargetBuff(source, command);
addBuff(source, target, command.getBuffNameTarget()); // Add target buff
if (target.getHealth() <= damage)
doCreatureDeath(target, source);
@@ -281,14 +283,6 @@ public class CombatManager extends Manager {
target.modifyHealth(-damage);
}
private void addTargetBuff(CreatureObject target, CombatCommand command) {
}
private void addSelfBuff(CreatureObject creature, CombatCommand command) {
}
private void enterCombat(CreatureObject creature) {
creature.setInCombat(true);
@@ -463,57 +457,56 @@ public class CombatManager extends Manager {
private CombatStatus canPerform(CreatureObject source, SWGObject target, CombatCommand c) {
if (source.getEquippedWeapon() == null)
return CombatStatus.NO_WEAPON;
if (target == null || source.equals(target))
return CombatStatus.SUCCESS;
if (!(target instanceof TangibleObject))
return CombatStatus.INVALID_TARGET;
TangibleObject tangibleTarget = (TangibleObject) target;
if(tangibleTarget.getPvpFaction() != PvpFaction.NEUTRAL) {
if(!tangibleTarget.isEnemy(source)) {
return CombatStatus.INVALID_TARGET;
}
} else if ((tangibleTarget.getPvpFlags() & PvpFlag.ATTACKABLE.getBitmask()) == 0)
if (!tangibleTarget.isEnemy(source)) {
return CombatStatus.INVALID_TARGET;
}
if(target instanceof CreatureObject) {
CreatureObject creature = (CreatureObject) target;
switch(creature.getPosture()) {
switch(((CreatureObject) target).getPosture()) {
case DEAD:
case INCAPACITATED:
return CombatStatus.INVALID_TARGET;
}
}
CombatStatus status;
switch (c.getAttackType()) {
case AREA:
case TARGET_AREA:
status = canPerformArea(source, c);
break;
return canPerformArea(source, c);
case SINGLE_TARGET:
status = canPerformSingle(source, target, c);
break;
return canPerformSingle(source, target, c);
default:
status = CombatStatus.UNKNOWN;
break;
return CombatStatus.UNKNOWN;
}
if (status != CombatStatus.SUCCESS)
return status;
return status;
}
private CombatStatus canPerformSingle(CreatureObject source, SWGObject target, CombatCommand c) {
if (target == null || !(target instanceof CreatureObject))
if (target == null || !(target instanceof TangibleObject))
return CombatStatus.NO_TARGET;
WeaponObject weapon = source.getEquippedWeapon();
double dist = source.getLocation().distanceTo(target.getLocation());
if (dist > weapon.getMaxRange() || (dist > c.getMaxRange() && c.getMaxRange() > 0))
float commandRange = c.getMaxRange();
float range = commandRange > 0 ? commandRange : weapon.getMaxRange();
if (dist > range)
return CombatStatus.TOO_FAR;
return CombatStatus.SUCCESS;
}
private CombatStatus canPerformArea(CreatureObject source, CombatCommand c) {
return CombatStatus.SUCCESS;
// TODO implement AoE
return CombatStatus.UNKNOWN;
}
private int calculateWeaponDamage(CreatureObject source, CombatCommand command) {
@@ -524,6 +517,14 @@ public class CombatManager extends Manager {
return (int) (weaponDamage * command.getPercentAddFromWeapon());
}
private void addBuff(CreatureObject caster, CreatureObject receiver, String buffName) {
if (buffName.isEmpty()) {
return;
}
new BuffIntent(buffName, caster, receiver, false).broadcast();
}
private void showFlyText(TangibleObject obj, String text, Scale scale, Color c, ShowFlyText.Flag ... flags) {
obj.sendSelf(new ShowFlyText(obj.getObjectId(), text, scale, new RGB(c), flags));
}
@@ -400,6 +400,7 @@ public class CommandService extends Service {
cc.setCooldownGroup2(c.getCooldownGroup2());
cc.setCooldownTime(c.getCooldownTime());
cc.setCooldownTime2(c.getCooldownTime2());
cc.setMaxRange(c.getMaxRange());
return cc;
}
@@ -417,6 +418,9 @@ public class CommandService extends Service {
int animDefault = combatCommands.getColumnFromName("animDefault");
int percentAddFromWeapon = combatCommands.getColumnFromName("percentAddFromWeapon");
int addedDamage = combatCommands.getColumnFromName("addedDamage");
int buffNameTarget = combatCommands.getColumnFromName("buffNameTarget");
int buffNameSelf = combatCommands.getColumnFromName("buffNameSelf");
int maxRange = combatCommands.getColumnFromName("maxRange");
// 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
@@ -440,6 +444,9 @@ public class CommandService extends Service {
cc.setDefaultAnimation(getAnimationList((String) cmdRow[animDefault]));
cc.setPercentAddFromWeapon((float) cmdRow[percentAddFromWeapon]);
cc.setAddedDamage((int) cmdRow[addedDamage]);
cc.setBuffNameTarget((String) cmdRow[buffNameTarget]);
cc.setBuffNameSelf((String) cmdRow[buffNameSelf]);
cc.setMaxRange((float) cmdRow[maxRange]);
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]));