2013-12-24 01:18:43 +01:00
|
|
|
/*************************************************************************
|
2013-12-29 00:02:50 +01:00
|
|
|
## Arrows Module
|
2013-12-24 01:18:43 +01:00
|
|
|
|
2013-12-26 16:38:24 +01:00
|
|
|
The arrows mod adds fancy arrows to the game. Arrows which...
|
2013-01-18 00:28:12 +01:00
|
|
|
|
2013-12-26 16:38:24 +01:00
|
|
|
* Launch fireworks.
|
|
|
|
* Explode on impact.
|
|
|
|
* Force Lightning to strike where they land.
|
|
|
|
* Teleport the player to the landing spot.
|
|
|
|
* Spawn Trees at the landing spot.
|
|
|
|
|
2013-12-29 00:02:50 +01:00
|
|
|
### Usage:
|
2013-12-26 16:38:24 +01:00
|
|
|
|
2013-12-30 22:33:12 +01:00
|
|
|
* `/js arrows.firework(self)` - A firework launches where the the arrow lands.
|
|
|
|
* `/js arrows.lightning(self)` - lightning strikes where the arrow lands.
|
|
|
|
* `/js arrows.teleport(self)` - makes player teleport to where arrow has landed.
|
|
|
|
* `/js arrows.flourish(self)` - makes a tree grow where the arrow lands.
|
|
|
|
* `/js arrows.explosive(self)` - makes arrows explode.
|
|
|
|
* `/js arrows.normal(self)` sets arrow type to normal.
|
|
|
|
* `/js arrows.sign(self)` turns a targeted sign into a Arrows menu
|
2013-06-23 20:56:18 +02:00
|
|
|
|
2013-12-29 13:58:20 +01:00
|
|
|
All of the above functions can take an optional player object or name
|
|
|
|
as a parameter. For example: `/js arrows.explosive('player23')` makes
|
|
|
|
player23's arrows explosive.
|
2013-01-18 00:28:12 +01:00
|
|
|
|
2013-12-24 01:18:43 +01:00
|
|
|
***/
|
2013-01-18 00:28:12 +01:00
|
|
|
|
2013-12-24 01:18:43 +01:00
|
|
|
var signs = require('signs');
|
|
|
|
var fireworks = require('fireworks');
|
2013-12-30 22:33:12 +01:00
|
|
|
var utils = require('utils');
|
2013-12-24 01:18:43 +01:00
|
|
|
|
|
|
|
var _store = {players: {}};
|
|
|
|
|
|
|
|
var arrows = plugin("arrows",{
|
2013-01-18 00:28:12 +01:00
|
|
|
/*
|
|
|
|
turn a sign into a menu of arrow choices
|
|
|
|
*/
|
|
|
|
sign: function(sign){},
|
|
|
|
/*
|
|
|
|
change player's arrows to normal
|
|
|
|
*/
|
|
|
|
normal: function(player){},
|
|
|
|
/*
|
|
|
|
change player's arrows to explode on impact
|
|
|
|
*/
|
|
|
|
explosive: function(player){},
|
|
|
|
/*
|
|
|
|
change player's arrows to teleporting
|
|
|
|
*/
|
|
|
|
teleport: function(player){},
|
|
|
|
/*
|
|
|
|
change player's arrows to plant trees where they land
|
|
|
|
*/
|
|
|
|
flourish: function(player){},
|
|
|
|
/*
|
|
|
|
change player's arrows to strike lightning where they land
|
|
|
|
*/
|
2013-05-11 17:03:49 +02:00
|
|
|
lightning: function(player){},
|
2013-06-23 20:56:18 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
launch a firework where the arrow lands
|
|
|
|
*/
|
2013-12-24 01:18:43 +01:00
|
|
|
explosiveYield: 2.5,
|
|
|
|
|
|
|
|
store: _store
|
2013-05-11 17:03:49 +02:00
|
|
|
|
2013-01-18 00:28:12 +01:00
|
|
|
},true);
|
2013-12-24 01:18:43 +01:00
|
|
|
|
|
|
|
exports.arrows = arrows;
|
|
|
|
|
|
|
|
//
|
|
|
|
// setup functions for the arrow types
|
|
|
|
//
|
|
|
|
var _types = {normal: 0, explosive: 1, teleport: 2, flourish: 3, lightning: 4, firework: 5};
|
|
|
|
for (var type in _types)
|
|
|
|
{
|
|
|
|
arrows[type] = (function(n){
|
|
|
|
return function(player){
|
2013-12-31 19:21:40 +01:00
|
|
|
player = utils.player(player);
|
|
|
|
if (player)
|
|
|
|
arrows.store.players[player.name] = n;
|
|
|
|
else
|
|
|
|
console.warn('arrows.' + n + ' No player ' + player);
|
2013-12-24 01:18:43 +01:00
|
|
|
};
|
|
|
|
})(_types[type]);
|
|
|
|
}
|
2013-01-18 00:28:12 +01:00
|
|
|
|
|
|
|
/*
|
2013-12-24 01:18:43 +01:00
|
|
|
called when the player chooses an arrow option from a menu sign
|
2013-01-18 00:28:12 +01:00
|
|
|
*/
|
2013-12-24 01:18:43 +01:00
|
|
|
var _onMenuChoice = function(event){
|
|
|
|
arrows.store.players[event.player.name] = event.number;
|
|
|
|
};
|
|
|
|
arrows.sign = signs.menu("Arrow",
|
|
|
|
["Normal","Explosive","Teleport","Flourish","Lightning","Firework"],
|
|
|
|
_onMenuChoice );
|
|
|
|
|
2013-01-18 00:28:12 +01:00
|
|
|
/*
|
2013-12-24 01:18:43 +01:00
|
|
|
event handler called when a projectile hits something
|
2013-01-18 00:28:12 +01:00
|
|
|
*/
|
2013-12-24 01:18:43 +01:00
|
|
|
var _onArrowHit = function(listener,event)
|
2013-01-18 00:28:12 +01:00
|
|
|
{
|
2013-12-24 01:18:43 +01:00
|
|
|
var projectile = event.entity;
|
|
|
|
var world = projectile.world;
|
|
|
|
var shooter = projectile.shooter;
|
|
|
|
var fireworkCount = 5;
|
|
|
|
if (projectile instanceof org.bukkit.entity.Arrow &&
|
|
|
|
shooter instanceof org.bukkit.entity.Player)
|
2013-01-18 00:28:12 +01:00
|
|
|
{
|
2013-12-24 01:18:43 +01:00
|
|
|
var arrowType = arrows.store.players[shooter.name];
|
|
|
|
|
|
|
|
switch (arrowType){
|
|
|
|
case 1:
|
|
|
|
projectile.remove();
|
|
|
|
world.createExplosion(projectile.location,arrows.explosiveYield);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
projectile.remove();
|
|
|
|
var teleportCause =org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
|
|
|
shooter.teleport(projectile.location,
|
|
|
|
teleportCause.PLUGIN);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
projectile.remove();
|
|
|
|
world.generateTree(projectile.location, org.bukkit.TreeType.BIG_TREE);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
projectile.remove();
|
|
|
|
world.strikeLightning(projectile.location);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
projectile.remove();
|
|
|
|
var launch = function(){
|
2013-06-23 20:56:18 +02:00
|
|
|
fireworks.firework(projectile.location);
|
2013-12-24 01:18:43 +01:00
|
|
|
if (--fireworkCount)
|
|
|
|
setTimeout(launch,2000);
|
|
|
|
};
|
|
|
|
launch();
|
|
|
|
break;
|
2013-01-18 00:28:12 +01:00
|
|
|
}
|
2013-12-24 01:18:43 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
events.on('entity.ProjectileHitEvent',_onArrowHit);
|
|
|
|
|