Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move raid system to globalevents #1813

Merged
merged 11 commits into from
Dec 13, 2023
Merged

Conversation

ranisalt
Copy link
Member

@ranisalt ranisalt commented Jun 2, 2016

This effectively nukes the raid system in favor of global events, which permit better management for raids. It's easier to define raids on interval, on exact times, force execution, force scheduling, add monsters on different delays and randomized amounts and positions... and also gets rid of a command.

I added a lib with helper functions to add monsters to a raid. The event is called onRaid and there is an example bundled pretty equivalent to the previous XML raid example. keep reading

@PrinterLUA
Copy link
Contributor

PrinterLUA commented Jun 2, 2016

Great job, but is it even necessary to have a seprate event for raid? We could just use onThink or onTime. If they wish and just create a raid library in lua.

It should be possible?

@ranisalt
Copy link
Member Author

ranisalt commented Jun 2, 2016

onRaid falls between onTime and onInterval here, it works as both. Yes it is possible to completely ditch onRaid and use just those two.

@TheSumm
Copy link
Contributor

TheSumm commented Jun 2, 2016

testraid.lua should use Position() constructor instead of the table constructor with x,y,z-fields.
I think it would be cleaner if you could pass the amount of creatures to the addSpawn function.

@ranisalt
Copy link
Member Author

ranisalt commented Jun 2, 2016

True that, I will fix it to use the Position constructor later.

I will also patch the addSpawn function to allow another parameter, but I see it as removing clutter from the raid (explicit) to move to a lib function (implicit).

@EvilHero90
Copy link
Contributor

EvilHero90 commented Jun 2, 2016

actually this entire thing should be handled completly in lua by coroutines and a simple addEvent timer at startup, could get rid of all c code then and we wouldn't hit server performence.

@ranisalt
Copy link
Member Author

ranisalt commented Jun 4, 2016

@EvilHero90 I agree with handling completely on Lua, but I couldn't figure how to use coroutines. Could you give me sample code for how you see raids?

@EvilHero90
Copy link
Contributor

I can do that on monday, I'm busy with work the entire weekend


-- Single spawns
addEvent(Game.createMonster, 15000, Position(93, 123, 7))
addEvent(Game.createMonster, 30000, Position(98, 125, 7))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing monster name ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, my eyes failed me. Fixed

@ranisalt
Copy link
Member Author

ranisalt commented Jun 28, 2016

This PR is (almost) on it's final form. I added a generic interface to search and force execute global events. I couldn't find an use to force execute startup, shutdown or record events, so they are ignored.

Also, it means it's possible to force trigger a server save on the Lua side.

Edit: actually I'll just reuse the previous Game.startRaid function, just renamed to Game.startEvent.

@wgrr
Copy link
Contributor

wgrr commented Jul 7, 2016

@ranisalt since seems he doesn't got time yet i made an example with coroutines.

addEvent(checkRaids, 15000)
local inProgress = false
function ratPlague()
    local pos = Position(146, 388, 7)
    broadcastMessage("Rat plague in city!", MESSAGE_STATUS_WARNING)
    Game.createMonster("Rat", pos)
    coroutine.yield()
    inProgress = false
end

function checkRaids()
    print(coroutine.status(start))
    if not inProgress then
        if math.random(1, 1) == 1 then
            inProgress = true
            coroutine.resume(start)
        end
    end
    addEvent(checkRaids, 15000)
end

start = coroutine.create(ratPlague)

to make this a real raid system with coroutines would needed a lib as big as npcs is, i personally don't know performence impact with this tho, in my opinion coroutines are just a complicated way to call functions.

@ranisalt
Copy link
Member Author

ranisalt commented Jul 7, 2016

If that is, I don't know how much better this is than addEvent.

@wgrr
Copy link
Contributor

wgrr commented Jul 7, 2016

i don't see the point also, if is needed to call a addEvent it becomes a complicated way to call functions, tho im curious to see how he would do that.

@ranisalt
Copy link
Member Author

Rebased against master.

@ranisalt ranisalt force-pushed the bye-bye-raids branch 5 times, most recently from 593e6d8 to e3e1bb2 Compare September 30, 2017 03:14
@ranisalt
Copy link
Member Author

ranisalt commented Oct 3, 2017

I still intend to keep it up to date and merge when possible. This alone shaves 20 seconds off the build time 😄 besides -800 line delta.

WibbenZ
WibbenZ previously approved these changes Oct 3, 2017
@WibbenZ
Copy link
Member

WibbenZ commented Oct 3, 2017

Only thing I can think you should "add" is a converter XML -> Lua
Maybe this should wait for the next stable release, but looks good to me 👍

@ranisalt
Copy link
Member Author

ranisalt commented Oct 4, 2017

@WibbenZ working on it! Check the new stuff under tools/ 😄

@ranisalt ranisalt force-pushed the bye-bye-raids branch 4 times, most recently from 1043391 to ed3911c Compare October 4, 2017 06:50
EPuncker
EPuncker previously approved these changes Apr 25, 2023
@EPuncker
Copy link
Contributor

let's go?!

@ranisalt
Copy link
Member Author

ranisalt commented Oct 2, 2023

@MillhioreBT your change request is blocking this PR

ranisalt and others added 9 commits October 10, 2023 00:52
- Move raids to globalevents, create Lua interface
- Move force raid command to talkaction
- Create example raid as globalevent
- Add Lua interface to execute timed GlobalEvents

Co-authored-by: Evil Puncker <EPuncker@users.noreply.github.com>
@ramon-bernardo
Copy link
Contributor

Ready to merge, right?

@omarcopires
Copy link
Contributor

Ready to merge, right?

This should have been added years ago, we really need this! 🥹

EPuncker
EPuncker previously approved these changes Dec 13, 2023
MillhioreBT
MillhioreBT previously approved these changes Dec 13, 2023
@ranisalt ranisalt dismissed stale reviews from MillhioreBT and EPuncker via 409f0a5 December 13, 2023 00:58
@EPuncker EPuncker merged commit 46e2b7a into otland:master Dec 13, 2023
22 checks passed
@ranisalt
Copy link
Member Author

I can't believe what my eyes are looking at

@ranisalt ranisalt deleted the bye-bye-raids branch December 13, 2023 01:25
@ramon-bernardo
Copy link
Contributor

ramon-bernardo commented Dec 13, 2023

2023/12/12, a milestone! OMG 🎉 🎉 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Increase or improvement in quality, value, or extent
Projects
None yet
Development

Successfully merging this pull request may close these issues.