Skip to content

Commit

Permalink
Merge pull request #6 from dofusdude/feat/alm
Browse files Browse the repository at this point in the history
Almanax
  • Loading branch information
stelzo authored Jan 27, 2024
2 parents 8a3a2d6 + 7516ca3 commit 8052102
Show file tree
Hide file tree
Showing 3 changed files with 251 additions and 14 deletions.
66 changes: 66 additions & 0 deletions mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package dodumap
import (
"fmt"
"log"
"strconv"
"strings"
)

var Languages = []string{"de", "en", "es", "fr", "it", "pt"}
Expand Down Expand Up @@ -91,6 +93,70 @@ func MapMounts(data *JSONGameData, langs *map[string]LangDict) []MappedMultilang
return mappedMounts
}

func MapAlmanax(data *JSONGameData, langs *map[string]LangDict) []MappedMultilangNPCAlmanax {
var mappedAlmanax []MappedMultilangNPCAlmanax

for _, almCat := range data.questCategories[31].QuestIds {
quest := data.quests[almCat]
if (*langs)["en"].Texts[quest.NameId][:8] != "Offering" {
continue
}

step := data.questSteps[quest.StepIds[0]]
objective := data.questObjectives[step.ObjectiveIds[0]].Parameters
item := data.Items[objective.Parameter1]
itemQuantity := objective.Parameter2

rewardKamas := int(data.questStepRewards[step.RewardsIds[0]].KamasRatio * 43980.0)
questObjectiveNpc := data.questObjectives[step.ObjectiveIds[2]].Parameters.Parameter0

var currAlm JSONGameAlamanaxCalendar
found := false
for _, almCal := range data.almanaxCalendars {
if almCal.NpcId == questObjectiveNpc {
currAlm = almCal
found = true
break
}
}
if !found {
log.Fatal(fmt.Sprintf("Could not find almanax calendar for NPC %d", questObjectiveNpc))
}

var mappedNPCAlmanax MappedMultilangNPCAlmanax
mappedNPCAlmanax.OfferingReceiver = (*langs)["en"].Texts[quest.NameId][13:] // remove "Offering to ". The name is the same in all languages.
itemNames := make(map[string]string)
mappedNPCAlmanax.Bonus = make(map[string]string)
mappedNPCAlmanax.BonusType = make(map[string]string)
for _, lang := range Languages {
itemNames[lang] = (*langs)[lang].Texts[item.NameId]
mappedNPCAlmanax.Bonus[lang] = (*langs)[lang].Texts[currAlm.DescId]
mappedNPCAlmanax.BonusType[lang] = (*langs)[lang].Texts[currAlm.NameId]

mappedNPCAlmanax.Bonus[lang] = strings.ReplaceAll(mappedNPCAlmanax.Bonus[lang], "<b>", "")
mappedNPCAlmanax.Bonus[lang] = strings.ReplaceAll(mappedNPCAlmanax.Bonus[lang], "</b>", "")
}
mappedNPCAlmanax.Offering.ItemId = item.Id
mappedNPCAlmanax.Offering.ItemName = itemNames
mappedNPCAlmanax.Offering.Quantity = itemQuantity
mappedNPCAlmanax.RewardKamas = rewardKamas

ImgBaseUrl := "https://api.dofusdu.de/dofus2/img/item/" + strconv.Itoa(item.IconId)
mappedNPCAlmanax.Offering.ImageUrls.HD = ImgBaseUrl + "-800.png"
mappedNPCAlmanax.Offering.ImageUrls.HQ = ImgBaseUrl + "-400.png"
mappedNPCAlmanax.Offering.ImageUrls.SD = ImgBaseUrl + "-200.png"
mappedNPCAlmanax.Offering.ImageUrls.Icon = ImgBaseUrl + ".png"

mappedAlmanax = append(mappedAlmanax, mappedNPCAlmanax)
}

if len(mappedAlmanax) == 0 {
return nil
}

return mappedAlmanax
}

func MapItems(data *JSONGameData, langs *map[string]LangDict) []MappedMultilangItem {
var filteredItems []JSONGameItem

Expand Down
42 changes: 42 additions & 0 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,12 @@ func ParseRawData(dir string) *JSONGameData {
mountFamilyChan := make(chan map[int]JSONGameMountFamily)
npcsChan := make(chan map[int]JSONGameNPC)
titlesChan := make(chan map[int]JSONGameTitle)
questsChan := make(chan map[int]JSONGameQuest)
questObjectivesChan := make(chan map[int]JSONGameQuestObjective)
questStepRewardsChan := make(chan map[int]JSONGameQuestStepRewards)
questCategoriesChan := make(chan map[int]JSONGameQuestCategory)
questStepsChan := make(chan map[int]JSONGameQuestStep)
almanaxCalendarsChan := make(chan map[int]JSONGameAlamanaxCalendar)

go func() {
ParseRawDataPart("npcs.json", npcsChan, dir)
Expand Down Expand Up @@ -589,6 +595,24 @@ func ParseRawData(dir string) *JSONGameData {
go func() {
ParseRawDataPart("titles.json", titlesChan, dir)
}()
go func() {
ParseRawDataPart("quests.json", questsChan, dir)
}()
go func() {
ParseRawDataPart("quest_objectives.json", questObjectivesChan, dir)
}()
go func() {
ParseRawDataPart("quest_step_rewards.json", questStepRewardsChan, dir)
}()
go func() {
ParseRawDataPart("quest_categories.json", questCategoriesChan, dir)
}()
go func() {
ParseRawDataPart("almanax.json", almanaxCalendarsChan, dir)
}()
go func() {
ParseRawDataPart("quest_steps.json", questStepsChan, dir)
}()

data.Items = <-itemChan
close(itemChan)
Expand Down Expand Up @@ -632,6 +656,24 @@ func ParseRawData(dir string) *JSONGameData {
data.titles = <-titlesChan
close(titlesChan)

data.quests = <-questsChan
close(questsChan)

data.questObjectives = <-questObjectivesChan
close(questObjectivesChan)

data.questStepRewards = <-questStepRewardsChan
close(questStepRewardsChan)

data.questCategories = <-questCategoriesChan
close(questCategoriesChan)

data.almanaxCalendars = <-almanaxCalendarsChan
close(almanaxCalendarsChan)

data.questSteps = <-questStepsChan
close(questStepsChan)

return &data
}

Expand Down
157 changes: 143 additions & 14 deletions parse_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,25 @@ type MappedMultilangItem struct {
HasParentSet bool `json:"hasParentSet"`
}

type MappedMultilangNPCAlmanax struct {
OfferingReceiver string `json:"offeringReceiver"`
Days []string `json:"days"`
Offering struct {
ItemId int `json:"itemId"`
ItemName map[string]string `json:"itemName"`
Quantity int `json:"quantity"`
ImageUrls struct {
HD string `json:"hd"`
HQ string `json:"hq"`
SD string `json:"sd"`
Icon string `json:"icon"`
}
}
Bonus map[string]string `json:"bonus"`
BonusType map[string]string `json:"bonusType"`
RewardKamas int `json:"rewardKamas"`
}

type JSONGameSpellType struct {
Id int `json:"id"`
LongNameId int `json:"longNameId"`
Expand Down Expand Up @@ -337,19 +356,129 @@ func (i JSONGameTitle) GetID() int {
return i.Id
}

type JSONGameCoordinate struct {
X int `json:"x"`
Y int `json:"y"`
}

type JSONGameQuestParameter struct {
DungeonOnly bool `json:"dungeonOnly"`
NumParams int `json:"numParams"`
Parameter0 int `json:"parameter0"`
Parameter1 int `json:"parameter1"`
Parameter2 int `json:"parameter2"`
Parameter3 int `json:"parameter3"`
Parameter4 int `json:"parameter4"`
}

type JSONGameQuestObjective struct {
Id int `json:"id"`
Coords JSONGameCoordinate `json:"coords"`
MapId int `json:"mapId"`
Parameters JSONGameQuestParameter `json:"parameters"`
StepId int `json:"stepId"`
TypeId int `json:"typeId"`
}

func (i JSONGameQuestObjective) GetID() int {
return i.Id
}

type JSONGameQuestCategory struct {
Id int `json:"id"`
NameId int `json:"nameId"`
Order int `json:"order"`
QuestIds []int `json:"questIds"`
}

func (i JSONGameQuestCategory) GetID() int {
return i.Id
}

type JSONGameQuest struct {
Id int `json:"id"`
NameId int `json:"nameId"`
StepIds []int `json:"stepIds"`
CategoryId int `json:"categoryId"`
RepeatType int `json:"repeatType"`
RepeatLimit int `json:"repeatLimit"`
IsDungeonQuest bool `json:"isDungeonQuest"`
LevelMin int `json:"levelMin"`
LevelMax int `json:"levelMax"`
Followable bool `json:"followable"`
IsPartyQuest bool `json:"isPartyQuest"`
StartCriterion string `json:"startCriterion"`
}

func (i JSONGameQuest) GetID() int {
return i.Id
}

type JSONGameQuestStepRewards struct {
Id int `json:"id"`
ExperienceRatio float64 `json:"experienceRatio"`
KamasRatio float64 `json:"kamasRatio"`
ItemsReward [][]int `json:"itemsReward"`
KamasScaleWithPlayerLevel bool `json:"kamasScaleWithPlayerLevel"`
LevelMax int `json:"levelMax"`
LevelMin int `json:"levelMin"`
//SpellsReward []int `json:"spellsReward"`
//EmotesReward []int `json:"emotesReward"`
//TitlesReward []int `json:"titlesReward"`
StepId int `json:"stepId"`
}

func (i JSONGameQuestStepRewards) GetID() int {
return i.Id
}

type JSONGameAlamanaxCalendar struct {
Id int `json:"id"`
DescId int `json:"descId"`
NameId int `json:"nameId"`
NpcId int `json:"npcId"`
BonusesIds []int `json:"bonusesIds"`
}

func (i JSONGameAlamanaxCalendar) GetID() int {
return i.Id
}

type JSONGameQuestStep struct {
Id int `json:"id"`
DescriptionId int `json:"descriptionId"`
DialogId int `json:"dialogId"`
NameId int `json:"nameId"`
OptimalLevel int `json:"optimalLevel"`
Duration float64 `json:"duration"`
ObjectiveIds []int `json:"objectiveIds"`
RewardsIds []int `json:"rewardsIds"`
QuestId int `json:"questId"`
}

func (i JSONGameQuestStep) GetID() int {
return i.Id
}

type JSONGameData struct {
Items map[int]JSONGameItem
Sets map[int]JSONGameSet
ItemTypes map[int]JSONGameItemType
effects map[int]JSONGameEffect
bonuses map[int]JSONGameBonus
Recipes map[int]JSONGameRecipe
spells map[int]JSONGameSpell
spellTypes map[int]JSONGameSpellType
areas map[int]JSONGameArea
Mounts map[int]JSONGameMount
classes map[int]JSONGameBreed
MountFamilys map[int]JSONGameMountFamily
npcs map[int]JSONGameNPC
titles map[int]JSONGameTitle
Items map[int]JSONGameItem
Sets map[int]JSONGameSet
ItemTypes map[int]JSONGameItemType
effects map[int]JSONGameEffect
bonuses map[int]JSONGameBonus
Recipes map[int]JSONGameRecipe
spells map[int]JSONGameSpell
spellTypes map[int]JSONGameSpellType
areas map[int]JSONGameArea
Mounts map[int]JSONGameMount
classes map[int]JSONGameBreed
MountFamilys map[int]JSONGameMountFamily
npcs map[int]JSONGameNPC
titles map[int]JSONGameTitle
questSteps map[int]JSONGameQuestStep
questObjectives map[int]JSONGameQuestObjective
questCategories map[int]JSONGameQuestCategory
quests map[int]JSONGameQuest
questStepRewards map[int]JSONGameQuestStepRewards
almanaxCalendars map[int]JSONGameAlamanaxCalendar
}

0 comments on commit 8052102

Please sign in to comment.