mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-13 13:54:37 +01:00
Implement weakness buffs when starting battle
This commit is contained in:
@@ -4,6 +4,7 @@ import java.lang.reflect.Field;
|
||||
|
||||
import emu.lunarcore.data.config.FloorInfo;
|
||||
import emu.lunarcore.data.excel.*;
|
||||
import emu.lunarcore.game.battle.MazeBuff;
|
||||
import emu.lunarcore.util.Utils;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
@@ -28,6 +29,7 @@ public class GameData {
|
||||
private static Int2ObjectMap<AvatarSkillTreeExcel> avatarSkillTreeExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
private static Int2ObjectMap<AvatarRankExcel> avatarRankExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
private static Int2ObjectMap<EquipmentPromotionExcel> equipmentPromotionExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
private static Int2ObjectMap<MazeBuffExcel> mazeBuffExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
private static Int2ObjectMap<PlayerLevelExcel> playerLevelExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
private static Int2ObjectMap<ExpTypeExcel> expTypeExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
@@ -101,4 +103,8 @@ public class GameData {
|
||||
public static FloorInfo getFloorInfo(int planeId, int floorId) {
|
||||
return floorInfos.get("P" + planeId + "_F" + floorId);
|
||||
}
|
||||
|
||||
public static MazeBuffExcel getMazeBuffExcel(int buffId, int level) {
|
||||
return mazeBuffExcelMap.get((buffId << 4) + level);
|
||||
}
|
||||
}
|
||||
|
||||
21
src/main/java/emu/lunarcore/data/excel/MazeBuffExcel.java
Normal file
21
src/main/java/emu/lunarcore/data/excel/MazeBuffExcel.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package emu.lunarcore.data.excel;
|
||||
|
||||
import emu.lunarcore.data.GameResource;
|
||||
import emu.lunarcore.data.ResourceType;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@ResourceType(name = {"MazeBuff.json"})
|
||||
public class MazeBuffExcel extends GameResource {
|
||||
private int ID;
|
||||
private int Lv;
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return (ID << 4) + Lv;
|
||||
}
|
||||
|
||||
public int getBuffId() {
|
||||
return ID;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,21 @@
|
||||
package emu.lunarcore.game.avatar;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
// These are in excels but i prefer them as enums
|
||||
public enum DamageType {
|
||||
Physical, Ice, Fire, Thunder, Wind, Quantum, Imaginary;
|
||||
Physical (1000111),
|
||||
Fire (1000112),
|
||||
Ice (1000113),
|
||||
Thunder (1000114),
|
||||
Wind (1000115),
|
||||
Quantum (1000116),
|
||||
Imaginary (1000117);
|
||||
|
||||
@Getter
|
||||
private int enterBattleBuff;
|
||||
|
||||
private DamageType(int enterBattleBuff) {
|
||||
this.enterBattleBuff = enterBattleBuff;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import emu.lunarcore.data.GameData;
|
||||
import emu.lunarcore.data.excel.MazeBuffExcel;
|
||||
import emu.lunarcore.data.excel.StageExcel;
|
||||
import emu.lunarcore.game.avatar.GameAvatar;
|
||||
import emu.lunarcore.game.player.Player;
|
||||
@@ -20,15 +21,31 @@ public class Battle {
|
||||
private final Player player;
|
||||
private final PlayerLineup lineup;
|
||||
private final List<EntityMonster> npcMonsters;
|
||||
private final List<MazeBuff> buffs;
|
||||
private StageExcel stage;
|
||||
|
||||
public Battle(Player player, PlayerLineup lineup, StageExcel stage) {
|
||||
this.player = player;
|
||||
this.lineup = lineup;
|
||||
this.npcMonsters = new ArrayList<>();
|
||||
this.buffs = new ArrayList<>();
|
||||
this.stage = stage;
|
||||
}
|
||||
|
||||
public MazeBuff addBuff(int buffId, int ownerId) {
|
||||
return addBuff(buffId, ownerId, 0xffffffff);
|
||||
}
|
||||
|
||||
public MazeBuff addBuff(int buffId, int ownerId, int waveFlag) {
|
||||
MazeBuffExcel excel = GameData.getMazeBuffExcel(buffId, 1);
|
||||
if (excel == null) return null;
|
||||
|
||||
MazeBuff buff = new MazeBuff(excel, ownerId, waveFlag);
|
||||
this.buffs.add(buff);
|
||||
|
||||
return buff;
|
||||
}
|
||||
|
||||
public SceneBattleInfo toProto() {
|
||||
var wave = SceneMonsterWave.newInstance()
|
||||
.setStageId(stage.getId());
|
||||
@@ -48,6 +65,11 @@ public class Battle {
|
||||
.addMonsterWaveList(wave)
|
||||
.setWorldLevel(player.getWorldLevel());
|
||||
|
||||
// Buffs
|
||||
for (MazeBuff buff : this.getBuffs()) {
|
||||
proto.addBuffList(buff.toProto());
|
||||
}
|
||||
|
||||
// Avatars
|
||||
for (int i = 0; i < lineup.getAvatars().size(); i++) {
|
||||
GameAvatar avatar = getPlayer().getAvatarById(lineup.getAvatars().get(i));
|
||||
|
||||
@@ -28,10 +28,12 @@ public class BattleService extends BaseGameService {
|
||||
}
|
||||
|
||||
public void onBattleStart(Player player, int attackerId, RepeatedInt attackedList) {
|
||||
//
|
||||
// Setup variables
|
||||
List<GameEntity> entities = new ArrayList<>();
|
||||
List<EntityMonster> monsters = new ArrayList<>();
|
||||
|
||||
boolean isPlayerCaster = false; // Set true if the player is the one casting
|
||||
|
||||
// Check if attacker is the player or not
|
||||
if (player.getScene().getAvatarEntityIds().contains(attackerId)) {
|
||||
// Attacker is the player
|
||||
@@ -42,6 +44,8 @@ public class BattleService extends BaseGameService {
|
||||
entities.add(entity);
|
||||
}
|
||||
}
|
||||
//
|
||||
isPlayerCaster = true;
|
||||
} else {
|
||||
// Player is ambushed
|
||||
GameEntity entity = player.getScene().getEntities().get(attackerId);
|
||||
@@ -75,6 +79,16 @@ public class BattleService extends BaseGameService {
|
||||
// Create battle and add npc monsters to it
|
||||
Battle battle = new Battle(player, player.getLineupManager().getCurrentLineup(), GameData.getStageExcelMap().get(1));
|
||||
battle.getNpcMonsters().addAll(monsters);
|
||||
// Add weakness buff to battle
|
||||
if (isPlayerCaster) {
|
||||
GameAvatar avatar = player.getLineupManager().getCurrentLeaderAvatar();
|
||||
if (avatar != null) {
|
||||
MazeBuff buff = battle.addBuff(avatar.getExcel().getDamageType().getEnterBattleBuff(), 0);
|
||||
if (buff != null) {
|
||||
buff.addDynamicValue("SkillIndex", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Set battle and send rsp packet
|
||||
player.setBattle(battle);
|
||||
player.sendPacket(new PacketSceneCastSkillScRsp(player, battle));
|
||||
|
||||
53
src/main/java/emu/lunarcore/game/battle/MazeBuff.java
Normal file
53
src/main/java/emu/lunarcore/game/battle/MazeBuff.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package emu.lunarcore.game.battle;
|
||||
|
||||
import emu.lunarcore.data.excel.MazeBuffExcel;
|
||||
import emu.lunarcore.proto.BattleBuffOuterClass.BattleBuff;
|
||||
import emu.lunarcore.proto.BattleBuffOuterClass.BattleBuff.DynamicValuesEntry;
|
||||
import it.unimi.dsi.fastutil.objects.Object2DoubleMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class MazeBuff {
|
||||
private MazeBuffExcel excel;
|
||||
private int ownerEntityId;
|
||||
private int waveFlag;
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
private Object2DoubleMap<String> dynamicValues;
|
||||
|
||||
public MazeBuff(MazeBuffExcel excel, int ownerEntityId, int waveFlag) {
|
||||
this.excel = excel;
|
||||
this.ownerEntityId = ownerEntityId;
|
||||
this.waveFlag = waveFlag;
|
||||
}
|
||||
|
||||
public void addDynamicValue(String key, double value) {
|
||||
if (this.dynamicValues == null) {
|
||||
this.dynamicValues = new Object2DoubleOpenHashMap<>();
|
||||
}
|
||||
|
||||
this.dynamicValues.put(key, value);
|
||||
}
|
||||
|
||||
public BattleBuff toProto() {
|
||||
var proto = BattleBuff.newInstance()
|
||||
.setId(excel.getBuffId())
|
||||
.setLevel(excel.getLv())
|
||||
.setOwnerId(this.getOwnerEntityId())
|
||||
.setWaveFlag(this.getWaveFlag());
|
||||
|
||||
if (this.dynamicValues != null) {
|
||||
for (var entry : this.dynamicValues.object2DoubleEntrySet()) {
|
||||
var dynamicValue = DynamicValuesEntry.newInstance()
|
||||
.setKey(entry.getKey())
|
||||
.setValue((float) entry.getDoubleValue());
|
||||
|
||||
proto.addDynamicValues(dynamicValue);
|
||||
}
|
||||
}
|
||||
|
||||
return proto;
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,15 @@ public class LineupManager {
|
||||
return getLineup(this.currentIndex);
|
||||
}
|
||||
|
||||
public GameAvatar getCurrentLeaderAvatar() {
|
||||
try {
|
||||
int avatarId = this.getCurrentLineup().getAvatars().get(currentLeader);
|
||||
return this.getPlayer().getAvatarById(avatarId);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Lineup functions
|
||||
|
||||
public boolean changeLeader(int slot) {
|
||||
|
||||
Reference in New Issue
Block a user