forked from Grasscutters/Grasscutter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt to implement item giving to NPCs (untested)
- Loading branch information
1 parent
a4ad781
commit b82567d
Showing
13 changed files
with
354 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/emu/grasscutter/data/excels/giving/GivingData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package emu.grasscutter.data.excels.giving; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import emu.grasscutter.data.*; | ||
import emu.grasscutter.data.common.ItemParamData; | ||
import emu.grasscutter.game.inventory.BagTab; | ||
import lombok.*; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@EqualsAndHashCode(callSuper = false) | ||
@ResourceType(name = "GivingExcelConfigData.json") | ||
public final class GivingData extends GameResource { | ||
@SerializedName(value = "id", alternate = "Id") | ||
private int id; | ||
private int talkId; | ||
private int mistakeTalkId; | ||
|
||
private BagTab tab; | ||
private GiveMethod givingMethod; | ||
|
||
private List<ItemParamData> exactItems; | ||
private int exactFinishTalkId; | ||
|
||
private List<Integer> givingGroupIds; | ||
private int givingGroupCount; | ||
|
||
private boolean isRemoveItem; | ||
private GiveType giveType; | ||
|
||
public enum GiveMethod { | ||
@SerializedName("GIVING_METHOD_EXACT") EXACT, | ||
@SerializedName("GIVING_METHOD_GROUP") GROUP, | ||
@SerializedName("GIVING_METHOD_VAGUE_GROUP") GROUP_VAGUE | ||
} | ||
|
||
public enum GiveType { | ||
@SerializedName("GIVING_TYPE_QUEST") QUEST, | ||
@SerializedName("GIVING_TYPE_GROUP") GROUP | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/emu/grasscutter/data/excels/giving/GivingGroupData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package emu.grasscutter.data.excels.giving; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import emu.grasscutter.data.*; | ||
import lombok.*; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@EqualsAndHashCode(callSuper = false) | ||
@ResourceType(name = "GivingGroupExcelConfigData.json") | ||
public final class GivingGroupData extends GameResource { | ||
@SerializedName(value = "id", alternate = "Id") | ||
private int id; | ||
|
||
@SerializedName(value = "itemIds", alternate = "ItemIds") | ||
private List<Integer> itemIds; | ||
|
||
private int finishTalkId; | ||
private int mistakeTalkId; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package emu.grasscutter.game.inventory; | ||
|
||
import it.unimi.dsi.fastutil.ints.*; | ||
import lombok.*; | ||
|
||
import java.util.*; | ||
import java.util.stream.Stream; | ||
|
||
@RequiredArgsConstructor | ||
public enum BagTab { | ||
TAB_NONE(0), | ||
TAB_WEAPON(1), | ||
TAB_EQUIP(2), | ||
TAB_AVATAR(3), | ||
TAB_FOOD(4), | ||
TAB_MATERIAL(5), | ||
TAB_QUEST(6), | ||
TAB_CONSUME(7), | ||
TAB_WIDGET(8), | ||
TAB_HOMEWORLD(9); | ||
|
||
private static final Int2ObjectMap<BagTab> map = new Int2ObjectOpenHashMap<>(); | ||
private static final Map<String, BagTab> stringMap = new HashMap<>(); | ||
|
||
static { | ||
Stream.of(BagTab.values()) | ||
.forEach( | ||
entry -> { | ||
map.put(entry.getValue(), entry); | ||
stringMap.put(entry.name(), entry); | ||
}); | ||
} | ||
|
||
@Getter private final int value; | ||
|
||
/** | ||
* Fetches the bag tab by its value. | ||
* | ||
* @param value The name of the bag tab. | ||
* @return The bag tab. | ||
*/ | ||
public static BagTab getTypeByValue(int value) { | ||
return map.getOrDefault(value, TAB_NONE); | ||
} | ||
|
||
/** | ||
* Fetches the bag tab by its name. | ||
* | ||
* @param name The name of the bag tab. | ||
* @return The bag tab. | ||
*/ | ||
public static BagTab getTypeByName(String name) { | ||
return stringMap.getOrDefault(name, TAB_NONE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/emu/grasscutter/game/quest/exec/ExecActiveItemGiving.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package emu.grasscutter.game.quest.exec; | ||
|
||
import emu.grasscutter.Grasscutter; | ||
import emu.grasscutter.data.excels.quest.QuestData.QuestExecParam; | ||
import emu.grasscutter.game.quest.*; | ||
import emu.grasscutter.game.quest.enums.QuestExec; | ||
import emu.grasscutter.game.quest.handlers.QuestExecHandler; | ||
|
||
@QuestValueExec(QuestExec.QUEST_EXEC_ACTIVE_ITEM_GIVING) | ||
public final class ExecActiveItemGiving extends QuestExecHandler { | ||
@Override | ||
public boolean execute(GameQuest quest, QuestExecParam condition, String... paramStr) { | ||
var questManager = quest.getOwner().getQuestManager(); | ||
var activeGivings = questManager.getActiveGivings(); | ||
|
||
var givingId = Integer.parseInt(condition.getParam()[0]); | ||
if (activeGivings.contains(givingId)) { | ||
Grasscutter.getLogger().debug("Quest {} attempted to add give action {} twice.", | ||
quest.getSubQuestId(), givingId); | ||
return false; | ||
} else { | ||
activeGivings.add(givingId); | ||
return true; | ||
} | ||
} | ||
} |
Oops, something went wrong.