Stamina Improvement

07/04/2013 04:49 CriticallyDev#1
I did not like the way Impulse had the stamina for a player coded because it was too plain and was missing quite a lot. So I took the liberty of implementing the codes used on Albetros for stamina onto the 5165 base. And It was a success .. somewhat.

The only issue I come across is literally having to sit over and over to gain stamina after using a skill that requires stamina usage. I'm not sure what I am missing so when the character is sitting, the stamina is increasing.

Code:
#region Stamina

                    //TODO: Fly update for stamina
                    {
                        try
                        {
                            byte ToUp = 2;
                            if (client.Entity.Action == Game.Enums.ConquerAction.Sit || client.Entity.Action == Game.Enums.ConquerAction.Lie)
                            {
                                if (DateTime.Now > client.Entity.SitAt.AddMilliseconds(300))
                                {
                                    ToUp = 11;
                                    client.Entity.Stamina = (byte)Math.Min(client.Entity.Stamina + ToUp, client.Entity.MaxStamina);
                                }
                                client.Entity.SitAt = DateTime.Now;
                            }
                        }
                        catch{}
                    }
                    #endregion
07/04/2013 04:57 Santa#2
Quote:
Originally Posted by CriticallyDev View Post
I did not like the way Impulse had the stamina for a player coded because it was too plain and was missing quite a lot. So I took the liberty of implementing the codes used on Albetros for stamina onto the 5165 base. And It was a success .. somewhat.

The only issue I come across is literally having to sit over and over to gain stamina after using a skill that requires stamina usage. I'm not sure what I am missing so when the character is sitting, the stamina is increasing.

Code:
#region Stamina

                    //TODO: Fly update for stamina
                    {
                        try
                        {
                            byte ToUp = 2;
                            if (client.Entity.Action == Game.Enums.ConquerAction.Sit || client.Entity.Action == Game.Enums.ConquerAction.Lie)
                            {
                                if (DateTime.Now > client.Entity.SitAt.AddMilliseconds(300))
                                {
                                    ToUp = 11;
                                    client.Entity.SitAt = DateTime.Now;
                                }
                            }
                             client.Entity.Stamina = (byte)Math.Min(client.Entity.Stamina + ToUp, client.Entity.MaxStamina);
                        }
                        catch{}
                    }
                    #endregion
Try this.
07/04/2013 09:53 ×Holo#3
It's all there and obvious, sorry, but I'm not actually aware of the issue you're facing..
07/04/2013 10:28 pro4never#4
as SB already pointed out, you have your brackets set so that stamina is ONLY gained if you are sitting rather than the slower passive rate at which it fills.

Note: You're also doing it wrong...

SitAt was used to determine how long you have been sitting for so that you couldn't just tap the sit key and magically gain stamina faster instantly.




Code:
#region Stamina

                    //TODO: Fly update for stamina
                    {
                            byte ToUp = 2;
                            if (client.Entity.Action == Game.Enums.ConquerAction.Sit || client.Entity.Action == Game.Enums.ConquerAction.Lie)
                            
                                if (DateTime.Now > client.Entity.SitAt.AddMilliseconds(300))                                
                                    ToUp = 11;

                              client.Entity.Stamina = (byte)Math.Min(client.Entity.Stamina + ToUp, client.Entity.MaxStamina); 
                            
                    }
                    #endregion
Note: There should be no need for try catches in this either. It's simple math. You'll also want to initialize SitAt when the user logs in as well as resetting it any time their action changes to Sit or Lie

Also fly is easy to check for, just don't fill it if they have the fly flag active.
07/04/2013 12:52 Super Aids#5
This is how I am doing stamina:
Code:
public void UpdateStamina(bool first)
		{
			if (Action != Enums.ActionType.Sit && !first && Action != Enums.ActionType.Lie)
				return;
			
			if (Stamina >= 100)
				return;
			
			if (Action == Enums.ActionType.Sit)
				Stamina += 10;
			else if (DateTime.Now >= LastMovement.AddMilliseconds(2000)) // lie
				Stamina += 15;
			
			ProjectX_V3_Lib.Threading.DelayedTask.StartDelayedTask(
				() => { UpdateStamina(false); }, Core.TimeIntervals.StaminaUpdate);
		}
07/05/2013 02:44 CriticallyDev#6
@Starbucks - That method basically gives the character an infinite amount of stamina.

@Pro - The method was already being called upon when the character connects to the server.

@Super - I like the way you wrote it, I actually tried doing something similar to what you and p4n recommended but I decided to keep it as it was originally and add checks when a player is flying and such.

This is the original method for Stamina which i'm still trying to improve.
Code:
#region Stamina
                    if (DateTime.Now > client.Entity.StaminaStamp.AddMilliseconds(800))
                    {
                        if (client.Entity.Action == Game.Enums.ConquerAction.Sit || client.Entity.Action == Game.Enums.ConquerAction.Lie)
                        {
                            if (client.Entity.Stamina <= 92)
                            {
                                client.Entity.Stamina += 8;
                            }
                            else
                            {
                                client.Entity.Stamina = 100;
                            }
                        }
                        else
                        {
                            if (client.Entity.Stamina <= 95)
                            {
                                client.Entity.Stamina += 5;
                            }
                            else
                            {
                                client.Entity.Stamina = 100;
                            }
                        }
                        client.Entity.StaminaStamp = DateTime.Now;
                    #endregion
07/05/2013 03:13 InfamousNoone#7
i don't know where the idea of "lie" came from, but the only two actions that affected stamina was kneel (although, I don't think it does anymore...) and sit.
07/05/2013 04:11 Super Aids#8
I'm not sure what others think, but I see it as you relax and regain energy. When you sit or lie down you're relaxing.
07/05/2013 04:15 pro4never#9
Quote:
Originally Posted by InfamousNoone View Post
i don't know where the idea of "lie" came from, but the only two actions that affected stamina was kneel (although, I don't think it does anymore...) and sit.
I used lie in my old source just for fun. Had nothing to do with how conquer programmed it. Apparently it caught on at some point and people started using it.


I actually was writing stamina recharge earlier today and this is my most recent implementation.

Code:
 if (stamina < 100 && !ContainsEffect(Effect.Flying))
                {
                    byte toGain = 2;
                    if ((Action == ActionType.Sit || Action == ActionType.Lie) && Common.Clock - LastSitAt > Common.MS_PER_SECOND)
                        toGain = 7;
                    Stamina = (byte)Math.Min(100, stamina + toGain);
                }
Time in this examples is ms since server started
OnTimer runs every 1000 ms from the world thread


Very heavily (aka ripped off) from one of devs source where he was essentially re-writing binaries from scratch using C# so yahhh, works nicely though.
07/07/2013 04:54 shadowman123#10
thats the way i coded it

Code:
if (Now > client.Entity.StaminaStamp.AddSeconds(1))
{
  if (!client.Entity.ContainsFlag(Update.Flags.Fly))
  {
    byte MaxStamina = (byte)(client.Entity.HeavenBlessing > 0 ? 150 : 100);
    byte IncreaseRate = (byte)((client.Entity.Action == Enums.ConquerAction.Sit || client.Entity.Action == Enums.ConquerAction.Lie) ? 7 : 3);
    client.Entity.Stamina = (byte)Math.Min(MaxStamina, client.Entity.Stamina + IncreaseRate);
    client.Entity.StaminaStamp = Now;
  }
}
07/11/2013 07:40 CriticallyDev#11
Quote:
Originally Posted by shadowman123 View Post
thats the way i coded it

Code:
if (Now > client.Entity.StaminaStamp.AddSeconds(1))
{
  if (!client.Entity.ContainsFlag(Update.Flags.Fly))
  {
    byte MaxStamina = (byte)(client.Entity.HeavenBlessing > 0 ? 150 : 100);
    byte IncreaseRate = (byte)((client.Entity.Action == Enums.ConquerAction.Sit || client.Entity.Action == Enums.ConquerAction.Lie) ? 7 : 3);
    client.Entity.Stamina = (byte)Math.Min(MaxStamina, client.Entity.Stamina + IncreaseRate);
    client.Entity.StaminaStamp = Now;
  }
}
I actually managed to get it running at a reasonable rate(kept it the old way but with very minor adjustments). All i'm missing now is the flag checks.