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

Many areas share one lastRespawnTick #2

Open
galaxian85 opened this issue Jun 20, 2019 · 2 comments
Open

Many areas share one lastRespawnTick #2

galaxian85 opened this issue Jun 20, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@galaxian85
Copy link

I have 3 areas (limbo, mapped and myarea) in my ranvier starter kit.
The manifest settings are:

title: "Limbo"
behaviors:
  progressive-respawn:
    interval: 10
title: "Map test"
behaviors:
  progressive-respawn:
    interval: 15
title: "My Area"
behaviors:
  progressive-respawn:
    interval: 20

And I noticed only limbo will trigger the event correctly.
I insert some code try to find out why.

      return function (config) {
        // setup respawnTick to only happen every [interval] seconds
        const respawnInterval = config.interval || 30;
        const sinceLastTick = Date.now() - lastRespawnTick;
        console.log(this.name + " " + sinceLastTick);
        if (sinceLastTick >= respawnInterval * 1000) {
          console.log(this.name + " is respawning"  + "\n");
          lastRespawnTick = Date.now();
          for (const [id, room] of this.rooms) {
            room.emit('respawnTick', state);
          }
        }
      };

And here is the console log.

limbo 10044
mapped 10044
myarea 10044
limbo is respawning

limbo 109
mapped 110
myarea 110

As you can see, limbo trigger the event and update the lastRespawnTick variable same time.
Means other areas will never respawn and makes this bundle unusable.

So I change the logic.
No count in millisecond anymore, it should be counted in ticks = Config.get(entityTickFrequency)
Since entityTickFrequency is hardcoded in main process, so I just use magic number 100 & 10 here.

    updateTick: state => {
      let serverStartTime = Math.trunc(Date.now() / 100);
      return function (config) {
        const respawnInterval = config.interval || 30;
        const upTime = Math.trunc(Date.now() / 100 - serverStartTime);
        if (upTime % (respawnInterval * 10) == 0) {
          console.log(this.name + " is respawning" + "\n");
          for (const [id, room] of this.rooms) {
            room.emit('respawnTick', state);
          }
        }
      };
    },

First time using github and English is not my native language(JavaScript neither).
Hope this post will not offend anybody.

At last, thanks you guys making this awesome software, have a nice day!

@galaxian85
Copy link
Author

I misunderstanding the meaning of
Config.get('entityTickFrequency', 100)
in the main process.

The 100 there is default setting, not hard-coded.
so here is the new code :)

const { Config } = require('ranvier');
...
..
.
    updateTick: state => {
      const tickFrequency = Config.get('entityTickFrequency', 100);
      const serverStartTime = Math.trunc(Date.now() / tickFrequency);
      return function (config) {
        const respawnInterval = config.interval || 30;
        const upTime = Math.trunc(Date.now() / tickFrequency - serverStartTime);
        if (upTime % (respawnInterval * (1000 / tickFrequency)) == 0) {
          for (const [id, room] of this.rooms) {
            room.emit('respawnTick', state);
          }
        }
      };
    },

@clagiordano
Copy link

@galaxian85 thanks for your fix, I had the same issue, the area with lower respan interval resets counter for other areas then just the area with lowest respawn interval was respawned, with this fix every area respawn correctly.

Thanks.

I hope @shawncplus will consider your fix and approve its merge.

@stennie stennie added the bug Something isn't working label Oct 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants