MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / newRoundHandler

Method newRoundHandler

modules/auctions/auctions.go:337–530  ·  view source on GitHub ↗
(e events.Event)

Source from the content-addressed store, hash-verified

335}
336
337func (mod *AuctionsModule) newRoundHandler(e events.Event) events.ListenerReturn {
338
339 evt := e.(events.NewRound)
340
341 auctionNow := mod.auctionMgr.GetCurrentAuction()
342 if auctionNow == nil {
343 return events.Continue
344 }
345
346 if auctionNow.IsEnded() {
347
348 mod.auctionMgr.EndAuction()
349
350 auctionNow.LastUpdate = evt.TimeNow
351
352 for _, uid := range users.GetOnlineUserIds() {
353
354 auctionTxt, _ := templates.Process("auctions/auction-end", auctionNow, uid)
355
356 if u := users.GetByUserId(uid); u != nil {
357 auctionOn := u.GetConfigOption(`auction`)
358 if auctionOn == nil || auctionOn.(bool) {
359 u.SendText(auctionTxt)
360 }
361 }
362 }
363
364 // Give the item to the winner and let them know
365 if auctionNow.HighestBidUserId > 0 {
366
367 if user := users.GetByUserId(auctionNow.HighestBidUserId); user != nil {
368 if user.Character.StoreItem(auctionNow.ItemData) {
369
370 events.AddToQueue(events.ItemOwnership{
371 UserId: user.UserId,
372 Item: auctionNow.ItemData,
373 Gained: true,
374 })
375
376 msg := fmt.Sprintf(`<ansi fg="yellow">You have won the auction for the <ansi fg="item">%s</ansi>! It has been added to your backpack.</ansi>`, auctionNow.ItemData.DisplayName())
377 user.SendText(msg)
378 }
379 } else {
380
381 msg := fmt.Sprintf(`You won the auction for the <ansi fg="item">%s</ansi> while you were offline.`, auctionNow.ItemData.DisplayName())
382
383 if sendInbox, ok := usercommands.GetExportedFunction(`SendMudMail`); ok {
384 if sendInboxFunc, ok := sendInbox.(func(int, string, string, int, *items.Item)); ok {
385 sendInboxFunc(auctionNow.HighestBidUserId, `Auction System`, msg, 0, &auctionNow.ItemData)
386 }
387 }
388
389 }
390
391 if auctionNow.SellerUserId > 0 {
392
393 msg := fmt.Sprintf(`Your auction of the <ansi fg="item">%s</ansi> has ended. The highest bid was made by <ansi fg="username">%s</ansi> for <ansi fg="gold">%d gold</ansi>.`, auctionNow.ItemData.DisplayName(), auctionNow.HighestBidderName, auctionNow.HighestBid)
394

Callers

nothing calls this directly

Calls 15

GetOnlineUserIdsFunction · 0.92
ProcessFunction · 0.92
GetByUserIdFunction · 0.92
AddToQueueFunction · 0.92
GetExportedFunctionFunction · 0.92
GetCurrentAuctionMethod · 0.80
IsEndedMethod · 0.80
EndAuctionMethod · 0.80
GetConfigOptionMethod · 0.80
SendTextMethod · 0.45
StoreItemMethod · 0.45
DisplayNameMethod · 0.45

Tested by

no test coverage detected