public object Connect(object[] args) { string name = ReturnValueConversions.SafeUnwrap <string>(args, 0); //Console.WriteLine(_caller + " connecting to " + name); MimanTing maybeTing = GetTingFromNameOrSourceCodeName(_tingRunner, name); // if (maybeTing is Character) { // _caller.Say("Can't connect to human " + name); // return new ReturnValue(-1); // } else if (maybeTing != null) { //_caller.PlaySound ("Modem"); return(_caller.AddConnectionToTing(maybeTing)); } else { if (_caller is Computer) { (_caller as Computer).API_Print("Can't find " + name + " to connect to"); } else { _caller.Say("Can't find " + name + " to connect to", ""); } return(-1f); } }
public override void Update(float dt) { if (currentGoods == null) { MimanTing goodsAtPosition = null; var occupants = room.GetTile(localPoint).GetOccupants(); foreach (var o in occupants) { if (o is Machine) { // ignore } else { goodsAtPosition = o as MimanTing; break; } } if (goodsAtPosition != null && !goodsAtPosition.isBeingHeld && !goodsAtPosition.isDeleted) { currentGoods = goodsAtPosition; masterProgram.executionsPerFrame = 10; masterProgram.Start(); } } else if (currentGoods.isBeingHeld) { D.Log("is being held"); RemovedGoods(); } else if (currentGoods.position != goodsPointInWorld) { D.Log("different pos: " + currentGoods.position + " goods point: " + goodsPointInWorld); RemovedGoods(); } else { // Check for several goods at machine position /*var occupants = room.GetTile (localPoint).GetOccupants (); * if (occupants.Length > 2) { // 1 for the machine, one for the goods that should be there * foreach (var o in occupants) { * if (o is Machine) { * // ignore * } else { * if (o == currentGoods) { * o.position = new WorldCoordinate (this.room.name, this.interactionPoints [0]); * currentGoods = null; * D.Log ("Pushed out current goods!"); * break; * } * } * } * }*/ } }
public void OnSomeoneSaidSomething(Speech pSpeech) { #if DEBUG if (!HasTing(pSpeech.speaker)) { throw new Exception("Can't find speaker with name '" + pSpeech.speaker + "'"); } #endif MimanTing speaker = GetTing(pSpeech.speaker) as MimanTing; speaker.Say(pSpeech.line, pSpeech.conversation); }
public void Fry(Character pUser, MimanTing pTing) { if (on) { _objectOnStove = pTing; masterProgram.Start(); } else { _objectOnStove = null; _worldSettings.Notify(pUser.name, "Stove is not on"); } }
public object RemoteFunctionCall(object[] args) { float receiverIndex = (int)ReturnValueConversions.SafeUnwrap <float>(args, 0); string functionName = ReturnValueConversions.SafeUnwrap <string>(args, 1); if (args [2].GetType() != typeof(SortedDictionary <KeyWrapper, object>)) { throw new Error("Argument array to " + functionName + " is not an array"); } var argsAsReturnValues = ReturnValueConversions.SafeUnwrap <SortedDictionary <KeyWrapper, object> >(args, 2); if (_caller.connectedTings.Length == 0) { _caller.Say("No connected object to call function on", ""); return(0f); } if (receiverIndex == -1) { _caller.Say("Connection not open, can't call function.", ""); return(0f); } else if (receiverIndex < 0) { _caller.Say("Receiver index is below 0: " + receiverIndex, ""); return(0f); } else if (receiverIndex >= _caller.connectedTings.Length) { _caller.Say("Receiver index is too big (" + _caller.connectedTings.Length + ")", ""); return(0f); } MimanTing receiverTing = _caller.connectedTings[(int)receiverIndex]; receiverTing.PrepareForBeingHacked(); if (receiverTing.programs.Length == 0) { _caller.Say("Connected thing has no programs to call", ""); return(0f); } var fixedArgs = argsAsReturnValues.Values.ToArray(); receiverTing.masterProgram.StartAtFunctionIfItExists(functionName, fixedArgs, _program); _program.waitingForInput = true; return(0f); // "WAITING FOR RETURN VALUE FROM REMOTE FUNCTION"; }
public bool PutTingIntoRandomFreeSpot(MimanTing pTing) { Room room = _roomRunner.GetRoom(inventoryRoomName); foreach (var tilePoint in room.points) { if (!room.GetTile(tilePoint).HasOccupants()) { pTing.position = new WorldCoordinate(inventoryRoomName, tilePoint); return(true); } } D.Log("No free spot in the locker"); return(false); }
public float API_Connect(string name) { //Console.WriteLine(_caller + " connecting to " + name); MimanTing maybeTing = ConnectionAPI_Optimized.GetTingFromNameOrSourceCodeName(_tingRunner, name); // _tingRunner.GetTingUnsafe (name) as MimanTing; if (maybeTing != null) { return(_caller.AddConnectionToTing(maybeTing)); } else { string msg = "Can't find " + name + " to connect to"; if (_caller is Computer) { (_caller as Computer).API_Print(msg); } else { _caller.Say(msg, ""); } return(-1f); } }
public void Fry(Character pUser, MimanTing pTing) { if (on) { _objectOnStove = pTing; masterProgram.Start (); } else { _objectOnStove = null; _worldSettings.Notify (pUser.name, "Stove is not on"); } }
public void Hack(MimanTing pHackableTing) { if(pHackableTing == null) { D.Log("Hackable ting of " + name + " was null!"); return; } if(hackdev == null) { D.Log(name + " has got no hackdev to hack with"); return; } //logger.Log("Going to hack " + pHackableTing.name); if (pHackableTing != handItem) { FaceTing (pHackableTing); } pHackableTing.PrepareForBeingHacked(); if (pHackableTing == hackdev) { _worldSettings.Notify (name, "Modifier can't modify itself"); } else if(pHackableTing.programs.Length > 0) { MockProgram receiver = new MockProgram (retVal => { //D.Log("Got response from hackdev Allow function: " + retVal); if(retVal.GetType() == typeof(bool) && ((bool)retVal) == true) { StartAction("Hacking", pHackableTing, LONG_TIME, LONG_TIME); _dialogueRunner.EventHappened(name + "_hack_" + pHackableTing.name); } else { D.Log("Hacking not allowed with current device for character " + name); _worldSettings.Notify(name, "Not allowed with current device"); StopAction(); } }); StartAction("AttemptHacking", pHackableTing, 1.0f, 1.0f); pHackableTing.PrepareForBeingHacked (); hackdev.PrepareForBeingHacked (); if (hackdev.masterProgram.HasFunction ("Allow", true)) { hackdev.masterProgram.StartAtFunctionWithMockReceiver ("Allow", new object[] { pHackableTing.name, (float)pHackableTing.securityLevel }, receiver); } else { _worldSettings.Notify(name, "No Allow-function in " + hackdev.name); } } else { _worldSettings.Notify(name, "No programs to hack in " + pHackableTing.name); StopAction(); } }
public void SlurpIntoInternet(MimanTing pStartingTing) { if(actionName != "UsingComputer" && actionName != "Inspect") { D.Log(name + " can't slurp because she/he is " + actionName); return; } StartAction ("SlurpingIntoComputer", pStartingTing, 2.0f, 2.0f); }
private int RemoteFunctionCall(float receiverIndex, string functionName, object [] arguments) { var argsAsReturnValues = new object[arguments.Length]; int i = 0; foreach (object o in arguments) { if (o is float) { argsAsReturnValues[i] = (float)o; } else if (o is string) { argsAsReturnValues[i] = (string)o; } else if (o is bool) { argsAsReturnValues[i] = (bool)o; } else { throw new Exception("Can't handle argument to remote function call."); } i++; } if (_caller.connectedTings.Length == 0) { _caller.Say("No connected object to call function on", ""); return(0); } if (receiverIndex == -1) { _caller.Say("Connection not open, can't call function.", ""); return(0); } else if (receiverIndex < 0) { _caller.Say("Receiver index is below 0: " + receiverIndex, ""); return(0); } else if (receiverIndex >= _caller.connectedTings.Length) { _caller.Say("Receiver index is too big (" + _caller.connectedTings.Length + ")", ""); return(0); } MimanTing receiverTing = _caller.connectedTings[(int)receiverIndex]; receiverTing.PrepareForBeingHacked(); if (receiverTing.programs.Length == 0) { _caller.Say("Connected thing has no programs to call", ""); return(0); } //Program.OnProgramEndsReturnValue onReturnHandler = OnReturnValue; receiverTing.masterProgram.StartAtFunctionIfItExists(functionName, argsAsReturnValues, _program); _program.waitingForInput = true; return(0); // "WAITING FOR RETURN VALUE FROM REMOTE FUNCTION"; }
public void Attach(Ting pTarget) { //D.Log(name + " attached to " + pTarget + " will run program with content " + masterProgram.sourceCodeContent); _target = pTarget as MimanTing; masterProgram.Start(); }
// OBS!!! With this solution only one program in the Ting can use the API safely!!! public ConnectionAPI_Optimized(MimanTing pCaller, TingRunner pTingRunner, Program pProgram) { _caller = pCaller; _tingRunner = pTingRunner; _program = pProgram; }
public void WalkToTingAndHack(MimanTing pHackableTing) { rememberToHackComputerAfterSittingDown = true; if (pHackableTing.HasInteractionPointHere (this.position)) { Hack (pHackableTing); return; } PrepareForNewWalkBehaviour(pHackableTing.position, pHackableTing, WalkMode.WALK_TO_TING_AND_HACK); }
private void ReachedFinalPosition() { #if LOG s_logger.Log("Reached final position at " + _character.finalTargetPosition); #endif if (_character.walkMode == Character.WalkMode.WALK_TO_POINT) { #if LOG s_logger.Log(_character.name + " ending WALK_TO_POINT"); #endif _character.StopAction(); } else if (_character.walkMode == Character.WalkMode.WALK_TO_TING_AND_INTERACT) { #if LOG s_logger.Log(_character.name + " ending WALK_TO_TING_AND_INTERACT"); #endif if (_character.finalTargetTing == null) { #if LOG s_logger.Log("Final target ting is null, it might have been destroyed while the character was walking to interact with it."); #endif } else if (!CharacterIsAtInteractionPointOfFinalTargetTing()) { #if LOG s_logger.Log(_character + "'s finalTargetTing " + _character.finalTargetTing + " is not within reach! Ting pos: " + _character.finalTargetTing.position + ", character pos: " + _character.position); //, it might have been moved while the character was walking to interact with it. Trying to walk to it again."); #endif if (_character.timetable != null) { D.Log(_character + " is at interaction point of his/her finalTargetTing, will reset the timetable timer to zero, has timetable: " + _character.timetable.name); _character.CancelWalking(); _character.timetableTimer = 0f; // better to see if the behaviour can generate another target to walk to } else { #if LOG s_logger.Log(_character + " will immedieately try to walk to the target again"); #endif _character.WalkToTingAndInteract(_character.finalTargetTing); } return; } else if (_character.finalTargetTing.canBePickedUp) { #if LOG s_logger.Log(_character + " will pick up final target ting"); #endif _character.PickUp(_character.finalTargetTing); } else if (_character.CanInteractWith(_character.finalTargetTing)) { #if LOG s_logger.Log(_character + " will interact with final target ting"); #endif _character.InteractWith(_character.finalTargetTing); } else { s_logger.Log(_character.name + " can't interact with " + _character.finalTargetTing.name); } } else if (_character.walkMode == Character.WalkMode.WALK_TO_TING_AND_HACK) { #if LOG s_logger.Log(_character.name + " ending WALK_TO_TING_AND_HACK"); #endif if (_character.finalTargetTing == null) { #if LOG s_logger.Log("Final target ting is null, it might have been destroyed while the character was walking to hack with it."); #endif } else if (!CharacterIsAtInteractionPointOfFinalTargetTing()) { #if LOG s_logger.Log(_character + "'s finalTargetTing " + _character.finalTargetTing + " is not within reach! Ting pos: " + _character.finalTargetTing.position + ", character pos: " + _character.position); //, it might have been moved while the character was walking to interact with it. Trying to walk to it again."); #endif _character.WalkToTingAndHack(_character.finalTargetTing as MimanTing); } else { MimanTing hackableTing = _character.finalTargetTing as MimanTing; D.isNull(hackableTing); _character.Hack(hackableTing); } } else if (_character.walkMode == Character.WalkMode.WALK_TO_TING_AND_USE_HAND_ITEM) { #if LOG s_logger.Log(_character.name + " ending WALK_TO_TING_AND_USE_HAND_ITEM"); #endif MimanTing finalTing = _character.finalTargetTing as MimanTing; D.isNull(finalTing); _character.UseHandItemToInteractWith(finalTing); } _character.ClearWalkingData(); }
static void PrintTingInfo(MimanTing pTing) { foreach(PropertyInfo p in pTing.GetType().GetProperties()) { foreach(Attribute a in p.GetCustomAttributes(true)) { if(a.Match(EDITABLE_IN_EDITOR) || a.Match(SHOW_IN_EDITOR)) { object o = p.GetValue(pTing, null); string line = ""; if(o == null) line = "null"; else if(o is string) line = "\"" + o.ToString() + "\""; else line = o.ToString(); Console.WriteLine(p.Name + ": " + line); } } } }
// OBS!!! With this solution only one program in the Ting can use the API safely!!! public ConnectionAPI(MimanTing pCaller, TingRunner pTingRunner, Program pProgram) { _caller = pCaller; _tingRunner = pTingRunner; _program = pProgram; }
private void SetHandItem(MimanTing pNewHandItem) { if (pNewHandItem == null) { D.Log ("pNewHandItem is null!"); return; } if (handItem != null) { MoveHandItemToInventoryForcefully (); if(onNewHandItem != null) { onNewHandItem("", false); } } handItem = pNewHandItem; handItem.isBeingHeld = true; handItem.PrepareForBeingHacked(); // this will make drinks generate programs if they don't have them already (happens when they are made by vending machines). if(onNewHandItem != null) { onNewHandItem(handItem.name, false); } }
public void Throw(MimanTing pTing) { currentTrash = pTing; masterProgram.Start(); }
public bool PutTingIntoRandomFreeSpot(MimanTing pTing) { Room room = _roomRunner.GetRoom(inventoryRoomName); foreach (var tilePoint in room.points) { if (!room.GetTile(tilePoint).HasOccupants()) { pTing.position = new WorldCoordinate(inventoryRoomName, tilePoint); return true; } } D.Log("No free spot in the locker"); return false; }
public void Throw(MimanTing pTing) { currentTrash = pTing; masterProgram.Start (); }