Пример #1
0
        private void HandleHurtEvent(SprotoType.scene_hurt_event_info hurtEvent)
        {
            // long uid = hurtEvent.attacker_uid;
            var entityMgr = SceneMgr.Instance.EntityManager;

            if (hurtEvent.defenders == null || hurtEvent.defenders.Count <= 0)
            {
                return;
            }
            for (int i = 0; i < hurtEvent.defenders.Count; i++)
            {
                var defender = hurtEvent.defenders[i];
                // Debug.Log("defender uid : "+defender.uid+" count:"+hurtEvent.defenders.Count+" hp:"+defender.cur_hp+" damagetype:"+defender.flag);
                var defenderEntity = SceneMgr.Instance.GetSceneObject(defender.uid);
                // Debug.Log("has LocomotionState : "+entityMgr.HasComponent<LocomotionState>(defenderEntity)+" isdead:"+ECSHelper.IsDead(defenderEntity, entityMgr)+" isnull:"+defenderEntity.Equals(Entity.Null));
                if (defenderEntity.Equals(Entity.Null) || ECSHelper.IsDead(defenderEntity, entityMgr))
                {
                    continue;
                }
                if (entityMgr.HasComponent <LocomotionState>(defenderEntity))
                {
                    var isMainRole = RoleMgr.GetInstance().IsMainRoleEntity(defenderEntity);
                    //进入受击状态
                    bool playBehit = UnityEngine.Random.RandomRange(0, 100) > 30.0f;
                    if (!isMainRole && playBehit)
                    {
                        var locomotionState = entityMgr.GetComponentData <LocomotionState>(defenderEntity);
                        locomotionState.LocoState    = LocomotionState.State.BeHit;
                        locomotionState.StateEndType = LocomotionState.EndType.PlayAnimationOnce;
                        // locomotionState.StartTime = Time.time;
                        entityMgr.SetComponentData <LocomotionState>(defenderEntity, locomotionState);
                    }
                    bool isNeedShakeCamera = (isMainRole && playBehit) || !isMainRole;
                    if (isNeedShakeCamera && entityMgr.HasComponent <CinemachineImpulseSource>(defenderEntity))
                    {
                        var impulseCom = entityMgr.GetComponentObject <CinemachineImpulseSource>(defenderEntity);
                        var velocity   = Vector3.one * defender.change_num / 5;
                        impulseCom.GenerateImpulse();
                    }
                    if (entityMgr.HasComponent <BeHitEffect>(defenderEntity))
                    {
                        var behitEffect = entityMgr.GetComponentObject <BeHitEffect>(defenderEntity);
                        behitEffect.EndTime = TimeEx.ServerTime + 300;
                        behitEffect.Status  = EffectStatus.WaitForRender;
                    }
                    //显示战斗飘字
                    var          defenderTrans = entityMgr.GetComponentObject <Transform>(defenderEntity);
                    var          flyWordObj    = ResMgr.GetInstance().GetGameObject("FightFlyWord");
                    FightFlyWord flyWord       = flyWordObj.GetComponent <FightFlyWord>();
                    flyWord.SetData(defender.change_num, defender.flag);
                    var pos = defenderTrans.position;
                    pos += Vector3.up * 1;
                    flyWord.transform.SetParent(UnityMMO.SceneMgr.Instance.FlyWordContainer);
                    flyWord.transform.position = pos;
                    flyWord.StartFly();
                }
                ChangeHP(defenderEntity, defender.cur_hp, defender.flag, hurtEvent.attacker_uid);
            }
        }
Пример #2
0
        private void HandleHurtEvent(SprotoType.scene_hurt_event_info hurtEvent)
        {
            // long uid = hurtEvent.attacker_uid;
            var entityMgr = SceneMgr.Instance.EntityManager;

            if (hurtEvent.defenders == null || hurtEvent.defenders.Count <= 0)
            {
                return;
            }
            for (int i = 0; i < hurtEvent.defenders.Count; i++)
            {
                var defender = hurtEvent.defenders[i];
                // Debug.Log("defender uid : "+defender.uid+" count:"+hurtEvent.defenders.Count+" damage:"+defender.damage+" hp:"+defender.cur_hp+" damagetype:"+defender.flag);
                var defenderEntity = SceneMgr.Instance.GetSceneObject(defender.uid);
                // Debug.Log("has health : "+entityMgr.HasComponent<HealthStateData>(defenderEntity));
                if (defenderEntity.Equals(Entity.Null) || ECSHelper.IsDead(defenderEntity, entityMgr))
                {
                    continue;
                }
                if (entityMgr.HasComponent <LocomotionState>(defenderEntity))
                {
                    //进入受击状态
                    bool playBehit = UnityEngine.Random.RandomRange(0, 100) > 90.0f;
                    if (playBehit)
                    {
                        var locomotionState = entityMgr.GetComponentData <LocomotionState>(defenderEntity);
                        locomotionState.LocoState = LocomotionState.State.BeHit;
                        locomotionState.StartTime = Time.time;
                        entityMgr.SetComponentData <LocomotionState>(defenderEntity, locomotionState);
                    }
                    //显示战斗飘字
                    var          defenderTrans = entityMgr.GetComponentObject <Transform>(defenderEntity);
                    var          flyWordObj    = ResMgr.GetInstance().GetGameObject("FightFlyWord");
                    FightFlyWord flyWord       = flyWordObj.GetComponent <FightFlyWord>();
                    flyWord.SetData(defender.change_num, defender.flag);
                    var pos = defenderTrans.position;
                    pos += Vector3.up * 1;
                    flyWord.transform.SetParent(UnityMMO.SceneMgr.Instance.FlyWordContainer);
                    flyWord.transform.position = pos;
                    flyWord.StartFly();
                }
                ChangeHP(defenderEntity, defender.cur_hp, defender.flag, hurtEvent.attacker_uid);
            }
        }