public static void buildMoveToRangeOfEntity(DecisionTree p_decisionTree, Entity p_sourceEntity) { /* * For now, only Entities with characteristics are considered elligible to move to. * //TODO, having a more complex targetting system. */ if (EntityComponentContainer.Components.ContainsKey(typeof(EntityCharacteristics))) { var l_entitiesToGo = EntityComponentContainer.Components[typeof(EntityCharacteristics)]; for (int i = 0; i < l_entitiesToGo.Count; i++) { Entity l_entity = l_entitiesToGo[i].AssociatedEntity; if (l_entity != p_sourceEntity) { foreach (ADecisionNode l_moveToNavigationNode in createMoveToEntityTree(p_decisionTree, p_decisionTree.RootNode, p_sourceEntity, l_entity)) { // For every potential target, we try to attack DecisionTree.linkDecisionNodes( p_decisionTree, l_moveToNavigationNode, AttackNode.alloc(p_sourceEntity, l_entity, EntityComponent.get_component <Attack>(p_sourceEntity))); } } } } }
private void ConstructBehaviourTree() { DieNode dieNode = new DieNode(this, animator); AttackNode attackNode = new AttackNode(animator); IsCloserNode isCloseToAttack = new IsCloserNode(this.transform, Player.instance.transform, agent.stoppingDistance); ChaseNode chaseNode = new ChaseNode(Player.instance.transform, agent, animator); WalkNode walkNode = new WalkNode(agent, animator, changeDestinationDelay, walkRadius); WasHittedNode wasHittedNode = new WasHittedNode(this); IsPlayerVisibleNode isPlayerVisibleNode = new IsPlayerVisibleNode(transform, zombieSettings.ZombieAgroRadius, zombieSettings.FieldsOfViewAngle, playerLayer); Sequence attackSequence = new Sequence(new List <Node>() { isCloseToAttack, attackNode }); Sequence chaseSequence = new Sequence(new List <Node>() { isPlayerVisibleNode, chaseNode }); Sequence hittedSequence = new Sequence(new List <Node>() { wasHittedNode, chaseNode }); topNode = new Selector(new List <Node>() { dieNode, attackSequence, hittedSequence, chaseSequence, walkNode }); }
override public void OnNodeEnter() { base.OnNodeEnter(); AttackNode next = GetPort("output").Connection.node as AttackNode; next.timeOffset = this.normalizedOffset; attackGraph.MoveNode(next); }
//builds the characters behaviour tree private void constructBehaviourTree() { //health node checks if health is below threshold HealthNode healthNode = new HealthNode(this, m_lowHealthThreshold); //inverted health checks if health is above threshhold Inverter invertHealth = new Inverter(healthNode); //Cover GetCoverNode getCoverNode = new GetCoverNode(target.transform, this); GoToCoverNode goToCoverNode = new GoToCoverNode(this, m_speed); HealNode Heal = new HealNode(20, this, m_healthRegenRate); Sequence CoverSequence = new Sequence(new List <BNode> { healthNode, getCoverNode, goToCoverNode, Heal }); //chase Range = new RangeNode(m_detectionRange, target.transform, gameObject.transform, this); Chase = new ChaseNode(target.transform, this, m_speed); Sequence ChaseSequence = new Sequence(new List <BNode> { invertHealth, Range, Chase }); //wander RangeNode wanderRange = new RangeNode(m_detectionRange, target.transform, gameObject.transform, this); Inverter invertWanderRange = new Inverter(wanderRange); WanderNode wander = new WanderNode(this, m_speed); Sequence WanderSequence = new Sequence(new List <BNode> { invertWanderRange, wander }); //attack attackRange = new RangeNode(m_attackRange, target.transform, gameObject.transform, this); attack = new AttackNode(target.transform, this); Sequence AttackSequence = new Sequence(new List <BNode> { attackRange, attack }); //root node topNode = new Selector(new List <BNode> { CoverSequence, AttackSequence, ChaseSequence, WanderSequence }); }
private void OnMoveStateEndEvent(object sender, MoveStateEndArgs e) { if (e.GetType == typeof(AttackNode)) { // Check which attack it was Debug.Log("Attack that ended is: " + ((AttackNode)sender).ID); } myState = CharState.Idle; currentNode = null; }
public bool AddAttack(AttackNode node) { // don't add if the node has same id as us // or if we already lead to that attack if (node.ID == ID || nextAttacks.Contains(node)) { return(false); } // Add node as possible chain route nextAttacks.Add(node); return(true); }
//builds the characters behaviour tree private void constructBehaviourTree() { ////Cover GetCoverNode getCoverNode = new GetCoverNode(m_target.transform, this); GoToCoverNode goToCoverNode = new GoToCoverNode(this, m_speed); HealNode Heal = new HealNode(20, this, m_healthRegenRate); Sequence CoverSequence = new Sequence(new List <BNode> { getCoverNode, goToCoverNode, Heal }); coverTopNode = new Selector(new List <BNode> { CoverSequence }); ////chase m_chase = new ChaseNode(m_target.transform, this, m_speed); Sequence ChaseSequence = new Sequence(new List <BNode> { m_chase }); chaseTopNode = new Selector(new List <BNode> { ChaseSequence }); ////wander WanderNode wander = new WanderNode(this, m_speed); Sequence WanderSequence = new Sequence(new List <BNode> { wander }); WanderTopNode = new Selector(new List <BNode> { WanderSequence }); ////attack m_attack = new AttackNode(m_target.transform, this); Sequence AttackSequence = new Sequence(new List <BNode> { m_attack }); attackTopNode = new Selector(new List <BNode> { AttackSequence }); }
// Start is called before the first frame update void Start() { bulletLayer = LayerMask.NameToLayer("PlayerBullet"); anim = GetComponent <Animator>(); rb = GetComponent <Rigidbody>(); mainSel = new Selector(); runStateSel = new Selector(); deathSeq = new Sequence(); chaseSeq = new Sequence(); surrenderSeq = new Sequence(); deathHealthCheck = new DeathHealthCheckNode(); surrenderCheck = new SurrenderCheckNode(); death = new DeathNode(); surrender = new SurrenderNode(); attack = new AttackNode(); injured = new InjuredRunNode(); normal = new NormalRunNode(); chase = new ChasePlayer(); node = mainSel; mainSel.nList.Add(deathSeq); mainSel.nList.Add(surrenderSeq); mainSel.nList.Add(chaseSeq); deathSeq.nList.Add(deathHealthCheck); deathSeq.nList.Add(death); surrenderSeq.nList.Add(surrenderCheck); surrenderSeq.nList.Add(surrender); chaseSeq.nList.Add(runStateSel); chaseSeq.nList.Add(chase); chaseSeq.nList.Add(attack); runStateSel.nList.Add(injured); runStateSel.nList.Add(normal); }
private void LaunchAttack() { AttackNode nextNode = null; if (currentNode == null) { nextNode = attackNodes[0]; } else { nextNode = currentNode.Next(); if (nextNode == null) { // Do nothing, let attack time out } else { nextNode = currentNode.Next(); } } if (nextNode != null) { // Set current state to attacking myState = CharState.Attack; nextNode.StartAttack(1.0f); // This delay in setting the current node is so that // If the current attack was activated previously, // it won't re-start itself currentNode = nextNode; } // TODO: Do a hitstun on hit opponents // TODO: Apply damage }
private void CheckMouseInput(Event currentEvent) { if (!_graphRect.Contains(currentEvent.mousePosition) || !(focusedWindow == this || mouseOverWindow == this)) { return; } //Pan if (currentEvent.button == 2 && currentEvent.type == EventType.MouseDown) { _panningScreen = true; _prevPan = new Vector2(_graphPan.x, _graphPan.y); _originalMousePosition = currentEvent.mousePosition; } else if (currentEvent.button == 2 && currentEvent.type == EventType.MouseUp) { _panningScreen = false; } if (_panningScreen) { float newX, newY; newX = _prevPan.x + currentEvent.mousePosition.x + _originalMousePosition.x; newY = _prevPan.y + currentEvent.mousePosition.y + _originalMousePosition.y; _graphPan.x = newX > 0 ? 0 : newX; _graphPan.y = newY > 0 ? 0 : newY; Repaint(); } //Muestro la context Menu if (currentEvent.button == 1 && currentEvent.type == EventType.MouseDown) { ContextMenuOpen(); } //Selección del nodo. AttackNode currentNode = null; for (int i = 0; i < AllNodes.Count; i++) { AllNodes[i].CheckMouse(Event.current, _graphPan); if (AllNodes[i].OverNode) { currentNode = AllNodes[i]; } } //Selección anterior. var prevSelected = currentNode; if (currentEvent.button == 0 && currentEvent.type == EventType.MouseDown) { if (currentNode != null) { selectedNode = currentNode; } else { selectedNode = null; } if (prevSelected != currentNode) { Repaint(); } } }