Example #1
0
        private void SetCooldownUI(ICooldownable cooldown)
        {
            float remainingCooldownTime = abilityCooldownDataHolder.GetDisplayCooldown(cooldown, out float maxCooldownDuration);

            cooldownOverlay.fillAmount = remainingCooldownTime / maxCooldownDuration;
            cooldownOverlayText.text   = Mathf.RoundToInt(remainingCooldownTime).ToString();
        }
Example #2
0
        private void CaseAttackStateNone()
        {
            Skill skillPrepared = null;

            foreach (Skill skill in skillList)
            {
                if (skill.IsSkillPrepared())
                {
                    skillPrepared = skill;
                    break;
                }
            }
            Skill skillPreparedExceptCooltime = null;

            if (skillPrepared == null)
            {
                foreach (Skill skill in skillList)
                {
                    ICooldownable cSkill = skill as ICooldownable;
                    if (cSkill != null && cSkill.IsSkillReadyExceptCooldown())
                    {
                        skillPreparedExceptCooltime = skill;
                        break;
                    }
                }
            }

            //if there exist any usable skill
            if (skillPrepared != null)
            {
                skillFocused = skillPrepared;
                moveState    = MoveState.idle;
                ICastable  cSkill = skillPrepared as ICastable;
                IReadiable rSkill = skillPrepared as IReadiable;
                if (cSkill != null && !cSkill.IsCastExempted)
                {
                    SetAttackState(AttackState.cast);
                }
                else if (rSkill != null && !rSkill.IsReadyExempted)
                {
                    SetAttackState(AttackState.ready);
                }
                else
                {
                    SetAttackState(AttackState.attack);
                }
            }
            else if (skillPreparedExceptCooltime != null)
            {
                SetMoveState(MoveState.idle);
                SetAttackState(AttackState.none);
            }
            else
            {
                SetMoveState(MoveState.walk);
                SetAttackState(AttackState.none);
            }
        }
Example #3
0
        public bool IsOnCooldown(ICooldownable cooldownable)
        {
            //We consider the item being on cooldown if the global cooldown is active.
            if (IsGlobalCooldownActive)
            {
                return(true);
            }

            return(cooldownData.ContainsKey(cooldownable));
        }
Example #4
0
 public void DoCombatTick()
 {
     foreach (Skill skill in skillList)
     {
         ICooldownable cSkill = skill as ICooldownable;
         if (cSkill != null && !cSkill.IsCooldownCompleted())
         {
             cSkill.Cooldown(Action.SimpleAction(0));
         }
     }
     DetermineState();
 }
Example #5
0
        public static void FinishAbilityCooldownTimer(this ICooldownable timer, IActor actor)
        {
            var actorPlayer = actor.Abilities.FirstOrDefault(a => a is AbilityActorPlayer) as AbilityActorPlayer;

            if (actorPlayer == null || !actorPlayer.actorToUI)
            {
                return;
            }

            if (!(timer is IBindable))
            {
                return;
            }

            var bindable = (IBindable)timer;

            var dstManager = World.DefaultGameObjectInjectionWorld.EntityManager;

            var uiReceiverList = actorPlayer.UIReceiverList;

            var abilityPlayerInput = actor.Abilities.FirstOrDefault(a => a is AbilityPlayerInput) as AbilityPlayerInput;

            if (abilityPlayerInput == null)
            {
                return;
            }

            var currentBinding =
                abilityPlayerInput.customBindings.FirstOrDefault(b => b.index == bindable.BindingIndex);

            if (!currentBinding.Equals(new CustomBinding()) && currentBinding.actions.FirstOrDefault(a =>
                                                                                                     a is IAimable aimable && aimable.AimingAvailable && aimable.DeactivateAimingOnCooldown) != null)
            {
                uiReceiverList.ForEach(r => ((UIReceiver)r).SetCustomButtonOnCooldown(bindable.BindingIndex, false));
            }

            if (dstManager.HasComponent <BindedActionsCooldownData>(actor.ActorEntity))
            {
                var existingComponent = dstManager.GetComponentData <BindedActionsCooldownData>(actor.ActorEntity);

                existingComponent.ReadyToUseBindingIndexes.Add(bindable.BindingIndex);
                dstManager.SetComponentData(actor.ActorEntity, existingComponent);
                return;
            }

            dstManager.AddComponentData(actor.ActorEntity,
                                        new BindedActionsCooldownData
            {
                ReadyToUseBindingIndexes = new FixedList32 <int> {
                    bindable.BindingIndex
                }
            });
        }
Example #6
0
        private IEnumerator CooldownUiCoroutine(ICooldownable cooldown)
        {
            //Update the cooldown UI whilst our item is on cooldown.
            while (abilityCooldownDataHolder.IsOnCooldown(cooldown))
            {
                SetCooldownUI(cooldown);
                yield return(null);
            }

            ClearCooldownUI();

            cooldownUICoroutine = null;
        }
Example #7
0
        public void PutOnCooldown(ICooldownable cooldownable)
        {
            //Make sure that the item isn't already on cooldown.
            if (cooldownData.ContainsKey(cooldownable))
            {
                return;
            }

            //Add it to the list of all cooldowns.
            cooldownData.Add(cooldownable, cooldownable.MaxCooldownDuration);

            //Reset the global cooldown.
            currentGlobalCooldown = GlobalCooldown;

            //Alert any listeners that we have started a cooldown.
            onCooldownStarted.Raise();
        }
Example #8
0
 public float GetDisplayCooldown(ICooldownable cooldownable, out float maxCooldownDuration)
 {
     //Get the current cooldown value and max cooldown value.
     if (cooldownData.TryGetValue(cooldownable, out float remainingCooldownTime))
     {
         //The item is on cooldown.
         maxCooldownDuration = cooldownable.MaxCooldownDuration;
         return(remainingCooldownTime);
     }
     else if (IsGlobalCooldownActive)
     {
         //The item isn't on cooldown so we use the global cooldown.
         maxCooldownDuration = GlobalCooldown;
         return(currentGlobalCooldown);
     }
     else
     {
         //The item isn't on cooldown and neither is the global cooldown.
         maxCooldownDuration = 0f;
         return(0f);
     }
 }
Example #9
0
        public void PrintDetail()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("\n=======================\n        ");
            sb.Append(this.ToString());
            sb.Append("\n=======================\n");
            sb.Append("\nSkill focused : ");
            if (skillFocused != null)
            {
                sb.Append(skillFocused.skillCode);
            }
            sb.Append("\nAttack state : ");
            sb.Append(attackState);
            sb.Append("\nMove state : ");
            sb.Append(moveState);
            for (int i = 0; i < skillList.Count; i++)
            {
                sb.Append("\n--Skill");
                sb.Append(i);
                sb.Append("--");
                sb.Append("\nSkill name : ");
                sb.Append(skillList[i].skillCode);
                sb.Append("\nSkill Cooldown : ");
                ICooldownable cSkill = skillList[i] as ICooldownable;
                if (cSkill != null)
                {
                    sb.Append(cSkill.CooldownTime + "/" + cSkill.CooldownTimeNeeded);
                    if (cSkill.IsSkillReadyExceptCooldown())
                    {
                        sb.Append(": Skill Ready Except Cooldown");
                    }
                }
                else
                {
                    sb.Append("Not Cooldownable");
                }
                sb.Append("\nSkill Ready : ");
                IReadiable rSkill = skillList[i] as IReadiable;
                if (rSkill != null)
                {
                    sb.Append(rSkill.ReadyTime + "/" + rSkill.ReadyTimeNeeded);
                }
                else
                {
                    sb.Append("Not Readiable");
                }
                sb.Append("\nSkill Delay : ");
                IDelayable dSkill = skillList[i] as IDelayable;
                if (dSkill != null)
                {
                    sb.Append(dSkill.DelayTime + "/" + dSkill.DelayTimeNeeded);
                }
                else
                {
                    sb.Append("Not Delayable");
                }
            }
            sb.Append("\n=======================");
            Console.WriteLine(sb);
        }