public void Trigger(ActionUsingNode node, string eventName)
        {
            var    entity    = node.Entity;
            var    cmdTarget = entity.Get <CommandTarget>();
            Entity target;

            if (cmdTarget != null && cmdTarget.Target != null)
            {
                target = cmdTarget.Target;
            }
            else
            {
                target = node.Entity;
            }
            if (target == null)
            {
                return;
            }
            var sourceNode = entity.FindNode <CollidableNode>();
            var targetNode = target.FindNode <CollidableNode>();

            if (sourceNode == null || targetNode == null)
            {
                return;
            }
            CollisionExtensions.GenerateHitLocDir(sourceNode.Tr, targetNode.Tr, targetNode.Collider, out var hitPoint, out var dir);
            var ce = new CollisionEvent(entity, sourceNode, targetNode, hitPoint, dir);

            target.Post(ce);
            entity.Post(new PerformedCollisionEvent(sourceNode, targetNode, ce.HitPoint, ce.HitNormal));
            var stateEvent = new ActionStateEvent(node.Entity, ce.Target.Entity, ce.HitPoint, Quaternion.LookRotation(ce.HitNormal), StateEvent);

            node.Entity.Post(stateEvent);
        }
Beispiel #2
0
        public void OnActionSpawn(ActionStateEvent state)
        {
            var focus = state.Target;

            if (focus == null)
            {
                return;
            }
            var rect = World.Get <CharacterRectSystem>().GetEntityRect(focus.Entity);

            //if (focus == null || !focus.HasComponent<PlayerComponent>()) {
            //    return;
            //}
            if (rect == null)
            {
                return;
            }
            if (_matSource == null)
            {
                _matSource = GetComponent <Renderer>();
            }
            var spawn       = ItemPool.Spawn(StringConst.ParticleUI, false, false);
            var altParticle = spawn.GetComponent <UIAnimation>();

            if (altParticle == null)
            {
                Debug.LogErrorFormat("{0} tried to convert to UI animation for {1} targeting {2} at state {3} spawn {4}", name, state.State, focus.Get <LabelComponent>(), state, spawn.name);
                ItemPool.Despawn(spawn);
                return;
            }
            altParticle.transform.SetParent(rect.RectTr);
            altParticle.Play(_animationUi, _matSource != null ? _matSource.sharedMaterial : null);
            ItemPool.Despawn(gameObject);
        }
Beispiel #3
0
        public void PostAnimationEvent(ActionUsingNode node, string eventName)
        {
            if (Events.TryGetValue(eventName, out var animationEvent))
            {
                animationEvent.Trigger(node, eventName);
            }
            ActionStateEvents state = AnimationEvents.ToStateEvent(eventName);

            if (state == ActionStateEvents.Activate)
            {
                node.Entity.Post(new ActionStateEvent(node.Entity, node.Entity, node.Animator.GetEventPosition, node.Animator.GetEventRotation, ActionStateEvents.Activate));
            }
            if (state == ActionStateEvents.None)
            {
                return;
            }
            var stateEvent = new ActionStateEvent(node.Entity, Action.GetEntity(), node.Animator.GetEventPosition, node.Animator.GetEventRotation, state);

            if (Action.Fx != null)
            {
                Action.Fx.TriggerEvent(stateEvent);
            }
            for (int i = 0; i < ScriptedEvents.Count; i++)
            {
                if (ScriptedEvents[i].Event != state)
                {
                    continue;
                }
                PostAnimationEvent(stateEvent);
                break;
            }
        }
Beispiel #4
0
        public void Trigger(ActionUsingNode node, string eventName)
        {
            var     entity = node.Entity;
            Vector3 originPos;

            if (entity.Tags.Contain(EntityTags.Player))
            {
                originPos = PlayerInputSystem.GetLookTargetRay.origin;
            }
            else
            {
                var animData = entity.Find <AnimatorComponent>();
                originPos = animData?.Value?.GetEventPosition ?? (node.Tr != null ? node.Tr.position : Vector3.zero);
            }
            var            target       = node.ActionEvent.Target;
            var            actionEntity = node.ActionEvent.Action.GetEntity();
            var            ray          = new Ray(originPos, (target - originPos).normalized);
            CollisionEvent?ce           = CollisionCheckSystem.Raycast(actionEntity, ray, RayDistance, LimitToEnemy);

            if (ce == null && RaySize > 0.01f)
            {
                ce = CollisionCheckSystem.SphereCast(actionEntity, ray, RayDistance, RaySize, LimitToEnemy);
            }
            if (ce != null)
            {
                var stateEvent = new ActionStateEvent(node.Entity, ce.Value.Target.Entity, ce.Value.HitPoint, Quaternion.LookRotation(ce.Value.HitNormal), StateEvent);
                node.Entity.Post(stateEvent);
            }
        }
Beispiel #5
0
 public void HandleGlobal(ManagedArray <CollisionEvent> arg)
 {
     for (int i = 0; i < arg.Count; i++)
     {
         var msg = arg[i];
         if (msg.Hit < 0)
         {
             msg.Hit = 10;
             for (int h = 0; h < Handlers.Count; h++)
             {
                 msg.Hit = MathEx.Min(Handlers[h].CheckHit(msg), msg.Hit);
             }
         }
         if (msg.Hit <= 0)
         {
             continue;
         }
         var actionStateEvent = new ActionStateEvent(msg.Origin, msg.Target, msg.HitPoint, Quaternion.LookRotation(msg.HitNormal), ActionStateEvents.Impact);
         var impacts          = msg.Origin.Find <ActionImpacts>();
         if (impacts == null)
         {
             Debug.LogFormat("{0} had no impacts", msg.Origin.Name);
         }
         else
         {
             impacts.ProcessAction(msg, actionStateEvent, msg.Target);
         }
         msg.Origin.Post(actionStateEvent);
     }
 }
Beispiel #6
0
 public void ProcessAction(CollisionEvent collisionEvent, ActionStateEvent stateEvent, Entity owner, Entity target)
 {
     if (collisionEvent.Hit <= 0)
     {
         return;
     }
     target.Post(new HealEvent(collisionEvent.Target.FindStatValue(Stats.Power) * _damagePercent, owner, target, _targetVital));
 }
Beispiel #7
0
 public void Trigger(ActionStateEvent stateEvent)
 {
     if (!stateEvent.Origin.Tags.Contain(EntityTags.Player))
     {
         return;
     }
     FirstPersonCamera.ZoomForce(Force, Frames);
 }
Beispiel #8
0
 public void Trigger(ActionStateEvent stateEvent)
 {
     if (!stateEvent.Origin.Tags.Contain(EntityTags.Player))
     {
         return;
     }
     FirstPersonCamera.AddForce(stateEvent.Rotation.eulerAngles, IsRotation, Frames);
 }
Beispiel #9
0
        public void ProcessAction(CollisionEvent collisionEvent, ActionStateEvent stateEvent, Entity target)
        {
            var owner = this.GetEntity();

            for (int i = 0; i < Count; i++)
            {
                this[i].ProcessAction(collisionEvent, stateEvent, owner, target);
            }
        }
Beispiel #10
0
        public void Handle(ActionStateEvent arg)
        {
            var data = arg.Origin.Entity.Find <ActionFxComponent>()?.Fx;

            if (data != null)
            {
                data.TriggerEvent(arg);
            }
        }
Beispiel #11
0
        private void CheckObjectForListener(GameObject newObject, ActionStateEvent stateEvent)
        {
            var actionListener = newObject.GetComponent <IActionPrefab>();

            if (actionListener != null)
            {
                actionListener.OnActionSpawn(stateEvent);
            }
        }
Beispiel #12
0
        public void ProcessAction(CollisionEvent collisionEvent, ActionStateEvent stateEvent, Entity owner, Entity target)
        {
            if (collisionEvent.Hit <= 0)
            {
                return;
            }
            var stat = owner.FindStatValue(Stats.Power);

            target.Post(new DamageEvent(stat * _normalizedPercent * CollisionExtensions.GetHitMultiplier(collisionEvent.Hit, owner), owner, target, _damageType, _targetVital));
        }
Beispiel #13
0
 public void PostAnimationEvent(ActionStateEvent stateEvent)
 {
     for (int i = 0; i < ScriptedEvents.Count; i++)
     {
         if (ScriptedEvents[i].Event == stateEvent.State)
         {
             ScriptedEvents[i].Trigger(stateEvent);
         }
     }
 }
Beispiel #14
0
 public void TriggerEvent(ActionStateEvent actionEvent)
 {
     for (int i = 0; i < _actionData.Length; i++)
     {
         if (_actionData[i].Event == actionEvent.State || (_actionData[i].Event == ActionStateEvents.CollisionOrImpact && (actionEvent.State == ActionStateEvents.Impact || actionEvent.State == ActionStateEvents.Collision)))
         {
             if (_actionData[i].Sound != null)
             {
                 AudioPool.PlayClip(_actionData[i].Sound, actionEvent.Position, 0.5f);
             }
             if (_actionData[i].Particle.Animation == null)
             {
                 continue;
             }
             switch (_actionData[i].Event)
             {
             case ActionStateEvents.Collision:
             case ActionStateEvents.CollisionOrImpact:
             case ActionStateEvents.Impact:
                 if (actionEvent.Target != null)
                 {
                     var impactRenderer = actionEvent.Target.Get <ImpactRendererComponent>();
                     if (impactRenderer != null)
                     {
                         impactRenderer.PlayAnimation(_actionData[i].Particle.Animation, _actionData[i].Particle.Color);
                         continue;
                     }
                 }
                 break;
             }
             //var spawn = ItemPool.SpawnScenePrefab(_actionPrefabs[i].Prefab, actionEvent.Position, actionEvent.Rotation);
             //CheckObjectForListener(spawn, actionEvent);
             var particle = SpriteParticleSystem.PlayParticle(_actionData[i].Particle, actionEvent.Position, actionEvent.Rotation);
             if (!_actionData[i].Parent)
             {
                 continue;
             }
             TransformComponent tr = null;
             if (actionEvent.Target == null)
             {
                 tr = actionEvent.Origin.Tr;
             }
             else
             {
                 tr = actionEvent.Target.Tr;
             }
             if (tr != null)
             {
                 tr.SetChild(particle.Tr);
             }
         }
     }
 }
Beispiel #15
0
 public void ProcessAction(CollisionEvent collisionEvent, ActionStateEvent stateEvent, Entity owner, Entity target)
 {
     if (collisionEvent.Hit <= 0)
     {
         return;
     }
     if (Game.DiceRollSuccess(_chance))
     {
         target.Post(new DeathEvent(owner, target));
         target.Post(new CombatStatusUpdate("Lethal Hit!", Color.red));
     }
 }
Beispiel #16
0
 public void OnActionSpawn(ActionStateEvent actionEvent)
 {
     if (_parentAnimTr && actionEvent.Origin != null)
     {
         var parentTr = actionEvent.Origin.Tr;
         if (parentTr != null)
         {
             parentTr.SetChild(transform);
         }
     }
     TimeManager.StartUnscaled(WaitForEventComplete(actionEvent));
 }
 public void OnActionSpawn(ActionStateEvent actionEvent)
 {
     if (_parentAnimTr && actionEvent.Origin != null)
     {
         var parentTr = actionEvent.Origin.GetSelfOrParent <AnimTr>().Tr;
         if (parentTr != null)
         {
             transform.SetParent(parentTr);
         }
     }
     TimeManager.StartUnscaled(WaitForEventComplete(actionEvent));
 }
Beispiel #18
0
 public void ProcessAction(CollisionEvent collisionEvent, ActionStateEvent stateEvent, Entity owner, Entity target)
 {
     if (collisionEvent.Hit <= 0)
     {
         return;
     }
     if (_actionFx != null)
     {
         _actionFx.TriggerEvent(stateEvent);
     }
     target.AddObserver(this);
     target.Post(new DamageEvent(owner.Stats.GetValue(Stats.Power) * _damagePercent * CollisionExtensions.GetHitMultiplier(collisionEvent.Hit, owner), owner, target, _damageType, _targetVital));
 }
Beispiel #19
0
 private IEnumerator AdvanceSequence(ActionStateEvent stateEvent)
 {
     for (int i = 0; i < ScriptedEvents.Length; i++)
     {
         ScriptedEvents[i].Trigger(stateEvent);
         if (ScriptedEvents[i] is WaitEvent wait)
         {
             while (!wait.CanAdvance)
             {
                 yield return(null);
             }
         }
     }
 }
        public void HandleGlobal(CollisionEvent msg)
        {
            _eventLog.Add(msg);
            if (msg.Hit < 0)
            {
                msg.Hit = CollisionResult.Hit;
                for (int h = 0; h < _globalHandlers.Count; h++)
                {
                    msg.Hit = MathEx.Min(_globalHandlers[h].CheckHit(msg), msg.Hit);
                }
            }
            var blockDamage = msg.Target.Entity.Get <BlockDamage>();

            if (blockDamage != null)
            {
                for (int h = 0; h < blockDamage.CollisionHandlers.Count; h++)
                {
                    msg.Hit = MathEx.Min(blockDamage.CollisionHandlers[h](msg), msg.Hit);
                }
            }
            if (msg.Hit <= 0)
            {
                return;
            }
            var actionStateEvent = new ActionStateEvent(msg.Origin.Entity, msg.Target.Entity, msg.HitPoint,
                                                        msg.HitNormal == Vector3.zero ? Quaternion.identity :Quaternion.LookRotation(msg.HitNormal),
                                                        ActionStateEvents.Impact);

            msg.Source.PostAll(new ImpactEvent(msg, msg.Origin.Entity.FindNode <CharacterNode>(), msg.Target.Entity.FindNode <CharacterNode>
                                                   ()));
            msg.Origin.Post(actionStateEvent);
            if (!_collisionMessage)
            {
                return;
            }
            _collisionString.Clear();
            _collisionString.Append(msg.Origin.GetName());
            _collisionString.Append(" struck ");
            _collisionString.Append(msg.Target.GetName());
            MessageKit <UINotificationWindow.Msg> .post(Messages.MessageLog, new UINotificationWindow.Msg(
                                                            _collisionString.ToString(), "", Color.blue));

            if (msg.Target.Entity.HasComponent <DespawnOnCollision>())
            {
                msg.Target.Entity.Destroy();
            }
        }
Beispiel #21
0
 public void TriggerEvent(ActionStateEvent actionEvent)
 {
     for (int i = 0; i < _actionPrefabs.Length; i++)
     {
         if (_actionPrefabs[i].Event == actionEvent.State)
         {
             if (_actionPrefabs[i].Prefab != null)
             {
                 var spawn = ItemPool.SpawnScenePrefab(_actionPrefabs[i].Prefab, actionEvent.Position, actionEvent.Rotation);
                 CheckObjectForListener(spawn, actionEvent);
             }
             if (_actionPrefabs[i].Sound != null)
             {
                 AudioPool.PlayClip(_actionPrefabs[i].Sound, actionEvent.Position, 0.5f);
             }
         }
     }
 }
Beispiel #22
0
        private IEnumerator WaitForEventComplete(ActionStateEvent actionEvent)
        {
            var maxTime = TimeManager.Time + _maxTime;
            var minTime = TimeManager.Time + _minTime;

            while (true)
            {
                if (TimeManager.Time > maxTime || actionEvent.Origin != null && actionEvent.Origin.Entity.IsDead())
                {
                    break;
                }
                if (TimeManager.Time > minTime && actionEvent.State != ActionStateEvents.Activate)
                {
                    break;
                }
                yield return(null);
            }
            ItemPool.Despawn(_entity);
        }
Beispiel #23
0
 public void TriggerSpawn(SpawnOnEvent spawnEvent, ActionStateEvent arg)
 {
     if (arg.State == spawnEvent.EndEvent && spawnEvent.ActiveGameObject != null)
     {
         ItemPool.Despawn(spawnEvent.ActiveGameObject);
     }
     else if (arg.State == spawnEvent.StartEvent && spawnEvent.Prefab != null)
     {
         var animData = arg.Origin.Entity.Find <AnimatorComponent>();
         var spawnPos = animData?.Value?.GetEventPosition ?? (arg.Origin.Tr != null ? arg.Origin.Tr.position : Vector3.zero);
         var spawnRot = animData?.Value?.GetEventRotation ??
                        (arg.Origin.Tr != null ? arg.Origin.Tr.rotation : Quaternion.identity);
         spawnEvent.ActiveGameObject = ItemPool.Spawn(spawnEvent.Prefab, spawnPos, spawnRot);
         if (spawnEvent.EndEvent == ActionStateEvents.None)
         {
             spawnEvent.ActiveGameObject = null;
         }
     }
 }
Beispiel #24
0
 public void Trigger(ActionStateEvent stateEvent)
 {
     _timer.Restart();
 }
Beispiel #25
0
 public void Trigger(ActionStateEvent stateEvent)
 {
     TimeManager.StartUnscaled(AdvanceSequence(stateEvent));
 }
Beispiel #26
0
 public void ProcessImpact(CollisionEvent collisionEvent, ActionStateEvent stateEvent)
 {
 }