private bool TryFindNewAction() { // if there is are any possible actions and there is no other action pending if (actionList.Count > 0 && _actionPathPending == false) { for (var i = 0; i < actionList.Count; i++) { Debug.Assert(actionList[i] != null, "actiunea este nula"); // the action must not be null } var random = UnityEngine.Random.value; // sa schimb in random mai incolo actionList.Sort(CompareAction); // sort the action list based on the probability for (var i = 0; i < actionList.Count; i++) { var action = actionList[i]; if (random < action.probability) // if the random satisfies { var place = action.place; Debug.Log("trying to go to place <color=green> </color>" + place); RandomShuffle(ActionPlace.Dictionary[place]); // random shuffle the possible targets foreach (var possiblePlace in ActionPlace.Dictionary[place]) { Debug.Assert(possiblePlace != null); // it must not be null // the bot in there is null and is not occupied and is different from the last action if (possiblePlace.occupied == false && possiblePlace.bot == null && possiblePlace != _lastPlace) { currentState = State.AnyAction; // enter the any action state possiblePlace.occupied = true; // occupy the action //possiblePlace.bot = this; _lastPlace = possiblePlace; _currentAction = action; // set the currentAction CurrentDestination = action.position + possiblePlace.transform.position; // set the destination to the relative pos _agent.SetDestination(CurrentDestination); Debug.Log( "<color=red>botul : " + name + " a reusit sa intre in actiunea : " + _currentAction.name + "</color>", this); Debug.Log("<color=red>destinatia este</color>" + CurrentDestination, possiblePlace); _actionPathPending = true; return(true); } } } else { //Debug.Log($"<color=red> " + action.name + "X</color>"); } } } return(false); }
void Awake() { Debug.Log("called awake"); if (Instance == null) { Instance = this; } infectionCurve = new AnimationCurve(); coughCurve = new AnimationCurve(); ActionPlace.ClearDict(); Bot.ClearBots(); MeetPoint.ClearList(); }
public override Action[] GetLocationActions(int currentTime, int locationIndex, Character player) { List <Action> actions = new List <Action>(); if (toggleAllowed) { string toggleText = isBurning ? "Turn Oven Off" : "Turn Oven On"; ActionToggle actionToggle = new ActionToggle(currentTime, toggleText, this); actions.Add(actionToggle); } bool freeSpace = false; for (int i = 0, length = itemsInside.Length; i < length; i++) { Item item = itemsInside[i]; if (item == null) { freeSpace = true; } else { ActionRecover actionRecover = new ActionRecover(currentTime, "Take " + item.ToShortString() + " from Oven", item, i, this, locationIndex); actions.Add(actionRecover); } } if (freeSpace) { for (int i = 0, count = player.inventory.Count; i < count; i++) { Item item = player.inventory[i]; //TODO, maybe allow the oven to filter somehow, this currently allows placing ingredients in oven // if(item.GetType() == typeof(Cake)) { ActionPlace actionPlace = new ActionPlace(currentTime, "Place " + item.ToShortString() + " in Oven", item, i, this, locationIndex); actions.Add(actionPlace); } } } return(actions.ToArray()); }
public IEnumerator animateAction(ActionPlace place, PlayerInput input) { this.setCantMoveForSeconds (1.5f); mCollider.enabled = false; Vector3 playerPos = this.mTransform.position; mTransform.position = place.gameObject.transform.position; string objName = this.ritualObject.objectName(); animator.SetTrigger ("Action"); yield return new WaitForSeconds (1f); animator.SetTrigger ("EndAction"); string actionName = Triplets.getActionName (objName, place.gameObject.name, input); yield return new WaitForSeconds (1f); StartCoroutine(place.animateObject (actionName)); mTransform.position = playerPos; mCollider.enabled = true; yield break; }
public override Action[] GetLocationActions(int currentTime, int locationIndex, Character player) { List <Action> actions = new List <Action>(); bool freeSpace = false; for (int i = 0, length = itemsInside.Length; i < length; i++) { Item item = itemsInside[i]; if (item == null) { freeSpace = true; } else { ActionRecover actionRecover = new ActionRecover(currentTime, "Detach " + item.ToString() + " from Car", item, i, this, locationIndex); actions.Add(actionRecover); } } if (freeSpace) { for (int i = 0, count = player.inventory.Count; i < count; i++) { Wheel wheel = player.inventory[i] as Wheel; if (wheel != null) { ActionPlace actionPlace = new ActionPlace(currentTime, "Attach " + wheel.ToString() + " to Car", wheel, i, this, locationIndex); actions.Add(actionPlace); } } } return(actions.ToArray()); }
public override Action[] GetLocationActions(int currentTime, int locationIndex, Character character) { List <Action> actions = new List <Action>(); Key key = Utils.FindItemOfType <Key>(character.inventory); if (locked) { if (key != null) { ActionUse actionUse = new ActionUse(currentTime, "Unlock " + this.GetType(), key, this); actions.Add(actionUse); } } else { if (key != null) { ActionUse actionUse = new ActionUse(currentTime, "Lock " + this.GetType(), key, this); actions.Add(actionUse); } //TODO, this is a good start for handling box content through timeline if (GameManager.Instance.itemTimeline.characters[0].timeline.Count > 0) { ItemEntry itemEntry = GameManager.Instance.itemTimeline.GetLatestFixedEntry(currentTime, age, locationIndex); Box previousBox = itemEntry.item as Box; if (previousBox != null) { //Debug.Log(previousBox.ToString() +", "+locationIndex); } } bool freeSpace = false; for (int i = 0, length = itemsInside.Length; i < length; i++) { Item item = itemsInside[i]; if (item == null) { freeSpace = true; } else { ActionRecover actionRecover = new ActionRecover(currentTime, "Take " + item.ToString() + " from Box " + age, item, i, this, locationIndex); actions.Add(actionRecover); } } if (freeSpace) { for (int i = 0, count = character.inventory.Count; i < count; i++) { Item item = character.inventory[i]; if (item is Box == false) { ActionPlace actionPlace = new ActionPlace(currentTime, "Place " + item.ToString() + " in Box " + age, item, i, this, locationIndex); actions.Add(actionPlace); } } } } return(actions.ToArray()); }
void UpdateManu(){ if (!inSecondPhase || GameManager.singleton == null) { return; } // Update generatorInRange if (this.ritualObject == null) { this.generatorInRange = this.getGeneratorInRange (); } else { this.generatorInRange = null; } // Update actionPlace if (this.ritualObject == null) { this.actionPlace = null; } else { this.actionPlace = this.getActionPlaceInRange(); } // Update UI if (GameManager.singleton!=null && GameManager.singleton.temporaryUItext != null) { GameManager.singleton.temporaryUItext.text = this.GetPlayerActionsInfo (); } if (Input.GetAxis("DownAction") > 0.5f) { if (this.ritualObject==null && this.generatorInRange != null) { // grab object from generator GameObject obj = this.generatorInRange.Generate(); this.ritualObject = obj.GetComponent<RitualObject> (); this.ritualObject.pickUpPosition = this.ritualObject.transform.position; obj.transform.SetParent (this.transform); GameManager.singleton.currentStep.ritualObject = this.ritualObject.objectName (); int objScore = Step.scoreObject (GameManager.singleton.currentStep, GameManager.singleton.currentOptimalStep()); GameManager.singleton.scoreManager.AddGenPoints (objScore); } } if (this.ritualObject != null && this.actionPlace != null) { bool pressedOther = false; PlayerInput playerInput = PlayerInput.Down; if (Input.GetAxis ("UpAction") > 0.5f) { pressedOther = true; playerInput = PlayerInput.Up; } if (Input.GetAxis ("LeftAction") > 0.5f) { pressedOther = true; playerInput = PlayerInput.Left; } if (Input.GetAxis ("RightAction") > 0.5f) { pressedOther = true; playerInput = PlayerInput.Right; } if(pressedOther) { this.ritualObject.Action (playerInput); GameManager.singleton.scoreManager.resetTimer (); // update current step info and start next step GameManager.singleton.currentStep.actionPlace = this.actionPlace.gameObject.name; GameManager.singleton.currentStep.playerInput = playerInput; int actionScore = Step.scoreAction (GameManager.singleton.currentStep, GameManager.singleton.currentOptimalStep()); GameManager.singleton.scoreManager.AddGenPoints (actionScore); GameManager.singleton.startNewStep (); } } }