Beispiel #1
0
        public override void Init(ActiveLinking activeLinking)
        {
            range = activeLinking.GetValueOrDefault <float>("range", range);

            if (movingTarget)
            {
                tranform = activeLinking.GetValueOrDefault <Transform>("target_position", tranform);
            }
            else
            {
                targetPosition = activeLinking.GetValueOrDefault <Vector3>("target_position", targetPosition);
            }
        }
    override public void StateUpdate(StateMachine stateMachine, ActiveLinking activeLinking)
    {
        var c = stateMachine.GetComponent <Character>();

        c.lookDirection = Quaternion.Euler(
            activeLinking.GetValueOrDefault <Quaternion>("start_rotation").eulerAngles +
            Vector3.forward * Mathf.Lerp(-lookAroundAngle, lookAroundAngle,
                                         0.5f + (Mathf.Sin((Time.time - activeLinking.timeStarted) * rotationSpeed) / 2))
            );
    }
Beispiel #3
0
    public override void StateUpdate(StateMachine stateMachine, ActiveLinking activeLinking)
    {
        var rb = stateMachine.GetComponent <Rigidbody2D>();

        rb.AddForce((
                        activeLinking.GetValueOrDefault <Vector3>("push_position") - rb.transform.position
                        ).normalized * force, ForceMode2D.Impulse
                    );
        //Debug.Log("Added force");
    }
    public override void StateUpdate(StateMachine stateMachine, ActiveLinking activeLinking)
    {
        var lastFireDamageTime = activeLinking.GetValueOrDefault <float>("lastFireDamageTime");

        if (Time.time - lastFireDamageTime > fireDamageInterval)
        {
            var c = stateMachine.GetComponent <Character>();
            c.AddDamage(fireDmg);

            activeLinking.linkingProperties["lastFireDamageTime"] = Time.time;
        }
    }
Beispiel #5
0
        override public void StateUpdate(StateMachine stateMachine, ActiveLinking activeLinking)
        {
            NonPlayerCharacter npc = stateMachine.GetComponent <NonPlayerCharacter>();


            npc.character.currentSpeed = CharacterSpeed.FAST;

            if (npc.characterTarget != null && npc.characterTarget.transform != null)
            {
                if (activeLinking.GetValueOrDefault <bool>("force_pathfinding_update") ||
                    (npc.characterTarget.transform.position - npc.oldPositionTarget).magnitude > npc.pathToTargetUpdateDistance)
                {
                    npc.MoveToOrFollow(npc.characterTarget.transform.position);
                    npc.oldPositionTarget = npc.characterTarget.transform.position;

                    activeLinking.linkingProperties["force_pathfinding_update"] = false;
                }
            }
        }
 public override void Init(ActiveLinking activeLinking)
 {
     time = activeLinking.GetValueOrDefault <float>("time", time);
 }
 public override void Init(ActiveLinking activeLinking)
 {
     start = Time.time;
     childImage.fillAmount = 0;
     suspiciousTime        = activeLinking.GetValueOrDefault <float>("time");
 }
    override public void StateUpdate(StateMachine stateMachine, ActiveLinking activeLinking)
    {
        NonPlayerCharacter npc       = stateMachine.GetComponent <NonPlayerCharacter>();
        Character          character = stateMachine.GetComponent <Character>();


        Nav2DAgent navAgent = stateMachine.GetComponent <Nav2DAgent>();

        character.currentSpeed = CharacterSpeed.SLOW;


        if (!npc.nav2DAgent.isMoving && !npc.nav2DAgent.isWaitingForPath)
        {
            //Debug.Log("moving is false");

            var colliders = Physics2D.OverlapCircleAll(stateMachine.transform.position,
                                                       findClosestBuildingRadius, LayerMask.GetMask(buildingFindLayers));


            if (colliders.Count() <= 0)
            {
                return;
            }

            var buildingQueue = activeLinking.GetValueOrDefault <Queue <Queue <Vector2> > >("buildings");
            var cornerQueue   = activeLinking.GetValueOrDefault <Queue <Vector2> >("corners");

            if (cornerQueue.Count < 1)
            {
                if (buildingQueue.Count < 1)
                {
                    var closestColliders = colliders.OrderBy(
                        x => (x.transform.position - stateMachine.transform.position).magnitude
                        );

                    foreach (var collider in closestColliders)
                    {
                        var c = collider.GetComponentInParent <BuildingController>();

                        // if has building component and parent building is on building layer (walls are building that cannot be patrolled)
                        if (c == null || c.gameObject.layer != LayerMask.NameToLayer("Building"))
                        {
                            var l = LayerMask.GetMask("Building");
                            continue;
                        }

                        buildingQueue.Enqueue(new Queue <Vector2>(c.WorldSpaceCorners));
                    }
                }


                if (buildingQueue.Count < 1)
                {
                    return;
                }


                var corners = new List <Vector2>(buildingQueue.Dequeue())
                              .Where(x =>
                {
                    // only take corners that are not inside a active spell
                    var c = Physics2D.OverlapPointAll(x, LayerMask.GetMask(spellTargetLayers));
                    foreach (var collider in c)
                    {
                        var target = collider.GetComponent <MagicTargetBase>();
                        if (!target.spellDone)
                        {
                            return(false);
                        }
                    }

                    // and the corner is accessable;
                    return(navAgent.navGrid.CanBeReached(x));
                }).ToList();


                // patrolling around building can be clockwise or anticlockwise
                if (Random.value > 0.5)
                {
                    corners.Reverse();
                }


                var closesCornerIndex = corners.FindIndex(x =>
                                                          x == corners.MinBy(c => (c - (Vector2)stateMachine.transform.position).magnitude).First()
                                                          );


                // shift the values so that the closest corner is first
                for (var i = 0; i < corners.Count; i++)
                {
                    cornerQueue.Enqueue(corners[(closesCornerIndex + i) % corners.Count]);
                }
            }
            else
            {
                npc.MoveToOrFollow(
                    cornerQueue.Dequeue()
                    );
            }
        }
    }