Ejemplo n.º 1
0
        // --------------------------------------------------------------------------------------------
        public static Quaternion FacingToRotation(EFacing facing)
        {
            float rot = 0f;

            switch (facing)
            {
            case EFacing.North:
                rot = 270;
                break;

            case EFacing.South:
                rot = 90;
                break;

            case EFacing.East:
                rot = 180;
                break;

            case EFacing.West:
                rot = 0;
                break;
            }

            return(Quaternion.Euler(0f, rot, 0f));
        }
Ejemplo n.º 2
0
        // --------------------------------------------------------------------------------------------
        protected virtual void Start()
        {
            _input          = new ActorInput();
            _targetPosition = transform.localPosition;
            _interactOffset = Vector3.right;
            _facing         = EFacing.Right;

            if (_destructible)
            {
                _destructible.AddDamageListener(OnDamaged);
            }
        }
Ejemplo n.º 3
0
        public static EFacing VectorToFacing(Vector3 v)
        {
            float   highestValue = float.MinValue;
            EFacing mostAligned  = 0;

            foreach (EFacing facingEnum in Enum.GetValues(typeof(EFacing)))
            {
                float dot = Vector3.Dot(FacingToRotation(facingEnum) * Vector2.right, v);
                if (dot > highestValue)
                {
                    highestValue = dot;
                    mostAligned  = facingEnum;
                }
            }
            return(mostAligned);
        }
Ejemplo n.º 4
0
        // --------------------------------------------------------------------------------------------
        public static IntVector2 RotateVectorForFacingDir(EFacing facing, IntVector2 v)
        {
            switch (facing)
            {
            case EFacing.East:
                return(v);

            case EFacing.South:
                return(v.Rotate90Clockwise());

            case EFacing.West:
                return(v.Rotate90Clockwise().Rotate90Clockwise());

            case EFacing.North:
                return(v.Rotate90Clockwise().Rotate90Clockwise().Rotate90Clockwise());

            default:
                Debug.LogError($"Facing not implemented: {facing}, can't rotate");
                return(v);
            }
        }
Ejemplo n.º 5
0
        // --------------------------------------------------------------------------------------------
        public void SetFacing(EFacing facing, bool animate)
        {
            _facing = facing;
            _facingAnim?.Stop();

            Quaternion rot = FacingToRotation(facing);

            if (animate)
            {
                Quaternion startRot = LocalRotation;
                _facingAnim = new TofuAnimation()
                              .Value01(0.5f, EEaseType.EaseOutExpo, (float newValue) =>
                {
                    LocalRotation = Quaternion.SlerpUnclamped(startRot, rot, newValue);
                })
                              .Play();
            }
            else
            {
                LocalRotation = rot;
            }
        }
Ejemplo n.º 6
0
 // --------------------------------------------------------------------------------------------
 protected virtual void TryMoveInteractOffset()
 {
     if (_input.up && CanTurnInteractOffset(Vector3.up))
     {
         _interactOffset = Vector3.up;
     }
     else if (_input.down && CanTurnInteractOffset(Vector3.down))
     {
         _interactOffset = Vector3.down;
     }
     else if (_input.left && CanTurnInteractOffset(Vector3.left))
     {
         _interactOffset       = Vector3.left;
         _spriteRenderer.flipX = true;
         _facing = EFacing.Left;
     }
     else if (_input.right && CanTurnInteractOffset(Vector3.right))
     {
         _interactOffset       = Vector3.right;
         _spriteRenderer.flipX = false;
         _facing = EFacing.Right;
     }
 }
Ejemplo n.º 7
0
        // --------------------------------------------------------------------------------------------
        public void UseSkill(EFacing faceTowards, IntVector2 targetCoord, Action onComplete)
        {
            if (!CanUseSkill)
            {
                Debug.LogError($"Unit {id} cannot use its skill");
                return;
            }

            HasUsedSkill = true;

            if (faceTowards != Facing)
            {
                SetFacing(faceTowards, false);
            }

            int numTimesSkillUsedOnTarget          = 0;
            int numTimesSkillUsedOnTargetCompleted = 0;

            void SkillUsedOnTargetCallback()
            {
                numTimesSkillUsedOnTargetCompleted++;
                if (numTimesSkillUsedOnTargetCompleted >= numTimesSkillUsedOnTarget)
                {
                    onComplete?.Invoke();
                }
            }

            if (Skill.Target == SkillData.ETarget.None)
            {
                numTimesSkillUsedOnTarget++;
                UseSkillNoTarget(SkillUsedOnTargetCallback);
            }
            else
            {
                List <BoardTile> targetTiles = Skill.GetAffectedTiles(faceTowards, targetCoord);
                foreach (BoardTile boardTile in targetTiles)
                {
                    if (Skill.Target == SkillData.ETarget.Tile)
                    {
                        numTimesSkillUsedOnTarget++;
                        UseSkillOnBoardTile(boardTile, SkillUsedOnTargetCallback);
                    }
                    else
                    {
                        switch (Skill.Target)
                        {
                        case SkillData.ETarget.Ally:
                            if (IsAllyOf(boardTile.Occupant))
                            {
                                numTimesSkillUsedOnTarget++;
                                UseSkillOnUnit(boardTile.Occupant, SkillUsedOnTargetCallback);
                            }
                            break;

                        case SkillData.ETarget.Enemy:
                            if (!IsAllyOf(boardTile.Occupant))
                            {
                                numTimesSkillUsedOnTarget++;
                                UseSkillOnUnit(boardTile.Occupant, SkillUsedOnTargetCallback);
                            }
                            break;

                        case SkillData.ETarget.Self:
                            if (boardTile.Occupant == this)
                            {
                                numTimesSkillUsedOnTarget++;
                                UseSkillOnUnit(boardTile.Occupant, SkillUsedOnTargetCallback);
                            }
                            break;
                        }
                    }
                }
            }
        }