Skip to content

Commit

Permalink
Add force from shooting the bow.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Apr 29, 2013
1 parent 2053f09 commit bbb4346
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
5 changes: 4 additions & 1 deletion Archer/archer_lists.txt
Expand Up @@ -233,4 +233,7 @@ constest lock and unlock ?
!contest edit contest property value. [show if property is different than selected + (allow edit world as well) + owner/general perms]
sub perms for properties.

add sub command usage (...)
add sub command usage (...)

might add contest start

28 changes: 26 additions & 2 deletions Archer/src/me/asofold/bpl/archer/Archer.java
Expand Up @@ -40,6 +40,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
Expand Down Expand Up @@ -310,6 +311,27 @@ private final String stringPos(final Location loc){
return Utils.stringPos(loc, settings);
}

@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled = true)
final void onLaunch(final EntityShootBowEvent event){
if (players.isEmpty()) return;
// TODO: Might check event class here too.
final Entity pEntity = event.getProjectile();
if (!(pEntity instanceof Projectile)) return;
final Entity shooter = event.getEntity();
if (!(shooter instanceof Player)) return;
final PlayerData data = getPlayerData((Player) shooter);
if (data == null || data.mayForget()){
// mayForget(): not in any contests not subscribed for target notification.
return;
}
// Cleanup.
final long time = System.currentTimeMillis();
final long tDiff = time - data.tsActivity;
if (tDiff > 60000L) data.clearLaunchs();
final LaunchSpec launchSpec = new LaunchSpec(data.player.getLocation(), data.player.getEyeHeight(), time, event.getForce());
data.addLaunch(pEntity.getEntityId(), launchSpec);
}

@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled = true)
final void onLaunch(final ProjectileLaunchEvent event){
if (players.isEmpty()) return;
Expand All @@ -324,7 +346,9 @@ final void onLaunch(final ProjectileLaunchEvent event){
final long time = System.currentTimeMillis();
final long tDiff = time - data.tsActivity;
if (tDiff > 60000L) data.clearLaunchs();
final LaunchSpec launchSpec = new LaunchSpec(data.player.getLocation(), data.player.getEyeHeight(), time);
final int id = projectile.getEntityId();
final LaunchSpec oldSpec = data.removeLaunch(id);
final LaunchSpec launchSpec = new LaunchSpec(data.player.getLocation(), data.player.getEyeHeight(), time, oldSpec == null ? 1f : oldSpec.force);
// Check active contests for removal due to shots.
final List<String> rem = new LinkedList<String>();
for (final ContestData cd : data.activeContests.values()){
Expand All @@ -339,7 +363,7 @@ final void onLaunch(final ProjectileLaunchEvent event){
if (data.mayForget()) return;
}
// Register projectile for tracking.
data.addLaunch(projectile.getEntityId(), launchSpec);
data.addLaunch(id, launchSpec);
}

@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled = false)
Expand Down
8 changes: 6 additions & 2 deletions Archer/src/me/asofold/bpl/archer/core/Contest.java
Expand Up @@ -38,6 +38,7 @@ public class Contest extends ConfigPropertyHolder implements Comparable<Contest>
public Property maxTime = setProperty("max-time", 0, Long.MAX_VALUE, 600000L); // 10 minutes.

public Property minDistance = setProperty("min-distance", 0, Integer.MAX_VALUE, 5.0);
public Property minForce= setProperty("min-distance", 0, 1.0, 0.4);

// public Property maxPlayers = setProperty("max-players", 0, Integer.MAX_VALUE, 0);
public Property minPlayers = setProperty("min-players", 0, Integer.MAX_VALUE, 2);
Expand Down Expand Up @@ -405,15 +406,18 @@ public boolean onPlayerDeath(final PlayerData data, final ContestData cd) {
* @param damagedCd
* @return
*/
public HitResult onHit(PlayerData data, ContestData cd, double distance, PlayerData damagedData, ContestData damagedCd)
public HitResult onHit(PlayerData data, ContestData cd, double distance, float force, PlayerData damagedData, ContestData damagedCd)
{
if (!started) return HitResult.NOT_HIT;
if (minDistance.nonzero() && distance < minDistance.value){
// TODO: Might check loss by number of shots.
return HitResult.NOT_HIT;
}
if (minForce.nonzero() && force < minForce.value){
return HitResult.NOT_HIT;
}
// TODO: Message ...
double score = distance;
double score = distance * force;
cd.hitsDealt ++;
cd.score += score;
damagedCd.hitsTaken ++;
Expand Down
2 changes: 1 addition & 1 deletion Archer/src/me/asofold/bpl/archer/core/ContestManager.java
Expand Up @@ -245,7 +245,7 @@ public void onProjectileHit(final PlayerData data, final LaunchSpec launchSpec,
// TODO: Might remove if shots used up...
final String key = cd.contest.name.toLowerCase();
if (!damagedData.activeContests.containsKey(key)) continue;
final HitResult thisResult = cd.contest.onHit(data, cd, distance, damagedData, damagedData.activeContests.get(key));
final HitResult thisResult = cd.contest.onHit(data, cd, distance, launchSpec.force, damagedData, damagedData.activeContests.get(key));
if (thisResult.hit && !result.hit){
// TODO: Make methods in Archer ?
Utils.sendMessage(data, Archer.msgStart + "Hit: " + ChatColor.GREEN + damagedData.playerName);
Expand Down
8 changes: 5 additions & 3 deletions Archer/src/me/asofold/bpl/archer/core/LaunchSpec.java
Expand Up @@ -13,20 +13,22 @@ public class LaunchSpec {
public final String world;
public final double x, y, z;
public final long time;
public final float force;

/** For periodic cleanup. */
public boolean consumed = false;

public LaunchSpec(Location footLoc, double eyeHeight, long time){
this(footLoc.getWorld().getName(), footLoc.getX(), footLoc.getY() + eyeHeight, footLoc.getZ(), time);
public LaunchSpec(Location footLoc, double eyeHeight, long time, float force){
this(footLoc.getWorld().getName(), footLoc.getX(), footLoc.getY() + eyeHeight, footLoc.getZ(), time, force);
}

public LaunchSpec(String world, double x, double y, double z, long time){
public LaunchSpec(String world, double x, double y, double z, long time, float force){
this.world = world;
this.x = x;
this.y = y;
this.z = z;
this.time = time;
this.force = force;
}

/**
Expand Down

0 comments on commit bbb4346

Please sign in to comment.