Commit 0fed7da0 authored by Mathieu Hilaire's avatar Mathieu Hilaire

enemies spawn gold at death

parent c2163620
# Fichier contenant l'ensemble des species du jeu.
# Nombre de species total
8
9
#Ronflex - Character
C
......@@ -308,4 +308,32 @@ TRIGGER_DEGAT_LP
#abilityList
1
TEST_SUICIDE
#--------------------------------------------------------------------
#Gold - Entity
E
#name
Gold
#tilePropertyVector
2
SOLID
LIQUID
#collisionBox
R
15
15
#visilibity
R
200
200
#entityDisplayerType
FIREBOLT
#triggers
1
#trigger function
DEFAULT_TRIGGER
#effect descriptor
1
TRAP_TRIGGER
#abilityList
0
......@@ -269,6 +269,29 @@ public class EffectBuilder implements Serializable{
}
};
}
Effect trigger_gold() {
return new Effect() {
private static final long serialVersionUID = 1L;
@Override
public void effect(List<Integer> targetCharacterIDList, GameContent gameContent, int casterCharacterID) throws InterruptedException {
boolean hit = false;
for (Integer targetID : targetCharacterIDList) {
try {
if(gameContent.getGameState().getEntity(casterCharacterID).getOwned_character() != targetID) {
gameContent.getGameState().getCharacter(targetID).takeDamage(Math.max(1, 0));
hit =true;
}
} catch (EntityNotFoundExeption entityNotFoundExeption) {
}
}
if(hit){
Event event = new AbilityEvent(casterCharacterID, 0);
DummyLocalGameLoop.getInstance().getNetworkConnection().sendEvent(event);
}
}
};
}
/** Methods to be applied on an Effect to transform it into another one **/
......
......@@ -96,6 +96,15 @@ public final class EffectGeneratorRoster {
eb.trigger_degat_lp()));
};
effectFactory.registerEffectGenerator(EffectKey.TRIGGER_DEGAT_LP, effectGenerator);
effectGenerator =
(casterCharacterID, parameters) -> {
return eb.affectZone((character -> character.getHitbox()),
eb.filter( CommonCharacterIDListFilter.allExceptOne(casterCharacterID),
eb.trigger_gold()));
};
effectFactory.registerEffectGenerator(EffectKey.TRIGGER_GOLD, effectGenerator);
}
}
......@@ -16,7 +16,9 @@ public enum EffectKey {
TRAP_TRIGGER(0),
TRIGGER_DEGAT(0),
TRIGGER_DEGAT_LP(0),
MENTALI_ATTACK_DAMAGE(2);
MENTALI_ATTACK_DAMAGE(2),
TRIGGER_GOLD(0),
SPAWN_GOLD(1);
private EffectKey(int parameterNb) {
this.parameterNb = parameterNb;
......
package core.event;
import core.abilities.effects.Effect;
import core.gamestate.*;
import core.gamestate.Character;
import core.relayer.RelayerEntity;
import core.zone.Direction;
import core.zone.Point;
import core.zone.Translation;
import gameloop.DummyLocalGameLoop;
import java.util.List;
/**
* Created by hilaire on 06/01/16.
*
* this event is used when some Gold is created
*/
public class SpawnGold implements ClientEvent,ServerEvent {
private static final long serialVersionUID = 1L;
private int targetID;
public SpawnGold(int targetID){
this.targetID=targetID;
}
@Override
public boolean execute(GameContent gameContent) throws InterruptedException {
Entity target = null;
try {
target = gameContent.getGameState().getEntity(targetID);
Character charac = null;
try {
charac = gameContent.getGameState().getCharacter(targetID);
} catch (EntityNotFoundExeption entityNotFoundExeption) {
return false;
}
Entity entity = SpeciesArray.create(charac.getX(), charac.getY(), 0, "Gold", "Gold");
entity.setOrientation(charac.getOrientation());
entity.setSpeed(0);
entity.setOwned_character(targetID);
gameContent.getGameState().addEntity(entity);
gameContent.addTriggerToCheck(entity);
RelayerEntity relayer = new RelayerEntity(entity.getID(),entity,gameContent);
entity.setRelayer(relayer);
if(DummyLocalGameLoop.getInstance().getFollowedRelayer().getDirection() != Direction.NONE) {
relayer.move(DummyLocalGameLoop.getInstance().getFollowedRelayer().getDirection());
}
else{
relayer.move(charac.getDirection());
}
relayer.start();
return true;
} catch (EntityNotFoundExeption entityNotFoundExeption) {
return true;
}
}
@Override
public Event resolve(GameContent gameContent) {
return this;
}
}
\ No newline at end of file
......@@ -6,7 +6,9 @@ import java.util.Objects;
import java.util.logging.Logger;
import core.abilities.Ability;
import core.abilities.effects.EffectBuilder;
import core.event.Event;
import core.event.SpawnGold;
import core.event.ToServerDeathEvent;
import core.zone.Zone;
import gameloop.DummyLocalGameLoop;
......@@ -153,6 +155,14 @@ public class Being extends Entity {
} else {
LOGGER.info("Death of "+this.getID()+" is send");
network.sendEvent(event);
}
Event event2 = new SpawnGold(this.getID());
if (network==null){
LOGGER.severe("NetworkConnection null, GOld"+this.getID()+" can't be created");
} else {
LOGGER.info("Gold creation by " + this.getID() + " is send");
network.sendEvent(event2);
}
}
......
......@@ -29,6 +29,8 @@ public final class Character extends Being {
*/
private int intel;
private int gold;
/**
* ????
*/
......@@ -82,6 +84,23 @@ public final class Character extends Being {
return intel;
}
/**
* Returns the character's gold value.
* @return the character's gold value.
*/
public int getGold() {
return gold;
}
/**
* Returns the character's gold value.
* @return the character's gold value.
*/
public void setGold( int gold2) {
this.gold = gold2;
}
/**
* ????
* @return
......
......@@ -6,7 +6,7 @@ package graphics.display_test;
import artificial_intelligence.AIControler;
import artificial_intelligence.AIEntities.AgressiveEntity;
import artificial_intelligence.AIEntities.EnumBehaviourType;
import com.sun.javafx.scene.traversal.Direction;
/** import com.sun.javafx.scene.traversal.Direction; had to comment because it led to error in compilation for me **/
import gameloop.DummyLocalGameLoop;
import gameloop.GameStarter;
import graphics.graphical_abstraction.GraphicsMasterAbstraction;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment