public override void OnStart() { // leader = WarServerManager.Instance.npcMgr.ActiveHero; ServerLifeNpc npc = GetComponent <ServerLifeNpc>(); fleetofollowRange = npc.data.configData.fleeRange; }
public override void OnAwake() { myHero = GetComponent <ServerLifeNpc>(); pathFind = myHero.pathFinding; mTrans = myHero.transform; param = new WarMsgParam(); }
// cast a ray between startPosition and targetPosition. Return true if a defensive object was hit private bool rayCollision(Vector3 startPosition, Vector3 targetPosition, out RaycastHit hit) { startPosition.y = 1; targetPosition.y = 1; float dis = AITools.GetSqrDis(this.transform.position, target.Value.transform.position); if (dis <= 0) { dis = 1.0f; } if (avoidDefeneUnits && Physics.Raycast(startPosition, targetPosition - startPosition, out hit, dis)) { ServerLifeNpc npc = null; if ((npc = hit.collider.GetComponent <ServerLifeNpc>()) != null) { return((npc.Camp == myHero.Camp) && (npc.UniqueID != myHero.UniqueID) && (npc.ATKRange == myHero.ATKRange)); } } hit = new RaycastHit(); return(false); }
public override void OnStart() { npc = GetComponent <ServerLifeNpc>(); if (npc == null) { Debug.LogWarning("npc is null"); } if (npc.data == null) { Debug.LogWarning("npc.data is null"); } mTrans = npc.transform; mTargetTrans = target.Value.transform; pathFind = npc.pathFinding; param = new WarMsgParam(); if (npc.data.configData.moveable == Moveable.Movable) { pathFind.speed = npc.data.configData.speed; pathFind.enabled = true; pathFind.destination = target.Value.transform.position; } }
public override void OnAwake() { npc = GetComponent <ServerLifeNpc> (); mTrans = npc.transform; seekRange = npc.data.configData.seekRange * 2.0f; chaPool = WarServerManager.Instance.realServer.monitor.CharactorPool; }
public override void OnAwake() { myHero = GetComponent <ServerLifeNpc>(); pathFind = myHero.pathFinding; npcList = new List <ServerNPC> (); param = new WarMsgParam(); }
/// <summary> /// 数据的初始化 /// </summary> /// <param name="go">Go.</param> /// <param name="num">Number.</param> /// <param name="id">Identifier.</param> /// <param name="camp">Camp.</param> void DynamicDataInit(ServerNPC curHero, NPCConfigData econfig, CAMP camp) { /// /// 填充阵营 /// curHero.Camp = camp; /// /// 填充NPC数据 /// NPCData dynamicData = new NPCData(); dynamicData.rtData = new NPCRuntimeData(econfig); dynamicData.configData = econfig; dynamicData.btData = new NPCBattleData(); curHero.data = dynamicData; /// /// 向WarManager注册 /// serNpcMgr.SignID(curHero); WarServerManager warMgr = WarServerManager.Instance; /// /// 填充技能数据 /// RtNpcSkillModel skMd = new RtNpcSkillModel(econfig.ID, curHero.UniqueID); ServerLifeNpc life = curHero as ServerLifeNpc; if (life != null) { life.runSkMd = skMd; } /// /// 填充默认的buff /// for (short i = 0; i < Consts.MAX_SKILL_COUNT; ++i) { RtSkData sk = skMd.getRuntimeSkill(i); if (sk != null) { int passive = sk.skillCfg.PassiveBuff; if (passive > 0) { BuffCtorParam ctor = new BuffCtorParam() { bufNum = passive, fromNpcId = curHero.UniqueID, toNpcId = curHero.UniqueID, origin = OriginOfBuff.BornWithSkill, initLayer = 1, duration = Consts.USE_BUFF_CONFIG_DURATION, }; warMgr.bufMgr.createBuff(ctor); } } } }
public override void OnAwake() { enermys = new List <ServerLifeNpc> (); hero = GetComponent <ServerLifeNpc>(); mTrans = this.transform; seekRange = hero.data.configData.seekRange + hero.data.configData.radius; //得到对方阵营的英雄 hostile = hero.Camp.Hostile(); }
public override void OnAwake() { npc = GetComponent <ServerLifeNpc>(); param = new WarMsgParam(); if (npc.data.configData.moveable == Moveable.Movable) { pathFind = npc.pathFinding; } }
public override void OnStart() { if (self) { npc = GetComponent <ServerLifeNpc> (); } else { npc = hero.Value; } }
public override void OnAwake() { npc = GetComponent <ServerLifeNpc>(); pathFind = npc.pathFinding; param = new WarMsgParam(); tempList = new List <ServerLifeNpc>(); sortList = new SortedList <int, ServerLifeNpc>(); targets = new List <ServerLifeNpc> (); mTrans = npc.transform; animMsg = new IpcNpcAnimMsg(); }
public override void OnAwake() { npc = GetComponent <ServerLifeNpc> (); npcSkill = WarServerManager.Instance.npcSkill; skillList = new List <RtSkData> (); for (short i = 0; i < Consts.MAX_SKILL_COUNT; i++) { skillList.Add(npc.runSkMd.getRuntimeSkill(i)); } rtSkill.Value = null; }
public override void OnStart() { if (self) { npc = GetComponent <ServerLifeNpc> (); } else { npc = hero.Value; } chaPool = WarServerManager.Instance.realServer.monitor.CharactorPool; }
//得到距离自己最近的npc public static ServerLifeNpc GetNeareastNPC(Vector3 from, ServerLifeNpc[] npcs) { float dis = Mathf.Infinity; ServerLifeNpc near = null; for (int i = 0; i < npcs.Length; i++) { float distance = GetSqrDis(from, npcs [i].transform.position); if (distance < dis * dis) { dis = distance; near = npcs[i]; } } return(near); }
public override void OnAwake() { myHero = GetComponent <ServerLifeNpc>(); if (myHero.data.configData.moveable == Moveable.Movable) { // cache for quick lookup // navMeshAgent = gameObject.GetComponent<NavMeshAgent> (); navMeshAgent = myHero.pathFinding; // set the speed and angular speed // navMeshAgent.angularSpeed = rotationSpeed.Value; // navMeshAgent.speed = myHero.data.configData.speed; param = new WarMsgParam(); } }
//如果是嘲讽状态,而且嘲讽者或者,返回成功 public override TaskStatus OnUpdate() { if (npc.curStatus.AnySame(NpcStatus.Taunt)) { BNPC caster = WarServerManager.Instance.npcMgr.GetNPCByUniqueID(npc.getHighestHatred); if (caster != null && caster is ServerLifeNpc) { ServerLifeNpc lifeTarget = caster as ServerLifeNpc; if (lifeTarget != null && lifeTarget.IsAlive) { target.Value = lifeTarget; return(TaskStatus.Success); } } } return(TaskStatus.Failure); }
public override void OnStart() { npc = GetComponent <ServerLifeNpc>(); mTransform = npc.transform; npcMgr = WarServerManager.Instance.npcMgr; CAMP camp = CAMP.Player; if (npc.Camp == CAMP.Enemy) { camp = CAMP.Player; } else if (npc.Camp == CAMP.Player) { camp = CAMP.Enemy; } tower = npcMgr.GetBuildByType(camp, BuildNPCType.Tower); }
bool IsUnderTower() { towers = WarServerManager.Instance.npcMgr.GetBuildByType(npc.Camp, BuildNPCType.Tower); if (towers == null || towers.Count == 0) { return(false); } ServerLifeNpc nearTower = AITools.GetNeareastNPC(mTrans.position, towers.ToArray()); if (nearTower != null) { // 塔后面 seekrange一半的地方以内 Vector3 targetPos = nearTower.transform.forward * nearTower.data.configData.seekRange * -1; if (AITools.IsInRange(mTrans.position, nearTower.data.configData.seekRange * 0.5f, targetPos)) { return(true); } } return(false); }
public override void OnStart() { npc = GetComponent <ServerLifeNpc> (); }
//初始化AI private void InitAi(ServerNPC npc) { // //如果是npc刷新点 if (npc.data.num == NpcMgr <BNPC> .FRESH_NPC) { #if NO_SOLDIER #else BehaviorTree tree = npc.gameObject.GetComponent <BehaviorTree> (); if (tree == null) { tree = npc.gameObject.AddComponent <BehaviorTree>(); } tree.ExternalBehavior = AiLoader.load(AILoader.NPC_FRESH); tree.StartWhenEnabled = true; tree.RestartWhenComplete = false; #endif } else { NPCAIType type = (NPCAIType)npc.dataInScene.AIType; ServerLifeNpc life = npc as ServerLifeNpc; switch (type) { case NPCAIType.Pathfind_Atk: { BehaviorTree tree = npc.gameObject.GetComponent <BehaviorTree> (); if (tree == null) { tree = npc.gameObject.AddComponent <BehaviorTree>(); } tree.ExternalBehavior = AiLoader.load(AILoader.PATHFIND_ATK); tree.StartWhenEnabled = true; tree.RestartWhenComplete = true; if (life != null && !life.pathFinding.enabled) { life.pathFinding.enabled = true; } if (!tree.enabled) { tree.enabled = true; } break; } case NPCAIType.Simple_PfAtk: { BehaviorTree tree = npc.gameObject.GetComponent <BehaviorTree> (); if (tree == null) { tree = npc.gameObject.AddComponent <BehaviorTree>(); } tree.ExternalBehavior = AiLoader.load(AILoader.SIMPLE_PFATK); tree.StartWhenEnabled = true; tree.RestartWhenComplete = true; if (life != null && !life.pathFinding.enabled) { life.pathFinding.enabled = true; } if (!tree.enabled) { tree.enabled = true; } break; } case NPCAIType.Patrol: { BehaviorTree tree = npc.gameObject.GetComponent <BehaviorTree> (); if (tree == null) { tree = npc.gameObject.AddComponent <BehaviorTree>(); } tree.ExternalBehavior = AiLoader.load(AILoader.NORMAL_ATTACK); tree.StartWhenEnabled = true; tree.RestartWhenComplete = true; if (life != null && !life.pathFinding.enabled) { life.pathFinding.enabled = true; } if (!tree.enabled) { tree.enabled = true; } break; } } } }
public override void OnAwake() { myHero = GetComponent <ServerLifeNpc>(); }
public override void OnStart() { npc = GetComponent <ServerLifeNpc>(); mTransform = npc.transform; seekRange = npc.data.configData.seekRange; }
public override TaskStatus OnUpdate() { curGroup = freshGroupModel.GetFreshGroup(curPool.freshPool[curGroupIndex.Value]); if (curGroup != null) { npcCnt.count.Value = curGroup.freshGroup.Count; } else { //空的一波怪 curIndex.Value = 0; curGroupIndex.Value++; curGroupCnt.Value++; //循环利用刷新池的数据 if (curGroupIndex.Value >= curPool.freshPool.Count) { curGroupIndex.Value = 0; } return(TaskStatus.Success); } if (curIndex.Value < curGroup.freshGroup.Count) { npcNum = curGroup.freshGroup [curIndex.Value]; } ServerNPC newNpc = WarServerManager.Instance.npcMgr.GetNpcFromCache(npcNum); if (newNpc != null) { WarServerManager.Instance.npcMgr.RemoveNpcFromCache(newNpc); } else { newNpc = loader.Load(npcNum, myHero.dataInScene.camp, mWarPoint); } GameObject go = newNpc.gameObject; go.SetActive(true); go.transform.localPosition = this.transform.localPosition; newNpc.data.rtData.curHp = newNpc.data.rtData.totalHp; newNpc.Camp = myHero.dataInScene.camp; newNpc.data.btData.way = myHero.dataInScene.way; newNpc.dataInScene = myHero.dataInScene; //发送消息通知客户端 SendCreateNpcMsg(newNpc); SendHpMsg(newNpc); InitAi(newNpc); InitBuff(newNpc); if (newNpc is ServerLifeNpc) { ServerLifeNpc life = newNpc as ServerLifeNpc; life.SwitchAutoBattle(true); } //同一拨,当前造兵索引++ curIndex.Value++; //同一拨,如果造了最后一个兵,当前造兵波数++ if (curIndex.Value >= curGroup.freshGroup.Count) { curIndex.Value = 0; curGroupIndex.Value++; curGroupCnt.Value++; //循环利用刷新池的数据 if (curGroupIndex.Value >= curPool.freshPool.Count) { curGroupIndex.Value = 0; } return(TaskStatus.Success); } return(TaskStatus.Success); }
public override void OnAwake() { myHero = GetComponent <ServerLifeNpc>(); pathFind = myHero.pathFinding; }
public override void OnAwake() { param = new WarMsgParam(); myHero = GetComponent <ServerLifeNpc>(); }
public override void SetValue(object value) { mValue = (ServerLifeNpc)value; }
public override void OnAwake() { myHero = GetComponent <ServerLifeNpc>(); pathFind = myHero.pathFinding; param = new WarSrcAnimParam(); }
public override TaskStatus OnUpdate() { if (!InitFinish) { InitData(); return(TaskStatus.Running); } InitData(); if (enermys == null || enermys.Count == 0) { return(TaskStatus.Failure); } //如果范围内有敌方敌人, List <ServerLifeNpc> list = AITools.GetAllNPCInRange(mTrans.position, seekRange, enermys.ToArray()); if (list != null && list.Count > 0) { ServerLifeNpc newTarget = null; //判断有没有攻击目标 IEnumerable <ServerNPC> enemyTargets = hero.FindAtkTarget(Sight.NearSight); if (enemyTargets != null && enemyTargets.Count <ServerNPC> () > 0) { newTarget = enemyTargets.ElementAt <ServerNPC> (0) as ServerLifeNpc; } else { enemyTargets = hero.FindAtkTarget(); if (enemyTargets != null && enemyTargets.Count <ServerNPC> () > 0) { newTarget = enemyTargets.ElementAt <ServerNPC> (0) as ServerLifeNpc; } } if (newTarget != null && newTarget.IsAlive) { //如果目标是建筑 if (newTarget.data.configData.type == LifeNPCType.Build) { //如果攻击目标是基地,判断三路是否有一路已经被破了,如果有一路被破了,才能打基地 if (newTarget.data.configData.bldType == BuildNPCType.Base) { bool canAtk = false; for (int i = 0; i < 3; i++) { //get all the tower on the way List <ServerLifeNpc> bldWay = WarServerManager.Instance.npcMgr.GetBuildByWay(newTarget.Camp, (BATTLE_WAY)i, false); if (bldWay != null && bldWay.Count > 0) { List <ServerLifeNpc> aliveBld = WarServerManager.Instance.npcMgr.GetBuildByWay(newTarget.Camp, (BATTLE_WAY)i, true); if (aliveBld != null && aliveBld.Count == 0) { canAtk = true; break; } } } if (canAtk) { target.Value = newTarget; return(TaskStatus.Success); } } //如果不是基地,判断前一个是否还活着,如果 else { // 得到当前这一路的所有活着的建筑 List <ServerLifeNpc> bldWay = WarServerManager.Instance.npcMgr.GetBuildByWay(newTarget.Camp, newTarget.dataInScene.way, true); if (bldWay != null && bldWay.Count > 0) { //检查活着的建筑里,有没有前一个建筑 bool canAtk = true; for (int i = 0; i < bldWay.Count; i++) { if (bldWay [i].dataInScene.index == newTarget.dataInScene.index - 1) { canAtk = false; break; } } if (canAtk) { target.Value = newTarget; return(TaskStatus.Success); } } } } else { target.Value = newTarget; return(TaskStatus.Success); } } } return(TaskStatus.Failure); }
public override void OnAwake() { npc = GetComponent <ServerLifeNpc> (); npcMgr = WarServerManager.Instance.npcMgr; mTrans = npc.transform; }