NPC & peer stat regeneration

Options
eyewitness4560
edited July 2013 in Photon Server
What solution would you guys recommend for calculating the regenerative stats of NPC's and Players?

Currently in what we have implemented every room has a unique timer object that runs every 2 seconds and calls the regeneration method, which in turn goes through all the NPC's and Peer's actor list, and calculates the regeneration where needed. After this, it relays the result to the clients.
This is probably not an ideal solution to this, because of the time difference, that it takes to scand update and send all the new relevant data. (obviously with a lot of NPC's and players about, this gets out of hand)

Idea #2 for this is that every npc and peer has a self based timer object, that uniquely calls for the regen of every copy.

Idea #3 is that we make a timer for every room, that generates an event, to which the peers are subscribed as listeners, and later unsubscribe once the regen has reached it's maximum value.

Any ideas on how we should proceed with it? Maybe a 4th option that we didn't think of?
Thanks in advance :)

Comments

  • I would go with Idea #2.

    Each player (represented by a "peer" on the server side) already has a fiber, where you can easily schedule the regeneration method, and you can add your own fiber for NPCs, like this (dummy code, might not compile - but you get the idea):

    [code2=csharp]public class NPC
    {
    private PoolFiber fiber = new PoolFiber();

    public NPC()
    {
    fiber.Start();
    fiber.ScheduleOnInterval(Regenerate(), 2000, 2000);
    }

    public void Regenerate()
    {
    // check stats & send event, if required
    }
    }[/code2]

    This example repeats the execution of the Regenerate() method every 2 secs.
    You can also schedule a Regenerate() call "manually" whenever someone takes a health loss or if the last regenerate did not fill the health to it's maximum etc.
  • Thanks Nicole, it's working splendidly :)
    And your dummy code was almost spot on, but for anyone having the same problem, it's the "ScheduleOnInterval" method that has the 2 parameters we need.

    Greatly appreciated as usual ;)
  • Thanks, fixed the example code. :)