Exemple #1
0
    protected float FacingSwitch(
        Formulae fdb,
        StatEffectTarget target,
        SkillDef scontext,
        Character ccontext,
        Character tcontext,
        Equipment econtext,
        Item icontext
        )
    {
        if (scontext == null)
        {
            Debug.LogError("Relative facing not available for non-attack/reaction skill effects.");
            return(float.NaN);
        }
        Character applier = scontext != null ?
                            scontext.character : ccontext;
        Character applied = scontext != null ?
                            scontext.currentTargetCharacter : tcontext;
        CharacterPointing pointing = CharacterPointing.Front;
        Character         x = null, y = null;

        if (target == StatEffectTarget.Applied)
        {
            x = applier;
            y = applied;
        }
        else if (target == StatEffectTarget.Applier)
        {
            x = applied;
            y = applier;
        }
        Vector3 xp = x.TilePosition;
        Vector3 yp = y.TilePosition;
        //see if y is facing towards x at all
        float xAngle = SRPGUtil.WrapAngle(x.Facing);
        float yAngle = SRPGUtil.WrapAngle(y.Facing);
        float interAngle     = Mathf.Atan2(yp.y - xp.y, yp.x - xp.x) * Mathf.Rad2Deg;
        float relativeYAngle = SRPGUtil.WrapAngle(yAngle - xAngle);
        bool  towards = Mathf.Abs(Mathf.DeltaAngle(interAngle, xAngle)) < 45;

        //is theta(y,x) within 45 of yAngle?
        // Debug.Log("xang "+xAngle);
        //      Debug.Log("yang "+yAngle);
        //      Debug.Log("interang "+interAngle);
        //      Debug.Log("towardsang "+Mathf.Abs(Mathf.DeltaAngle(xAngle, interAngle)));
        //      Debug.Log("relY "+relativeYAngle);
        if (towards)
        {
            //next, get the quadrant
            //quadrant ~~ theta (target -> other)
            if (relativeYAngle >= 45 && relativeYAngle < 135)
            {
                pointing = CharacterPointing.Left;
            }
            else if (relativeYAngle >= 135 && relativeYAngle < 225)
            {
                pointing = CharacterPointing.Front;
            }
            else if (relativeYAngle >= 225 && relativeYAngle < 315)
            {
                pointing = CharacterPointing.Right;
            }
            else
            {
                pointing = CharacterPointing.Back;
            }
        }
        else
        {
            pointing = CharacterPointing.Away;
        }
        // Debug.Log("pt "+pointing);

        //order:
        //front, left, right, back, away, sides, towards, default
        //must have null entries
        if (arguments.Count != 8)
        {
            Debug.Log("Bad facing switch in skill " + (scontext != null ? scontext.skillName : "none"));
        }
        if (pointing == CharacterPointing.Front && NotNullFormula(arguments[0]))
        {
            //front
            //Debug.Log("ft");
            return(arguments[0].GetValue(fdb, scontext, ccontext, tcontext, econtext, icontext));
        }
        else if (pointing == CharacterPointing.Left && NotNullFormula(arguments[1]))
        {
            //left
            //Debug.Log("lt");
            return(arguments[1].GetValue(fdb, scontext, ccontext, tcontext, econtext, icontext));
        }
        else if (pointing == CharacterPointing.Right && NotNullFormula(arguments[2]))
        {
            //right
            //Debug.Log("rt");
            return(arguments[2].GetValue(fdb, scontext, ccontext, tcontext, econtext, icontext));
        }
        else if (pointing == CharacterPointing.Back && NotNullFormula(arguments[3]))
        {
            //back
            //Debug.Log("bk");
            return(arguments[3].GetValue(fdb, scontext, ccontext, tcontext, econtext, icontext));
        }
        else if (pointing == CharacterPointing.Away && NotNullFormula(arguments[4]))
        {
            //away
            //Debug.Log("away");
            return(arguments[4].GetValue(fdb, scontext, ccontext, tcontext, econtext, icontext));
        }
        else if ((pointing == CharacterPointing.Left || pointing == CharacterPointing.Right) && NotNullFormula(arguments[5]))
        {
            //sides
            // Debug.Log("sides");
            return(arguments[5].GetValue(fdb, scontext, ccontext, tcontext, econtext, icontext));
        }
        else if ((pointing != CharacterPointing.Away) && NotNullFormula(arguments[6]))
        {
            //towards
            // Debug.Log("twds");
            return(arguments[6].GetValue(fdb, scontext, ccontext, tcontext, econtext, icontext));
        }
        else if (NotNullFormula(arguments[7]))
        {
            //default
            // Debug.Log("default");
            return(arguments[7].GetValue(fdb, scontext, ccontext, tcontext, econtext, icontext));
        }
        else
        {
            Debug.LogError("No valid branch for pointing " + pointing + " in skill " + (scontext != null ? scontext.skillName : "none"));
            return(float.NaN);
        }
    }
Exemple #2
0
    protected float FacingSwitch(
		Formulae fdb,
		StatEffectTarget target,
		SkillDef scontext,
		Character ccontext,
		Character tcontext,
		Equipment econtext,
		Item icontext
	)
    {
        if(scontext == null) {
            Debug.LogError("Relative facing not available for non-attack/reaction skill effects.");
            return float.NaN;
        }
        Character applier = scontext != null ?
            scontext.character : ccontext;
        Character applied = scontext != null ?
            scontext.currentTargetCharacter : tcontext;
        CharacterPointing pointing = CharacterPointing.Front;
        Character x = null, y = null;
        if(target == StatEffectTarget.Applied) {
            x = applier;
            y = applied;
        } else if(target == StatEffectTarget.Applier) {
            x = applied;
            y = applier;
        }
        Vector3 xp = x.TilePosition;
        Vector3 yp = y.TilePosition;
        //see if y is facing towards x at all
        float xAngle = SRPGUtil.WrapAngle(x.Facing);
        float yAngle = SRPGUtil.WrapAngle(y.Facing);
        float interAngle = Mathf.Atan2(yp.y-xp.y, yp.x-xp.x)*Mathf.Rad2Deg;
        float relativeYAngle = SRPGUtil.WrapAngle(yAngle - xAngle);
        bool towards = Mathf.Abs(Mathf.DeltaAngle(interAngle, xAngle)) < 45;
        //is theta(y,x) within 45 of yAngle?
        // Debug.Log("xang "+xAngle);
        // 		Debug.Log("yang "+yAngle);
        // 		Debug.Log("interang "+interAngle);
        // 		Debug.Log("towardsang "+Mathf.Abs(Mathf.DeltaAngle(xAngle, interAngle)));
        // 		Debug.Log("relY "+relativeYAngle);
        if(towards) {
            //next, get the quadrant
            //quadrant ~~ theta (target -> other)
            if(relativeYAngle >= 45 && relativeYAngle < 135) {
                pointing = CharacterPointing.Left;
            } else if(relativeYAngle >= 135 && relativeYAngle < 225) {
                pointing = CharacterPointing.Front;
            } else if(relativeYAngle >= 225 && relativeYAngle < 315) {
                pointing = CharacterPointing.Right;
            } else {
                pointing = CharacterPointing.Back;
            }
        } else {
            pointing = CharacterPointing.Away;
        }
        // Debug.Log("pt "+pointing);

        //order:
        //front, left, right, back, away, sides, towards, default
        //must have null entries
        if(arguments.Count != 8) {
            Debug.Log("Bad facing switch in skill "+(scontext != null ? scontext.skillName : "none"));
        }
        if(pointing == CharacterPointing.Front && NotNullFormula(arguments[0])) {
            //front
            //Debug.Log("ft");
            return arguments[0].GetValue(fdb, scontext, ccontext, tcontext, econtext, icontext);
        } else if(pointing == CharacterPointing.Left && NotNullFormula(arguments[1])) {
            //left
            //Debug.Log("lt");
            return arguments[1].GetValue(fdb, scontext, ccontext, tcontext, econtext, icontext);
        } else if(pointing == CharacterPointing.Right && NotNullFormula(arguments[2])) {
            //right
            //Debug.Log("rt");
            return arguments[2].GetValue(fdb, scontext, ccontext, tcontext, econtext, icontext);
        } else if(pointing == CharacterPointing.Back && NotNullFormula(arguments[3])) {
            //back
            //Debug.Log("bk");
            return arguments[3].GetValue(fdb, scontext, ccontext, tcontext, econtext, icontext);
        } else if(pointing == CharacterPointing.Away && NotNullFormula(arguments[4])) {
            //away
            //Debug.Log("away");
            return arguments[4].GetValue(fdb, scontext, ccontext, tcontext, econtext, icontext);
        } else if((pointing == CharacterPointing.Left || pointing == CharacterPointing.Right) && NotNullFormula(arguments[5])) {
            //sides
            // Debug.Log("sides");
            return arguments[5].GetValue(fdb, scontext, ccontext, tcontext, econtext, icontext);
        } else if((pointing != CharacterPointing.Away) && NotNullFormula(arguments[6])) {
            //towards
            // Debug.Log("twds");
            return arguments[6].GetValue(fdb, scontext, ccontext, tcontext, econtext, icontext);
        } else if(NotNullFormula(arguments[7])) {
            //default
            // Debug.Log("default");
            return arguments[7].GetValue(fdb, scontext, ccontext, tcontext, econtext, icontext);
        } else {
            Debug.LogError("No valid branch for pointing "+pointing+" in skill "+(scontext != null ? scontext.skillName : "none"));
            return float.NaN;
        }
    }