예제 #1
0
    private void doRoam()
    {
        float random = UnityEngine.Random.value;

        if (random < Constants.ROAM_MOVE_CHANCE)
        {
            Vector2 dir = UnityEngine.Random.insideUnitCircle.normalized;
            m_movingEntity.Move(dir);
            Synchronizer.Continue(m_actor, m_movingEntity.moveActionCost);
        }
        else
        {
            m_actor.AssignAction(new SynchronizedActor.IdleAction(m_actor, Constants.DEFAULT_IDLE_DURATION));
            Synchronizer.Continue(m_actor, Constants.DEFAULT_IDLE_DURATION);
        }
    }
    public override void Activate(MovingEntity user, Vector2Int direction = default)
    {
        this.direction = direction;

        //Store a reference to a temporary "subtract usages" function
        Action <Vector3, Vector3> subtractUsages = (oldPosition, newPosition) => usagesLeft--;

        //Subscribe subtractUsages to OnMove so if the player succeeds in moving, subtract a use, and if
        //they don't, don't subtract a use. Unsubscribe afterwards so normal moving doesn't subtract usages
        user.OnMove += subtractUsages;
        user.Move(direction * leapDistance);
        user.OnMove -= subtractUsages;
    }
예제 #3
0
 protected void TryToMove()
 {
     if (!isWaiting || isForcedMovement)
     {
         if (isMoving)
         {
             LerpToDestination();
         }
         else
         {
             Movement next = movingEntity.NextMovement();
             if (movingEntity.Move())
             {
                 Move(next);
                 lastDirectionFaced = next == Movement.WAIT ? lastDirectionFaced : next;
             }
             else
             {
                 Move(Movement.WAIT);
             }
             setAnimatorState(next);
         }
     }
 }
예제 #4
0
    // Update is called once per frame
    void Update()
    {
        if (m_myTurn)
        {
            World.Cell mouseOverCell = GetMouseOverCell();
            if (mouseOverCell != null && mouseOverCell.ContainsEntity)
            {
                ApplyLOS();
                int    x, y;
                Entity ent = mouseOverCell.GetEntity();
                ent.GetPosition(out x, out y);

                if (!"Player".Equals(ent.GetType().ToString()) && ent.GetCell().IsVisible())
                {
                    SetCrosshair(x, y);
                }
                else
                {
                    HideCrosshair();
                }

                if (Input.GetMouseButtonDown(0))
                {
                    AttackingEntity.AttackResult res = CombatSolver.Fight(m_actor, mouseOverCell.GetEntity().Actor);

                    if (res != null && res.Weapon != null)
                    {
                        Synchronizer.Continue(m_actor, res.Weapon.TimeCost);
                        return;
                    }
                    else if (res.Result == AttackingEntity.AttackResult.ResultValue.NoEnergy)
                    {
                        Debug.Log(res.Weapon.Name + " Out of energy");
                    }
                }
            }
            else
            {
                HideCrosshair();
            }

            Vector2 move = Vector2.zero;
            if (Input.GetButtonDown("Horizontal"))
            {
                float h = Input.GetAxis("Horizontal");
                move.x = Mathf.Sign(h);
            }
            if (Input.GetButtonDown("Vertical"))
            {
                float h = Input.GetAxis("Vertical");

                move.y = Mathf.Sign(h);
            }

            if (move != Vector2.zero)
            {
                //Debug.Log("Move: " + move);
                MovingEntity.MoveResult result = m_movingEntity.Move(move);
                switch (result.Result)
                {
                case MovingEntity.MoveResult.ResultValue.Ok:
                    Synchronizer.Continue(m_actor, m_movingEntity.moveActionCost);

                    if (m_levelBuilder.LevelType != LevelType.Ambush)
                    {
                        if (m_levelBuilder.EndPoint.X == result.Cell.X && m_levelBuilder.EndPoint.Y == result.Cell.Y)
                        {
                            if (OnPlayerMovedToEndEvent != null)
                            {
                                OnPlayerMovedToEndEvent();
                            }
                        }

                        if (m_levelBuilder.ObjectivePoint.X == result.Cell.X && m_levelBuilder.ObjectivePoint.Y == result.Cell.Y)
                        {
                            if (OnPlayerMovedToObjectiveEvent != null)
                            {
                                OnPlayerMovedToObjectiveEvent();
                            }
                        }
                    }
                    break;

                case MovingEntity.MoveResult.ResultValue.TileBlocked:
                    //Debug.Log("Tile blocked!");
                    break;

                case MovingEntity.MoveResult.ResultValue.TileOccupied:
                    AttackingEntity.AttackResult res = CombatSolver.Fight(m_actor, result.Cell.GetEntity().Actor);
                    Synchronizer.Continue(m_actor, res.Weapon.TimeCost);
                    break;
                }
            }
        }
    }