/// <summary> /// 获取路径最近的怪物 /// </summary> /// <param name="_gameStage"></param> /// <param name="_player"></param> /// <param name="_needAlive"></param> /// <returns></returns> public static Monster GetClosestMob(this GameStage _gameStage, SmartActor _player, ref float _distance) { List <Monster> mobs = _gameStage.GetMobs(); FDictionary distanceDic = new FDictionary(); FDictionary mobDic = new FDictionary(); int selfCamp = _player.Camp; SceneType sceneType = GameCenter.curGameStage.SceneType; Vector3 selfPosition = _player.transform.position; for (int i = 0; i < mobs.Count; i++) { Monster mob = mobs[i]; if (mob.isDummy || !mob.IsShowing || mob.isDead) { continue; } if (mob.gameObject != null && !mob.isDead && !mob.IsActor && ConfigMng.Instance.GetRelationType(selfCamp, mob.Camp, sceneType) == RelationType.AUTOMATEDATTACKS) { Vector3[] path = GameStageUtility.StartPath(selfPosition, mob.transform.position); if (path != null) { if (path.Length != 2) { distanceDic.Add(mob.id, path.CountPathDistance());//距离计算方法改变 } else { distanceDic.Add(mob.id, Vector3.Distance(selfPosition, mob.transform.position)); } mobDic.Add(mob.id, mob); } } } int closestOne = -1; float distance = -1; foreach (int id in distanceDic.Keys) { if (distance < 0 || distance >= (float)distanceDic[id]) { closestOne = id; distance = (float)distanceDic[id]; _distance = distance; } } return(mobDic.ContainsKey(closestOne) ? mobDic[closestOne] as Monster : null); }
/// <summary> /// 获取路径最近指定关系随从 by吴江 /// </summary> /// <param name="_gameStage"></param> /// <param name="_player"></param> /// <param name="_needAlive"></param> /// <returns></returns> public static OtherEntourage GetClosestEntourage(this GameStage _gameStage, SmartActor _player, RelationType _relationType, ref float _distance) { List <OtherEntourage> opcs = _gameStage.GetOtherEntourages(); FDictionary distanceDic = new FDictionary(); FDictionary opcDic = new FDictionary(); int selfCamp = _player.Camp; SceneType sceneType = GameCenter.curGameStage.SceneType; Vector3 selfPosition = _player.transform.position; for (int i = 0; i < opcs.Count; i++) { OtherEntourage opc = opcs[i]; if (opc.isDummy || !opc.IsShowing) { continue; } if (opc.gameObject != null && !opc.isDead && !opc.IsActor && ConfigMng.Instance.GetRelationType(selfCamp, opc.Camp, sceneType) == _relationType) { Vector3[] path = GameStageUtility.StartPath(selfPosition, opc.transform.position); if (path != null) { if (path.Length != 2) { distanceDic.Add(opc.id, path.CountPathDistance());//距离计算方法改变 } else { distanceDic.Add(opc.id, Vector3.Distance(selfPosition, opc.transform.position)); } opcDic.Add(opc.id, opc); } } } int closestOne = -1; float distance = -1; foreach (int id in distanceDic.Keys) { if (distance < 0 || distance >= (float)distanceDic[id]) { closestOne = id; distance = (float)distanceDic[id]; _distance = distance; } } return(opcDic.ContainsKey(closestOne) ? opcDic[closestOne] as OtherEntourage : null); }
public void RefreshFlyPoint() { List <FlyPointRef> flyPointList = ConfigMng.Instance.GetFlyPointRefByScene(curScene); // List<FlyPoint> flys = GameCenter.curGameStage.GetFlypoints(); for (int i = 0; i < flyPointList.Count; i++) { GameObject myPoint = Instantiate(flyPointInstance) as GameObject; myPoint.SetActive(true); myPoint.transform.parent = mapCtrl.transform; myPoint.transform.localScale = Vector3.one; myPoint.transform.localPosition = new Vector3(flyPointList[i].sceneVector.x * posXRate, flyPointList[i].sceneVector.z * posYRate, 0); flyPointDic.Add(flyPointList[i].id, myPoint); MapItem item = myPoint.GetComponent <MapItem>(); if (item != null) { item.Init(flyPointList[i].name, new Vector3(flyPointList[i].sceneVector.x, flyPointList[i].sceneVector.z), flyPointList[i].scene); if (item.Obj != null) { UIEventListener.Get(item.Obj).onClick -= OnClickMapItem; UIEventListener.Get(item.Obj).onClick += OnClickMapItem; } } } }
protected void RefreshNpc() { List <NPCAIRef> NpcList = ConfigMng.Instance.GetNPCAIRefByScene(curScene); //List<NPC> npcs = GameCenter.curGameStage.GetNPCs(); for (int i = 0; i < NpcList.Count; i++) { GameObject myPoint = null; myPoint = Instantiate(npcNoTaskPointInstance) as GameObject; myPoint.SetActive(true); myPoint.transform.parent = mapCtrl.transform; myPoint.transform.localScale = Vector3.one; myPoint.transform.localPosition = new Vector3(NpcList[i].sceneX * posXRate, NpcList[i].sceneY * posYRate, 0); npcPointDic.Add(NpcList[i].npcId, myPoint); MapItem item = myPoint.GetComponent <MapItem>(); if (item != null) { item.Init(ConfigMng.Instance.GetNPCTypeRef(NpcList[i].npcId).name, new Vector3(NpcList[i].pointX, NpcList[i].pointY), NpcList[i].scene); if (item.Obj != null) { UIEventListener.Get(item.Obj).onClick -= OnClickMapItem; UIEventListener.Get(item.Obj).onClick += OnClickMapItem; } } } }
/// <summary> /// 获取路径最近的怪物 /// </summary> /// <param name="_gameStage"></param> /// <param name="_player"></param> /// <param name="_needAlive"></param> /// <returns></returns> public static SmartActor GetClosestSmartActor(PlayerBase _player, List <SmartActor> smartActors, RelationType _relationType, ref float _instance) { List <SmartActor> smActors = smartActors; FDictionary distanceDic = new FDictionary(); FDictionary mobDic = new FDictionary(); int selfCamp = _player.Camp; SceneType sceneType = GameCenter.curGameStage.SceneType; Vector3 selfPosition = _player.transform.position; for (int i = 0; i < smActors.Count; i++) { SmartActor smActor = smActors[i]; if (smActor.gameObject != null && !smActor.isDead && !smActor.IsActor && ConfigMng.Instance.GetRelationType(selfCamp, smActor.Camp, sceneType) == _relationType) { Vector3[] path = GameStageUtility.StartPath(selfPosition, smActor.transform.position); if (path != null) { if (path.Length != 2) { distanceDic.Add(smActor.id, path.CountPathDistance());//距离计算方法改变 } else { distanceDic.Add(smActor.id, Vector3.Distance(selfPosition, smActor.transform.position)); } mobDic.Add(smActor.id, smActor); } } } int closestOne = -1; float distance = -1; foreach (int id in distanceDic.Keys) { if (distance < 0 || distance >= (float)distanceDic[id]) { closestOne = id; distance = (float)distanceDic[id]; } } _instance = distance; return(mobDic.ContainsKey(closestOne) ? mobDic[closestOne] as SmartActor : null); }
/// <summary> /// 获取路径最近的场景物品 /// </summary> /// <param name="_gameStage"></param> /// <param name="_player"></param> /// <param name="_needAlive"></param> /// <returns></returns> public static SceneItem GetClosestSceneItem(this GameStage _gameStage, PlayerBase _player) { List <SceneItem> sceneItems = _gameStage.GetSceneItems(); FDictionary distanceDic = new FDictionary(); FDictionary sceneDic = new FDictionary(); //int selfCamp = _player.Camp; //SceneType sceneType = GameCenter.curGameStage.SceneType; Vector3 selfPosition = _player.transform.position; Debug.Log(sceneItems.Count); for (int i = 0; i < sceneItems.Count; i++) { SceneItem sceneItem = sceneItems[i]; Debug.Log(sceneItem.isDummy + ":" + sceneItem.IsShowing); // if (sceneItem.isDummy || !sceneItem.IsShowing) continue; if (sceneItem.gameObject != null) { Vector3[] path = GameStageUtility.StartPath(selfPosition, sceneItem.transform.position); if (path != null) { if (path.Length != 2) { distanceDic.Add(sceneItem.id, path.CountPathDistance());//距离计算方法改变 } else { distanceDic.Add(sceneItem.id, Vector3.Distance(selfPosition, sceneItem.transform.position)); } sceneDic.Add(sceneItem.id, sceneItem); } } } int closestOne = -1; float distance = -1; foreach (int id in distanceDic.Keys) { if (distance < 0 || distance >= (float)distanceDic[id]) { closestOne = id; Debug.Log(closestOne); distance = (float)distanceDic[id]; } } return(sceneDic.ContainsKey(closestOne) ? sceneDic[closestOne] as SceneItem : null); }
protected void OnAddNpcs() { List <NPC> npcs = GameCenter.curGameStage.GetNPCs(); for (int i = 0; i < npcs.Count; i++) { NPC instance = npcs[i]; if (npcPointDic.ContainsKey(instance.id) || instance.isDead) { continue; } GameObject myPoint = Instantiate(npcPointInstance) as GameObject; myPoint.transform.parent = mapCtrl; myPoint.transform.localScale = Vector3.one; myPoint.transform.localPosition = new Vector3(instance.curSector.c * Mathf.PI, instance.curSector.r * Mathf.PI, 0); SmartActorMapPoint p = myPoint.AddComponent <SmartActorMapPoint>(); p.SetTarget(instance); npcPointDic.Add(instance.id, myPoint); } }
public void RefreshFlyMonster() { List <MonsterDistributionRef> list = ConfigMng.Instance.GetMonsterDistributionRefByScene(curScene); for (int i = 0; i < list.Count; i++) { GameObject myPoint = Instantiate(monsterInstance) as GameObject; myPoint.SetActive(true); myPoint.transform.parent = mapCtrl.transform; myPoint.transform.localScale = Vector3.one; myPoint.transform.localPosition = new Vector3(list[i].position.x * posXRate, list[i].position.z * posYRate, 0); mobPointDic.Add(list[i].monsterId, myPoint); MapItem item = myPoint.GetComponent <MapItem>(); if (item != null) { if (list[i].refreshObjType == 2) { SceneItemDisRef dis = ConfigMng.Instance.GetSceneItemDisRef(list[i].monsterId); if (dis != null) { SceneItemRef S = ConfigMng.Instance.GetSceneItemRef(dis.sceneItemId); if (S != null) { string moName = S.name; item.Init(moName, new Vector3(list[i].position.x, list[i].position.z), list[i].sceneId); } } } else { MonsterRef R = ConfigMng.Instance.GetMonsterRef(list[i].monsterId); if (R != null) { string moName = R.name + "(" + R.lv + "级)"; item.Init(moName, new Vector3(list[i].position.x, list[i].position.z), list[i].sceneId); } } if (item.Obj != null) { UIEventListener.Get(item.Obj).onClick -= OnClickMapItem; UIEventListener.Get(item.Obj).onClick += OnClickMapItem; } } } }
public void InitCreatePlayerInfo() { createPlayerInfoDic.Add(1, new PlayerBaseInfo(1, 1, true)); createPlayerInfoDic.Add(2, new PlayerBaseInfo(2, 2, true)); createPlayerInfoDic.Add(3, new PlayerBaseInfo(3, 3, true)); }
protected void InitMap() { if (manName != null) { manName.text = GameCenter.mainPlayerMng.MainPlayerInfo.CurSceneRef.name; } if (mapCtrl != null) { mapCtrl.localPosition = new Vector3(mapCtrlOriginPos.x - mainPlayer.curSector.c * Mathf.PI + mapFrameScale.x / 2.0f, mapCtrlOriginPos.y - mainPlayer.curSector.r * Mathf.PI + mapFrameScale.y / 2.0f, 0); } List <Monster> mobs = GameCenter.curGameStage.GetMobs(); for (int i = 0; i < mobs.Count; i++) { Monster instance = mobs[i]; if (mobPointDic.ContainsKey(instance.id) || instance.isDead) { continue; } GameObject myPoint = Instantiate(mobPointInstance) as GameObject; myPoint.transform.parent = mapCtrl; myPoint.transform.localScale = Vector3.one; myPoint.transform.localPosition = new Vector3(instance.curSector.c * Mathf.PI, instance.curSector.r * Mathf.PI, 0); SmartActorMapPoint p = myPoint.AddComponent <SmartActorMapPoint>(); p.SetTarget(instance); mobPointDic.Add(instance.id, myPoint); } List <NPC> npcs = GameCenter.curGameStage.GetNPCs(); for (int i = 0; i < npcs.Count; i++) { NPC instance = npcs[i]; if (npcPointDic.ContainsKey(instance.id)) { continue; } GameObject myPoint = Instantiate(npcPointInstance) as GameObject; myPoint.transform.parent = mapCtrl; myPoint.transform.localScale = Vector3.one; myPoint.transform.localPosition = new Vector3(instance.curSector.c * Mathf.PI, instance.curSector.r * Mathf.PI, 0); SmartActorMapPoint p = myPoint.AddComponent <SmartActorMapPoint>(); p.SetTarget(instance); npcPointDic.Add(instance.id, myPoint); } List <FlyPoint> flys = GameCenter.curGameStage.GetFlypoints(); for (int i = 0; i < flys.Count; i++) { FlyPoint instance = flys[i]; if (flyPointDic.ContainsKey(instance.id)) { continue; } GameObject myPoint = Instantiate(flyPointInstance) as GameObject; myPoint.transform.parent = mapCtrl; myPoint.transform.localScale = Vector3.one; myPoint.transform.localPosition = new Vector3(instance.curSector.c * Mathf.PI, instance.curSector.r * Mathf.PI, 0); flyPointDic.Add(instance.id, myPoint); } LimitMapCtr(); }