mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-02 09:17:19 -04:00
Add npc.txt loader (#650)
This commit is contained in:
parent
c398c8f1ad
commit
9789372e8f
@ -258,6 +258,7 @@ func (a *App) loadDataDict() error {
|
||||
{d2resource.ElemType, d2datadict.LoadElemTypes},
|
||||
{d2resource.PlrMode, d2datadict.LoadPlrModes},
|
||||
{d2resource.PetType, d2datadict.LoadPetTypes},
|
||||
{d2resource.NPC, d2datadict.LoadNPCs},
|
||||
}
|
||||
|
||||
d2datadict.InitObjectRecords()
|
||||
|
100
d2common/d2data/d2datadict/npc.go
Normal file
100
d2common/d2data/d2datadict/npc.go
Normal file
@ -0,0 +1,100 @@
|
||||
package d2datadict
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
||||
)
|
||||
|
||||
//NPCRecord represents a single line in NPC.txt
|
||||
//The information has been gathered from [https://d2mods.info/forum/kb/viewarticle?a=387]
|
||||
type NPCRecord struct {
|
||||
//ID pointer to row of this npc in monstats.txt
|
||||
NPC string
|
||||
|
||||
//Percentage of base item price used when an item is bought by NPC
|
||||
//Actual value in file is fraction of 1024
|
||||
//Notice: BuyMultiplier used when selling an item to an NPC
|
||||
BuyMultiplier float64
|
||||
|
||||
//Percentage of base item price used when an item is sold by NPC
|
||||
//Actual value in file is fraction of 1024
|
||||
//Notice: SellMultiplier used when buying an item from an NPC
|
||||
SellMultiplier float64
|
||||
|
||||
//Percentage of base item price used to calculate the base repair price
|
||||
//Actual value in file is fraction of 1024
|
||||
RepairMultiplier float64
|
||||
|
||||
//The quest flag that must be checked to activate the corresponding QuestBuyMultiplier
|
||||
QuestFlagA int
|
||||
|
||||
//Percentage of change of multiplier when the corresponding quest flag is checked
|
||||
//Example: Quest flag A is checked, so the item price will be: (base price) * BuyMultiplier * QuestBuyMultiplierA
|
||||
//Actual value in file is fraction of 1024
|
||||
QuestBuyMultiplierA float64
|
||||
|
||||
//Percentage of change of multiplier when the corresponding quest flag is checked
|
||||
//Actual value in file is fraction of 1024
|
||||
QuestSellMultiplierA float64
|
||||
|
||||
//Percentage of change of multiplier when the corresponding quest flag is checked
|
||||
//Actual value in file is fraction of 1024
|
||||
QuestRepairMultiplierA float64
|
||||
|
||||
//ditto, three quests maximum
|
||||
QuestFlagB int
|
||||
QuestBuyMultiplierB float64
|
||||
QuestSellMultiplierB float64
|
||||
QuestRepairMultiplierB float64
|
||||
|
||||
QuestFlagC int
|
||||
QuestBuyMultiplierC float64
|
||||
QuestSellMultiplierC float64
|
||||
QuestRepairMultiplierC float64
|
||||
|
||||
//The maximum amount of gold an NPC will pay for an item for the corresponding difficulty
|
||||
MaxBuy int
|
||||
MaxBuyNightmare int
|
||||
MaxBuyHell int
|
||||
}
|
||||
|
||||
//NPCs stores the NPCRecords
|
||||
var NPCs map[string]*NPCRecord //nolint:gochecknoglobals // Currently global by design
|
||||
|
||||
//LoadNPCs loads NPCRecords into NPCs
|
||||
func LoadNPCs(file []byte) {
|
||||
NPCs = make(map[string]*NPCRecord)
|
||||
|
||||
d := d2common.LoadDataDictionary(file)
|
||||
for d.Next() {
|
||||
record := &NPCRecord{
|
||||
NPC: d.String("npc"),
|
||||
BuyMultiplier: float64(d.Number("buy mult")) / 1024.,
|
||||
SellMultiplier: float64(d.Number("sell mult")) / 1024.,
|
||||
RepairMultiplier: float64(d.Number("rep mult")) / 1024.,
|
||||
QuestFlagA: d.Number("questflag A"),
|
||||
QuestBuyMultiplierA: float64(d.Number("questbuymult A")) / 1024.,
|
||||
QuestSellMultiplierA: float64(d.Number("questsellmult A")) / 1024.,
|
||||
QuestRepairMultiplierA: float64(d.Number("questrepmult A")) / 1024.,
|
||||
QuestFlagB: d.Number("questflag B"),
|
||||
QuestBuyMultiplierB: float64(d.Number("questbuymult B")) / 1024.,
|
||||
QuestSellMultiplierB: float64(d.Number("questsellmult B")) / 1024.,
|
||||
QuestRepairMultiplierB: float64(d.Number("questrepmult B")) / 1024.,
|
||||
QuestFlagC: d.Number("questflag C"),
|
||||
QuestBuyMultiplierC: float64(d.Number("questbuymult C")) / 1024.,
|
||||
QuestSellMultiplierC: float64(d.Number("questsellmult C")) / 1024.,
|
||||
QuestRepairMultiplierC: float64(d.Number("questrepmult C")) / 1024.,
|
||||
MaxBuy: d.Number("max buy"),
|
||||
MaxBuyNightmare: d.Number("max buy (N)"),
|
||||
MaxBuyHell: d.Number("max buy (H)"),
|
||||
}
|
||||
NPCs[record.NPC] = record
|
||||
}
|
||||
|
||||
if d.Err != nil {
|
||||
panic(d.Err)
|
||||
}
|
||||
|
||||
log.Printf("Loaded %d NPC records", len(NPCs))
|
||||
}
|
@ -202,6 +202,7 @@ const (
|
||||
ElemType = "/data/global/excel/ElemTypes.txt"
|
||||
PlrMode = "/data/global/excel/PlrMode.txt"
|
||||
PetType = "/data/global/excel/pettype.txt"
|
||||
NPC = "/data/global/excel/npc.txt"
|
||||
|
||||
// --- Animations ---
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user