added Quest Trigger

- added EXEC_ADD_CUR_AVATAR_ENERGY
 - added EXEC_CAHNGE_AVATAR_ELEMET
 - added new function 'changeAvatarElement' in player.java
 - changed hardcoded MC depot skill to read json data in HandlerSetPlayerBornDataReq.Data
 - changed and added refill function in EnergyManager.java
This commit is contained in:
WQJ 2022-10-28 15:39:54 +11:00
parent d21f020ee8
commit c0f79b2071
6 changed files with 75 additions and 12 deletions

View File

@ -30,7 +30,7 @@ public class AvatarData extends GameResource {
@Getter private String cutsceneShow;
@Getter private int skillDepotId;
@Getter private int staminaRecoverSpeed;
@Getter private List<String> candSkillDepotIds;
@Getter private List<Integer> candSkillDepotIds;
@Getter private String avatarIdentityType;
@Getter private List<Integer> avatarPromoteRewardLevelList;
@Getter private List<Integer> avatarPromoteRewardIdList;

View File

@ -382,12 +382,16 @@ public class EnergyManager extends BasePlayerManager {
return this.energyUsage;
}
public void refillTeamEnergy (PropChangeReason changeReason) {
for (EntityAvatar entityAvatar : this.player.getTeamManager().getActiveTeam()) {
entityAvatar.addEnergy(1000, changeReason, true);
}
}
public void setEnergyUsage(boolean energyUsage) {
this.energyUsage = energyUsage;
if (!energyUsage) { // Refill team energy if usage is disabled
for (EntityAvatar entityAvatar : this.player.getTeamManager().getActiveTeam()) {
entityAvatar.addEnergy(1000, PropChangeReason.PROP_CHANGE_REASON_GM,true);
}
refillTeamEnergy(PropChangeReason.PROP_CHANGE_REASON_GM);
}
}
}

View File

@ -4,6 +4,7 @@ import dev.morphia.annotations.*;
import emu.grasscutter.GameConstants;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.excels.AvatarSkillDepotData;
import emu.grasscutter.data.excels.PlayerLevelData;
import emu.grasscutter.data.excels.WeatherData;
import emu.grasscutter.database.DatabaseHelper;
@ -36,6 +37,7 @@ import emu.grasscutter.game.managers.stamina.StaminaManager;
import emu.grasscutter.game.managers.SotSManager;
import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.game.props.ClimateType;
import emu.grasscutter.game.props.ElementType;
import emu.grasscutter.game.props.PlayerProperty;
import emu.grasscutter.game.props.WatcherTriggerType;
import emu.grasscutter.game.quest.QuestManager;
@ -779,6 +781,33 @@ public class Player {
addAvatar(avatar, true);
}
public boolean changeAvatarElement(int elementTypeId){
EntityAvatar mainCharacterEntity = getTeamManager().getCurrentAvatarEntity();
Avatar mainCharacter = mainCharacterEntity.getAvatar();
// if no candidate skill to change
if (mainCharacter.getData().getCandSkillDepotIds() == null){
return false;
}
ElementType elementTypeToChange = ElementType.getTypeByValue(elementTypeId);
int candSkillDepotIndex = elementTypeToChange.getDepotValue();
int candSkillDepotId = mainCharacter.getData().getCandSkillDepotIds().get(candSkillDepotIndex-1);
// Sanity checks for skill depots
AvatarSkillDepotData skillDepot = GameData.getAvatarSkillDepotDataMap().get(candSkillDepotId);
if (skillDepot == null || skillDepot.getId() == mainCharacter.getSkillDepotId()) {
return false;
}
// Set skill depot
mainCharacter.setSkillDepotData(skillDepot);
// Ability change packet
sendPacket(new PacketAvatarSkillDepotChangeNotify(mainCharacter));
sendPacket(new PacketAbilityChangeNotify(mainCharacterEntity));
return true;
}
public void addFlycloak(int flycloakId) {
this.getFlyCloakList().add(flycloakId);
this.sendPacket(new PacketAvatarGainFlycloakNotify(flycloakId));

View File

@ -0,0 +1,19 @@
package emu.grasscutter.game.quest.exec;
import emu.grasscutter.data.excels.QuestData;
import emu.grasscutter.game.quest.GameQuest;
import emu.grasscutter.game.quest.QuestValue;
import emu.grasscutter.game.quest.enums.QuestTrigger;
import emu.grasscutter.game.quest.handlers.QuestExecHandler;
import emu.grasscutter.net.proto.PropChangeReasonOuterClass.PropChangeReason;
import emu.grasscutter.Grasscutter;
@QuestValue(QuestTrigger.QUEST_EXEC_ADD_CUR_AVATAR_ENERGY)
public class ExecAddCurAvatarEnergy extends QuestExecHandler {
@Override
public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) {
Grasscutter.getLogger().info("Energy refilled");
quest.getOwner().getEnergyManager().refillTeamEnergy(PropChangeReason.PROP_CHANGE_REASON_FINISH_QUEST);
return true;
}
}

View File

@ -0,0 +1,18 @@
package emu.grasscutter.game.quest.exec;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.excels.QuestData;
import emu.grasscutter.game.quest.GameQuest;
import emu.grasscutter.game.quest.QuestValue;
import emu.grasscutter.game.quest.enums.QuestTrigger;
import emu.grasscutter.game.quest.handlers.QuestExecHandler;
import emu.grasscutter.Grasscutter;
@QuestValue(QuestTrigger.QUEST_EXEC_CHANGE_AVATAR_ELEMET)
public class ExecChangeAvatarElemet extends QuestExecHandler {
@Override
public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) {
Grasscutter.getLogger().info("Changing skill element for quest {}", quest.getSubQuestId());
return quest.getOwner().changeAvatarElement(Integer.parseInt(paramStr[0]));
}
}

View File

@ -30,14 +30,6 @@ public class HandlerSetPlayerBornDataReq extends PacketHandler {
// Sanity checks
int avatarId = req.getAvatarId();
int startingSkillDepot;
if (avatarId == GameConstants.MAIN_CHARACTER_MALE) {
startingSkillDepot = 504;
} else if (avatarId == GameConstants.MAIN_CHARACTER_FEMALE) {
startingSkillDepot = 704;
} else {
return;
}
// Make sure resources folder is set
if (!GameData.getAvatarDataMap().containsKey(avatarId)) {
@ -53,6 +45,7 @@ public class HandlerSetPlayerBornDataReq extends PacketHandler {
// Create avatar
if (player.getAvatars().getAvatarCount() == 0) {
Avatar mainCharacter = new Avatar(avatarId);
int startingSkillDepot = mainCharacter.getData().getSkillDepotId();
mainCharacter.setSkillDepotData(GameData.getAvatarSkillDepotDataMap().get(startingSkillDepot));
// Manually handle adding to team
player.addAvatar(mainCharacter, false);