Added finishTask (for achievement diary) to ContentAPI
This commit is contained in:
@@ -2,6 +2,7 @@ package content.global.dialogue;
|
||||
|
||||
import content.global.handlers.item.book.GeneralRuleBook;
|
||||
import core.game.dialogue.DialoguePlugin;
|
||||
import core.game.diary.DiaryLevel;
|
||||
import core.game.node.entity.npc.NPC;
|
||||
import core.game.node.entity.player.Player;
|
||||
import core.game.node.entity.player.link.diary.DiaryType;
|
||||
@@ -10,6 +11,10 @@ import core.game.world.GameWorld;
|
||||
import core.game.world.update.flag.context.Animation;
|
||||
import core.plugin.Initializable;
|
||||
import core.tools.RandomFunction;
|
||||
import org.rs09.consts.NPCs;
|
||||
|
||||
import static content.region.misthalin.lumbridge.diary.LumbridgeAchivementDiary.Companion.BeginnerTasks.DRAYNOR_TALK_TO_TOWNCRIER_ABOUT_RULES;
|
||||
import static core.api.ContentAPIKt.finishTask;
|
||||
|
||||
/**
|
||||
* Represents the town crier dialogue plugin.
|
||||
@@ -127,9 +132,8 @@ public final class TownCrierDialogue extends DialoguePlugin {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
// Find out about the Rules of Conduct from the Draynor<br><br>Town Crier
|
||||
if (npc.getId() == 6136) {
|
||||
player.getAchievementDiaryManager().finishTask(player, DiaryType.LUMBRIDGE, 0, 10);
|
||||
if (npc.getId() == NPCs.TOWN_CRIER_6136) {
|
||||
finishTask(player, DiaryType.LUMBRIDGE, DiaryLevel.BEGINNER, DRAYNOR_TALK_TO_TOWNCRIER_ABOUT_RULES);
|
||||
}
|
||||
stage = 71;
|
||||
break;
|
||||
|
||||
@@ -25,6 +25,7 @@ import core.game.consumable.*
|
||||
import core.game.container.impl.EquipmentContainer
|
||||
import core.game.dialogue.DialogueFile
|
||||
import core.game.dialogue.SkillDialogueHandler
|
||||
import core.game.diary.DiaryLevel
|
||||
import core.game.ge.GrandExchangeRecords
|
||||
import core.game.interaction.*
|
||||
import core.game.node.Node
|
||||
@@ -42,6 +43,7 @@ import core.game.node.entity.player.link.HintIconManager
|
||||
import core.game.node.entity.player.link.IronmanMode
|
||||
import core.game.node.entity.player.link.TeleportManager
|
||||
import core.game.node.entity.player.link.audio.Audio
|
||||
import core.game.node.entity.player.link.diary.DiaryType
|
||||
import core.game.node.entity.player.link.emote.Emotes
|
||||
import core.game.node.entity.player.link.prayer.PrayerType
|
||||
import core.game.node.entity.player.link.quest.Quest
|
||||
@@ -3335,4 +3337,33 @@ fun openSingleTab(player: Player, component: Int) {
|
||||
player.interfaceManager.openSingleTab(Component(component))
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish an achievement diary task for the player.
|
||||
* @param player the player who just finished the task.
|
||||
* @param diary the diary the task belongs to.
|
||||
* @param level the level of the task.
|
||||
* @param task The task that was just finished.
|
||||
*/
|
||||
fun finishTask(player: Player, diary: DiaryType, level: DiaryLevel, task: Int) {
|
||||
player.achievementDiaryManager.finishTask(player, diary, getDiaryLevelIndex(diary, level), task)
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a [DiaryLevel] to an index for a specific diary.
|
||||
* @param diary The diary the task belongs to.
|
||||
* @param level The task level in the diary.
|
||||
* @throws IllegalArgumentException if the level is not present in the diary.
|
||||
* @return the index of the level that can be used with [core.game.node.entity.player.link.diary.AchievementDiaryManager.finishTask].
|
||||
*/
|
||||
fun getDiaryLevelIndex(diary: DiaryType, level: DiaryLevel): Int {
|
||||
val levelName = level.name.lowercase().replaceFirstChar { c -> c.uppercase() }
|
||||
val levelIndex = diary.levelNames.indexOf(levelName)
|
||||
|
||||
if (levelIndex < 0) {
|
||||
throw IllegalArgumentException("'$levelName' was not found in diary '$diary'.")
|
||||
}
|
||||
|
||||
return levelIndex
|
||||
}
|
||||
|
||||
private class ContentAPI
|
||||
|
||||
@@ -180,16 +180,7 @@ abstract class DiaryEventHookBase(private val diaryType: DiaryType) : MapArea, L
|
||||
)
|
||||
}
|
||||
|
||||
private fun findIndexFor(level: DiaryLevel): Int {
|
||||
val levelName = level.name.lowercase().replaceFirstChar { c -> c.uppercase() }
|
||||
val levelIndex = diaryType.levelNames.indexOf(levelName)
|
||||
|
||||
if (levelIndex < 0) {
|
||||
throw IllegalArgumentException("'$levelName' was not found in diary '$diaryType'.")
|
||||
}
|
||||
|
||||
return levelIndex
|
||||
}
|
||||
private fun findIndexFor(level: DiaryLevel): Int = getDiaryLevelIndex(diaryType, level)
|
||||
|
||||
protected open fun onAreaVisited(player: Player) {
|
||||
areaTasks.forEach {
|
||||
|
||||
Reference in New Issue
Block a user