Ejemplo n.º 1
0
    /// <summary>
    /// build random.
    /// </summary>
    /// <param name="rBehaviour"></param>
    /// <param name="bRebuild"></param>
    /// <returns></returns>
    public SRandomInfoConditon BuildRandom(int randomId, int maxValue, bool bRebuild = false)
    {
        var c = m_preBuildRandom.Find(item => item.randomId == randomId);

        if (c == null)
        {
            //最后的随机数需要加1,因为策划需要从1~maxValue
            int random = Module_Battle.Range(1, maxValue == 0 ? 2 : maxValue + 1);
            m_preBuildRandom.Add(new SRandomInfoConditon(randomId, random));
        }
        else
        {
            if (bRebuild)
            {
                int random = Module_Battle.Range(1, maxValue == 0 ? 2 : maxValue + 1);
                c.value = random;
            }
        }
        return(c);
    }
Ejemplo n.º 2
0
    public void OnHit(AttackCollider c, AttackInfo a, int t)
    {
        if (null == m_creature)
        {
            return;
        }
        var alive = !m_creature.isDead;

        var ts      = t == byte.MaxValue ? AttackInfo.hitProtectTrans : a.targetStates[t];
        var cc      = c.creature;
        var ss      = c.currentState;
        var passive = ss.info.ignoreTough || (!m_creature.tough || a.breakToughLevel > m_creature.toughLevel) || m_creature.weak && a.fromBullet;  // can we enter passive state ?
        var toState = -1;

        if (passive)
        {
            var pt         = 0L;
            var breakTough = m_creature.tough && (ss.info.ignoreTough || a.breakToughLevel > m_creature.toughLevel || cc.breakToughLevel > m_creature.toughLevel);
            var isCatch    = ss.info.catchState > 0;
            if (isCatch)
            {
                pt = pt.BitMask(StateMachine.PASSIVE_CATCH, true);
            }
            if (breakTough)
            {
                pt = pt.BitMask(StateMachine.PASSIVE_TOUGH, true);
            }
            if (a.fromBullet && (m_creature.weak || c.creature.HawkEye))
            {
                pt = pt.BitMask(StateMachine.PASSIVE_WEAK, true);
            }

            var opt = m_stateMachine.GetLong(StateMachineParam.forcePassive) >> 48 & 0xFFFF;
            if (opt == 0 || pt.BitMask(StateMachine.PASSIVE_CATCH) || !opt.BitMask(StateMachine.PASSIVE_CATCH) && pt.BitMask(StateMachine.PASSIVE_WEAK))
            {
                var tid = breakTough && m_creature.HasState(ts.toToughStateID) ? ts.toToughStateID : ts.toStateID;
                toState = tid;

                var p = pt << 48 | (long)cc.id << 32 | (uint)tid;
                m_stateMachine.SetParam(StateMachineParam.forcePassive, p);

                if (pt.BitMask(StateMachine.PASSIVE_CATCH))
                {
                    m_creature.RemoveBuff(BuffInfo.EffectTypes.Freez);
                }

                if (c.type == AttackColliderTypes.Attack)
                {
                    var mask = m_stateMachine.GetStateMask(toState);
                    cc.stateMachine.SetParam(StateMachineParam.targetGroupMask, mask);
                    cc.stateMachine.SetParam(StateMachineParam.targetHitGroupMask, m_stateMachine.GetLong(StateMachineParam.groupMask));
                    cc.stateMachine.SetParam(StateMachineParam.targetConfigID, m_creature.configID);
                    if (isCatch && !mask.BitMasks(ss.info.ignoreCatchPosGroups) && m_creature.HasState(toState))
                    {
                        if (ss.info.catchState == 1)
                        {
                            m_creature.position_ = cc.position_;
                        }
                        else
                        {
                            cc.position_ = m_creature.position_;
                        }
                    }
                }
            }
            else
            {
                passive = false;
            }
        }

        if (c.type == AttackColliderTypes.Attack)
        {
            cc.stateMachine.SetParam(StateMachineParam.hit, true);
        }

        m_stateMachine.SetParam(StateMachineParam.hited, cc.id);

        cc.DispatchAttackEvent(m_creature, a);
        if (!m_creature.isDead)
        {
            cc.rage += a.selfRageReward * (1 + cc.attackRageMul);                      // ignore rage reward if target is dead
        }
        m_creature.DispatchEvent(CreatureEvents.ATTACKED, Event_.Pop(cc, a));
        if (a.fromBullet)
        {
            m_creature.DispatchEvent(CreatureEvents.SHOOTED, Event_.Pop(m_creature, a));
        }
        if (!m_creature.isDead) // ignore rage reward if target is dead
        {
            m_creature.rage += a.targetRageReward * (1 + m_creature.attackedRageMul);
            m_creature.TakeDamage(cc, cc.CalculateDamage(a, m_creature, ss.damageMul));
        }
        else if (!alive)
        {
            UpdateDeadCombo();
        }

        if (a.freezTime > 0)
        {
            m_stateMachine.Pending(a.freezTime, passive, alive && m_creature.isDead);
            if (!a.fromEffect)
            {
                c.stateMachine.Pending(a.freezTime);
            }
        }

        if (passive)
        {
            if (a.preventTurn == 0)
            {
                if (a.fromBullet)
                {
                    m_creature.FaceTo(cc);
                }
                else
                {
                    var direction = CalculateHitDirection(c, a, m_creature.x);
                    if (direction != 0)
                    {
                        m_creature.direction = direction < 0 ? CreatureDirection.BACK : CreatureDirection.FORWARD;
                    }
                }
            }
            if (a.acttackSlide != 0)
            {
                m_creature.Knockback(m_creature.isForward ? -a.acttackSlide * 0.1 : a.acttackSlide * 0.1);
            }
        }

        var s = a.soundEffect.SelectSound(m_creature.roleProto, m_creature.gender);

        if (!s.isEmpty)
        {
            AudioManager.PlayAudio(s.sound, a.soundEffect.isVoice || s.isVoice ? AudioTypes.Voice : AudioTypes.Sound, false, a.soundEffect.overrideType);
        }

        if (c.type == AttackColliderTypes.Attack && !a.ignoreHitEffect)
        {
            behaviour.effects.PlayEffect(c.hitEff);
        }

        if (!m_creature.isDead)  // do not trigger buffs if target is dead
        {
            var level = 1;
            if (cc is PetCreature)
            {
                level = ((PetCreature)cc).petInfo.AdditiveLevel;
            }

            var b = a.selfBuff;
            if (b.intValue0 != 0 && (b.doubleValue0 == 0 || Module_Battle.Range() <= b.doubleValue0))
            {
                Buff.Create(b.intValue0, cc, null, b.intValue1, -1, level);
            }

            b = a.targetBuff;
            if (b.intValue0 != 0 && (b.doubleValue0 == 0 || Module_Battle.Range() <= b.doubleValue0))
            {
                Buff.Create(b.intValue0, m_creature, cc, b.intValue1, -1, level);
            }
        }

        #region Debug log
        #if DEVELOPMENT_BUILD || UNITY_EDITOR
        Logger.LogInfo("[{3}:{4}-{5}], [{0}] hited by attackInfo [{1}], translate to state [{2}]", m_creature.gameObject.name, a.ID, toState == ts.toStateID ? ts.toState : toState == ts.toToughStateID ? ts.toToughState : string.Empty, Level.levelTime, creature.frameTime, creature.frameCount);
        #endif

        #if AI_LOG
        Module_AI.LogBattleMsg(m_creature, "[m_creature.tough = {0},currentState is {1} ss.info.ignoreTough = {2} attackinfo.breaktoughLevel = {3} m_creature.toughLevel = {4} cc.breakToughLevel = {5}", m_creature.tough, m_creature.stateMachine.currentState.name, ss.info.ignoreTough, a.breakToughLevel, m_creature.toughLevel, cc.breakToughLevel);
        Module_AI.LogBattleMsg(m_creature, "[[{0}] hited by attackInfo [{1}], translate to state [{2}]", m_creature.gameObject.name, a.ID, toState == ts.toStateID ? ts.toState : toState == ts.toToughStateID ? ts.toToughState : string.Empty);
        #endif
        #endregion
    }
Ejemplo 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);
        }
    }