Skip to content

Commit

Permalink
fix birth turn
Browse files Browse the repository at this point in the history
  • Loading branch information
5pilow committed Aug 31, 2023
1 parent 1d2e478 commit c8eff18
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/leekwars/generator/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public Outcome runScenario(Scenario scenario, FightListener listener, RegisterMa
var entity = entityInfo.createEntity(this, scenario, fight);
fight.getState().addEntity(t, entity);
entity.setFight(fight);
entity.setBirthTurn(1);

// Resolve AI
entity.setLogs(new LeekLog(outcome.logs.get(aiOwner), entity));
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/leekwars/generator/classes/EntityClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -903,16 +903,16 @@ public static Boolean isSummon(EntityAI ai, Object value) throws LeekRunExceptio
}

public static long getBirthTurn(EntityAI ai) throws LeekRunException {
return (long) ai.getBirthTurn();
return (long) ai.getEntity().getBirthTurn();
}

public static Long getBirthTurn(EntityAI ai, Object value) throws LeekRunException {
if (value == null)
return (long) ai.getBirthTurn();
return (long) ai.getEntity().getBirthTurn();
if (value instanceof Number) {
var l = ai.getFight().getEntity(((Number) value).intValue());
if (l != null && l.getAI() != null)
return (long) ((EntityAI) l.getAI()).getBirthTurn();
if (l != null)
return (long) l.getBirthTurn();
}
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/leekwars/generator/fight/Fight.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ public void startTurn() throws Exception {
var ai = (EntityAI) current.getAI();
if (ai != null) {
if (ai.isValid()) {
ai.setEntity(current);

// System.out.println("Run " + current.getName() + " ai...");
long startTime = System.nanoTime();
ai.runTurn(state.getOrder().getTurn());
Expand Down Expand Up @@ -321,6 +323,8 @@ public int summonEntity(Entity caster, Cell target, Chip template, FunctionLeekV
// On assigne l'ia de l'invocation
if (result > 0) {
var summon = state.getLastEntity();
summon.setFight(this);
summon.setBirthTurn(getTurn());
summon.setAI(new BulbAI(summon, (EntityAI) caster.getAI(), value));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public BulbAI(Entity entity, EntityAI owner_ai, FunctionLeekValue ai) {
valid = true;
mAIFunction = ai;
setFight(owner_ai.fight);
mBirthTurn = fight.getTurn();
mOwnerAI = owner_ai;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.leekwars.generator.action.ActionAIError;
import com.leekwars.generator.effect.Effect;
Expand Down Expand Up @@ -76,7 +74,6 @@ public GenericArrayLeekValue getArray(EntityAI ai) throws LeekRunException {
protected Entity mEntity;
protected Fight fight;
protected final static boolean LOG_IA = true;
protected int mBirthTurn = 1;

protected long mIARunTime = 0;
protected long mIACpuRunTime = 0;
Expand Down Expand Up @@ -414,10 +411,6 @@ public Object runIA() throws LeekRunException {
return null;
}

public int getBirthTurn() {
return mBirthTurn;
}

public List<LeekMessage> getMessages() {
return mMessages;
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/leekwars/generator/state/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public abstract class Entity {
protected long totalOperations = 0;
public int saysTurn = 0;
public int showsTurn = 0;
protected int mBirthTurn = 1;

// Current effects on the entity
protected final ArrayList<Effect> effects = new ArrayList<Effect>();
Expand Down Expand Up @@ -1095,4 +1096,12 @@ public void addState(EntityState state) {
public Set<EntityState> getStates() {
return this.states;
}

public void setBirthTurn(int birthTurn) {
mBirthTurn = birthTurn;
}

public int getBirthTurn() {
return mBirthTurn;
}
}

0 comments on commit c8eff18

Please sign in to comment.