Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions _datafiles/guides/building/scripting/FUNCTIONS_ACTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ ActorObjects are the basic object that represents Users and NPCs
- [ActorObject.SetTameMastery(mobId int, newSkillLevel int)](#actorobjectsettamemasterymobid-int-newskilllevel-int)
- [ActorObject.GetChanceToTame(target ScriptActor) int](#actorobjectgetchancetotametarget-scriptactor-int)
- [ActorObject.GetStatMod(statModName string) int](#actorobjectgetstatmodstatmodname-string-int)
- [ActorObject.IsHome() bool](#actorobjectishome-bool)
- [ActorObject.Pathing() bool](#actorobjectpathing-bool)
- [ActorObject.PathingAtWaypoint() bool](#actorobjectpathingatwaypoint-bool)



Expand Down Expand Up @@ -553,3 +556,12 @@ returns the total specific statmod from worn items and buffs
| Argument | Explanation |
| --- | --- |
| statModName | The name of the special stat mod, such as "strength" or "tame" |

## [ActorObject.IsHome() bool](/internal/scripting/actor_func.go)
(mobs only) Returns true if the actor is at their home roomId

## [ActorObject.Pathing() bool](/internal/scripting/actor_func.go)
(mobs only) Returns true if actor is currently pathing

## [ActorObject.PathingAtWaypoint() bool](/internal/scripting/actor_func.go)
(mobs only) Returns true if actor is pathing and at a waypoint.
13 changes: 13 additions & 0 deletions _datafiles/guides/building/scripting/SCRIPTING_MOBS.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,16 @@ function onDie(mob ActorObject, room RoomObject, eventDetails object) {

---

```
function onAsk(mob ActorObject, room RoomObject, eventDetails object) {
}
```

`onPath()` is called when mob is asked something. Returning `true` will end the pathing and skip any additional path processing.
NOTE: You can safely start a new path with `mob.Command('pathto 123')` before returning true, since the command will be executed slightly later in the event chain.

| Argument | Explanation |
| --- | --- |
| mob | [ActorObject](FUNCTIONS_ACTORS.md) |
| room | [RoomObject](FUNCTIONS_ROOMS.md) |
| eventDetails.status | `start`, `waypoint`, or `end` |
9 changes: 9 additions & 0 deletions _datafiles/world/default/conversations/frostfang/40.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-
Supported: # A map of lowercase names of "Initiator" (#1) to array of "Participant" (#2) names allowed to use this conversation.
"rodric": ["wench"]
Conversation:
- ["#1 sayto #2 I'll 'ave a mug 'o ale, wench!"]
- ["#2 say Very well, Rodric, but be off with you. We don't need you lingering around the guests smelling like death."]
- ["#2 emote hands Rodric a mug."]
- ["#1 say Aye, i'll be off, then."]
- ["#2 emote mumbles something under their breath."]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mobid: 40
zone: Frostfang Slums
zone: Frostfang
itemdropchance: 2
hostile: false
maxwander: 5
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@

SAID_STUFF = false;
WALK_DIRECTION = 1;
WALK_POSITION = 0;
WALK_PATH = [362, // old dock
333,
332,
331,
330,
329,
328,
327,
326,
325,
324,
323,
322,
321,
320,
319] // crashing waves leading to the rocky island
var SAID_STUFF = false; // Whether lakework has spoken this "visit" to the crash site

const HOME_ROOM_ID = 362; // old dock
const TRASH_PICKUP_SPOTS = [331,327,323,322]; // miscellaneous points along the way to do a random emote
const CRASH_ROOM_ID = 319; // crashing waves leading to the rocky island

const boatNouns = ["boats", "oars", "ships", "paddles"];
const crashNouns = ["rocks", "crash", "choppy", "water", "waves"];

// Emotes randomly selected at various waypoints.
const randomEmotes = [
"emote picks up some trash along the shoreline.",
"emote moves some driftwood to a pile.",
"emote picks up a small rock and throws it into the lake.",
"emote gently brushes leaves off a bench.",
"emote tosses a fallen branch off the trail.",
"emote stoops to examine a patch of wildflowers.",
"emote skips a stone across the water.",
"emote watches a dragonfly hover near the reeds.",
"emote nudges a small frog back toward the water.",
"emote smooths out a scuffed trail marker.",
"emote pauses to listen to the rustling trees.",
"emote adjusts a loose rock on the path.",
]

function onAsk(mob, room, eventDetails) {

roomId = room.RoomId();
match = UtilFindMatchIn(eventDetails.askText, boatNouns);
var roomId = room.RoomId();

var match = UtilFindMatchIn(eventDetails.askText, boatNouns);
if ( match.found ) {

if ( roomId == 319 ) {
if ( roomId == CRASH_ROOM_ID ) {

mob.Command("say I hit those rocks just over there and lost all of our oars.");
mob.Command("emote points to the northwest.");
Expand All @@ -49,7 +50,7 @@ function onAsk(mob, room, eventDetails) {
if ( match.found ) {


if ( roomId == 319 ) {
if ( roomId == CRASH_ROOM_ID ) {

mob.Command("say I hit those rocks just over there and lost all of our oars.");
mob.Command("emote points to the northwest.");
Expand Down Expand Up @@ -79,6 +80,20 @@ function onAsk(mob, room, eventDetails) {

}


function onPath(mob, room, eventDetails) {

if ( eventDetails.status == "waypoint" && mob.GetRoomId() != CRASH_ROOM_ID ) {

if ( UtilDiceRoll(1, 5) == 1 ) {
var emoteSelection = UtilDiceRoll(1, randomEmotes.length)-1;
mob.Command(randomEmotes[emoteSelection]);
}

}

}

function onGive(mob, room, eventDetails) {

if (eventDetails.item) {
Expand All @@ -99,61 +114,30 @@ function onGive(mob, room, eventDetails) {
// Invoked once every round if mob is idle
function onIdle(mob, room) {


if ( mob.GetRoomId() == 319 ) {
if ( mob.GetRoomId() == CRASH_ROOM_ID ) {

if ( !SAID_STUFF ) {
mob.Command("emote squints and peers towards a rocky island in the lake to the northwest.");
mob.Command("emote mutters to himself.");
if ( UtilDiceRoll(1, 2) == 1 ) {
mob.Command("say Ever since I crashed my boat on those rocks, I've been demoted to cleaning up the lakeshore.");
}
mob.Command("say Ever since I crashed my boat on those rocks, I've been demoted to cleaning up the lakeshore.", 2);

SAID_STUFF = true;
return true;
}
}

SAID_STUFF = false; // reset

} else if ( UtilDiceRoll(1, 2) > 1 ) {
if ( UtilDiceRoll(1, 2) > 1 ) {
return true;
}



if ( WALK_POSITION < 0 ) {
WALK_POSITION = 0;
} else if ( WALK_POSITION > WALK_PATH.length - 1) {
WALK_POSITION = WALK_PATH.length - 1;
if ( mob.IsHome() ) {
SAID_STUFF = false; // reset once they get home
mob.Command("pathto " + TRASH_PICKUP_SPOTS.join(" ") + " " + String(CRASH_ROOM_ID));
return true
}

roomNow = WALK_PATH[WALK_POSITION];

if ( roomNow != mob.GetRoomId() ) {

WALK_POSITION = 0;
WALK_DIRECTION = 1;
mob.MoveRoom(WALK_PATH[WALK_POSITION]);

} else {

if ( WALK_POSITION >= WALK_PATH.length -1 ) {
WALK_DIRECTION = -1;
}
if ( WALK_POSITION < 0 ) {
WALK_DIRECTION = 1;
}

WALK_POSITION += WALK_DIRECTION;

exitList = room.GetExits();
for (var key in exitList) {
if ( exitList[key].RoomId == WALK_PATH[WALK_POSITION] ) {
mob.Command( exitList[key].Name );

}
}

if ( mob.GetRoomId() == CRASH_ROOM_ID ) {
mob.Command("pathto " + TRASH_PICKUP_SPOTS.slice().reverse().join(" ") + " home");
}

return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

const startNouns = ["rat", "rats", "too many", "problem"];
const thievesNouns = ["thief", "thieves", "guild", "hideout", "entrance", "dogs", "slums"];
const INN_ROOM_ID = 61;

function onAsk(mob, room, eventDetails) {

Expand Down Expand Up @@ -111,24 +112,38 @@ function onGive(mob, room, eventDetails) {
}


RANDOM_IDLE = [
function onPath(mob, room, eventDetails) {

if ( eventDetails.status == "waypoint" && room.RoomId() == INN_ROOM_ID ) {
mob.Command("converse 1");
}

}

const RANDOM_IDLE = [
"emote shakes his head in disbelief.",
"emote attempts to fix a rat trap.",
"say There's just too many rats. We'll never get rid of them all.",
"say I'm so tired. I need a break.",
"say I'm running out of traps. I need to find more.",
"say I'm worried about the rats in the slums. They're everywhere!",
"say I'm running out of traps and don't seem to be making a dent in the rat numbers."
"say I'm running out of traps and don't seem to be making a dent in the rat numbers.",
"pathto "+String(INN_ROOM_ID),
];

// Invoked once every round if mob is idle
function onIdle(mob, room) {

if ( room.RoomId() == INN_ROOM_ID ) {
mob.Command("pathto home");
return true;
}

if ( UtilGetRoundNumber()%3 != 0 ) {
return true;
}

randNum = UtilDiceRoll(1, 10)-1;
randNum = UtilDiceRoll(1, 12)-1;
if ( randNum < RANDOM_IDLE.length ) {
mob.Command(RANDOM_IDLE[randNum]);
return true;
Expand Down
13 changes: 12 additions & 1 deletion internal/conversations/conversations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package conversations
import (
"fmt"
"os"
"strconv"
"strings"

"github.com/GoMudEngine/GoMud/internal/configs"
Expand All @@ -12,6 +13,7 @@ import (
)

var (
converseCheckCache = map[string]bool{}
conversations = map[int]*Conversation{}
conversationCounter = map[string]int{}
conversationUniqueId = 0
Expand Down Expand Up @@ -77,7 +79,6 @@ func AttemptConversation(initiatorMobId int, initatorInstanceId int, initiatorNa
}

lowestCount := -1

for _, index := range possibleConversations {
val := conversationCounter[fmt.Sprintf(`%s:%d`, fileName, index)]
if val < lowestCount || lowestCount == -1 {
Expand Down Expand Up @@ -155,16 +156,26 @@ func HasConverseFile(mobId int, zone string) bool {

zone = ZoneNameSanitize(zone)

cacheKey := strconv.Itoa(mobId) + `-` + zone
if result, ok := converseCheckCache[cacheKey]; ok {
if result == false {
return false
}
}

convFolder := string(configs.GetFilePathsConfig().DataFiles) + `/conversations`

fileName := fmt.Sprintf("%s/%d.yaml", zone, mobId)

filePath := util.FilePath(convFolder + `/` + fileName)

if _, err := os.Stat(filePath); err != nil {
converseCheckCache[cacheKey] = false
return false
}

converseCheckCache[cacheKey] = true

return true

}
Expand Down
Loading
Loading