Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8671855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:03:25+00:00 2026-06-12T19:03:25+00:00

i like to get some thoughts on how to implement a tick based system.

  • 0

i like to get some thoughts on how to implement a tick based system.

Every action a player or non player got has a initial time to perform and a cooldown time. Once a creatures cooldown time has passed it gets to choose a new action. If the player has to choose a action the game is “paused”.

Example:

1: Player heavy swing (50 ticks to perform, 50 ticks to cool down)

2: Game goes on for 50 ticks.

3: NPC’s can set actions.

4: Player swings and cools down for 50 ticks.

5: NPC’s can set actions.

6: Game paused for the player.

What i currently have works but is not efficient. I have a class with each action as a static method. These method output a struct containing all the data. This will be passed to a actioncue of a individual creature.

Every update loop call the cue and start counting down the attack time if the player has put in a action. Once the attack should be solved i call a static method in the actions class again. And i start counting down the cooldown timer.

So what i should have is probably a list holding all actions and sorting that list skipping unnecessary time/ticks and go straight to the next action. But there will be different types of actions like move, attack, ability and i cant wrap my head around a good implementation of this.

When a creature performs a basic attack this gets called (attack is the creatures own instanced attack struct)

attack = Actions.BasicAttack(this, player, rand);

This is how the Actions class looks like.

public struct Attack
    {
        public int Damage;
        public string Type;
        public int Time;
        public int Cooldown;
        public Creature target;
        public bool solved;
    }




    public static Attack BasicAttack(Creature attacker, Creature defender, Random rand)
    {
        Attack attack = new Attack();

        attack.Damage = rand.Next(attacker.MinBaseDmg, attacker.MaxBaseDmg + 1);
        attack.Type = "Melee";
        attack.Time = 50;
        attack.Cooldown = 30;
        attack.target = defender;
        attack.solved = false;

        return attack;
    }

And this gets called in the update method of each creature when the player has a action cued. Tick = 0 if player has no action cued and tick = 1 when player has a action cued up.

protected void ActionCue(int tick)
    {
        if (attack.target != null)
        {
            if (attack.Time > 1)
            {
                Console.WriteLine(attack.Time);
                attack.Time -= tick;
                this.free = false;
            }
            else if (!attack.solved)
            {
                Actions.SolveAttack(attack.Damage, attack.Type, attack.target);
                attack.solved = true;
            }
            else if (attack.solved && attack.Cooldown > 1)
            {
                //Console.WriteLine(attack.Cooldown);
                attack.Cooldown -= tick;
            }
            else
                free = true;
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:03:26+00:00Added an answer on June 12, 2026 at 7:03 pm

    Consider something like this (i will use pseudocode – its far from being optimized etc. but it might be just fast enough, or set you on your way to optimize what youre trying to do)

    class CombatEventList
    {
       public static AddEvent(CombatEvent event, int ticksTillHappens)   
    }
    
    virtual class CombatEvent
    {
        public virtual void CombatAction()
    }
    
    class PlayerActionChoice : ComabtEvent
    {
       public void CombatAction
       {
           var playerAction = GetUserDecision();//returns i.e CombatEvent PlayerMeeleAttack
           CombatEventList.AddEvent(playerAction, 0);
       }
    }
    
    class PlayerMeeleAttack : CombatEvent
    {
       int cooldownInTicks = 50;
    
       public void CombatAction
       {
           MakeAttack()//damages the moster etc - all the stuff the attack is supposed to do
           var nextEvent = new PlayerActionChoice();
           CombatEventList.AddEvent(nextEvent, cooldownInTicks);
       }
    }
    

    So, how this works?

    We got a list of events.

    The list checks all the events that are supposed to happen now and, executes their CombatAction.

    In their CombatAction, the events add new events to the list. For example a PlayerMeeleAttack event sets the PlayerActionChoice event after an appropriate cooldown, so that he can take another action later.

    After all current CombatEvents are resolved and have added their own CombatEvents to the list, the list checks the next Event (lowest delay)

    The list sleeps for the specified number of ticks (the delay of the next Event). Once its done sleeping, it lowers the cooldowns on all events by an appropriate amount, and handles all the current events (those that just hit 0 delay)

    This goes in a loop

    The list starts with the CombatStartEvent on it, thats going to happen right away(delay 0). It sets the PlayerActionChoice and MonsterActionChoice events in the CombatAction method.

    Of course this is far from being optimal, its just a sketch, or an idea for you to think through. There may be better ideas, i didnt give the problem very much thought – but this is obviously more efficient than your current solution 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to get some nested params. I have an Order that has
I'd like to get some community input on best practices for styling your ERB
I'd like to get some help with my search script. A little about the
What I would like to get some input on is how to remove certain
I would like to get some information on list of points that needs to
I would like to get some feedback on what is one of my first
I would like to get some clarification regarding lazy loading and session boundaries etc.
I'd like to get some advice on how to structure the user data for
I have a number of links which I would like to get some information
I'm new on this, and I would like to get some advice because I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.