Exemplo n.º 1
0
 private void Jump(CharacterMovementComponent movementComponent, Data data)
 {
     if (data.Character.IsGrounded)
     {
         data.Character.Jump();
         data.ModelEntityTransform.Entity.BroadcastEvent <IAnimationEvents>().SetGrounded(false);
         gameEventSystem.Log(new JumpEvent(movementComponent.Entity));
     }
 }
        public override void Update(GameTime time)
        {
            foreach (var kvp in ComponentDatas)
            {
                var component = kvp.Key;

                if (!component.CanExecute)
                {
                    continue;
                }

                if (component.State == CharacterAttackComponent.AttackState.Primary)
                {
                    if (component.PrimaryHandler != null)
                    {
                        scriptSystem.AddTask(async() => await component.PrimaryHandler.ExecuteAttack(
                                                 component.Entity,
                                                 (bool canExecute) => component.CanExecute = canExecute,
                                                 Services));
                    }

                    gameEventSystem.Log(new PrimaryAttackEvent(component.Entity));
                }
                else if (component.State == CharacterAttackComponent.AttackState.Secondary)
                {
                    if (component.SecondaryHandler != null)
                    {
                        scriptSystem.AddTask(async() => await component.SecondaryHandler.ExecuteAttack(
                                                 component.Entity,
                                                 (bool canExecute) => component.CanExecute = canExecute,
                                                 Services));
                    }

                    gameEventSystem.Log(new SecondaryAttackEvent(component.Entity));
                }

                component.State = CharacterAttackComponent.AttackState.None;
            }
        }
        public override void Update(GameTime time)
        {
            if (gameEventSystem == null)
            {
                gameEventSystem = GameEventSystem.GetFromServices(Services);
            }

            foreach (var kvp in ComponentDatas)
            {
                var punchComponent = kvp.Key;
                var data           = kvp.Value;

                if (punchComponent.ShouldPunch)
                {
                    // animate punch
                    punchComponent.Entity.BroadcastEvent <IAnimationEvents>().Punch();
                    data.WaitTime = TimeSpan.FromSeconds(0.2);
                }

                if (data.WaitTime.HasValue)
                {
                    if (data.WaitTime.Value > new TimeSpan())
                    {
                        data.WaitTime -= time.Elapsed;
                    }
                    else
                    {
                        gameEventSystem.Log(new PunchEvent(punchComponent.Entity));
                        foreach (var collision in punchComponent.InteractionSource.Collisions)
                        {
                            var otherEntity = collision.ColliderA.Entity.Get <CharacterInteractionSource>() != null
                                ? collision.ColliderB.Entity
                                : collision.ColliderA.Entity;
                            if (otherEntity.Name == "PlayerCharacter")
                            {
                                otherEntity.BroadcastEvent <IDamageEvents>().DealDamage(1);
                            }
                        }
                        data.WaitTime = null;
                    }
                }

                // reset state
                punchComponent.ShouldPunch = false;
            }
        }
        public override void Update(GameTime time)
        {
            if (gameEventSystem == null)
            {
                gameEventSystem = GameEventSystem.GetFromServices(Services);
                gameEventSystem.RegisterListener(new CharacterHealthListener());
            }

            foreach (var kvp in ComponentDatas)
            {
                var stats = kvp.Key;

                var oldHealth = stats.Health;
                var newHealth = MathUtil.Clamp(oldHealth - stats.DamageDealt + stats.AmountHealed, 0, stats.MaxHealth);

                if (oldHealth != newHealth)
                {
                    stats.Health = newHealth;
                    gameEventSystem.Log(new HealthChangeEvent(stats.Entity, oldHealth, newHealth));
                }

                ResetStatsDiff(stats);
            }
        }