public void inspect() { PubSub.subscribe("inspect_rotate", this); PubSub.subscribe("inspect_action", this); locationInBag = this.transform.localPosition; rotationInBag = this.transform.localRotation; parentBag = this.transform.parent; // Turn off casting shadows enableShadows(false); // TODO - When action is taken, don't forget to enable shadows again // Target object position Vector3 targetPosition = Game.instance.gameCamera.transform.position + Game.instance.gameCamera.transform.rotation * (Vector3.forward * 18f); this.transform.parent = null; Misc.AnimateMovementTo("content-zoom-" + id, this.gameObject, targetPosition); // Special method to run when starting inspection on this object ActionOnInspect[] actionOnInspects = GetComponents <ActionOnInspect>(); foreach (ActionOnInspect actionOnInspect in actionOnInspects) { Debug.Log(actionOnInspect); if (actionOnInspect != null) { actionOnInspect.run(); } } inspecting = true; BagContentProperties.currentInspectedItem = this; }
public void run() { Vector3 chosenScale = ItsRandom.pickRandom(possibleScales.ToList()); BagContentProperties bagContentProperties = this.GetComponent <BagContentProperties>(); bagContentProperties.objectSize = Vector3.Scale(bagContentProperties.objectSize, chosenScale); bagContentProperties.transform.localScale = chosenScale; bagContentProperties.GetComponent <Rigidbody>().mass = chosenScale.magnitude; }
public void registerWrongAction(BagContentProperties item) { if (Array.IndexOf(item.acceptableActions, item.actionTaken) == -1) { string newMistake = "warning"; if (item.acceptableActions.Contains(InspectUIButton.INSPECT_TYPE.POLICE)) { newMistake = item.category; } if (WORST_MISTAKES.IndexOf(worstMistake) > WORST_MISTAKES.IndexOf(newMistake)) { worstMistake = newMistake; } } }
public void inspectDone() { PubSub.unsubscribe("inspect_rotate", this); PubSub.unsubscribe("inspect_action", this); BagContentProperties.currentInspectedItem = null; // Special method to run when starting inspection on this object ActionOnInspect[] actionOnInspects = GetComponents <ActionOnInspect>(); foreach (ActionOnInspect actionOnInspect in actionOnInspects) { if (actionOnInspect != null) { actionOnInspect.run(true); } } }
private IEnumerator reactOnItemInspection(BagContentProperties item) { // Get applicable audio clips string coroutineKey = "inspect-reaction-" + item.id; List <AudioClip> itemAudioClips = clips.FindAll(i => i.name.Contains(item.category + "-")); yield return(new WaitForSeconds(ItsRandom.randomRange(4f, 8f, personRandom))); while (Misc.HasCoroutine(coroutineKey)) { if (ItsRandom.randomRange(0, 100, personRandom) < 25) { yield return(playVoice(ItsRandom.pickRandom(itemAudioClips, personRandom))); } yield return(new WaitForSeconds(ItsRandom.randomRange(3f, 5f, personRandom))); } }
private void assignProppertiesBasedOnBagContentProperties(BagContentProperties bagContentProperties) { // Assign paper material Material[] materials = paperMaterialObject.GetComponent <Renderer>().materials; materials[0] = ItsRandom.pickRandom(paperMaterials); paperMaterialObject.GetComponent <Renderer>().materials = materials; // Medicine name string displayName = bagContentProperties.displayName; string pillName = displayName.Substring("Bottle of \"".Length); string medicineNameStr = pillName.Substring(0, pillName.Length - 1); medicineName.text = " - " + medicineNameStr; // Person name Person person = BagHandler.instance.currentBagInspect.bagDefinition.person; string patientNameStr = person.personName; patientName.text = patientNameStr; // Doctor name // TODO - Real logic ("real"/fake names) string doctorNameStr = ItsRandom.pickRandom(new List <string>() { "Nick Riviera", "Julius Hibbert", "Hannibal Lecter", "Saw U Apart", "Genital Fondler", "Pepper" }); doctorName.text = "Dr. " + doctorNameStr; doctorSignature.font = ItsRandom.pickRandom(signatureFonts); doctorSignature.text = doctorNameStr; PillBottle pillBottle = bagContentProperties.gameObject.GetComponent <PillBottle>(); Debug.Log("Color 1: " + pillBottle.colorHalf1.ToString()); Debug.Log("Color 2: " + pillBottle.colorHalf2.ToString()); pillColorHalf1.color = pillBottle.colorHalf1; pillColorHalf2.color = pillBottle.colorHalf2; }
private void reactOnInspectAction(InspectUIButton.INSPECT_TYPE action, BagContentProperties item) { if (action == InspectUIButton.INSPECT_TYPE.MANUAL_INSPECT || action == InspectUIButton.INSPECT_TYPE.MANUAL_INSPECT_NEW) { // TODO - Maybe don't react on 50% (ajdust level) if (ItsRandom.randomBool(personRandom)) { StartCoroutine(reactOnAction("manual")); } } else if (action == InspectUIButton.INSPECT_TYPE.TRASHCAN) { StartCoroutine(reactOnAction("throw")); } else if (action == InspectUIButton.INSPECT_TYPE.POLICE) { StartCoroutine(reactOnAction("police")); } }
private void stopTimerAndPossiblyReact(InspectUIButton.INSPECT_TYPE action, BagContentProperties item) { Misc.StopCoroutine("inspect-reaction-" + item.id); reactOnInspectAction(action, item); }
private void setTimerAndReact(BagContentProperties item) { Coroutine itemReaction = StartCoroutine(reactOnItemInspection(item)); Misc.SetCoroutine("inspect-reaction-" + item.id, itemReaction); }
public InspectActionBag(int bagId, BagContentProperties item, InspectUIButton.INSPECT_TYPE action) { this.bagId = bagId; this.item = item; this.action = action; }
IEnumerator placeItemsInBag(BagProperties bagProperties, int amount, List <BagContentProperties> toBePlacedInTrays, Person person, String randomSeed) { int yieldEveryXthItem = 5; int yieldCounter = yieldEveryXthItem; // float lastCycleStart = Time.realtimeSinceStartup; Vector3 bagSize = bagProperties.placingCube.transform.localScale; bagProperties.placingCube.SetActive(true); Bounds bagBounds = bagProperties.placingCube.GetComponent <Collider>().bounds; bagProperties.placingCube.SetActive(false); // Debug.Log(bagBounds); // TODO - Hidden items, make sure to check person config on frequency of putting these items in // TODO - For now, always put one item GameObject hiddenObj = ItsRandom.pickRandom <BagContentType>(bagContentTypesHidden.ToList(), randomSeed).contentObj; GameObject hiddenItem = Instantiate(hiddenObj); hiddenItem.transform.parent = bagProperties.transform; BagContentProperties hiddenItemProperties = hiddenItem.GetComponent <BagContentProperties> (); // Randomize place in bottom of bag findPlaceForItemInBag(hiddenItemProperties, bagProperties, randomSeed, int.MaxValue, true); bagProperties.bagContents.Add(hiddenItemProperties); // TODO - This code block is only made for forcing an illegal item GameObject gunObj = ItsRandom.pickRandom <BagContentType>(bagContentTypesIllegal.ToList(), randomSeed).contentObj; GameObject gun = Instantiate(gunObj); gun.transform.parent = bagProperties.contents.transform; BagContentProperties gunProperties = gun.GetComponent <BagContentProperties> (); // Randomize place in bag findPlaceForItemInBag(gunProperties, bagProperties, randomSeed, int.MaxValue, false); bagProperties.bagContents.Add(gunProperties); // TODO - END for (int i = 0; i < amount; i++) { List <int> weights = bagContentTypesLegal.Select(obj => obj.frequency).ToList(); List <GameObject> gameObjects = bagContentTypesLegal.Select(obj => obj.contentObj).ToList(); // TODO - below are the REAL CODE - NOT ABOVE // List<int> weights = bagContentTypes.Select(obj => obj.frequency).ToList(); // List<GameObject> gameObjects = bagContentTypes.Select(obj => obj.contentObj).ToList(); GameObject randomGameObject = ItsRandom.pickRandomWithWeights(weights, gameObjects, randomSeed); // Check if item should be in tray, or not instantiated by any other reason (eg. not place 3 guns in bag...) bool acceptItem = true; // TODO - Do this! // bool acceptItem = randomGameObject.GetComponent<BagContentInstantiationRules>()(toBePlacedInTrays, person); if (!acceptItem) { i--; continue; } GameObject contentPiece = Instantiate(randomGameObject); contentPiece.transform.parent = bagProperties.contents.transform; // Randomly rotate 90°-angle // TODO - When rotation turned on, objects seem to fall outside bag // contentPiece.transform.localRotation = Quaternion.Euler(0f, 90f * Misc.random.Next(), 0f); BagContentProperties bagContentProperties = contentPiece.GetComponent <BagContentProperties> (); // Randomize place in bag bool itemFitsInBag = findPlaceForItemInBag(bagContentProperties, bagProperties, randomSeed, 10, false); if (itemFitsInBag) { bagContentProperties.person = person; bagProperties.bagContents.Add(bagContentProperties); // Trigger "random"-functions on it RandomInterface[] randomInterfaces = contentPiece.GetComponents <RandomInterface>(); foreach (RandomInterface randomInterface in randomInterfaces) { randomInterface.run(); } } else { Debug.Log("Item removed: " + contentPiece); contentPiece.transform.parent = null; Destroy(contentPiece); } /* * yieldCounter--; * if (yieldCounter == 0) { * yieldCounter = yieldEveryXthItem; * // if (lastCycleStart + MAX_ITEM_PLACE_CYCLE_SECONDS < Time.realtimeSinceStartup) { * Debug.Log("YIELD"); * yield return null; * // // TODO - Compact items by code (move downwards) * // yield return null; * // lastCycleStart = Time.realtimeSinceStartup; * } */ } Debug.Log("Items in bag: " + bagProperties.bagContents.Count()); // Debug.Break(); yield return(null); }
public PROPAGATION onMessage(string message, object data) { if (message == "Click") { if (Game.instance.cameraXPos == 2 && !Game.instance.zoomedOutState) { Vector3 position = Vector3.zero; if (data.GetType() == typeof(Vector2)) { Vector2 posV2 = (Vector2)data; position = new Vector3(posV2.x, posV2.y); } else { position = (Vector3)data; } // Get camera Camera camera = GetComponent <Game>().gameCamera; RaycastHit hit; Ray ray = camera.ScreenPointToRay(position); if (bagInspectState == BagInspectState.NOTHING) { if (Physics.Raycast(ray, out hit)) { Debug.Log(hit.transform.gameObject.name); BagProperties clickedBagProperties = hit.transform.GetComponent <BagProperties>(); // // TODO - Can't contents be clicked directly when in a bag without lid? // if (clickedBagProperties == null) {} if (clickedBagProperties != null && !clickedBagProperties.isOpen) { clickedBagProperties.showItems(true); clickedBagProperties.animateLidState(true); clickedBagProperties.enableContentColliders(true); currentBagInspect = clickedBagProperties; bagInspectState = BagInspectState.BAG_OPEN; clickedBagProperties.resetActionOnItems(); } } } else if (bagInspectState == BagInspectState.BAG_OPEN) { // Debug.Log("Bag is open; " + BAG_CONTENTS_LAYER_MASK); bool isBagEmpty = currentBagInspect.contents.transform.childCount == 0; if (!isBagEmpty) { if (Physics.Raycast(ray, out hit, Mathf.Infinity, BAG_CONTENTS_LAYER_MASK)) { Debug.Log(hit.transform.gameObject.name); BagContentProperties clickedBagContentProperties = hit.transform.GetComponent <BagContentProperties>(); if (clickedBagContentProperties != null) { switchToGameCamera(true); clickedBagContentProperties.inspect(); Misc.AnimateBlurTo("blurCamera", Game.instance.blurCamera.GetComponent <BlurOptimized>(), 1, 3f, 2); bagInspectState = BagInspectState.ITEM_INSPECT; PubSub.publish("inspect_active"); PubSub.publish("bag_inspect_item", new InspectActionBag(currentBagInspect.id, clickedBagContentProperties, InspectUIButton.INSPECT_TYPE.UNDEFINED)); } } } else { // Bag is empty, if clicked - close it and end inspect state if (Physics.Raycast(ray, out hit)) { // Debug.Log(hit.transform.gameObject.name); BagProperties clickedBagProperties = hit.transform.GetComponent <BagProperties>(); if (clickedBagProperties == currentBagInspect) { inspectBagDone(); } } } } } } return(PROPAGATION.DEFAULT); }