Esempio n. 1
0
    public void Update()
    {
        //button inputs for camera
        //rotate-left, rotate-right, tilt-up, tilt-down, zoom-in, zoom-out
        MovableCamera mc = Camera.main.transform.parent.GetComponent <MovableCamera>();

        if (Input.GetButton("Rotate Left"))
        {
            if (!mc.IsMoving)
            {
                mc.targetRotation = (float)SRPGUtil.LockFacing(mc.targetRotation - 90, FacingLock.Ordinal);
            }
        }
        if (Input.GetButton("Rotate Right"))
        {
            if (!mc.IsMoving)
            {
                mc.targetRotation = (float)SRPGUtil.LockFacing(mc.targetRotation + 90, FacingLock.Ordinal);
            }
        }
        if (Input.GetButton("Tilt Up"))
        {
            if (Mathf.Approximately(mc.targetTilt, 30) && !mc.IsMoving)
            {
                mc.targetTilt = 45;
            }
        }
        if (Input.GetButton("Tilt Down"))
        {
            if (Mathf.Approximately(mc.targetTilt, 45) && !mc.IsMoving)
            {
                mc.targetTilt = 30;
            }
        }
        if (Input.GetButton("Zoom In"))
        {
            if (Mathf.Approximately(mc.targetDistance, 45) && !mc.IsMoving)
            {
                mc.targetDistance = 30;
            }
        }
        if (Input.GetButton("Zoom Out"))
        {
            if (Mathf.Approximately(mc.targetDistance, 30) && !mc.IsMoving)
            {
                mc.targetDistance = 45;
            }
        }
        //also, if we're in an active skill, make the selected tile the target pivot
        if (activeSkill != null)
        {
            if (activeSkill is ActionSkillDef)
            {
                FocusOnPoint(map.TransformPointWorld(((ActionSkillDef)activeSkill).TargetPosition));
            }
        }
    }
Esempio n. 2
0
    public Arrow ArrowForFacing(float f)
    {
        LockedFacing l = SRPGUtil.LockFacing(f, FacingLock.Cardinal, map.transform.eulerAngles.y);

        switch (l)
        {
        case LockedFacing.XP:
            return(Arrow.XP);

        case LockedFacing.YP:
            return(Arrow.YP);

        case LockedFacing.XN:
            return(Arrow.XN);

        case LockedFacing.YN:
            return(Arrow.YN);

        default:
            Debug.LogError("Bad locked facing " + l + " from " + f);
            return((Arrow)(-1));
        }
    }
Esempio n. 3
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);
        }
    }
Esempio n. 4
0
    public void SpecialMove(
        Vector3 start,
        bool animateMoveToStart,
        string moveType,
        Region lineMove,
        float specialMoveSpeedXY,
        float specialMoveSpeedZ,
        SkillDef cause
        )
    {
        specialMoveType                = moveType;
        specialMoveExecutor.XYSpeed    = specialMoveSpeedXY;
        specialMoveExecutor.ZSpeedDown = specialMoveSpeedZ;
        List <Character> collidedCharacters = new List <Character>();
        float            direction = -1, amount = -1, remaining = -1, dropDistance = -1;
        PathNode         movePath = lineMove.GetLineMove(
            out direction,
            out amount,
            out remaining,
            out dropDistance,
            collidedCharacters,
            this,
            start
            );

        //move executor special move (path)
        specialMoveExecutor.Activate();
        CharacterSpecialMoveReport rep = new CharacterSpecialMoveReport(
            this,
            moveType,
            lineMove,
            cause,
            start,
            movePath,
            direction,
            amount,
            remaining,
            dropDistance,
            collidedCharacters
            );

        map.BroadcastMessage(
            "WillSpecialMoveCharacter",
            rep,
            SendMessageOptions.DontRequireReceiver
            );
        MoveExecutor.MoveFinished movedToStart =
            (srcStart, srcEndNode, srcFinishedNicely) => {
            Debug.Log("src finished nicely? " + srcFinishedNicely);
            specialMoveExecutor.SpecialMoveTo(
                movePath,
                (src, endNode, finishedNicely) => {
                Debug.Log(
                    "specially moved character " + this.name +
                    " by " + moveType +
                    " from " + start +
                    " in dir " + direction +
                    " node " + movePath +
                    " into " + (
                        collidedCharacters.Count == 0 ?
                        "nobody":
                        "" + collidedCharacters.Count + " folks"
                        ) +
                    " left over " + remaining +
                    " dropped " + dropDistance
                    );
                map.BroadcastMessage(
                    "DidSpecialMoveCharacter",
                    rep,
                    SendMessageOptions.DontRequireReceiver
                    );
                specialMoveExecutor.Deactivate();
                var allChars      = map.CharactersAt(endNode.pos);
                var otherChars    = allChars.Where(c => c != this && c != mountedCharacter).ToArray();
                Character[] chars = null;
                if (otherChars.Length > 0)
                {
                    //try to fix myself
                    chars = new Character[] { IsMounting?mountedCharacter: this };
                }
                if (chars != null && chars.Length > 0)
                {
                    //if any collisions left over between me and somebody else...
                    Debug.Log("fix collisions");
                    bool success = false;
                    if (!success)
                    {
                        Debug.Log("try straight");
                        success = TrySpecialMoveResponse(direction, endNode, chars, lineMove, cause);
                    }
                    if (!success)
                    {
                        Debug.Log("try left");
                        success = TrySpecialMoveResponse(SRPGUtil.WrapAngle(direction + 90), endNode, chars, lineMove, cause);
                    }
                    if (!success)
                    {
                        Debug.Log("try right");
                        success = TrySpecialMoveResponse(SRPGUtil.WrapAngle(direction - 90), endNode, chars, lineMove, cause);
                    }
                    if (!success)
                    {
                        Debug.Log("try back");
                        success = TrySpecialMoveResponse(SRPGUtil.WrapAngle(direction + 180), endNode, chars, lineMove, cause);
                    }
                    if (!success)
                    {
                        Debug.LogError("Can't shove " + chars.Length + " chars out of the way!");
                    }
                }
            }
                );
        };

        if (start != TilePosition)
        {
            if (animateMoveToStart)
            {
                specialMoveExecutor.SpecialMoveTo(
                    new PathNode(start, null, 0),
                    movedToStart,
                    3.0f
                    );
            }
            else
            {
                specialMoveExecutor.ImmediatelyMoveTo(
                    new PathNode(start, null, 0),
                    movedToStart,
                    3.0f
                    );
            }
        }
        else
        {
            movedToStart(start, new PathNode(start, null, 0), true);
        }
    }