コード例 #1
0
 public void AddEffect(SOEffect e)
 {
     if (!AffectedBy(e))
     {
         currentEffects.Add(e.ID);
     }
 }
コード例 #2
0
    IEnumerator DoT(float ammount, int time, IEffectable target, SOEffect effect)
    {
        if (ammount != 0)
        {
            bool isHeal = (effect.ID == CONSTANTS.EFFECT_REGEN || effect.ID == CONSTANTS.EFFECT_HEAL);
            for (int i = 0; i < time; i++)
            {
                if (!target.AffectedBy(effect))
                {
                    // perhaps they got cured
                    break;
                }
                if (isHeal)
                {
                    // hurting
                    target.Heal(ammount);
                }
                else
                {
                    // healing
                    target.Harm(ammount);
                }

                yield return(new WaitForSeconds(1));
            }
            target.RemoveEffect(effect);
        }
    }
コード例 #3
0
 public void RemoveEffect(SOEffect e)
 {
     if (AffectedBy(e))
     {
         currentEffects.Remove(e.ID);
     }
 }
コード例 #4
0
    void PrintSOs()
    {
        string printString = "ScriptableObjects:\n--ContainerFillers--\n";

        ContainerFiller[] toListi = ContainerFiller.GetAll();
        foreach (ContainerFiller s in toListi)
        {
            printString += s.GetDebugString() + "\n";
        }

        printString += "--Effects--\n";
        SOEffect[] toListe = SOEffect.GetAll();
        foreach (SOEffect s in toListe)
        {
            printString += s.GetDebugString() + "\n";
        }

        printString += "--Items--\n";
        SOItem[] toListit = SOItem.GetAll();
        foreach (SOItem s in toListit)
        {
            printString += s.GetDebugString() + "\n";
        }

        printString += "--Recipes--\n";
        SORecipe[] toListre = SORecipe.GetAll();
        foreach (SORecipe s in toListre)
        {
            printString += s.GetDebugString() + "\n";
        }
        printString += "End of ScriptableObjects";

        Debug.Log(printString);
    }
コード例 #5
0
    IEnumerator ShrinkLarge(float targetScale, float time, IEffectable target, SOEffect effect)
    {
        Vector3 tagetScaleV3 = target.GetDefaultScale() * targetScale;

        for (float i = 0; i < time; i = i + 1f)
        {
            if (!target.AffectedBy(effect))
            {
                // perhaps they got cured
                break;
            }

            Transform t2 = target.GetTransform();
            t2.localScale = tagetScaleV3;
            target.SetTransform(t2);

            yield return(new WaitForSeconds(1));
        }
        Transform t = target.GetTransform();

        t.localScale = target.GetDefaultScale();
        target.SetTransform(t);

        target.RemoveEffect(effect);
    }
コード例 #6
0
 bool applyAffect(SOEffect s, IEffectable target)
 {
     if (target.AffectedBy(s))
     {
         return(false);
     }
     target.AddEffect(s);
     return(true);
 }
コード例 #7
0
    public bool CureEntity(IEffectable toCure, float noop)
    {
        SOEffect thisEffect = SOEffect.GetByID(CONSTANTS.EFFECT_CURE);

        if (applyAffect(thisEffect, toCure))
        {
            toCure.RemoveEffect(SOEffect.GetByID(CONSTANTS.EFFECT_POISON));
        }
        toCure.RemoveEffect(thisEffect);
        return(false);
    }
コード例 #8
0
    public SOEffect[] getCurrentEffects()
    {
        int[]           IDs  = currentEffects.ToArray();
        List <SOEffect> temp = new List <SOEffect>(0);

        for (int i = 0; i < IDs.Length; i++)
        {
            temp.Add(SOEffect.GetByID(IDs[i]));
        }

        return(temp.ToArray());
    }
コード例 #9
0
    public bool KillEntity(IEffectable toKill, float noop)
    {
        SOEffect thisEffect = SOEffect.GetByID(CONSTANTS.EFFECT_DEATH);

        if (applyAffect(thisEffect, toKill))
        {
            toKill.Harm(toKill.MaxHP);
        }

        toKill.RemoveEffect(thisEffect);

        return(true);
    }
コード例 #10
0
    public bool PoisonEntity(IEffectable toPoison, float potency)
    {
        float    damage     = 1;
        int      time       = 10;
        SOEffect thisEffect = SOEffect.GetByID(CONSTANTS.EFFECT_POISON);

        if (applyAffect(thisEffect, toPoison))
        {
            // Coroutine
            StartCoroutine(DoT(damage * potency, time, toPoison, thisEffect));
        }

        return(true);
    }
コード例 #11
0
    public bool HealEntity(IEffectable toHeal, float potency)
    {
        float    value      = 20;
        SOEffect thisEffect = SOEffect.GetByID(CONSTANTS.EFFECT_HEAL);

        if (applyAffect(thisEffect, toHeal))
        {
            toHeal.Heal(value * potency);
        }

        toHeal.RemoveEffect(thisEffect);

        return(true);
    }
コード例 #12
0
    public bool HealOverTime(IEffectable toHeal, float potency)
    {
        float    heal       = 1;
        int      time       = 10;
        SOEffect thisEffect = SOEffect.GetByID(CONSTANTS.EFFECT_REGEN);

        if (applyAffect(thisEffect, toHeal))
        {
            // Coroutine
            StartCoroutine(DoT(heal * potency, time, toHeal, thisEffect));
        }

        return(true);
    }
コード例 #13
0
    public bool SlowEntity(IEffectable target, float potency)
    {
        float scaleup = 0.5f;
        float time    = 10;

        // Conflicting
        target.RemoveEffect(SOEffect.GetByID(CONSTANTS.EFFECT_SPEED));
        SOEffect thisEffect = SOEffect.GetByID(CONSTANTS.EFFECT_SLOW);

        if (applyAffect(thisEffect, target))
        {
            StartCoroutine(SpeedSlow(scaleup, time * potency, target, thisEffect));
        }

        return(true);
    }
コード例 #14
0
    public bool ShrinkEntity(IEffectable target, float potency)
    {
        float scaleup = 0.5f;
        float time    = 10;

        // Conflicting
        target.RemoveEffect(SOEffect.GetByID(CONSTANTS.EFFECT_ENLARGE));
        SOEffect thisEffect = SOEffect.GetByID(CONSTANTS.EFFECT_SHRINK);

        if (applyAffect(thisEffect, target))
        {
            StartCoroutine(ShrinkLarge(scaleup, time * potency, target, thisEffect));
        }

        return(true);
    }
コード例 #15
0
    public bool HighGravEntity(IEffectable target, float potency)
    {
        float scaleup = 5f;
        float time    = 10;

        // Conflicting
        target.RemoveEffect(SOEffect.GetByID(CONSTANTS.EFFECT_LOW_GRAV));
        SOEffect thisEffect = SOEffect.GetByID(CONSTANTS.EFFECT_HIGH_GRAV);

        if (applyAffect(thisEffect, target))
        {
            StartCoroutine(Gravupdown(scaleup, time * potency, target, thisEffect));
        }

        return(true);
    }
コード例 #16
0
    IEnumerator SpeedSlow(float factor, float time, IEffectable target, SOEffect effect)
    {
        float targetSpeed = target.GetDefaultSpeed() * factor;

        for (float i = 0; i < time; i = i + 1f)
        {
            if (!target.AffectedBy(effect))
            {
                // perhaps they got cured
                break;
            }

            target.SetSpeed(targetSpeed);

            yield return(new WaitForSeconds(1));
        }
        target.SetSpeed(target.GetDefaultSpeed());
        target.RemoveEffect(effect);
    }
コード例 #17
0
    IEnumerator Gravupdown(float factor, float time, IEffectable target, SOEffect effect)
    {
        float targetGrav = target.GetDefaultGravity() * factor;
        float jumpHeight = target.GetDefaultJumpHeight() / factor;

        for (float i = 0; i < time; i = i + 1f)
        {
            if (!target.AffectedBy(effect))
            {
                // perhaps they got cured
                break;
            }

            target.SetGravity(targetGrav);
            target.SetJumpHeight(jumpHeight);

            yield return(new WaitForSeconds(1));
        }
        target.SetGravity(target.GetDefaultGravity());
        target.SetJumpHeight(target.GetDefaultJumpHeight());
        target.RemoveEffect(effect);
    }
コード例 #18
0
    bool DevCommandAddEffect(string[] parms)
    {
        if (parms.Length != 1)
        {
            DeveloperConsole.instance.writeError("Missing Effect ID or too many parameters.");
            return(false);
        }
        if (!Int32.TryParse(parms[0].Trim(), out int id))
        {
            DeveloperConsole.instance.writeError("Effect ID must be a number.");
            return(false);
        }

        SOEffect s = SOEffect.GetByID(id);

        if (s == null)
        {
            DeveloperConsole.instance.writeError("Unknown Effect ID " + id);
            return(false);
        }
        GameObject charo = gc.GetCharacter();

        if (charo == null)
        {
            DeveloperConsole.instance.writeError("Unable to get player.(1)");
            return(false);
        }
        IEffectable toEffect = charo.GetComponent <IEffectable>();

        if (toEffect == null)
        {
            DeveloperConsole.instance.writeError("Unable to get player.(2)");
            return(false);
        }

        s.onEffect(toEffect, 1);
        DeveloperConsole.instance.writeMessage("Applied effect " + s.PrintString() + " to player");
        return(true);
    }
コード例 #19
0
    void TestSOs()
    {
        //test ContainerFiller
        {
            ContainerFiller[]        toCheck   = ContainerFiller.GetAll();
            Dictionary <int, string> potionIDs = new Dictionary <int, string>();
            foreach (ContainerFiller s in toCheck)
            {
                if (potionIDs.ContainsKey(s.ID))
                {
                    Debug.LogError("ERROR: ContainerFiller " + s.name + " has the same ID as " + potionIDs[s.ID] + " = " + s.ID);
                }
                else
                {
                    potionIDs.Add(s.ID, s.name);
                }
                // Check for null parameters
                if (s.color == null)
                {
                    Debug.LogError("ERROR: ContainerFiller " + s.name + " has a NULL Color");
                }
                if (s.onConsumeEffect == null)
                {
                    Debug.LogError("ERROR: ContainerFiller " + s.name + " has a NULL onConsumeEffect");
                }
                if (s.onGroundModel == null)
                {
                    Debug.LogError("ERROR: ContainerFiller " + s.name + " has a NULL onGroundModel");
                }
                if (s.texture == null)
                {
                    Debug.LogError("ERROR: ContainerFiller " + s.name + " has a NULL Texture");
                }
            }
        }

        {
            //test effects
            SOEffect[] toCheck = SOEffect.GetAll();
            Dictionary <int, string> effectIDs = new Dictionary <int, string>();
            foreach (SOEffect s in toCheck)
            {
                if (effectIDs.ContainsKey(s.ID))
                {
                    Debug.LogError("ERROR: SOEffect " + s.name + " has the same ID as " + effectIDs[s.ID] + " = " + s.ID);
                }
                else
                {
                    effectIDs.Add(s.ID, s.name);
                }
            }
        }

        {
            //test items
            SOItem[] toCheck = SOItem.GetAll();
            Dictionary <int, string> itemIDs = new Dictionary <int, string>();
            foreach (SOItem s in toCheck)
            {
                if (itemIDs.ContainsKey(s.ID))
                {
                    Debug.LogError("ERROR: SOItem " + s.name + " has the same ID as " + itemIDs[s.ID] + " = " + s.ID);
                }
                else
                {
                    itemIDs.Add(s.ID, s.name);
                }
                if (s.model == null)
                {
                    Debug.LogError("ERROR: SOItem " + s.name + " has a NULL model");
                }
            }
        }

        {
            //test Recipes
            SORecipe[] toCheck = SORecipe.GetAll();
            Dictionary <int, string> itemIDs = new Dictionary <int, string>();
            foreach (SORecipe s in toCheck)
            {
                if (itemIDs.ContainsKey(s.ID))
                {
                    Debug.LogError("ERROR: SORecipe " + s.name + " has the same ID as " + itemIDs[s.ID] + " = " + s.ID);
                }
                else
                {
                    itemIDs.Add(s.ID, s.name);
                }
                if (s.result == null)
                {
                    Debug.LogError("ERROR: SORecipe " + s.name + " has a NULL result");
                }
                if (s.ingredients == null)
                {
                    Debug.LogError("ERROR: SORecipe " + s.name + " has a NULL ingredients");
                }
                else if (s.ingredients.Length < 2)
                {
                    Debug.LogError("ERROR: SORecipe " + s.name + " has a less than 2 ingredients");
                }
                else
                {
                    foreach (ContainerFiller c in s.ingredients)
                    {
                        if (c == null)
                        {
                            Debug.LogError("ERROR: SORecipe " + s.name + " contains a NULL ingredient in it's list.");
                            break;
                        }
                    }
                }
            }
        }
    }
コード例 #20
0
 public bool AffectedBy(SOEffect e)
 {
     return(currentEffects.Contains(e.ID));
 }
コード例 #21
0
 IEnumerator LerpAValue(float originalVal, float targetvalue, float holdfor, SOEffect effect, IEffectable target)
 {
     // TODO
     yield return(new WaitForSeconds(1));
 }
コード例 #22
0
    private void Awake()
    {
        gc = GetComponent <GameController>();
        DeveloperConsole.instance.RegisterCommand("applyeffect", "[ID] Applies a given effect to the player.", DevCommandAddEffect);
        DeveloperConsole.instance.RegisterCommand("removeeffect", "[ID] Removes a given effect from the player.", DevCommandRemoveEffect);

        //sets up the effects below
        SOEffect[] AllEffects = SOEffect.GetAll();
        for (int i = 0; i < AllEffects.Length; i++)
        {
            switch (AllEffects[i].ID)
            {
            case CONSTANTS.EFFECT_NOTHING:
                //nothing
                AllEffects[i].onEffect = Nothing;
                break;

            case CONSTANTS.EFFECT_DEATH:
                // death
                AllEffects[i].onEffect = KillEntity;
                break;

            case CONSTANTS.EFFECT_HEAL:
                // heal
                AllEffects[i].onEffect = HealEntity;
                break;

            case CONSTANTS.EFFECT_CURE:
                AllEffects[i].onEffect = CureEntity;
                break;

            case CONSTANTS.EFFECT_POISON:
                AllEffects[i].onEffect = PoisonEntity;
                break;

            case CONSTANTS.EFFECT_REGEN:
                AllEffects[i].onEffect = HealOverTime;
                break;

            case CONSTANTS.EFFECT_ENLARGE:
                //nothing
                AllEffects[i].onEffect = EnlargeEntity;
                break;

            case CONSTANTS.EFFECT_SHRINK:
                // death
                AllEffects[i].onEffect = ShrinkEntity;
                break;

            case CONSTANTS.EFFECT_LOW_GRAV:
                // heal
                AllEffects[i].onEffect = LowGravEntity;
                break;

            case CONSTANTS.EFFECT_HIGH_GRAV:
                AllEffects[i].onEffect = HighGravEntity;
                break;

            case CONSTANTS.EFFECT_SLOW:
                AllEffects[i].onEffect = SlowEntity;
                break;

            case CONSTANTS.EFFECT_SPEED:
                AllEffects[i].onEffect = SpeedEntity;
                break;

            default:
                Debug.LogError("Effect runner is unable to handle effect " + AllEffects[i].GetDebugString());
                break;
            }
        }
    }