mrbot/common/KnowledgeBook.iss
2023-12-08 15:07:11 -06:00

315 lines
8.5 KiB
Plaintext

#include "${LavishScript.HomeDirectory}/Scripts/mr/common/StringHelpers.iss"
objectdef AbilityEffect
{
variable int64 ID
variable int64 Indentation
variable string Description
method Initialize(jsonvalueref jo)
{
This:FromJSON[jo]
}
method FromJSON(jsonvalueref jo)
{
echo "AbilityEffect:FromJSON ${jo.Type}"
if !${jo.Type.Equal[object]}
{
return FALSE
}
ID:Set["${jo.Get[ID]~}"]
Indentation:Set["${jo.Get[Indentation]~}"]
Description:Set["${jo.Get[Description]~}"]
}
member:jsonvalueref AsJSON()
{
variable jsonvalue jo="{}"
jo:SetInteger[ID, "${ID~}"]
jo:SetInteger[Indentation, "${Indentation~}"]
jo:SetString[Description, "${Description~}"]
return jo
}
}
objectdef AbilityEffectCollection
{
variable index:AbilityEffect Effects
method AddEffectFromJSON(jsonvalueref jo)
{
if !${jo.Type.Equal[object]}
{
echo "AbilityEffectCollection:AddEffectFromJSON jo is not an object"
return FALSE
}
Effects:Insert[jo]
}
method FromJSON(jsonvalueref jo)
{
if !${jo.Type.Equal[array]}
{
return FALSE
}
jo:ForEach["This:AddEffectFromJSON[ForEach.Value]"]
}
member:jsonvalueref AsJSON()
{
variable jsonvalue jo="[]"
variable iterator effectIterator
Effects:GetIterator[effectIterator]
if ${effectIterator:First(exists)}
{
do
{
jo:Add["${effectIterator.Value.AsJSON~}"]
}
while ${effectIterator:Next(exists)}
}
return jo
}
}
objectdef AbilityDetail
{
variable int64 ID
variable string Name
variable string Description
variable int Level
variable string Tier
variable int HealthCost
variable int PowerCost
variable int DissonanceCost
variable int SavageryCost
variable int ConcentrationCost
variable float CastingTime
variable float RecoveryTime
variable float RecastTime
variable float MaxDuration
variable int HealthCostPerTick
variable int PowerCostPerTick
variable int DissonanceCostPerTick
variable int SavageryCostPerTick
variable int MaxAOETargets
variable bool IsBeneficial
variable bool DoesNotExpire
variable bool GroupRestricted
variable bool AllowRaid
variable int TargetType
variable int SpellBookType
variable float MinRange
variable float MaxRange
variable AbilityEffectCollection Effects
method Initialize(jsonvalueref jo)
{
This:FromJSON[jo]
}
method FromJSON(jsonvalueref jo)
{
if !${jo.Type.Equal[object]}
{
return FALSE
}
Name:Set["${jo.Get[Name]~}"]
Description:Set["${jo.Get[Description]~}"]
ID:Set["${jo.Get[ID]~}"]
Level:Set["${jo.Get[Level]~}"]
Tier:Set["${jo.Get[Tier]~}"]
HealthCost:Set["${jo.Get[HealthCost]~}"]
PowerCost:Set["${jo.Get[PowerCost]~}"]
DissonanceCost:Set["${jo.Get[DissonanceCost]~}"]
SavageryCost:Set["${jo.Get[SavageryCost]~}"]
ConcentrationCost:Set["${jo.Get[ConcentrationCost]~}"]
CastingTime:Set["${jo.Get[CastingTime]~}"]
RecoveryTime:Set["${jo.Get[RecoveryTime]~}"]
RecastTime:Set["${jo.Get[RecastTime]~}"]
MaxDuration:Set["${jo.Get[MaxDuration]~}"]
HealthCostPerTick:Set["${jo.Get[HealthCostPerTick]~}"]
PowerCostPerTick:Set["${jo.Get[PowerCostPerTick]~}"]
DissonanceCostPerTick:Set["${jo.Get[DissonanceCostPerTick]~}"]
SavageryCostPerTick:Set["${jo.Get[SavageryCostPerTick]~}"]
MaxAOETargets:Set["${jo.Get[MaxAOETargets]~}"]
IsBeneficial:Set["${jo.Get[IsBeneficial]~}"]
DoesNotExpire:Set["${jo.Get[DoesNotExpire]~}"]
GroupRestricted:Set["${jo.Get[GroupRestricted]~}"]
AllowRaid:Set["${jo.Get[AllowRaid]~}"]
TargetType:Set["${jo.Get[TargetType]~}"]
SpellBookType:Set["${jo.Get[SpellBookType]~}"]
MinRange:Set["${jo.Get[MinRange]~}"]
MaxRange:Set["${jo.Get[MaxRange]~}"]
Effects:FromJSON["${jo.Get["Effects"]~}"]
}
member:jsonvalueref AsJSON()
{
variable jsonvalue jo="{}"
jo:SetString[Name, "${Name~}"]
jo:SetString[Description, "${Description~}"]
jo:SetString[ID, "${ID~}"]
jo:SetInteger[Level, "${Level~}"]
jo:SetString[Tier, "${Tier~}"]
jo:SetInteger[HealthCost, "${HealthCost~}"]
jo:SetInteger[PowerCost, "${PowerCost~}"]
jo:SetInteger[DissonanceCost, "${DissonanceCost~}"]
jo:SetInteger[SavageryCost, "${SavageryCost~}"]
jo:SetInteger[ConcentrationCost, "${ConcentrationCost~}"]
jo:SetNumber[CastingTime, "${CastingTime~}"]
jo:SetNumber[RecoveryTime, "${RecoveryTime~}"]
jo:SetNumber[RecastTime, "${RecastTime~}"]
jo:SetNumber[MaxDuration, "${MaxDuration~}"]
jo:SetInteger[HealthCostPerTick, "${HealthCostPerTick~}"]
jo:SetInteger[PowerCostPerTick, "${PowerCostPerTick~}"]
jo:SetInteger[DissonanceCostPerTick, "${DissonanceCostPerTick~}"]
jo:SetInteger[SavageryCostPerTick, "${SavageryCostPerTick~}"]
jo:SetInteger[MaxAOETargets, "${MaxAOETargets~}"]
jo:SetBool[IsBeneficial, "${IsBeneficial~}"]
jo:SetBool[DoesNotExpire, "${DoesNotExpire~}"]
jo:SetBool[GroupRestricted, "${GroupRestricted~}"]
jo:SetBool[AllowRaid, "${AllowRaid~}"]
jo:SetInteger[TargetType, "${TargetType~}"]
jo:SetInteger[SpellBookType, "${SpellBookType~}"]
jo:SetNumber[MinRange, "${MinRange~}"]
jo:SetNumber[MaxRange, "${MaxRange~}"]
jo:Set[Effects, "${Effects.AsJSON~}"]
return jo
}
}
objectdef Ability
{
variable string Name
variable AbilityDetail Details
variable int HighestLevel
variable int CurrentID
method Initialize(jsonvalueref jo)
{
This:FromJSON[jo]
}
method FromJSON(jsonvalueref jo)
{
if !${jo.Type.Equal[object]}
{
echo "Ability:FromJson jo is not an object"
return FALSE
}
Name:Set["${jo.Get[Name]~}"]
CurrentID:Set[${jo.GetInteger["CurrentID"]}]
HighestLevel:Set[${jo.GetInteger["HighestLevel"]}]
Details:FromJSON["${jo.Get["Details"]~}"]
}
member:jsonvalueref AsJSON()
{
variable jsonvalue jo="{}"
jo:SetString[Name, "${Name~}"]
jo:SetInteger[CurrentID, ${CurrentID}]
jo:SetInteger[HighestLevel, ${HighestLevel}]
jo:Set[Details, "${Details.AsJSON~}"]
return jo
}
}
objectdef KnowledgeBook
{
variable collection:Ability Abilities
method AddAbilityFromJSON(jsonvalueref jo)
{
variable StringHelpers stringHelpers
variable string abilityLine = "${stringHelpers.StripRomanNumerals[${jo.Get["Name"]}]}"
if ${jo.GetInteger["Level"]} < ${Abilities.Element["${abilityLine}"].HighestLevel}
{
return
}
variable jsonvalue tiers = "[]"
variable jsonvalue abilityLineJSON = "{}"
abilityLineJSON:SetValue[$$>"{
"Name": "${abilityLine~}",
"HighestLevel": ${jo.GetInteger["Level"]},
"CurrentID": ${jo.GetInteger["ID"]},
"Details": ${jo.AsJSON~}
}"<$$]
Abilities:Set["${abilityLine}", abilityLineJSON]
}
method FromFile(string filename)
{
variable jsonvalue jo
jo:ParseFile["${filename}"]
This:FromJSON[jo]
}
method WriteFile(string filename)
{
This.AsJSON:WriteFile["${filename}", multiline]
}
method AddAbilityLineFromJson(jsonvalueref jo)
{
if !${jo.Type.Equal[object]}
{
return FALSE
}
Abilities:Set[${jo.Get["Name"].AsJSON}, jo]
}
method FromJSON(jsonvalueref jo)
{
if !${jo.Type.Equal[array]}
{
echo "jo is not an array ${jo.Type}"
return FALSE
}
jo:ForEach["This:AddAbilityLineFromJson[ForEach.Value]"]
}
member:jsonvalueref AsJSON()
{
variable jsonvalue jo="[]"
variable iterator abilityIterator
Abilities:GetIterator[abilityIterator]
if ${abilityIterator:First(exists)}
{
do
{
jo:Add["${abilityIterator.Value.AsJSON~}"]
}
while ${abilityIterator:Next(exists)}
}
return jo
}
}