Exemple #1
0
        private void ShowCastTip()
        {
            _viewModel.Show = false;
            var pointerData = _castData;

            if (null == pointerData)
            {
                Logger.Error("no pointer data ");
                return;
            }
            if (null == pointerData.IdList)
            {
                Logger.Error("id list of pointer data  is null, raycast target may not been inited");
                return;
            }
            var type = pointerData.IdList[0];

            switch ((ECastDataType)type)
            {
            case ECastDataType.SceneObject:
                _currentCastLogic = _sceneObjectCastLogic;
                break;

            case ECastDataType.MapObject:
                _currentCastLogic = _mapObjectCastLogic;
                break;

            case ECastDataType.Vehicle:
                _currentCastLogic = _vehicleCastLogic;
                break;

            case ECastDataType.FreeObject:
                _currentCastLogic = _freeCastLogic;
                break;

            case ECastDataType.Door:
                _currentCastLogic = _doorCastLogic;
                break;

            case ECastDataType.Player:
                _currentCastLogic = _playerCastLogic;
                break;

            case ECastDataType.Common:
                _currentCastLogic = _commonCastLogic;
                break;
            }
            _currentCastLogic.SetData(pointerData);
            var tip = _currentCastLogic.Tip;

            //倒计时出现时不显示Tip,不能进行F键操作
            if (_pickUpUiAdapter.IsCountDown())
            {
                return;
            }

            if (string.IsNullOrEmpty(tip))
            {
                return;
            }
            else
            {
                ShowText(tip);
                if (null != _doCastAction)
                {
                    _doCastAction();
                    _doCastAction = null;
                }
            }
        }
Exemple #2
0
 private void LogError(string msg)
 {
     Logger.Error(msg);
     System.Console.WriteLine(msg);
 }
Exemple #3
0
        protected override void ExecuteUserCmd(PlayerEntity player, IUserCmd cmd)
        {
            if (player.time.ClientTime < player.meleeAttackInfoSync.AttackTime)
            {
                return;
            }
            // Logger.Info("Try Attack One Time, Interval:"+ (player.meleeAttackInfoSync.AttackTime - player.meleeAttackInfoSync.BeforeAttackTime));
            // Logger.Info("Try Attack One Time, Interval:"+ (player.time.ClientTime - player.meleeAttackInfoSync.BeforeAttackTime));

            var config = player.meleeAttackInfo.AttackConfig;

            if (null == config)
            {
                Logger.Error("attack info in player MeleeAttackInfo is null");
                return;
            }
            var attackInfo = player.meleeAttackInfo.AttackInfo;

            player.RemoveMeleeAttackInfoSync();
            var compensationWorld = _compensationWorldFactory.CreateCompensationWorld(cmd.RenderTime);

            if (null == compensationWorld)
            {
                Logger.ErrorFormat("CompensationWorld is null for time {0}", cmd.RenderTime);
                return;
            }

            compensationWorld.Self = player.entityKey.Value;
            compensationWorld.ExcludePlayerList =
                player.playerHitMaskController.HitMaskController.MeleeExcludeTargetList;

            Quaternion rotation;

            player.TryGetMeleeAttackRotation(out rotation);
            RaycastHit hit;
            //小于这个距离没有检测,设一个足够小的值
            var     minDistance = 0.01f;
            var     extens      = new Vector3(config.Width, config.Height, minDistance);
            Vector3 emitPos;

            if (!PlayerEntityUtility.TryGetMeleeAttackPosition(player, out emitPos))
            {
                Logger.Error("get melee attack position failed ");
                emitPos = player.position.Value + Vector3.up * MeleeHitUtil.GetDefaultHeight(player);
            }

            var box = new BoxInfo
            {
                Length      = config.Range,
                Direction   = rotation.Forward(),
                Origin      = emitPos,
                Orientation = rotation,
                HalfExtens  = extens / 2f,
            };

            if (compensationWorld.BoxCast(box, out hit, BulletLayers.GetBulletLayerMask()))
            {
                PlayerEntity  targetPlayer  = null;
                VehicleEntity targetVehicle = null;
                var           comp          = hit.collider.transform.gameObject.GetComponent <HitBoxOwnerComponent>();
                if (comp != null)
                {
                    targetPlayer  = _contexts.player.GetEntityWithEntityKey(comp.OwnerEntityKey);
                    targetVehicle = _contexts.vehicle.GetEntityWithEntityKey(comp.OwnerEntityKey);
                }

                if (targetPlayer != null)
                {
                    hitHandler.OnHitPlayer(_contexts, player, targetPlayer, hit, attackInfo, config, cmd.Seq);
                }
                else if (targetVehicle != null)
                {
                    hitHandler.OnHitVehicle(_contexts, player, targetVehicle, hit, attackInfo, config);
                }
                else
                {
                    hitHandler.OnHitEnvrionment(_contexts, player, hit, attackInfo, config);
                }
            }

            compensationWorld.Release();
            // Logger.Info("Try Attack Finish");
        }
        public virtual void Act(IEventArgs args)
        {
            long   s         = FreeLog.Start(this, args);
            string actName   = this.GetName();
            long   startTime = FreeTimeDebug.RecordStart(actName);

            try
            {
                SingletonManager.Get <DurationHelp>().ProfileStart(actName);
                DoAction(args);
            }
            catch (Exception e)
            {
                int length = _tempStringBuilder.Length;
                _tempStringBuilder.Remove(0, length);
                _tempStringBuilder.Append("action failed\nat ");
                _tempStringBuilder.Append(FreeLog.ActionMark);
                _tempStringBuilder.Append("\n at ");
                _tempStringBuilder.Append(this.ToMessage(args));
                _tempStringBuilder.Append("\nat ");
                _tempStringBuilder.Append(ExceptionUtil.GetExceptionContent(e));
#if UNITY_EDITOR
                string err = _tempStringBuilder.ToString();
                FreeLog.Error(err, this);
                Debug.LogError(err);
                _logger.Error(err);
#else
                string err = _tempStringBuilder.ToString();
                _logger.Error(err);
#endif

                if (args.FreeContext.DebugMode)
                {
                    FreeUIUpdateAction update = new FreeUIUpdateAction();
                    update.SetKey("testUI");
                    //update.SetPlayer(FreeUtil.ReplaceVar(player, args));
                    update.SetScope(FreeUtil.ReplaceInt(SendMessageAction.SCOPE_ALL.ToString(), args));

                    FreeUITextValue textValue = new FreeUITextValue();
                    textValue.SetSeq("1");
                    update.AddValue(textValue);

                    FreeUIShowAction show = new FreeUIShowAction();
                    show.SetKey("testUI");
                    //show.SetPlayer(FreeUtil.ReplaceVar(player, args));
                    show.SetScope(FreeUtil.ReplaceInt(SendMessageAction.SCOPE_ALL.ToString(), args));
                    show.SetTime("3000");

                    long lastTime = 0L;
                    if (Runtime.CurrentTimeMillis(false) - lastTime >= 3000L)
                    {
                        textValue.SetText(FreeUtil.ReplaceVar(err, args));
                        update.DoAction(args);
                        show.DoAction(args);
                        lastTime = Runtime.CurrentTimeMillis(false);
                    }
                }
            }
            finally
            {
                SingletonManager.Get <DurationHelp>().ProfileEnd(actName);
            }
            FreeTimeDebug.RecordEnd(this.GetType().Name, startTime);
            FreeLog.Stop(s, this, args);
        }
        public void CreateUnitedInstance(InstancingDraw[] instancingData)
        {
            if (instancingData[0].State == InstancingDrawState.NotInitialized || _newInstanceCountLimit)
            {
                var dataLength = instancingData.Length;
                for (int i = 0; i < dataLength; ++i)
                {
                    instancingData[i].SetInstancingFullSizeParam(_cachedNodes.Length, _maxInstanceCountPerRenderInUnit[i]);
                }
            }

            if (_previousInstantiatingNode != null)
            {
                if (_previousInstantiatingNode.IsDuringInstantiation)
                {
                    _previousInstantiatingNode.SetInstantiated();
                    var count = _cachedNodes.Length;
                    var index = 0;
                    for (; index < count; ++index)
                    {
                        if (_cachedNodes[index] == null)
                        {
                            _cachedNodes[index] = _previousInstantiatingNode;

                            if (index >= _cachedNodesActualLength)
                            {
                                _cachedNodesActualLength = index + 1;
                            }

                            break;
                        }
                    }

                    if (index == count)
                    {
                        _logger.Error("Full Exception");
                    }

                    if (!_newInstanceCountLimit)
                    {
                        ReplaceBuffer(_previousInstantiatingNode.Node, index, instancingData);
                    }
                }
                else
                {
                    _previousInstantiatingNode.Node.ReleaseBuffer();
                }

                _previousInstantiatingNode = null;
            }

            if (_newInstanceCountLimit)
            {
                for (int i = 0; i < _cachedNodesActualLength; ++i)
                {
                    if (_cachedNodes[i] != null)
                    {
                        ReplaceBuffer(_cachedNodes[i].Node, i, instancingData);
                    }
                }

                _newInstanceCountLimit = false;
            }

            if (_curInstantiatingNode != null)
            {
                _previousInstantiatingNode = _curInstantiatingNode;
                _curInstantiatingNode      = null;
            }

            var drawCount = instancingData.Length;

            for (int i = 0; i < drawCount; ++i)
            {
                if (instancingData[i].State == InstancingDrawState.Enable)
                {
                    instancingData[i].ClearRealBlockCount();

                    bool canShrink = true;
                    for (int j = _cachedNodesActualLength; j > 0; --j)
                    {
                        var index = j - 1;
                        var node  = _cachedNodes[index];
                        if (node != null)
                        {
                            if (node.IsOutOfRange)
                            {
                                _cachedNodes[index] = null;

                                if (canShrink)
                                {
                                    _cachedNodesActualLength = j - 1;
                                }

                                continue;
                            }

                            if (node.IsActive)
                            {
                                var realCount = node.Node.GetInstancingDataCount(i);
                                instancingData[i].SetRealBlockCount(index, realCount);
                            }

                            canShrink = false;
                        }
                    }
                }
            }
        }
        public void OnLoadSucc(object source, AssetInfo assetInfo, UnityEngine.Object obj)
        {
            var asset = obj as TextAsset;

            if (null == asset)
            {
                Logger.ErrorFormat("Asset {0}:{1} Load Fialed ", assetInfo.BundleName, assetInfo.AssetName);
                return;
            }
            if (string.IsNullOrEmpty(asset.text))
            {
                Logger.ErrorFormat("MapConfig is Empty");
                return;
            }

            MapConfig cfg = null;

            try
            {
                cfg = XmlConfigParser <MapConfig> .Load(asset.text);
            }
            catch (Exception e)
            {
                Logger.Error("Parse MapConfig Error", e);
                return;
            }
            Logger.InfoFormat("OnLoadSucc mapInfo count:{0}", cfg.MapInfos.Count);
            SceneParameters = null;
            _mapConfig      = cfg;
            foreach (var v in cfg.MapInfos)
            {
                if (v.Id == _mapId)
                {
                    SceneParameters = v;

                    _zone = new ZoneController();
                    _zone.AddZone(SceneParameters.SpecialZones);

                    IOperationAfterConfigLoaded op = null;
                    if (SceneParameters is LevelConfig)
                    {
                        op = new LevelInit(SingletonManager.Get <TriggerObjectManager>());
                    }
                    else if (SceneParameters is SceneConfig)
                    {
                        op = new TerrainInit(SingletonManager.Get <TriggerObjectManager>());
                    }

                    if (op != null)
                    {
                        if (SharedConfig.IsServer)
                        {
                            op.ServerOperation(v, _callBack);
                        }
                        else
                        {
                            op.ClientOperation(v, _callBack);
                        }

                        foreach (var req in op.LoadInitialScene())
                        {
                            _loadedMapNames.Add(req.Address.AssetName);
                            _loadSceneHandler.AddSceneRequest(req);
                        }
                    }

                    break;
                }
            }

            if (SceneParameters == null)
            {
                Logger.ErrorFormat("mapId:{0} is invalid", _mapId);
            }
        }
 public override void SetStatisticData(GameOverPlayer gameOverPlayer, IPlayerInfo playerInfo, IFreeArgs freeArgs)
 {
     gameOverPlayer.Id = playerInfo.PlayerId;
     if (null == playerInfo.StatisticsData)
     {
         Logger.Error("player's statisticsData is null ");
         return;
     }
     gameOverPlayer.Score = playerInfo.StatisticsData.KillCount;
     foreach (EStatisticsID eId in Enum.GetValues(typeof(EStatisticsID)))
     {
         gameOverPlayer.Statistics.Add((int)eId, 0);
     }
     gameOverPlayer.Statistics[(int)EStatisticsID.KillCount]           = playerInfo.StatisticsData.KillCount;
     gameOverPlayer.Statistics[(int)EStatisticsID.HitDownCount]        = playerInfo.StatisticsData.HitDownCount;
     gameOverPlayer.Statistics[(int)EStatisticsID.PlayerDamage]        = (int)playerInfo.StatisticsData.PlayerDamage;
     gameOverPlayer.Statistics[(int)EStatisticsID.TotalDamage]         = (int)playerInfo.StatisticsData.TotalDamage;
     gameOverPlayer.Statistics[(int)EStatisticsID.ShootingCount]       = playerInfo.StatisticsData.ShootingCount;
     gameOverPlayer.Statistics[(int)EStatisticsID.ShootingSuccCount]   = playerInfo.StatisticsData.ShootingSuccCount;
     gameOverPlayer.Statistics[(int)EStatisticsID.ShootingPlayerCount] = playerInfo.StatisticsData.ShootingPlayerCount;
     gameOverPlayer.Statistics[(int)EStatisticsID.CritCount]           = playerInfo.StatisticsData.CritCount;
     gameOverPlayer.Statistics[(int)EStatisticsID.TotalMoveDistance]   = (int)playerInfo.StatisticsData.TotalMoveDistance;
     gameOverPlayer.Statistics[(int)EStatisticsID.VehicleMoveDistance] = (int)playerInfo.StatisticsData.VehicleMoveDistance;
     gameOverPlayer.Statistics[(int)EStatisticsID.AssistCount]         = playerInfo.StatisticsData.AssistCount;
     gameOverPlayer.Statistics[(int)EStatisticsID.CureVolume]          = (int)playerInfo.StatisticsData.CureVolume;
     gameOverPlayer.Statistics[(int)EStatisticsID.AccSpeedTime]        = playerInfo.StatisticsData.AccSpeedTime;
     gameOverPlayer.Statistics[(int)EStatisticsID.SaveCount]           = playerInfo.StatisticsData.SaveCount;
     gameOverPlayer.Statistics[(int)EStatisticsID.TotalBeDamage]       = (int)playerInfo.StatisticsData.TotalBeDamage;
     gameOverPlayer.Statistics[(int)EStatisticsID.DefenseDamage]       = (int)playerInfo.StatisticsData.DefenseDamage;
     gameOverPlayer.Statistics[(int)EStatisticsID.DeadCount]           = playerInfo.StatisticsData.DeadCount;
     gameOverPlayer.Statistics[(int)EStatisticsID.KillDistance]        = (int)playerInfo.StatisticsData.MaxKillDistance;
     gameOverPlayer.Statistics[(int)EStatisticsID.DestroyVehicle]      = playerInfo.StatisticsData.DestroyVehicle;
     gameOverPlayer.Statistics[(int)EStatisticsID.UseThrowingCount]    = playerInfo.StatisticsData.UseThrowingCount;
     gameOverPlayer.Statistics[(int)EStatisticsID.IsFullArmed]         = playerInfo.StatisticsData.IsFullArmed ? 1 : 0;
     gameOverPlayer.Statistics[(int)EStatisticsID.EvenKillCount]       = playerInfo.StatisticsData.MaxEvenKillCount;
     gameOverPlayer.Statistics[(int)EStatisticsID.SwimTime]            = playerInfo.StatisticsData.SwimTime;
     gameOverPlayer.Statistics[(int)EStatisticsID.Drown]               = playerInfo.StatisticsData.Drown ? 1 : 0;
     gameOverPlayer.Statistics[(int)EStatisticsID.PoisionDead]         = playerInfo.StatisticsData.PoisionDead ? 1 : 0;
     gameOverPlayer.Statistics[(int)EStatisticsID.DropDead]            = playerInfo.StatisticsData.DropDead ? 1 : 0;
     gameOverPlayer.Statistics[(int)EStatisticsID.KillByVehicle]       = playerInfo.StatisticsData.KillByVehicle ? 1 : 0;
     gameOverPlayer.Statistics[(int)EStatisticsID.KillByPlayer]        = playerInfo.StatisticsData.KillByPlayer ? 1 : 0;
     gameOverPlayer.Statistics[(int)EStatisticsID.KillByAirBomb]       = playerInfo.StatisticsData.KillByAirBomb ? 1 : 0;
     gameOverPlayer.Statistics[(int)EStatisticsID.KillByRifle]         = playerInfo.StatisticsData.KillWithRifle;
     gameOverPlayer.Statistics[(int)EStatisticsID.KillByMachineGun]    = playerInfo.StatisticsData.KillWithMachineGun;
     gameOverPlayer.Statistics[(int)EStatisticsID.KillBySubMachineGun] = playerInfo.StatisticsData.KillWithSubmachineGun;
     gameOverPlayer.Statistics[(int)EStatisticsID.KillByThrowWeapon]   = playerInfo.StatisticsData.KillWithThrowWeapon;
     gameOverPlayer.Statistics[(int)EStatisticsID.KillByMelee]         = playerInfo.StatisticsData.KillWithMelee;
     gameOverPlayer.Statistics[(int)EStatisticsID.KillByPistol]        = playerInfo.StatisticsData.KillWithPistol;
     gameOverPlayer.Statistics[(int)EStatisticsID.KillBySniper]        = playerInfo.StatisticsData.KillWithSniper;
     gameOverPlayer.Statistics[(int)EStatisticsID.KillByShotGun]       = playerInfo.StatisticsData.KillWithShotGun;
     gameOverPlayer.Statistics[(int)EStatisticsID.GameTime]            = playerInfo.StatisticsData.GameTime;
     gameOverPlayer.Statistics[(int)EStatisticsID.GameCount]           = playerInfo.StatisticsData.IsRunaway ? 0 : 1;
     gameOverPlayer.Statistics[(int)EStatisticsID.CritKillCount]       = playerInfo.StatisticsData.CritKillCount;
     gameOverPlayer.Statistics[(int)EStatisticsID.GetFirstBlood]       = playerInfo.StatisticsData.GetFirstBlood ? 1 : 0;
     if (((PlayerEntity)playerInfo.PlayerEntity).gamePlay.LifeState != (int)EPlayerLifeState.Alive)
     {
         playerInfo.StatisticsData.DeadTime += (int)System.DateTime.Now.Ticks / 10000 - playerInfo.StatisticsData.LastDeadTime;
     }
     gameOverPlayer.Statistics[(int)EStatisticsID.DeadTime] = playerInfo.StatisticsData.DeadTime;
     AddHonorData(gameOverPlayer, playerInfo);
     PlayerReportTrigger(gameOverPlayer, playerInfo, freeArgs);
 }
        private static List <PlayerEntity> OnePlayerHealthDamage(Contexts contexts, IGameRule gameRule, PlayerEntity srcPlayer, PlayerEntity playerEntity, PlayerDamageInfo damage, bool isTeam)
        {
            GamePlayComponent gamePlay = playerEntity.gamePlay;

            if (gamePlay.IsDead())
            {
                return(null);
            }

            float realDamage = gameRule == null ? damage.damage : gameRule.HandleDamage(srcPlayer, playerEntity, damage);

            WeaponResConfigItem weaponConfig = SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(damage.weaponId);

            if (srcPlayer != null)
            {
                try
                {
                    //受伤梯形标记
                    if (SharedConfig.IsServer)
                    {
                        if (damage.type == (int)EUIDeadType.Weapon || damage.type == (int)EUIDeadType.Unarmed)
                        {
                            if (weaponConfig != null && weaponConfig.SubType != (int)EWeaponSubType.Grenade)
                            {
                                BulletStatisticsUtil.SetPlayerDamageInfoS(srcPlayer, playerEntity, realDamage, (EBodyPart)damage.part);
                            }
                        }
                    }
                    else
                    {
                        BulletStatisticsUtil.SetPlayerDamageInfoC(srcPlayer, playerEntity, realDamage, (EBodyPart)damage.part);
                    }
                }
                catch (Exception e)
                {
                    _logger.Error("受伤梯形标记", e);
                }
            }

            if (!SharedConfig.IsOffline && !SharedConfig.IsServer)
            {
                return(null);
            }

            if (!playerEntity.hasStatisticsData)
            {
                return(null);
            }

            StatisticsData statisticsData = playerEntity.statisticsData.Statistics;


            var now = gameRule == null ? playerEntity.time.ClientTime : gameRule.ServerTime;

            if (now - statisticsData.LastHitDownTime <= 1000 && !damage.InstantDeath)
            {
                return(null);
            }

            damage.damage = gamePlay.DecreaseHp(realDamage);

            //玩家状态
            List <PlayerEntity> teamList = CheckUpdatePlayerStatus(playerEntity, damage, isTeam ? null : contexts, (int)now);

            //保存最后伤害来源
            if (statisticsData.DataCollectSwitch)
            {
                try
                {
                    if (gamePlay.IsLastLifeState(EPlayerLifeState.Alive))
                    {
                        //statisticsData.IsHited = true;
                        statisticsData.LastHurtKey      = null != srcPlayer ? srcPlayer.entityKey.Value : EntityKey.Default;
                        statisticsData.LastHurtType     = damage.type;
                        statisticsData.LastHurtPart     = damage.part;
                        statisticsData.LastHurtWeaponId = damage.weaponId;
                    }

                    //击倒人头
                    if ((gamePlay.IsLifeState(EPlayerLifeState.Dying) || gamePlay.IsDead()) &&
                        (damage.type == (int)EUIDeadType.NoHelp || damage.type == (int)EUIDeadType.Poison || damage.type == (int)EUIDeadType.Bomb ||
                         damage.type == (int)EUIDeadType.Drown || damage.type == (int)EUIDeadType.Bombing || damage.type == (int)EUIDeadType.Fall))
                    {
                        PlayerEntity lastEntity = contexts.player.GetEntityWithEntityKey(statisticsData.LastHurtKey);
                        if (null != lastEntity)
                        {
                            srcPlayer = lastEntity;
                            if (srcPlayer.playerInfo.TeamId == playerEntity.playerInfo.TeamId)
                            {
                                damage.type     = statisticsData.LastHurtType;
                                damage.part     = statisticsData.LastHurtPart;
                                damage.weaponId = statisticsData.LastHurtWeaponId;
                            }
                            else
                            {
                                damage.type = (int)EUIDeadType.NoHelp;
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    _logger.Error("计算玩家战报信息失败", e);
                }

                if (gamePlay.IsHitDown())
                {
                    try
                    {
                        statisticsData.LastHitDownTime = now;
                        SimpleProto message = FreePool.Allocate();
                        message.Key = FreeMessageConstant.ScoreInfo;
                        int feedbackType = 0;
                        message.Ks.Add(3);
                        message.Bs.Add(true);
                        if (null != srcPlayer)
                        {
                            if (srcPlayer.playerInfo.TeamId != playerEntity.playerInfo.TeamId)
                            {
                                feedbackType |= 1 << (int)EUIKillFeedbackType.Hit;
                            }
                            message.Ss.Add(srcPlayer.playerInfo.PlayerName);
                            message.Ds.Add(srcPlayer.playerInfo.TeamId);
                            message.Ins.Add(damage.weaponId);
                        }
                        else
                        {
                            message.Ss.Add("");
                            message.Ds.Add(-1);
                            message.Ins.Add(0);
                        }
                        message.Ins.Add((int)EUIKillType.Hit);
                        message.Ins.Add(feedbackType);
                        message.Ss.Add(playerEntity.playerInfo.PlayerName);
                        message.Ds.Add(playerEntity.playerInfo.TeamId);
                        message.Ins.Add(damage.type);
                        SendMessageAction.sender.SendMessage(contexts.session.commonSession.FreeArgs as IEventArgs, message, 4, string.Empty);
                    }
                    catch (Exception e)
                    {
                        _logger.Error("计算玩家ScoreInfo信息失败", e);
                    }
                }

                if (gamePlay.IsDead())
                {
                    try
                    {
                        //UI击杀信息
                        int killType = 0;
                        if (damage.part == (int)EBodyPart.Head)
                        {
                            killType |= (int)EUIKillType.Crit;
                        }
                        damage.KillType = killType;
                        playerEntity.playerInfo.SpecialFeedbackType = 0;
                        //UI击杀反馈
                        if (null != srcPlayer && srcPlayer.playerInfo.TeamId != playerEntity.playerInfo.TeamId)
                        {
                            int feedbackType = 0;
                            if (damage.part == (int)EBodyPart.Head)
                            {
                                //爆头
                                feedbackType |= 1 << (int)EUIKillFeedbackType.CritKill;
                            }
                            if (damage.IsOverWall)
                            {
                                //穿墙击杀
                                feedbackType |= 1 << (int)EUIKillFeedbackType.ThroughWall;
                            }
                            if (SharedConfig.IsServer && null != gameRule && contexts.session.serverSessionObjects.DeathOrder == 0 && srcPlayer.playerInfo.TeamId != playerEntity.playerInfo.TeamId)
                            {
                                //一血
                                feedbackType |= 1 << (int)EUIKillFeedbackType.FirstBlood;
                            }
                            if (playerEntity.playerInfo.PlayerId == srcPlayer.statisticsData.Statistics.RevengeKillerId)
                            {
                                //复仇
                                feedbackType |= 1 << (int)EUIKillFeedbackType.Revenge;
                                srcPlayer.statisticsData.Statistics.RevengeKillerId = 0L;
                            }
                            if (srcPlayer.gamePlay.JobAttribute == (int)EJobAttribute.EJob_Hero)
                            {
                                //英雄击杀
                                feedbackType |= 1 << (int)EUIKillFeedbackType.HeroKO;
                                playerEntity.playerInfo.SpecialFeedbackType = (int)EUIKillFeedbackType.HeroKO;
                            }
                            //武器
                            if (null != weaponConfig)
                            {
                                switch ((EWeaponSubType)weaponConfig.SubType)
                                {
                                case EWeaponSubType.Melee:
                                    feedbackType |= 1 << (int)EUIKillFeedbackType.MeleeWeapon;
                                    playerEntity.playerInfo.SpecialFeedbackType = (int)EUIKillFeedbackType.MeleeWeapon;
                                    break;

                                case EWeaponSubType.BurnBomb:
                                    feedbackType |= 1 << (int)EUIKillFeedbackType.Burning;
                                    break;

                                case EWeaponSubType.Grenade:
                                    feedbackType |= 1 << (int)EUIKillFeedbackType.Grenade;
                                    break;

                                default:
                                    break;
                                }
                            }
                            if (feedbackType == 0)
                            {
                                //普通击杀
                                feedbackType = 1 << (int)EUIKillFeedbackType.Normal;
                            }
                            damage.KillFeedbackType = feedbackType;
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.Error("计算玩家战报信息失败", e);
                    }
                }

                //数据统计
                ProcessDamageStatistics(contexts, gameRule, srcPlayer, playerEntity, damage);
            }

            //击杀|击倒
            if (gamePlay.IsDead())
            {
                gameRule.KillPlayer(srcPlayer, playerEntity, damage);
                try
                {
                    if (damage.HitPoint != Vector3.zero && damage.HitDirection != Vector3.zero && playerEntity.hasRagDoll)
                    {
                        playerEntity.ragDoll.ForceAtPosition = Vector3.zero;
                        switch (damage.type)
                        {
                        case (int)EUIDeadType.Weapon:
                            var config = SingletonManager.Get <WeaponConfigManagement>().FindConfigById(damage.weaponId);
                            if (weaponConfig.Type == (int)EWeaponType_Config.ThrowWeapon)
                            {
                                playerEntity.ragDoll.RigidBodyTransformName = "Bip01 Spine1";
                                playerEntity.ragDoll.Impulse = (damage.HitDirection.normalized + new Vector3(0, 1.732f)).normalized *
                                                               config.S_Ragdoll.RagdollForce * DamageFactor(realDamage);
                            }
                            else
                            {
                                foreach (var pair in Joint2BodyPart)
                                {
                                    if (pair.Value == (EBodyPart)damage.part)
                                    {
                                        playerEntity.ragDoll.RigidBodyTransformName = pair.Key.Substring(0, pair.Key.LastIndexOf("_"));
                                        break;
                                    }
                                }

                                playerEntity.ragDoll.Impulse = damage.HitDirection.normalized * config.S_Ragdoll.RagdollForce *
                                                               DamageFactor(realDamage);
                            }

                            break;

                        default:
                            var explosionConfig = SingletonManager.Get <WeaponConfigManagement>().FindConfigById(46);
                            playerEntity.ragDoll.RigidBodyTransformName = "Bip01 Spine1";
                            playerEntity.ragDoll.Impulse = (damage.HitDirection.normalized + new Vector3(0, 1.732f)).normalized *
                                                           explosionConfig.S_Ragdoll.RagdollForce * DamageFactor(realDamage);
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    _logger.Error("计算玩家死亡ragdoll运动信息失败", e);
                }
            }

            //_logger.DebugFormat("change player hp entityId:{0}, health {1}->{2}, state {3}, srcPlayerId:{4}, playerId:{5}, hurtType:{6}, weaponId:{7}",
            //    playerEntity.entityKey.Value.EntityId, playerEntity.gamePlay.CurHp, playerEntity.gamePlay.CurHp, playerEntity.gamePlay.LifeState, (srcPlayer != null) ? srcPlayer.playerInfo.PlayerId : 0, playerEntity.playerInfo.PlayerId, damage.type, damage.weaponId);
            return(teamList);
        }
        public Vector3 GetAnchorPosition(PlayerEntity player, ECameraArchorType type)
        {
            player.cameraArchor.Active = true;
            switch (type)
            {
            case ECameraArchorType.Car:
                eCameraPositionArchorType = ECameraArchorType.Car;
                var t = player.controlledVehicle.CameraCurrentPosition;
                return(new Vector3(t.x, t.y, t.z));

            case ECameraArchorType.AirPlane:
                eCameraPositionArchorType = ECameraArchorType.AirPlane;
                return(player.GetAirPlane(_freeMoveContext).position.Value);

            case ECameraArchorType.FollowEntity:
                eCameraPositionArchorType = ECameraArchorType.FollowEntity;
                PlayerEntity follow = _playerContext.GetEntityWithEntityKey(new Core.EntityComponent.EntityKey(player.gamePlay.CameraEntityId, (short)EEntityType.Player));
                if (follow != null)
                {
                    return(follow.position.Value);
                }
                else
                {
                    return(player.position.Value);
                }

            case ECameraArchorType.Parachuting:
                eCameraPositionArchorType = ECameraArchorType.Parachuting;
                return(player.playerSkyMove.Position.ShiftedVector3());

            case ECameraArchorType.Witness:
                if (ECameraArchorType.Witness != eCameraPositionArchorType)
                {
                    PlayerEntity cameraEntity = _playerContext.GetEntityWithEntityKey(new Core.EntityComponent.EntityKey(player.gamePlay.CameraEntityId, (short)EEntityType.Player));
                    if (cameraEntity != null)
                    {
                        _freePosition = cameraEntity.position.Value;
                    }
                    else
                    {
                        _freePosition = player.position.Value;
                    }
                }
                eCameraPositionArchorType = ECameraArchorType.Witness;
                return /*Vector3.zero*/ (UpdateFreeTransition());

            default:
                eCameraPositionArchorType = ECameraArchorType.Default;
                if (player.hasAppearanceInterface && player.appearanceInterface.Appearance.IsFirstPerson)
                {
                    var camRoot = player.characterBoneInterface.CharacterBone.GetLocation(SpecialLocation
                                                                                          .FirstPersonCamera, CharacterView.FirstPerson);
                    if (null != camRoot)
                    {
                        return(camRoot.position);
                    }
                    else
                    {
                        Logger.Error("First camera root can't be found");
                    }
                }
                return(player.position.Value);
            }
        }
        public override void Initialize(ClientEffectEntity entity)
        {
            var offset = 0.001f;
            var normal = entity.normal.Value;
            var go     = entity.assets.FirstAsset;

            if (!go)
            {
                return;
            }
            go.transform.SetPositionAndRotation(entity.position.Value + offset * normal,
                                                Quaternion.FromToRotation(Vector3.forward, normal));
            go.transform.localScale = GlobalConst.LocalScale;
            if (entity.hasAttachParent)
            {
                switch ((EEntityType)entity.attachParent.ParentKey.EntityType)
                {
                case EEntityType.Vehicle:
                    var vehicle = AllContexts.vehicle.GetEntityWithEntityKey(entity.attachParent.ParentKey);
                    if (vehicle != null && vehicle.hasGameObject && null != vehicle.gameObject.UnityObject)
                    {
                        go.transform.SetParent(vehicle.gameObject.UnityObject.AsGameObject.transform, false);
                        go.transform.localPosition = entity.attachParent.Offset;
                    }
                    else
                    {
                        Logger.Error("vehicle gameobject does not exist");
                    }

                    break;
                    // case EEntityType.Player:
                    //     var player = AllContexts.player.GetEntityWithEntityKey(entity.attachParent.ParentKey);
                    //     if (player !=null && player.hasBones && null != player.bones.Spine)
                    //     {
                    //         go.transform.SetParent(player.bones.Spine.transform, false);
                    //         go.transform.localPosition = entity.attachParent.Offset;
                    //     }
                    //     else
                    //     {
                    //         Logger.Error("player sprine bones doesn't exist !");
                    //     }
                    //
                    //     break;
                    // case EEntityType.SceneObject:
                    //     var trunkId = entity.attachParent.FragmentId;
                    //     var sceneObj = AllContexts.sceneObject.GetEntityWithEntityKey(entity.attachParent.ParentKey);
                    //     if (null == sceneObj)
                    //     {
                    //         entity.isFlagDestroy = true;
                    //     }
                    //     else
                    //     {
                    //         if (sceneObj.hasRawGameObject && null != sceneObj.rawGameObject)
                    //         {
                    //             var fracturedObject = sceneObj.rawGameObject.Value.GetComponent<FracturedObject>();
                    //             if (trunkId > -1 && trunkId < fracturedObject.ListFracturedChunks.Count)
                    //             {
                    //                 var trunk = fracturedObject.ListFracturedChunks[trunkId];
                    //                 if (null != trunk)
                    //                 {
                    //                     var transform = trunk.transform;
                    //                     go.transform.SetParent(transform, false);
                    //                     go.transform.localPosition = entity.attachParent.Offset + normal * 0.01f;
                    //                 }
                    //             }
                    //         }
                    //         else
                    //         {
                    //             Logger.Error("target scene object has no rawgameobject");
                    //         }
                    //     }
                    //
                    //     break;
                }
            }
            go.SetActive(true);
        }
Exemple #11
0
        public static string GetMaterialByHit(RaycastHit hit)
        {
            var go           = hit.transform.gameObject;
            var meshRenderer = go.GetComponent <MeshRenderer>();

            if (null == meshRenderer || !meshRenderer.enabled)
            {
                return(string.Empty);
            }
            //只有一种材质不需要进行submesh的检测
            var matCount = meshRenderer.sharedMaterials.Length;

            if (matCount == 1)
            {
                return(meshRenderer.sharedMaterials[0].name);
            }
            if (hit.triangleIndex < 0)
            {
                Logger.WarnFormat("illegal triagnle index {0}, mesh collder {1} should not be convex", hit.triangleIndex, hit.transform.name);
                return(string.Empty);
            }

            var mesh = GetMesh(hit);

            if (null == mesh)
            {
                Logger.ErrorFormat("No mesh attached to {0}", go);
                return(string.Empty);
            }

            var startIndex   = hit.triangleIndex * 3;
            var hitTriangles = new int[]
            {
                mesh.triangles[startIndex],
                mesh.triangles[startIndex + 1],
                mesh.triangles[startIndex + 2],
            };

            for (int i = 0; i < mesh.subMeshCount; i++)
            {
                var subMeshTris = mesh.GetTriangles(i);
                for (int j = 0; j < subMeshTris.Length; j += 3)
                {
                    if (subMeshTris[j] == hitTriangles[0] && subMeshTris[j + 1] == hitTriangles[1] &&
                        subMeshTris[j + 2] == hitTriangles[2])
                    {
                        var mat = GetMaterial(go, i);
                        if (null != mat)
                        {
                            return(mat.name);
                        }
                        else
                        {
                            Logger.Error("Get material failed ");
                        }
                    }
                }
            }
            Logger.WarnFormat("No matched triangle ");
            return(string.Empty);
        }
Exemple #12
0
        private void GoLoaded(UnityObject unityObj)
        {
            --_concurrentCount;
            if (_loadingGoes.ContainsKey(unityObj.Address))
            {
                var loadingGo = _loadingGoes[unityObj.Address].Dequeue();
                var sceneName = _sceneDescription.Scenes[loadingGo.SceneIndex].SceneName;

                if (_unloadingScene.ContainsKey(sceneName))
                {
                    _unloadingScene[sceneName].Enqueue(unityObj);
                    RequestForUnload();
                }
                else
                {
                    _streamingGo.GoLoaded(loadingGo.SceneIndex, loadingGo.GoIndex, unityObj);
                    var data = _sceneDescription.Scenes[loadingGo.SceneIndex].Objects[loadingGo.GoIndex];
                    var go   = unityObj.AsGameObject;
                    go.transform.localPosition    = data.Position.ShiftedPosition();
                    go.transform.localEulerAngles = data.Rotation;
                    go.transform.localScale       = data.Scale;
                    unityObj.SceneObjAttr.Id      = data.Id;

                    Transform prefabTf = null;
                    if (go.transform.childCount > 0)
                    {
                        prefabTf = go.transform.GetChild(0);

                        // 还原各个 AbstractSaveMono
                        string errorStr = data.LoadCompDatas(prefabTf);
                        if (!string.IsNullOrEmpty(errorStr))
                        {
                            _logger.Error(errorStr);
                        }
                    }

                    if (!loadedGoes.ContainsKey(data.Id))
                    {
                        loadedGoes.Add(data.Id, go);
                    }

                    if (!SharedConfig.IsServer)
                    {
                        // 烘焙贴图数据的复原
                        TryApplyLightmaps(data.Id);

                        // 室内灯光剔除组件的应用
                        IndoorCullRecord indoorCullRecord;
                        _scenesIndoorCullRecords.recordsDict.TryGetValue(data.Id, out indoorCullRecord);
                        if (indoorCullRecord != null)
                        {
                            HouseLightsCull cull = go.GetComponent <HouseLightsCull>();
                            if (cull == null)
                            {
                                cull = go.gameObject.AddComponent <HouseLightsCull>();
                            }
                            cull.Clear();
                            cull.id              = indoorCullRecord.id;
                            cull.bakeId          = indoorCullRecord.bakeId;
                            cull.bound           = indoorCullRecord.bounds;
                            cull.lightIndexes    = indoorCullRecord.lights;
                            cull.refProbeIndexes = indoorCullRecord.refProbes;
                            cull.SetGetLightsFunc(GetLightsFun);
                            cull.SetGetRefProbesFunc(GetReflectionProbesFun);
                        }
                    }
                    if (hideImportObject)
                    {
                        checkObjectVisible(go, data);
                    }
                    RequestForLoad();
                }
            }
        }
Exemple #13
0
        protected override void DoSetData(PointerData data)
        {
            _pointerData = data;
            var entityId = SceneObjCastData.EntityId(_pointerData.IdList);
            var sceneObj = _sceneObjectContext.GetEntityWithEntityKey(new Core.EntityComponent.EntityKey(entityId, (short)EEntityType.SceneObject));

            if (null != sceneObj)
            {
                if (!sceneObj.hasPosition)
                {
                    Logger.Error("sceneobject has no postion");
                    return;
                }
                var player = _playerContext.flagSelfEntity;
                if (!player.hasPosition)
                {
                    Logger.Error("player has no position");
                    return;
                }
                if (IsUntouchable(sceneObj, player))
                {
                    return;
                }
                if (!sceneObj.IsCanPickUpByPlayer(player))
                {
                    return;
                }
                if (player.hasGamePlay && !player.gamePlay.CanAutoPick())
                {
                    return;
                }
            }
            else
            {
                return;
            }
            var itemId   = SceneObjCastData.ItemId(_pointerData.IdList);
            var count    = SceneObjCastData.Count(_pointerData.IdList);
            var category = SceneObjCastData.Category(_pointerData.IdList);

            switch ((ECategory)category)
            {
            case ECategory.Weapon:
                var itemCfg = SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(itemId);
                if (null != itemCfg)
                {
                    if (itemCfg.Type == (int)EWeaponType_Config.ThrowWeapon)
                    {
                        Tip = string.Format(ScriptLocalization.client_actiontip.pickup, itemCfg.Name, string.Format("({0})", count));
                    }
                    else
                    {
                        Tip = string.Format(ScriptLocalization.client_actiontip.pickandequip, itemCfg.Name);
                    }
                }
                else
                {
                    Tip = string.Format("weapon {0} doesn't exist ", itemId);
                }
                break;

            case ECategory.Avatar:
                var equip = SingletonManager.Get <RoleAvatarConfigManager>().GetConfigById(itemId);
                if (null != equip)
                {
                    Tip = string.Format(ScriptLocalization.client_actiontip.pickandequip, equip.Name);
                }
                else
                {
                    Tip = string.Format("avatar {0} doesn't exist ", itemId);
                }
                break;

            case ECategory.WeaponPart:
                var part = SingletonManager.Get <WeaponPartSurvivalConfigManager>().FindConfigBySetId(itemId);
                if (null != part)
                {
                    Tip = string.Format(ScriptLocalization.client_actiontip.pickup, part.Name, "");
                }
                else
                {
                    Tip = string.Format("part {0} doesn't exist", itemId);
                }
                break;

            case ECategory.GameItem:
                var item = SingletonManager.Get <GameItemConfigManager>().GetConfigById(itemId);
                if (null != item)
                {
                    Tip = string.Format(ScriptLocalization.client_actiontip.pickup, item.Name, string.Format("({0})", count));
                }
                else
                {
                    Tip = string.Format("item {0} doesn't exist", itemId);
                }
                break;

            default:
                Tip = string.Format("EntityId {0} ItemId {1} do not exist in config ", entityId, itemId);
                break;
            }
        }
Exemple #14
0
        public void AddMessage(BroadcastMessageData data)
        {
            var tf = GetNewMessageItem();

            if (tf != null && data != null && data.ChatMessage != null)
            {
                if (TargetIdDict != null)
                {
                    if (!TargetIdDict.ContainsKey(data.SendRoleId))
                    {
                        TargetIdDict[data.SendRoleId] = string.Empty;
                    }
                    TargetIdDict[data.SendRoleId] = data.SendRoleName;
                }

                if (data.SendRoleId == 0)
                {
                    tf.GetComponent <Text>().text = data.ChatMessage.Message;
                }
                else
                {
                    tf.GetComponent <Text>().text = data.SendRoleName + ":" + data.ChatMessage.Message;
                }
                if (data.ChatType == (int)ChatType.PrivateChat)
                {
                    long privateChatId = 0;
                    if (data.SendRoleId == _chatState.MyselfId)
                    {
                        privateChatId = data.TargetId;
                        tf.GetComponent <Text>().text = string.Format(ScriptLocalization.hall_chat.word231,
                                                                      TargetIdDict[privateChatId]) + data.ChatMessage.Message;
                        PrivateChatRecentUseQueueUpdate(privateChatId);
                    }
                    else
                    {
                        privateChatId = data.SendRoleId;
                        PrivateChatRecentUseQueueUpdate(privateChatId);
                    }
                    if (ChatListState != EUIChatListState.Send)
                    {
                        _curChannel = ChatChannel.PrivateChat;
                        SetPrivateTarget(privateChatId);
                        UpdateChannel();
                    }
                }

                if (data.SendRoleId > 0)
                {
                    tf.GetComponent <Text>().color = UiCommonColor.GetChatChannelColor(ChatTypeToChannel((ChatType)data.ChatType));
                }
                else
                {
                    tf.GetComponent <Text>().color = Color.red;
                }
            }
            else
            {
                Logger.Error("Null object,can't addMessage");
            }
            ResetTime();
            _closeViewAnim.Rewind();
            if (messageDict != null)
            {
                if (ChatListState == EUIChatListState.None)
                {
                    ChatListState = EUIChatListState.Receive;
                }
                messageDict.Add(tf, data);
            }
        }
        public bool TerrainLoaded(TextAsset asset, UnityEngine.Terrain setting, float detailDistance, Vector3 basePos)
        {
            var data = setting.terrainData;
            // ignore version
            int dataIndex = 2;

            int        heightMapResolution = 0;
            int        detailResolution    = 0;
            int        detailCount         = 0;
            List <int> maxCountInLayer     = new List <int>();

            unsafe
            {
                var     head     = new IntPtr(asset.GetBytesIntPtr().ToInt64() + dataIndex);
                ushort *flowData = (ushort *)head.ToPointer();

                heightMapResolution = *flowData++;
                detailResolution    = *flowData++;
                _nodeSize           = *flowData++;
                detailCount         = *flowData++;
                for (int i = 0; i < detailCount; ++i)
                {
                    maxCountInLayer.Add(*flowData++);
                }

                dataIndex += 2 * (4 + detailCount);
            }

            var division   = detailResolution / _nodeSize;
            var prototypes = data.detailPrototypes;

            if (heightMapResolution != data.heightmapResolution || detailResolution != data.detailResolution ||
                detailCount != prototypes.Length)
            {
                _logger.WarnFormat("unmatch param in detail: heightMapResolution -> {0}:{1}, detailResolution -> {2}:{3}, detailCount -> {4}:{5}",
                                   data.heightmapResolution, heightMapResolution, data.detailResolution, detailResolution, prototypes.Length, detailCount);
                return(false);
            }

            if (detailCount == 0)
            {
                _logger.Error("no grass prototypes exists");
                return(false);
            }

            if (_instancingDraw == null)
            {
                _instancingDraw = new DetailInstancingDraw[detailCount];
            }

            if (detailCount != _instancingDraw.Length)
            {
                _logger.ErrorFormat("unmatch grass count: unique->{0} other->{1}", detailCount, _instancingDraw);
                return(false);
            }

            List <DividedDetailProperty> detailProps = new List <DividedDetailProperty>();
            float nodeMargin = float.MinValue;

            for (int i = 0; i < detailCount; ++i)
            {
                detailProps.Add(new DividedDetailProperty(prototypes[i], _nodeSize, i));

                if (_instancingDraw[i] == null)
                {
                    var renderer = new InstancingRenderer(prototypes[i]);
                    nodeMargin         = Mathf.Max(nodeMargin, renderer.SphereRadius);
                    _instancingDraw[i] = new DetailInstancingDraw(renderer, VisibilityShader, SortShader, setting, data, basePos);
                }
                else
                {
                    nodeMargin = Mathf.Max(nodeMargin, _instancingDraw[i].RendererSphereRadius);
                }
            }

            var nodeSize = new Vector2(data.size.x / division, data.size.z / division);

            var cluster = new GpuInstancingNodeCluster <GpuInstancingDetailNode>();

            cluster.InitDivision(basePos, nodeSize, division, division, detailDistance);
            cluster.InitHeightMap(asset, dataIndex, data.size.y, heightMapResolution, nodeMargin);

            cluster.TerrainName = setting.name;

            dataIndex += heightMapResolution * heightMapResolution * 2;

            _data.SetGridParam(data.size.x, detailDistance, nodeSize);

            _terrainProperty = new TerrainProperty();
            _terrainProperty.InitForDetail(setting, data, detailDistance, basePos);

            var layerLength = (detailResolution * detailResolution + division * division) * 2;

            for (int z = 0; z < division; ++z)
            {
                for (int x = 0; x < division; ++x)
                {
                    var node = new GpuInstancingDetailNode();

                    node.TerrainName = setting.name;
                    node.X           = x;
                    node.Z           = z;

                    node.SetInstantiationShader(_instantiationShader);
                    node.SetShaderProperty(_terrainProperty, detailProps);
                    node.InitCountInUnit(x, z, _nodeSize, asset, maxCountInLayer, dataIndex, layerLength, division);

                    cluster.AddNode(x, z, node);
                }
            }

            cluster.SetMaxCountInLayer(maxCountInLayer);

            _data.AddCluster(cluster);
            return(true);
        }