public int getRespawnTime() { try { int baseRespawn = CivSettings.getInteger(CivSettings.warConfig, "war.respawn_time"); int controlRespawn = CivSettings.getInteger(CivSettings.warConfig, "war.control_block_respawn_time"); int invalidRespawnPenalty = CivSettings.getInteger(CivSettings.warConfig, "war.invalid_respawn_penalty"); int totalRespawn = baseRespawn; for (ControlPoint cp : this.controlPoints.values()) { if (cp.isDestroyed()) { totalRespawn += controlRespawn; } } if (this.validated && !this.isValid()) { totalRespawn += invalidRespawnPenalty * 60; } // Search for any town in our civ with the medicine goodie. for (Town t : this.getCiv().getTowns()) { if (t.getBuffManager().hasBuff(Buff.MEDICINE)) { int respawnTimeBonus = t.getBuffManager().getEffectiveInt(Buff.MEDICINE); totalRespawn = Math.max(1, (totalRespawn - respawnTimeBonus)); break; } } return totalRespawn; } catch (InvalidConfiguration e) { e.printStackTrace(); } return 60; }
public void regenControlBlocks() { for (BlockCoord coord : this.controlPoints.keySet()) { ItemManager.setTypeId(coord.getBlock(), CivData.OBSIDIAN); ControlPoint cp = this.controlPoints.get(coord); cp.setHitpoints(cp.getMaxHitpoints()); } }
public void onCannonDamage(int damage, CannonProjectile projectile) throws CivException { this.hitpoints -= damage; Resident resident = projectile.whoFired; if (hitpoints <= 0) { for (BlockCoord coord : this.controlPoints.keySet()) { ControlPoint cp = this.controlPoints.get(coord); if (cp != null) { if (cp.getHitpoints() > CannonProjectile.controlBlockHP) { cp.damage(cp.getHitpoints() - 1); this.hitpoints = this.getMaxHitPoints() / 2; StructureBlock hit = CivGlobal.getStructureBlock(coord); onControlBlockCannonDestroy(cp, CivGlobal.getPlayer(resident), hit); CivMessage.sendCiv( getCiv(), "Our " + this.getDisplayName() + " has been hit by a cannon and a control block was set to " + CannonProjectile.controlBlockHP + " HP!"); CivMessage.sendCiv( getCiv(), "Our " + this.getDisplayName() + " has regenerated " + this.getMaxHitPoints() / 2 + " HP! If it drops to zero, we will lose another Control Point."); return; } } } CivMessage.sendCiv( getCiv(), "Our " + this.getDisplayName() + " is out of hitpoints, walls can be destroyed by cannon and TNT blasts!"); hitpoints = 0; } CivMessage.sendCiv( getCiv(), "Our " + this.getDisplayName() + " has been hit by a cannon! (" + this.hitpoints + "/" + this.getMaxHitPoints() + ")"); }
public void onControlBlockHit(ControlPoint cp, World world, Player player, StructureBlock hit) { world.playSound(hit.getCoord().getLocation(), Sound.ANVIL_USE, 0.2f, 1); world.playEffect(hit.getCoord().getLocation(), Effect.MOBSPAWNER_FLAMES, 0); CivMessage.send( player, CivColor.LightGray + "Damaged Control Block (" + cp.getHitpoints() + " / " + cp.getMaxHitpoints() + ")"); CivMessage.sendTown( hit.getTown(), CivColor.Yellow + "One of our Town Hall's Control Points is under attack!"); }
@Override public void onDamage( int amount, World world, Player player, BlockCoord coord, BuildableDamageBlock hit) { ControlPoint cp = this.controlPoints.get(coord); Resident resident = CivGlobal.getResident(player); if (!resident.canDamageControlBlock()) { CivMessage.send( player, CivColor.Rose + "Cannot damage control blocks due to missing/invalid Town Hall or Capitol structure."); return; } if (cp != null) { if (!cp.isDestroyed()) { if (resident.isControlBlockInstantBreak()) { cp.damage(cp.getHitpoints()); } else { cp.damage(amount); } if (cp.isDestroyed()) { onControlBlockDestroy(cp, world, player, (StructureBlock) hit); } else { onControlBlockHit(cp, world, player, (StructureBlock) hit); } } else { CivMessage.send(player, CivColor.Rose + "Control Block already destroyed."); } } else { CivMessage.send( player, CivColor.Rose + "Cannot Damage " + this.getDisplayName() + ", go after the control points!"); } }
public void onControlBlockCannonDestroy(ControlPoint cp, Player player, StructureBlock hit) { // Should always have a resident and a town at this point. Resident attacker = CivGlobal.getResident(player); ItemManager.setTypeId(hit.getCoord().getLocation().getBlock(), CivData.AIR); boolean allDestroyed = true; for (ControlPoint c : this.controlPoints.values()) { if (c.isDestroyed() == false) { allDestroyed = false; break; } } CivMessage.sendTownSound(hit.getTown(), Sound.AMBIENCE_CAVE, 1.0f, 0.5f); if (allDestroyed) { if (this.getTown().getCiv().getCapitolName().equals(this.getTown().getName())) { CivMessage.global( CivColor.LightBlue + ChatColor.BOLD + "The civilization of " + this.getTown().getCiv().getName() + " has been conquered by " + attacker.getCiv().getName() + "!"); for (Town town : this.getTown().getCiv().getTowns()) { town.defeated = true; } War.transferDefeated(this.getTown().getCiv(), attacker.getTown().getCiv()); WarStats.logCapturedCiv(attacker.getTown().getCiv(), this.getTown().getCiv()); War.saveDefeatedCiv(this.getCiv(), attacker.getTown().getCiv()); if (CivGlobal.isCasualMode()) { HashMap<Integer, ItemStack> leftovers = player .getInventory() .addItem( this.getCiv() .getRandomLeaderSkull("Victory Over " + this.getCiv().getName() + "!")); for (ItemStack stack : leftovers.values()) { player.getWorld().dropItem(player.getLocation(), stack); } } } else { CivMessage.global( CivColor.Yellow + ChatColor.BOLD + "The town of " + getTown().getName() + " in " + this.getCiv().getName() + " has been conquered by " + attacker.getCiv().getName() + "!"); // this.getTown().onDefeat(attacker.getTown().getCiv()); this.getTown().defeated = true; // War.defeatedTowns.put(this.getTown().getName(), attacker.getTown().getCiv()); WarStats.logCapturedTown(attacker.getTown().getCiv(), this.getTown()); War.saveDefeatedTown(this.getTown().getName(), attacker.getTown().getCiv()); } } else { CivMessage.sendTown( hit.getTown(), CivColor.Rose + "One of our Town Hall's Control Points has been destroyed!"); CivMessage.sendCiv( attacker.getTown().getCiv(), CivColor.LightGreen + "We've destroyed a control block in " + hit.getTown().getName() + "!"); CivMessage.sendCiv( hit.getTown().getCiv(), CivColor.Rose + "A control block in " + hit.getTown().getName() + " has been destroyed!"); } }
public void onControlBlockDestroy( ControlPoint cp, World world, Player player, StructureBlock hit) { // Should always have a resident and a town at this point. Resident attacker = CivGlobal.getResident(player); ItemManager.setTypeId(hit.getCoord().getLocation().getBlock(), CivData.AIR); world.playSound(hit.getCoord().getLocation(), Sound.ANVIL_BREAK, 1.0f, -1.0f); world.playSound(hit.getCoord().getLocation(), Sound.EXPLODE, 1.0f, 1.0f); FireworkEffect effect = FireworkEffect.builder() .with(Type.BURST) .withColor(Color.YELLOW) .withColor(Color.RED) .withTrail() .withFlicker() .build(); FireworkEffectPlayer fePlayer = new FireworkEffectPlayer(); for (int i = 0; i < 3; i++) { try { fePlayer.playFirework(world, hit.getCoord().getLocation(), effect); } catch (Exception e) { e.printStackTrace(); } } boolean allDestroyed = true; for (ControlPoint c : this.controlPoints.values()) { if (c.isDestroyed() == false) { allDestroyed = false; break; } } CivMessage.sendTownSound(hit.getTown(), Sound.AMBIENCE_CAVE, 1.0f, 0.5f); if (allDestroyed) { if (this.getTown().getCiv().getCapitolName().equals(this.getTown().getName())) { CivMessage.global( CivColor.LightBlue + ChatColor.BOLD + "The civilization of " + this.getTown().getCiv().getName() + " has been conquered by " + attacker.getCiv().getName() + "!"); for (Town town : this.getTown().getCiv().getTowns()) { town.defeated = true; } War.transferDefeated(this.getTown().getCiv(), attacker.getTown().getCiv()); WarStats.logCapturedCiv(attacker.getTown().getCiv(), this.getTown().getCiv()); War.saveDefeatedCiv(this.getCiv(), attacker.getTown().getCiv()); if (CivGlobal.isCasualMode()) { HashMap<Integer, ItemStack> leftovers = player .getInventory() .addItem( this.getCiv() .getRandomLeaderSkull("Victory Over " + this.getCiv().getName() + "!")); for (ItemStack stack : leftovers.values()) { player.getWorld().dropItem(player.getLocation(), stack); } } } else { CivMessage.global( CivColor.Yellow + ChatColor.BOLD + "The town of " + getTown().getName() + " in " + this.getCiv().getName() + " has been conquered by " + attacker.getCiv().getName() + "!"); // this.getTown().onDefeat(attacker.getTown().getCiv()); this.getTown().defeated = true; // War.defeatedTowns.put(this.getTown().getName(), attacker.getTown().getCiv()); WarStats.logCapturedTown(attacker.getTown().getCiv(), this.getTown()); War.saveDefeatedTown(this.getTown().getName(), attacker.getTown().getCiv()); } } else { CivMessage.sendTown( hit.getTown(), CivColor.Rose + "One of our Town Hall's Control Points has been destroyed!"); CivMessage.sendCiv( attacker.getTown().getCiv(), CivColor.LightGreen + "We've destroyed a control block in " + hit.getTown().getName() + "!"); CivMessage.sendCiv( hit.getTown().getCiv(), CivColor.Rose + "A control block in " + hit.getTown().getName() + " has been destroyed!"); } }