Exemple #1
0
        public async Task <DoAfterStatus> DoAfter(DoAfterEventArgs eventArgs)
        {
            // Setup
            var doAfter = new DoAfter(eventArgs);
            // Caller's gonna be responsible for this I guess
            var doAfterComponent = eventArgs.User.GetComponent <DoAfterComponent>();

            doAfterComponent.Add(doAfter);
            IDamageableComponent?damageableComponent = null;

            // TODO: If the component's deleted this may not get unsubscribed?
            if (eventArgs.BreakOnDamage && eventArgs.User.TryGetComponent(out damageableComponent))
            {
                damageableComponent.HealthChangedEvent += doAfter.HandleDamage;
            }

            await doAfter.AsTask;

            if (damageableComponent != null)
            {
                damageableComponent.HealthChangedEvent -= doAfter.HandleDamage;
            }

            return(doAfter.Status);
        }
Exemple #2
0
        public DoAfter(DoAfterEventArgs eventArgs)
        {
            EventArgs = eventArgs;
            StartTime = IoCManager.Resolve <IGameTiming>().CurTime;

            if (eventArgs.BreakOnUserMove)
            {
                UserGrid = eventArgs.User.Transform.Coordinates;
            }

            if (eventArgs.BreakOnTargetMove)
            {
                // Target should never be null if the bool is set.
                TargetGrid = eventArgs.Target !.Transform.Coordinates;
            }

            // For this we need to stay on the same hand slot and need the same item in that hand slot
            // (or if there is no item there we need to keep it free).
            if (eventArgs.NeedHand && eventArgs.User.TryGetComponent(out HandsComponent? handsComponent))
            {
                _activeHand = handsComponent.ActiveHand;
                _activeItem = handsComponent.GetActiveHand;
            }

            Tcs    = new TaskCompletionSource <DoAfterStatus>();
            AsTask = Tcs.Task;
        }
        public async Task <DoAfterStatus> DoAfter(DoAfterEventArgs eventArgs)
        {
            // Setup
            var doAfter = new DoAfter(eventArgs);
            // Caller's gonna be responsible for this I guess
            var doAfterComponent = eventArgs.User.GetComponent <DoAfterComponent>();

            doAfterComponent.Add(doAfter);

            await doAfter.AsTask;

            return(doAfter.Status);
        }