mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2026-05-20 16:01:04 +08:00
0b5329514b
* Deserialization support for tsv files * Benchmarking * Apparently moving the setter out of the lambda fixed the setAccessible issue * Thread it * Use AllArgsConstructor instead of field reflection * Clean up AllArgsConstructor TSV deserialization * Refactor TsvUtils * Remove AllArgsConstructors from Excels * Set field accessible * [WIP] TSJ improvements * [WIP] More TSV stuff * [WIP] More TSV stuff * Working TSV parser (slow) * Load Excels in TSJ > JSON > TSV priority
49 lines
1.7 KiB
Java
49 lines
1.7 KiB
Java
package emu.grasscutter.game.props.ItemUseAction;
|
|
|
|
import java.util.Optional;
|
|
|
|
import emu.grasscutter.game.avatar.Avatar;
|
|
import emu.grasscutter.game.props.ItemUseOp;
|
|
import emu.grasscutter.game.systems.InventorySystem;
|
|
|
|
public class ItemUseGainAvatar extends ItemUseInt {
|
|
private int level = 1;
|
|
private int constellation = 0;
|
|
|
|
@Override
|
|
public ItemUseOp getItemUseOp() {
|
|
return ItemUseOp.ITEM_USE_GAIN_AVATAR;
|
|
}
|
|
|
|
public ItemUseGainAvatar(String[] useParam) {
|
|
super(useParam);
|
|
try {
|
|
this.level = Integer.parseInt(useParam[1]);
|
|
} catch (NumberFormatException | ArrayIndexOutOfBoundsException ignored) {}
|
|
try {
|
|
this.constellation = Integer.parseInt(useParam[2]);
|
|
} catch (NumberFormatException | ArrayIndexOutOfBoundsException ignored) {}
|
|
}
|
|
|
|
@Override
|
|
public boolean useItem(UseItemParams params) {
|
|
int haveConstellation = InventorySystem.checkPlayerAvatarConstellationLevel(params.player, this.i);
|
|
if (haveConstellation == -2 || haveConstellation >= 6) {
|
|
return false;
|
|
} else if (haveConstellation == -1) {
|
|
var avatar = new Avatar(this.i);
|
|
avatar.setLevel(this.level);
|
|
avatar.forceConstellationLevel(this.constellation);
|
|
avatar.recalcStats();
|
|
params.player.addAvatar(avatar);
|
|
return true;
|
|
} else {
|
|
int itemId = Optional.ofNullable(params.player.getAvatars().getAvatarById(this.i))
|
|
.map(Avatar::getSkillDepot)
|
|
.map(depot -> depot.getTalentCostItemId())
|
|
.orElse((this.i % 1000) + 100);
|
|
return params.player.getInventory().addItem(itemId);
|
|
}
|
|
}
|
|
}
|