Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows multiple players to damage bastion field #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Bastion/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion Bastion/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Bastion
version: 0.5.0
version: 0.6.0
main: isaac.bastion.Bastion
depend: [Citadel]
softdepend: [Humbug]
Expand Down
30 changes: 24 additions & 6 deletions Bastion/src/isaac/bastion/BastionBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@ public class BastionBlock implements QTBox, Comparable<BastionBlock>
private double balance=0; //the amount remaining still to be eroded after the whole part has been removed
private int strength; //current durability
private long placed; //time when the bastion block was created

private long lastPlace; //time when the last erode took place

private class BastionPlaces{ //class that saves player and last time they placed a block
public String player; //the player this instance is in reference to
public long lastPlace; //last time said player placed a block
}

private ArrayList<BastionPlaces> myPlaces = new ArrayList<BastionPlaces>(); //array storing info on players who have placed blocks since initialized
private BastionPlaces currentPlace; //variable to be used in determining what instance of array to useBastion
private long setupPlace; //time when block is initilaized
private boolean loaded=true; //has the object not been modified since it was loaded?
private boolean ghost=false; //should the object be deleted

Expand Down Expand Up @@ -102,7 +109,7 @@ private void setup(){
}

balance=0;
lastPlace=System.currentTimeMillis();
setupPlace=System.currentTimeMillis();

}
//called if this is the first Bastion block created to set up the static variables
Expand Down Expand Up @@ -323,7 +330,7 @@ public boolean canPlace(String playerName){
}

//Take care of a block that should be removed from inside the field
public void handlePlaced(Block block,boolean handleRemoval) {
public void handlePlaced(Block block,boolean handleRemoval,String thePlayer) {
if(handleRemoval)
block.breakNaturally();

Expand All @@ -332,6 +339,17 @@ public void handlePlaced(Block block,boolean handleRemoval) {
reinforcement.setDurability(0);
Citadel.getReinforcementManager().addReinforcement(reinforcement);
}
for (BastionPlaces bp : myPlaces)
{
if (bp.player==thePlayer){
currentPlace=bp;
break;
}
}
if (currentPlace==null||currentPlace.player!=thePlayer){
currentPlace=new BastionPlaces(thePlayer,setupTime);
myPlaces.add(currentPlace);
}
erode(erosionFromPlace());
}

Expand Down Expand Up @@ -360,7 +378,7 @@ private void erode(double amount){
int wholeToRemove=(int) toBeRemoved;
double fractionToRemove=(double) toBeRemoved-wholeToRemove;

if((time-lastPlace)>=min_break_time){ //not still locked after last erosion
if((time-currentPlace.lastPlace)>=min_break_time){ //not still locked after last erosion
IReinforcement reinforcement = getReinforcement();

if (reinforcement != null) {
Expand All @@ -375,7 +393,7 @@ private void erode(double amount){

reinforcement.setDurability(strength);
Citadel.getReinforcementManager().addReinforcement(reinforcement);
lastPlace=time;
currentPlace.lastPlace=time;

}
set.updated(this);
Expand Down
4 changes: 2 additions & 2 deletions Bastion/src/isaac/bastion/manager/BastionBlockManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public boolean handleBucketPlace(PlayerBucketEmptyEvent event) {
Location location=added.getLocation();
BastionBlock blocking=getBlockingBastion(location,event.getPlayer().getName());
if(blocking!=null){
blocking.handlePlaced(added, false);
blocking.handlePlaced(added, false, event.getPlayer().getName());
event.setCancelled(true);
return true;
}
Expand Down Expand Up @@ -191,7 +191,7 @@ private boolean handleBlockPlace(Location loc, String player, boolean shouldHand
BastionBlock bastion=getBlockingBastion(loc,player);
if(bastion!=null){
if(shouldHandle){
bastion.handlePlaced(loc.getBlock(),true);
bastion.handlePlaced(loc.getBlock(),true,player);
}
if(bastion.shouldCull())
bastions.remove(bastion);
Expand Down