private void ExplosionEffect(ThrowingEntity throwing) { //特效 int effectId; Vector3 effectPos = throwing.position.Value; if (SingletonManager.Get <MapConfigManager>().InWater(throwing.position.Value)) { effectId = throwing.throwingData.Config.WaterBombEffectId; float wy = SingletonManager.Get <MapConfigManager>().WaterSurfaceHeight(effectPos); if (!float.IsNaN(wy) && throwing.throwingData.WeaponSubType == (int)EWeaponSubType.Grenade) {//破片手雷水里特效拉到水面 effectPos.y = wy; } } else { effectId = throwing.throwingData.Config.BombEffectId; } //烟雾弹位置计算 if (throwing.throwingData.WeaponSubType == (int)EWeaponSubType.FogBomb) { effectPos = CommonMathUtil.GetSpacePos(effectPos, 0.5f, _layerMask); } PlayOneEffect(throwing, effectId, effectPos, true); }
private float GetAngle(PlayerEntity myEntity, PlayerEntity teamEntity) { //角度 float yaw = CommonMathUtil.TransComAngle(myEntity.orientation.Yaw); float angle = CommonMathUtil.GetAngle(new Vector2(teamEntity.position.Value.x, teamEntity.position.Value.z), new Vector2(myEntity.position.Value.x, myEntity.position.Value.z)); return(CommonMathUtil.GetDiffAngle(angle, yaw)); }
private void GrenadeDamageHandler(ThrowingEntity throwing) { PlayerEntity sourcePlayer = null; if (throwing.hasOwnerId) { sourcePlayer = _contexts.player.GetEntityWithEntityKey(throwing.ownerId.Value); } Vector3 hitPoint; foreach (PlayerEntity player in _players) { float dis = Vector3.Distance(throwing.position.Value, player.position.Value); //头部 Vector3 headPos = player.position.Value; Transform tran; if (player.appearanceInterface.Appearance.IsFirstPerson) { var root = player.RootGo(); tran = BoneMount.FindChildBoneFromCache(root, BoneName.CharacterHeadBoneName); } else { var root = player.RootGo(); tran = BoneMount.FindChildBoneFromCache(root, BoneName.CharacterHeadBoneName); } if (null != tran) { headPos = tran.position; } if (dis < throwing.throwingData.Config.DamageRadius && ((!throwing.throwingData.IsFly && throwing.ownerId.Value == player.entityKey.Value) || !CommonMathUtil.Raycast(throwing.position.Value, player.position.Value, dis, _layerMask, out hitPoint) || !CommonMathUtil.Raycast(throwing.position.Value, headPos, dis, _layerMask, out hitPoint))) { float damage = (1 - dis / throwing.throwingData.Config.DamageRadius) * throwing.throwingData.Config.BaseDamage; _throwingHitHandler.OnPlayerDamage(sourcePlayer, player, new PlayerDamageInfo(damage, (int)EUIDeadType.Weapon, (int)EBodyPart.Chest, GetWeaponIdBySubType((EWeaponSubType)throwing.throwingData.WeaponSubType))); } } foreach (VehicleEntity vehicle in _vehicles) { float dis = Vector3.Distance(throwing.position.Value, vehicle.position.Value); if (dis < throwing.throwingData.Config.DamageRadius && !CommonMathUtil.Raycast(throwing.position.Value, vehicle.position.Value, dis, _layerMask, out hitPoint)) { float damage = (1 - dis / throwing.throwingData.Config.DamageRadius) * throwing.throwingData.Config.BaseDamage; _throwingHitHandler.OnVehicleDamage(vehicle, damage); } } }
public bool Meet(IEventArgs args) { FreeData fd = (FreeData)args.GetUnit(player); object obj = ((FreeRuleEventArgs)args).GetEntity(entity); if (fd != null && obj != null) { PlayerEntity playerEntity = fd.Player; FreeMoveEntity objEntity = (FreeMoveEntity)obj; float yaw = CommonMathUtil.TransComAngle(playerEntity.orientation.Yaw); float ang = CommonMathUtil.GetAngle(new Vector2(objEntity.position.Value.x, objEntity.position.Value.z), new Vector2(playerEntity.position.Value.x, playerEntity.position.Value.z)); return(CommonMathUtil.GetDiffAngle(ang, yaw) <= FreeUtil.ReplaceFloat(angle, args) && Vector3.Distance(playerEntity.position.Value, objEntity.position.Value) <= FreeUtil.ReplaceFloat(distance, args)); } return(false); }
private void NewRaycast() { RaycastHit hit; foreach (var segment in _allThrowingSegments) { if (!segment.IsValid) { continue; } bool isHit = CommonMathUtil.Raycast(segment.RaySegment.Ray, segment.RaySegment.Length, _layerMask, out hit); if (isHit) { CollisionHandler(segment, hit); break; } } }
private void DrawThrowingLine(Vector3 pos, Vector3 vel, float gravity, float decay, float lineWidth, float deltaTime, float length) { if (null == _throwingMesh || !_assetLoaded) { return; } Vector3 movePos; Vector3 moveVel = vel; float sumLength = 0; _Vertices.Clear(); _Uvs.Clear(); Vector3 offset = Vector3.Cross(new Vector3(0, 1, 0), vel); offset = offset.normalized * lineWidth / 2; Vector3 oldPos; Vector3 hitPoint = new Vector3(); float moveLen = 0; bool isHit = false; while (sumLength < length) { oldPos = pos; movePos = moveVel * deltaTime; pos += movePos; _Vertices.Add(new Vector3(pos.x - offset.x, pos.y, pos.z - offset.z)); _Vertices.Add(new Vector3(pos.x + offset.x, pos.y, pos.z + offset.z)); _Uvs.Add(new Vector2(sumLength / length, 0)); _Uvs.Add(new Vector2(sumLength / length, 1)); moveLen = movePos.magnitude; sumLength += moveLen; moveVel.y = moveVel.y - gravity * deltaTime; moveVel = moveVel * Mathf.Pow(decay, deltaTime); isHit = false; if (sumLength > _beginCollLength) { isHit = CommonMathUtil.Raycast(oldPos, pos, moveLen, _layerMask, out hitPoint); } if (isHit) { break; } } //triangles int vertLen = _Vertices.Count - 2; int triLen = vertLen * 3; int[] triangles = new int[triLen]; for (int i = 0, j = 0; i < triLen; i += 6, j += 2) { triangles[i] = j; triangles[i + 1] = j + 1; triangles[i + 2] = j + 3; triangles[i + 3] = j; triangles[i + 4] = j + 3; triangles[i + 5] = j + 2; } _throwingMesh.Clear(); _throwingMesh.vertices = _Vertices.ToArray(); _throwingMesh.triangles = triangles; _throwingMesh.uv = _Uvs.ToArray(); //Sphere if (isHit) { SetSpherePos(hitPoint); } else { SetSphereActive(false); } _isDrawLine = true; }
private void CheckFlash(ClientEffectEntity entity) { PlayerEntity player = AllContexts.player.flagSelfEntity; //闪光弹位置 Vector3 pos = entity.position.Value; //水里1米 if (SingletonManager.Get <MapConfigManager>().InWater(pos)) { float wy = SingletonManager.Get <MapConfigManager>().WaterSurfaceHeight(pos); if (!float.IsNaN(wy) && wy - pos.y > 1) { return; } } bool isShow = false; float alpha = 0, keepTime = 0, decayTime = 0; Vector3 playerPos = player.position.Value; //位置稍上抬 pos.y += 0.1f; //玩家头部位置 Transform tran; if (player.appearanceInterface.Appearance.IsFirstPerson) { var root = player.RootGo(); tran = BoneMount.FindChildBoneFromCache(root, BoneName.CharacterHeadBoneName); } else { var root = player.RootGo(); tran = BoneMount.FindChildBoneFromCache(root, BoneName.CharacterHeadBoneName); } if (null != tran) { playerPos = tran.position; } //距离 float dis = Vector3.Distance(playerPos, pos); if (dis >= 40) { return; } float diffAngle = 0; //判断是否手上爆炸 bool isHandBomb = entity.hasEffectRotation && entity.effectRotation.Yaw > 0; if (!(entity.ownerId.Value == player.entityKey.Value && isHandBomb)) { //遮挡 Vector3 hitPoint; bool isHit = CommonMathUtil.Raycast(playerPos, pos, dis, _layerMask, out hitPoint); if (isHit) { return; } //角度 float yaw = CommonMathUtil.TransComAngle(player.orientation.Yaw); float angle = CommonMathUtil.GetAngle(new Vector2(pos.x, pos.z), new Vector2(playerPos.x, playerPos.z)); diffAngle = Mathf.Abs(angle - yaw); diffAngle = Mathf.Min(360 - diffAngle, diffAngle); } if (diffAngle <= 60) { if (dis < 20) { isShow = true; alpha = 1; keepTime = Mathf.Max(1.2f, 3 * Mathf.Pow(0.4f, dis / 30)); decayTime = alpha / 0.4f; } else if (dis < 40) { isShow = true; alpha = 1 - dis * 0.00025f; keepTime = 0; decayTime = alpha / 0.4f; } } else if (diffAngle <= 90) { if (dis <= 20) { isShow = true; alpha = Mathf.Max(0, 1 - dis * 0.00025f); keepTime = 0; decayTime = alpha / 0.4f; } } else if (diffAngle <= 180) { if (dis <= 10) { isShow = true; alpha = Mathf.Max(0, 0.8f - dis * 0.00025f); keepTime = 0; decayTime = alpha / 0.5f; } } if (isShow) { ScreenFlashInfo screenFlashInfo = new ScreenFlashInfo(); screenFlashInfo.IsShow = true; screenFlashInfo.Alpha = alpha; screenFlashInfo.KeepTime = keepTime; screenFlashInfo.DecayTime = decayTime; AllContexts.ui.uI.ScreenFlashInfo = screenFlashInfo; player.AudioController().PlayDizzyAudio(dis, 40); // GameAudioMedia.PlayFlashDizzyAudio(pos,Math.Min(0,40-dis)); } }
private void GrenadeDamageHandler(ThrowingEntity throwing) { PlayerEntity sourcePlayer = null; if (throwing.hasOwnerId) { sourcePlayer = _contexts.player.GetEntityWithEntityKey(throwing.ownerId.Value); } Vector3 hitPoint; foreach (PlayerEntity player in _players) { if (player.hasPlayerMask && player.playerMask.SelfMask == (int)EPlayerMask.Invincible) { continue; } float dis = Vector3.Distance(throwing.position.Value, player.position.Value); if (dis < throwing.throwingData.ThrowConfig.DamageRadius && ((!throwing.throwingData.IsFly && throwing.ownerId.Value == player.entityKey.Value) || !CommonMathUtil.Raycast(throwing.position.Value, player.position.Value, dis, _layerMask, out hitPoint) || !CommonMathUtil.Raycast(throwing.position.Value, player.bones.Head.position, dis, _layerMask, out hitPoint))) { float damage = (1 - dis / throwing.throwingData.ThrowConfig.DamageRadius) * throwing.throwingData.ThrowConfig.BaseDamage; _throwingHitHandler.OnPlayerDamage(_contexts, sourcePlayer, player, new PlayerDamageInfo(damage, (int)EUIDeadType.Weapon, (int)EBodyPart.None, GetWeaponIdBySubType((EWeaponSubType)throwing.throwingData.WeaponSubType), false, false, false, player.position.Value, player.position.Value - throwing.position.Value)); } } foreach (VehicleEntity vehicle in _vehicles) { float dis = Vector3.Distance(throwing.position.Value, vehicle.position.Value); if (dis < throwing.throwingData.ThrowConfig.DamageRadius && !CommonMathUtil.Raycast(throwing.position.Value, vehicle.position.Value, dis, _layerMask, out hitPoint)) { float damage = (1 - dis / throwing.throwingData.ThrowConfig.DamageRadius) * throwing.throwingData.ThrowConfig.BaseDamage; _throwingHitHandler.OnVehicleDamage(vehicle, damage); } } var colliders = Physics.OverlapSphere(throwing.position.Value, throwing.throwingData.ThrowConfig.DamageRadius, UnityLayerManager.GetLayerMask(EUnityLayerName.UserInputRaycast) | UnityLayerManager.GetLayerMask(EUnityLayerName.Glass)); foreach (var collider in colliders) { CreateMapObjWhenBomb(collider, sourcePlayer); var distance = Vector3.Distance(collider.transform.position, throwing.position.Value); float trueDamage = distance > throwing.throwingData.ThrowConfig.DamageRadius ? 0f : Mathf.Max(0f, throwing.throwingData.ThrowConfig.BaseDamage * (1 - distance / throwing.throwingData.ThrowConfig.DamageRadius)); if (collider.gameObject.layer == UnityLayerManager.GetLayerIndex(EUnityLayerName.UserInputRaycast)) { var parent = collider.transform; while (null != parent) { var fractured = parent.GetComponent <FracturedObject>(); if (null != fractured) { if (!HasObstacle(collider.transform.position, throwing.position.Value, (obstacleTrans) => { var obstacleParent = obstacleTrans.parent; while (null != obstacleParent) { if (obstacleParent == fractured.transform) { return(true); } obstacleParent = obstacleParent.parent; } return(false); })) { fractured.Explode(Vector3.zero, trueDamage); } break; } parent = parent.parent; } } if (collider.gameObject.layer == UnityLayerManager.GetLayerIndex(EUnityLayerName.Glass)) { var parent = collider.transform; while (null != parent) { var fractured = parent.GetComponent <FracturedGlassyChunk>(); if (null != fractured) { fractured.MakeBroken(); } parent = parent.parent; } } } }
public void UIUpdate(int frameTime) { if (SingletonManager.Get <FreeUiManager>().Contexts1 == null || SingletonManager.Get <FreeUiManager>().Contexts1.ui.uISessionEntity.uISession == null || SingletonManager.Get <FreeUiManager>().Contexts1.player.flagSelfEntity == null) { return; } UpdatePlaine(); PlayerEntity selfEntity = SingletonManager.Get <FreeUiManager>().Contexts1.ui.uI.Player; var data = SingletonManager.Get <FreeUiManager>().Contexts1.ui.map; data.TeamInfos.Clear(); _teamNums = ""; var map = SingletonManager.Get <FreeUiManager>().Contexts1.ui.map; map.TeamPlayerMarkInfos.Clear(); var modeId = SingletonManager.Get <FreeUiManager>().Contexts1.session.commonSession.RoomInfo.ModeId; foreach (PlayerEntity playerEntity in SingletonManager.Get <FreeUiManager>().Contexts1.player.GetEntities()) { try { if (playerEntity.hasPlayerInfo && playerEntity.hasPosition && ((!GameRules.IsBio(modeId) && playerEntity.playerInfo.TeamId == selfEntity.playerInfo.TeamId) || (GameRules.IsBio(modeId) && playerEntity.hasGamePlay && selfEntity.gamePlay.IsMatchJob(playerEntity.gamePlay.JobAttribute)))) { if (!infoMap.ContainsKey(playerEntity.playerInfo.PlayerId)) { MiniMapTeamPlayInfo info = new MiniMapTeamPlayInfo(playerEntity.playerInfo.PlayerId, playerEntity.playerInfo.EntityId, true, 1, MapUtils.TeamColor(playerEntity.playerInfo.Num), MiniMapPlayStatue.NORMAL, new Vector3(500, 0, 300), 45f, new List <MiniMapPlayMarkInfo>() { new MiniMapPlayMarkInfo(new Vector3(500, 250), 1, Color.black), }, false, 0, playerEntity.playerInfo.PlayerName, (int)playerEntity.gamePlay.CurHp, playerEntity.gamePlay.MaxHp, (int)playerEntity.gamePlay.InHurtedHp, false, playerEntity.position.Value); infoMap[playerEntity.playerInfo.PlayerId] = info; } // Vector3 leftMinPos = TerrainCommonData.leftMinPos; MiniMapTeamPlayInfo oneInfo = infoMap[playerEntity.playerInfo.PlayerId]; if (playerEntity == selfEntity) { oneInfo.IsPlayer = true; data.CurPlayer = oneInfo; } else { oneInfo.IsPlayer = false; } if (oneInfo.Num != playerEntity.playerInfo.Num) { oneInfo.Num = playerEntity.playerInfo.Num; oneInfo.PlayerName = playerEntity.playerInfo.PlayerName; oneInfo.Color = MapUtils.TeamColor(oneInfo.Num); } //pos,rot /*if (playerEntity.hasControlledVehicle) * { * //车上 * Transform trans = playerEntity.GetVehicleSeatTransform(SingletonManager.Get<FreeUiManager>().Contexts1.vehicle); * oneInfo.Pos = new Vector2(trans.position.x - leftMinPos.x, trans.position.z - leftMinPos.z); * oneInfo.FaceDirection = trans.eulerAngles.y; * } * else */ if (playerEntity.gamePlay.GameState == GameState.AirPlane) { //飞机上(位置已做过偏移,这里不再偏移) AirPlaneData planeData = data.PlaneData; oneInfo.Pos = new MapFixedVector2(planeData.Pos.WorldVector3().To2D()); oneInfo.Pos3D = new MapFixedVector3(planeData.Pos.WorldVector3()); oneInfo.FaceDirection = planeData.Direction; } else { // oneInfo.Pos = new Vector2(playerEntity.position.Value.x - leftMinPos.x, playerEntity.position.Value.z - leftMinPos.z); oneInfo.Pos = new MapFixedVector2(playerEntity.position.FixedVector3.To2D()); oneInfo.Pos3D = new MapFixedVector3(playerEntity.position.FixedVector3); oneInfo.FaceDirection = playerEntity.orientation.Yaw; } //Test Trace if (oneInfo.IsPlayer) { TerrainTestSystem.yaw = oneInfo.FaceDirection; } if (_teamNums.Equals("")) { _teamNums = oneInfo.Num.ToString(); } else { _teamNums += "|" + oneInfo.Num; } //status if (playerEntity.gamePlay.IsLifeState(EPlayerLifeState.Dead)) { oneInfo.Statue = MiniMapPlayStatue.DEAD; data.RemoveMapMark(playerEntity.playerInfo.PlayerId); } else if (playerEntity.gamePlay.IsLifeState(EPlayerLifeState.Dying)) { oneInfo.Statue = MiniMapPlayStatue.HURTED; } else { if (playerEntity.IsOnVehicle()) { oneInfo.Statue = MiniMapPlayStatue.ZAIJU; } else if (PlayerIsDrop(playerEntity)) { oneInfo.Statue = MiniMapPlayStatue.TIAOSAN; } else { oneInfo.Statue = MiniMapPlayStatue.NORMAL; } } //map mark oneInfo.MarkList.Clear(); if (oneInfo.IsPlayer) { foreach (var mark in data.MapMarks.Values) { oneInfo.MarkList.Add(mark); TeamPlayerMarkInfo lmark = new TeamPlayerMarkInfo(); lmark.Angel = CommonMathUtil.GetAngle(mark.Pos, oneInfo.Pos.ShiftedUIVector2()); lmark.MarkColor = MapUtils.TeamColor(mark.Num); map.TeamPlayerMarkInfos.Add(lmark); } TerrainTestSystem.mark = map.TeamPlayerMarkInfos.Count; } //New oneInfo.PlayerName = playerEntity.playerInfo.PlayerName; oneInfo.CurHp = (int)playerEntity.gamePlay.CurHp; oneInfo.MaxHp = playerEntity.gamePlay.MaxHp; oneInfo.CurHpInHurted = (int)playerEntity.gamePlay.InHurtedHp; oneInfo.IsMark = data.MapMarks.ContainsKey(oneInfo.PlayerId) ? true : false; oneInfo.TopPos = PlayerEntityUtility.GetPlayerTopPosition(playerEntity); oneInfo.EntityId = playerEntity.entityKey.Value.EntityId; data.TeamInfos.Add(oneInfo); } } catch (Exception e) { Debug.LogErrorFormat(e.Message); } } TerrainTestSystem.teamCnt = data.TeamInfos.Count; TerrainTestSystem.teamNum = _teamNums; }