GetParam() public method

public GetParam ( string pname, float fallback = float.NaN, SkillDef, parentCtx = null ) : float
pname string
fallback float
parentCtx SkillDef,
return float
Example #1
0
    public float Lookup(
		string fname, LookupType type,
		SkillDef scontext=null,
		Character ccontext=null,
		Character tcontext=null,
		Equipment econtext=null,
		Item icontext=null,
		Formula f=null
	)
    {
        switch(type) {
            case LookupType.Auto: {
                float ret =
                    (icontext != null ? icontext.GetParam(fname) :
                    (econtext != null ? econtext.GetParam(fname) :
                    (scontext != null ? scontext.GetParam(fname) :
                    (ccontext != null ? ccontext.GetStat(fname) :
                    (tcontext != null ? tcontext.GetStat(fname) :
                    (HasFormula(fname) ? LookupFormula(fname).GetValue(this, scontext, ccontext, tcontext, econtext, icontext) : float.NaN))))));
                if(float.IsNaN(ret)) {
                    Debug.LogError("auto lookup failed for "+fname);
                }
                return ret;
            }
            case LookupType.SkillParam:
                return scontext.GetParam(fname);
            case LookupType.ItemParam: {
                if(icontext == null && scontext != null) {
                    icontext = scontext.InvolvedItem;
                }
                if(icontext == null && econtext != null) {
                    icontext = econtext.baseItem;
                }
                return icontext.GetParam(fname, scontext);
            }
            case LookupType.ReactedItemParam: {
                icontext = scontext.currentReactedSkill.InvolvedItem;
                return icontext.GetParam(fname, scontext);
            }
            case LookupType.ActorStat:
                if(scontext != null) { return scontext.character.GetStat(fname); }
                if(econtext != null) { return econtext.wielder.GetStat(fname); }
                if(ccontext != null) { return ccontext.GetStat(fname); }
                Debug.LogError("Cannot find actor stat "+fname);
                return float.NaN;
            case LookupType.ActorMountStat: {
                Character m = null;
                if(scontext != null) { m = scontext.character.mountedCharacter; }
                if(econtext != null) { m = econtext.wielder.mountedCharacter; }
                if(ccontext != null) { m = ccontext.mountedCharacter; }
                // Debug.Log("lookup "+fname+" on mount "+m+" ? "+(m != null ? m.GetStat(fname) : 0));
                if(m != null) {
                    return m.GetStat(fname);
                }
                Debug.LogError("Cannot find actor mount stat "+fname);
                return float.NaN;
            }
            case LookupType.ActorMounterStat: {
                Character m = null;
                if(scontext != null) { m = scontext.character.mountingCharacter; }
                if(econtext != null) { m = econtext.wielder.mountingCharacter; }
                if(ccontext != null) { m = ccontext.mountingCharacter; }
                if(m != null) {
                    return m.GetStat(fname);
                }
                Debug.LogError("Cannot find actor mounter stat "+fname);
                return float.NaN;
            }
            case LookupType.ActorEquipmentParam:
                if(scontext != null) {
                    ccontext = scontext.character;
                } else if(ccontext == null && econtext != null) {
                    if(econtext.Matches(f.equipmentSlots, f.equipmentCategories)) {
                        return econtext.GetParam(fname);
                    } else {
                        ccontext = econtext.wielder;
                    }
                }
                return LookupEquipmentParamOn(fname, type, ccontext, f, scontext);
            case LookupType.ActorMountEquipmentParam:
                if(scontext != null) {
                    ccontext = scontext.character.mountedCharacter;
                } else if(ccontext == null && econtext != null) {
                    if(econtext.Matches(f.equipmentSlots, f.equipmentCategories)) {
                        return econtext.GetParam(fname);
                    } else {
                        ccontext = econtext.wielder.mountedCharacter;
                    }
                }
                return LookupEquipmentParamOn(fname, type, ccontext, f, scontext);
            case LookupType.ActorMounterEquipmentParam:
                if(scontext != null) {
                    ccontext = scontext.character.mountingCharacter;
                } else if(ccontext == null && econtext != null) {
                    if(econtext.Matches(f.equipmentSlots, f.equipmentCategories)) {
                        return econtext.GetParam(fname);
                    } else {
                        ccontext = econtext.wielder.mountingCharacter;
                    }
                }
                return LookupEquipmentParamOn(fname, type, ccontext, f, scontext);
            case LookupType.ActorStatusEffect:
            case LookupType.ActorMountStatusEffect:
            case LookupType.ActorMounterStatusEffect:
                Debug.LogError("lookup semantics not defined for own status effect "+fname);
                return float.NaN;
            case LookupType.ActorSkillParam:
                //TODO: look up skill by slot, name, type?
                if(scontext != null) { return scontext.GetParam(fname); }
                Debug.LogError("Cannot find skill param "+fname);
                return float.NaN;
            case LookupType.TargetStat:
                if(scontext != null) { return scontext.currentTargetCharacter.GetStat(fname); }
                if(tcontext != null) { return tcontext.GetStat(fname); }
                Debug.LogError("Cannot find target stat "+fname);
                return float.NaN;
            case LookupType.TargetMountStat: {
                Character m = null;
                if(scontext != null) { m = scontext.currentTargetCharacter.mountedCharacter; }
                if(tcontext != null) { m = tcontext.mountedCharacter; }
                if(m != null) { return m.GetStat(fname); }
                Debug.LogError("Cannot find target stat "+fname);
                return float.NaN;
            }
            case LookupType.TargetMounterStat: {
                Character m = null;
                if(scontext != null) { m = scontext.currentTargetCharacter.mountingCharacter; }
                if(tcontext != null) { m = tcontext.mountingCharacter; }
                if(m != null) { return m.GetStat(fname); }
                Debug.LogError("Cannot find target stat "+fname);
                return float.NaN;
            }
            case LookupType.TargetEquipmentParam:
                if(scontext != null) {
                    ccontext = scontext.currentTargetCharacter;
                } else if(tcontext != null) {
                    ccontext = tcontext;
                } else {
                    ccontext = null;
                }
                return LookupEquipmentParamOn(fname, type, ccontext, f, scontext);
            case LookupType.TargetMountEquipmentParam:
                if(scontext != null) {
                    ccontext = scontext.currentTargetCharacter.mountedCharacter;
                } else if(tcontext != null) {
                    ccontext = tcontext.mountedCharacter;
                } else {
                    ccontext = null;
                }
                return LookupEquipmentParamOn(fname, type, ccontext, f, scontext);
            case LookupType.TargetMounterEquipmentParam:
                if(scontext != null) {
                    ccontext = scontext.currentTargetCharacter.mountingCharacter;
                } else if(tcontext != null) {
                    ccontext = tcontext.mountingCharacter;
                } else {
                    ccontext = null;
                }
                return LookupEquipmentParamOn(fname, type, ccontext, f, scontext);
            case LookupType.TargetStatusEffect:
            case LookupType.TargetMountStatusEffect:
            case LookupType.TargetMounterStatusEffect:
                Debug.LogError("lookup semantics not defined for target status effect "+fname);
                return float.NaN;
            case LookupType.TargetSkillParam:
            case LookupType.ActorMountSkillParam:
            case LookupType.ActorMounterSkillParam:
            case LookupType.TargetMountSkillParam:
            case LookupType.TargetMounterSkillParam:
            //TODO: look up skill by slot, name, type?
                Debug.LogError("Cannot find "+type+" "+fname);
                return float.NaN;
            case LookupType.NamedFormula:
                if(!HasFormula(fname)) {
                    Debug.LogError("Missing formula "+fname);
                    return float.NaN;
                }
                // Debug.Log("F:"+LookupFormula(fname));
                return LookupFormula(fname).GetValue(this, scontext, ccontext, tcontext, econtext, icontext);
            case LookupType.ReactedSkillParam:
                if(scontext != null) {
                    return scontext.currentReactedSkill.GetParam(fname);
                }
                Debug.LogError("Cannot find reacted skill for "+fname);
                return float.NaN;
            case LookupType.ReactedEffectType:
                if(scontext != null) {
                    //ignore lookupRef
                    string[] fnames = f.searchReactedStatNames;
                    var results = scontext.currentReactedSkill.lastEffects.
                        Where(fx => fx.Matches(fnames, f.searchReactedStatChanges, f.searchReactedEffectCategories)).
                        Select(fx => fx.value);
                    switch(f.mergeMode) {
                        case FormulaMergeMode.Sum:
                            return results.Sum();
                        case FormulaMergeMode.Mean:
                            return results.Average(x => x);
                        case FormulaMergeMode.Min:
                            return results.Min(x => x);
                        case FormulaMergeMode.Max:
                            return results.Max(x => x);
                        case FormulaMergeMode.First:
                            return results.First();
                        case FormulaMergeMode.Last:
                            return results.Last();
                        case FormulaMergeMode.Nth:
                            return results.ElementAt(f.mergeNth);
                    }
                } else {
                    Debug.LogError("Skill effect lookups require a skill context.");
                    return float.NaN;
                }
                Debug.LogError("Cannot find reacted effects for "+f);
                return float.NaN;
            case LookupType.SkillEffectType:
                if(scontext != null) {
                    string[] fnames = f.searchReactedStatNames;
                    //ignore lookupRef
                    var results = scontext.lastEffects.
                        Where(fx => fx.Matches(fnames, f.searchReactedStatChanges, f.searchReactedEffectCategories)).
                        Select(fx => fx.value);
                    switch(f.mergeMode) {
                        case FormulaMergeMode.Sum:
                            return results.Sum();
                        case FormulaMergeMode.Mean:
                            return results.Average(x => x);
                        case FormulaMergeMode.Min:
                            return results.Min(x => x);
                        case FormulaMergeMode.Max:
                            return results.Max(x => x);
                        case FormulaMergeMode.First:
                            return results.First();
                        case FormulaMergeMode.Last:
                            return results.Last();
                        case FormulaMergeMode.Nth:
                            Debug.Log("nth "+f.mergeNth+" is "+results.ElementAt(f.mergeNth));
                            return results.ElementAt(f.mergeNth);
                    }
                } else {
                    Debug.LogError("Skill effect lookups require a skill context.");
                    return float.NaN;
                }
                Debug.LogError("Cannot find effects for "+f);
                return float.NaN;
        }
        Debug.LogError("failed to look up "+type+" "+fname+" with context s:"+scontext+", c:"+ccontext+", e:"+econtext+", i:"+icontext+" and formula "+f);
        return float.NaN;
    }
Example #2
0
    public float Lookup(
        string fname, LookupType type,
        SkillDef scontext  = null,
        Character ccontext = null,
        Character tcontext = null,
        Equipment econtext = null,
        Item icontext      = null,
        Formula f          = null
        )
    {
        switch (type)
        {
        case LookupType.Auto: {
            float ret =
                (icontext != null ? icontext.GetParam(fname) :
                 (econtext != null ? econtext.GetParam(fname) :
                  (scontext != null ? scontext.GetParam(fname) :
                   (ccontext != null ? ccontext.GetStat(fname) :
                    (tcontext != null ? tcontext.GetStat(fname) :
                     (HasFormula(fname) ? LookupFormula(fname).GetValue(this, scontext, ccontext, tcontext, econtext, icontext) : float.NaN))))));
            if (float.IsNaN(ret))
            {
                Debug.LogError("auto lookup failed for " + fname);
            }
            return(ret);
        }

        case LookupType.SkillParam:
            return(scontext.GetParam(fname));

        case LookupType.ItemParam: {
            if (icontext == null && scontext != null)
            {
                icontext = scontext.InvolvedItem;
            }
            if (icontext == null && econtext != null)
            {
                icontext = econtext.baseItem;
            }
            return(icontext.GetParam(fname, scontext));
        }

        case LookupType.ReactedItemParam: {
            icontext = scontext.currentReactedSkill.InvolvedItem;
            return(icontext.GetParam(fname, scontext));
        }

        case LookupType.ActorStat:
            if (scontext != null)
            {
                return(scontext.character.GetStat(fname));
            }
            if (econtext != null)
            {
                return(econtext.wielder.GetStat(fname));
            }
            if (ccontext != null)
            {
                return(ccontext.GetStat(fname));
            }
            Debug.LogError("Cannot find actor stat " + fname);
            return(float.NaN);

        case LookupType.ActorMountStat: {
            Character m = null;
            if (scontext != null)
            {
                m = scontext.character.mountedCharacter;
            }
            if (econtext != null)
            {
                m = econtext.wielder.mountedCharacter;
            }
            if (ccontext != null)
            {
                m = ccontext.mountedCharacter;
            }
            // Debug.Log("lookup "+fname+" on mount "+m+" ? "+(m != null ? m.GetStat(fname) : 0));
            if (m != null)
            {
                return(m.GetStat(fname));
            }
            Debug.LogError("Cannot find actor mount stat " + fname);
            return(float.NaN);
        }

        case LookupType.ActorMounterStat: {
            Character m = null;
            if (scontext != null)
            {
                m = scontext.character.mountingCharacter;
            }
            if (econtext != null)
            {
                m = econtext.wielder.mountingCharacter;
            }
            if (ccontext != null)
            {
                m = ccontext.mountingCharacter;
            }
            if (m != null)
            {
                return(m.GetStat(fname));
            }
            Debug.LogError("Cannot find actor mounter stat " + fname);
            return(float.NaN);
        }

        case LookupType.ActorEquipmentParam:
            if (scontext != null)
            {
                ccontext = scontext.character;
            }
            else if (ccontext == null && econtext != null)
            {
                if (econtext.Matches(f.equipmentSlots, f.equipmentCategories))
                {
                    return(econtext.GetParam(fname));
                }
                else
                {
                    ccontext = econtext.wielder;
                }
            }
            return(LookupEquipmentParamOn(fname, type, ccontext, f, scontext));

        case LookupType.ActorMountEquipmentParam:
            if (scontext != null)
            {
                ccontext = scontext.character.mountedCharacter;
            }
            else if (ccontext == null && econtext != null)
            {
                if (econtext.Matches(f.equipmentSlots, f.equipmentCategories))
                {
                    return(econtext.GetParam(fname));
                }
                else
                {
                    ccontext = econtext.wielder.mountedCharacter;
                }
            }
            return(LookupEquipmentParamOn(fname, type, ccontext, f, scontext));

        case LookupType.ActorMounterEquipmentParam:
            if (scontext != null)
            {
                ccontext = scontext.character.mountingCharacter;
            }
            else if (ccontext == null && econtext != null)
            {
                if (econtext.Matches(f.equipmentSlots, f.equipmentCategories))
                {
                    return(econtext.GetParam(fname));
                }
                else
                {
                    ccontext = econtext.wielder.mountingCharacter;
                }
            }
            return(LookupEquipmentParamOn(fname, type, ccontext, f, scontext));

        case LookupType.ActorStatusEffect:
        case LookupType.ActorMountStatusEffect:
        case LookupType.ActorMounterStatusEffect:
            Debug.LogError("lookup semantics not defined for own status effect " + fname);
            return(float.NaN);

        case LookupType.ActorSkillParam:
            //TODO: look up skill by slot, name, type?
            if (scontext != null)
            {
                return(scontext.GetParam(fname));
            }
            Debug.LogError("Cannot find skill param " + fname);
            return(float.NaN);

        case LookupType.TargetStat:
            if (scontext != null)
            {
                return(scontext.currentTargetCharacter.GetStat(fname));
            }
            if (tcontext != null)
            {
                return(tcontext.GetStat(fname));
            }
            Debug.LogError("Cannot find target stat " + fname);
            return(float.NaN);

        case LookupType.TargetMountStat: {
            Character m = null;
            if (scontext != null)
            {
                m = scontext.currentTargetCharacter.mountedCharacter;
            }
            if (tcontext != null)
            {
                m = tcontext.mountedCharacter;
            }
            if (m != null)
            {
                return(m.GetStat(fname));
            }
            Debug.LogError("Cannot find target stat " + fname);
            return(float.NaN);
        }

        case LookupType.TargetMounterStat: {
            Character m = null;
            if (scontext != null)
            {
                m = scontext.currentTargetCharacter.mountingCharacter;
            }
            if (tcontext != null)
            {
                m = tcontext.mountingCharacter;
            }
            if (m != null)
            {
                return(m.GetStat(fname));
            }
            Debug.LogError("Cannot find target stat " + fname);
            return(float.NaN);
        }

        case LookupType.TargetEquipmentParam:
            if (scontext != null)
            {
                ccontext = scontext.currentTargetCharacter;
            }
            else if (tcontext != null)
            {
                ccontext = tcontext;
            }
            else
            {
                ccontext = null;
            }
            return(LookupEquipmentParamOn(fname, type, ccontext, f, scontext));

        case LookupType.TargetMountEquipmentParam:
            if (scontext != null)
            {
                ccontext = scontext.currentTargetCharacter.mountedCharacter;
            }
            else if (tcontext != null)
            {
                ccontext = tcontext.mountedCharacter;
            }
            else
            {
                ccontext = null;
            }
            return(LookupEquipmentParamOn(fname, type, ccontext, f, scontext));

        case LookupType.TargetMounterEquipmentParam:
            if (scontext != null)
            {
                ccontext = scontext.currentTargetCharacter.mountingCharacter;
            }
            else if (tcontext != null)
            {
                ccontext = tcontext.mountingCharacter;
            }
            else
            {
                ccontext = null;
            }
            return(LookupEquipmentParamOn(fname, type, ccontext, f, scontext));

        case LookupType.TargetStatusEffect:
        case LookupType.TargetMountStatusEffect:
        case LookupType.TargetMounterStatusEffect:
            Debug.LogError("lookup semantics not defined for target status effect " + fname);
            return(float.NaN);

        case LookupType.TargetSkillParam:
        case LookupType.ActorMountSkillParam:
        case LookupType.ActorMounterSkillParam:
        case LookupType.TargetMountSkillParam:
        case LookupType.TargetMounterSkillParam:
            //TODO: look up skill by slot, name, type?
            Debug.LogError("Cannot find " + type + " " + fname);
            return(float.NaN);

        case LookupType.NamedFormula:
            if (!HasFormula(fname))
            {
                Debug.LogError("Missing formula " + fname);
                return(float.NaN);
            }
            // Debug.Log("F:"+LookupFormula(fname));
            return(LookupFormula(fname).GetValue(this, scontext, ccontext, tcontext, econtext, icontext));

        case LookupType.ReactedSkillParam:
            if (scontext != null)
            {
                return(scontext.currentReactedSkill.GetParam(fname));
            }
            Debug.LogError("Cannot find reacted skill for " + fname);
            return(float.NaN);

        case LookupType.ReactedEffectType:
            if (scontext != null)
            {
                //ignore lookupRef
                string[] fnames  = f.searchReactedStatNames;
                var      results = scontext.currentReactedSkill.lastEffects.
                                   Where(fx => fx.Matches(fnames, f.searchReactedStatChanges, f.searchReactedEffectCategories)).
                                   Select(fx => fx.value);
                switch (f.mergeMode)
                {
                case FormulaMergeMode.Sum:
                    return(results.Sum());

                case FormulaMergeMode.Mean:
                    return(results.Average(x => x));

                case FormulaMergeMode.Min:
                    return(results.Min(x => x));

                case FormulaMergeMode.Max:
                    return(results.Max(x => x));

                case FormulaMergeMode.First:
                    return(results.First());

                case FormulaMergeMode.Last:
                    return(results.Last());

                case FormulaMergeMode.Nth:
                    return(results.ElementAt(f.mergeNth));
                }
            }
            else
            {
                Debug.LogError("Skill effect lookups require a skill context.");
                return(float.NaN);
            }
            Debug.LogError("Cannot find reacted effects for " + f);
            return(float.NaN);

        case LookupType.SkillEffectType:
            if (scontext != null)
            {
                string[] fnames = f.searchReactedStatNames;
                //ignore lookupRef
                var results = scontext.lastEffects.
                              Where(fx => fx.Matches(fnames, f.searchReactedStatChanges, f.searchReactedEffectCategories)).
                              Select(fx => fx.value);
                switch (f.mergeMode)
                {
                case FormulaMergeMode.Sum:
                    return(results.Sum());

                case FormulaMergeMode.Mean:
                    return(results.Average(x => x));

                case FormulaMergeMode.Min:
                    return(results.Min(x => x));

                case FormulaMergeMode.Max:
                    return(results.Max(x => x));

                case FormulaMergeMode.First:
                    return(results.First());

                case FormulaMergeMode.Last:
                    return(results.Last());

                case FormulaMergeMode.Nth:
                    Debug.Log("nth " + f.mergeNth + " is " + results.ElementAt(f.mergeNth));
                    return(results.ElementAt(f.mergeNth));
                }
            }
            else
            {
                Debug.LogError("Skill effect lookups require a skill context.");
                return(float.NaN);
            }
            Debug.LogError("Cannot find effects for " + f);
            return(float.NaN);
        }
        Debug.LogError("failed to look up " + type + " " + fname + " with context s:" + scontext + ", c:" + ccontext + ", e:" + econtext + ", i:" + icontext + " and formula " + f);
        return(float.NaN);
    }