Skip to content

Commit df50a25

Browse files
authored
Expanding scripting object methods
# Description Expands the scripting API surface for `ActorObject`, `RoomObject`, `ItemObject`, `PetObject`, and `ContainerObject` with a broad set of new methods covering character state, inventory, equipment, quests, skills, spells, cooldowns, combat state, room properties, and container inspection. Updates the admin scripting reference documentation to match, and corrects "See Also" links across all script type pages to point to the new `scripting-objects` reference instead of the old `scripting-functions` anchors. ## Changes **`internal/scripting/actor_func.go`** - Added `GetDescription` — returns the actor's current description text - Added `GetGold` / `GetBank` — returns carried gold and banked gold - Added `GetWornItems` / `GetWornItem(slot)` — returns all equipped items or the item in a specific slot - Added `FindInBackpack(itemName)` / `FindOnBody(itemName)` — fuzzy-search actor inventory and equipped slots - Added `IsQuestDone(questToken)` / `ClearQuestToken(questToken)` — check quest completion and reset quest progress - Added `GetAllSkills` / `GetSpells` — return skill ranks and spellbook as maps - Added `UnLearnSpell` / `DisableSpell` / `EnableSpell` — mutate the actor's spellbook - Added `GetCooldown(tag)` / `TryCooldown(tag, period)` — read and atomically check-and-set cooldowns - Added `GetSetting(name)` / `SetSetting(name, value)` — read and write persistent character settings - Added `GetExperience` / `GetExtraLives` — read progression state - Added `IsInCombat` / `IsDowned` — check combat and health state - Added `GetDefense` / `GetGearValue` / `GetCarryCapacity` — read gear and carry stats - Added `GetZoneVisitProgress(zoneName)` — returns visited/total/percent exploration for a zone (user actors only) - Added `GetAdjectives` / `HasAdjective(adj)` — inspect actor adjective state - Added `GetActionPoints` / `GetActionPointsMax` — read current and maximum action points - Added `GetHealthAppearance` — returns a human-readable health description string **`internal/scripting/room_func.go`** - Added `GetTitle` / `SetTitle(title)` — read and write the room's title - Added `GetDescription` / `SetDescription(desc)` — read and write the room's description - Added `GetGold` / `AddGold(amount)` / `RemoveGold(amount)` — inspect and mutate floor gold - Added `GetZone` — returns the room's zone name - Added `IsPvp` / `IsBank` — check room flags - Added `GetContainer(name)` — returns a `ContainerObject` for the named container, or null - Added `SpawnTempContainer(name, duration, lockDifficulty, ...trapBuffIds)` — creates a temporary container - Added `IsCalm` / `AreMobsAttacking(userId)` / `ArePlayersAttacking(userId)` — query room combat state - Added `MobCount` / `PlayerCount` — returns occupant counts - Added `GetVisibility` — returns the room's current light level (0=dark, 1=dim, 2=lit) - Added `GetNouns` / `AddNoun(noun, desc)` / `RemoveNoun(noun)` — manage room interactive nouns - Added `GetSigns` / `AddSign(text, userId, days)` — read and post room signs - Added `HasRecentVisitors` — returns whether the room has had recent activity - Added `ContainerObject.GetLockDifficulty` / `GetTrapBuffIds` / `GetDespawnRound` / `Exists` — inspect container lock and lifecycle state **`internal/scripting/item_func.go`** - Added `GetType` / `GetSubtype` — returns the item's type and subtype strings - Added `GetValue` / `GetDescription` / `GetQuestToken` / `GetElement` — read item spec fields - Added `GetBuffIds` / `GetWornBuffIds` — returns use and passive buff IDs - Added `GetStatMods` — returns stat modifier map - Added `GetDamageReduction` / `GetDamage` — read armor and weapon stats - Added `GetBreakChance` / `GetKeyLockId` — read item fragility and key lock ID - Added `IsCursed` / `HasUses` / `IsWearable` / `IsWeapon` — boolean item classification helpers **`internal/scripting/pet_func.go`** - Added `GetItems` — returns all items in the pet's inventory - Added `FindItem(itemName)` — fuzzy-search pet inventory - Added `StoreItem(item)` / `RemoveItem(item)` — add and remove items from pet inventory - Added `GetBuffIds` — returns the passive buff IDs the pet grants its owner **Admin documentation (`_datafiles/html/admin/`)** - Added documentation entries for all new methods to `scripting-objects.html` under their respective object sections - Updated `scripting.html` to include `ContainerObject` in the function reference description - Updated "See Also" links in `scripting-buffs.html`, `scripting-items.html`, `scripting-mobs.html`, `scripting-pets.html`, `scripting-rooms.html`, and `scripting-spells.html` to point to `scripting-objects` anchors instead of the old `scripting-functions` anchors - Added a `ContainerObject Reference` See Also link to `scripting-rooms.html`
1 parent 6c1cd15 commit df50a25

12 files changed

Lines changed: 1144 additions & 14 deletions

_datafiles/html/admin/scripting-buffs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ <h2>Event Hooks</h2>
168168
<div class="see-also">
169169
<h3>See Also</h3>
170170
<div class="see-also-links">
171-
<a class="see-also-link" href="/admin/scripting-functions#actor">ActorObject Functions</a>
171+
<a class="see-also-link" href="/admin/scripting-objects#actor">ActorObject Reference</a>
172172
<a class="see-also-link" href="/admin/buffs">Buff Definitions</a>
173173
<a class="see-also-link" href="/admin/scripting">Scripting Overview</a>
174174
</div>

_datafiles/html/admin/scripting-items.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,9 @@ <h2>Event Hooks</h2>
239239
<div class="see-also">
240240
<h3>See Also</h3>
241241
<div class="see-also-links">
242-
<a class="see-also-link" href="/admin/scripting-functions#item">ItemObject Functions</a>
243-
<a class="see-also-link" href="/admin/scripting-functions#actor">ActorObject Functions</a>
244-
<a class="see-also-link" href="/admin/scripting-functions#room">RoomObject Functions</a>
242+
<a class="see-also-link" href="/admin/scripting-objects#item">ItemObject Reference</a>
243+
<a class="see-also-link" href="/admin/scripting-objects#actor">ActorObject Reference</a>
244+
<a class="see-also-link" href="/admin/scripting-objects#room">RoomObject Reference</a>
245245
<a class="see-also-link" href="/admin/scripting">Scripting Overview</a>
246246
</div>
247247
</div>

_datafiles/html/admin/scripting-mobs.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,9 @@ <h2>Event Hooks</h2>
370370
<div class="see-also">
371371
<h3>See Also</h3>
372372
<div class="see-also-links">
373-
<a class="see-also-link" href="/admin/scripting-functions#actor">ActorObject Functions</a>
374-
<a class="see-also-link" href="/admin/scripting-functions#room">RoomObject Functions</a>
375-
<a class="see-also-link" href="/admin/scripting-functions#item">ItemObject Functions</a>
373+
<a class="see-also-link" href="/admin/scripting-objects#actor">ActorObject Reference</a>
374+
<a class="see-also-link" href="/admin/scripting-objects#room">RoomObject Reference</a>
375+
<a class="see-also-link" href="/admin/scripting-objects#item">ItemObject Reference</a>
376376
<a class="see-also-link" href="/admin/scripting-functions#messaging">Messaging Functions</a>
377377
<a class="see-also-link" href="/admin/scripting">Scripting Overview</a>
378378
</div>

_datafiles/html/admin/scripting-objects.html

Lines changed: 585 additions & 0 deletions
Large diffs are not rendered by default.

_datafiles/html/admin/scripting-pets.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ <h2>Event Hooks</h2>
228228
<div class="see-also">
229229
<h3>See Also</h3>
230230
<div class="see-also-links">
231-
<a class="see-also-link" href="/admin/scripting-functions#pet">PetObject Functions</a>
232-
<a class="see-also-link" href="/admin/scripting-functions#actor">ActorObject Functions</a>
233-
<a class="see-also-link" href="/admin/scripting-functions#room">RoomObject Functions</a>
231+
<a class="see-also-link" href="/admin/scripting-objects#pet">PetObject Reference</a>
232+
<a class="see-also-link" href="/admin/scripting-objects#actor">ActorObject Reference</a>
233+
<a class="see-also-link" href="/admin/scripting-objects#room">RoomObject Reference</a>
234234
<a class="see-also-link" href="/admin/pets">Pet Definitions</a>
235235
<a class="see-also-link" href="/admin/scripting">Scripting Overview</a>
236236
</div>

_datafiles/html/admin/scripting-rooms.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,9 @@ <h2>Event Hooks</h2>
413413
<div class="see-also">
414414
<h3>See Also</h3>
415415
<div class="see-also-links">
416-
<a class="see-also-link" href="/admin/scripting-functions#actor">ActorObject Functions</a>
417-
<a class="see-also-link" href="/admin/scripting-functions#room">RoomObject Functions</a>
416+
<a class="see-also-link" href="/admin/scripting-objects#actor">ActorObject Reference</a>
417+
<a class="see-also-link" href="/admin/scripting-objects#room">RoomObject Reference</a>
418+
<a class="see-also-link" href="/admin/scripting-objects#container">ContainerObject Reference</a>
418419
<a class="see-also-link" href="/admin/scripting-functions#messaging">Messaging Functions</a>
419420
<a class="see-also-link" href="/admin/scripting">Scripting Overview</a>
420421
</div>

_datafiles/html/admin/scripting-spells.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ <h2>Event Hooks</h2>
193193
<div class="see-also">
194194
<h3>See Also</h3>
195195
<div class="see-also-links">
196-
<a class="see-also-link" href="/admin/scripting-functions#actor">ActorObject Functions</a>
196+
<a class="see-also-link" href="/admin/scripting-objects#actor">ActorObject Reference</a>
197197
<a class="see-also-link" href="/admin/spells">Spell Definitions</a>
198198
<a class="see-also-link" href="/admin/scripting">Scripting Overview</a>
199199
</div>

_datafiles/html/admin/scripting.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ <h2>Quick Links</h2>
268268
<div class="feature-card-icon">📖</div>
269269
<div class="feature-card-body">
270270
<div class="feature-card-title">Function Reference</div>
271-
<div class="feature-card-desc">Complete API docs for ActorObject, RoomObject, ItemObject, PetObject, PartyObject, Utility, Messaging, and Panel functions.</div>
271+
<div class="feature-card-desc">Complete API docs for ActorObject, RoomObject, ItemObject, PetObject, PartyObject, ContainerObject, Utility, Messaging, and Panel functions.</div>
272272
</div>
273273
</a>
274274
<a class="feature-card" href="/admin/scripting-api">

internal/scripting/actor_func.go

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import (
88
"github.com/GoMudEngine/GoMud/internal/combat"
99
"github.com/GoMudEngine/GoMud/internal/configs"
1010
"github.com/GoMudEngine/GoMud/internal/events"
11+
"github.com/GoMudEngine/GoMud/internal/items"
1112
"github.com/GoMudEngine/GoMud/internal/mobs"
1213
"github.com/GoMudEngine/GoMud/internal/races"
1314
"github.com/GoMudEngine/GoMud/internal/rooms"
1415
"github.com/GoMudEngine/GoMud/internal/skills"
1516
"github.com/GoMudEngine/GoMud/internal/templates"
1617
"github.com/GoMudEngine/GoMud/internal/users"
18+
"github.com/GoMudEngine/GoMud/internal/util"
1719
"github.com/dop251/goja"
1820
)
1921

@@ -914,3 +916,186 @@ func ActorNames(actorList []*ScriptActor) string {
914916

915917
return sBuilder.String()
916918
}
919+
920+
// ////////////////////////////////////////////////////////
921+
//
922+
// New ScriptActor methods
923+
//
924+
// ////////////////////////////////////////////////////////
925+
926+
func (a ScriptActor) GetDescription() string {
927+
return a.characterRecord.GetDescription()
928+
}
929+
930+
func (a ScriptActor) GetGold() int {
931+
return a.characterRecord.Gold
932+
}
933+
934+
func (a ScriptActor) GetBank() int {
935+
return a.characterRecord.Bank
936+
}
937+
938+
func (a ScriptActor) GetWornItems() []ScriptItem {
939+
itms := make([]ScriptItem, 0)
940+
for _, itm := range a.characterRecord.GetAllWornItems() {
941+
itms = append(itms, newScriptItem(itm))
942+
}
943+
return itms
944+
}
945+
946+
func (a ScriptActor) GetWornItem(slot string) *ScriptItem {
947+
itm := a.characterRecord.Equipment.Get(items.ItemType(slot))
948+
if itm == nil || itm.ItemId <= 0 || itm.IsDisabled() {
949+
return nil
950+
}
951+
si := newScriptItem(*itm)
952+
return &si
953+
}
954+
955+
func (a ScriptActor) FindInBackpack(itemName string) *ScriptItem {
956+
itm, found := a.characterRecord.FindInBackpack(itemName)
957+
if !found {
958+
return nil
959+
}
960+
si := newScriptItem(itm)
961+
return &si
962+
}
963+
964+
func (a ScriptActor) FindOnBody(itemName string) *ScriptItem {
965+
itm, found := a.characterRecord.FindOnBody(itemName)
966+
if !found {
967+
return nil
968+
}
969+
si := newScriptItem(itm)
970+
return &si
971+
}
972+
973+
func (a ScriptActor) IsQuestDone(questToken string) bool {
974+
return a.characterRecord.IsQuestDone(questToken)
975+
}
976+
977+
func (a ScriptActor) ClearQuestToken(questToken string) {
978+
a.characterRecord.ClearQuestToken(questToken)
979+
}
980+
981+
func (a ScriptActor) GetAllSkills() map[string]int {
982+
return a.characterRecord.GetAllSkillRanks()
983+
}
984+
985+
func (a ScriptActor) GetSpells() map[string]int {
986+
return a.characterRecord.GetSpells()
987+
}
988+
989+
func (a ScriptActor) UnLearnSpell(spellId string) bool {
990+
return a.characterRecord.UnLearnSpell(spellId)
991+
}
992+
993+
func (a ScriptActor) DisableSpell(spellId string) bool {
994+
return a.characterRecord.DisableSpell(spellId)
995+
}
996+
997+
func (a ScriptActor) EnableSpell(spellId string) bool {
998+
return a.characterRecord.EnableSpell(spellId)
999+
}
1000+
1001+
func (a ScriptActor) GetCooldown(tag string) int {
1002+
return a.characterRecord.GetCooldown(tag)
1003+
}
1004+
1005+
func (a ScriptActor) TryCooldown(tag string, period string) bool {
1006+
return a.characterRecord.TryCooldown(tag, period)
1007+
}
1008+
1009+
func (a ScriptActor) GetSetting(name string) string {
1010+
return a.characterRecord.GetSetting(name)
1011+
}
1012+
1013+
func (a ScriptActor) SetSetting(name string, value string) {
1014+
a.characterRecord.SetSetting(name, value)
1015+
}
1016+
1017+
func (a ScriptActor) GetExperience() int {
1018+
return a.characterRecord.Experience
1019+
}
1020+
1021+
func (a ScriptActor) GetExtraLives() int {
1022+
return a.characterRecord.ExtraLives
1023+
}
1024+
1025+
func (a ScriptActor) IsInCombat() bool {
1026+
return a.characterRecord.Aggro != nil
1027+
}
1028+
1029+
func (a ScriptActor) IsDowned() bool {
1030+
return a.characterRecord.Health < 1
1031+
}
1032+
1033+
func (a ScriptActor) GetDefense() int {
1034+
return a.characterRecord.GetDefense()
1035+
}
1036+
1037+
func (a ScriptActor) GetGearValue() int {
1038+
return a.characterRecord.GetGearValue()
1039+
}
1040+
1041+
func (a ScriptActor) GetCarryCapacity() int {
1042+
return a.characterRecord.CarryCapacity()
1043+
}
1044+
1045+
func (a ScriptActor) GetZoneVisitProgress(zoneName string) map[string]any {
1046+
resolvedZone := rooms.FindZoneName(zoneName)
1047+
if resolvedZone == `` {
1048+
return map[string]any{`visited`: 0, `total`: 0, `percent`: 0}
1049+
}
1050+
zCfg := rooms.GetZoneConfig(resolvedZone)
1051+
var validRoomIds map[int]struct{}
1052+
if zCfg != nil {
1053+
validRoomIds = zCfg.RoomIds
1054+
}
1055+
visited, total := a.characterRecord.ZoneVisitProgress(resolvedZone, validRoomIds)
1056+
percent := 0
1057+
if total > 0 {
1058+
percent = int(float64(visited) / float64(total) * 100)
1059+
}
1060+
return map[string]any{`visited`: visited, `total`: total, `percent`: percent}
1061+
}
1062+
1063+
func (a ScriptActor) GetAdjectives() []string {
1064+
return a.characterRecord.GetAdjectives()
1065+
}
1066+
1067+
func (a ScriptActor) HasAdjective(adj string) bool {
1068+
return a.characterRecord.HasAdjective(adj)
1069+
}
1070+
1071+
func (a ScriptActor) GetActionPoints() int {
1072+
return a.characterRecord.ActionPoints
1073+
}
1074+
1075+
func (a ScriptActor) GetActionPointsMax() int {
1076+
return a.characterRecord.ActionPointsMax.Value
1077+
}
1078+
1079+
func (a ScriptActor) GetHealthAppearance() string {
1080+
if a.characterRecord.HealthMax.Value < 1 {
1081+
return a.GetCharacterName(true) + ` is in perfect health.`
1082+
}
1083+
nameTag := `username`
1084+
if a.mobRecord != nil {
1085+
nameTag = `mobname`
1086+
}
1087+
pct := int(float64(a.characterRecord.Health) / float64(a.characterRecord.HealthMax.Value) * 100)
1088+
className := util.HealthClass(a.characterRecord.Health, a.characterRecord.HealthMax.Value)
1089+
name := `<ansi fg="` + nameTag + `">` + a.characterRecord.Name + `</ansi>`
1090+
switch {
1091+
case pct < 15:
1092+
return name + ` looks like they're <ansi fg="` + className + `">about to die!</ansi>`
1093+
case pct < 50:
1094+
return name + ` looks to be in <ansi fg="` + className + `">pretty bad shape.</ansi>`
1095+
case pct < 80:
1096+
return name + ` has some <ansi fg="` + className + `">cuts and bruises.</ansi>`
1097+
case pct < 100:
1098+
return name + ` has <ansi fg="` + className + `">a few scratches.</ansi>`
1099+
}
1100+
return name + ` is in <ansi fg="` + className + `">perfect health.</ansi>`
1101+
}

0 commit comments

Comments
 (0)