//turn on all weapons public void ManualFire(bool doFire) { FindWeapons(); SetWeaponPower(doFire); if (doFire) { Util.GetInstance() .Log(_fireGun + "[Drone.ManualFire] Number of guns -> " + _manualGuns.Count, "weapons.txt"); Util.GetInstance() .Log(_fireGun + "[Drone.ManualFire] number of all weapons -> " + _allWeapons.Count, "weapons.txt"); foreach (var gun in _manualGuns) { gun.ApplyAccumulatedDamage(); _fireGun.Apply(gun.FatBlock); } if (Math.Abs((DateTime.Now - _lastRocketFired).TotalMilliseconds) > 500 && _fireRocket != null && _manualRockets.Count > 0) { var launcher = _manualRockets[missileStaggeredFireIndex]; _fireGun.Apply(launcher.FatBlock); if (missileStaggeredFireIndex + 1 < _manualRockets.Count()) { missileStaggeredFireIndex++; } else { missileStaggeredFireIndex = 0; } _lastRocketFired = DateTime.Now; } } _isFiringManually = doFire; }
internal void SetBroadcasting(bool broadcastingEnabled) { FindBeacons(); ITerminalAction power = broadcastingEnabled ? _blockOn : _blockOff; foreach (var v in beacons) { power.Apply(v); } FindAntennas(); foreach (var v in antennas) { power.Apply(v); } }
void cambiarAccionObjeto(string _objeto, string _accion) { IMyTerminalBlock objeto = captureCube(_objeto); ITerminalAction accion = objeto.GetActionWithName(_accion); accion.Apply(objeto); }
//Disables all beacons and antennas and deletes the ship. public void DeleteShip() { var lstSlimBlock = new List <IMySlimBlock>(); _cubeGrid.GetBlocks(lstSlimBlock, (x) => x.FatBlock is Sandbox.ModAPI.IMyRadioAntenna); foreach (var block in lstSlimBlock) { Sandbox.ModAPI.IMyRadioAntenna antenna = (Sandbox.ModAPI.IMyRadioAntenna)block.FatBlock; ITerminalAction act = antenna.GetActionWithName("OnOff_Off"); act.Apply(antenna); } lstSlimBlock = new List <IMySlimBlock>(); _cubeGrid.GetBlocks(lstSlimBlock, (x) => x.FatBlock is Sandbox.ModAPI.IMyBeacon); foreach (var block in lstSlimBlock) { Sandbox.ModAPI.IMyBeacon beacon = (Sandbox.ModAPI.IMyBeacon)block.FatBlock; ITerminalAction act = beacon.GetActionWithName("OnOff_Off"); act.Apply(beacon); } _cubeGrid.SyncObject.SendCloseRequest(); MyAPIGateway.Entities.RemoveEntity(_cubeGrid as IMyEntity); //_cubeGrid = null; }
private TriggerResult triggerApplyAction(List <string> args) { if (args.Count < 2) { Program.Echo("Expected 2 args: name, action"); return(TriggerResult.Error); } string name = args[0]; string actionName = args[1]; findBlocksOfType <IMyTerminalBlock>(_tempBlocks, b => b.CustomName.Contains(name) && isSameConstructAsMe(b)); foreach (IMyTerminalBlock b in _tempBlocks) { ITerminalAction action = b.GetActionWithName(actionName); if (action == null) { Program.Echo("No action '" + actionName + "' for block of type '" + b.GetType() + "'"); return(TriggerResult.Error); } action.Apply(b); } return(TriggerResult.Ok); }
private void ChangeActionToObject(string _objeto, string _accion) { IMyTerminalBlock objeto = CaptureCube(_objeto); ITerminalAction accion = objeto.GetActionWithName(_accion); accion.Apply(objeto); }
public void rotorAction(String Name) { ITerminalAction Action = this.rotor.GetActionWithName(Name); if (Action != null) { Action.Apply(this.rotor); } }
public void Apply() { Init(); if (_action != null && _parent.HasEntity) { Log.Write("{0}#{1}::{2}", _parent.EntityTypeName, _parent.Entity.EntityId, _name); _action.Apply((Sandbox.ModAPI.IMyCubeBlock)_parent.Entity); } }
public void ApplyAction(IMyTerminalBlock block, string actionName) { ITerminalAction action = block.GetActionWithName(actionName); if (action == null) { throw new ArgumentException("Action could not be found: " + actionName); } action.Apply(block); }
public EasyBlock ApplyAction(String Name) { ITerminalAction Action = this.GetAction(Name); if (Action != null) { Action.Apply(this.Block); } return(this); }
void ControlTurret(Turret turret, long?target) { if (!target.HasValue) { foreach (var mySmallGatlingGun in turret.guns) { _shootOff.Apply(mySmallGatlingGun); } return; } MyDetectedEntityInfo targetMdei = program.trackedEntities[target.Value]; //desired rotation Vector3 turretPositionApprox = turret.gunsRotor.TopGrid.GridIntegerToWorld(turret.averageGunPosition); //expected interception time float expectedInterceptTime = (float)Math.Sqrt(Vector3.Distance(targetMdei.Position, turretPositionApprox) / (400 + targetMdei.Velocity.Length())); Vector3 positionAtIntercept = targetMdei.Position + expectedInterceptTime * targetMdei.Velocity; /*program.logMessages.Enqueue($"from guns: {positionAtIntercept - turretPositionApprox}"); * program.logMessages.Enqueue($"from base: {positionAtIntercept - turret.baseRotor.CubeGrid.GridIntegerToWorld(turret.baseRotor.Position)}"); * * program.logMessages.Enqueue($"Target velocity : {targetMdei.Velocity}"); * program.logMessages.Enqueue($"Expected intercept time : {expectedInterceptTime}");*/ float angleDiff = 0; foreach (var stator in turret.joints) { float desiredJointAngle = CalculateDesiredAngle(stator, positionAtIntercept - turretPositionApprox); angleDiff += RotateTowardsAngle(stator, desiredJointAngle); } //program.logMessages.Enqueue($"Angle diff : {angleDiff}"); //program.Log($"Turret local position: {Me.CubeGrid.WorldToGridInteger(turretPositionApprox)}"); //program.Log($"Target local position: {Me.CubeGrid.WorldToGridInteger(positionAtIntercept)}"); if (angleDiff < TolerableAngleDiff) { bool targetBlocked = false; program.Me.CubeGrid.RayCastGrid(turretPositionApprox, (positionAtIntercept - turretPositionApprox), (pos) => { targetBlocked = true; //program.logMessages.Enqueue( $"Block: {program.Me.CubeGrid.GetCubeBlock(pos).BlockDefinition.SubtypeName} " ); }); foreach (var mySmallGatlingGun in turret.guns) { (targetBlocked ? _shootOff : _shootOn).Apply(mySmallGatlingGun); } } }
//add objects to this ships local known objects collection (within detection range - 2km by defualt) //Turn weapons on and off SetWeaponPower(true) turns weapons online: vice versa public void SetWeaponPower(bool isOn) { foreach (var w in _allWeapons) { if (isOn) { _blockOn.Apply(w.FatBlock); } else { _blockOff.Apply(w.FatBlock); } } }
private void TopGrid_OnClose(IMyEntity e) { e.OnClose -= TopGrid_OnClose; listening = false; if (!wheel.MarkedForClose && !wheel.Closed) { if (builder == null) { addWheel.Apply(wheel); } else { SpawnWheel(); } } }
public void Main(string argument, UpdateType updateSource) { sb.Append(projector.CustomName).AppendLine(); int timer = this.timer.GetValue(projector); if (waitingOnGrid) { if (timer == 0) { waitingOnGrid = false; } sb.Append("Timer: ").Append(timerMax - timer).Append('/').Append(timerMax).AppendLine(); float percent = 1 - (timer / (float)timerMax); int barCount = (int)Math.Round(percent * 20); sb.Append('[').Append('|', barCount).Append('.', 20 - barCount).Append(']').AppendLine(); AppendTime(sb, timer); sb.Append('s').AppendLine(); } else { if (timer > 0) { // New Grid waitingOnGrid = true; timerMax = Math.Max(timer, projectedGridTimer.GetValue(projector)); } sb.Append("Timer: ").Append(projectedGridTimer.GetValue(projector)).AppendLine(); Dictionary <MyItemType, int> comps = projectedGridComps.GetValue(projector) ?? new Dictionary <MyItemType, int>(); sb.Append("Components: (").Append(comps.Count).Append(')').AppendLine(); foreach (KeyValuePair <MyItemType, int> kv in comps) { sb.Append(kv.Key.SubtypeId).Append(": ").Append(kv.Value).AppendLine(); } if (autoBuild) { spawnProjection.Apply(projector); } } canvas.WriteText(sb); sb.Clear(); }
public JsValue ApplyAction(JsValue obj, JsValue[] arguments) { if (arguments.Length < 1) { return(false); } var name = TypeConverter.ToString(arguments.At(0)); ITerminalAction action = tb.GetActionWithName(name); if (action == null) { return(false); } // TODO - handle parameters action.Apply(tb); return(true); }
private void Lock(IMyCubeBlock obj) { IMyLargeTurretBase Turret = Entity as IMyLargeTurretBase; if (obj.OwnerId == 0 && Turret.IsWorking) { Turret.Enabled = false; Turret.RefreshCustomInfo(); return; } ITerminalAction TargetLarge = Turret.GetActionWithName("TargetLargeShips_Off"); if (TargetLarge != null) { TargetLarge.Apply(Turret); } ITerminalAction TargetSmall = Turret.GetActionWithName("TargetSmallShips_Off"); if (TargetSmall != null) { TargetSmall.Apply(Turret); } ITerminalAction TargetStation = Turret.GetActionWithName("TargetStations_Off"); if (TargetStation != null) { TargetStation.Apply(Turret); } ITerminalAction TargetMoving = Turret.GetActionWithName("TargetMoving_Off"); if (TargetMoving != null) { TargetMoving.Apply(Turret); } }
//Disables all beacons and antennas and deletes the ship. public void DeleteShip() { var lstSlimBlock = new List <IMySlimBlock>(); Ship.GetBlocks(lstSlimBlock, (x) => x.FatBlock is Sandbox.ModAPI.IMyRadioAntenna); foreach (var block in lstSlimBlock) { Sandbox.ModAPI.IMyRadioAntenna antenna = (Sandbox.ModAPI.IMyRadioAntenna)block.FatBlock; ITerminalAction act = antenna.GetActionWithName("OnOff_Off"); act.Apply(antenna); } lstSlimBlock = new List <IMySlimBlock>(); Ship.GetBlocks(lstSlimBlock, (x) => x.FatBlock is Sandbox.ModAPI.IMyBeacon); foreach (var block in lstSlimBlock) { Sandbox.ModAPI.IMyBeacon beacon = (Sandbox.ModAPI.IMyBeacon)block.FatBlock; ITerminalAction act = beacon.GetActionWithName("OnOff_Off"); act.Apply(beacon); } MyAPIGateway.Entities.RemoveEntity(Ship as IMyEntity); Ship = null; }
public void Main(string argument, UpdateType updateSource) { // clear console logger.clear(); List <IMyMotorStator> rotors = GetRotors(); foreach (var rotor in rotors.OrderBy(r => r.CustomName).ToList()) { logger.log(rotor.CustomName.ToString()); if (rotor.LowerLimitDeg != float.MinValue || rotor.UpperLimitDeg != float.MaxValue) { resetLimits(rotor); } else { updateLimits(rotor); } List <ITerminalAction> actions = new List <ITerminalAction>(); ITerminalAction turnOn = rotor.GetActionWithName("OnOff_On"); turnOn.Apply(rotor); } } //main
/// <summary> /// Used for open close logic /// </summary> public override void UpdateAfterSimulation10() { frameMod = (short)((frameMod + 1) % 3); if (frameMod > 0) { return; } if (myDoor == null) { return; } if (!myDoor.IsFunctional || !myDoor.IsWorking) { return; } //LogMessage("Looking for CustomName", false); string myName = myDoor.CustomName; if (_LastCustomName != myName) { _LastCustomName = myName; _IsActive = myName != null && myName.Contains("AutoDoor"); if (_IsActive) { int idx = myName.LastIndexOf('-'); if (idx >= 0 && idx + 1 < myName.Length) { string partialName = myName.Substring(idx + 1); float newDistValue = _DefaultDistValue; // try to parse it if (float.TryParse(partialName, out newDistValue)) { distValue = newDistValue; } else { distValue = _DefaultDistValue; } } else { distValue = _DefaultDistValue; } } } if (!_IsActive) { return; } // cache the block position var myWM = myDoor.WorldMatrix; var myBB = myDoor.LocalAABB; var minVec = myBB.Min; var maxVec = myBB.Max; minVec.Z -= distValue; maxVec.Z += distValue; //minVec.X = 0; //maxVec.X = 0; minVec.Y -= 0.05f; maxVec.Y = 0; myBB.Min = minVec; myBB.Max = maxVec; var myBackBB = myBB; myBB = myBB.Transform(ref myWM); // result if any player is within range bool playerInRange = false; //LogMessage("Got to player list lookup!", false); List <IMyPlayer> players = new List <IMyPlayer>(); // check to make sure players exist and then find all the players if (MyAPIGateway.Multiplayer != null && MyAPIGateway.Multiplayer.Players != null) { MyAPIGateway.Multiplayer.Players.GetPlayers(players); } //Base6Directions.Direction pForward = Base6Directions.Direction.Up; // look through for players in that are in range foreach (var player in players) { // check that there is a valid character if (player.PlayerCharacter == null) { continue; } // get there position var charPosition = player.PlayerCharacter.Entity.GetPosition(); //if( (myDoor.GetPosition() - charPosition).Length() < 10 ) { // LogMessage(myBackBB.ToString(), true); // LogMessage(myBB.ToString(), true); //} var result = myBB.Contains(charPosition); bool inRange = result == ContainmentType.Contains; //distVec.Length() <= distValue; //LogMessage(string.Format("inRange was {0}", inRange), true); if (!inRange) { continue; } //LogMessage(string.Format("Cen {0}", myBB.Center), true); //LogMessage(string.Format("Min {0}", myBB.Min), true); //LogMessage(string.Format("Max {0}", myBB.Max), true); // check for acces, we only open for friendlys if (!myDoor.HasPlayerAccess(player.PlayerId)) { continue; } //var charWM = player.PlayerCharacter.Entity.WorldMatrix; //pForward = Base6Directions.GetForward(ref charWM); //var dir = myWM.GetClosestDirection(distVec); // result //bool inOri = (pForward == myForward || pForward == myBackward);//&&(dir != Base6Directions.Direction.Up && dir != Base6Directions.Direction.Down); playerInRange = inRange; //&& inOri; if (playerInRange) { break; } } //LogMessage(string.Format("playerInRange was {0} and DoorState was {1}", playerInRange,_DoorState), false); if (toggleAction == null && !SetupToggleAction()) { return; } if (!playerInRange && _DoorState == _DoorOpen) { MyAPIGateway.Utilities.ShowNotification(string.Format("Closing {0}", (Entity as Sandbox.ModAPI.Ingame.IMyTerminalBlock).DisplayNameText), 1000, MyFontEnum.Red); toggleAction.Apply(myDoorBlock); } if (playerInRange && _DoorState == _DoorClosed) { MyAPIGateway.Utilities.ShowNotification(string.Format("Opening {0}", (Entity as Sandbox.ModAPI.Ingame.IMyTerminalBlock).DisplayNameText), 1000, MyFontEnum.Red); toggleAction.Apply(myDoorBlock); } }
private void runActionOnBlock(string blockName, string actionString) { //log("entered runActionOnBlock("+blockName+", "+actionString+")", "runActionOnBlock()", Logger.severity.TRACE); blockName = blockName.ToLower().Replace(" ", ""); actionString = actionString.Trim(); List <IMySlimBlock> blocksWithName = new List <IMySlimBlock>(); owner.myGrid.GetBlocks(blocksWithName); foreach (IMySlimBlock block in blocksWithName) { IMyCubeBlock fatblock = block.FatBlock; if (fatblock == null) { continue; } Sandbox.Common.MyRelationsBetweenPlayerAndBlock relationship = fatblock.GetUserRelationToOwner(owner.currentRCblock.OwnerId); if (relationship != Sandbox.Common.MyRelationsBetweenPlayerAndBlock.Owner && relationship != Sandbox.Common.MyRelationsBetweenPlayerAndBlock.FactionShare) { //log("failed relationship test for " + fatblock.DisplayNameText + ", result was " + relationship.ToString(), "runActionOnBlock()", Logger.severity.TRACE); continue; } //log("passed relationship test for " + fatblock.DisplayNameText + ", result was " + relationship.ToString(), "runActionOnBlock()", Logger.severity.TRACE); //log("testing: " + fatblock.DisplayNameText, "runActionOnBlock()", Logger.severity.TRACE); // name test if (fatblock is Ingame.IMyRemoteControl) { string nameOnly = fatblock.getNameOnly(); if (nameOnly == null || !nameOnly.Contains(blockName)) { continue; } } else { if (!fatblock.DisplayNameText.looseContains(blockName)) { //log("testing failed " + fatblock.DisplayNameText + " does not contain " + blockName, "runActionOnBlock()", Logger.severity.TRACE); continue; } //log("testing successfull " + fatblock.DisplayNameText + " contains " + blockName, "runActionOnBlock()", Logger.severity.TRACE); } if (!(fatblock is IMyTerminalBlock)) { //log("not a terminal block: " + fatblock.DisplayNameText, "runActionOnBlock()", Logger.severity.TRACE); continue; } IMyTerminalBlock terminalBlock = fatblock as IMyTerminalBlock; ITerminalAction actionToRun = terminalBlock.GetActionWithName(actionString); // get actionToRun on every iteration so invalid blocks can be ignored if (actionToRun != null) { log("running action: " + actionString + " on block: " + fatblock.DisplayNameText, "runActionOnBlock()", Logger.severity.DEBUG); actionToRun.Apply(fatblock); } else { log("could not get action: " + actionString + " for: " + fatblock.DisplayNameText, "runActionOnBlock()", Logger.severity.TRACE); } } }
public Drone(IMyEntity ent) { var ship = (IMyCubeGrid)ent; Ship = ship; var lstSlimBlock = new List <IMySlimBlock>(); GridTerminalSystem = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(ship); //If it has any type of cockipt ship.GetBlocks(lstSlimBlock, (x) => x.FatBlock is Sandbox.ModAPI.IMyRemoteControl); FindWeapons(); SetupActions(); //If no cockpit the ship is either no ship or is broken. if (lstSlimBlock.Count != 0) { //Make the controls be the cockpit ShipControls = lstSlimBlock[0].FatBlock as IMyControllableEntity; #region Activate Beacons && Antennas //Maximise radius on antennas and beacons. lstSlimBlock.Clear(); ship.GetBlocks(lstSlimBlock, (x) => x.FatBlock is Sandbox.ModAPI.IMyRadioAntenna); foreach (var block in lstSlimBlock) { Sandbox.ModAPI.IMyRadioAntenna antenna = (Sandbox.ModAPI.IMyRadioAntenna)block.FatBlock; if (antenna != null) { //antenna.GetActionWithName("SetCustomName").Apply(antenna, new ListReader<TerminalActionParameter>(new List<TerminalActionParameter>() { TerminalActionParameter.Get("Combat Drone " + _manualGats.Count) })); antenna.SetValueFloat("Radius", 10000);//antenna.GetMaximum<float>("Radius")); _blockOn.Apply(antenna); } } lstSlimBlock = new List <IMySlimBlock>(); ship.GetBlocks(lstSlimBlock, (x) => x.FatBlock is Sandbox.ModAPI.IMyBeacon); foreach (var block in lstSlimBlock) { Sandbox.ModAPI.IMyBeacon beacon = (Sandbox.ModAPI.IMyBeacon)block.FatBlock; if (beacon != null) { beacon.SetValueFloat("Radius", 10000);//beacon.GetMaximum<float>("Radius")); _blockOn.Apply(beacon); } } #endregion //SetWeaponPower(true); //AmmoManager.ReloadReactors(_allReactors); //AmmoManager.ReloadGuns(_manualGats); ship.GetBlocks(lstSlimBlock, x => x is IMyEntity); List <IMyTerminalBlock> allTerminalBlocks = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType <IMyCubeBlock>(allTerminalBlocks); HealthBlockBase = allTerminalBlocks.Count; if (ShipControls != null) { navigation = new ThrusterGyroControls(ship, ShipControls); _ownerId = ((Sandbox.ModAPI.IMyTerminalBlock)ShipControls).OwnerId; tc = new TargetingControls(Ship, _ownerId); } } Ship.OnBlockAdded += RecalcMaxHp; myNumber = numDrones; numDrones++; }