Commit 23800745 authored by omg-xtao's avatar omg-xtao Committed by GitHub
Browse files

Merge branch 'development' into tp

parents 7fdf7498 eef216ae
name: "Build" name: "Build"
on: on:
workflow_dispatch: ~
push: push:
paths:
- "**.java"
branches: branches:
- "stable" - "stable"
- "development" - "development"
pull_request: pull_request:
paths:
- "**.java"
types: types:
- opened - opened
- synchronize - synchronize
......
...@@ -106,46 +106,50 @@ There is a dummy user named "Server" in every player's friends list that you can ...@@ -106,46 +106,50 @@ There is a dummy user named "Server" in every player's friends list that you can
| Commands | Usage | Permission node | Availability | description | Alias | | Commands | Usage | Permission node | Availability | description | Alias |
| -------------- | ------------------------------------------------- | ------------------------- | ------------ | ------------------------------------------------------------ | ----------------------------------------------- | | -------------- | ------------------------------------------------- | ------------------------- | ------------ | ------------------------------------------------------------ | ----------------------------------------------- |
| account | account <create\|delete> <username> [UID] | | Server only | Creates an account with the specified username and the in-game UID for that account. The UID will be auto generated if not set. | | | account | account <create\|delete> \<username> [UID] | | Server only | Creates an account with the specified username and the in-game UID for that account. The UID will be auto generated if not set. | |
| broadcast | broadcast <message> | server.broadcast | Both side | Sends a message to all the players. | b | | broadcast | broadcast \<message> | server.broadcast | Both side | Sends a message to all the players. | b |
| coop | coop <playerId> <target playerId> | server.coop | Both side | Forces someone to join the world of others. | | | coop | coop \<playerId> \<target playerId> | server.coop | Both side | Forces someone to join the world of others. | |
| changescene | changescene <scene id> | player.changescene | Client only | Switch scenes by scene ID. | scene | | changescene | changescene \<scene id> | player.changescene | Client only | Switch scenes by scene ID. | scene |
| clearartifacts | clearartifacts | player.clearartifacts | Client only | Deletes all unequipped and unlocked level 0 artifacts, including 5-star rarity ones from your inventory. | clearart | | clearartifacts | clearartifacts | player.clearartifacts | Client only | Deletes all unequipped and unlocked level 0 artifacts, including 5-star rarity ones from your inventory. | clearart |
| clearweapons | clearweapons | player.clearweapons | Client only | Deletes all unequipped and unlocked weapons, including 5-star rarity ones from your inventory. | clearwpns | | clearweapons | clearweapons | player.clearweapons | Client only | Deletes all unequipped and unlocked weapons, including 5-star rarity ones from your inventory. | clearwpns |
| drop | drop <itemID\|itemName> [amount] | server.drop | Client only | Drops an item around you. | `d` `dropitem` | | drop | drop <itemID\|itemName> [amount] | server.drop | Client only | Drops an item around you. | `d` `dropitem` |
| give | give [player] <itemId\|itemName> [amount] [level] [finement] | player.give | Both side | Gives item(s) to you or the specified player. (finement option only weapon.) | `g` `item` `giveitem` | | give | give [player] <itemId\|itemName> [amount] [level] [finement] | player.give | Both side | Gives item(s) to you or the specified player. (finement option only weapon.) | `g` `item` `giveitem` |
| givechar | givechar <uid> <avatarId> | player.givechar | Both side | Gives the player a specified character. | givec | | givechar | givechar \<uid> \<avatarId> | player.givechar | Both side | Gives the player a specified character. | givec |
| giveart | giveart [player] \<artifactId> \<mainPropId> [\<appendPropId>[,\<times>]]... [level] | player.giveart | Both side | Gives the player a specified reliquary. | givea |
| giveall | giveall [uid] [amount] | player.giveall | Both side | Gives all items. | givea | | giveall | giveall [uid] [amount] | player.giveall | Both side | Gives all items. | givea |
| godmode | godmode [uid] | player.godmode | Client only | Prevents you from taking damage. | | | godmode | godmode [uid] | player.godmode | Client only | Prevents you from taking damage. | |
| heal | heal | player.heal | Client only | Heals all characters in your current team. | h | | heal | heal | player.heal | Client only | Heals all characters in your current team. | h |
| help | help [command] | | Both side | Sends the help message or shows information about a specified command. | | | help | help [command] | | Both side | Sends the help message or shows information about a specified command. | |
| kick | kick <player> | server.kick | Both side | Kicks the specified player from the server. (WIP) | k | | kick | kick \<player> | server.kick | Both side | Kicks the specified player from the server. (WIP) | k |
| killall | killall [playerUid] [sceneId] | server.killall | Both side | Kills all entities in the current scene or specified scene of the corresponding player. | | | killall | killall [playerUid] [sceneId] | server.killall | Both side | Kills all entities in the current scene or specified scene of the corresponding player. | |
| list | list | | Both side | Lists online players. | | | list | list | | Both side | Lists online players. | |
| permission | permission <add\|remove> <username> <permission> | * | Both side | Grants or removes a permission for a user. | | | permission | permission <add\|remove> \<username> \<permission> | * | Both side | Grants or removes a permission for a user. | |
| position | position | | Client only | Sends your current coordinates. | pos | | position | position | | Client only | Sends your current coordinates. | pos |
| reload | reload | server.reload | Both side | Reloads the server config | | | reload | reload | server.reload | Both side | Reloads the server config | |
| resetconst | resetconst [all] | player.resetconstellation | Client only | Resets the constellation level on your currently selected character, will need to relog after using the command to see any changes. | resetconstellation | | resetconst | resetconst [all] | player.resetconstellation | Client only | Resets the constellation level on your currently selected character, will need to relog after using the command to see any changes. | resetconstellation |
| restart | | | Both side | Restarts the current session | | | restart | | | Both side | Restarts the current session | |
| say | say <player> <message> | server.sendmessage | Both side | Sends a message to a player as the server | `sendservmsg` `sendservermessage` `sendmessage` | | say | say \<player> \<message> | server.sendmessage | Both side | Sends a message to a player as the server | `sendservmsg` `sendservermessage` `sendmessage` |
| setfetterlevel | setfetterlevel <level> | player.setfetterlevel | Client only | Sets the friendship level for your currently selected character | setfetterlvl | | setfetterlevel | setfetterlevel \<level> | player.setfetterlevel | Client only | Sets the friendship level for your currently selected character | setfetterlvl |
| setstats | setstats <stat> <value> | player.setstats | Client only | Sets a stat for your currently selected character | stats | | setstats | setstats \<stat> \<value> | player.setstats | Client only | Sets a stat for your currently selected character | stats |
| setworldlevel | setworldlevel <level> | player.setworldlevel | Client only | Sets your world level (Relog to see proper effects) | setworldlvl | | setworldlevel | setworldlevel \<level> | player.setworldlevel | Client only | Sets your world level (Relog to see proper effects) | setworldlvl |
| spawn | spanw <entityID\|entityName> [level] [amount] | server.spawn | Client only | Spawns an entity near you | | | spawn | spanw <entityID\|entityName> [level] [amount] | server.spawn | Client only | Spawns an entity near you | |
| stop | stop | server.stop | Both side | Stops the server | | | stop | stop | server.stop | Both side | Stops the server | |
| talent | talent <talentID> <value> | player.settalent | Client only | Sets talent level for your currently selected character | | | talent | talent \<talentID> \<value> | player.settalent | Client only | Sets talent level for your currently selected character | |
| teleport | teleport [@player id] <x> <y> <z> [scene id] | player.teleport | Both side | Change the player's position. | tp | | teleport | teleport [@playerUid] \<x> \<y> \<z> [sceneId] | player.teleport | Both side | Change the player's position. | tp |
| tpall | | player.tpall | Client only | Teleports all players in your world to your position | | | tpall | | player.tpall | Client only | Teleports all players in your world to your position | |
| weather | weather <weatherID> <climateID> | player.weather | Client only | Changes the weather | w | | weather | weather \<weatherID> \<climateID> | player.weather | Client only | Changes the weather | w |
### Bonus ### Bonus
When you want to teleport to somewhere, use the ingame marking function on Map, click Confirm. You will see your When you want to teleport to somewhere, use the ingame marking function on Map, click Confirm. You will see your
character falling from a very high destination, exact location that you marked. character falling from a very high destination, exact location that you marked.
You can also specify a set Y coordinate by renaming the map marker.
# Quick Troubleshooting # Quick Troubleshooting
* If compiling wasn't successful, please check your JDK installation (JDK 17 and validated JDK's bin PATH variable) * If compiling wasn't successful, please check your JDK installation (JDK 17 and validated JDK's bin PATH variable)
* My client doesn't connect, doesn't login, 4206, etc... - Mostly your proxy daemon setup is *the issue*, if using * My client doesn't connect, doesn't login, 4206, etc... - Mostly your proxy daemon setup is *the issue*, if using
Fiddler make sure it running on another port except 8888 Fiddler make sure it running on another port except 8888
* Startup sequence: Mongodb -> Grasscutter -> Proxy daemon (mitmdump, fiddler, etc.) -> Client
* Startup sequence: Mongodb > Grasscutter > Proxy daemon (mitmdump, fiddler, etc.) > Game
...@@ -109,18 +109,19 @@ chmod +x gradlew ...@@ -109,18 +109,19 @@ chmod +x gradlew
| -------------- | -------------------------------------------- | ------------------------- | -------- | ------------------------------------------ | ----------------------------------------------- | | -------------- | -------------------------------------------- | ------------------------- | -------- | ------------------------------------------ | ----------------------------------------------- |
| account | account <create\|delete> <用户名> [uid] | | 仅服务端 | 通过指定用户名和uid增删账户 | | | account | account <create\|delete> <用户名> [uid] | | 仅服务端 | 通过指定用户名和uid增删账户 | |
| broadcast | broadcast <消息内容> | server.broadcast | 均可使用 | 给所有玩家发送公告 | b | | broadcast | broadcast <消息内容> | server.broadcast | 均可使用 | 给所有玩家发送公告 | b |
| coop | coop <uid> <目标uid> | server.coop | 均可使用 | 强制某位玩家进入指定玩家的多人世界 | | | coop | coop \<uid> <目标uid> | server.coop | 均可使用 | 强制某位玩家进入指定玩家的多人世界 | |
| changescene | changescene <场景ID> | player.changescene | 仅客户端 | 切换到指定场景 | scene | | changescene | changescene <场景ID> | player.changescene | 仅客户端 | 切换到指定场景 | scene |
| clearartifacts | clearartifacts | player.clearartifacts | 仅客户端 | 删除所有未装备及未解锁的圣遗物,包括五星 | clearart | | clearartifacts | clearartifacts | player.clearartifacts | 仅客户端 | 删除所有未装备及未解锁的圣遗物,包括五星 | clearart |
| clearweapons | clearweapons | player.clearweapons | 仅客户端 | 删除所有未装备及未解锁的武器,包括五星 | clearwp | | clearweapons | clearweapons | player.clearweapons | 仅客户端 | 删除所有未装备及未解锁的武器,包括五星 | clearwp |
| drop | drop <物品ID\|物品名称> [数量] | server.drop | 仅客户端 | 在指定玩家周围掉落指定物品 | `d` `dropitem` | | drop | drop <物品ID\|物品名称> [数量] | server.drop | 仅客户端 | 在指定玩家周围掉落指定物品 | `d` `dropitem` |
| give | give [uid] <物品ID\|物品名称> [数量] [等级] [精炼等级] | | | 给予指定玩家一定数量及等级的物品 (精炼等级仅适用于武器) | `g` `item` `giveitem` | | give | give [uid] <物品ID\|物品名称> [数量] [等级] [精炼等级] | | | 给予指定玩家一定数量及等级的物品 (精炼等级仅适用于武器) | `g` `item` `giveitem` |
| givechar | givechar <uid> <角色ID> [等级] | player.givechar | 均可使用 | 给予指定玩家对应角色 | givec | | givechar | givechar \<uid> <角色ID> [等级] | player.givechar | 均可使用 | 给予指定玩家对应角色 | givec |
| giveart | giveart [uid] \<圣遗物ID> \<主属性ID> [\<副属性ID>[,<次数>]]... [等级] | player.giveart | 均可使用 | 给予玩家指定属性的圣遗物 | givea |
| giveall | giveall [uid] [数量] | player.giveall | 均可使用 | 给予指定玩家全部物品 | givea | | giveall | giveall [uid] [数量] | player.giveall | 均可使用 | 给予指定玩家全部物品 | givea |
| godmode | godmode [uid] | player.godmode | 仅客户端 | 保护你不受到任何伤害(依然会被击退) | | | godmode | godmode [uid] | player.godmode | 仅客户端 | 保护你不受到任何伤害(依然会被击退) | |
| heal | heal | player.heal | 仅客户端 | 治疗队伍中所有角色 | h | | heal | heal | player.heal | 仅客户端 | 治疗队伍中所有角色 | h |
| help | help [命令] | | 均可使用 | 显示帮助或展示指定命令的帮助 | | | help | help [命令] | | 均可使用 | 显示帮助或展示指定命令的帮助 | |
| kick | kick <uid> | server.kick | 均可使用 | 从服务器中踢出指定玩家 (WIP) | k | | kick | kick \<uid> | server.kick | 均可使用 | 从服务器中踢出指定玩家 (WIP) | k |
| killall | killall [uid] [场景ID] | server.killall | 均可使用 | 杀死指定玩家世界中所在或指定场景的全部生物 | | | killall | killall [uid] [场景ID] | server.killall | 均可使用 | 杀死指定玩家世界中所在或指定场景的全部生物 | |
| list | list | | 均可使用 | 列出在线玩家 | | | list | list | | 均可使用 | 列出在线玩家 | |
| permission | permission <add\|remove> <用户名> <权限节点> | * | 均可使用 | 添加或移除玩家的权限 | | | permission | permission <add\|remove> <用户名> <权限节点> | * | 均可使用 | 添加或移除玩家的权限 | |
...@@ -128,14 +129,14 @@ chmod +x gradlew ...@@ -128,14 +129,14 @@ chmod +x gradlew
| reload | reload | server.reload | 均可使用 | 重载服务器配置 | | | reload | reload | server.reload | 均可使用 | 重载服务器配置 | |
| resetconst | resetconst [all] | player.resetconstellation | 仅客户端 | 重置当前角色的命座,重新登录即可生效 | resetconstellation | | resetconst | resetconst [all] | player.resetconstellation | 仅客户端 | 重置当前角色的命座,重新登录即可生效 | resetconstellation |
| restart | restart | | 均可使用 | 重启服务端 | | | restart | restart | | 均可使用 | 重启服务端 | |
| say | say <uid> <消息> | server.sendmessage | 均可使用 | 作为服务器发送消息给玩家 | `sendservmsg` `sendservermessage` `sendmessage` | | say | say \<uid> <消息> | server.sendmessage | 均可使用 | 作为服务器发送消息给玩家 | `sendservmsg` `sendservermessage` `sendmessage` |
| setfetterlevel | setfetterlevel <好感等级> | player.setfetterlevel | 仅客户端 | 设置当前角色的好感等级 | `setfetterlvl` `setfriendship` | | setfetterlevel | setfetterlevel <好感等级> | player.setfetterlevel | 仅客户端 | 设置当前角色的好感等级 | `setfetterlvl` `setfriendship` |
| setstats | setstats <属性> <数值> | player.setstats | 仅客户端 | 直接修改当前角色的面板 | stats | | setstats | setstats <属性> <数值> | player.setstats | 仅客户端 | 直接修改当前角色的面板 | stats |
| setworldlevel | setworldlevel <世界等级> | player.setworldlevel | 仅客户端 | 设置世界等级(重新登陆即可生效) | setworldlvl | | setworldlevel | setworldlevel <世界等级> | player.setworldlevel | 仅客户端 | 设置世界等级(重新登陆即可生效) | setworldlvl |
| spawn | spanw <实体ID\|实体名称> [等级] [数量] | server.spawn | 仅客户端 | 在你周围生成实体 | | | spawn | spanw <实体ID\|实体名称> [等级] [数量] | server.spawn | 仅客户端 | 在你周围生成实体 | |
| stop | stop | server.stop | 均可使用 | 停止服务器 | | | stop | stop | server.stop | 均可使用 | 停止服务器 | |
| talent | talent <天赋ID> <等级> | player.settalent | 仅客户端 | 设置当前角色的天赋等级 | | | talent | talent <天赋ID> <等级> | player.settalent | 仅客户端 | 设置当前角色的天赋等级 | |
| teleport | teleport [@player id] <x> <y> <z> [scene id] | player.teleport | 均可使用 | 传送玩家到指定坐标 | tp | | teleport | teleport [@playerUid] \<x> \<y> \<z> [sceneId] | player.teleport | 均可使用 | 传送玩家到指定坐标 | tp |
| tpall | | player.tpall | 仅客户端 | 传送多人世界中所有的玩家到自身地点 | | | tpall | | player.tpall | 仅客户端 | 传送多人世界中所有的玩家到自身地点 | |
| weather | weather <天气ID> <气候ID> | player.weather | 仅客户端 | 改变天气 | w | | weather | weather <天气ID> <气候ID> | player.weather | 仅客户端 | 改变天气 | w |
......
...@@ -6,6 +6,7 @@ import java.io.FileReader; ...@@ -6,6 +6,7 @@ import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.Calendar;
import emu.grasscutter.command.CommandMap; import emu.grasscutter.command.CommandMap;
import emu.grasscutter.plugin.PluginManager; import emu.grasscutter.plugin.PluginManager;
...@@ -32,6 +33,8 @@ public final class Grasscutter { ...@@ -32,6 +33,8 @@ public final class Grasscutter {
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
private static final File configFile = new File("./config.json"); private static final File configFile = new File("./config.json");
private static int day; // Current day of week
public static RunMode MODE = RunMode.BOTH; public static RunMode MODE = RunMode.BOTH;
private static DispatchServer dispatchServer; private static DispatchServer dispatchServer;
private static GameServer gameServer; private static GameServer gameServer;
...@@ -67,8 +70,10 @@ public final class Grasscutter { ...@@ -67,8 +70,10 @@ public final class Grasscutter {
Grasscutter.getLogger().info("Starting Grasscutter..."); Grasscutter.getLogger().info("Starting Grasscutter...");
// Load all resources. // Load all resources.
Grasscutter.updateDayOfWeek();
ResourceLoader.loadAll(); ResourceLoader.loadAll();
ScriptLoader.init(); ScriptLoader.init();
// Database // Database
DatabaseManager.initialize(); DatabaseManager.initialize();
...@@ -179,4 +184,13 @@ public final class Grasscutter { ...@@ -179,4 +184,13 @@ public final class Grasscutter {
public static PluginManager getPluginManager() { public static PluginManager getPluginManager() {
return pluginManager; return pluginManager;
} }
public static void updateDayOfWeek() {
Calendar calendar = Calendar.getInstance();
day = calendar.get(Calendar.DAY_OF_WEEK);
}
public static int getCurrentDayOfWeek() {
return day;
}
} }
...@@ -83,6 +83,9 @@ public class GiveAllCommand implements CommandHandler { ...@@ -83,6 +83,9 @@ public class GiveAllCommand implements CommandHandler {
Avatar avatar = new Avatar(avatarData); Avatar avatar = new Avatar(avatarData);
avatar.setLevel(90); avatar.setLevel(90);
avatar.setPromoteLevel(6); avatar.setPromoteLevel(6);
for(int i = 1;i <= 6;++i){
avatar.getTalentIdList().add((avatar.getAvatarId()-10000000)*10+i);
}
// This will handle stats and talents // This will handle stats and talents
avatar.recalcStats(); avatar.recalcStats();
player.addAvatar(avatar); player.addAvatar(avatar);
...@@ -95,16 +98,16 @@ public class GiveAllCommand implements CommandHandler { ...@@ -95,16 +98,16 @@ public class GiveAllCommand implements CommandHandler {
if (isTestItem(itemdata.getId())) continue; if (isTestItem(itemdata.getId())) continue;
if (itemdata.isEquip()) { if (itemdata.isEquip()) {
if (itemdata.getItemType() == ItemType.ITEM_WEAPON) {
for (int i = 0; i < 5; ++i) { for (int i = 0; i < 5; ++i) {
GameItem item = new GameItem(itemdata); GameItem item = new GameItem(itemdata);
if (itemdata.getItemType() == ItemType.ITEM_WEAPON) {
item.setLevel(90); item.setLevel(90);
item.setPromoteLevel(6); item.setPromoteLevel(6);
item.setRefinement(4); item.setRefinement(4);
}
itemList.add(item); itemList.add(item);
} }
} }
}
else { else {
GameItem item = new GameItem(itemdata); GameItem item = new GameItem(itemdata);
item.setCount(amount); item.setCount(amount);
......
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.def.ItemData;
import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.inventory.ItemType;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.ActionReason;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Command(label = "giveart", usage = "giveart [player] <artifactId> <mainPropId> [<appendPropId>[,<times>]]... [level]", description = "Gives the player a specified reliquary", aliases = {"givea"}, permission = "player.giveart")
public final class GiveArtifactCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
int size = args.size(), target, itemId, mainPropId, level;
ArrayList<Integer> appendPropIdList = new ArrayList<>();
String msg = "Usage: giveart|givea [player] <artifactId> <mainPropId> [<appendPropId>[,<times>]]... [level]";
if (sender == null && size < 2) {
CommandHandler.sendMessage(null, msg);
return;
}
if (size >= 2) {
try {
level = Integer.parseInt(args.get(size - 1));
if (level <= 21) size--;
else level = 1;
target = Integer.parseInt(args.get(0));
int fromIdx;
if (Grasscutter.getGameServer().getPlayerByUid(target) == null && sender != null) {
target = sender.getUid();
itemId = Integer.parseInt(args.get(0));
mainPropId = Integer.parseInt(args.get(1));
fromIdx = 2;
} else {
target = Integer.parseInt(args.get(0));
itemId = Integer.parseInt(args.get(1));
mainPropId = Integer.parseInt(args.get(2));
fromIdx = 3;
}
args.subList(fromIdx, size).forEach(it -> {
String[] arr;
int n = 1;
if ((arr = it.split(",")).length == 2) {
it = arr[0];
n = Integer.parseInt(arr[1]);
}
appendPropIdList.addAll(Collections.nCopies(n, Integer.parseInt(it)));
});
} catch (Exception ignored) {
CommandHandler.sendMessage(sender, msg);
return;
}
} else {
CommandHandler.sendMessage(sender, msg);
return;
}
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found.");
return;
}
ItemData itemData = GameData.getItemDataMap().get(itemId);
if (itemData.getItemType() != ItemType.ITEM_RELIQUARY) {
CommandHandler.sendMessage(sender, "Invalid artifact ID.");
return;
}
GameItem item = new GameItem(itemData);
item.setLevel(level);
item.setMainPropId(mainPropId);
item.getAppendPropIdList().clear();//Clear default random props first
item.getAppendPropIdList().addAll(appendPropIdList);
targetPlayer.getInventory().addItem(item, ActionReason.SubfieldDrop);
CommandHandler.sendMessage(sender, String.format("Given %s to %s.", itemId, target));
}
}
...@@ -163,20 +163,28 @@ public final class GiveCommand implements CommandHandler { ...@@ -163,20 +163,28 @@ public final class GiveCommand implements CommandHandler {
List<GameItem> items = new LinkedList<>(); List<GameItem> items = new LinkedList<>();
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
GameItem item = new GameItem(itemData); GameItem item = new GameItem(itemData);
if (item.isEquipped()) {
// check item max level
if (item.getItemType() == ItemType.ITEM_WEAPON) {
if (lvl > 90) lvl = 90;
} else {
if (lvl > 21) lvl = 21;
}
}
item.setCount(amount); item.setCount(amount);
item.setLevel(lvl); item.setLevel(lvl);
if (lvl > 20 && lvl < 40) { if (lvl > 80) {
item.setPromoteLevel(1);
} else if (lvl > 40 && lvl <= 50) {
item.setPromoteLevel(2);
} else if (lvl > 50 && lvl <= 60) {
item.setPromoteLevel(3);
} else if (lvl > 60 && lvl <= 70) {
item.setPromoteLevel(4);
} else if (lvl > 70 && lvl <= 80) {
item.setPromoteLevel(5);
} else if (lvl > 80 && lvl <= 90) {
item.setPromoteLevel(6); item.setPromoteLevel(6);
} else if (lvl > 70) {
item.setPromoteLevel(5);
} else if (lvl > 60) {
item.setPromoteLevel(4);
} else if (lvl > 50) {
item.setPromoteLevel(3);
} else if (lvl > 40) {
item.setPromoteLevel(2);
} else if (lvl > 20) {
item.setPromoteLevel(1);
} }
if (item.getItemType() == ItemType.ITEM_WEAPON) { if (item.getItemType() == ItemType.ITEM_WEAPON) {
if (refinement > 0) { if (refinement > 0) {
......
...@@ -15,6 +15,8 @@ import emu.grasscutter.data.def.*; ...@@ -15,6 +15,8 @@ import emu.grasscutter.data.def.*;
import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
public class GameData { public class GameData {
// BinOutputs // BinOutputs
...@@ -61,12 +63,14 @@ public class GameData { ...@@ -61,12 +63,14 @@ public class GameData {
private static final Int2ObjectMap<FetterCharacterCardData> fetterCharacterCardDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap<FetterCharacterCardData> fetterCharacterCardDataMap = new Int2ObjectOpenHashMap<>();
private static final Int2ObjectMap<RewardData> rewardDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap<RewardData> rewardDataMap = new Int2ObjectOpenHashMap<>();
private static final Int2ObjectMap<WorldLevelData> worldLevelDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap<WorldLevelData> worldLevelDataMap = new Int2ObjectOpenHashMap<>();
private static final Int2ObjectMap<DailyDungeonData> dailyDungeonDataMap = new Int2ObjectOpenHashMap<>();
private static final Int2ObjectMap<DungeonData> dungeonDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap<DungeonData> dungeonDataMap = new Int2ObjectOpenHashMap<>();
private static final Int2ObjectMap<ShopGoodsData> shopGoodsDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap<ShopGoodsData> shopGoodsDataMap = new Int2ObjectOpenHashMap<>();
// Cache // Cache
private static Map<Integer, List<Integer>> fetters = new HashMap<>(); private static Map<Integer, List<Integer>> fetters = new HashMap<>();
private static Map<Integer, List<ShopGoodsData>> shopGoods = new HashMap<>(); private static Map<Integer, List<ShopGoodsData>> shopGoods = new HashMap<>();
private static final IntList scenePointIdList = new IntArrayList();
public static char EJWOA = 's'; public static char EJWOA = 's';
...@@ -280,6 +284,10 @@ public class GameData { ...@@ -280,6 +284,10 @@ public class GameData {
return dungeonDataMap; return dungeonDataMap;
} }
public static Int2ObjectMap<DailyDungeonData> getDailyDungeonDataMap() {
return dailyDungeonDataMap;
}
public static Map<Integer, List<ShopGoodsData>> getShopGoodsDataEntries() { public static Map<Integer, List<ShopGoodsData>> getShopGoodsDataEntries() {
if (shopGoods.isEmpty()) { if (shopGoods.isEmpty()) {
shopGoodsDataMap.forEach((k, v) -> { shopGoodsDataMap.forEach((k, v) -> {
...@@ -291,4 +299,8 @@ public class GameData { ...@@ -291,4 +299,8 @@ public class GameData {
return shopGoods; return shopGoods;
} }
public static IntList getScenePointIdList() {
return scenePointIdList;
}
} }
...@@ -48,11 +48,12 @@ public class ResourceLoader { ...@@ -48,11 +48,12 @@ public class ResourceLoader {
loadOpenConfig(); loadOpenConfig();
// Load resources // Load resources
loadResources(); loadResources();
loadScenePoints();
// Process into depots // Process into depots
GameDepot.load(); GameDepot.load();
// Load spawn data // Load spawn data
loadSpawnData(); loadSpawnData();
// Load scene points - must be done AFTER resources are loaded
loadScenePoints();
// Custom - TODO move this somewhere else // Custom - TODO move this somewhere else
try { try {
GameData.getAvatarSkillDepotDataMap().get(504).setAbilities( GameData.getAvatarSkillDepotDataMap().get(504).setAbilities(
...@@ -168,6 +169,9 @@ public class ResourceLoader { ...@@ -168,6 +169,9 @@ public class ResourceLoader {
ScenePointEntry sl = new ScenePointEntry(sceneId + "_" + entry.getKey(), pointData); ScenePointEntry sl = new ScenePointEntry(sceneId + "_" + entry.getKey(), pointData);
scenePointList.add(sl); scenePointList.add(sl);
GameData.getScenePointIdList().add(pointData.getId());
pointData.updateDailyDungeon();
} }
for (ScenePointEntry entry : scenePointList) { for (ScenePointEntry entry : scenePointList) {
......
package emu.grasscutter.data.common; package emu.grasscutter.data.common;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.def.DailyDungeonData;
import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Position;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
public class PointData { public class PointData {
private int id; private int id;
private String $type; private String $type;
private Position tranPos; private Position tranPos;
private int[] dungeonIds; private int[] dungeonIds;
private int[] dungeonRandomList;
public int getId() { public int getId() {
return id; return id;
...@@ -27,4 +33,31 @@ public class PointData { ...@@ -27,4 +33,31 @@ public class PointData {
public int[] getDungeonIds() { public int[] getDungeonIds() {
return dungeonIds; return dungeonIds;
} }
public int[] getDungeonRandomList() {
return dungeonRandomList;
}
public void updateDailyDungeon() {
if (getDungeonRandomList() == null) {
return;
}
IntList newDungeons = new IntArrayList();
int day = Grasscutter.getCurrentDayOfWeek();
for (int randomId : getDungeonRandomList()) {
DailyDungeonData data = GameData.getDailyDungeonDataMap().get(randomId);
if (data != null) {
int[] addDungeons = data.getDungeonsByDay(day);
for (int d : addDungeons) {
newDungeons.add(d);
}
}
}
this.dungeonIds = newDungeons.toIntArray();
}
} }
package emu.grasscutter.data.def;
import java.util.Calendar;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.GameResource;
import emu.grasscutter.data.ResourceType;
import emu.grasscutter.game.props.SceneType;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
@ResourceType(name = "DailyDungeonConfigData.json")
public class DailyDungeonData extends GameResource {
private int Id;
private int[] Monday;
private int[] Tuesday;
private int[] Wednesday;
private int[] Thursday;
private int[] Friday;
private int[] Saturday;
private int[] Sunday;
private static final int[] empty = new int[0];
private final Int2ObjectMap<int[]> map;
public DailyDungeonData() {
this.map = new Int2ObjectOpenHashMap<>();
}
@Override
public int getId() {
return this.Id;
}
public int[] getDungeonsByDay(int day) {
return map.getOrDefault(day, empty);
}
@Override
public void onLoad() {
map.put(Calendar.MONDAY, Monday);
map.put(Calendar.TUESDAY, Tuesday);
map.put(Calendar.WEDNESDAY, Wednesday);
map.put(Calendar.THURSDAY, Thursday);
map.put(Calendar.FRIDAY, Friday);
map.put(Calendar.SATURDAY, Saturday);
map.put(Calendar.SUNDAY, Sunday);
}
}
...@@ -104,7 +104,10 @@ public class Account { ...@@ -104,7 +104,10 @@ public class Account {
} }
public boolean hasPermission(String permission) { public boolean hasPermission(String permission) {
return this.permissions.contains(permission) || this.permissions.contains("*") ? true : false; return this.permissions.contains(permission) ||
this.permissions.contains("*") ||
(this.permissions.contains("player") || this.permissions.contains("player.*")) && permission.startsWith("player.") ||
(this.permissions.contains("server") || this.permissions.contains("server.*")) && permission.startsWith("server.");
} }
public boolean removePermission(String permission) { public boolean removePermission(String permission) {
......
...@@ -28,7 +28,7 @@ public class DungeonManager { ...@@ -28,7 +28,7 @@ public class DungeonManager {
public void getEntryInfo(Player player, int pointId) { public void getEntryInfo(Player player, int pointId) {
ScenePointEntry entry = GameData.getScenePointEntryById(player.getScene().getId(), pointId); ScenePointEntry entry = GameData.getScenePointEntryById(player.getScene().getId(), pointId);
if (entry == null || entry.getPointData().getDungeonIds() == null) { if (entry == null) {
// Error // Error
player.sendPacket(new PacketDungeonEntryInfoRsp()); player.sendPacket(new PacketDungeonEntryInfoRsp());
return; return;
...@@ -79,4 +79,10 @@ public class DungeonManager { ...@@ -79,4 +79,10 @@ public class DungeonManager {
player.getWorld().transferPlayerToScene(player, prevScene, prevPos); player.getWorld().transferPlayerToScene(player, prevScene, prevPos);
player.sendPacket(new BasePacket(PacketOpcodes.PlayerQuitDungeonRsp)); player.sendPacket(new BasePacket(PacketOpcodes.PlayerQuitDungeonRsp));
} }
public void updateDailyDungeons() {
for (ScenePointEntry entry : GameData.getScenePointEntries().values()) {
entry.getPointData().updateDailyDungeon();
}
}
} }
...@@ -18,24 +18,30 @@ import emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo; ...@@ -18,24 +18,30 @@ import emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo;
import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo; import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo;
import emu.grasscutter.net.proto.VectorOuterClass.Vector; import emu.grasscutter.net.proto.VectorOuterClass.Vector;
import emu.grasscutter.net.proto.VehicleInfoOuterClass.*; import emu.grasscutter.net.proto.VehicleInfoOuterClass.*;
import emu.grasscutter.net.proto.VehicleMemberOuterClass.*;
import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Position;
import emu.grasscutter.utils.ProtoHelper; import emu.grasscutter.utils.ProtoHelper;
import it.unimi.dsi.fastutil.ints.Int2FloatMap; import it.unimi.dsi.fastutil.ints.Int2FloatMap;
import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
import java.util.List;
import java.util.ArrayList;
public class EntityVehicle extends EntityBaseGadget { public class EntityVehicle extends EntityBaseGadget {
private final Player owner; private final Player owner;
private final Int2FloatOpenHashMap fightProp; private final Int2FloatOpenHashMap fightProp;
private final Position pos; private final Position pos;
private final Position rot; private final Position rot;
private float curStamina;
private final int pointId; private final int pointId;
private final int gadgetId; private final int gadgetId;
private float curStamina;
private List<VehicleMember> vehicleMembers;
public EntityVehicle(Scene scene, Player player, int gadgetId, int pointId, Position pos, Position rot) { public EntityVehicle(Scene scene, Player player, int gadgetId, int pointId, Position pos, Position rot) {
super(scene); super(scene);
this.owner = player; this.owner = player;
...@@ -46,6 +52,7 @@ public class EntityVehicle extends EntityBaseGadget { ...@@ -46,6 +52,7 @@ public class EntityVehicle extends EntityBaseGadget {
this.gadgetId = gadgetId; this.gadgetId = gadgetId;
this.pointId = pointId; this.pointId = pointId;
this.curStamina = 240; this.curStamina = 240;
this.vehicleMembers = new ArrayList<VehicleMember>();
} }
@Override @Override
...@@ -61,6 +68,8 @@ public class EntityVehicle extends EntityBaseGadget { ...@@ -61,6 +68,8 @@ public class EntityVehicle extends EntityBaseGadget {
public int getPointId() { return pointId; } public int getPointId() { return pointId; }
public List<VehicleMember> getVehicleMembers() { return vehicleMembers; }
@Override @Override
public Int2FloatOpenHashMap getFightProperties() { public Int2FloatOpenHashMap getFightProperties() {
return fightProp; return fightProp;
......
...@@ -34,6 +34,10 @@ public abstract class GameEntity { ...@@ -34,6 +34,10 @@ public abstract class GameEntity {
return this.id; return this.id;
} }
public int getEntityType() {
return getId() >> 24;
}
public World getWorld() { public World getWorld() {
return this.getScene().getWorld(); return this.getScene().getWorld();
} }
......
...@@ -244,6 +244,10 @@ public class GameItem { ...@@ -244,6 +244,10 @@ public class GameItem {
return mainPropId; return mainPropId;
} }
public void setMainPropId(int mainPropId) {
this.mainPropId = mainPropId;
}
public List<Integer> getAppendPropIdList() { public List<Integer> getAppendPropIdList() {
return appendPropIdList; return appendPropIdList;
} }
......
...@@ -822,7 +822,7 @@ public class Player { ...@@ -822,7 +822,7 @@ public class Player {
.setProfilePicture(ProfilePicture.newBuilder().setAvatarId(this.getHeadImage())); .setProfilePicture(ProfilePicture.newBuilder().setAvatarId(this.getHeadImage()));
if (this.getWorld() != null) { if (this.getWorld() != null) {
onlineInfo.setCurPlayerNumInWorld(this.getWorld().getPlayers().indexOf(this) + 1); onlineInfo.setCurPlayerNumInWorld(getWorld().getPlayerCount());
} else { } else {
onlineInfo.setCurPlayerNumInWorld(1); onlineInfo.setCurPlayerNumInWorld(1);
} }
......
...@@ -375,8 +375,8 @@ public class Scene { ...@@ -375,8 +375,8 @@ public class Scene {
this.broadcastPacket(new PacketLifeStateChangeNotify(attackerId, target, LifeState.LIFE_DEAD)); this.broadcastPacket(new PacketLifeStateChangeNotify(attackerId, target, LifeState.LIFE_DEAD));
// Reward drop // Reward drop
if (target instanceof EntityMonster) { if (target instanceof EntityMonster && this.getSceneType() != SceneType.SCENE_WORLD) {
Grasscutter.getGameServer().getDropManager().callDrop((EntityMonster) target); getWorld().getServer().getDropManager().callDrop((EntityMonster) target);
} }
this.removeEntity(target); this.removeEntity(target);
...@@ -508,6 +508,7 @@ public class Scene { ...@@ -508,6 +508,7 @@ public class Scene {
} }
group.triggers.forEach(getScriptManager()::registerTrigger); group.triggers.forEach(getScriptManager()::registerTrigger);
group.regions.forEach(getScriptManager()::registerRegion);
} }
// Spawn gadgets AFTER triggers are added // Spawn gadgets AFTER triggers are added
...@@ -526,6 +527,7 @@ public class Scene { ...@@ -526,6 +527,7 @@ public class Scene {
for (SceneGroup group : block.groups) { for (SceneGroup group : block.groups) {
group.triggers.forEach(getScriptManager()::deregisterTrigger); group.triggers.forEach(getScriptManager()::deregisterTrigger);
group.regions.forEach(getScriptManager()::deregisterRegion);
} }
} }
......
...@@ -27,6 +27,7 @@ import emu.grasscutter.net.proto.AttackResultOuterClass.AttackResult; ...@@ -27,6 +27,7 @@ import emu.grasscutter.net.proto.AttackResultOuterClass.AttackResult;
import emu.grasscutter.net.proto.EnterTypeOuterClass.EnterType; import emu.grasscutter.net.proto.EnterTypeOuterClass.EnterType;
import emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType; import emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType;
import emu.grasscutter.scripts.data.SceneConfig; import emu.grasscutter.scripts.data.SceneConfig;
import emu.grasscutter.server.game.GameServer;
import emu.grasscutter.server.packet.send.PacketDelTeamEntityNotify; import emu.grasscutter.server.packet.send.PacketDelTeamEntityNotify;
import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
import emu.grasscutter.server.packet.send.PacketLifeStateChangeNotify; import emu.grasscutter.server.packet.send.PacketLifeStateChangeNotify;
...@@ -44,6 +45,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMaps; ...@@ -44,6 +45,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
public class World implements Iterable<Player> { public class World implements Iterable<Player> {
private final GameServer server;
private final Player owner; private final Player owner;
private final List<Player> players; private final List<Player> players;
private final Int2ObjectMap<Scene> scenes; private final Int2ObjectMap<Scene> scenes;
...@@ -61,6 +63,7 @@ public class World implements Iterable<Player> { ...@@ -61,6 +63,7 @@ public class World implements Iterable<Player> {
public World(Player player, boolean isMultiplayer) { public World(Player player, boolean isMultiplayer) {
this.owner = player; this.owner = player;
this.server = player.getServer();
this.players = Collections.synchronizedList(new ArrayList<>()); this.players = Collections.synchronizedList(new ArrayList<>());
this.scenes = Int2ObjectMaps.synchronize(new Int2ObjectOpenHashMap<>()); this.scenes = Int2ObjectMaps.synchronize(new Int2ObjectOpenHashMap<>());
...@@ -75,6 +78,10 @@ public class World implements Iterable<Player> { ...@@ -75,6 +78,10 @@ public class World implements Iterable<Player> {
return owner; return owner;
} }
public GameServer getServer() {
return server;
}
public int getLevelEntityId() { public int getLevelEntityId() {
return levelEntityId; return levelEntityId;
} }
......
package emu.grasscutter.scripts; package emu.grasscutter.scripts;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
...@@ -23,6 +24,7 @@ import emu.grasscutter.data.def.WorldLevelData; ...@@ -23,6 +24,7 @@ import emu.grasscutter.data.def.WorldLevelData;
import emu.grasscutter.game.entity.EntityGadget; import emu.grasscutter.game.entity.EntityGadget;
import emu.grasscutter.game.entity.EntityMonster; import emu.grasscutter.game.entity.EntityMonster;
import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.game.props.EntityType;
import emu.grasscutter.game.world.Scene; import emu.grasscutter.game.world.Scene;
import emu.grasscutter.scripts.constants.EventType; import emu.grasscutter.scripts.constants.EventType;
import emu.grasscutter.scripts.constants.ScriptGadgetState; import emu.grasscutter.scripts.constants.ScriptGadgetState;
...@@ -33,6 +35,7 @@ import emu.grasscutter.scripts.data.SceneGadget; ...@@ -33,6 +35,7 @@ import emu.grasscutter.scripts.data.SceneGadget;
import emu.grasscutter.scripts.data.SceneGroup; import emu.grasscutter.scripts.data.SceneGroup;
import emu.grasscutter.scripts.data.SceneInitConfig; import emu.grasscutter.scripts.data.SceneInitConfig;
import emu.grasscutter.scripts.data.SceneMonster; import emu.grasscutter.scripts.data.SceneMonster;
import emu.grasscutter.scripts.data.SceneRegion;
import emu.grasscutter.scripts.data.SceneSuite; import emu.grasscutter.scripts.data.SceneSuite;
import emu.grasscutter.scripts.data.SceneTrigger; import emu.grasscutter.scripts.data.SceneTrigger;
import emu.grasscutter.scripts.data.SceneVar; import emu.grasscutter.scripts.data.SceneVar;
...@@ -49,14 +52,17 @@ public class SceneScriptManager { ...@@ -49,14 +52,17 @@ public class SceneScriptManager {
private Bindings bindings; private Bindings bindings;
private SceneConfig config; private SceneConfig config;
private List<SceneBlock> blocks; private List<SceneBlock> blocks;
private Int2ObjectOpenHashMap<Set<SceneTrigger>> triggers;
private boolean isInit; private boolean isInit;
private final Int2ObjectOpenHashMap<Set<SceneTrigger>> triggers;
private final Int2ObjectOpenHashMap<SceneRegion> regions;
public SceneScriptManager(Scene scene) { public SceneScriptManager(Scene scene) {
this.scene = scene; this.scene = scene;
this.scriptLib = new ScriptLib(this); this.scriptLib = new ScriptLib(this);
this.scriptLibLua = CoerceJavaToLua.coerce(this.scriptLib); this.scriptLibLua = CoerceJavaToLua.coerce(this.scriptLib);
this.triggers = new Int2ObjectOpenHashMap<>(); this.triggers = new Int2ObjectOpenHashMap<>();
this.regions = new Int2ObjectOpenHashMap<>();
this.variables = new HashMap<>(); this.variables = new HashMap<>();
// TEMPORARY // TEMPORARY
...@@ -108,6 +114,18 @@ public class SceneScriptManager { ...@@ -108,6 +114,18 @@ public class SceneScriptManager {
getTriggersByEvent(trigger.event).remove(trigger); getTriggersByEvent(trigger.event).remove(trigger);
} }
public SceneRegion getRegionById(int id) {
return regions.get(id);
}
public void registerRegion(SceneRegion region) {
regions.put(region.config_id, region);
}
public void deregisterRegion(SceneRegion region) {
regions.remove(region.config_id);
}
// TODO optimize // TODO optimize
public SceneGroup getGroupById(int groupId) { public SceneGroup getGroupById(int groupId) {
for (SceneBlock block : this.getScene().getLoadedBlocks()) { for (SceneBlock block : this.getScene().getLoadedBlocks()) {
...@@ -134,9 +152,6 @@ public class SceneScriptManager { ...@@ -134,9 +152,6 @@ public class SceneScriptManager {
bindings = ScriptLoader.getEngine().createBindings(); bindings = ScriptLoader.getEngine().createBindings();
// Set variables // Set variables
bindings.put("EventType", new EventType()); // TODO - make static class to avoid instantiating a new class every scene
bindings.put("GadgetState", new ScriptGadgetState());
bindings.put("RegionShape", new ScriptRegionShape());
bindings.put("ScriptLib", getScriptLib()); bindings.put("ScriptLib", getScriptLib());
// Eval script // Eval script
...@@ -211,6 +226,7 @@ public class SceneScriptManager { ...@@ -211,6 +226,7 @@ public class SceneScriptManager {
group.gadgets = ScriptLoader.getSerializer().toList(SceneGadget.class, bindings.get("gadgets")); group.gadgets = ScriptLoader.getSerializer().toList(SceneGadget.class, bindings.get("gadgets"));
group.triggers = ScriptLoader.getSerializer().toList(SceneTrigger.class, bindings.get("triggers")); group.triggers = ScriptLoader.getSerializer().toList(SceneTrigger.class, bindings.get("triggers"));
group.suites = ScriptLoader.getSerializer().toList(SceneSuite.class, bindings.get("suites")); group.suites = ScriptLoader.getSerializer().toList(SceneSuite.class, bindings.get("suites"));
group.regions = ScriptLoader.getSerializer().toList(SceneRegion.class, bindings.get("regions"));
group.init_config = ScriptLoader.getSerializer().toObject(SceneInitConfig.class, bindings.get("init_config")); group.init_config = ScriptLoader.getSerializer().toObject(SceneInitConfig.class, bindings.get("init_config"));
// Add variables to suite // Add variables to suite
...@@ -235,11 +251,27 @@ public class SceneScriptManager { ...@@ -235,11 +251,27 @@ public class SceneScriptManager {
} }
public void onTick() { public void onTick() {
checkTriggers(); checkRegions();
} }
public void checkTriggers() { public void checkRegions() {
if (this.regions.size() == 0) {
return;
}
for (SceneRegion region : this.regions.values()) {
getScene().getEntities().values()
.stream()
.filter(e -> e.getEntityType() <= 2 && region.contains(e.getPosition()))
.forEach(region::addEntity);
if (region.hasNewEntities()) {
// This is not how it works, source_eid should be region entity id, but we dont have an entity for regions yet
callEvent(EventType.EVENT_ENTER_REGION, new ScriptArgs(region.config_id).setSourceEntityId(region.config_id));
region.resetNewEntities();
}
}
} }
public void spawnGadgetsInGroup(SceneGroup group) { public void spawnGadgetsInGroup(SceneGroup group) {
......
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