[uMMORPG] True Stealth

  • Lunar Engine v0.2.6 is out now! Download and check it out here. The map editor is also now fixed!

SkywardRiver

Legend
Legend
Veteran
Jun 23, 2018
33
35
18
Canada
Gold
2,195
Preface:
This tutorial will guide you in adding True Stealth to uMMO. This is done in 2D, but should easily transfer.

This edits the core code of uMMORPG. This is disconcertingly seen as taboo in the uMMO community. You should be editing Core, guys. Pick a version, and start to build your game on top of it.

What this does:
What this tutorial will allow you to do is attach a Stealth effect to any Buff. Stealth will basically remove you from the game for mobs and other players. Stealth can be ended when attacking, and will last until the "buff" ends otherwise. This is not the end-all Stealth System. To truly have a stealth system worth having in your game, you will want to design it yourself.

Step 1:
First off, we'll add this to BonusSkill.cs:
C#:
public bool hasStealth;
We'll tick this for buffs that we want to add stealth to.

Step 2:
Next, we'll wanna set up the proper handler for the new variable.
Find this line of code in Buff.cs:
C#:
public float bonusSpeed { get { return data.bonusSpeed.Get(level); } }
Paste this just under it:
C#:
public bool hasStealth { get { return data.hasStealth; } }
Step 3:
Next, we'll add the "I'm stealthed" variable to Entity.cs.
So, find this line in Entity.cs:
C#:
  [Header("Damage Popup")]
and paste this just above it:
C#:
[SyncVar, HideInInspector] public bool _isStealthed = false;
    [HideInInspector] public virtual bool isStealthed
    {
        get
        {
            int buffHasStealth = buffs.Sum(buff => Convert.ToInt32(buff.hasStealth));
            if (buffHasStealth > 0) return true;
            else return false;
        }
    }
Step 4:
Next you'll want to find these lines of code in Entity.cs:
C#:
 // helper function to remove all buffs that ended
    void CleanupBuffs()
    {
        for (int i = 0; i < buffs.Count; ++i)
        {
            if (buffs[i].BuffTimeRemaining() == 0)
            {
                buffs.RemoveAt(i);
                --i;
            }
        }
    }
and change it to this:
C#:
 // helper function to remove all buffs that ended
    void CleanupBuffs()
    {
        for (int i = 0; i < buffs.Count; ++i)
        {
            if (buffs[i].BuffTimeRemaining() == 0)
            {
                buffs.RemoveAt(i);
                --i;
            }
        }
        _isStealthed = isStealthed;
        proxchecker.forceHidden = _isStealthed;
    }
Step 5:
Next you'll want to find this in Entity.cs:
C#:
 // helper function to add or refresh a buff
    public void AddOrRefreshBuff(Buff buff)
    {
        // reset if already in buffs list, otherwise add
        int index = buffs.FindIndex(b => b.name == buff.name);
        if (index != -1) buffs[index] = buff;
        else buffs.Add(buff);
    }
and change it to this:
C#:
 // helper function to add or refresh a buff
    public void AddOrRefreshBuff(Buff buff)
    {
        // reset if already in buffs list, otherwise add
        int index = buffs.FindIndex(b => b.name == buff.name);
        if (index != -1) buffs[index] = buff;
        else buffs.Add(buff);
        _isStealthed = isStealthed;
        proxchecker.forceHidden = _isStealthed;
    }
Step 6:
Next you'll want to add this into Entity.cs:
C#:
void RemoveStealth()
    {
        for (int i = 0; i < buffs.Count; ++i)
        {
            if (buffs[i].hasStealth)
            {
                buffs.RemoveAt(i);
                --i;
            }
        }
        _isStealthed = isStealthed;
    }
Step 7:
Next, under this line of code in Entity.cs:
C#:
DamageType damageType = DamageType.Normal;
You want to add this:
C#:
RemoveStealth();
This will remove all stealth buffs when you deal damage to someone or something.

Step 8:
In Player.cs, add this:
C#:
 bool lastStealthStatus = false;
    void CheckStealth()
    {
        if (_isStealthed != lastStealthStatus)
        {
            if (_isStealthed)
            {
                gameObject.GetComponent<SpriteRenderer>().color = new Color(1,1,1, 0.5f);
            }
            else
            {
                gameObject.GetComponent<SpriteRenderer>().color = Color.white;
            }
            lastStealthStatus = _isStealthed;
        }
    }
This is what controls the visual effects for stealth! This is meant for 2D, standard sprite based rendering. You'll have to devise your own visual effects for 3D and any other rendering methods.

Step 9:
And finally, under this line of code in Player.cs:
C#:
animator.SetFloat("LookY", lookDirection.y);
add this:
C#:
CheckStealth();
The Result:
Simply tick "Has Stealth" on any Self-Target Buff, and enjoy! Here's a video to show you what it looks like:

 
Last edited:
  • Like
  • Love
Reactions: John and Rob