Skip to content

Commit

Permalink
t
Browse files Browse the repository at this point in the history
  • Loading branch information
5pilow committed Dec 8, 2023
1 parent cf6dea8 commit 9d762e9
Show file tree
Hide file tree
Showing 47 changed files with 586 additions and 92 deletions.
2 changes: 1 addition & 1 deletion data/chips.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion leekscript
Submodule leekscript updated 71 files
+12 −0 src/main/java/leekscript/Util.java
+13 −7 src/main/java/leekscript/common/ClassType.java
+6 −0 src/main/java/leekscript/common/Error.java
+1 −0 src/main/java/leekscript/common/FunctionType.java
+60 −0 src/main/java/leekscript/common/IntervalType.java
+2 −2 src/main/java/leekscript/common/MapType.java
+56 −0 src/main/java/leekscript/common/SetType.java
+13 −7 src/main/java/leekscript/common/Type.java
+0 −3 src/main/java/leekscript/common/VersionsType.java
+9 −0 src/main/java/leekscript/compiler/IACompiler.java
+9 −7 src/main/java/leekscript/compiler/JavaWriter.java
+158 −11 src/main/java/leekscript/compiler/LexicalParser.java
+5 −0 src/main/java/leekscript/compiler/LexicalParserTokenStream.java
+0 −8 src/main/java/leekscript/compiler/Location.java
+67 −1 src/main/java/leekscript/compiler/TokenType.java
+344 −187 src/main/java/leekscript/compiler/WordCompiler.java
+7 −0 src/main/java/leekscript/compiler/bloc/ClassMethodBlock.java
+1 −2 src/main/java/leekscript/compiler/bloc/ConditionalBloc.java
+1 −2 src/main/java/leekscript/compiler/bloc/DoWhileBlock.java
+1 −2 src/main/java/leekscript/compiler/bloc/ForBlock.java
+1 −2 src/main/java/leekscript/compiler/bloc/ForeachBlock.java
+1 −2 src/main/java/leekscript/compiler/bloc/ForeachKeyBlock.java
+5 −5 src/main/java/leekscript/compiler/bloc/MainLeekBlock.java
+1 −2 src/main/java/leekscript/compiler/bloc/WhileBlock.java
+4 −0 src/main/java/leekscript/compiler/expression/Expression.java
+1 −1 src/main/java/leekscript/compiler/expression/LeekArrayAccess.java
+29 −10 src/main/java/leekscript/compiler/expression/LeekExpression.java
+20 −17 src/main/java/leekscript/compiler/expression/LeekFunctionCall.java
+87 −13 src/main/java/leekscript/compiler/expression/LeekInterval.java
+9 −1 src/main/java/leekscript/compiler/expression/LeekNumber.java
+1 −0 src/main/java/leekscript/compiler/expression/LeekObject.java
+13 −2 src/main/java/leekscript/compiler/expression/LeekObjectAccess.java
+103 −0 src/main/java/leekscript/compiler/expression/LeekSet.java
+6 −0 src/main/java/leekscript/compiler/expression/LeekTernaire.java
+50 −15 src/main/java/leekscript/compiler/expression/LeekVariable.java
+12 −1 src/main/java/leekscript/compiler/instruction/ClassDeclarationInstruction.java
+1 −2 src/main/java/leekscript/compiler/instruction/LeekBreakInstruction.java
+1 −2 src/main/java/leekscript/compiler/instruction/LeekContinueInstruction.java
+1 −1 src/main/java/leekscript/compiler/instruction/LeekGlobalDeclarationInstruction.java
+131 −84 src/main/java/leekscript/runner/AI.java
+55 −6 src/main/java/leekscript/runner/LeekFunctions.java
+5 −0 src/main/java/leekscript/runner/LeekOperations.java
+18 −17 src/main/java/leekscript/runner/LeekValueManager.java
+6 −5 src/main/java/leekscript/runner/classes/NumberClass.java
+4 −0 src/main/java/leekscript/runner/classes/StandardClass.java
+6 −6 src/main/java/leekscript/runner/values/ArrayLeekValue.java
+2 −2 src/main/java/leekscript/runner/values/Box.java
+14 −6 src/main/java/leekscript/runner/values/ClassLeekValue.java
+5 −2 src/main/java/leekscript/runner/values/FunctionLeekValue.java
+1 −1 src/main/java/leekscript/runner/values/GenericArrayLeekValue.java
+1 −1 src/main/java/leekscript/runner/values/GenericMapLeekValue.java
+409 −0 src/main/java/leekscript/runner/values/IntegerIntervalLeekValue.java
+22 −81 src/main/java/leekscript/runner/values/IntervalLeekValue.java
+6 −53 src/main/java/leekscript/runner/values/LeekValue.java
+62 −0 src/main/java/leekscript/runner/values/LeekValueType.java
+20 −20 src/main/java/leekscript/runner/values/LegacyArrayLeekValue.java
+36 −38 src/main/java/leekscript/runner/values/MapLeekValue.java
+1 −1 src/main/java/leekscript/runner/values/ObjectLeekValue.java
+323 −0 src/main/java/leekscript/runner/values/RealIntervalLeekValue.java
+229 −0 src/main/java/leekscript/runner/values/SetLeekValue.java
+2 −0 src/test/java/test/TestFunction.java
+15 −28 src/test/java/test/TestGeneral.java
+14 −0 src/test/java/test/TestGlobals.java
+203 −50 src/test/java/test/TestInterval.java
+3 −3 src/test/java/test/TestJSON.java
+4 −4 src/test/java/test/TestLoops.java
+1 −0 src/test/java/test/TestMain.java
+1 −0 src/test/java/test/TestMap.java
+14 −6 src/test/java/test/TestNumber.java
+19 −16 src/test/java/test/TestObject.java
+117 −0 src/test/java/test/TestSet.java
19 changes: 14 additions & 5 deletions src/main/java/com/leekwars/generator/Data.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.leekwars.generator;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
Expand All @@ -24,24 +25,27 @@ public class Data {
public static List<LocalDate> fullmoon = new ArrayList<>();

public static void checkData(String api) {
Log.i(TAG, "Check api: " + api);

new File("data").mkdir();

System.out.println("Check api: " + api);
// File weaponsFile = new File("data/weapons.json");
Log.i(TAG, "Load weapons from API...");
System.out.println("Load weapons from API...");
JSONObject weapons = JSON.parseObject(get(api + "weapon/get-all", "")).getJSONObject("weapons");
Util.writeFile(weapons.toJSONString(), "data/weapons.json");

// File chipsFile = new File("data/chips.json");
Log.i(TAG, "Load chips from API...");
System.out.println("Load chips from API...");
JSONObject chips = JSON.parseObject(get(api + "chip/get-all", "")).getJSONObject("chips");
Util.writeFile(chips.toJSONString(), "data/chips.json");

// File summonsFile = new File("data/summons.json");
Log.i(TAG, "Load summons from API...");
System.out.println("Load summons from API...");
JSONObject summons = JSON.parseObject(get(api + "summon/get-templates", "")).getJSONObject("summon_templates");
Util.writeFile(summons.toJSONString(), "data/summons.json");

// File fullmoonFile = new File("data/fullmoon.json");
Log.i(TAG, "Load fullmoon from API...");
System.out.println("Load fullmoon from API...");
JSONArray f = JSON.parseArray(get(api + "fight/fullmoon", ""));
for (var d : f) {
var dateUTC = ZonedDateTime.of(LocalDateTime.parse((String) d), ZoneOffset.UTC);
Expand All @@ -50,6 +54,11 @@ public static void checkData(String api) {
}
// System.out.println("full moon = " + fullmoon);
Util.writeFile(f.toJSONString(), "data/fullmoon.json");

// TODO
System.out.println("Load components from API...");
JSONObject components = JSON.parseObject(get(api + "component/get-all/dfgdfgzegktyrtytm", ""));
Util.writeFile(components.toJSONString(), "data/components.json");
}

private static String get(String url, String urlParameters) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/leekwars/generator/FightConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public enum FightConstants implements ILeekConstant {
ENTITY_BULB(2, Type.INT),
ENTITY_TURRET(3, Type.INT),
ENTITY_CHEST(4, Type.INT),
ENTITY_MOB(5, Type.INT),

// Constants
EFFECT_TARGET_ALLIES(Effect.TARGET_ALLIES, Type.INT),
Expand Down Expand Up @@ -109,8 +110,10 @@ public enum FightConstants implements ILeekConstant {
EFFECT_KILL_TO_TP(Effect.TYPE_KILL_TO_TP, Type.INT),
EFFECT_RAW_HEAL(Effect.TYPE_RAW_HEAL, Type.INT),
EFFECT_CRITICAL_TO_HEAL(Effect.TYPE_CRITICAL_TO_HEAL, Type.INT),
EFFECT_ADD_STATE(Effect.TYPE_ADD_STATE, Type.INT),

STATE_UNHEALABLE(EntityState.UNHEALABLE.ordinal(), Type.INT),
STATE_INVINCIBLE(EntityState.INVINCIBLE.ordinal(), Type.INT),

// Résultats attaque
USE_CRITICAL(2, Type.INT),
Expand Down Expand Up @@ -159,6 +162,9 @@ public enum FightConstants implements ILeekConstant {
WEAPON_UNSTABLE_DESTROYER(226, Type.INT),
WEAPON_SWORD(277, Type.INT),
WEAPON_HEAVY_SWORD(278, Type.INT),
WEAPON_ODACHI(408, Type.INT),
WEAPON_EXCALIBUR(409, Type.INT),
WEAPON_SCYTHE(410, Type.INT),

// Messages
MESSAGE_HEAL(1, Type.INT),
Expand Down Expand Up @@ -316,6 +322,7 @@ public enum FightConstants implements ILeekConstant {
FIGHT_TYPE_FARMER(Fight.TYPE_FARMER, Type.INT),
FIGHT_TYPE_TEAM(Fight.TYPE_TEAM, Type.INT),
FIGHT_TYPE_BATTLE_ROYALE(Fight.TYPE_BATTLE_ROYALE, Type.INT),
FIGHT_TYPE_BOSS(Fight.TYPE_BOSS, Type.INT),

FIGHT_CONTEXT_TEST(Fight.CONTEXT_TEST, Type.INT),
FIGHT_CONTEXT_GARDEN(Fight.CONTEXT_GARDEN, Type.INT),
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/leekwars/generator/FightFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ public class FightFunctions {
new CallableVersion(Type.compound(Type.array(Type.array(Type.INT_OR_REAL)), Type.NULL), new Type[] { Type.INT_OR_NULL }),
new CallableVersion(Type.array(Type.array(Type.INT_OR_REAL))),
});
method("getStates", "Entity", 25, true, new CallableVersion[] {
new CallableVersion(Type.compound(Type.array(Type.INT), Type.NULL), new Type[] { Type.INT_OR_NULL }),
new CallableVersion(Type.array(Type.INT)),
});
method("getLevel", "Entity", 15, true, new CallableVersion[] {
new CallableVersion(Type.INT_OR_NULL, new Type[] { Type.INT_OR_NULL }),
new CallableVersion(Type.INT),
Expand All @@ -132,7 +136,11 @@ public class FightFunctions {
new CallableVersion(Type.INT),
});
method("getCores", "Entity", 15, true, new CallableVersion[] {
new CallableVersion(Type.INT, new Type[] { Type.INT }),
new CallableVersion(Type.INT_OR_NULL, new Type[] { Type.INT_OR_NULL }),
new CallableVersion(Type.INT),
});
method("getRAM", "Entity", 15, true, new CallableVersion[] {
new CallableVersion(Type.INT_OR_NULL, new Type[] { Type.INT_OR_NULL }),
new CallableVersion(Type.INT),
});
method("getTeamName", "Entity", 15, true, new CallableVersion[] {
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/leekwars/generator/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.leekwars.generator.chips.Chip;
import com.leekwars.generator.chips.ChipType;
import com.leekwars.generator.chips.Chips;
import com.leekwars.generator.component.Component;
import com.leekwars.generator.component.Components;
import com.leekwars.generator.leek.RegisterManager;
import com.leekwars.generator.weapons.Weapon;
import com.leekwars.generator.weapons.Weapons;
Expand Down Expand Up @@ -47,6 +49,7 @@ public Generator() {
loadWeapons();
loadChips();
loadSummons();
loadComponents();
}

/**
Expand Down Expand Up @@ -204,6 +207,7 @@ private void loadChips() {
JSONObject chips = JSON.parseObject(Util.readFile("data/chips.json"));
for (String id : chips.keySet()) {
JSONObject chip = chips.getJSONObject(id);
// System.out.println("New chip " + chip.getString("name") + " " + id + " " + chip.getInteger("template"));
Chips.addChip(new Chip(Integer.parseInt(id), chip.getInteger("cost"), chip.getInteger("min_range"),
chip.getInteger("max_range"), chip.getJSONArray("effects"), chip.getByte("launch_type"),
chip.getByte("area"), chip.getBoolean("los"), chip.getInteger("cooldown"),
Expand Down Expand Up @@ -231,6 +235,20 @@ private void loadSummons() {
}
}

private void loadComponents() {
try {
Log.start(TAG, "- Loading components... ");
JSONObject components = JSON.parseObject(Util.readFile("data/components.json"));
for (String id : components.keySet()) {
JSONObject component = components.getJSONObject(id);
Components.addComponent(new Component(Integer.parseInt(id), component.getString("name"), component.getString("stats"), component.getInteger("template")));
}
Log.end(components.size() + " components loaded.");
} catch (Exception e) {
exception(e);
}
}

public void setCache(boolean cache) {
this.use_leekscript_cache = cache;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/leekwars/generator/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public void run() {

public static void writeFile(String data, String file) {
File f = new File(file);
System.out.println("Write file " + f.getAbsolutePath());
try {
PrintWriter out = new PrintWriter(f);
out.append(data);
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/com/leekwars/generator/action/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ public void addEntity(Entity entity, boolean critical) {

object.put("team", entity.getTeam() + 1);
object.put("name", entity.getName());
object.put("cellPos", entity.getCell().getId());
object.put("cellPos", entity.getCell() != null ? entity.getCell().getId() : null);
object.put("farmer", entity.getFarmer());
object.put("type", entity.getType());
object.put("orientation", entity.getOrientation());

object.put("summon", entity.isSummon());
if (entity.isSummon()) {
Expand All @@ -116,16 +117,26 @@ public void addMap(Map map) {
Cell c = map.getCell(i);
if (c != null && !c.isWalkable() && c.getObstacleSize() > 0) {

JSONArray obstacle = new JSONArray();
obstacle.add(c.getObstacle());
obstacle.add(c.getObstacleSize());
if (map.getId() != 0) {
obstacles.put(String.valueOf(c.getId()), c.getObstacle());
} else {
JSONArray obstacle = new JSONArray();
obstacle.add(c.getObstacle());
obstacle.add(c.getObstacleSize());

obstacles.put(String.valueOf(c.getId()), map.isCustom() ? obstacle : c.getObstacleSize());
obstacles.put(String.valueOf(c.getId()), map.isCustom() ? obstacle : c.getObstacleSize());
}
}
}
if (map.getId() != 0) {
this.map.put("id", map.getId());
}
this.map.put("obstacles", obstacles);
this.map.put("type", map.getType());
this.map.put("width", map.getWidth());
this.map.put("height", map.getWidth());
if (map.getPattern() != null) {
this.map.put("pattern", map.getPattern());
}
}
}
9 changes: 8 additions & 1 deletion src/main/java/com/leekwars/generator/area/Area.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.leekwars.generator.attack.Attack;
import com.leekwars.generator.maps.Cell;
import com.leekwars.generator.maps.Map;
import com.leekwars.generator.state.Entity;

public abstract class Area {

Expand All @@ -23,6 +24,8 @@ public abstract class Area {
public final static int TYPE_SQUARE_1 = 11;
public final static int TYPE_SQUARE_2 = 12;
public final static int TYPE_FIRST_IN_LINE = 13;
public final static int TYPE_ENEMIES = 14;
public final static int TYPE_ALLIES = 15;

protected int mId;
protected Attack mAttack;
Expand All @@ -31,7 +34,7 @@ public Area(Attack attack) {
mAttack = attack;
}

public abstract List<Cell> getArea(Map map, Cell launchCell, Cell targetCell);
public abstract List<Cell> getArea(Map map, Cell launchCell, Cell targetCell, Entity caster);

protected boolean isAvailable(Cell c, List<Cell> cells_to_ignore) {
if (c.isWalkable())
Expand Down Expand Up @@ -68,6 +71,10 @@ else if (type == Area.TYPE_SQUARE_2)
return new AreaSquare2(attack);
else if (type == Area.TYPE_FIRST_IN_LINE)
return new AreaFirstInLine(attack);
else if (type == Area.TYPE_ALLIES)
return new AreaAllies(attack);
else if (type == Area.TYPE_ENEMIES)
return new AreaEnemies(attack);
return null;
}
}
30 changes: 30 additions & 0 deletions src/main/java/com/leekwars/generator/area/AreaAllies.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.leekwars.generator.area;

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

import com.leekwars.generator.attack.Attack;
import com.leekwars.generator.maps.Cell;
import com.leekwars.generator.maps.Map;
import com.leekwars.generator.state.Entity;

public class AreaAllies extends Area {

public AreaAllies(Attack attack) {
super(attack);
}

@Override
public List<Cell> getArea(Map map, Cell launchCell, Cell targetCell, Entity caster) {
var cells = new ArrayList<Cell>();
if (caster != null) {
for (var entity : map.getState().getEntities().values()) {
if (entity.getTeam() == caster.getTeam() && entity.getName().contains("crystal")) continue;
if (entity.getCell() != null && entity.getTeam() == caster.getTeam()) {
cells.add(entity.getCell());
}
}
}
return cells;
}
}
29 changes: 29 additions & 0 deletions src/main/java/com/leekwars/generator/area/AreaEnemies.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.leekwars.generator.area;

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

import com.leekwars.generator.attack.Attack;
import com.leekwars.generator.maps.Cell;
import com.leekwars.generator.maps.Map;
import com.leekwars.generator.state.Entity;

public class AreaEnemies extends Area {

public AreaEnemies(Attack attack) {
super(attack);
}

@Override
public List<Cell> getArea(Map map, Cell launchCell, Cell targetCell, Entity caster) {
var cells = new ArrayList<Cell>();
if (caster != null) {
for (var entity : map.getState().getEntities().values()) {
if (entity.getCell() != null && entity.getTeam() != caster.getTeam()) {
cells.add(entity.getCell());
}
}
}
return cells;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.leekwars.generator.maps.Cell;
import com.leekwars.generator.maps.Map;
import com.leekwars.generator.maps.Pathfinding;
import com.leekwars.generator.state.Entity;

public class AreaFirstInLine extends Area {

Expand All @@ -15,7 +16,7 @@ public AreaFirstInLine(Attack attack) {
}

@Override
public List<Cell> getArea(Map map, Cell launchCell, Cell targetCell) {
public List<Cell> getArea(Map map, Cell launchCell, Cell targetCell, Entity caster) {
List<Cell> cells = new ArrayList<>();
Cell cell = map.getFirstEntity(launchCell, targetCell, mAttack.getMinRange(), mAttack.getMaxRange());
if (cell != null) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/leekwars/generator/area/AreaLaserLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.leekwars.generator.attack.Attack;
import com.leekwars.generator.maps.Cell;
import com.leekwars.generator.maps.Map;
import com.leekwars.generator.state.Entity;

public class AreaLaserLine extends Area {

Expand All @@ -14,7 +15,7 @@ public AreaLaserLine(Attack attack) {
}

@Override
public List<Cell> getArea(Map map, Cell launchCell, Cell targetCell) {
public List<Cell> getArea(Map map, Cell launchCell, Cell targetCell, Entity caster) {

ArrayList<Cell> cells = new ArrayList<Cell>();
int dx = 0, dy = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.leekwars.generator.attack.Attack;
import com.leekwars.generator.maps.Cell;
import com.leekwars.generator.maps.Map;
import com.leekwars.generator.state.Entity;

public class AreaSingleCell extends Area {

Expand All @@ -14,7 +15,7 @@ public AreaSingleCell(Attack attack) {
}

@Override
public List<Cell> getArea(Map map, Cell launchCell, Cell targetCell) {
public List<Cell> getArea(Map map, Cell launchCell, Cell targetCell, Entity caster) {
ArrayList<Cell> area = new ArrayList<Cell>();
area.add(targetCell);
return area;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/leekwars/generator/area/MaskArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.leekwars.generator.attack.Attack;
import com.leekwars.generator.maps.Cell;
import com.leekwars.generator.maps.Map;
import com.leekwars.generator.state.Entity;

public class MaskArea extends Area {

Expand All @@ -17,7 +18,7 @@ public MaskArea(Attack attack, int[][] area) {
}

@Override
public List<Cell> getArea(Map map, Cell launchCell, Cell targetCell) {
public List<Cell> getArea(Map map, Cell launchCell, Cell targetCell, Entity caster) {
int x = targetCell.getX(), y = targetCell.getY();
ArrayList<Cell> cells = new ArrayList<Cell>();
for (int i = 0; i < area.length; i++) {
Expand Down
Loading

0 comments on commit 9d762e9

Please sign in to comment.