Skip to content

Commit

Permalink
Add display and calculation stuff for maximum damage with thrown weapons
Browse files Browse the repository at this point in the history
  • Loading branch information
bonii-xx committed Oct 28, 2014
1 parent 92fd2cc commit 525baf8
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 7 deletions.
1 change: 1 addition & 0 deletions resources/assets/tinker/lang/en_US.lang
Expand Up @@ -760,6 +760,7 @@ gui.toolstation19=Damage Reduction:
gui.toolstation20=Protection:
gui.toolstation21=Ammo:
gui.toolstation22=Break Chance:
gui.toolstation23=Max. Attack:

gui.mining1=Stone
gui.mining2=Iron
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/tconstruct/library/weaponry/AmmoWeapon.java
Expand Up @@ -88,7 +88,7 @@ public float getAccuracy(ItemStack itemStack, EntityPlayer player)

@Override
public String[] getTraits() {
return new String[] {"weapon", "projectile", "ammo", "windup"};
return new String[] {"weapon", "thrown", "ammo", "windup"};
}

@Override
Expand All @@ -115,6 +115,10 @@ protected void launchProjectile(ItemStack stack, World world, EntityPlayer playe

protected abstract Entity createProjectile(ItemStack reference, World world, EntityPlayer player, float accuracy);

/** used for displaying the damage, return the value used for pseed in createProjectile/ProjectileBase constructor
*/
public abstract float getProjectileSpeed();

@SideOnly(Side.CLIENT)
public CrosshairType getCrosshairType() { return CrosshairType.SQUARE; }

Expand Down
25 changes: 23 additions & 2 deletions src/main/java/tconstruct/tools/gui/ToolStationGuiHelper.java
Expand Up @@ -14,6 +14,7 @@
import tconstruct.library.tools.HarvestTool;
import tconstruct.library.tools.ToolCore;
import tconstruct.library.util.HarvestLevels;
import tconstruct.library.weaponry.AmmoWeapon;
import tconstruct.library.weaponry.IAmmo;
import tconstruct.library.weaponry.ProjectileWeapon;

Expand Down Expand Up @@ -86,6 +87,9 @@ else if (categories.contains("harvest"))
// weapon?
if (categories.contains("weapon"))
drawWeaponStats(tool, tags);
// throwing weapon?
if (categories.contains("thrown") && tool instanceof AmmoWeapon)
drawThrowingWeaponStats((AmmoWeapon) tool, tags);
// projectile weapon?
if (categories.contains("bow") && tool instanceof ProjectileWeapon)
drawProjectileWeaponStats((ProjectileWeapon) tool, tags, stack);
Expand Down Expand Up @@ -192,7 +196,7 @@ private static void drawDualHarvestStats(ToolCore tool, NBTTagCompound tags)
private static void drawWeaponStats(ToolCore tool, NBTTagCompound tags)
{
// DAMAGE
int attack = (tags.getInteger("Attack")) + 1;
int attack = (tags.getInteger("Attack"));

// factor in Stonebound
float stoneboundDamage = -AbilityHelper.calcStoneboundBonus(tool, tags);
Expand All @@ -216,6 +220,23 @@ private static void drawWeaponStats(ToolCore tool, NBTTagCompound tags)
}
}

private static void drawThrowingWeaponStats(AmmoWeapon weapon, NBTTagCompound tags) {
float attackf = (tags.getInteger("Attack"));
attackf *= weapon.getDamageModifier();
attackf *= weapon.getProjectileSpeed();

if (attackf < 1)
attackf = 1;

int attack = (int)attackf;

String heart = attack == 2 ? StatCollector.translateToLocal("gui.partcrafter8") : StatCollector.translateToLocal("gui.partcrafter9");
if (attack % 2 == 0)
write(StatCollector.translateToLocal("gui.toolstation23") + attack / 2 + heart);
else
write(StatCollector.translateToLocal("gui.toolstation23") + df.format(attack / 2f) + heart);
}

private static void drawProjectileWeaponStats(ProjectileWeapon weapon, NBTTagCompound tags, ItemStack stack)
{
// drawspeed
Expand Down Expand Up @@ -245,7 +266,7 @@ private static void drawProjectileStats(NBTTagCompound tags)

private static void drawArmorStats(ArmorCore armor, NBTTagCompound tags, ItemStack stack)
{
// Damage reduction
// Damage reduction
double damageReduction = tags.getDouble("DamageReduction");
if(damageReduction > 0)
write(StatCollector.translateToLocal("gui.toolstation19") + df.format(damageReduction));
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/tconstruct/weaponry/weapons/Javelin.java
Expand Up @@ -163,14 +163,24 @@ public Item getAccessoryItem() {
return TinkerTools.toughRod;
}

@Override
public String[] getTraits() {
return new String[] {"weapon", "thrown", "ammo", "windup"};
}

@Override
protected Entity createProjectile(ItemStack reference, World world, EntityPlayer player, float accuracy) {
reference.getTagCompound().getCompoundTag("InfiTool").removeTag("Throwing"); // needed so the NBTs are equal
JavelinEntity entity = new JavelinEntity(world, player, 2.0f, accuracy, reference);
JavelinEntity entity = new JavelinEntity(world, player, getProjectileSpeed(), accuracy, reference);

return entity;
}

@Override
public float getProjectileSpeed() {
return 2.0f;
}

@SideOnly(Side.CLIENT)
@Override
public CrosshairType getCrosshairType() { return CrosshairType.WEIRD; }
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/tconstruct/weaponry/weapons/Shuriken.java
Expand Up @@ -111,7 +111,12 @@ public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer pla

@Override
protected Entity createProjectile(ItemStack reference, World world, EntityPlayer player, float accuracy) {
return new ShurikenEntity(world, player, 1.9f, 0f, reference);
return new ShurikenEntity(world, player, getProjectileSpeed(), 0f, reference);
}

@Override
public float getProjectileSpeed() {
return 1.9f;
}

@Override
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/tconstruct/weaponry/weapons/ThrowingKnife.java
Expand Up @@ -77,9 +77,12 @@ public float minAccuracy(ItemStack itemStack) {

@Override
protected Entity createProjectile(ItemStack reference, World world, EntityPlayer player, float accuracy) {
float speed = 1.5f;
return new ThrowingKnifeEntity(world, player, getProjectileSpeed(), accuracy, reference);
}

return new ThrowingKnifeEntity(world, player, speed, accuracy, reference);
@Override
public float getProjectileSpeed() {
return 1.5f;
}

@SideOnly(Side.CLIENT)
Expand Down

0 comments on commit 525baf8

Please sign in to comment.