Add the ability for Damage Manager to support constant values of knockback

This commit is contained in:
Sam 2017-11-16 20:28:30 +00:00 committed by Alexander Meech
parent d15e76d5a6
commit 6e56f97e25
3 changed files with 40 additions and 11 deletions

View File

@ -58,11 +58,16 @@ public class DamageManager extends MiniPlugin
public boolean UseSimpleWeaponDamage = false; public boolean UseSimpleWeaponDamage = false;
public boolean DisableDamageChanges = false; public boolean DisableDamageChanges = false;
/**
* The value of knockback that is applied when a player is attacked.
* If 0, the value is calculated from log10(damage).
*/
private double _constantKnockback;
private boolean _enabled = true; private boolean _enabled = true;
private final HashMap<String, Integer> _protectionTypeModifiers = new HashMap<String, Integer>(); private final HashMap<String, Integer> _protectionTypeModifiers = new HashMap<>();
private final HashMap<String, DamageCause[]> _protectionCauses = new HashMap<String, DamageCause[]>(); private final HashMap<String, DamageCause[]> _protectionCauses = new HashMap<>();
public DamageManager(JavaPlugin plugin, CombatManager combatManager, NpcManager npcManager, DisguiseManager disguiseManager, ConditionManager conditionManager) public DamageManager(JavaPlugin plugin, CombatManager combatManager, NpcManager npcManager, DisguiseManager disguiseManager, ConditionManager conditionManager)
{ {
@ -530,13 +535,18 @@ public class DamageManager extends MiniPlugin
if (event.IsKnockback() && (event.getKnockbackOrigin() != null || event.GetDamagerEntity(true) != null)) if (event.IsKnockback() && (event.getKnockbackOrigin() != null || event.GetDamagerEntity(true) != null))
{ {
//Base //Base
double knockback = event.GetDamage(); double knockback = _constantKnockback;
if (knockback < 2) knockback = 2;
knockback = Math.log10(knockback); if (_constantKnockback == 0)
{
knockback = Math.log10(Math.max(event.GetDamage(), 2));
}
//Mults //Mults
for (double cur : event.GetKnockback().values()) for (double cur : event.GetKnockback().values())
knockback = knockback * cur; {
knockback *= cur;
}
//Origin //Origin
Location origin = null; Location origin = null;
@ -836,6 +846,24 @@ public class DamageManager extends MiniPlugin
_enabled = var; _enabled = var;
} }
/**
* Sets the value of {@link #_constantKnockback}.
**/
public void setConstantKnockback(double constantKnockback)
{
_constantKnockback = constantKnockback;
}
/**
* Resets the configuration of damage manager and ensures it is enabled.
*/
public void resetConfiguration()
{
DisableDamageChanges = false;
_constantKnockback = 0;
SetEnabled(true);
}
public CombatManager GetCombatManager() public CombatManager GetCombatManager()
{ {
return _combatManager; return _combatManager;

View File

@ -91,6 +91,10 @@ public class CakeWars extends TeamGame
"All players standing on the Resource Generator get the items generated." "All players standing on the Resource Generator get the items generated."
}; };
private static final int RESPAWN_TIME = 6; private static final int RESPAWN_TIME = 6;
/**
* This value is the base value of knockback for Cake Wars. it is derived from log10(7).
*/
private static final double GAME_KNOCKBACK = 0.845;
private static final LeaderboardManager LEADERBOARD_MANAGER = Managers.get(LeaderboardManager.class); private static final LeaderboardManager LEADERBOARD_MANAGER = Managers.get(LeaderboardManager.class);
private final Map<GameTeam, Location> _averages; private final Map<GameTeam, Location> _averages;
@ -162,7 +166,7 @@ public class CakeWars extends TeamGame
new ChatStatData("EatWholeCake", "Whole Cakes", true) new ChatStatData("EatWholeCake", "Whole Cakes", true)
); );
manager.GetDamage().SetEnabled(false); manager.GetDamage().setConstantKnockback(GAME_KNOCKBACK);
manager.GetCreature().SetDisableCustomDrops(true); manager.GetCreature().SetDisableCustomDrops(true);
new AbsorptionFix(this); new AbsorptionFix(this);

View File

@ -155,17 +155,14 @@ public class GameCreationManager implements Listener
private void CreateGame(GameType gameType) private void CreateGame(GameType gameType)
{ {
//Reset Changes //Reset Changes
Manager.GetDamage().DisableDamageChanges = false;
Manager.GetCreature().SetDisableCustomDrops(false); Manager.GetCreature().SetDisableCustomDrops(false);
Manager.GetDamage().SetEnabled(true); Manager.GetDamage().resetConfiguration();
Manager.GetExplosion().resetConfiguration(); Manager.GetExplosion().resetConfiguration();
// Manager.GetAntiStack().SetEnabled(true); // Manager.GetAntiStack().SetEnabled(true);
Manager.getCosmeticManager().setHideParticles(false); Manager.getCosmeticManager().setHideParticles(false);
Manager.GetDamage().GetCombatManager().setUseWeaponName(AttackReason.CustomWeaponName); Manager.GetDamage().GetCombatManager().setUseWeaponName(AttackReason.CustomWeaponName);
ItemStackFactory.Instance.SetUseCustomNames(false); ItemStackFactory.Instance.SetUseCustomNames(false);
HashMap<String, ChatColor> pastTeams = null;
System.out.println(_nextGame == null ? "Next Game = null" : "Next Game = " + _nextGame.GetName()); System.out.println(_nextGame == null ? "Next Game = null" : "Next Game = " + _nextGame.GetName());
System.out.println(MapPref == null ? "Map Pref = null" : "Map Pref = " + MapPref); System.out.println(MapPref == null ? "Map Pref = null" : "Map Pref = " + MapPref);