示例#1
0
        internal void OnInteract(Entity entity, MessageSession session, InteractMsg msg)
        {
            if (entity.Has <Fightable>())
            {
                var template = DataCenter.Instance.GetDatum <InteractTemplate>(msg.InteractId);
                if (template == null)
                {
                    Logger.Write("Request a invalid interact[{0}]", msg.InteractId);
                    return;
                }

                EffectSystem.Affect(entity, template);
            }
            else
            {
                PositionSystem.Global.Interact(entity, targets =>
                {
                    // default interaction - remove removables
                    foreach (var target in targets.Where(target => target.Has <Removable>() && target.Get <Removable>().Action))
                    {
                        // despawn target
                        PositionSystem.Global.Disappear(target);
                        EntityBinder.Instance.Remove(target);
                        EntityManager.Instance.Remove(target.Id);
                    }
                });
            }
        }
	// Initially, this will be just Handle User COmmands, but should also migrate any character responses like acknowledgements in here.

	public override bool ExecuteCommand( string command, string preferredHandler = ""){
		// commands initialed thru the NLU, Menu, or Filter should pass thru this for processing
		
		//TODO migrate these next two blocks down to a Trauma Brain override of this method 
		if (HandleUserCommand (command)) { // decision panel, abort, confirm handled here
			// send out the ISM for tracking...
			InteractMsg imsg = new InteractMsg(null, command );
			InteractStatusMsg ism = new InteractStatusMsg(imsg);
			Brain.GetInstance().PutMessage(ism);
			return true;
		}

		if (limitInteractions){
			if (!enabledInteractions.Contains(command)){
				if (SAPISpeechManager.Instance != null)
					SAPISpeechManager.Speak ("That's not what we need to do right now.");
				// give some other kind of feedback ?
				return false;
			}
			else{
				// the desired interaction was called, now open up so scripts can use interactions to run...
				limitInteractions = false;
			}
		}
		
		if (!IsCommandAvailable( command)){ // voice commands can come in that are not currently possible
			VoiceMgr.GetInstance().Play ("ProcedureResident","VOICE:CANT:DO:THAT");
//			if (SAPISpeechManager.Instance != null)
//				SAPISpeechManager.Speak ("We can't do that right now");
			return false;
		}

		if (IsCommandQueued( command)){ // voice commands can come in that are already queued
			VoiceMgr.GetInstance().Play ("ProcedureResident","VOICE:ALREADY:WORKING");
//			if (SAPISpeechManager.Instance != null)
//				SAPISpeechManager.Speak ("We're already working on that.");
			return false;
		}
		
		// Handle Confirm Command here ?
		SAPISpeechManager.Speak (InteractionMgr.GetInstance ().Get (command).response);
		return base.ExecuteCommand (command, preferredHandler);

	}
示例#3
0
	public override void HandleInteractMsg(InteractMsg msg)
	{
        base.HandleInteractMsg(msg);
        //msg.map.Debug();

        // respond to med administer
        InteractMsg interact = msg as InteractMsg;
        if (interact != null)
        {
            if (interact.map.item == "MED:ADMINISTER")
            {
                UnityEngine.Debug.Log("Provider.PutMessage(" + interact.map.item + ")");

                MedAdministrationDialogMsg dmsg = new MedAdministrationDialogMsg();
                dmsg.command = DialogMsg.Cmd.open;
                dmsg.modal = true;
                dmsg.provider = this;
                dmsg.patient = null;
                MedAdministrationDialog.GetInstance().PutMessage(dmsg);
            }
        }

    }
示例#4
0
    public InteractStatusMsg(InteractMsg msg)
    {
        // save name
        InteractName = msg.map.item;
        // save msg
        InteractMap = msg.map;
		// create new param list
		Params = new List<string>();
    }
示例#5
0
    public override void OnGUI()
    {
        if(!IsVisible())
            return;

        Texture2D texture;
        base.OnGUI();

        float x = Screen.width * 0.5f - 300;
        float y = Screen.height * 0.5f - 190;
        float width = 600;
        float height = 420;

        // Render background
        GUILayout.BeginArea(new Rect(x, y, width, height), skin.box);
        {
            // Render title
            GUILayout.Label(dialogueTitle, skin.customStyles[1], GUILayout.MaxWidth(width));

            // Render NPC dialogue
            GUILayout.BeginHorizontal();
            {
                // Render NPC picture
                GUILayout.BeginVertical();
                {
                    texture = DialogueTree.Instance.GetProfileImage(image);
                    if (texture != null)
                        GUILayout.Label(texture, skin.label);
                }
                GUILayout.EndVertical();

                // Render text
                float textWidth = width - (texture.width + skin.label.border.top + skin.label.border.bottom + skin.scrollView.border.left + skin.scrollView.border.right);
                float textHeight = skin.label.border.top + skin.label.border.bottom + texture.height;
                scrollPositionDialogue = GUILayout.BeginScrollView(scrollPositionDialogue, false, false, skin.horizontalScrollbar, skin.verticalScrollbar, skin.label, GUILayout.MaxWidth(textWidth), GUILayout.MaxHeight(textHeight));
                {
                    // Render dialogue
                    //GUILayout.Space(10);
                    GUILayout.Label(displayDialogue, skin.customStyles[0]);
                }
                GUILayout.EndScrollView();
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(3);

            // Render PC choices
            GUILayout.BeginVertical();
            {
                scrollPositionOptions = GUILayout.BeginScrollView(scrollPositionOptions, false, false, skin.horizontalScrollbar, skin.verticalScrollbar, skin.label);
                {
                    // Render option buttons
                    for (int i = 0; i < options.Length; i++)
                    {
                        if (options[i] != null && options[i].text.Length > 0 && !(options[i].visited && options[i].clearOnVisited))
                        {
                            // Render option 1
                            if (GUILayout.Button(options[i].text, skin.button) || CommandOption == i )
                            {
                                // reset command option
                                CommandOption = -1;

                                Brain.GetInstance().StopVocals();
                                // play special audio or click if nothing here
                                if (options[i].audio != null)
                                    Brain.GetInstance().PlayAudio(options[i].audio);
                                else
                                    Brain.GetInstance().PlayAudio("GENERIC:CLICK");

                                options[i].visited = true;

                                // Log dialogue result.
                                if(!(displayDialogue.Length == 0 && options[i].text == "Next"))
                                    LogMgr.GetInstance().Add(new DialogueLogItem(Time.time, dialogueTitle, options[i].text, options[i].correctAnswer));

                                // Report titled dialogues to brain
                                if (title.Length > 0)
                                    DialogueTree.Instance.ReportDialogue(title, i, options[i].correctAnswer);

                                // Report InteractMsg
                                if (options[i].interactMsg != null && options[i].interactMsg.Length > 0)
                                {
                                    InteractMsg iMsg = new InteractMsg(this.gameObject, options[i].interactMsg);
                                    // log it
                                    InteractLogItem logitem = new InteractLogItem(Time.time, this.name, iMsg.map.item, StringMgr.GetInstance().Get(iMsg.map.response),iMsg);
                                    if (iMsg.log == true)
                                        LogMgr.GetInstance().Add(logitem);
                                    // send to brain
                                    Brain.GetInstance().PutMessage(iMsg);
                                }

                                if (options[i].goToID == -1)
                                {
                                    // End dialogue
                                    DialogueTree.Instance.EndActiveDialogue();
                                }
                                else if (options[i].goToID >= 0)
                                {
                                    // Move to next dialogue
                                    DialogueTree.Instance.GoToDialogue(options[i].goToID, false);
                                }
                            }
                        }
                    }
                }
                GUILayout.EndScrollView();
            }
            GUILayout.EndVertical();
        }
        GUILayout.EndArea();

    }
示例#6
0
	public GameMsg ToGameMsg( ScriptedAction scriptedAction ){
		// create a message of the appropriate type, and send it to the singleton, or	
		if (msgType == eMsgType.interactMsg){
			GameObject target = GameObject.Find (gameObjectName); // cant use ObjectManager from the editor
			if (target != null){
				InteractMsg newMsg = new InteractMsg(target,map.GetMap());
				//	newMsg.map.task = map.task; // Task master faults if this is null

				for(int i=0;i<newMsg.map.param.Count;i++)
				{
					if ( newMsg.map.param[i] != null && newMsg.map.param[i] != "" )
						newMsg.map.param[i]= scriptedAction.executedBy.ResolveArgs(newMsg.map.param[i]); // substitute any #values
				}
				// this is problematic, because BaseObject.PutMessage does NOTHING! TODO
				//target.GetComponent<BaseObject>().PutMessage(newMsg);
				return newMsg as GameMsg;
			}
		}
		if (msgType == eMsgType.interactStatusMsg){
			GameObject target = GameObject.Find (gameObjectName);
			if (target != null){
				InteractMsg newMsg;
				if (sendMap)
					newMsg = new InteractMsg(target,map.GetMap());
				else
					newMsg = new InteractMsg(target,interactName,log);
				//newMsg.map.task = map.task; // Task master faults if this is null
				if (sendMap)
					for(int i=0;i<newMsg.map.param.Count;i++)
					{
						if ( newMsg.map.param[i] != null && newMsg.map.param[i] != "" )
							newMsg.map.param[i]= scriptedAction.executedBy.ResolveArgs(newMsg.map.param[i]); // substitute any #values
					}
				InteractStatusMsg newisMsg = new InteractStatusMsg(newMsg);
				if (Params.Length > 0){
					newisMsg.Params=new List<string>();
					for(int i=0;i<Params.Length;i++)
					{
						if ( Params[i] != null && Params[i] != "" )
							newisMsg.Params.Add (scriptedAction.executedBy.ResolveArgs(Params[i])); // substitute any #values
					}
				}
				return newisMsg as GameMsg;
			}
		}
		if (msgType == eMsgType.quickInfoDialogMsg){
			DialogMsg newMsg = new QuickInfoMsg();
		
			newMsg.x = x;
			newMsg.y = y;
			newMsg.w = w;
			newMsg.h = h;
			newMsg.text = text;
			newMsg.title = title;
			newMsg.time = time;
			newMsg.modal = modal;
			newMsg.command = command;
			
			return newMsg as GameMsg;
		}
		if (msgType == eMsgType.dialogMsg){
			
			DialogMsg newMsg = new DialogMsg();
		
			newMsg.x = x;
			newMsg.y = y;
			newMsg.w = w;
			newMsg.h = h;
			newMsg.text = text;
			newMsg.title = title;
			newMsg.time = time;
			newMsg.modal = modal;
			newMsg.command = command;
			newMsg.className = className;
			newMsg.xmlName = xmlName;
			newMsg.arguments = new List<string>();
			newMsg.callback += scriptedAction.DialogCallback;
			foreach( string arg in arguments )
			{
				if ( arg != null && arg != "" )
					newMsg.arguments.Add (scriptedAction.executedBy.ResolveArgs(arg)); // substitute any #values
			}
			// fire off the dialog
			return newMsg as GameMsg;
		}	
		if (msgType == eMsgType.guiScreenMsg){
			
			GUIScreenMsg newMsg = new GUIScreenMsg();
		
			newMsg.ScreenName = ScreenName;

			foreach( string arg in arguments )
			{
				if ( arg != null && arg != "" )
					newMsg.arguments.Add (scriptedAction.executedBy.ResolveArgs(arg)); // substitute any #values
			}
			// fire off the dialog
			return newMsg as GameMsg;
		}
		return null;
	}	
示例#7
0
    public void QueueInteractMsg(InteractMsg msg)
    {
        if (InteractQueue == null)
            InteractQueue = new List<InteractMsg>();

        InteractQueue.Add(msg);
    }
	bool HandleUserCommand(string command){
		/*"USER:COMMAND:YES";</tag></item>
      <item> no <tag> out="USER:COMMAND:NO";</tag></item>
      <item> stop <tag>out="USER:COMMAND:STOP";</tag> </item><!-- might be a conflict with other stop commands -->
      <item> abort <tag> out="USER:COMMAND:ABORT";</tag></item>
      <item> confirm <tag> out="USER:COMMAND:CONFIRM"
		 USER:COMMAND:QUERY */
		
		if (!command.Contains ("USER:"******"ABORT")){
			// see if a specific character is called out...
			ObjectInteraction target = GetCharacter( command );
			if ( target != null){
				ScriptedObject so = target.GetComponent<ScriptedObject>();
				if ( so != null){
					so.AbortAllScripts();
				}
				((TaskCharacter)target).Reset();
				InteractMsg imsg = new InteractMsg(null,"GO:HOME");
				target.PutMessage(imsg);
			}
			else
			{
				// stop everyone's scripts. and send them home.
				SAPISpeechManager.Speak("Stopping Everything"); 
				foreach (ObjectInteraction oi in actors){
					if (oi as TaskCharacter != null){
						ScriptedObject so = oi.GetComponent<ScriptedObject>();
						if ( so != null){
							so.AbortAllScripts();
						}
						((TaskCharacter)oi).Reset();
//						TaskMaster.GetInstance().GoHome(oi.name); // this creates a Task. not a Character task, so it never gets updated... :/

						InteractMsg imsg = new InteractMsg(null,"GO:HOME");
						oi.PutMessage(imsg);
					}
				}
			}
			return true;
		}
		if (command.Contains("QUERY")){
			
			ObjectInteraction target = GetCharacter( command );
			if ( target != null){
				ScriptedObject so = target.GetComponent<ScriptedObject>();
				if ( so != null){
					// show somehow what scripts are being run...
					if (so.scriptStack.Count != 0){
						GameHUD gh = GUIManager.GetInstance().FindScreenByType<GameHUD>() as GameHUD;
						if (gh != null){
							gh.ShowRecentOrders();
							Invoke ("HideRecentOrders",5);
						}
						SAPISpeechManager.Speak(target.Name+" is ");
						foreach (ScriptedObject.QueuedScript qs in so.scriptStack){
							string taskDescription = qs.script.prettyname;
							if (taskDescription == "") taskDescription = qs.script.commandVariation.CmdString;
							if (taskDescription == "") taskDescription = qs.script.commandVariation.Cmd;
							if (taskDescription == "") taskDescription = qs.script.triggerStrings[0];
							if (taskDescription == "") taskDescription = "doing something with no description.";
							SAPISpeechManager.Speak(taskDescription);
						}
					}else{
						SAPISpeechManager.Speak("Nothing");
					}
				}
			}
			else
			{
				GameHUD gh = GUIManager.GetInstance().FindScreenByType<GameHUD>() as GameHUD;
				if (gh != null){
					gh.ShowRecentOrders();
					Invoke ("HideRecentOrders",5);
				}
				else{

				foreach (ObjectInteraction oi in actors){
					if (oi as TaskCharacter != null){
						ScriptedObject so = oi.GetComponent<ScriptedObject>();
						if ( so != null){
							// show somehow what scripts are being run...
							if (so.scriptStack.Count != 0){
								SAPISpeechManager.Speak(oi.Name+" is ");
								foreach (ScriptedObject.QueuedScript qs in so.scriptStack){
									string taskDescription = qs.script.prettyname;
									if (taskDescription == "") taskDescription = qs.script.commandVariation.CmdString;
									if (taskDescription == "") taskDescription = qs.script.commandVariation.Cmd;
									if (taskDescription == "") taskDescription = qs.script.triggerStrings[0];
									if (taskDescription == "") taskDescription = "doing something with no description.";
									SAPISpeechManager.Speak(taskDescription);
								}
							}
						}
					}
				}
				}
			}
			return true;
		}
		// find a dialog that might contain selected buttons
		
		GUIScreen panel = GUIManager.GetInstance().FindScreen("XrayViewerMain");//  FindScreenByType<InteractConfirmDialog>(); 
		if (panel == null)
			panel = GUIManager.GetInstance().FindScreen ("traumaDecisionPanel"); // FindScreenByType<DecisionPanel>();
		if (panel == null)
			panel = GUIManager.GetInstance().FindScreen ("dialogConfirm"); 
		if (panel == null)
			return true;
		
		
		if (command.Contains(":SELECT:")){
			// look for some toggles or buttons with names that match the selected option
			string buttonName = command.Replace ("USER:SELECT:","").ToLower();
			if (buttonName == "chatenter"){
				buttonName = "submit"; // was ChatEnter
			}
			if (buttonName == "exitbutton") buttonName = "exitButton";
			if (buttonName == "all"){
				// for this, find all the checkboxes, toggle them all to ON, then activate the chat enter button.
				// how to do this will take a bit of digging...
				//TODO
			}
			
			GUIButton selectedButton = panel.Find (buttonName) as GUIButton;
			
			
			if (selectedButton != null) {
				selectedButton.SimulateButtonAction ();
				panel.Update(); // get the submit button updated.
			}
			else
			{
				GUIToggle selectedToggle = panel.Find (buttonName) as GUIToggle;
				if (selectedToggle != null) {
					selectedToggle.SimulateButtonAction ();
				}
			}
			return true;
		}
		
		if (command.Contains ("YES")) {
			// see if there is an InteractConformDialog and a button with the text "YES"
			GUIButton okButton = panel.Find ("ok") as GUIButton;
			if (okButton != null) {
				okButton.SimulateButtonAction ();
			}
		}
		if (command.Contains ("NO")){
			// see if there is an InteractConformDialog and a button with the text "YES"
			GUIButton okButton = panel.Find("cancel") as GUIButton; // find by text would be better
			if (okButton != null){
				okButton.SimulateButtonAction();
			}
		}

		return true; // because it WAS a user:command
	}
示例#9
0
    public override void HandleInteractMsg(InteractMsg msg)
    {
        //UnityEngine.Debug.Log("Character.HandleInteractMsg(" + msg.GetType() + ") : target=" + this.Name);

        base.HandleInteractMsg(msg);

        // special case : this handles all messages coming from an interaction list.  
        InteractListMsg imsg = msg as InteractListMsg;
        if (imsg != null)
        {
#if DEBUG_INTERACTIONLIST
            imsg.map.Debug();
#endif
            // handle InteractionList case
            if (imsg.map.list != null)
            {
                InteractionList tmp = InteractionMgr.GetInstance().GetList(imsg.map.list);
                if (tmp != null)
                {
                    // only create a list if the current list is null or we have a list and it is interruptable
                    if (InteractionList == null || (InteractionList != null && InteractionList.Interrupt == true))
                    {
                        // make a copy
                        InteractionList = new InteractionList(imsg.map,tmp);
#if DEBUG_INTERACTIONLIST
                        UnityEngine.Debug.Log("Character.HandleInteractMsg(" + imsg.map.item + ") : Name=" + Name + "List=" + imsg.map.list);
                        InteractionList.Debug();
#endif
                        InteractionList.SetTarget(this);
                        InteractionList.Start();
                    }
                }
            }
        }
        else
        {
            // check to see if we can interrupt the list in progress with this incoming message
            if (InteractionList != null)
            {
#if DEBUG_INTERACTIONLIST
                UnityEngine.Debug.Log("Character.PutMessage(InteractMsg) : InteractionList=" + InteractionList.Name + " : Interrupt=" + InteractionList.Interrupt);
#endif
                if (InteractionList.Interrupt == true)
                    InteractionList = null;
            }
        }

        // handle InteractionList case
        if (msg.map.list != null)
        {
            InteractionList = InteractionMgr.GetInstance().GetList(msg.map.list);
            if (InteractionList != null)
            {
                // make a copy
                InteractionList = new InteractionList(msg.map, InteractionList);

#if DEBUG_INTERACTIONLIST
                UnityEngine.Debug.Log("Provider.HandleInteractMsg(" + msg.map.item + ") : Name=" + Name + "List=" + msg.map.list);
                InteractionList.Debug();
#endif

//  lets not ow that we are script driven              InteractionList.SetTarget(this);
//                InteractionList.Start();
            }
        }

    }
    virtual public void DoInteractMenu()
    {
        // causes object to dim
        OnMouseExit();
		
		if (interactOverrideTrigger != null && interactOverrideTrigger != ""){ // allow object to trigger a script instead of putting up a menu
			InteractMsg im = new InteractMsg( gameObject, interactOverrideTrigger, true);
			PutMessage(im);
			return;
		}

		// interact menu
		/* // disabling these menus PAA 6/22/15
        InteractDialogMsg msg = new InteractDialogMsg();
        msg.command = DialogMsg.Cmd.open;
        msg.baseobj = this;
        msg.title = prettyname;
        msg.x = (int)Input.mousePosition.x;
        msg.y = (int)Input.mousePosition.y;
		ScriptedObject so = GetComponent<ScriptedObject>(); // collect a list of items for the menu to show
		if (so != null)
			msg.items = so.QualifiedInteractions();
		else
			msg.items = ItemResponse; // this is where added items get placed on the menu, because they are in here...
        msg.modal = true;
		msg.baseXML = originXML;
        InteractDialogLoader.GetInstance().PutMessage(msg);

        Brain.GetInstance().PlayAudio("OBJECT:INTERACT:CLICK");
        */
    }
    virtual public void HandleInteractMsg(string name, InteractMsg interactMsg)
    {
		if ( interactMsg == null || interactMsg.map == null )
			return;
		
        // translate
        string response = Translate(interactMsg.map.response);
        // log interaction
        if (interactMsg.log == true)
        {
            InteractLogItem logitem = new InteractLogItem(Time.time, interactMsg.gameObject, interactMsg.map.item, StringMgr.GetInstance().Get(response), interactMsg);
            LogMgr.GetInstance().Add(logitem);
        }
    }
示例#12
0
	public virtual bool ExecuteCommand( string command, string preferredHandler = ""){
		// commands initialed thru the NLU, Menu, or Filter should pass thru this for processing

		InteractionMgr.GetInstance().EvaluateInteractionSet(command); //		
		
		InteractionMap map = InteractionMgr.GetInstance().Get(command);
		if (map == null){
			Debug.LogWarning("InteractionMgr found no map for "+command);
			map = new InteractionMap();
			map.item = command;
			// return false;
		}
		
		GameObject preferredGO = null;
		if (preferredHandler != null){
			preferredGO = ObjectManager.GetInstance().GetGameObject(preferredHandler);	
		}
		
	    InteractMsg msg = new InteractMsg( preferredGO, map);
		bool dispatched = DispatchMessage (  msg );

		if (dispatched && scribeNurse != null && scribeNurse.GetComponent<ScriptedObject>().scriptArray.Count<1){
			// have the scribe nurse write this down.
			InteractionMap recordMap = new InteractionMap();
			recordMap.item = "RECORD:RESULT";
			recordMap.param = new List<string>();
			recordMap.param.Add(command);
			InteractMsg recordMsg = new InteractMsg( scribeNurse.gameObject, recordMap);
			recordMsg.scripted = true;
			scribeNurse.PutMessage(recordMsg);
		}

		return dispatched;
	
//		PutMessage (msg); // use our normal code to find the best character to do this.
	}
示例#13
0
	private bool DispatchMessage ( InteractMsg msg ){

		// this routine includes triggering the Generic Response System voice cues
		
		ObjectInteraction preferredHandler = null;
//		bool phIsValidInteraction = false;
		int phQc = -1; // flags that we have not checked this yet
		float lowestCost=99999;
		List<ObjectInteraction> actorsHavingInteraction = new List<ObjectInteraction>();
		
		if (msg.gameObject != null && msg.gameObject != "" && msg.gameObject != "null" && msg.gameObject.ToLower() != "dispatcher"){ // here. gameObject is just a string.
			preferredHandler = ObjectManager.GetInstance().GetBaseObject(msg.gameObject) as ObjectInteraction;
			if (preferredHandler != null){
				
				// The message asked for SOMEBODY in particular to do this
		
				if (!preferredHandler.IsValidInteraction(msg.map)){
					// the preferred handler doesn't know how to do this interaction.
					
					// if it's a valid interaction, then respond "VOICE:MISMATCH"
					if (InteractionMgr.GetInstance ().Get(msg.map.item)!= null)
						VoiceMgr.GetInstance().Play (msg.gameObject,"VOICE:MISMATCH:*"); //* is a wildcard for multiple responses
					// If it's not recognised by the interaction manager, then respond "VOICE:BAD:COMMAND"
					else
						VoiceMgr.GetInstance().Play (msg.gameObject,"VOICE:BAD:COMMAND:*");
					return false;
				}
				ScriptedObject phSo = preferredHandler.GetComponent<ScriptedObject>();
				if (phSo != null){
					phQc = phSo.scriptArray.Count;
					if (phQc < 2){ // then we're going to let our ph do this.
						if (phQc == 0){
							//VoiceMgr.GetInstance().Play (msg.gameObject,"VOICE:ACKNOWLEDGE");
							VoiceMgr.GetInstance().Play(msg.gameObject,"VOICE:ACKNOWLEDGE:*");
						}
						else{
							//VoiceMgr.GetInstance().Play (msg.gameObject,"VOICE:BUSY:QUEUED");
							//Brain.GetInstance().PlayAudio("AUDIO:ACKNOWLEDGE");
							VoiceMgr.GetInstance().Play(msg.gameObject,"VOICE:BUSY:QUEUED:*");
						}
						preferredHandler.PutMessage(msg);
						return true;
					}
					else // Qc>= 2: The requested person is pretty busy, is there someone else who can do this?
					{
						ObjectInteraction handoffActor = null;
						foreach(ObjectInteraction testActor in actors){
							if (testActor.IsValidInteraction(msg.map)){
								actorsHavingInteraction.Add(testActor);
							}
						}
						foreach (ObjectInteraction testActor in actorsHavingInteraction){
							// add in cost if we're the scribe nurse
							float cost = ( testActor == scribeNurse )?100:0;
							ScriptedObject taSo = testActor.GetComponent<ScriptedObject>();
							if (taSo != null){
								int taQc = taSo.scriptArray.Count;
								if (phQc == -1 || taQc < phQc){ // shorter queue, choose this one
									handoffActor = testActor;
									phQc = taQc;
									lowestCost = testActor.GetCost(msg.map)+cost;
								}
								else
								{
									if (taQc == phQc){ // same q length, base on cost
										if ((testActor.GetCost(msg.map)+cost) < lowestCost){ // same q. lower cost, choose
											handoffActor = testActor;
											lowestCost = testActor.GetCost(msg.map);
										}
									}
								}
							}	
						}
						if (handoffActor != null){
							// say the handoff message
							// can we set the lookat ?
							CharacterBuilder cb = handoffActor.GetComponent<CharacterBuilder>();
							Transform lookAt;
							if (cb != null)
								lookAt = cb.bodyHeadbone;
							else
								lookAt = handoffActor.transform; // could search for that lookAt child...

							if (preferredHandler as Character != null){
	                  		  	(preferredHandler as Character).LookAt(lookAt, Time.time + 3);
								// set talk time
								(preferredHandler as Character).TalkTime = Time.time + 3;
							}
							
							VoiceMgr.GetInstance().Play(msg.gameObject,"VOICE:BUSY:HANDOFF:*");
							// say the acknowledge for the handoff actor
							if (phQc == 0)
								VoiceMgr.GetInstance().Play(handoffActor.Name,"VOICE:ACKNOWLEDGE:*");
							else if (phQc == 1)
								VoiceMgr.GetInstance().Play(handoffActor.Name,"VOICE:BUSY:QUEUED:*");
							else
								VoiceMgr.GetInstance().Play(handoffActor.Name,"VOICE:BUSY:DELAYED:*");
							// send the handoff actor the message
							handoffActor.PutMessage(msg);
							return true;
						}
						
						// no one else to do this, so put it on the queue.
						VoiceMgr.GetInstance().Play(msg.gameObject,"VOICE:BUSY:DELAYED:*");
						preferredHandler.PutMessage(msg);
						return true;
					}
					// here, we have a preferred handler with a q > 2, so we can
					// ask about priorities or hand off
				}				
			} // end the handler specified was valid
		} // end message specified a specific handler
		
		// we've handled all the cases if the handler was specified already.
		
		
		if (preferredHandler == null){ // this should always be true.
			// No valid preferred handler was given, build list of who can do this interaction.
			foreach(ObjectInteraction testActor in actors){
				if (testActor.IsValidInteraction(msg.map))
					actorsHavingInteraction.Add(testActor);
			}	
			// if no one knows how to do this, we just bail.
			if (actorsHavingInteraction.Count == 0){
				Brain.GetInstance().PlayAudio("AUDIO:BAD:COMMAND");
				return false;
			}
			// if someone can do this, pick the best one, weighting Q length the heaviest.
			// and set them up as the preferred handler
			foreach (ObjectInteraction testActor in actorsHavingInteraction)
			{
				// if we're the scribe have a higher cost
				float cost = (testActor == scribeNurse)?100:0;
				//
				ScriptedObject taSo = testActor.GetComponent<ScriptedObject>();
				if (taSo != null){
					int taQc = taSo.scriptArray.Count;
					if (phQc == -1 || taQc+2 < phQc){ // much shorter queue, choose this one
						preferredHandler = testActor;
						phQc = taQc;
						lowestCost = testActor.GetCost(msg.map)+cost;
					}
					else
					{
						if (taQc <= phQc){ // nearly same q length, base on cost
							if ((testActor.GetCost(msg.map)+cost) < lowestCost){ // same q. lower cost, choose
								preferredHandler = testActor;
								phQc = taQc;
								lowestCost = testActor.GetCost(msg.map);
							}
						}
					}
				}	
			}		
		}	
		// we should be guaranteed a preferred handler at this point.
		// we have picked THE best person to perform the task, so we just need to acnowledge appropriately
		if (preferredHandler != null ){

			ScriptedObject phSo = preferredHandler.GetComponent<ScriptedObject>();
			if (phSo != null){
				phQc = phSo.scriptArray.Count;
				if (phQc == 0){ // then we're going to let our ph do this.
						VoiceMgr.GetInstance().Play (preferredHandler.name,"VOICE:ACKNOWLEDGE:*");
				}
				else 
				{	if (phQc == 1) {
						VoiceMgr.GetInstance().Play (preferredHandler.name,"VOICE:BUSY:QUEUED:*");
					}
					else
					{
						VoiceMgr.GetInstance().Play (preferredHandler.name,"VOICE:BUSY:DELAYED:*");
					}
				}
				preferredHandler.PutMessage(msg);
				return true;
			}
		}

#if MAKE_ISM_FROM_IM
		// always dispatch an ISM for each IM (for AssessmentMgr) NOTE!! if we don't have a handler
		InteractStatusMsg ismsg = new InteractStatusMsg(msg);
		Brain.GetInstance().PutMessage(ismsg);
#endif

		// either no preferredHandler, or too busy to do this. Make a list of everyone who can do this.
		return false;
		
		
	}
示例#14
0
	public bool ExecuteCommand(InteractionMap map){

		// menu commands are coming thru here
		InteractionMgr.GetInstance().EvaluateInteractionSet( map.item);

		GameObject preferredGO = ObjectManager.GetInstance().GetGameObject(map.objectName);	
	
	    InteractMsg msg = new InteractMsg( preferredGO, map);
		
		return DispatchMessage (  msg );		
		
	}
示例#15
0
    public InteractMsg SendInteractionMap(string objname, InteractionMap map)
    {
        InteractMsg imsg = new InteractMsg(null, map);

        // log it
        if (map.log == true)
        {
            InteractLogItem logitem = new InteractLogItem(Time.time, objname, imsg.map.item, StringMgr.GetInstance().Get(imsg.map.response), imsg);
            LogMgr.GetInstance().Add(logitem);
        }

        // send to brain
        Brain.GetInstance().PutMessage(imsg);

        return imsg;
    }
示例#16
0
	public virtual void DoAbort()
	{
		// clear current set - try doing this before running the abort scripts instead of after
		InteractionMgr.GetInstance().AbortCurrentSet();
		// send the abort list thru the dispatcher for queuing
		foreach (string tag in ScriptsAbort){
			InteractionMap map = new InteractionMap(tag, null, null, null, null, null, null, true );
			InteractMsg msg = new InteractMsg(null, map); // who should be the game object here? the dispatcher will figure that out.
			Dispatcher.GetInstance().PutMessage( msg);	
		}
		// clear current set - moved to before ?
		//InteractionMgr.GetInstance().AbortCurrentSet();
	}
示例#17
0
	public virtual void DoExit()
	{
		// send the exit list thru the dispatcher for queuing
		foreach (string tag in ScriptsExit){
			InteractionMap map = new InteractionMap(tag, null, null, null, null, null, null, true );
			InteractMsg msg = new InteractMsg(null, map); // who should be the game object here? the dispatcher will figure that out.
			Dispatcher.GetInstance().PutMessage( msg);	
		}
		// clear current set

		//InteractionMgr.GetInstance().CurrentSet = null;
		InteractionMgr.GetInstance ().AbortCurrentSet(); // this sets current set null and calls init for next time
	}
示例#18
0
    public override void HandleInteractionError(InteractMsg imsg, string error)
    {
        // no subject, find someone to do the command
        List<ObjectInteraction> objects = ObjectInteractionMgr.GetInstance().GetEligibleObjects(imsg.map.item);
        foreach (ObjectInteraction obj in objects)
        {
            Character character = obj as Character;
            if (character != null)
            {
                if (character.IsDone() == true)
                {
                    UnityEngine.Debug.Log("TraumaPatient.HandleInteractionError(" + imsg.map.item + ") : found character=" + character.name);
                    InteractionMap map = InteractionMgr.GetInstance().Get(imsg.map.item);
                    character.PutMessage(new InteractMsg(character.gameObject, map));
                    return;
                }
            }
        }
		base.HandleInteractionError(imsg,error);
    }
 virtual public void HandleInteractMsg( InteractMsg interactMsg )
 {
     // handle default
     ObjectInteractionMgr.GetInstance().HandleInteractMsg(this.name,interactMsg);
     // save interaction
     Add(interactMsg.map);
 }
示例#20
0
 public void Play(InteractMsg msg)
 {
     Play(msg.gameObject, msg.map.item);
 }
示例#21
0
	IEnumerator SendMessageAfterDelay(float delay)
	{
		yield return new WaitForSeconds(delay);
		if (ignoreTimeout) yield break;
		if (gameMsgForm != null){
			if ((gameMsgForm.gameObjectName == null || gameMsgForm.gameObjectName == "") &&
				 objectToAffect != null)
				gameMsgForm.gameObjectName = objectToAffect.name;
			
			//executedBy.nestingDepth += 1; // see if this is going to be an if-then-else dialog

			// add ability to wait for a dialog to be closed before proceeding...this is implemented
			// to avoid having a lockup on multiple dialog waits.  
			if ( gameMsgForm.waitForDialogClosed == true )
			{
				StartCoroutine(WaitForDialogClosed(this,gameMsgForm));
				yield break;
			}
			else
				gameMsgForm.PutMessage(this);
		}
		else
		{
			// default to just sending an interact message
			InteractMsg imsg = new InteractMsg( objectToAffect, stringParam);
			imsg.map.task = stringParam;
			(objectToAffect.GetComponent<BaseObject>() as BaseObject).PutMessage(imsg);
		}
		if (waitForCompletion)
		{
			if ( gameMsgForm.msgType == GameMsgForm.eMsgType.dialogMsg )
				waitingForDialog = true;
			else
				StartCoroutine(CompleteAfterDelay(gameMsgForm.time));
		} else
			OnComplete ();

		Cleanup ();
	}
示例#22
0
	// handles messages coming back from the GUI.  these messages are setup in the DialogMsg,
	// and passed when the button button specified.  The messages can be either an "onbutton=" event or
	// a default "button" event
    public bool ProcessMessage(string msg)
    {
		bool handled = false;

		// make lower case version
		string msgLower = msg.ToLower();
		
		if (msgLower.Contains("onbutton=") || 
		    msgLower.Contains("interact=") || 
		    msgLower.Contains("script=") || 
		    msgLower.Contains("audio=") || 
		    msgLower.Contains("action="))
		{
			// check name of pressed button
			string buttonName;
			if ( GetToken(msgLower, "onbutton", out buttonName) == true )
			{
				if ( msgLower.Contains("pressed"))
				{
					string pressedName;
					if ( GetToken(msgLower,"pressed", out pressedName) == true )
					{
						// if button pressed is not equal to this action, return
						if ( buttonName != pressedName )
							return false;
					}
				}
			}
			
	        if (msgLower.Contains("interact="))
        	{
	            // get rid of tag
            	string map;
            	if (GetToken(msg, "interact", out map) == true) // this used to process msgLower, but produced unmatchable tags
            	{
                   	// create interaction map
                  	InteractionMap imap;
					// lookup interaction map
                    imap = InteractionMgr.GetInstance().Get(map);
                    if (imap == null)
                    {
	                       // not found, generic...make one
                       	imap = new InteractionMap(map, null, null, null, null, null, null, true);
                    }
					// get object to send to....if no object then assume that we are sending msg to script owner
					BaseObject obj = null;
					// first look for object token
					string _object;
                	if (GetToken(msgLower, "object", out _object) == true)
                	{
						// we have an object, go find it
	                    // get object
                    	obj = ObjectManager.GetInstance().GetBaseObject(_object);
                	}
					else
					{
						// sending msg to script owner
						if ( executedBy != null && executedBy.caller != null )
							obj = executedBy.caller.ObjectInteraction;
					}
					// send to object if we have one!
                    if (obj != null)
                    {
						if ( executedBy.debug == true )
		            		UnityEngine.Debug.Log("GUIButton.ProcessMessage() : obj=" + obj.name + " : map=" + map);
                       	// create InteractMsg
                       	InteractMsg imsg = new InteractMsg(obj.gameObject, imap);
                       	imsg.map.confirm = false;
                       	obj.PutMessage(imsg);
                    }
					else
					{
						if ( executedBy.debug == true )
			            	UnityEngine.Debug.Log("GUIButton.ProcessMessage() : can't find obj=" + obj.Name + " : map=" + map);
					}
            	}
			}

			// this is the audio handling block.  Allows audio to play on button
			if (msgLower.Contains("audio"))
			{
				string audio;
               	if (GetToken(msgLower, "audio", out audio) == true)
               	{	
					// play some audio
					Brain.GetInstance().PlayAudio(audio);
				}
			}	
				
			// this is the script handling block.  the specified script will be executed on either the
			// calling object or on the object=obj specified.  system queues the script on the ScriptedObject
			// to be completed after the object is finished with the current script.
        	if (msgLower.Contains("script="))
        	{
				string _script;
				// NOTE!! don't use lower case here because scripts need to be literal
               	if (GetToken(msg, "script", out _script) == true)
               	{	
					BaseObject obj=null;
					
					// get object to send script too
					string _object;
               		if (GetToken(msgLower, "object", out _object) == true)
               		{
						// we have an object, go find it
                   		obj = ObjectManager.GetInstance().GetBaseObject(_object);
               		}
					else
					{
						// no target, sending msg to script owner
						if ( executedBy != null && executedBy.caller != null )
							obj = executedBy.caller.ObjectInteraction;
					}	

					// split to see if we have multiple scripts
					string[] scripts = _script.Split(',');

					// process all of them
					foreach ( string item in scripts )
					{
						BaseObject thisObj = obj;
						string thisItem = item; // so we can assign
						// added feature to allow sending the object name along with the script name, using  "@"
						if (item.Contains("@")){
							string[] parts = item.Split('@');
							thisItem = parts[1];
							if (ObjectManager.GetInstance().GetBaseObject(parts[0])!= null)
								thisObj = ObjectManager.GetInstance().GetBaseObject(parts[0]);
						}
						// send it
						if ( thisObj != null )
						{
							// we have a valid object and script....execute it!
							if ( executedBy.debug == true )
								UnityEngine.Debug.Log("ScriptedAction.ProcessMessage(" + msgLower + ") script=" + thisItem + " : object=" + thisObj.Name);							
							// try finding the named game object and look for an interaction script there
							GameObject isGO = GameObject.Find(thisItem);
							if (isGO != null)
								scriptToExecute = isGO.GetComponent<InteractionScript>();
							
							if (scriptToExecute != null){					
								//build a string with our script's args and add to stringParam args...
								string paramString = "trigger=" + "DIALOG" ;
								ScriptedObject sObj = thisObj.GetComponent<ScriptedObject>();
								if (sObj != null)
									sObj.QueueScript(scriptToExecute, paramString, thisObj.gameObject);
								else
									executedBy.caller.QueueScript(scriptToExecute, paramString, thisObj.gameObject);
								// yield until we get an update. which will complete us.  we HAVE to wait, no multi threading support yet.
								waitingForUpdate = true;
							}
							else
							{
								if ( executedBy.debug == true )
									Debug.LogError("scriptedAction could not find script to execute at "+name+executedBy.name);
								waitingForUpdate = true;
								handled = true; // should probably do this in the other branches as well...s
							}
						}
					}
				}
        	}
						
			// all buttons execpt for close must provide either action=abort, or action=ok to
			// make the dialog continue execution.  We do this because we have to have the buttons
			// be able to continue scripts
			if (msgLower.Contains("action"))
			{
	            string action;
           		if (GetToken(msgLower, "action", out action) == true)
           		{
					if ( executedBy.debug == true )
						UnityEngine.Debug.Log("ScriptedAction.ProcessMessage() : action=" + action);
					// set specific lines based on action
					if ( action == "abort" )
					{
						executedBy.nextLineLabel = "abort"; // this is setting the abort case
						error = "abort";					// this is error case
						handled = true;
					}
					if ( action == "else" )
					{
						if (dialogIfThen){ // either treat like if-then, or abort
							executedBy.nextLineLabel = "else";
						}
						else{
							executedBy.nextLineLabel = "abort"; 
							error = "abort";
						}
						handled = true;
					}
					if ( action == "ok" || action == "close" )
					{
						executedBy.nextLineLabel = ""; 		// this means just continue execution
						handled = true;
					}
				}
			}
			// this is not a closer
			return handled;
       	}		

		// Default button handling...
		if ( msgLower.Contains("button") )
		{
            string button;
       		if (GetToken(msgLower, "button", out button) == true)
        	{
				if ( executedBy.debug == true )
					UnityEngine.Debug.Log("ScriptedAction.ProcessMessage() : button=" + button);
				switch( button.ToLower() )
				{
				case "close":
				case "cancel":
				case "buttonnext": // traumaQuickFast sends this
					if (dialogIfThen){ // either treat like if-then, or abort
						executedBy.nextLineLabel = "else";
					}
					else{
						executedBy.nextLineLabel = "abort"; 
						error = "abort";
					}
					handled = true;
					break;
				case "ok":
					executedBy.nextLineLabel = ""; 
					handled = true;
					break;
				}
			}
		}
		
		return handled;		
    }
示例#23
0
    public void SpeechToText(string command)
    {
        // move to lower case
        command = command.ToLower();

        // translate command to game world
        command = Translate(command);

        // put info qi
        //QuickInfoMsg qimsg = new QuickInfoMsg();
        //qimsg.command = DialogMsg.Cmd.open;
        //qimsg.title = "Speech Command";
        //qimsg.text = "Cmd=<" + command + "> ...";
        //QuickInfoDialog.GetInstance().PutMessage(qimsg);

        // check dialog manager
        DialogMgr.GetInstance().SpeechToText(command);

        // run it through the dialog
        if (DialogueTree.Instance.ActiveDialogue != null)
            DialogueTree.Instance.ActiveDialogue.SpeechToText(command);

        // send to everyone
        SpeechMsg speechmsg = new SpeechMsg(command);
        ObjectManager.GetInstance().PutMessage(speechmsg);

        // find closest command by interrigating all the objects
        if (speechmsg.Stats.Count > 0)
        {
            SpeechMsg.Info info = null;
            foreach (SpeechMsg.Info tmp in speechmsg.Stats)
            {
                if (info == null)
                    // first one
                    info = tmp;
                else
                {
                    // check for higher percentage
                    if (tmp.percent > info.percent)
                        info = tmp;
                }
            }
            if (info != null)
            {
                // send this command
                InteractMsg interact = new InteractMsg(info.obj.gameObject, info.map, true);
                info.obj.PutMessage(interact);

                // close the interact menu....just in case
                InteractDialogMsg msg = new InteractDialogMsg();
                msg.command = DialogMsg.Cmd.close;
                InteractDialogLoader.GetInstance().PutMessage(msg);
            }
        }
    }
示例#24
0
    public static void Parse(string action)
    {
        // var:object.variable equals:0.5 .. sets equal
        // var:object.variable dec:0.5 .. decrements by .5
#if DEBUG_DECISION_ENGINE
        UnityEngine.Debug.Log("Action.Parse(" + action + ")");
#endif
        if (action.Contains("var") && action.Contains("equals"))
        {
            DecisionVariable variable = GetVar(action, "var");
            if (variable != null)
            {
                // get value of operator
                string val = GetArg(action,"equals");
                if (val != null)
                {
#if DEBUG_DECISION_ENGINE
                    UnityEngine.Debug.Log("Action.Parse(equals:" + action + ") : variable=" + variable.Object + "." + variable.Variable + " : value=" + variable.Get());
#endif
                    variable.Set(val);
                }
            }
        }

        // var:object.variable inc:0.5 .. increments by .5
        if (action.Contains("var") && action.Contains("inc"))
        {
            DecisionVariable variable = GetVar(action, "var");
            if (variable != null)
            {
                // get value of operator
                string val = GetArg(action,"inc");
                if (val != null)
                {
#if DEBUG_DECISION_ENGINE
                    UnityEngine.Debug.Log("Action.Parse(inc:" + action + ") : variable=" + variable.Object + "." + variable.Variable + " : value=" + val);
#endif
                    variable.Inc(val);
                }
            }
        }

        if (action.Contains("var") && action.Contains("dec"))
        {
            DecisionVariable variable = GetVar(action, "var");
            if (variable != null)
            {
                // get value of operator
                string val = GetArg(action,"dec");
                if (val != null)
                {
#if DEBUG_DECISION_ENGINE
                    UnityEngine.Debug.Log("Action.Parse(dec:" + action + ") : variable=" + variable.Object + "." + variable.Variable + " : value=" + val);
#endif
                    variable.Dec(val);
                }
            }
        }

        // var:object interact:MSG:EXAMPLE
        if (action.Contains("var") && action.Contains("interact"))
        {
            string objname = GetArg(action, "var");
            string interaction = GetString(action, "interact");

#if DEBUG_DECISION_ENGINE
            UnityEngine.Debug.Log("Action.Parse(interact:" + action + ") : objname=" + objname + " : interaction=" + interaction);
#endif
            ObjectInteraction objint = ObjectManager.GetInstance().GetBaseObject(objname) as ObjectInteraction;
            if (objint != null)
            {
                InteractionMap map = InteractionMgr.GetInstance().Get(interaction);
                if (map != null)
                {
                    // send interaction
                    InteractMsg imsg = new InteractMsg(objint.gameObject,map,true);
                    objint.PutMessage(imsg);
                }
            }
        }

        if (action.Contains("status:"))
        {
            string status = GetString(action, "status");
            if (status != null)
            {
                InteractStatusMsg ismsg = new InteractStatusMsg(status);
                Brain.GetInstance().PutMessage(ismsg);
            }
        }
		
#if CHANGE_STATE
		if (action.Contains("state:"))
		{
			string state = GetArg(action,"state");
			if ( state != null )
			{
				DecisionState newstate = Parent.FindState(state);
				if ( newstate != null )
				{
					Parent.Current = newstate;
				}
			}
		}
#endif

        // changestate:BRAINSTATE
        if (action.Contains("changestate"))
        {
            string statename = GetArg(action, "changestate");
            if (statename != null)
            {
                ChangeStateMsg msg = new ChangeStateMsg(statename);
                Brain.GetInstance().PutMessage(msg);
            }
        }

        // sound effect
        if (action.Contains("audio:"))
        {
            string audio = GetString(action, "audio");
            if (audio != null)
            {
                Brain.GetInstance().PlayAudio(audio);
            }
        }

        // dialog title:"title" text:"text" timeout:seconds
        if (action.Contains("dialog"))
        {
            string text="none", title="title";
            float time=0.0f;

            if (action.Contains("title"))
            {
                title = GetString(action, "title");
            }
            if (action.Contains("text"))
            {
                text = GetString(action, "text");
            }
            if (action.Contains("timeout"))
            {
                time = Convert.ToSingle(GetArg(action, "timeout"));
            }
            QuickInfoMsg msg = new QuickInfoMsg();
            msg.command = DialogMsg.Cmd.open;
            msg.title = title;
            msg.text = text;
            msg.timeout = time;
            QuickInfoDialog.GetInstance().PutMessage(msg);
        }
    }
示例#25
0
 public virtual void HandleInteractionError(InteractMsg imsg, string error)
 {
     UnityEngine.Debug.LogError("Character.HandleInteractionError() : name=" + Name + " : InteractName=" + imsg.map.item + " : error=" + error);
     VoiceMgr.GetInstance().Play(Name, error);
 }
示例#26
0
	/* ----------------------------  SERIALIZATION ----------------------------------------- */	
	
	
	
	public void PutMessage( ScriptedAction scriptedAction ){
		// create a message of the appropriate type, and send it to the singleton, or	
		if (msgType == eMsgType.interactMsg){
			BaseObject bo = ObjectManager.GetInstance().GetBaseObject(gameObjectName);
			if (bo == null){
				Debug.LogWarning("GameMsgForm "+name+" could not send message to '"+gameObjectName+"', not known to ObjectManager.");
				return;
			}
			GameObject target = bo.gameObject;
			if (target != null){
				InteractMsg newMsg = new InteractMsg(target,map.GetMap());
				// add flag to let everyone know that this command as generated internally
				newMsg.scripted = true;
				//	newMsg.map.task = map.task; // Task master faults if this is null

				for(int i=0;i<newMsg.map.param.Count;i++)
				{
					if ( newMsg.map.param[i] != null && newMsg.map.param[i] != "" )
						newMsg.map.param[i]= scriptedAction.executedBy.ResolveArgs(newMsg.map.param[i]); // substitute any #values
				}
				// this is problematic, because BaseObject.PutMessage does NOTHING! TODO
				//target.GetComponent<BaseObject>().PutMessage(newMsg);
				ObjectManager.GetInstance ().GetBaseObject(gameObjectName).PutMessage(newMsg);
			}
		}
		if (msgType == eMsgType.interactStatusMsg){
			GameObject target = GameObject.Find (gameObjectName);
			if (target != null){
				InteractMsg newMsg;
				if (sendMap)
					newMsg = new InteractMsg(target,map.GetMap());
				else
					newMsg = new InteractMsg(target,interactName,log);
				// add flag to let everyone know that this command as generated internally
				newMsg.scripted = true;
				//newMsg.map.task = map.task; // Task master faults if this is null
				if (sendMap)
					for(int i=0;i<newMsg.map.param.Count;i++)
					{
						if ( newMsg.map.param[i] != null && newMsg.map.param[i] != "" )
							newMsg.map.param[i]= scriptedAction.executedBy.ResolveArgs(newMsg.map.param[i]); // substitute any #values
					}
				InteractStatusMsg newisMsg = new InteractStatusMsg(newMsg);
				if (Params != null && Params.Length > 0){
					newisMsg.Params=new List<string>();
					for(int i=0;i<Params.Length;i++)
					{
						if ( Params[i] != null && Params[i] != "" )
							newisMsg.Params.Add (scriptedAction.executedBy.ResolveArgs(Params[i])); // substitute any #values
					}
				}
				// send to all objects
			//	ObjectManager.GetInstance().PutMessage(newisMsg);  // the brain sends to the object manager
				// send to the brain
				Brain.GetInstance().PutMessage(newisMsg);
			}
		}
		if (msgType == eMsgType.animateMsg){
			
		}
		if (msgType == eMsgType.taskMsg){
			
		}
		if (msgType == eMsgType.errorDialogMsg){
			
		}
		if (msgType == eMsgType.interactDialogMsg){
			
		}
		if (msgType == eMsgType.quickInfoDialogMsg){
			QuickInfoMsg newMsg = new QuickInfoMsg();
		
			newMsg.x = x;
			newMsg.y = y;
			newMsg.w = w;
			newMsg.h = h;
			newMsg.text = text;
			newMsg.title = title;
			newMsg.time = time;
			// all the QuickInfo's had a timeout of 0 which was not getting passed, so if you see that, leave it alone
			// treat -1 as the value to leave the dialog up.
			if (timeout == 0) timeout = 2;
			if (timeout == -1) timeout = 0;
			newMsg.timeout = timeout;
			newMsg.modal = modal;
			newMsg.command = command;
			
			QuickInfoDialog.GetInstance().PutMessage( newMsg );
		}
		if (msgType == eMsgType.popupMsg){
			
		}
		if (msgType == eMsgType.dialogMsg){
			
			DialogMsg newMsg = new DialogMsg();

			newMsg.x = x;
			newMsg.y = y;
			newMsg.w = w;
			newMsg.h = h;
			newMsg.text = text;
			newMsg.title = title;
			newMsg.time = time;
			newMsg.modal = modal;
			newMsg.command = command;
			newMsg.className = className;
			newMsg.name = dialogName;
			newMsg.anchor = anchor;
			newMsg.xmlName = xmlName;
			newMsg.arguments = new List<string>();
			newMsg.callback += scriptedAction.DialogCallback;
			foreach( string arg in arguments )
			{
				if ( arg != null && arg != "" )
					newMsg.arguments.Add (StringLookup(scriptedAction.executedBy.ResolveArgs(arg))); // substitute any #values
			}
			// fire off the dialog
			GUIManager.GetInstance().PutMessage( newMsg );
		}	
		if (msgType == eMsgType.guiScreenMsg){
			
			GUIScreenMsg newMsg = new GUIScreenMsg();
		
			newMsg.ScreenName = ScreenName;

			foreach( string arg in arguments )
			{
				if ( arg != null && arg != "" )
					newMsg.arguments.Add (StringLookup(scriptedAction.executedBy.ResolveArgs(arg))); // substitute any #values
			}
			// fire off the dialog
			GUIManager.GetInstance().PutMessage( newMsg );
		}		
	}
示例#27
0
	public void ConfirmInteractDialogCallback( string msg )
	{
		// obj should be us, and the button
		
		bool handled = false;
		
		if (msg.Contains("onbutton="))
		{
	        if (msg.Contains("interact="))
        	{
	            // get rid of tag
            	string map;
            	if (ScriptedAction.GetToken(msg, "interact", out map) == true)
            	{
                   	// create interaction map
                  	InteractionMap imap;
					// lookup interaction map
                    imap = InteractionMgr.GetInstance().Get(map);
                    if (imap == null)
                    {
	                       // not found, generic...make one
                       	imap = new InteractionMap(map, null, null, null, null, null, null, true);
                    }
					// get object to send to....if no object then assume that we are sending msg to script owner
					BaseObject obj = null;
					// first look for object token
					string _object;
                	if (ScriptedAction.GetToken(msg, "object", out _object) == true)
                	{
						// we have an object, go find it
	                    // get object
                    	obj = ObjectManager.GetInstance().GetBaseObject(_object);
                	}

					// send to object if we have one!
                    if (obj != null)
                    {
						// create InteractMsg
                       	InteractMsg imsg = new InteractMsg(obj.gameObject, imap);
                       	imsg.map.confirm = false;
                       	obj.PutMessage(imsg);
                    }
            	}
			}
		}

	}
示例#28
0
	public void OrderFluids( string name, int bloodDrip, int bloodPressure, int bloodRapid, int salineDrip, int salinePressure, int salineRapid)
	{
		InteractMsg imsg;
		
		if ( bloodDrip > 0 )
		{
			// ORDER:BLOOD:1:IV
			InteractStatusMsg ismsg = new InteractStatusMsg("ORDER:BLOOD:" + bloodDrip.ToString() + "IV");
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(ismsg);
#if LATER			
			imsg = new InteractMsg(null,"ORDER:BLOOD:SCRIPT",true);
			imsg.gameObject = name;
			imsg.map.param = new List<string>();
			imsg.map.param.Add("units=" + bloodDrip);
			imsg.map.param.Add("delivery=\"IV\"");
			imsg.map.param.Add("product=\"bloodbag\"");
			imsg.map.param.Add("affect=\"Patient.%BloodbagsIV\"");
			// send to primary nurse
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(imsg);
#endif
		}
		if ( bloodPressure > 0 )
		{
			InteractStatusMsg ismsg = new InteractStatusMsg("ORDER:BLOOD:" + bloodPressure.ToString() + "PR");
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(ismsg);
#if LATER			
			imsg = new InteractMsg(null,"ORDER:BLOOD:SCRIPT",true);
			imsg.gameObject = name;
			imsg.map.param = new List<string>();
			imsg.map.param.Add("units=" + bloodPressure);
			imsg.map.param.Add("delivery=\"PR\"");
			imsg.map.param.Add("product=\"bloodbag\"");
			imsg.map.param.Add("affect=\"Patient.%BloodbagsPR\"");
			// send to primary nurse
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(imsg);
#endif
		}
		if ( bloodRapid > 0 )
		{
			InteractStatusMsg ismsg = new InteractStatusMsg("ORDER:BLOOD:" + bloodRapid.ToString() + "RI");
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(ismsg);
#if LATER
			imsg = new InteractMsg(null,"ORDER:BLOOD:SCRIPT",true);
			imsg.gameObject = name;
			imsg.map.param = new List<string>();
			imsg.map.param.Add("units=" + bloodRapid);
			imsg.map.param.Add("delivery=\"RI\"");
			imsg.map.param.Add("product=\"bloodbag\"");
			imsg.map.param.Add("affect=\"Patient.%BloodbagsRI\"");
			// send to primary nurse
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(imsg);
#endif
		}
		if ( salineDrip > 0 )
		{
			InteractStatusMsg ismsg = new InteractStatusMsg("ORDER:SALINE:" + salineDrip.ToString() + "IV");
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(ismsg);
#if LATER
			imsg = new InteractMsg(null,"ORDER:BLOOD:SCRIPT",true);
			imsg.gameObject = name;
			imsg.map.param = new List<string>();
			imsg.map.param.Add("units=" + salineDrip);
			imsg.map.param.Add("delivery=\"IV\"");
			imsg.map.param.Add("product=\"salinebag\"");
			imsg.map.param.Add("affect=\"Patient.%SalinebagsIV\"");
			// send to primary nurse
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(imsg);
#endif
		}
		if ( salinePressure > 0 )
		{
			InteractStatusMsg ismsg = new InteractStatusMsg("ORDER:SALINE:" + salinePressure.ToString() + "PR");
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(ismsg);
#if LATER
			imsg = new InteractMsg(null,"ORDER:BLOOD:SCRIPT",true);
			imsg.gameObject = name;
			imsg.map.param = new List<string>();
			imsg.map.param.Add("units=" + salinePressure);
			imsg.map.param.Add("delivery=\"PR\"");
			imsg.map.param.Add("product=\"salinebag\"");
			imsg.map.param.Add("affect=\"Patient.%SalinebagsPR\"");
			// send to primary nurse
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(imsg);
#endif
		}
		if ( salineRapid > 0 )
		{
			InteractStatusMsg ismsg = new InteractStatusMsg("ORDER:SALINE:" + salineRapid.ToString() + "PR");
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(ismsg);
#if LATER
			imsg = new InteractMsg(null,"ORDER:BLOOD:SCRIPT",true);
			imsg.gameObject = name;
			imsg.map.param = new List<string>();
			imsg.map.param.Add("units=" + salineRapid);
			imsg.map.param.Add("delivery=\"RI\"");
			imsg.map.param.Add("product=\"salinebag\"");
			imsg.map.param.Add("affect=\"Patient.%SalineBagsRI\"");
			// send to primary nurse
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(imsg);
#endif
		}
	}