예제 #1
0
        protected override void Apply(GameObject caster, GameObject target)
        {
            if (target.IsImmovable() || target.GetComponent <BehavioursComponent>().IsImmobilized)
            {
                TriggerFinished();
                return;
            }

            var direction = (target.transform.position - OriginPosition()).normalized;

            this.destination = this.boardNavigator.WithinLine(
                target.transform.position, direction, this.data.Distance)
                               .Where(cell => !cell.IsReserved)
                               .OrderByDescending(cell => (target.transform.position - cell.transform.position).sqrMagnitude)
                               .FirstOrDefault();

            if (this.destination == null)
            {
                TriggerFinished();
                return;
            }

            this.destination.IsReserved = true;

            this.mover                           = Mover.Factory(this.data.Mover);
            this.mover.Finished                 += OnMoverFinished;
            this.mover.CollidingWithEntity      += OnMoverCollidingWithEntity;
            this.mover.CollidingWithEnvironment += OnMoverCollidingWithEnvironment;
            this.mover.Start(target, this.destination.transform.position);
        }
예제 #2
0
        protected void Launch(GameObject caster, object target, Vector3 origin, Vector3 destination)
        {
            var missile = GetMissile();

            AssignEffects(missile);

            missile.Mover = Mover.Factory(this.Data.Mover);

            if (!this.Data.FinishImmediately)
            {
                missile.Finished += OnMissileFinished;
            }

            missile.FlyHeight                  = this.Data.MissileFlyHeight;
            missile.StopOnEntityCollision      = this.Data.StopOnEntityCollision;
            missile.StopOnEnvironmentCollision = this.Data.StopOnEnvironmentCollision;
            missile.gameObject.SetActive(false);
            missile.transform.position = origin;
            missile.Launch(caster, target, destination);
            missile.gameObject.SetActive(true);

            if (this.Data.FinishImmediately)
            {
                TriggerFinished();
            }
        }
예제 #3
0
        private void OnHookMoverFinished()
        {
            var actor = Caster.GetComponent <ActorComponent>();

            actor.PlayAnimation("hook_end");

            this.hookMover.Finished -= OnHookMoverFinished;

            var destination = GetNearestFreeCell();

            if (destination == null || this.target.IsImmovable())
            {
                Stop();
                return;
            }

            var unitComponent = this.target.GetComponent <UnitComponent>();

            unitComponent.Flags |= UnitFlags.Airborne;
            unitComponent.Flags |= UnitFlags.MovingViaScript;

            this.targetMover           = Mover.Factory(new MoverData(MoverType.Parabolic, 15, 0, 2, false));
            this.targetMover.Finished += OnTargetMoverFinished;
            this.targetMover.Start(this.target, destination.transform.position);

            this.hookMover = Mover.Factory(new MoverData(MoverType.Parabolic, 15, 0, 2, false));
            this.hookMover.Start(
                this.hook, actor.Model.GetAttachmentPoint(AttachmentPoint.RightHand).transform.position);
        }
예제 #4
0
        protected override void Apply(GameObject caster, GameObject target)
        {
            if (target.GetComponent <UnitComponent>().IsMovingViaScript)
            {
                TriggerFinished();
                return;
            }

            this.target = target;

            var actor = Caster.GetComponent <ActorComponent>();

            actor.PlayAnimation("hook_start");

            Timer.Instance.Wait(0.33f, () =>
            {
                var rightHand = actor.Model.GetAttachmentPoint(AttachmentPoint.RightHand);

                this.hook = Object.Instantiate(Resources.Load <GameObject>(this.data.Hook));
                this.hook.transform.position = rightHand.transform.position;

                this.beam = Object.Instantiate(Resources.Load <Lightning>(this.data.Beam));
                this.beam.Initialize(rightHand, this.hook.transform);

                this.hookMover           = Mover.Factory(new MoverData(MoverType.Linear, 20, 0, 0, true));
                this.hookMover.Finished += OnHookMoverFinished;
                this.hookMover.Start(this.hook,
                                     this.target.GetComponent <ActorComponent>().Model
                                     .GetAttachmentPoint(AttachmentPoint.Chest).transform.position);
            });
        }
예제 #5
0
        public override Missile ToEntity(MissileData data)
        {
            var prefab = Resources.Load <GameObject>(data.Prefab);

            if (prefab == null)
            {
                Debug.LogError("Can't find prefab " + data.Prefab);
                return(null);
            }

            var missile = new GameObject(prefab.name).AddComponent <Missile>();

            missile.transform.SetParent(Parent.transform);
            missile.gameObject.AddComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Kinematic;

            var collider = missile.gameObject.AddComponent <CircleCollider2D>();

            collider.radius    = 0.1f;
            collider.isTrigger = true;

            missile.Graphics     = Object.Instantiate(prefab, Vector3.zero, Quaternion.identity, missile.transform);
            missile.name         = data.Name;
            missile.ImpactPrefab = data.ImpactPrefab;
            missile.Mover        = Mover.Factory(new MoverData(MoverType.Linear, 5.0f, 0, 0, false));

            return(missile);
        }
예제 #6
0
        protected override void Apply(GameObject caster, Vector3 target)
        {
            caster.GetComponent <ActorComponent>().PlayAnimation(this.data.StartAnimation);

            if (this.data.IsAirborne)
            {
                caster.GetComponent <UnitComponent>().Flags |= UnitFlags.Airborne;
            }

            this.mover                           = Mover.Factory(this.data.Mover);
            this.mover.Finished                 += OnMoverFinished;
            this.mover.CollidingWithEntity      += OnCollidingWithEntity;
            this.mover.CollidingWithEnvironment += OnCollidingWithEnvironment;
            this.mover.Start(caster, target);
        }
예제 #7
0
        protected override void Apply(GameObject caster, Vector3 target)
        {
            var casterBehaviours = caster.GetComponent <BehavioursComponent>();

            if (casterBehaviours.IsImmobilized || casterBehaviours.IsUncontrollable)
            {
                TriggerFinished();
                return;
            }

            this.destination = BoardNavigator.Instance.WithinCircle(target, 0).FirstOrDefault();

            if (this.destination == null)
            {
                TriggerFinished();
                return;
            }

            var path = this.pathfinder.FindPath(caster, this.destination.transform.position, true);

            var nearest = path.Count > 0 ? path.Last() : caster.transform.position;

            if ((nearest - this.destination.transform.position).magnitude <= 2.3f)
            {
                path.Add(this.destination.transform.position);
            }

            if (path.Count == 0)
            {
                TriggerFinished();
                return;
            }

            this.queue = new Queue <Vector3>(path.Take(GetDistance(caster) + 1));

            this.actor = caster.GetComponent <ActorComponent>();
            this.actor.PlayAnimation(this.data.Animation);

            caster.GetComponent <HealthComponent>().Died += OnDeath;

            this.behaviours = casterBehaviours;
            this.behaviours.BehaviourApplied += OnBehaviourApplied;

            this.mover           = Mover.Factory(new MoverData(MoverType.Linear, GetSpeed(caster), 0, 0, false));
            this.mover.Finished += OnMoverFinished;

            OnMoverFinished();
        }
예제 #8
0
        protected void Launch(GameObject caster, object target, Vector3 origin, Vector3 destination)
        {
            var missile = this.missileRepository.FindOrFail(this.data.MissileId);

            AssignEffects(missile);

            missile.Mover                      = Mover.Factory(this.data.Mover);
            missile.Mover.Finished            += OnMoverFinished;
            missile.EnterCell                 += OnMissileEnterCell;
            missile.FlyHeight                  = this.data.MissileFlyHeight;
            missile.StopOnEntityCollision      = this.data.StopOnEntityCollision;
            missile.StopOnEnvironmentCollision = this.data.StopOnEnvironmentCollision;
            missile.gameObject.SetActive(false);
            missile.transform.position = origin;
            missile.Launch(caster, target, destination);
            missile.gameObject.SetActive(true);
        }
예제 #9
0
        protected override void Apply(GameObject caster, GameObject target)
        {
            if (target.GetComponent <BehavioursComponent>().IsImmobilized ||
                target.GetComponent <UnitComponent>().IsMovingViaScript ||
                target.GetComponent <UnitComponent>().IsImmovable)
            {
                TriggerFinished();
                return;
            }

            this.destination = GetDestination(caster, target);

            if (this.destination == null)
            {
                TriggerFinished();
                return;
            }

            this.path = new Queue <Vector3>(this.pathfinder.FindPath(target, this.destination.transform.position, true));

            if (this.path.Count == 0)
            {
                TriggerFinished();
                return;
            }

            this.destination.IsReserved = true;

            this.actor = target.GetComponent <ActorComponent>();
            this.actor.PlayAnimation(this.data.Animation);

            this.behaviours = target.GetComponent <BehavioursComponent>();
            this.behaviours.BehaviourApplied += OnBehaviourApplied;

            this.mover           = Mover.Factory(new MoverData(MoverType.Linear, this.data.Speed, 0, 0, false));
            this.mover.Finished += OnMoverFinished;

            this.actor.GetComponent <UnitComponent>().Flags |= UnitFlags.MovingViaScript;

            OnMoverFinished();
        }