Skip to content

Commit

Permalink
added BuffTypes so now we have passive and continuous buffs
Browse files Browse the repository at this point in the history
added buffHandlers
multiple cellAffects for one cell
handled all cellAffects !
  • Loading branch information
Saee Saadat authored and Siniorss committed May 7, 2019
1 parent e81e046 commit a5f1931
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 32 deletions.
14 changes: 10 additions & 4 deletions duelyst/src/Model/Map/Cell.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

import Model.card.hermione.Hermione;

import java.util.ArrayList;


public class Cell {
private int x;
private int y;
private Hermione cardOnCell;
private boolean hasFlag = false;
private boolean isFull = false;
private CellAffects cellAffect = CellAffects.normal ;
private ArrayList<CellAffects> cellAffect = new ArrayList<>() ;

public Cell(int x, int y) {
this.x = x;
Expand Down Expand Up @@ -53,12 +55,16 @@ public void setFull(boolean full) {
isFull = full;
}

public CellAffects getCellAffect() {
public boolean isHasFlag() {
return hasFlag;
}

public ArrayList<CellAffects> getCellAffect() {
return cellAffect;
}

public void setCellAffect(CellAffects cellAffect) {
this.cellAffect = cellAffect;
public void addCellAffect(CellAffects cellAffect) {
this.cellAffect.add(cellAffect);
}

}
21 changes: 19 additions & 2 deletions duelyst/src/Model/Map/Map.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package Model.Map;

import Controller.Game;
import Model.account.Collection;
import Model.card.spell.Buff.Buff;
import Model.card.spell.Buff.BuffActions.BuffActionPoison;
import Model.card.spell.BuffTypes.BuffTypePassive;
import Model.item.Flag;
import exeption.InvalidCellException;

Expand Down Expand Up @@ -59,14 +63,27 @@ public ArrayList<Cell> getCells(){
return cells ;
}

public void applyFireCellAffect() {
public void handleFireCellAffect() {
for (Cell[] cellRow : this.board) {
for (Cell cell : cellRow) {
if (cell.getCellAffect() == CellAffects.fire) {
if (cell.getCellAffect().contains(CellAffects.fire)) {
cell.getCardOnCell().changeHealthPoint(-2);
}
}
}
}

public void handlePoisonCell() throws InvalidCellException{
for (Cell[] cellRow : this.board) {
for (Cell cell : cellRow) {
if (cell.getCellAffect().contains(CellAffects.poison)) {
Buff buff = new Buff(1 , false , BuffActionPoison.getBuffAction() , new BuffTypePassive());
buff.deploy(Game.battle.getPlayer() , cell.getCardOnCell());
}
}
}
}



}
16 changes: 9 additions & 7 deletions duelyst/src/Model/card/hermione/BuffEffectsOnHermione.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import Model.Map.Cell;
import Model.card.spell.SpellAction.ActionDeployPoison;
import Model.card.spell.Target;
import Model.card.spell.Targets.TargetRandom;
import Model.card.spell.Targets.TargetRandomEnemy;
import exeption.InvalidCellException;

Expand All @@ -12,7 +10,7 @@ public class BuffEffectsOnHermione {
private boolean hasTheDeathCurse = false ;
private int HollyBuffLevel = 0 ;
private int originalAttackPoint ;
private int lostHealthPointDueToBuff = 0 ;
private int changedHealthPointDueToBuff = 0 ;
private boolean hasTheGiantSnakeEffect = false ;
private boolean hasThePoisonousDagger = false ;

Expand Down Expand Up @@ -41,8 +39,8 @@ public int getOriginalAttackPoint() {
return originalAttackPoint;
}

public int getLostHealthPointDueToBuff() {
return lostHealthPointDueToBuff;
public int getChangedHealthPointDueToBuff() {
return changedHealthPointDueToBuff;
}

public void setHasTheDeathCurse(boolean hasTheDeathCurse) {
Expand All @@ -57,8 +55,12 @@ public void setOriginalAttackPoint(int originalAttackPoint) {
this.originalAttackPoint = originalAttackPoint;
}

public void setLostHealthPointDueToBuff(int lostHealthPointDueToBuff) {
this.lostHealthPointDueToBuff = lostHealthPointDueToBuff;
public void setChangedHealthPointDueToBuff(int changedHealthPointDueToBuff) {
this.changedHealthPointDueToBuff = changedHealthPointDueToBuff;
}

public void changeBackHealthPoint(){
this.card.changeHealthPoint(-changedHealthPointDueToBuff);
}

public boolean isHasTheGiantSnakeEffect() {
Expand Down
16 changes: 9 additions & 7 deletions duelyst/src/Model/card/hermione/Hermione.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import Controller.Game;
import Model.Map.Cell;
import Model.Map.CellAffects;
import Model.Map.Map;
import Model.card.Card;
import Model.card.spell.Buff.Buff;
Expand Down Expand Up @@ -59,6 +60,8 @@ public void attack(Hermione enemyCard) throws DestinationOutOfreachException, Ca
this.attackCounter++ ;
this.buffEffects.handle() ;
enemyCard.setHealthPoint(enemyCard.healthPoint-this.attackPoint);
if (enemyCard.getLocation().getCellAffect().contains(CellAffects.holly))
enemyCard.changeHealthPoint(1);
enemyCard.counterAttack(this);
if(enemyCard.getHealthPoint()<=0){
enemyCard.die();
Expand Down Expand Up @@ -108,11 +111,6 @@ public boolean move (int x, int y) throws MoveTrunIsOverException, DestinationOu

public abstract boolean applySpecialPower(int x, int y);// TODO: 4/15/19 saE

private void handleAppliedBuffs() throws InvalidCellException{
for (Buff appliedBuff : this.appliedBuffs) {
appliedBuff.affect();
}
}

public void spawn(Cell cell){
this.setLocation(cell);
Expand All @@ -128,7 +126,7 @@ public void reverseAP(){
}

public void reverseHP(){
this.healthPoint+=this.buffEffects.getLostHealthPointDueToBuff();
this.healthPoint+=this.buffEffects.getChangedHealthPointDueToBuff();
}


Expand Down Expand Up @@ -249,7 +247,7 @@ public void setHasTheDeathCurse(boolean hasTheDeathCurse) {
}

public void setLostHealthPointDueToBuff(int lostHealthPointDueToBuff) {
this.buffEffects.setLostHealthPointDueToBuff(lostHealthPointDueToBuff);
this.buffEffects.setChangedHealthPointDueToBuff(lostHealthPointDueToBuff);
}

public int getOriginalHealthPoint() {
Expand All @@ -259,4 +257,8 @@ public int getOriginalHealthPoint() {
public void setOriginalHealthPoint(int originalHealthPoint) {
this.originalHealthPoint = originalHealthPoint;
}

public BuffEffectsOnHermione getBuffEffects() {
return buffEffects;
}
}
37 changes: 28 additions & 9 deletions duelyst/src/Model/card/spell/Buff/Buff.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import Model.account.Player;
import Model.card.hermione.Hermione;
import Model.card.spell.Buff.BuffActions.BuffActions;
import Model.card.spell.BuffTypes.BuffTypes;
import exeption.BuffHasntBeenDeployedYetException;
import exeption.InvalidCellException;

import java.util.ArrayList;
Expand All @@ -15,13 +17,23 @@ public class Buff {
private Player player;
private BuffActions action;
private int perk ;
private BuffTypes buffType ;

public Buff(int duration, boolean isPositive, BuffActions action) {
this.action = action;
this.duration = duration;
this.isPositive = isPositive;
}

public Buff(int duration, boolean isPositive, BuffActions action, BuffTypes buffType) {
this.action = action;
this.duration = duration;
this.isPositive = isPositive;
this.buffType = buffType ;
this.buffType.setBuff(this);
}


public Buff(Buff buff){

}
Expand All @@ -39,22 +51,25 @@ public void deploy(Player player , Hermione target ) throws InvalidCellException
activeBuffs.add(this);
this.action.affect(this);
}
public void affect() throws InvalidCellException {
if (this.player == null || this.target == null || this.action == null) return;
public void affect() throws InvalidCellException , BuffHasntBeenDeployedYetException {
if (this.player == null || this.target == null || this.action == null)
throw new BuffHasntBeenDeployedYetException();
this.action.affect(this);
}

public void destroy(){
this.action.destroy(this) ;
activeBuffs.remove(this);
this.target.getAppliedBuffs().remove(this) ;
if(this.buffType.isShouldBeDispelled() || this.duration == 0) {
activeBuffs.remove(this);
this.target.getAppliedBuffs().remove(this);
}
}

public void nextTurnForBuffs(){
for (Buff buff : activeBuffs){
buff.duration -- ;
if (buff.duration == 0) buff.destroy();
}
public void handleBuffBeginningOfTurn() throws InvalidCellException , BuffHasntBeenDeployedYetException{
this.buffType.handleBeginningOfTheTurn();
}
public void handleBuffEndOfTurn() throws InvalidCellException{
this.buffType.handleEndOfTheTurn();
}

public int getPerk() {
Expand Down Expand Up @@ -97,6 +112,10 @@ public Hermione getTarget() {
public boolean isPositive() {
return isPositive;
}

public BuffTypes getBuffType() {
return buffType;
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ public void affect(Buff buff){
buff.getTarget().changeHealthPoint(buff.getPerk());
buff.getTarget().setLostHealthPointDueToBuff(buff.getPerk());
}

@Override
public void destroy(Buff buff) {
buff.getTarget().getBuffEffects().changeBackHealthPoint();
}
}
26 changes: 26 additions & 0 deletions duelyst/src/Model/card/spell/BuffTypes/BuffTypeContinuous.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package Model.card.spell.BuffTypes;

import Model.card.spell.Buff.Buff;
import exeption.BuffHasntBeenDeployedYetException;
import exeption.InvalidCellException;

public class BuffTypeContinuous extends BuffTypes{
public BuffTypeContinuous() {
shouldBeDispelled = false ;
}

@Override
public void handleBeginningOfTheTurn() throws InvalidCellException, BuffHasntBeenDeployedYetException {
if (buff.getDuration()==0) {
buff.destroy();
return ;
}
buff.reduceDuration();
buff.affect();
}

@Override
public void handleEndOfTheTurn() throws InvalidCellException{
buff.destroy();
}
}
22 changes: 22 additions & 0 deletions duelyst/src/Model/card/spell/BuffTypes/BuffTypePassive.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package Model.card.spell.BuffTypes;

import Model.card.spell.Buff.Buff;
import exeption.BuffHasntBeenDeployedYetException;
import exeption.InvalidCellException;

public class BuffTypePassive extends BuffTypes{
private static BuffTypePassive obj ;

public BuffTypePassive() {
shouldBeDispelled = false ;
}

@Override
public void handleBeginningOfTheTurn() throws InvalidCellException, BuffHasntBeenDeployedYetException {
}

@Override
public void handleEndOfTheTurn() throws InvalidCellException{
buff.destroy();
}
}
33 changes: 33 additions & 0 deletions duelyst/src/Model/card/spell/BuffTypes/BuffTypes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package Model.card.spell.BuffTypes;

import Model.card.spell.Buff.Buff;
import exeption.BuffHasntBeenDeployedYetException;
import exeption.InvalidCellException;

import java.util.ArrayList;

public abstract class BuffTypes {
protected Buff buff ;
protected static ArrayList<Buff> buffs = new ArrayList<>() ;
protected boolean shouldBeDispelled = true ;

public void setBuff(Buff buff) {
this.buff = buff;
}

public static ArrayList<Buff> getBuffs() {
return buffs;
}

public boolean isShouldBeDispelled() {
return shouldBeDispelled;
}

public static void addToBuffs(Buff buff){
buffs.add(buff) ;
}
public abstract void handleBeginningOfTheTurn() throws InvalidCellException , BuffHasntBeenDeployedYetException;

public abstract void handleEndOfTheTurn() throws InvalidCellException;
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static ActionApplyFirecell getAction() {
@Override
public void deploy(Spell spell, Cell... cells) {
for (Cell cell : cells) {
cell.setCellAffect(CellAffects.fire);
cell.addCellAffect(CellAffects.fire);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static ActionHollyCell getAction() {
@Override
public void deploy(Spell spell, Cell... cells) throws InvalidCellException {
for (Cell cell : cells) {
cell.setCellAffect(CellAffects.holly);
cell.addCellAffect(CellAffects.holly);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static ActionPoisonCell getAction() {
@Override
public void deploy(Spell spell, Cell... cells) {
for (Cell cell : cells) {
cell.setCellAffect(CellAffects.poison);
cell.addCellAffect(CellAffects.poison);
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions duelyst/src/exeption/BuffHasntBeenDeployedYetException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package exeption;

public class BuffHasntBeenDeployedYetException extends Exception {

public BuffHasntBeenDeployedYetException(String message) {
super(message);
}

public BuffHasntBeenDeployedYetException() {
}
}

0 comments on commit a5f1931

Please sign in to comment.