Esempio n. 1
0
    public static BuffEntity CreateBuff(this BuffContext context, Buff type)
    {
        var entity = context.CreateEntity();

        entity.AddBuff(type);
        return(entity);
    }
Esempio n. 2
0
    public Contexts()
    {
        buff      = new BuffContext();
        card      = new CardContext();
        game      = new GameContext();
        gameEvent = new GameEventContext();
        tile      = new TileContext();
        unit      = new UnitContext();

        var postConstructors = System.Linq.Enumerable.Where(
            GetType().GetMethods(),
            method => System.Attribute.IsDefined(method, typeof(Entitas.CodeGeneration.Attributes.PostConstructorAttribute))
            );

        foreach (var postConstructor in postConstructors)
        {
            postConstructor.Invoke(this, null);
        }
    }
Esempio n. 3
0
    private void HandleFrameEvent()
    {
        var creature = stateMachine.creature;

        if (m_currentFrame == info.processes.x)
        {
            stateMachine.SetParam(StateMachineParam.exit, true);
            stateMachine.SetParam(StateMachineParam.process, 1);
        }

        if (m_currentFrame == info.processes.y)
        {
            m_waitToResetKey = true;                                     // Clear key input next update
        }
        if (info.ignoreInput.y > 0 && info.ignoreInput.x != info.ignoreInput.y)
        {
            if (m_currentFrame == info.ignoreInput.x)
            {
                m_acceptInput = false;
            }
            else if (m_currentFrame == info.ignoreInput.y)
            {
                m_acceptInput = true;
            }
        }

        if (m_currentFrame == info.landingFrame && !creature.onGround)
        {
            m_falling = true;
            if (m_motionIndex > 1)
            {
                var velocity = (m_motion.points[m_motionIndex] - m_motion.points[m_motionIndex - 1]) * 0.3;
                if (velocity.magnitude == 0)
                {
                    velocity = defaultFallSpeed;
                }
                else
                {
                    velocity = new Vector3_(!stateMachine.creature.isForward ? -velocity.z : velocity.z, velocity.y >= 0 ? defaultFallSpeed.y : velocity.y, -velocity.x);
                }

                #region Debug log
                #if DEVELOPMENT_BUILD || UNITY_EDITOR
                if (velocity.z != 0)
                {
                    Logger.LogError("<color=#00DDFF><b>[{6}:{5}]</b></color>, state <color=#00DDFF><b>[{0}:{1}]</b></color> has invalid landing frame <color=#00DDFF><b>[{2}]</b></color>, fallSpeed has Z velocity <color=#00DDFF><b>[{3}]</b></color>, motion ID: <color=#00DDFF><b>[{4}]</b></color>, last frame: <color=#00DDFF><b>[{7}]</b></color>",
                                    ID, name, info.landingFrame, velocity.z, m_motion.ID, parent.ID, parent.GetType(), m_motion.points[m_motionIndex - 1]);
                }
                #endif
                #endregion

                velocity.z = 0; // @TODO: Fix velocity validation
                fallSpeed  = velocity;
            }
        }

        if (m_curSectionIdx < info.sections.Length && info.sections[m_curSectionIdx].startFrame == m_currentFrame)
        {
            creature.behaviour.attackCollider.SetAttackBox(info.sections[m_curSectionIdx].attackBox, stateMachine.GetHitEffect(off), creature.isForward);

            ++m_curSectionIdx;
            stateMachine.SetParam(StateMachineParam.section, m_curSectionIdx);
        }

        if (m_curInvisibleIndex < info.invisibles.Length && info.invisibles[m_curInvisibleIndex].startFrame == m_currentFrame)
        {
            var invisible = info.invisibles[m_curInvisibleIndex].disable;
            creature.SetLayer(invisible ? Layers.INVISIBLE : -1, invisible);

            ++m_curInvisibleIndex;
        }

        if (m_curWeakIndex < info.weaks.Length && info.weaks[m_curWeakIndex].startFrame == m_currentFrame)
        {
            if (info.weaks[m_curWeakIndex].disable)
            {
                creature.weakCount++;
                weakCount++;
            }
            else if (weakCount > 0)
            {
                creature.weakCount--;
                weakCount--;
            }

            ++m_curWeakIndex;
        }

        if (m_curToughIdx < info.toughs.Length && info.toughs[m_curToughIdx].startFrame == m_currentFrame)
        {
            var idx = m_toughs.Count - 1;
            if (idx > -1)
            {
                creature.RemoveToughState(m_toughs[idx]);
                m_toughs.RemoveAt(idx);

                UpdateRimLightState(-1);
            }

            var tlvl = info.toughs[m_curToughIdx].intValue0;

            if (tlvl > 0)
            {
                m_toughs.Add(creature.AddToughState(tlvl));

                UpdateRimLightState(1);
            }

            ++m_curToughIdx;
        }

        if (info.invincible.y > 0)
        {
            if (m_currentFrame == info.invincible.x)
            {
                creature.invincibleCount++;
                invincibleCount++;

                UpdateRimLightState(1);
            }
            if (m_currentFrame == info.invincible.y + 1)
            {
                creature.invincibleCount--;
                invincibleCount--;

                UpdateRimLightState(-1);
            }
        }

        if (info.hideHpSlider.y > 0)
        {
            if (m_currentFrame == info.hideHpSlider.x)
            {
                hideHpSliderCount++;
                creature.hpVisiableCount--;
            }
            if (m_currentFrame == info.hideHpSlider.y + 1)
            {
                hideHpSliderCount--;
                creature.hpVisiableCount++;
            }
        }

        if (info.ethereal.y > 0)
        {
            if (m_currentFrame == info.ethereal.x)
            {
                creature.etherealCount++;
                etherealCount++;
            }
            if (m_currentFrame == info.ethereal.y + 1)
            {
                creature.etherealCount--;
                etherealCount--;
            }
        }

        if (info.passiveEthereal.y > 0)
        {
            if (m_currentFrame == info.passiveEthereal.x)
            {
                creature.passiveEtherealCount++;
                passiveEtherealCount++;
            }
            if (m_currentFrame == info.passiveEthereal.y + 1)
            {
                creature.passiveEtherealCount--;
                passiveEtherealCount--;
            }
        }

        while (m_curBuffIndex < info.buffs.Length && info.buffs[m_curBuffIndex].startFrame == m_currentFrame)
        {
            var b = info.buffs[m_curBuffIndex];

            if (b.doubleValue0 == 0 || Module_Battle.Range() < b.doubleValue0)
            {
                var pet = creature as PetCreature;
                if (pet && b.intValue0 <= 0)
                {
                    var skill = pet.GetSkillByState(name);
                    if (skill)
                    {
                        var count = skill.skillInfo.buffs.Length;
                        for (int i = 0; i < count; i++)
                        {
                            Buff.Create(skill.skillInfo.buffs[i], creature, creature, 0, -1, pet.petInfo.AdditiveLevel);
                        }
                    }
                }
                else
                {
                    Buff.Create(b.intValue0, creature, null, b.intValue1);
                }
            }

            ++m_curBuffIndex;
        }

        var effects = info.effects;
        while (m_curEffectIdx < effects.Length && effects[m_curEffectIdx].startFrame == m_currentFrame)
        {
            if (m_inheritEffectsFrame.Contains(m_curEffectIdx))
            {
                ++m_curEffectIdx;
                continue;
            }

            if (!creature.isPlayer && effects[m_curEffectIdx].self)
            {
                ++m_curEffectIdx;
                continue;
            }

            var eff = creature.behaviour.effects.PlayEffect(effects[m_curEffectIdx]);
            if (eff)
            {
                eff.localTimeScale = animationSpeed;
                if (eff.name == "effect_ringring" && info.fatalRadius > 0)
                {
                    eff.lifeTime   = -1;
                    eff.localScale = Vector3.one * (float)info.fatalRadius;
                }
            }

            if (effects[m_curEffectIdx].inherit)
            {
                m_inheritEffectsFrame.Add(m_curEffectIdx);
                m_inheritEffects.Add(eff);
            }

            ++m_curEffectIdx;
        }

        while (m_curFlyingEffectIdx < info.flyingEffects.Length && info.flyingEffects[m_curFlyingEffectIdx].startFrame == m_currentFrame)
        {
            creature.behaviour.effects.PlayEffect(info.flyingEffects[m_curFlyingEffectIdx], stateMachine.GetHitEffect(off));

            ++m_curFlyingEffectIdx;
        }

        while (m_curSoundEffectIdx < info.soundEffects.Length && info.soundEffects[m_curSoundEffectIdx].startFrame == m_currentFrame)
        {
            var se = info.soundEffects[m_curSoundEffectIdx];
            ++m_curSoundEffectIdx;

            if (se.isEmpty || !se.global && !creature.isPlayer || UnityEngine.Random.Range(0, 1.0f) > se.rate)
            {
                continue;
            }

            var s = se.SelectSound(creature.roleProto, creature.gender);
            if (!s.isEmpty)
            {
                if (!se.interrupt)
                {
                    AudioManager.PlayAudio(s.sound, se.isVoice || s.isVoice ? AudioTypes.Voice : AudioTypes.Sound, false, se.overrideType);
                }
                else
                {
                    AudioManager.PlayAudio(s.sound, se.isVoice || s.isVoice ? AudioTypes.Voice : AudioTypes.Sound, false, se.overrideType, h => { if (h)
                                                                                                                                                  {
                                                                                                                                                      m_audios.Add(h.id);
                                                                                                                                                  }
                                           });
                }
            }
        }

        if (m_curDarkIndex < info.darkScreens.Length && info.darkScreens[m_curDarkIndex].startFrame == m_currentFrame)
        {
            var alpha = (float)info.darkScreens[m_curDarkIndex].doubleValue0;
            var draw  = alpha > 0;

            darkCount += draw ? 1 : -1;
            Camera_Combat.Dark(draw ? 1 : -1, alpha);

            ++m_curDarkIndex;
        }

        if (m_curRimIndex < info.rimLights.Length && info.rimLights[m_curRimIndex].startFrame == m_currentFrame)
        {
            m_rimLight = !info.rimLights[m_curRimIndex].disable;

            UpdateRimLightState();

            ++m_curRimIndex;
        }

        if (m_curShakeIdx < info.cameraShakes.Length && info.cameraShakes[m_curShakeIdx].startFrame == m_currentFrame)
        {
            var shake = ConfigManager.Get <CameraShakeInfo>(info.cameraShakes[m_curShakeIdx].intValue0);
            if (shake)
            {
                Camera_Combat.Shake(shake.intensity, shake.duration * 0.001f, shake.range, creature);
            }

            ++m_curShakeIdx;
        }

        if (m_curHideIdx < info.hideWeapons.Length && info.hideWeapons[m_curHideIdx].startFrame == m_currentFrame)
        {
            var hide = info.hideWeapons[m_curHideIdx].disable;
            creature.behaviour.SetWeaponVisibility(-1, !hide, false);

            ++m_curHideIdx;
        }

        if (m_curHideOffIdx < info.hideOffWeapons.Length && info.hideOffWeapons[m_curHideOffIdx].startFrame == m_currentFrame)
        {
            var hide = info.hideOffWeapons[m_curHideOffIdx].disable;
            creature.behaviour.SetWeaponVisibility(-1, m_showOffWeapon && !hide, true);

            ++m_curHideOffIdx;
        }

        if (m_curHidePetIdx < info.hidePets.Length && info.hidePets[m_curHidePetIdx].startFrame == m_currentFrame)
        {
            if (creature.pet)
            {
                var hidePet = info.hidePets[m_curHidePetIdx].disable;
                creature.pet.enabledAndVisible = !hidePet;
            }

            ++m_curHidePetIdx;
        }

        if (m_curActorIdx < info.sceneActors.Length && info.sceneActors[m_curActorIdx].frame == m_currentFrame)
        {
            var a     = info.sceneActors[m_curActorIdx];
            var actor = (Level.current as Level_Battle)?.CreateSceneActor(
                a.actorID,
                creature.position_ + a.offset * (creature.direction == CreatureDirection.FORWARD ? 1 :-1),
                creature.direction, a.groupID,
                a.level);
            ++m_curActorIdx;
            if (actor == null)
            {
                return;
            }

            actor.SetCreatureCamp(creature.creatureCamp);
            BuffContext c = new BuffContext
            {
                id    = 444,
                level = 1,
                owner = actor,
                delay = a.lifeTime
            };
            Buff.Create(c);
        }
    }
Esempio n. 4
0
 public BuffReactiveSystem(Contexts contexts) : base(contexts.buff)
 {
     _context = contexts.buff;
 }