public void Escape(BasicEnemy enemy) { BasicEntity entity = enemy.m_entity; VoxelBlocks map = GameObject.Find("Voxel Map").GetComponent <VoxelBlocks> (); List <BasicEntity> enemyList = entity.GetComponent <MonitorComponent> ().m_enemy; if (AiToInput.CallFriend(entity, enemyList)) { //呼叫成功 StateComponent state = entity.GetComponent <StateComponent> (); state.AnimationStart(); state.m_actionPoint -= 1; state.Invoke("AnimationEnd", 1); return; } Vector3 escapePos = FindPath.GetNearestFriend(entity.GetComponent <BlockInfoComponent> ().m_logicPosition); if (escapePos == Vector3.down) { //无路可走等死 return; } else { AiToInput.Move(entity, escapePos); } return; }
//每帧都会调用对应的实体 public override void Execute(List <BasicEntity> entities) { foreach (BasicEntity e in entities) { AttackComponent attack = e.GetComponent <AttackComponent> (); VoxelBlocks map = GameObject.Find("Voxel Map").transform.GetComponent <VoxelBlocks> (); AbilityComponent ab = e.GetComponent <AbilityComponent> (); InputComponent input = e.GetComponent <InputComponent> (); StateComponent ap = e.GetComponent <StateComponent> (); int i = AiToInput.GetAbilityCount(e, M_LinkedType); //检测是否按下攻击键 if (i >= ab.m_temporaryAbility.Count || i != input.currentKey) { continue; } //若无攻击对象则获取周围可攻击对象 if (attack.enemy == null) { attack.enemy = GetEnemyAround(e); if (attack.enemy == null) { return; } } List <Vector3> el = new List <Vector3> (); foreach (var enemy in attack.enemy) { el.Add(enemy.GetComponent <BlockInfoComponent> ().m_logicPosition); } UISimple ui = GameObject.Find("UI").GetComponent <UISimple> (); ui.ShowUI(el, 2); //左键攻击 if (input.leftButtonDown) { BasicEntity enemy = map.GetBlockByLogicPos(input.currentPos).entity; //检测当前选中敌人是否处于攻击范围内 List <BasicEntity> list = GetEnemyAround(e); if (list != null && !list.Contains(enemy)) { attack.enemy = list; return; } //扣除敌人HP值 DeadComponent dead = enemy.GetComponent <DeadComponent> (); StateComponent state = e.GetComponent <StateComponent> (); dead.hp -= attack.STR; state.m_actionPoint -= 1; state.Invoke("AnimationEnd", 1); state.AnimationStart(); //播放攻击动画 //播放敌人受击动画 //减少AP } } }
void Bomb(BasicEntity entity, float mr, float ridus, int demage) { InputComponent input = entity.GetComponent <InputComponent>(); VoxelBlocks map = GameObject.Find("Voxel Map").GetComponent <VoxelBlocks>(); //获取鼠标位置与角色位置的距离 float r = (input.currentPos - entity.GetComponent <BlockInfoComponent>().m_logicPosition).magnitude; //若距离大于预设值则退出 if (r > mr) { return; } //获取炸弹投掷后可能影响的范围 List <Vector3> ar = FindPath.GetArea(input.currentPos, Mathf.FloorToInt(ridus)); //显示炸弹影响范围 List <DeadComponent> mc = new List <DeadComponent>(); UISimple ui = GameObject.Find("UI").GetComponent <UISimple>(); ui.ShowUI(ar, 3); //获取该范围内所有的敌人的生命脚本 foreach (var pos in ar) { BlockInfo block = map.GetBlockByLogicPos(pos); if (block != null && block.entity != null) { if (block.entity.GetComponent <BlockInfoComponent>().m_blockType == BlockType.Enemy) { mc.Add(block.entity.GetComponent <DeadComponent>()); } } } //显示可被影响的敌人 //若按下鼠标左键则扔出炸弹,影响周围敌人。 if (input.leftButtonDown) { Debug.Log(mc.Count); foreach (var m in mc) { if (m != null) { m.hp -= demage; } } ItemComponent itemComp = entity.GetComponent <ItemComponent>(); //移除炸弹 itemComp.item.Remove(ItemType.Bomb); entity.GetComponent <ItemComponent>().current = ItemType.Null; //使用一次消耗一点行动点 StateComponent state = entity.GetComponent <StateComponent>(); state.m_actionPoint -= 1; state.AnimationStart(); state.Invoke("AnimationEnd", 1); } }
public override void Execute(List <BasicEntity> entities) { foreach (var entity in entities) { KnockComponent knock = entity.gameObject.GetComponent <KnockComponent>(); AbilityComponent ab = entity.GetComponent <AbilityComponent>(); InputComponent input = entity.GetComponent <InputComponent>(); StateComponent ap = entity.GetComponent <StateComponent>(); int i = AiToInput.GetAbilityCount(entity, M_LinkedType); if (i >= ab.m_temporaryAbility.Count || i != input.currentKey) { knock.m_area = null; continue; } //获取影响范围 if (knock.m_area == null) { knock.m_area = FindPath.GetArea(knock.GetComponent <BlockInfoComponent>().m_logicPosition, knock.m_ridus); } UISimple ui = GameObject.Find("UI").GetComponent <UISimple>(); ui.ShowUI(knock.m_area, 3); VoxelBlocks map = GameObject.Find("Voxel Map").GetComponent <VoxelBlocks>(); List <BasicEntity> enemy = new List <BasicEntity>(); //获取影响范围内的敌人 foreach (var pos in knock.m_area) { var e = map.GetBlockByLogicPos(pos).entity; if (e != null) { if (e.GetComponent <BlockInfoComponent>().m_blockType == BlockType.Enemy) { enemy.Add(e); } } } //UI显示范围与敌人 if (input.leftButtonDown) { foreach (var e in enemy) { Debug.Log(e.name); e.GetComponent <MonitorComponent>().m_voice.Add(entity.GetComponent <BlockInfoComponent>().m_logicPosition); } ui.ShowUI(null, 3); StateComponent state = entity.GetComponent <StateComponent>(); state.m_actionPoint -= 1; state.AnimationStart(); state.Invoke("AnimationEnd", 1); } } }
public override void Execute(List <BasicEntity> entities) { int ck = getCurrentKey(keySize); Vector3 mousePos = getMousePos(); foreach (var entity in entities) { InputComponent input = entity.GetComponent <InputComponent>(); //过滤所有AI控制的角色 if (entity.GetComponent <BlockInfoComponent>().m_blockType == BlockType.Enemy) { //一旦AI出现问题,过久未操作就进行强制操作 if (input.afkTime > StateStaticComponent.afkLimiteTime) { StateComponent state = entity.GetComponent <StateComponent>(); state.AnimationStart(); state.m_actionPoint -= 1; state.Invoke("AnimationEnd", 0.5f); } input.afkTime += Time.deltaTime; continue; } if (ck == (int)InputType.StopTurn) { StateComponent state = entity.GetComponent <StateComponent>(); state.m_actionPoint = 0; state.Invoke("AnimationEnd", 0.5f); state.AnimationStart(); StateStaticComponent.m_currentSystemState = StateStaticComponent.SystemState.Action; } if (ck != 0) { input.currentKey = ck; } if (mousePos != Vector3.down) { input.currentPos = mousePos; } input.leftButtonDown = Input.GetMouseButtonDown(0); input.rightButtonDown = Input.GetMouseButtonDown(1); input.midButtonDown = Input.GetMouseButtonDown(2); if (input.rightButtonDown) { input.currentKey = 0; } } }
public override void Execute(List <BasicEntity> entities) { foreach (BasicEntity entity in entities) { AbilityComponent ab = entity.GetComponent <AbilityComponent>(); InputComponent input = entity.GetComponent <InputComponent>(); StateComponent ap = entity.GetComponent <StateComponent>(); CheerUpComponent cu = entity.GetComponent <CheerUpComponent>(); int i = AiToInput.GetAbilityCount(entity, M_LinkedType); if (i >= ab.m_temporaryAbility.Count || i != input.currentKey) { continue; } ap.AnimationStart(); ap.m_actionPoint += cu.m_addAp; if (!ab.m_coldDown.ContainsKey(M_LinkedType)) { ab.m_coldDown.Add(M_LinkedType, cu.m_coldDown); } ap.Invoke("AnimationEnd", 1); } }