public override IEnumerator BuffCoroutine(UnitInfo owner) { AddBuffAction(owner); Rigidbody rigidbody = owner.GetComponent <Rigidbody>(); float buffTimeCount = buffTime; do { if (!owner.GetMovement().isOnGround) { Vector3 newVelocity = rigidbody.velocity; if (newVelocity.y < 0) { /*newVelocity.y *= 0.8f; * rigidbody.velocity = newVelocity;*/ } } buffTimeCount -= Time.deltaTime; yield return(null); } while (buffTimeCount > 0); ActionBehaviour aBehaviour = owner.GetAction().GetBehaviour("Flying"); if (aBehaviour) { owner.GetAction().RemoveAction(aBehaviour); GameObject.Destroy(aBehaviour.gameObject); } owner.RemoveBuff(this); }
public void ActivateAgent(ActionBehaviour _action) { //Debug.Log("activating agent"); thisAgent.SetRootAction(_action); thisAgent.SetSocialInterruption(); }
public void LogActionBegin(ActionBehaviour _action) { float currentTime = clock.timeOfDay; behaviourLog.Add(new AgentLog(_action.name, currentTime)); // run this once to get the action decision hierarchy GetRunningActions(); }
public override void AddBuffAction(UnitInfo _unit) { GameObject buffActionPrefab = Resources.Load <GameObject>("Actions/AFlying"); Transform newParent = _unit.GetAction().GetActionList()[0].transform.parent; ActionBehaviour newSkill = GameObject.Instantiate(buffActionPrefab, newParent).GetComponent <ActionBehaviour>(); _unit.GetAction().GetActionList().Add(newSkill); newSkill.transform.localPosition = Vector3.zero; }
// protected override void actionBehaviourInit() { base.actionBehaviourInit(); // // if (gameUnitBelongSide == RTSGameUnitBelongSide.Player) { ActionBehaviour ac = gameObject.AddComponent <Action_Collect> (); ActionList.Add(ac); } }
// protected override void actionBehaviourInit() { base.actionBehaviourInit(); // UnitManager.ShareInstance.Buildings[playerInfo].Add(gameObject); // ActionBehaviour aa = gameObject.AddComponent <Action_Attack> (); ActionList.Add(aa); ActionBehaviour ab = gameObject.AddComponent <Action_Build> (); ActionList.Add(ab); }
public void RemoveAction(ActionBehaviour _behaviour) { int index = actionList.FindIndex(b => b == _behaviour); if (usingActionIndex != -1) { if (usingActionIndex == index) { StopAction(); actionList.RemoveAt(index); } } }
protected override void actionBehaviourInit() { base.actionBehaviourInit(); // UnitManager.ShareInstance.Armys[playerInfo].Add(gameObject); // // if (playerInfo.gameUnitBelongSide == RTSGameUnitBelongSide.Player) { Interaction m = gameObject.AddComponent <Move> (); interactionList.Add(m); ActionBehaviour aa = gameObject.AddComponent <Action_Attack> (); ActionList.Add(aa); } // }
// this is for providing a list of currently running actions through the hierarchy public void GetRunningActions() { runningActions.Clear(); ActionBehaviour runningAction = thisAgent.linkedRootAction.action; // do a quick pass down the hierarchy while (!runningAction.isLeafAction) { runningActions.Add(runningAction.name); runningAction = runningAction.TopAction; } // add the running leaf action runningActions.Add(behaviourLog[behaviourLog.Count - 1].action); }
//Takes a look at child actions and picks the one with best utility score public float EvaluateChildActions() { if (topAction != null) { previousAction = topAction; } topActionScore = 0.0f; for (int i = 0; i < linkedChildActions.Count; i++) { if (linkedChildActions[i].isActionEnabled == true) { linkedChildActions[i].action.EvaluateActionUtil(); if (isConsoleLogging) { Debug.Log("Evaluating " + linkedChildActions[i].action.GetName() + " Score: " + linkedChildActions[i].action.GetActionScore()); } if (linkedChildActions[i].action.GetActionScore() >= topActionScore) { topAction = linkedChildActions[i].action; topActionScore = linkedChildActions[i].action.GetActionScore(); topLinkedActionIndex = i; } } } if (topAction != previousAction) { newAction = true; } if (isConsoleLogging) { Debug.Log(name + ". New topAction: " + topAction.name + ". With actionScore: " + topActionScore); } currentActionScore = topActionScore; return(topActionScore); }
// Update is called once per frame void Update() { if (Input.GetKey("b") && !single) { single = true; //print("agent instantiated"); townAgents.Add(Instantiate(baseAgent, startLocation.position, Quaternion.identity)); GameObject newAgent = townAgents[townAgents.Count - 1]; newAgent.SetActive(true); // set the name newAgent.name = "AliveBoy"; Character newAgentCharacter = newAgent.GetComponent <Character>(); //set the home newAgentCharacter.homeLocation = startLocation; //set the occupation //newAgentCharacter.occupation = OccupationType.1; //set the action hierarchy // make an instance of the gameobject, set it as a child of the new agent GameObject newActions = Instantiate(baseAction, newAgent.transform.position, Quaternion.identity); newActions.SetActive(true); newActions.transform.parent = newAgent.transform; // get the actions to run their StartAwake function newActions.BroadcastMessage("StartAwake"); tempRootaction = newActions.GetComponent <ActionBehaviour>(); newAgentCharacter.ActivateAgent(tempRootaction); } }
public void CheckActionChildren(ActionBehaviour action, string name, ActionBehaviour.Del del) { if (action.name == name) { SetActionDelegate(action, del); return; } else if (!action.isLeafAction) { for (int i = 0; i < action.linkedChildActions.Count; i++) { CheckActionChildren(action.linkedChildActions[i].action, name, del); } } else { return; } }
public bool UseSkill(ActionBehaviour _behaviour, bool forced = false) { if (forced == false && usingActionIndex != -1) { return(false); } int index = actionList.FindIndex(get => get == _behaviour); if (index < 0) { return(false); } if (forced && actionList[usingActionIndex] != _behaviour) { StopAction(); } if (actionList[index].PlayAction()) { usingActionIndex = index; return(true); } return(false); }
protected override IEnumerator combat() { Vector3 forward = (targetUnit.transform.position - pivot.position); forward.y = 0; forward.Normalize(); float targetAngle = Quaternion.Angle(transform.rotation, Quaternion.LookRotation(forward)); float targetDistance = Vector3.Distance(pivot.position, actionTarget.transform.position); float delay = 0; float rotateDelay = 0; actionComponent.GetBehaviour("DragonDash").SetTarget(targetUnit.transform); actionComponent.GetBehaviour("DragonBreathAir").SetTarget(targetUnit.transform); ik.SetAllTarget(actionTarget); actionComponent.UseSkill("DragonRoar", true); while (true) { if (unitInfo.GetCondition() >= ConditionData.UnitCondition.stuned) { yield return(null); continue; } forward = (targetUnit.transform.position - transform.position); forward.Normalize(); targetAngle = Quaternion.Angle(transform.rotation, Quaternion.LookRotation(forward)); if (delay > 0 && !actionComponent.IsUsingAction()) { delay = Mathf.Clamp(delay - Time.deltaTime, 0, 10); } if (rotateDelay > 0) { rotateDelay = Mathf.Clamp(rotateDelay - Time.deltaTime, 0, 10); } ActionBehaviour currentAction = actionComponent.GetUsingAction(); if (readyType == ActionReadyType.Roar) {// POINT -- ACTION ETC if (currentAction == null || currentAction.GetActionName() != "WakeUp") { actionComponent.UseSkill("DragonRoar", true); readyType = ActionReadyType.Fly; delay = 0.5f; } } else if (delay == 0 && readyType == ActionReadyType.Fly) { actionComponent.UseSkill("DragonFly", true); readyType = ActionReadyType.none; delay = 0.5f; } else if (delay == 0) { if (!weaknessPointObject.isEnable) { StartCoroutine(AppearWeakness(UnityEngine.Random.Range(0, weaknessPoints.Count))); } bool isGroundMoving = movement.GetMovingType() == CharacterMovement.MOVING_TYPE.ground; if (!movement.isOnGround && isGroundMoving) { yield return(null); continue; } if (isGroundMoving) { targetDistance = Vector3.Distance(transform.position, targetUnit.transform.position); } else { Vector2 p1 = new Vector2(transform.position.x, transform.position.z); Vector2 p2 = new Vector2(targetUnit.transform.position.x, targetUnit.transform.position.z); targetDistance = Vector2.Distance(p1, p2); } foreach (AIStateActionDragon sA in aiStateAction) { //POINT -- ACTION if (sA.enable && sA.movingType == movement.GetMovingType() && targetAngle < sA.angleLimit && !sA.behaviour.IsCoolDown() && IsInRange(targetDistance, sA.minDistance, sA.maxDistance)) { movement.Stop(); movement.StopRotating(); actionComponent.UseSkill(sA.behaviour, false); delay = 0.5f; break; } } if (!actionComponent.IsUsingAction() && (!isGroundMoving || (isGroundMoving && movement.isOnGround))) { float minD = (isGroundMoving) ? minMovingDistance : minAirMovingDistance; float maxD = (isGroundMoving) ? maxMovingDistance : maxAirMovingDistance; if (IsInRange(targetDistance, minD, maxD)) { float speed = (isGroundMoving) ? walkSpeed : flySpeed; //POINT -- moving forward.y = 0; movement.Move(forward, speed, 0.2f); movement.RotateTo(forward, 5); actionTarget.position = Vector3.Lerp(actionTarget.position, targetUnit.transform.position, Time.deltaTime * lookSpeed); } else { //POINT -- rotating if (movement.IsMoving()) { movement.Stop(); movement.StopRotating(); } ik.ToggleIK(true); float a = Quaternion.Angle(transform.rotation, Quaternion.LookRotation(forward)); Quaternion rot = Quaternion.LookRotation(forward); forward.y = 0; if (a > 40 && !movement.IsRotating() && rotateDelay == 0) { movement.RotateTo(forward, turnSpeed); rotateDelay = 3; } if (a < 90) { actionTarget.position = Vector3.Lerp(actionTarget.position, targetUnit.transform.position, Time.deltaTime * lookSpeed); } } } } yield return(null); } }
public void SetActionDelegate(ActionBehaviour action, ActionBehaviour.Del del) { action.handle = del; return; }
public void SetRootAction(ActionBehaviour arg) { linkedRootAction.action = arg; }
public void Visit(ActionBehaviour <TContext> obj) { PrintNode(obj); }
public WaitForMessageReceiving(ActionBehaviour _behaviour, string _msg) { behaviour = _behaviour; message = _msg; }
public WaitForStateChange(ActionBehaviour _behaviour, int _toState) { behaviour = _behaviour; toState = _toState; }