Example #1
0
        private void OnHitEnvironment(PlayerEntity srcPlayer, IBulletEntity bulletEntity, RaycastHit hit)
        {
            if (srcPlayer.gamePlay.IsDead())
            {
                _logger.InfoFormat("[hit] environment dead");
                return;
            }

            ThicknessInfo   thicknessInfo;
            EnvironmentInfo info = BulletEnvironmentUtility.GetEnvironmentInfoByHitBoxName(hit, bulletEntity.Velocity, out thicknessInfo);
            float           damageDecayFactor = _environmentTypeConfigManager.GetDamageDecayFactorByEnvironmentType(info.Type);
            float           energyDecayFactor = _environmentTypeConfigManager.GetEnergyDecayFactorByEnvironmentType(info.Type);
            float           oldThickNess      = bulletEntity.PenetrableThickness;
            float           oldDamage         = bulletEntity.BaseDamage;

            bulletEntity.BaseDamage           *= damageDecayFactor;
            bulletEntity.PenetrableThickness   = bulletEntity.PenetrableThickness * energyDecayFactor - info.Thickness;
            bulletEntity.PenetrableLayerCount -= info.LayerCount;

            if (bulletEntity.PenetrableLayerCount <= 0 || bulletEntity.PenetrableThickness <= 0)
            {
                bulletEntity.IsValid = false;
            }
            else
            {
                bulletEntity.AddPenetrateInfo(info.Type);
            }

            EBulletCaliber caliber = bulletEntity.Caliber; //根据口径

            var collider          = hit.collider;
            var fracturedHittable = collider.GetComponent <FracturedHittable>();

            if (fracturedHittable != null)
            {
                EntityKey?hittedObjectKey = null;

                var script = fracturedHittable.gameObject.GetComponent <FracturedHittable>();
                if (script == null)
                {
                    return;
                }

                var objtype = MapObjectUtility.GetGameObjType(script.Owner);
                if (objtype < 0)
                {
                    return;
                }

                var rawObjKey = MapObjectUtility.GetGameObjId(script.Owner);

                if (rawObjKey != Int32.MinValue && !SharedConfig.IsServer &&
                    MapObjectUtility.GetMapObjectByGameObject(script.Owner) == null)
                {
                    MapObjectUtility.SendCreateMapObjMsg(objtype, rawObjKey);
                    _logger.InfoFormat("CreateMapObjEvent: type:{0}, obj:{1}, num:{2}", (ETriggerObjectType)objtype,
                                       fracturedHittable.gameObject,
                                       srcPlayer.uploadEvents.Events.Events[EEventType.CreateMapObj].Count);
                }

                FracturedAbstractChunk fracturedChunk = null;

                fracturedChunk = fracturedHittable.Hit(hit.point, hit.normal);
                if (fracturedHittable.HasBulletHole && fracturedChunk != null)
                {
                    ClientEffectFactory.CreateHitFracturedChunkEffect(_contexts.clientEffect, _entityIdGenerator, hit.point,
                                                                      srcPlayer.entityKey.Value, hittedObjectKey.Value, fracturedChunk.ChunkId,
                                                                      hit.point - fracturedChunk.transform.position, hit.normal);
                }

                srcPlayer.statisticsData.Statistics.ShootingSuccCount++;

                if (fracturedHittable.HasBulletHole && fracturedChunk != null && bulletEntity.IsValid && thicknessInfo.Thickness > 0)
                {
                    ClientEffectFactory.CreateHitFracturedChunkEffect(_contexts.clientEffect, _entityIdGenerator, thicknessInfo.OutPoint, srcPlayer.entityKey.Value,
                                                                      hittedObjectKey.Value, fracturedChunk.ChunkId, thicknessInfo.OutPoint - fracturedChunk.transform.position, thicknessInfo.Normal);
                }
            }
            else
            {
                ClientEffectFactory.AdHitEnvironmentEffectEvent(srcPlayer, hit.point, hit.normal, info.Type);

                if (bulletEntity.IsValid && thicknessInfo.Thickness > 0)
                {
                    ClientEffectFactory.AdHitEnvironmentEffectEvent(srcPlayer, thicknessInfo.OutPoint, thicknessInfo.Normal, info.Type);
                }
            }

            _logger.InfoFormat("[hit]bullet from {0} hit environment {1}, collier {2}, base damage {3}->{4}, penetrable thick {5}->{6}, env ({7}), remain layer {8}",
                               bulletEntity.OwnerEntityKey, hit.point, hit.collider.name, oldDamage, bulletEntity.BaseDamage, oldThickNess, bulletEntity.PenetrableThickness,
                               info, bulletEntity.PenetrableLayerCount);
        }
Example #2
0
        private void OnHitEnvironment(PlayerEntity srcPlayer, IBulletEntity bulletEntity, RaycastHit hit)
        {
            ThicknessInfo   thicknessInfo;
            EnvironmentInfo info = BulletEnvironmentUtility.GetEnvironmentInfoByHitBoxName(hit, bulletEntity.Velocity, out thicknessInfo);
            float           damageDecayFactor = _environmentTypeConfigManager.GetDamageDecayFactorByEnvironmentType(info.Type);
            float           energyDecayFactor = _environmentTypeConfigManager.GetEnergyDecayFactorByEnvironmentType(info.Type);
            float           oldThickNess      = bulletEntity.PenetrableThickness;
            float           oldDamage         = bulletEntity.BaseDamage;

            bulletEntity.BaseDamage           *= damageDecayFactor;
            bulletEntity.PenetrableThickness   = bulletEntity.PenetrableThickness * energyDecayFactor - info.Thickness;
            bulletEntity.PenetrableLayerCount -= info.LayerCount;

            if (bulletEntity.PenetrableLayerCount <= 0 || bulletEntity.PenetrableThickness <= 0)
            {
                bulletEntity.IsValid = false;
            }
            else
            {
                bulletEntity.AddPenetrateInfo(info.Type);
            }

            EBulletCaliber caliber = bulletEntity.Caliber; //根据口径

            var collider          = hit.collider;
            var fracturedHittable = collider.GetComponent <FracturedHittable>();

            if (fracturedHittable != null)
            {
                EntityKey?hittedObjectKey = null;

                var sceneObjectEntity = MapObjectUtility.GetMapObjectOfFracturedHittable(fracturedHittable);
                if (sceneObjectEntity != null)
                {
                    hittedObjectKey = sceneObjectEntity.entityKey.Value;
                }
                else
                {
                    var mapObjectEntity = MapObjectUtility.GetMapObjectOfFracturedHittable(fracturedHittable);
                    if (mapObjectEntity != null)
                    {
                        hittedObjectKey = mapObjectEntity.entityKey.Value;
                    }
                }

                FracturedAbstractChunk fracturedChunk = null;

                if (null != hittedObjectKey)
                {
                    fracturedChunk = fracturedHittable.Hit(hit.point, hit.normal);
                    if (fracturedHittable.HasBulletHole && fracturedChunk != null)
                    {
                        ClientEffectFactory.CreateHitFracturedChunkEffect(
                            _contexts.clientEffect,
                            _entityIdGenerator,
                            hit.point,
                            srcPlayer.entityKey.Value,
                            hittedObjectKey.Value,
                            fracturedChunk.ChunkId,
                            hit.point - fracturedChunk.transform.position,
                            hit.normal);
                    }

                    srcPlayer.statisticsData.Statistics.ShootingSuccCount++;
                }
                else
                {
                    _logger.ErrorFormat("no entity reference attached to {0}", fracturedHittable.name);
                }
                if (fracturedHittable.HasBulletHole && fracturedChunk != null &&
                    bulletEntity.IsValid && thicknessInfo.Thickness > 0)
                {
                    ClientEffectFactory.CreateHitFracturedChunkEffect(_contexts.clientEffect,
                                                                      _entityIdGenerator,
                                                                      thicknessInfo.OutPoint,
                                                                      srcPlayer.entityKey.Value,
                                                                      hittedObjectKey.Value,
                                                                      fracturedChunk.ChunkId,
                                                                      thicknessInfo.OutPoint - fracturedChunk.transform.position,
                                                                      thicknessInfo.Normal);
                }
            }
            else
            {
                ClientEffectFactory.AdHitEnvironmentEffectEvent(srcPlayer, hit.point,
                                                                hit.normal, info.Type);

                if (bulletEntity.IsValid && thicknessInfo.Thickness > 0)
                {
                    ClientEffectFactory.AdHitEnvironmentEffectEvent(srcPlayer, thicknessInfo.OutPoint, thicknessInfo.Normal, info.Type);
                }
            }


            _logger.DebugFormat(
                "bullet from {0} hit environment {1}, collier {2}, base damage {3}->{4}, penetrable thick {5}->{6}, env ({7}), remain layer {8}",
                bulletEntity.OwnerEntityKey,
                hit.point, hit.collider.name,
                oldDamage, bulletEntity.BaseDamage,
                oldThickNess, bulletEntity.PenetrableThickness,
                info,
                bulletEntity.PenetrableLayerCount);

            DamageInfoDebuger.OnEnvironmentHit(_contexts.player, _damager, _damageInfoCollector);
        }