-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
56 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package hooks | ||
|
||
import ( | ||
"github.com/volte6/gomud/internal/events" | ||
"github.com/volte6/gomud/internal/rooms" | ||
"github.com/volte6/gomud/internal/users" | ||
) | ||
|
||
// | ||
// RoomChangeHandler waits for RoomChange events | ||
// It then sends out GMCP data updates | ||
// Also sends music changes out | ||
// | ||
|
||
func LocationMusicChange_Listener(e events.Event) bool { | ||
evt := e.(events.RoomChange) | ||
|
||
// If this isn't a user changing rooms, just pass it along. | ||
if evt.UserId == 0 { | ||
return true | ||
} | ||
|
||
// Get user... Make sure they still exist too. | ||
user := users.GetByUserId(evt.UserId) | ||
if user == nil { | ||
return false | ||
} | ||
|
||
// Get the new room data... abort if doesn't exist. | ||
newRoom := rooms.LoadRoom(evt.ToRoomId) | ||
if newRoom == nil { | ||
return false | ||
} | ||
|
||
// Get the old room data... abort if doesn't exist. | ||
oldRoom := rooms.LoadRoom(evt.FromRoomId) | ||
if oldRoom == nil { | ||
return false | ||
} | ||
|
||
// If this zone has music, play it. | ||
// Room music takes priority. | ||
if newRoom.MusicFile != `` { | ||
user.PlayMusic(newRoom.MusicFile) | ||
} else { | ||
zoneInfo := rooms.GetZoneConfig(newRoom.Zone) | ||
if zoneInfo.MusicFile != `` { | ||
user.PlayMusic(zoneInfo.MusicFile) | ||
} else if oldRoom.MusicFile != `` { | ||
user.PlayMusic(`Off`) | ||
} | ||
} | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters