using Thousandto.Cfg.Data; using Thousandto.Code.Center; using Thousandto.Code.Global; using Thousandto.Core.Base; using System; using System.Collections.Generic; using XLua; using Thousandto.Plugins.Common; using Thousandto.Code.Logic.LocalPlayerBT; using Thousandto.Core.PostEffect; using UnityEngine; using Thousandto.Core.Asset; namespace Thousandto.Code.Logic { //地图逻辑系统,用于实现每个地图单独的逻辑处理 public class MapLogicSwitch { #region//私有变量 private bool _hideOtherPlayer = false; private bool _hideFaBao = false; private bool _canRide = true; private bool _showServerID = false; private Dictionary _collectionTitles = new Dictionary(); #endregion #region//开关定义 //是否可以骑马 public bool CanRide { get { return _canRide; } set { if (_canRide != value) { _canRide = value; if (!_canRide) { var lp = GameCenter.GameSceneSystem.GetLocalPlayer(); if (lp != null) { lp.MountDown(); } } } } } //是否可以飞行 public bool CanFly { get; set; } //是否可以翻滚 public bool CanRollDoge { get; set; } //是否可以挂机 public bool CanMandate { get; set; } //是否可以切换到队伍分页 public bool CanOpenTeam { get; set; } //是否展示新功能开启效果,如果为否将会缓存到下个地图进行展示 public bool ShowNewFunction { get; set; } //是否开启自动反击 public bool UseAutoStrikeBack { get; set; } //是否自动使用XP技能 public bool AutoUseXPSkill { get; set; } //是否可以传送 public bool CanTeleport { get; set; } //是否是副本 public bool IsCopyMap { get; set; } //是否是位面 public bool IsPlaneCopyMap { get; set; } //是否一直保持战斗状态 public bool HoldFighting { get; set; } //阵营Icon定义 public Dictionary CampIcons { get; set; } //其他面板打开事件 public int EventOpen = 0; //其他面板打开事件 public int EventClose = 0; //其他面板显示的文字 public string OtherName = string.Empty; //其他面板显示的图片,如果填空字符串就是不显示图片 public string OtherSprName = "tongyong"; //是否隐藏其他玩家 public bool HideOtherPlayer { get { return _hideOtherPlayer; } set { if (_hideOtherPlayer != value) { _hideOtherPlayer = value; var rpList = GameCenter.GameSceneSystem.FindEntityAll(); if (rpList != null) { for (int i = 0; i < rpList.Count; ++i) { rpList[i].IsShowModel = rpList[i].IsShowModel; GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_HUD_UPDATEHUD_INVISIBLE_STATE, rpList[i]); } } var petList = GameCenter.GameSceneSystem.FindEntityAll(); if (petList != null) { for (int i = 0; i < petList.Count; ++i) { petList[i].IsShowModel = petList[i].IsShowModel; } } } } } //是否隐藏法宝 public bool HideFaBao { get { return _hideFaBao; } set { if (_hideFaBao != value) { _hideFaBao = value; } } } //是否在头顶展示服务器ID public bool ShowServerID { get { return _showServerID; } set { if (_showServerID != value) { _showServerID = value; var playerList = GameCenter.GameSceneSystem.FindEntityAll(); if (playerList != null && playerList.Count > 0) { for (int i = 0; i < playerList.Count; ++i) { GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_HUD_UPDATE_HEADINFO, playerList[i]); } } } } } //阴影摄像机size,值越小阴影越清晰,阴影范围越小 public float ShadowCameraSize { set { if (PostEffectManager.Instance != null) { PostEffectManager.Instance.SetShadowViewPort(value); } } } //是否自定义处理传送,如果为ture,将会在触发传送的时候push public bool CustomTriggerTeleport { get; set; } public Dictionary CollectionTitles { get { return _collectionTitles; } } //暂停物品使用提醒 public bool PauseGetNewItemTips { get; set; } //最大特效数量 public int MaxSkillVfxCount { get; set; } #endregion #region//公有函数 public void Reset() { CanRide = true; CanFly = true; CanRollDoge = true; CanMandate = true; CanOpenTeam = true; ShowNewFunction = true; UseAutoStrikeBack = true; CanTeleport = true; IsCopyMap = false; IsPlaneCopyMap = false; HoldFighting = false; CampIcons = null; OtherName = string.Empty; OtherSprName = "tongyong"; _hideFaBao = false; _hideOtherPlayer = false; _showServerID = false; #if UNITY_STANDALONE_WIN || UNITY_EDITOR ShadowCameraSize = 20f; #else ShadowCameraSize = 7.5f; #endif CustomTriggerTeleport = false; _collectionTitles.Clear(); PauseGetNewItemTips = false; AutoUseXPSkill = true; MaxSkillVfxCount = 10; if (GameCenter.GameSceneSystem != null) { //刷新主角名字 GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_HUD_UPDATE_HEADINFO, GameCenter.GameSceneSystem.GetLocalPlayer()); } } public void SetCampIcons(object obj) { var luaTable = obj as LuaTable; if (luaTable != null) { CampIcons = new Dictionary(); luaTable.ForEach((key, value) => { CampIcons[key] = value; }); } else { CampIcons = null; } //更新玩家头顶 var playerList = GameCenter.GameSceneSystem.FindEntityAll(); for (int i = 0; i < playerList.Count; ++i) { GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_HUD_UPDATE_HEADINFO, playerList[i]); } } //获取地图特殊阵营icon public int GetSceneCampIcon(Player player) { if (player != null && CampIcons != null && CampIcons.ContainsKey(player.PropMoudle.SceneCampID)) { return CampIcons[player.PropMoudle.SceneCampID]; } return -1; } //主角退出副本准备 public void DoPlayerExitPrepare() { //主角停止挂机,停止移动 GameCenter.LuaSystem.Adaptor.EndMandate(); var lp = GameCenter.GameSceneSystem.GetLocalPlayer(); if (lp != null) { PlayerBT.ChangeState(PlayerBDState.Default); lp.Stop_Action(); } } //播放模糊效果 public void PlayRadiaBlur(float start, float end, float time, bool pingpong) { if (GameCenter.GameSetting.IsEnabled(GameSettingKeyCode.EnablePostEffect) && GameCenter.GameSetting.IsEnabled(GameSettingKeyCode.EnableRadialBlurEffect)) { PostEffectManager.Instance.PlayRadiaBlur(start, end, time, pingpong); } } //设置雾效 public void SetFog(float start, float end, float r, float g, float b) { RenderSettings.fogColor = new Color(r, g, b); RenderSettings.fogStartDistance = start; RenderSettings.fogEndDistance = end; } //执行主线 public void DoMainTask() { GameCenter.TaskController.Run(GameCenter.TaskManager.GetMainTaskId()); } //预加载需求的资源 public void PreLoadPrefab(ModelTypeCode type, int code) { PrefabAssetManager.SharedInstance.PreLoadPrefab(AssetUtils.GetModelAssetPath(type, code), null); } public int GetSceneChange1Layer() { return (LayerUtils.LayerToMask(LayerUtils.LocalPlayer) | LayerUtils.LayerToMask(LayerUtils.RemotePlayer) | LayerUtils.LayerToMask(LayerUtils.Monster) | LayerUtils.LayerToMask(LayerUtils.SummonObj) | LayerUtils.LayerToMask(LayerUtils.SceneChange1)); } public int GetSceneChange2Layer() { return (LayerUtils.LayerToMask(LayerUtils.LocalPlayer) | LayerUtils.LayerToMask(LayerUtils.RemotePlayer) | LayerUtils.LayerToMask(LayerUtils.Monster) | LayerUtils.LayerToMask(LayerUtils.SummonObj) | LayerUtils.LayerToMask(LayerUtils.SceneChange2)); } public bool MonsterIsAllDead(bool removed) { var mList = GameCenter.GameSceneSystem.FindEntityAll(); if (mList != null) { if (removed) { return mList.Count <= 0; } else { for (int i = 0; i < mList.Count; ++i) { if (!mList[i].IsDead()) { return false; } } } } return true; } public bool IsMonsterBorn() { var mList = GameCenter.GameSceneSystem.FindEntityAll(); bool isBron = false; if (mList != null) { for (int i = 0; i < mList.Count; ++i) { if (!mList[i].IsDead()) { isBron = true; } } } return isBron; } //播放水波纹效果 public void PlayWaterWave(float disFactor, float timeFactor, float totalFactor, float width, float speed) { if (GameCenter.GameSetting.IsEnabled(GameSettingKeyCode.EnablePostEffect)) { PostEffectManager.Instance.PlayWaterWave(disFactor, timeFactor, totalFactor, width, speed); } } //播放震动效果 public void PlayCameraShake(AnimationCurve curve, float totalTime, VFXCameraShakerType shakeType, float power) { PostEffectManager.Instance.PlayCameraShake(curve, totalTime, shakeType, power); } //角色说话 public void CharacterTalk(ulong id, string text, float time) { var character = GameCenter.GameSceneSystem.FindEntity(id); if (character != null) { if (!character.IsShowHUD) { character.ShowHUD(true); } GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_HUD_SHOWEMONSTER_SERVERSTRINGPOP, new object[] { character, text, time }); } } //查找NPC public Npc FindNpcByDataID(int id) { var nps = GameCenter.GameSceneSystem.FindNpcs(); if (nps != null) { for (int i = 0; i < nps.Count; ++i) { if (nps[i].PropMoudle.CfgID == id) return nps[i]; } } return null; } //查找怪物 public Monster FindMonsterByDataID(int id) { var monsters = GameCenter.GameSceneSystem.FindMonsters(); if (monsters != null) { for (int i = 0; i < monsters.Count; ++i) { if (monsters[i].PropMoudle.CfgID == id) return monsters[i]; } } return null; } //查找采集物 public Collection FindCollectionByDataID(int id) { var cols = GameCenter.GameSceneSystem.FindEntityAll(); if (cols != null) { for (int i = 0; i < cols.Count; ++i) { if (cols[i].PropMoudle.CfgID == id) return cols[i]; } } return null; } //位面结束效果是否播放完成 public bool PlaneEndEffectIsFinish(bool monsterRemoved) { bool monsterFinish = MonsterIsAllDead(monsterRemoved); var goldList = GameCenter.GameSceneSystem.FindEntityAll(); if (goldList != null) { monsterFinish &= goldList.Count <= 0; } var itemList = GameCenter.GameSceneSystem.FindEntityAll(); if (itemList != null) { monsterFinish &= itemList.Count <= 0; } return monsterFinish; } //机器人聊天 public void RobotChat(string name, int occ, int level, string chatText) { GameCenter.ChatSystem.RobotChat(occ, name, level, chatText); } //播放地面特效 public FGameObjectVFX PlayGroundVFX(ModelTypeCode typeCode, int id, float x, float y, float z, float scale) { var vfx = new FGameObjectVFX(typeCode, id); vfx.SetPosition(new Vector3(x, y, z)); vfx.SetLayer(LayerUtils.LocalPlayer); vfx.SetLocalScale(scale); vfx.Play(); return vfx; } //查找最近的boss private int SortBoss(Monster left, Monster right) { var lp = GameCenter.GameSceneSystem.GetLocalPlayer(); if (lp == null) return 0; float lDis = 0f; float rDis = 0f; if (left.IsBoss) { lDis = lp.GetSqrDistance2d(left.Position2d); } else { lDis = float.MaxValue; } if (right.IsBoss) { rDis = lp.GetSqrDistance2d(right.Position2d); } else { rDis = float.MaxValue; } return lDis.CompareTo(rDis); } public Monster FindMinDisBoss() { var mList = GameCenter.GameSceneSystem.FindMonsters(); if (mList != null && mList.Count > 0) { mList.Sort(SortBoss); if (mList[0].IsBoss) { return mList[0]; } } return null; } //执行采集 public void DoCollect(int id) { var lp = GameCenter.GameSceneSystem.GetLocalPlayer(); var collection = FindCollectionByDataID(id); if (collection != null && lp != null) { lp.SetCurSelectedTargetId(collection.ID); PlayerBT.Collect.Write(); } } //获取阻挡开启状态,true表示阻挡生效,false表示阻挡无效 public bool GetDynamicBlockerOpenState(string name) { var blocker = GameCenter.DynamicBlockerManager.FindBlocker(name); if (blocker != null) { return blocker.CurState == SceneEditor.Proxy.Plugin.DynamicBlocker.State.Enabled; } return false; } //设置采集物动态称号 public void SetCollectionTitle(int dataId, string title) { if (string.IsNullOrEmpty(title)) { _collectionTitles.Remove(dataId); } else { _collectionTitles[dataId] = title; } GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_COLLECTION_TITLE_CHANGED); } //发送快速消息 public void SendGuildQuickMsg(string content) { GameCenter.ChatSystem.SendGuildQuickMsg(content); } //播放特效 public FGameObjectVFX PlayVfx(ulong characterId, ModelTypeCode vfxType, int vfxId, string vfxSlot, int part, bool isBind) { var character = GameCenter.GameSceneSystem.FindEntity(characterId); if (character != null && character.Skin != null) { return character.Skin.PlayVFX(vfxType, vfxId, vfxSlot, part, isBind, 1f, true, false, null, false, false); } return null; } //飞剑播放特效 public FGameObjectVFX FlySwordPlayVfx(ulong characterId, ModelTypeCode vfxType, int vfxId, string vfxSlot, int part) { var character = GameCenter.GameSceneSystem.FindEntity(characterId); if (character != null && character.Skin != null) { var trans = UnityHierarchyUtils.SearchHierarchy(character.Skin.RealTransform, vfxSlot, true); if (trans == null) { trans = character.Skin.RealTransform; } var vfx = new FGameObjectVFX(vfxType, vfxId, true, false, 0); vfx.SetLayer(character.Layer); vfx.SetParent(trans); vfx.SetLocalPosition(Vector3.zero); vfx.SetLocalEulerAngles(Vector3.zero); vfx.Play(); return vfx; } return null; } //播放地面特效 public FGameObjectVFX PlayGroundVFX(ModelTypeCode vfxType, int vfxId, float x, float z) { var scene = GameCenter.GameSceneSystem.ActivedScene; if (scene == null) return null; var vfx = new FGameObjectVFX(vfxType, vfxId, true, false, 0); vfx.SetLayer(LayerUtils.SceneVFX); vfx.SetLocalPosition(new Vector3(x, scene.GetHeightOnTerrain(x, z), z)); vfx.SetLocalEulerAngles(Vector3.zero); vfx.Play(); return vfx; } //释放特效 public void DestoryVfx(FGameObjectVFX vfx) { if (vfx != null) { vfx.Destroy(); } } //判断角色是否存在 public bool CharacterIsAlive(ulong id) { var c = GameCenter.GameSceneSystem.FindEntity(id); if (c != null && !c.IsDead()) return true; return false; } //判断怪物是否存在 public bool MonsterIsAliveByCfgID(int id) { var monsterList = GameCenter.GameSceneSystem.FindMonsters(); if (monsterList != null && monsterList.Count > 0) { for (int i = 0; i < monsterList.Count; ++i) { if (monsterList[i].PropMoudle.CfgID == id) { return !monsterList[i].IsDead(); } } } return false; } //增加动作 public void PutOnAnimation(Player p, string animName) { if (p != null && !string.IsNullOrEmpty(animName) && p.Skin != null) { var body = p.Skin.GetSkinPart(FSkinPartCode.Body); if (body != null && body.RealScript != null) { AnimationClipManager.SharedInstance.PutOnAnimation(body.RealScript.GetAnimationGo(), ModelTypeCode.Player, (int)p.Occ, new string[] { animName }); } } } //卸载动作 public void TakeOffAnimation(Player p, string animName) { if (p != null && !string.IsNullOrEmpty(animName) && p.Skin != null) { var body = p.Skin.GetSkinPart(FSkinPartCode.Body); if (body != null && body.RealScript != null) { AnimationClipManager.SharedInstance.TakeOffAnimation(body.RealScript.GetAnimationGo(), ModelTypeCode.Player, (int)p.Occ, new string[] { animName }); } } } //执行转职渡劫 private Vector2 _changeJobEnterPos = Vector2.zero; private Vector2 _changeJobTransPos = Vector2.zero; private int _changeJobMapId = 0; private int _changeJobCopyId = 0; public void DoChangeJobDujie() { if (_changeJobMapId <= 0) { var gCfg = DeclareGlobal.Get((int)GlobalName.Change_Job_Finish); if (gCfg != null) { var strParams = gCfg.Params.Split('_'); _changeJobMapId = int.Parse(strParams[0]); _changeJobTransPos.x = int.Parse(strParams[1]); _changeJobTransPos.y = int.Parse(strParams[2]); _changeJobEnterPos.x = int.Parse(strParams[3]); _changeJobEnterPos.y = int.Parse(strParams[4]); _changeJobCopyId = int.Parse(strParams[5]); } } if (_changeJobMapId <= 0) return; var activeScene = GameCenter.GameSceneSystem.ActivedScene; if (activeScene == null) return; var lp = GameCenter.GameSceneSystem.GetLocalPlayer(); if (lp == null) return; if (activeScene.MapId == _changeJobMapId) { //寻路 if (lp.GetSqrDistance2d(_changeJobEnterPos) <= 9f) { //直接进入位面 var req = new MSG_zone.ReqEnterZone(); req.modelId = _changeJobCopyId; req.Send(); } else { //寻路 PlayerBT.MapMove.Write2D(_changeJobMapId, _changeJobEnterPos, 1, false, true, DoChangeJobDujie); } } else { //传送 var req = new MSG_Map.ReqTransportControl(); req.x = _changeJobTransPos.x; req.y = _changeJobTransPos.y; req.mapID = _changeJobMapId; req.param = 0; req.type = (int)TransportTypeDef.DuJie; req.Send(); } } //设置skinpart的位置 public void SetSkinPartPos(ulong id, int part, float x, float y, float z) { var character = GameCenter.GameSceneSystem.FindEntity(id); if (character == null || character.Skin == null) return; var partInst = character.Skin.GetSkinPart(part); if (partInst == null) return; partInst.RootTransform.position = new Vector3(x, y, z); } //查找所有动态高度的角色 public void ForEachDyanmicHeightCharacter(Action func) { if (func == null) return; var entityCon = GameCenter.GameSceneSystem.GetEntityContainer(); if (entityCon != null) { entityCon.ForEach((id, e) => { if ((e != null) && (e is Character) && !(e is FlySword)) { func(e as Character); } /* var c = e as Character; if (c == null) return; if (c is FlySword) return; func(c); */ }); } } public void SetPathGridData(bool[] array, int rowMax, int colMax) { var scene = GameCenter.GameSceneSystem.ActivedScene; if (scene == null) return; var nav = scene.navigator; if (nav == null) return; var pathData = nav.PathGridData; if (pathData == null) return; for (int row = 0; row < pathData.NumberOfRows; row++) { for (int col = 0; col < pathData.NumberOfColumns; col++) { if (row >= rowMax || col >= colMax) { if ((row == rowMax / 2 || row == rowMax / 2 - 1) && (col == colMax || col == colMax + 1)) { //入口 nav.PathGridData.MergedData[row, col] = PathEditor.Proxy.Plugin.PathGridType.Safe; } else { nav.PathGridData.MergedData[row, col] = PathEditor.Proxy.Plugin.PathGridType.Block; } continue; } var _index = row * colMax + col; if (array.Length > _index) { if (array[_index]) { nav.PathGridData.MergedData[row, col] = PathEditor.Proxy.Plugin.PathGridType.Block; continue; } } nav.PathGridData.MergedData[row, col] = PathEditor.Proxy.Plugin.PathGridType.Safe; } } } #endregion } }