public void CreateNodesAndTriggers() { foreach (KeyValuePair <string, KeyValuePair <string, string> > triggerStatePair in TriggerData.TriggerStates) { AddTrigger(triggerStatePair, Transforms.Triggers, false, false); } foreach (KeyValuePair <string, List <ActionNodeState> > actionNodeStateList in NodeData.NodeStates) { for (int i = 0; i < actionNodeStateList.Value.Count; i++) { ActionNodeState actionNodeState = actionNodeStateList.Value [i]; GameObject newNodeGameObject = Transforms.Nodes.gameObject.FindOrCreateChild(actionNodeState.FullName).gameObject; ActionNode newNode = newNodeGameObject.GetOrAdd <ActionNode> (); newNode.State = actionNodeState; newNode.State.Transform.ApplyTo(newNode.transform); newNode.State.actionNode = newNode; newNode.State.ParentGroupPath = actionNodeStateList.Key; } } }
public bool FindGuardNode() { if (GuardNode == null) { ActionNodeState guardNodeState = null; if (ParentChunk.GetNode(State.GuardActionNodeName, false, out guardNodeState)) { guardNodeState.OccupantIsDead = State.GuardIsDead; GuardNode = guardNodeState.actionNode; if (GuardNode == null) { //Debug.Log ("Couldn't get guard node from action node state, quitting in " + name); return(false); } } else { //Debug.Log ("Couldn't get guard node from parent chunk, quitting in " + name); return(false); } } return(true); }
public bool GetNode(string actionNodeName, bool skipReserved, out ActionNodeState nodeState) { bool foundNode = false; nodeState = null; foreach (Transform nodeTransform in Transforms.Nodes) { if (nodeTransform.name.Contains(actionNodeName)) { ActionNode actionNode = null; if (nodeTransform.gameObject.HasComponent <ActionNode> (out actionNode) && actionNode.State.Name == actionNodeName) { if (!(skipReserved && actionNode.IsReserved)) { nodeState = actionNode.State; foundNode = true; break; } } } } return(foundNode); }
public static Creature SpawnRandomCreature(CreatureFlags flags, ActionNode node, WIGroup group) { Creature newCreature = null; return(newCreature); }
public IEnumerator SpawnOverTime() { ActionNodeState nodeState = AvailableSpawnNodes [0]; if (State.SpawnBehindPlayer) { Vector3 nodeDirection = Vector3.zero; float dot = 0f; float leastDotSoFar = Mathf.Infinity; for (int i = 0; i < AvailableSpawnNodes.Count; i++) { nodeDirection = (AvailableSpawnNodes [i].actionNode.Position - Player.Local.Position).normalized; dot = Vector3.Dot(Player.Local.FocusVector, nodeDirection); if (dot < leastDotSoFar) { leastDotSoFar = dot; nodeState = AvailableSpawnNodes [i]; } } } CurrentSpawnNode = nodeState.actionNode; if (!string.IsNullOrEmpty(State.CustomSpeech)) { //overrides node state's speech nodeState.CustomSpeech = State.CustomSpeech; } if (!string.IsNullOrEmpty(State.CustomConversation)) { //overrides node state's speech nodeState.CustomConversation = State.CustomConversation; } //wait until we're ready to spawn double waitUntil = Frontiers.WorldClock.AdjustedRealTime + State.SpawnDelay; while (Frontiers.WorldClock.AdjustedRealTime < waitUntil) { yield return(null); } //then boom! go if (!Characters.GetOrSpawnCharacter(CurrentSpawnNode, State.CharacterName, ParentChunk.AboveGroundGroup, out SpawnedCharacter)) { Debug.Log("Couldn't spawn character"); } else { if (!string.IsNullOrEmpty(State.DTSOnSpawn)) { if (!State.DTSFirstTimeOnly || State.NumTimesTriggered < 2) { Talkative talkative = null; if (SpawnedCharacter.worlditem.Is <Talkative> (out talkative)) { talkative.SayDTS(State.DTSOnSpawn); SpawnedCharacter.LookAtPlayer(); } } } } mSpawningOverTime = false; yield break; }
public static IEnumerator UpdateGoToActionNode(Motile m, MotileAction action) { if (action.HasLiveTarget) { //m.rvoController.usePath = (action.Method == MotileGoToMethod.Pathfinding); m.GoalObject.position = action.LiveTarget.Position; ActionNode node = null; if (action.LiveTarget.IOIType == ItemOfInterestType.ActionNode) //see if we're there yet { node = action.LiveTarget.node; float distanceFromTarget = Vector3.Distance(m.worlditem.Position, m.GoalObject.position); //use the range variable for our distance check if (distanceFromTarget <= action.Range) { m.TargetMovementSpeed = m.State.MotileProps.SpeedWalk; //can we occupy this thing? if (node.CanOccupy(m.worlditem)) //hooray! we can occupy it { if (node.TryToOccupyNode(m.worlditem)) //we've occupied it, huzzah { m.LastOccupiedNode = node; m.TargetMovementSpeed = 0.0f; FinishAction(m, action); yield break; } //if we didn't occupy it, it might mean we're not close enough //because our range may be larger than the node range //so try again next frame } else //whoops, node is inaccessible //set to error { action.State = MotileActionState.Error; action.Error = MotileActionError.TargetInaccessible; } } else if (distanceFromTarget <= action.Range * 1.5) { //don't stop, but do slow down a bit m.TargetMovementSpeed = m.State.MotileProps.SpeedWalk; } else { //run and catch up! m.TargetMovementSpeed = m.State.MotileProps.SpeedRun; } } else //weird, it got unloaded for some reason { action.State = MotileActionState.Error; action.Error = MotileActionError.TargetNotLoaded; } } else //weird, live target is gone for some reason //try to get it again //(not implemented) { action.State = MotileActionState.Error; action.Error = MotileActionError.TargetNotLoaded; } //otherwise get live target yield return(null); yield break; }
public static bool FinishAction(Motile m, MotileAction action) { //Debug.Log("Finishing action " + action.Name); if (action.BaseAction) { return(false); } m.AvoidingObstacle = false; action.State = MotileActionState.Finishing; bool finished = false; switch (action.Type) { case MotileActionType.FocusOnTarget: finished = true; break; case MotileActionType.FollowGoal: finished = true; break; case MotileActionType.FollowRoutine: finished = true; break; case MotileActionType.WanderIdly: finished = true; break; case MotileActionType.FollowTargetHolder: m.GoalHolder = null; //move goal to group transform //this will stop the target holder from using it finished = true; break; case MotileActionType.GoToActionNode: //if we're at the action node, vacate the node //if we're not at the action node, do nothing if (m.LastOccupiedNode == null && action.HasLiveTarget && action.LiveTarget.IOIType == ItemOfInterestType.ActionNode) //if we actually have a live target { ActionNode node = action.LiveTarget.node; if (!node.IsOccupant(m.worlditem)) //try to occupy it one last time { node.TryToOccupyNode(m.worlditem); //if we don't make it oh well } } finished = true; break; case MotileActionType.Wait: default: finished = true; break; } if (finished) { if (action.State != MotileActionState.Error) //preserve the error { action.State = MotileActionState.Finished; } action.UpdateCoroutine = null; //reset this action.WTFinished = WorldClock.AdjustedRealTime; m.LastFinishedAction = action; //send final messages and whatnot action.OnFinishAction.SafeInvoke(); action.OnFinishAction = null; if (m != null && m.GoalObject != null) { m.GoalObject.parent = m.worlditem.Group.transform; } } //wait for finish to end (not implemented) //force refresh hud //m.rvoController.PositionLocked = false; //m.rvoController.RotationLocked = false; if (m != null) { m.worlditem.RefreshHud(); } //action state is finsihed return(finished); }