Example #1
0
 public void AddLoopable(Loopable l)
 {
     if (l != null)
     {
         loopables.Add(l);
     }
 }
Example #2
0
        public virtual void OnPreFinish(Character character)
        {
            for (int i = 0; i < characterAndBuff.Count; i++)
            {
                Character character_ = characterAndBuff[i].Element2;
                Modifier  buff       = characterAndBuff[i].Element1;
                character_.RemoveModifierAndChangeState(buff);
            }

            for (int kIndex = 0; kIndex < vfxs.Count; kIndex++)
            {
                vfxs[kIndex].Interrupt();
            }

            int count = loopableElements.Count;

            for (int i = 0; i < count; i++)
            {
                Loopable l = loopableElements[i];
                if (l is Vfx)
                {
                    ((Vfx)l).Interrupt();
                }
            }
//
//			for (int kIndex = 0; kIndex < loopableElements.Count; kIndex++) {
//				loopableElements[kIndex].Interrupt();
//			}

            DestroyProjectiles();
        }
Example #3
0
    public void OnCollisionStay2D(Collision2D collision)
    {
        if (ScoreManager.instance.damagedFences <= 0)
        {
            return;
        }

        if (Time.time > tickTimer)
        {
            Loopable loopable = collision.collider.GetComponent <Loopable>();
            if (loopable != null && !loopable.expired)
            {
                _currHealth--;

                if (_currHealth <= 0)
                {
                    liveCar.SetActive(false);
                    brokenCar.SetActive(true);
                    ScoreManager.instance.GameOver();
                }
                else
                {
                    liveCar.SetActive(true);
                    brokenCar.SetActive(false);
                }
            }
            tickTimer = Time.time + tick;
        }
    }
Example #4
0
 public void LateUpdate(float dt)
 {
     for (int kIndex = loopableElements.Count - 1; kIndex >= 0; kIndex--)
     {
         Loopable loopableElement = loopableElements[kIndex];
         loopableElement.LateUpdate(dt);
     }
     OnLateUpdate(dt);
 }
Example #5
0
 public void OnCollisionStay2D(Collision2D collision)
 {
     if (Time.time > tickTimer)
     {
         Loopable loopable = collision.collider.GetComponent <Loopable>();
         if (loopable != null && !loopable.expired)
         {
             ScoreManager.instance.AddMessage("-1", Color.red, new Vector3(.5f, 0, 0), transform);
             _currHealth--;
             if (_currHealth <= 0)
             {
                 KillFence();
             }
         }
         tickTimer = Time.time + tick;
     }
 }
Example #6
0
    private void CheckLoopables()
    {
        loopManager.targets.Clear();

        foreach (Loopable loopable in containedLoopables.Keys)
        {
            loopable.isActive = false;
        }
        containedLoopables.Clear();

        foreach (LoopSegment segment in segments)
        {
            Vector2      midPoint = (segment.start + segment.end) / 2;
            Vector2      dir      = LoopUtils.CrossProduct(segment.start, segment.end, winding);
            RaycastHit2D hit      = Physics2D.Raycast(midPoint, dir, maxLoopRadius, loopables);

            if (hit.collider != null)
            {
                Debug.DrawLine(midPoint, hit.point, Color.green);
                Loopable hitLoopable = hit.collider.GetComponent <Loopable>();
                if (containedLoopables.ContainsKey(hitLoopable))
                {
                    containedLoopables[hitLoopable]++;
                }
                else
                {
                    containedLoopables.Add(hitLoopable, 1);
                }
            }
            else
            {
                Debug.DrawLine(midPoint, midPoint + dir.normalized * maxLoopRadius, Color.red);
            }
        }

        foreach (Loopable loopable in containedLoopables.Keys)
        {
            float currentRatio = containedLoopables[loopable] / segments.Count;
            if (currentRatio >= hitThreshold)
            {
                loopManager.targets.Add(loopable);
                loopable.onLoopActivate();
            }
        }
    }
Example #7
0
    // Update is called once per frame
    void Update()
    {
        flash.SetActive(Input.GetMouseButton(0) && loopManager.targets.Count > 0);



        if (Time.time > nextShotTimer && Input.GetMouseButton(0))
        {
            nextShotTimer = Time.time + (60f / rpm);
            if (loopManager.targets.Count > 0)
            {
                Loopable target = loopManager.targets[0];

                if (audioSource != null)
                {
                    audioSource.pitch = Random.Range(.9f, 1.1f);
                    audioSource.PlayOneShot(audioSource.clip);
                }

                var     offset      = 0f;
                Vector2 pos         = new Vector2(target.transform.position.x, target.transform.position.y);
                bool    facingRight = pos.x >= transform.position.x;
                Vector2 direction   = (pos - (Vector2)transform.position) * (facingRight ? 1 : -1);
                direction.Normalize();
                float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
                angle = Mathf.Clamp(angle, -50, 50);

                transform.localScale = new Vector3(facingRight ? 1 : -1, 1, 1);

                top.transform.rotation = Quaternion.Euler(Vector3.forward * (angle + offset));

                // foreach (Loopable target in possibleTargets)
                {
                    Projectile instance = GameObject.Instantiate(projectilePrefab);
                    instance.Launch(
                        (target.transform.position - transform.position).normalized,
                        transform.position,
                        target.transform.position);
                    target.OnHit();
                }
            }
        }
    }
Example #8
0
        internal void InterruptLoopable <T>()
        {
            List <Loopable> removedLoopables = new List <Loopable>();

            for (int kIndex = 0; kIndex < loopableElements.Count; kIndex++)
            {
                Loopable loopable = loopableElements[kIndex];
                if (loopable is T)
                {
                    removedLoopables.Add(loopable);
                    loopable.Interrupt();
                }
            }

            for (int i = 0; i < removedLoopables.Count; i++)
            {
                RemoveLoopable(removedLoopables[i]);
            }
        }
Example #9
0
        public virtual void Update(float dt)
        {
            if (isInterrupted)
            {
                return;
            }
            if (pauseDuration > 0)
            {
                pauseDuration -= dt;
                pauseDuration  = Mathf.Max(0, pauseDuration);
                if (pauseDuration > 0)
                {
                    return;
                }
            }

            elapsed      += dt;
            phaseElapsed += dt;
            TriggerEventFrame(dt);
//			DLog.LogError(this.GetType()+" "+BattleUtils.frame+" "+BattleUtils.time);

            for (int kIndex = loopableElements.Count - 1; kIndex >= 0; kIndex--)
            {
                Loopable loopableElement = loopableElements[kIndex];
                if (loopableElement.IsFinished())
                {
                    loopableElements.RemoveAt(kIndex);
                    if (loopableElement is Jump)
                    {
                        jumps.Remove((Jump)loopableElement);
                    }
                    else if (loopableElement is Vfxs.Vfx)
                    {
                        vfxs.Remove((Vfxs.Vfx)loopableElement);
                    }
                    continue;
                }

                loopableElement.Update(dt);
            }

            OnUpdate(dt);
        }
Example #10
0
        protected void Trigger(BaseEvent be, TemplateArgs args = null)
        {
            try {
                if (!IsEventTriggerable(be))
                {
                    return;
                }

                BaseAction ba         = be.ShowAction();
                ActionType actionType = ba.ShowActionType();
                switch (actionType)
                {
                case ActionType.CastProjectile:
                case ActionType.Impact:
                    List <ProjectileComponent> justLaunchedProjectiles = LaunchProjectiles(be);
                    projectiles.AddRange(justLaunchedProjectiles);
                    break;

                default:
                    Loopable loopable = loopableElementFactory.Produce(
                        caster, this, config.ShowSkillId(), be, config.ShowSkillCastingSource(), args
                        );
                    loopableElements.Insert(0, loopable);
                    if (actionType == ActionType.Jump)
                    {
                        jumps.Add((Jump)loopable);
                    }
                    OnLoopableElementProduction(be, loopable);
                    break;
                }
            }
            catch (Exception e) {
                Exception ex = new Exception("Error trigger event of skill id " + config.ShowSkillId(), e);
                DLog.LogException(ex);
            }
        }
Example #11
0
        public void Update(float dt)
        {
            if (spawnPosition.Equals(new Vector3(-1, -1, -1)))
            {
                spawnPosition = Position();
            }
            foreach (SkillCastingRequirement skillCastingRequirement in skillCastingRequirements.Values)
            {
                skillCastingRequirement.Update(dt);
            }
//			DLog.LogError(this.GetType()+" "+BattleUtils.frame+" "+BattleUtils.time);
            CleanupSkillsThatAreFinished();
            for (int i = ongoingSkills.Count - 1; i >= 0; i--)
            {
                Skill skill = ongoingSkills[i];
                skill.Update(dt);
            }

            foreach (SkillId skillId in queuedInterruptSkills)
            {
                InterruptSkill(skillId);
            }
            queuedInterruptSkills.Clear();

            if (isUnderChanneling && channelingSkill.IsChannelingFinish())
            {
                isUnderChanneling = false;
            }

            for (int i = ongoingModifiers.Count - 1; i >= 0; i--)
            {
                Modifier modifier = ongoingModifiers[i];
                modifier.Update(dt);
                if (modifier.IsFinish())
                {
                    ongoingModifiers.RemoveAt(i);
                    modifier.OnDetach(this);
                    NotifyModifierDetachment(modifier);
                }
            }
            List <Modifier> ongoingModifiersCauseStateChange = new List <Modifier>();

            foreach (Modifier modifier in ongoingModifiers)
            {
                if (modifier.IsBuff())
                {
                    continue;
                }
                if (IsDebuffWithoutStateChangeContains(modifier.Type()))
                {
                    continue;
                }

                ongoingModifiersCauseStateChange.Add(modifier);
            }
            if (ongoingModifiersCauseStateChange.Count < 1 && State() != CharacterState.Default)
            {
                ChangeToState(CharacterState.Default);
            }

            for (int i = loopables.Count - 1; i >= 0; i--)
            {
                Loopable loopable = loopables[i];
                loopable.Update(dt);
                if (loopable.IsFinished())
                {
                    loopables.RemoveAt(i);
                }
            }
        }
Example #12
0
 protected virtual void OnLoopableElementProduction(BaseEvent be, Loopable loopable)
 {
 }
Example #13
0
 protected bool RemoveLoopable(Loopable l)
 {
     return(loopableElements.Remove(l));
 }
Example #14
0
        public Loopable Produce(Character caster, Skill skill, SkillId skillId, BaseEvent baseEvent,
                                SkillCastingSource skillCastingSource, TemplateArgs args)
        {
            BaseAction ba         = baseEvent.ShowAction();
            ActionType actionType = ba.ShowActionType();
            Loopable   loopable   = null;

            switch (actionType)
            {
            case ActionType.Camera:
                CameraAction        ca     = (CameraAction)ba;
                CameraAction.BaseFx bf     = ca.fx;
                CameraAction.FxType fxType = bf.ShowFxType();
                switch (fxType)
                {
                case CameraAction.FxType.Shake:
                    CameraAction.ShakeFx sf = (CameraAction.ShakeFx)bf;
                    loopable = new CameraShake(environment, sf);
                    break;

                case CameraAction.FxType.Fade:
                    loopable = new CameraFade(environment, baseEvent);
                    break;

                case CameraAction.FxType.CinematicZoomToSelf:
                    loopable = new CameraCinematicZoomToSelf(environment, baseEvent, caster);
                    break;

                case CameraAction.FxType.SlowMotion:
                    loopable = new CameraSlowMotion(environment, baseEvent);
                    break;

                case CameraAction.FxType.AddTarget:
                    loopable = new CameraAddTarget(environment, baseEvent, caster);
                    break;

                default:
                    throw new Exception("Missing logic to handle camera fx of type " + fxType);
                }
                break;

            case ActionType.Dash:
                Dash dash = new Dash(baseEvent, caster, skill.IgnoreMinSpeedOnAirForDashes(), skill, environment);
                loopable = dash;
                break;

            case ActionType.Jump:
                bool jumpOverDistance = true;
                if (args != null)
                {
                    bool found;
                    jumpOverDistance = args.TryGetEntry <bool>(TemplateArgsName.JumpSkill_JumpOverDistance, out found);
                    if (!found)
                    {
                        jumpOverDistance = true;
                    }
                }
                Jump jump = new Jump(baseEvent, caster, skill, environment, jumpOverDistance);
                loopable = jump;
                break;

            case ActionType.Vfx:
                Vfxs.Vfx vfx = new Vfxs.Vfx(
                    baseEvent, environment, caster, skillCastingSource, skill, args
                    );
                loopable = vfx;
                break;

            case ActionType.Modifier:
                ModifierAction     ma       = (ModifierAction)ba;
                BaseModifierConfig bmc      = ma.modifierConfig;
                ModifierInfo       mi       = modifierInfoFactory.CreateFrom(skill, bmc, environment);
                EntityReference    er       = caster.GameObject().GetComponent <EntityReference>();
                Modifier           modifier = DamageSystem.Instance.CreateModifier(
                    mi, er.Entity, er.Entity, caster.Position(),
                    caster.Position(), skill, skillId, 0
                    );
                if (modifier != null)
                {
                    caster.AddModifier(modifier);
                }
                loopable = new ModifierLoopable(modifier);
                break;

            case ActionType.Animation:
                loopable = new AnimationPlayback(baseEvent, caster);
                break;

            case ActionType.Teleport:
                TeleportAction          ta   = (TeleportAction)baseEvent.action;
                TeleportAction.ModeName mode = ta.mode.ShowModeName();
                switch (mode)
                {
                case TeleportAction.ModeName.PredefinedPositionOnMap:
                    new Teleport(baseEvent, caster, environment);
                    loopable = new ImmediatelyFinishedLoopable();
                    break;

                case TeleportAction.ModeName.KeepDistance:
                    TeleportAction.KeepDistanceMode kdm = (TeleportAction.KeepDistanceMode)ta.mode;
                    loopable = new TeleportKeepDistanceLogic(kdm, skill, environment, caster);
                    break;

                case TeleportAction.ModeName.AroundTarget:
                    TeleportAction.AroundTargetMode atm = (TeleportAction.AroundTargetMode)ta.mode;
                    loopable = new TeleportAroundTargetLogic(atm, caster, environment, skill);
                    break;

                case TeleportAction.ModeName.AroundTeamMate:
                    TeleportAction.AroundTeamMateMode atmm = (TeleportAction.AroundTeamMateMode)ta.mode;
                    loopable = new TeleportAroundTeamMate(atmm, caster, environment, skill);
                    break;

                default:
                    throw new Exception("Cannot create teleport of type " + mode);
                }
                break;

            case ActionType.FacingDirection:
                loopable = new FacingDirection(baseEvent, caster, environment);
                break;

            case ActionType.DashTowardTarget:
                DashTowardTarget dtt = new DashTowardTarget(baseEvent, caster, environment);
                loopable = dtt;
                break;

            case ActionType.JumpTowardTarget:
                loopable = new JumpTowardTarget(baseEvent, caster, environment);
                break;

            case ActionType.SpawnCharacter:
                SpawnCharacterAction sca = (SpawnCharacterAction)ba;
                loopable = new SpawnCharacter(sca, entitySpawner, caster, args, environment, skillId, hamc);
                break;

            case ActionType.Rotation:
                loopable = new Rotation(baseEvent, caster, environment);
                break;

            case ActionType.Timer:
                loopable = new Timer(baseEvent, skill);
                break;

            case ActionType.Sound:
                loopable = new AudioClipPlayback(baseEvent, environment);
                break;

            case ActionType.PassiveSkillOnOff:
                loopable = new PassiveSkillOnOff(baseEvent, caster);
                break;

            case ActionType.DistanceTracker:
                loopable = new DistanceTracker(baseEvent, skill, caster);
                break;

            case ActionType.SelfDamageDealing:
                loopable = new SelfDamageDealing(baseEvent, caster, skill, skillId);
                break;

            case ActionType.SwitchPhase:
                loopable = new SwitchPhase(skill);
                break;

            case ActionType.Movable:
                Entity        casterEntity  = caster.GameObject().GetComponent <EntityReference>().Entity;
                UserInput     userInput     = casterEntity.GetComponent <HeroStateMachineComponent>().UserInput;
                MovableAction movableAction = (MovableAction)ba;
                loopable = new Movable(movableAction, skill, caster.FacingDirection(), userInput, caster);
                break;

            case ActionType.Input:
                casterEntity = caster.GameObject().GetComponent <EntityReference>().Entity;
                userInput    = casterEntity.GetComponent <HeroStateMachineComponent>().UserInput;
                InputAction ia = (InputAction)ba;
                loopable = new InputSimulation(ia, (DefaultUserInput)userInput);
                break;

#if UNITY_EDITOR
            case ActionType.Macro:
                loopable = new Macro(baseEvent, caster);
                break;
#endif
            default:
                DLog.Log("Missing logic to handle action of type " + actionType);
                break;
            }

            return(loopable);
        }