示例#1
0
    public void ChangeResource(Source source, Defs.ResourceTypes target, float amount, bool skipPopups)
    {
        if (amount != 0)
        {
            bool isNegative = false;
            if (amount < 0)
            {
                sinceLoss = 0;
                hud.FadeMode(false);
                isNegative = true;
            }

            switch (target)
            {
            case Defs.ResourceTypes.Health:
                //PRE PROCESSING
                bool negate = false;
                switch (source.type)
                {
                case Source.Type.Weapon:

                    #region PARRY
                    if (source.weapon.WeaponType == Defs.WeaponType.Melee)
                    {
                        if (states != null)
                        {
                            if (states.HasState(stateParry))
                            {
                                if (isNegative)
                                {
                                    negate = true;
                                    RpcCreatePopupText("Parried!", Color.grey);
                                }
                            }
                        }
                    }
                    #endregion

                    break;

                case Source.Type.Item:
                    break;

                case Source.Type.State:
                    break;

                case Source.Type.Natural:
                    break;

                case Source.Type.System:
                    break;
                }

                if (negate)
                {
                    return;
                }

                //Apply Amount
                Health.Val = Mathf.Clamp(Health.Val + amount, 0, Health.Max);

                switch (mode)
                {
                case Defs.UnitType.Critter:
                    aggro = source.causer.transform;
                    break;

                case Defs.UnitType.Troop:
                    break;

                case Defs.UnitType.Player:
                    break;
                }

                //Bounty
                if (source.causer != this)
                {
                    if (isNegative)
                    {
                        //Damage
                        bool exists = false;
                        for (int count = 0; count < bounty.Count; count++)
                        {
                            if (bounty[count].causer == source.causer)
                            {
                                bounty[count].damage += Mathf.Abs(amount);
                                exists = true;
                                break;
                            }
                        }

                        if (!exists)
                        {
                            Bounty newBounty = new Bounty()
                            {
                                causer = source.causer,
                                damage = Mathf.Abs(amount),
                            };
                            bounty.Add(newBounty);
                        }
                    }
                }

                //Popups
                if (Health.Popups && !skipPopups)
                {
                    Color to = Health.Color;
                    if (isNegative)
                    {
                        to = Color.red;
                    }

                    if (Mathf.Abs(amount) < 5000)
                    {
                        RpcCreatePopup(Mathf.Abs(amount), Health.PCT(amount), to);
                    }
                    else
                    {
                        int    num  = Random.Range(0, 7);
                        string text = "Kek lmao, the programmer can't maths";
                        switch (num)
                        {
                        case 0:
                            text = "Tons of damage!";
                            break;

                        case 1:
                            text = "I am fed";
                            break;

                        case 2:
                            text = "Holy S*** run from me!";
                            break;

                        case 3:
                            text = "I am a balanced character";
                            break;

                        case 4:
                            text = "The definition of OP";
                            break;

                        case 5:
                            text = "My presence has been made clear";
                            break;

                        case 6:
                            text = "This is your queue to leave";
                            break;
                        }
                        RpcCreatePopupText(text, Color.red);
                    }
                }

                //HUD
                RpcUpdateHUD(Defs.ResourceTypes.Health, new Transfer(Health));

                //Effects
                if (isNegative)
                {
                    //Effects
                    RpcEffects(Health.PCT(Mathf.Abs(amount)));
                }

                //Player Specific
                if (mode == Defs.UnitType.Player)
                {
                    //Delay Regen
                    if (isNegative)
                    {
                        regenerationHealthDelay = 6;
                    }

                    //HUD
                    RpcUpdateResource(Defs.ResourceTypes.Health, new Transfer(Health));
                }

                if (Health.Val == 0)
                {
                    StartCoroutine(Die(source.causer));
                }
                break;

            case Defs.ResourceTypes.Stamina:
                //Apply Amount
                Stamina.Val = Mathf.Clamp(Stamina.Val + amount, 0, Stamina.Max);

                //Popups
                if (Stamina.Popups && !skipPopups)
                {
                    RpcCreatePopup(amount, Stamina.PCT(amount), Stamina.Color);
                }

                //HUD
                RpcUpdateHUD(Defs.ResourceTypes.Stamina, new Transfer(Stamina));

                //Player Specific
                if (mode == Defs.UnitType.Player)
                {
                    //HUD
                    RpcUpdateResource(Defs.ResourceTypes.Stamina, new Transfer(Stamina));
                }
                break;

            case Defs.ResourceTypes.Mana:
                //Apply Amount
                Mana.Val = Mathf.Clamp(Mana.Val + amount, 0, Mana.Max);

                //Popups
                if (Mana.Popups && !skipPopups)
                {
                    RpcCreatePopup(amount, Mana.PCT(amount), Mana.Color);
                }

                //HUD
                RpcUpdateHUD(Defs.ResourceTypes.Mana, new Transfer(Mana));

                //Player Specific
                if (mode == Defs.UnitType.Player)
                {
                    //HUD
                    RpcUpdateResource(Defs.ResourceTypes.Mana, new Transfer(Mana));
                }
                break;

            case Defs.ResourceTypes.Bloodlust:
                //Apply Amount
                Bloodlust.Val = Mathf.Clamp(Bloodlust.Val + amount, 0, Bloodlust.Max);

                //Popups
                if (Bloodlust.Popups && !skipPopups)
                {
                    RpcCreatePopup(amount, Bloodlust.PCT(amount), Bloodlust.Color);
                }

                //HUD
                RpcUpdateHUD(Defs.ResourceTypes.Bloodlust, new Transfer(Bloodlust));

                //Player Specific
                if (mode == Defs.UnitType.Player)
                {
                    //HUD
                    RpcUpdateResource(Defs.ResourceTypes.Bloodlust, new Transfer(Bloodlust));
                }
                break;

            case Defs.ResourceTypes.Sunlight:
                //Apply Amount
                Sunlight.Val = Mathf.Clamp(Sunlight.Val + amount, 0, Sunlight.Max);

                //Popups
                if (Sunlight.Popups && !skipPopups)
                {
                    RpcCreatePopup(amount, Sunlight.PCT(amount), Sunlight.Color);
                }

                //HUD
                RpcUpdateHUD(Defs.ResourceTypes.Sunlight, new Transfer(Sunlight));

                //Player Specific
                if (mode == Defs.UnitType.Player)
                {
                    //HUD
                    RpcUpdateResource(Defs.ResourceTypes.Sunlight, new Transfer(Sunlight));
                }
                break;

            case Defs.ResourceTypes.Moonlight:
                //Apply Amount
                Moonlight.Val = Mathf.Clamp(Moonlight.Val + amount, 0, Moonlight.Max);

                //Popups
                if (Moonlight.Popups && !skipPopups)
                {
                    RpcCreatePopup(amount, Moonlight.PCT(amount), Moonlight.Color);
                }

                //HUD
                RpcUpdateHUD(Defs.ResourceTypes.Moonlight, new Transfer(Moonlight));

                //Player Specific
                if (mode == Defs.UnitType.Player)
                {
                    //HUD
                    RpcUpdateResource(Defs.ResourceTypes.Moonlight, new Transfer(Moonlight));
                }
                break;

            case Defs.ResourceTypes.Curse:
                //Apply Amount
                Curse.Val = Mathf.Clamp(Curse.Val + amount, 0, Curse.Max);

                //Popups
                if (Curse.Popups && !skipPopups)
                {
                    RpcCreatePopup(amount, Curse.PCT(amount), Curse.Color);
                }

                //HUD
                RpcUpdateHUD(Defs.ResourceTypes.Curse, new Transfer(Curse));

                //Player Specific
                if (mode == Defs.UnitType.Player)
                {
                    //HUD
                    RpcUpdateResource(Defs.ResourceTypes.Curse, new Transfer(Curse));
                }
                break;

            case Defs.ResourceTypes.Corruption:
                //Apply Amount
                Corruption.Val = Mathf.Clamp(Corruption.Val + amount, 0, Corruption.Max);

                //Popups
                if (Corruption.Popups && !skipPopups)
                {
                    RpcCreatePopup(amount, Corruption.PCT(amount), Corruption.Color);
                }

                //HUD
                RpcUpdateHUD(Defs.ResourceTypes.Corruption, new Transfer(Corruption));

                //Player Specific
                if (mode == Defs.UnitType.Player)
                {
                    //HUD
                    RpcUpdateResource(Defs.ResourceTypes.Corruption, new Transfer(Corruption));
                }
                break;

            case Defs.ResourceTypes.Darkness:
                //Apply Amount
                Darkness.Val = Mathf.Clamp(Darkness.Val + amount, 0, Darkness.Max);

                //Popups
                if (Darkness.Popups && !skipPopups)
                {
                    RpcCreatePopup(amount, Darkness.PCT(amount), Darkness.Color);
                }

                //HUD
                RpcUpdateHUD(Defs.ResourceTypes.Darkness, new Transfer(Darkness));

                //Player Specific
                if (mode == Defs.UnitType.Player)
                {
                    //HUD
                    RpcUpdateResource(Defs.ResourceTypes.Darkness, new Transfer(Darkness));
                }
                break;
            }
        }
        else
        {
            //Debug.LogError("CHANGE RESOURCE: Passed a value of 0! :" + target.ToString());
        }
    }
示例#2
0
 public Transfer(Parameters.Resource target)
 {
     Val = target.Val;
     Max = target.Max;
     PCT = target.PCT();
 }