Jump to content
  • 1

Losing level and experience when you die


EduKrowlley

Question

Hi guys! I'm pretty new here, since the dark and ancient times of playerworlds mmorpg engine 2d I've not been present in game development forums... until now!

I've started to using the source code of Intersect Game Engine and not found a configuration to loss experience and level when you die, and started to develop myself experience lost system.

 

This way, when the player dies, we can apply a formula to calculate the amount of experience player must lost, and if must, player goes level downgrade and subtract the rest of experience what he must lose in the downgraded level.

 

My question would be if there is already such a system inside the engine and if so, where can I use it. If not, I hope you can help me improve the code and if possible, be able to parameterize this code within the settings of a .json file. I am new to C # and I am learning almost exclusively for use with this engine, because in fact I have been a Java programmer for about 10 years.

Spoiler

12204d0ae241613743fa851ca907cf52.gif

Spoiler

 


        public override void Die(int dropitems = 0, Entity killer = null)
        {
            //Flag death to the client
            PacketSender.SendPlayerDeath(this);

            //Event trigger
            foreach (var evt in EventLookup)
            {
                evt.Value.PlayerHasDied = true;
            }

            //Expdecay
            DecayExperience();
            
            base.Die(dropitems, killer);
            PacketSender.SendEntityDie(this);
            Reset();
            Respawn();
            PacketSender.SendInventory(this);
        }

        public void DecayExperience()
        {
            var formula = Convert.ToInt64(ExperienceToNextLevel * 3 / 10);
            if (Exp < formula)
            {
                var experienceGap = Exp - formula;
                if (Level > 1)
                {
                    SetLevel(Level - 1, true);
                    Exp = Convert.ToInt64(ExperienceToNextLevel + experienceGap);
                    PacketSender.SendChatMsg(this, Strings.Combat.died.ToString() + formula.ToString(), CustomColors.Combat.LevelUp, Name);
                }
                else
                {
                    if (Exp == 0)
                    {
                        PacketSender.SendChatMsg(this, Strings.Combat.died.ToString() + Exp.ToString(), CustomColors.Combat.LevelUp, Name);
                        return;
                    }
                    Exp = 0;
                    PacketSender.SendChatMsg(this, Strings.Combat.died.ToString() + formula.ToString(), CustomColors.Combat.LevelUp, Name);
                }                
            }
            else
            {
                Exp -= Convert.ToInt64(formula);
                PacketSender.SendChatMsg(this, Strings.Combat.died.ToString() + formula.ToString(), CustomColors.Combat.LevelUp, Name);
            }
            
        }

 

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

 

5 minutes ago, panda said:

There's no level downgrade system in the engine.

Look at the TNL and related variables and functions in the Player class to get an idea of where this might need to be implemented.

I've implemented this already, as shown on spoiler gif. My question was if already has any internal system to do that. But you said it hasn't, thanks. If someone can look at the code and help to improve.

Link to comment
Share on other sites

  • 0
37 minutes ago, Beefy Kasplant said:

Seems like it would be pretty beneficial to die now since you don't lose stats when leveling down..

This isn't true @Beefy Kasplant, when you die, SetLevel() method keeps running and executing RecalculateStatsAndPoints() method, who is responsible to recalculate this stuff and keep everything correctly. As you can see on gif, max HP is being slower when the level going down, and if you test, you will also see that the same happens with the attributes.

Link to comment
Share on other sites

  • 0
6 minutes ago, EduKrowlley said:

This isn't true @Beefy Kasplant, when you die, SetLevel() method keeps running and executing RecalculateStatsAndPoints() method, who is responsible to recalculate this stuff and keep everything correctly. As you can see on gif, max HP is being slower when the level going down, and if you test, you will also see that the same happens with the attributes.

 

Ah, alright! In that case it seems like a good system. 

 

When you figure it out, it would be cool to have configurable what the exp drain is per death and the option to set if you lose levels or not.

Link to comment
Share on other sites

  • 0
Just now, Beefy Kasplant said:

 

Ah, alright! In that case it seems like a good system. 

 

When you figure it out, it would be cool to have configurable what the exp drain is per death and the option to set if you lose levels or not.

Exactly @Beefy Kasplant! Its all I want to do now, make it configurable, parameterizing these configurations on a .json file! If someone can help with that, will be awesome.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...