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

[ai] Add getActions() #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
64 changes: 63 additions & 1 deletion src/main/java/com/leekwars/generator/FightConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.leekwars.generator.attack.Attack;
import com.leekwars.generator.attack.effect.Effect;
import com.leekwars.generator.fight.Fight;
import com.leekwars.generator.fight.action.Action;
import com.leekwars.generator.fight.action.DamageType;

import leekscript.common.Type;
import leekscript.runner.ILeekConstant;
Expand Down Expand Up @@ -104,6 +106,8 @@ public enum FightConstants implements ILeekConstant {
EFFECT_REPEL(Effect.TYPE_REPEL, Type.INT),
EFFECT_RAW_RELATIVE_SHIELD(Effect.TYPE_RAW_RELATIVE_SHIELD, Type.INT),
EFFECT_ALLY_KILLED_TO_AGILITY(Effect.TYPE_ALLY_KILLED_TO_AGILITY, Type.INT),
EFFECT_KILL_TO_TP(Effect.TYPE_KILL_TO_TP, Type.INT),
EFFECT_RAW_HEAL(Effect.TYPE_RAW_HEAL, Type.INT),

// Résultats attaque
USE_CRITICAL(2, Type.INT),
Expand Down Expand Up @@ -150,6 +154,8 @@ public enum FightConstants implements ILeekConstant {
WEAPON_SWORD(185, Type.INT),
WEAPON_HEAVY_SWORD(186, Type.INT),
WEAPON_DARK_KATANA(187, Type.INT),
WEAPON_ENHANCED_LIGHTNINGER(225, Type.INT),
WEAPON_UNSTABLE_DESTROYER(226, Type.INT),

// Messages
MESSAGE_HEAL(1, Type.INT),
Expand Down Expand Up @@ -314,7 +320,63 @@ public enum FightConstants implements ILeekConstant {
FIGHT_CONTEXT_BATTLE_ROYALE(Fight.CONTEXT_BATTLE_ROYALE, Type.INT),

SUMMON_LIMIT(Fight.SUMMON_LIMIT, Type.INT),
CRITICAL_FACTOR(Effect.CRITICAL_FACTOR, Type.REAL);
CRITICAL_FACTOR(Effect.CRITICAL_FACTOR, Type.REAL),

// Actions
ACTION_START_FIGHT(Action.START_FIGHT, Type.INT),
ACTION_USE_WEAPON(Action.USE_WEAPON, Type.INT),
ACTION_USE_CHIP(Action.USE_CHIP, Type.INT),
ACTION_SET_WEAPON(Action.SET_WEAPON, Type.INT),
ACTION_END_FIGHT(Action.END_FIGHT, Type.INT),
ACTION_PLAYER_DEAD(Action.PLAYER_DEAD, Type.INT),
ACTION_NEW_TURN(Action.NEW_TURN, Type.INT),
ACTION_LEEK_TURN(Action.LEEK_TURN, Type.INT),
ACTION_END_TURN(Action.END_TURN, Type.INT),
ACTION_SUMMON(Action.SUMMON, Type.INT),
ACTION_MOVE_TO(Action.MOVE_TO, Type.INT),
ACTION_KILL(Action.KILL, Type.INT),

// Buffs
ACTION_TP_LOST(Action.LOST_PT, Type.INT),
ACTION_LIFE_LOST(Action.LOST_LIFE, Type.INT),
ACTION_MP_LOST(Action.LOST_PM, Type.INT),
ACTION_HEAL(Action.HEAL, Type.INT),
ACTION_VITALITY(Action.VITALITY, Type.INT),
ACTION_RESURRECT(Action.RESURRECT, Type.INT),
ACTION_LOSE_STRENGTH(Action.LOSE_STRENGTH, Type.INT),
ACTION_NOVA_DAMAGE(Action.NOVA_DAMAGE, Type.INT),
ACTION_DAMAGE_RETURN(Action.DAMAGE_RETURN, Type.INT),
ACTION_LIFE_DAMAGE(Action.LIFE_DAMAGE, Type.INT),
ACTION_POISON_DAMAGE(Action.POISON_DAMAGE, Type.INT),
ACTION_AFTEREFFECT(Action.AFTEREFFECT, Type.INT),
ACTION_NOVA_VITALITY(Action.NOVA_VITALITY, Type.INT),

// "fun" actions
ACTION_SAY(Action.SAY, Type.INT),
ACTION_LAMA(Action.LAMA, Type.INT),
ACTION_SHOW_CELL(Action.SHOW_CELL, Type.INT),

// Effects
ACTION_ADD_WEAPON_EFFECT(Action.ADD_WEAPON_EFFECT, Type.INT),
ACTION_ADD_CHIP_EFFECT(Action.ADD_CHIP_EFFECT, Type.INT),
ACTION_REMOVE_EFFECT(Action.REMOVE_EFFECT, Type.INT),
ACTION_UPDATE_EFFECT(Action.UPDATE_EFFECT, Type.INT),
ACTION_ADD_STACKED_EFFECT(Action.ADD_STACKED_EFFECT, Type.INT),
ACTION_REDUCE_EFFECTS(Action.REDUCE_EFFECTS, Type.INT),
ACTION_REMOVE_POISONS(Action.REMOVE_POISONS, Type.INT),
ACTION_REMOVE_SHACKLES(Action.REMOVE_SHACKLES, Type.INT),

// Other
ACTION_ERROR(Action.ERROR, Type.INT),
ACTION_MAP(Action.MAP, Type.INT),
ACTION_AI_ERROR(Action.AI_ERROR, Type.INT),

ACTION_DAMAGE_TYPE_DIRECT(DamageType.DIRECT.value, Type.INT),
ACTION_DAMAGE_TYPE_NOVA(DamageType.NOVA.value, Type.INT),
ACTION_DAMAGE_TYPE_RETURN(DamageType.RETURN.value, Type.INT),
ACTION_DAMAGE_TYPE_LIFE(DamageType.LIFE.value, Type.INT),
ACTION_DAMAGE_TYPE_POISON(DamageType.POISON.value, Type.INT),
ACTION_DAMAGE_TYPE_AFTEREFFECT(DamageType.AFTEREFFECT.value, Type.INT);

private double value;
private Type type;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/leekwars/generator/FightFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,12 @@ public Object run(AI ai, ILeekFunction function, Object... parameters) throws Le
return null;
}
},
getActions(0) {
@Override
public Object run(AI ai, ILeekFunction function, Object... parameters) throws LeekRunException {
return ((EntityAI) ai).getActions();
}
},
getRegisters(0) {
@Override
public Object run(AI ai, ILeekFunction function, Object... parameters) throws LeekRunException {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/leekwars/generator/attack/chips/Chips.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@
public class Chips {

private static Map<Integer, Chip> chips = new TreeMap<Integer, Chip>();
private static Map<Integer, Chip> template2chips = new TreeMap<Integer, Chip>();

public static void addChip(Chip chip) {
chips.put(chip.getId(), chip);
template2chips.put(chip.getTemplate(), chip);
Items.addChip(chip.getId());
}

public static Chip getChipFromTemplate(int template) {
return template2chips.get(template);
}

public static Chip getChip(int id) {
return chips.get(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public abstract class Effect {
public final static int TYPE_REPEL = 53;
public final static int TYPE_RAW_RELATIVE_SHIELD = 54;
public final static int TYPE_ALLY_KILLED_TO_AGILITY = 55;
public final static int TYPE_KILL_TO_TP = 56;
public final static int TYPE_RAW_HEAL = 57;
public final static int TYPE_CRITICAL_TO_HEAL = 58;

// Target filters constants
public final static int TARGET_ENEMIES = 1; // Enemies
Expand Down Expand Up @@ -146,6 +149,8 @@ public abstract class Effect {
EffectRepel.class, // 53
EffectRawRelativeShield.class, // 54
null, // 55
null, // 56
EffectRawHeal.class, // 57
};

// Effect characteristics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void apply(Fight fight) {
target.onNovaDamage(erosion);

// Life steal
if (!caster.isDead() && lifeSteal > 0) {
if (!caster.isDead() && lifeSteal > 0 && caster.getLife() < caster.getTotalLife()) {

if (caster.getLife() + lifeSteal > caster.getTotalLife()) {
lifeSteal = caster.getTotalLife() - caster.getLife();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.leekwars.generator.attack.effect;

import com.leekwars.generator.fight.Fight;
import com.leekwars.generator.fight.action.ActionHeal;

public class EffectRawHeal extends Effect {

@Override
public void apply(Fight fight) {

value = (int) Math.round((value1 + jet * value2) * aoe * criticalPower * targetCount);

if (target.getLife() + value > target.getTotalLife()) {
value = target.getTotalLife() - target.getLife();
}
fight.log(new ActionHeal(target, value));
target.addLife(caster, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@
public class Weapons {

private static Map<Integer, Weapon> weapons = new TreeMap<Integer, Weapon>();
private static Map<Integer, Weapon> template2weapons = new TreeMap<Integer, Weapon>();

public static void addWeapon(Weapon weapon) {
weapons.put(weapon.getId(), weapon);
template2weapons.put(weapon.getTemplate(), weapon);
Items.addWeapon(weapon.getId());
}

public static Weapon getWeaponFromTemplate(int template) {
return template2weapons.get(template);
}

public static Weapon getWeapon(int id) {
return weapons.get(id);
}
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/com/leekwars/generator/fight/Fight.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public int getInt(int min, int max) {
private int context;
private int type;

JSONObject custom_map = null;
public JSONObject custom_map = null;
public StatisticsManager statistics;
private RegisterManager registerManager;
public long executionTime = 0;
Expand Down Expand Up @@ -565,6 +565,11 @@ public void onPlayerDie(Entity entity, Entity killer) {
ally.onAllyKilled();
}
}

// Passive effect kill
if (killer != null) {
killer.onKill();
}
}

/*
Expand Down Expand Up @@ -643,6 +648,7 @@ public int useWeapon(Entity launcher, Cell target) {
var cellEntity = target.getPlayer();
ActionUseWeapon log_use = new ActionUseWeapon(launcher, target, weapon, result);
actions.log(log_use);
if (critical) launcher.onCritical();
List<Entity> target_leeks = weapon.getAttack().applyOnCell(this, launcher, target, critical);
log_use.setEntities(target_leeks);
statistics.useWeapon(launcher, weapon, target, target_leeks, cellEntity);
Expand Down Expand Up @@ -690,6 +696,7 @@ public int useChip(Entity caster, Cell target, Chip template) {
var cellEntity = target.getPlayer();
ActionUseChip log = new ActionUseChip(caster, target, template, result);
actions.log(log);
if (critical) caster.onCritical();
List<Entity> targets = template.getAttack().applyOnCell(this, caster, target, critical);
log.setEntities(targets);
statistics.useChip(caster, template, target, targets, cellEntity);
Expand Down Expand Up @@ -821,6 +828,7 @@ public int summonEntity(Entity caster, Cell target, Chip template, FunctionLeekV

ActionUseChip log = new ActionUseChip(caster, target, template, result);
actions.log(log);
if (critical) caster.onCritical();

// On invoque
Entity summon = createSummon(caster, (int) params.getValue1(), target, value, template.getLevel(), critical);
Expand Down Expand Up @@ -871,6 +879,7 @@ public int resurrectEntity(Entity caster, Cell target, Chip template, Entity tar

ActionUseChip log = new ActionUseChip(caster, target, template, result);
actions.log(log);
if (critical) caster.onCritical();

// Resurrect
resurrect(caster, target_entity, target, critical);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class ActionEntityTurn implements Action {

private final int id;
public final int id;

public ActionEntityTurn(Entity leek) {
if (leek == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

public class ActionUseChip implements Action {

private final int caster;
private final int cell;
private final int chip;
private final int success;
private int[] leeks;
public final int caster;
public final int cell;
public final int chip;
public final int success;
public int[] leeks;

public ActionUseChip(Entity caster, Cell cell, Chip chip, int success) {
this.caster = caster.getFId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

public class ActionUseWeapon implements Action {

private final int caster;
private final int cell;
private final int weapon;
private final int success;
private int[] leeks;
public final int caster;
public final int cell;
public final int weapon;
public final int success;
public int[] leeks;

public ActionUseWeapon(Entity caster, Cell cell, Weapon weapon, int success) {

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/leekwars/generator/fight/action/Actions.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.leekwars.generator.fight.action;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
Expand All @@ -27,6 +28,21 @@ public Actions() {
this.actions = new ArrayList<Action>();
}

public List<Action> getActionsAfter(int leekId) {
List<Action> result = new ArrayList<Action>();
int i = this.actions.size() - 1;
for (; i >= 0; i--) {
result.add(this.actions.get(i));
if (this.actions.get(i) instanceof ActionEntityTurn) {
if (((ActionEntityTurn) this.actions.get(i)).id == leekId) {
break;
}
}
}
Collections.reverse(result);
return result;
}

public int getEffectId() {
return mNextEffectId++;
}
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/com/leekwars/generator/fight/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,22 @@ public void onAllyKilled() {
}
}

public void onCritical() {
for (Weapon weapon : mWeapons) {
for (EffectParameters effect : weapon.getPassiveEffects()) {
activateOnCriticalPassiveEffect(effect, weapon.getAttack());
}
}
}

public void onKill() {
for (Weapon weapon : mWeapons) {
for (EffectParameters effect : weapon.getPassiveEffects()) {
activateOnKillPassiveEffect(effect, weapon.getAttack());
}
}
}

public void activateOnMovedPassiveEffect(EffectParameters effect, Attack attack) {
if (effect.getId() == Effect.TYPE_MOVED_TO_MP) {
double value = effect.getValue1();
Expand Down Expand Up @@ -529,6 +545,24 @@ public void activateOnAllyKilledPassiveEffect(EffectParameters effect, Attack at
}
}

public void activateOnCriticalPassiveEffect(EffectParameters effect, Attack attack) {
if (effect.getId() == Effect.TYPE_CRITICAL_TO_HEAL) {
if (this.getLife() < this.getTotalLife()) {
double value1 = effect.getValue1();
double value2 = effect.getValue2();
double jet = fight.getRandom().getDouble();
Effect.createEffect(this.fight, Effect.TYPE_RAW_HEAL, 0, 1, value1, value2, false, this, this, attack, jet, false, 0, 1, 0, effect.getModifiers());
}
}
}

public void activateOnKillPassiveEffect(EffectParameters effect, Attack attack) {
if (effect.getId() == Effect.TYPE_KILL_TO_TP) {
double value = effect.getValue1();
Effect.createEffect(this.fight, Effect.TYPE_RAW_BUFF_TP, effect.getTurns(), 1, value, value, false, this, this, attack, 0, true, 0, 1, 0, effect.getModifiers());
}
}

public void addLife(Entity healer, int pv) {
if (pv > getTotalLife() - life) {
pv = getTotalLife() - life;
Expand Down
Loading