private void updatePatrols(IMyCubeBlock block) { if (patrolPoints.Count == 0) { return; } foreach (var npc in npcsSpawned) { if (!patrolProgress.ContainsKey(npc.ID)) { patrolProgress[npc.ID] = 0; } var progress = patrolProgress[npc.ID]; var first = patrolPoints[progress]; npc.clearWaypointsConservingEnemy(); npc.addWaypoint(first, this.block); //check if npc is close enough var dist = Vector3.Distance(localToWorldPos(block, first), npc.animator.grid.GetPosition()); if (dist < 1.8f || npc.wasStuck) { //point reached progress++; npc.wasStuck = false; npc.stuckTimer = 0; } progress = progress % patrolPoints.Count; patrolProgress[npc.ID] = progress; } }
public override void UpdateOnceBeforeFrame() { MyLog.Default.WriteLine("executing once before frame for npc control block!"); block = Entity as IMyCargoContainer; NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME; if (!controlsCreated) { TerminalGroupSelector.createControls(); controlsCreated = true; //addStoreTrades(); } var terminalBlock = ((IMyTerminalBlock)block); if (terminalBlock != null) { terminalBlock.AppendingCustomInfo += addcustomInfo; } if (block.BlockDefinition.SubtypeId.Equals("NPC_Control_block")) { npc_subtype = "NPC_Basic"; } if (block.BlockDefinition.SubtypeId.Equals("NPC_Control_elite")) { npc_subtype = "NPC_Elite"; } }
protected override AutopilotActionList.AutopilotAction Parse(VRage.Game.ModAPI.IMyCubeBlock autopilot, string command, out string message) { string[] split = command.Split(','); if (split.Length != 3) { if (split.Length > 3) { message = "Too many arguments: " + split.Length; } else { message = "Too few arguments: " + split.Length; } return(null); } string split2 = split[2].Trim(); try { m_value = (T)Convert.ChangeType(split2, typeof(T)); } catch (Exception ex) { Logger.DebugLog("string: " + split2 + ", exception: " + ex); message = ex.GetType() + ex.Message; m_hasValue = false; return(null); } m_hasValue = true; message = null; return(mover => SetPropertyOfBlock(mover, split[0], split[1], m_value)); }
public static Vector3 worldToLocalPos(IMyCubeBlock referenceBlock, Vector3 worldPosition) { Vector3D referenceWorldPosition = referenceBlock.WorldMatrix.Translation; Vector3D worldDirection = worldPosition - referenceWorldPosition; return(Vector3D.TransformNormal(worldDirection, MatrixD.Transpose(referenceBlock.WorldMatrix))); //note that we transpose to go from world -> body }
private void OnIsWorkingChanged(IMyCubeBlock block) { if (block == null || block.Closed) { return; } SetTurretLightOnOff(!block.IsWorking); }
private void attackPointOrder(IMyCubeBlock block) { foreach (var npc in npcsSpawned) { if (npc.getWaypointCount() == 0) { npc.addWaypoint(attackPoint); } } }
private void standAtPoint(IMyCubeBlock block) { foreach (var npc in npcsSpawned) { if (npc.getWaypointCount() == 0) { npc.addWaypoint(standPoint, block); } } }
public static IMyIdentity CubeBlockOwnerToIdentity(IMyCubeBlock block) { if (block == null) { return(null); } var identities = new List <IMyIdentity>(); MyAPIGateway.Players.GetAllIdentites(identities, i => i.IdentityId == block.OwnerId); return(identities.FirstOrDefault()); }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { base.Init(objectBuilder); m_reactor = Entity as IMyReactor; m_parent = Entity as VRage.Game.ModAPI.IMyCubeBlock; m_parent.UpgradeValues.Add("Power", 0f); m_objectBuilder = objectBuilder; m_parent.OnUpgradeValuesChanged += OnUpgradeValuesChanged; }
private void followPlayer(IMyCubeBlock myCubeBlock) { var playerPos = MyAPIGateway.Session.Player.GetPosition(); playerPos = NPCBasicMover.toSurfacePos(playerPos, MyAPIGateway.Session.Player.Character, playerPos); foreach (var npc in npcsSpawned) { var offset = offsets[npc.ID]; var npcPositionTarget = playerPos + offset; if (Vector3.Distance(npc.getCurrentWaypoint(), npcPositionTarget) < 1f) { return; } npc.clearWaypointsConservingEnemy(); npc.addWaypoint(npcPositionTarget); } }
private void updateMode(IMyCubeBlock block) { try { var selected = getSelected(block as IMyTerminalBlock); var newMode = (NPCMode)(int.Parse(selected)); if (newMode != selectedMode) { //mode change stopRecordingPoints(); resetData(); deleteOldWaypoints(newMode == NPCMode.follow); } selectedMode = newMode; } catch (Exception ex) { // ignored } }
private static bool CheckParams(VRage.Game.ModAPI.IMyCubeBlock autopilot, string blockName, string actionName, string[] parameters, out string message, out List<Ingame.TerminalActionParameter> termParams) { int needParams = -1; message = actionName + " not found"; foreach (IMyCubeBlock block in AttachedGrid.AttachedCubeBlocks((IMyCubeGrid)autopilot.CubeGrid, AttachedGrid.AttachmentKind.Permanent, true)) { if (!block.DisplayNameText.Contains(blockName, StringComparison.InvariantCultureIgnoreCase)) continue; IMyTerminalBlock term = block as IMyTerminalBlock; if (term == null) continue; ITerminalAction terminalAction = (ITerminalAction)term.GetActionWithName(actionName); if (terminalAction != null) { int paramCount = terminalAction.GetParameterDefinitions().Count; if (Math.Abs(parameters.Length - paramCount) > (Math.Abs(parameters.Length - needParams))) continue; needParams = paramCount; if (parameters.Length == needParams && CheckParams(terminalAction, out message, out termParams, parameters)) return true; } } if (needParams < 0) { message = actionName + " has no parameters"; termParams = null; return false; } if (parameters.Length != needParams) { message = actionName + " requires " + needParams + " parameters, got " + parameters.Length; termParams = null; return false; } termParams = null; return false; }
protected override AutopilotActionList.AutopilotAction Parse(VRage.Game.ModAPI.IMyCubeBlock autopilot, string command, out string message) { string[] split = command.Split(new char[] { ',' }, 3); if (split.Length < 2) { message = "Too few arguments: " + split.Length; return null; } string blockName = split[0].Trim(), actionName = split[1].Trim(); if (string.IsNullOrWhiteSpace(blockName)) { message = "missing block name"; return null; } if (string.IsNullOrWhiteSpace(actionName)) { message = "missing action"; return null; } List<Ingame.TerminalActionParameter> termParams = null; if (split.Length > 2) { if (!CheckParams(autopilot, blockName, actionName, split[2].Split(','), out message, out termParams)) return null; m_actionParams = new StringBuilder(split[2]); } else m_actionParams = new StringBuilder(); m_targetBlock = new StringBuilder(blockName); m_termAction = actionName; message = null; return mover => RunActionOnBlock(mover, blockName, actionName, termParams); }
protected override AutopilotActionList.AutopilotAction Parse(VRage.Game.ModAPI.IMyCubeBlock autopilot, string command, out string message) { string[] split = command.Split(','); switch (split.Length) { case 1: m_panelName = new StringBuilder(split[0]); m_identifier = new StringBuilder(); break; case 2: m_panelName = new StringBuilder(split[0]); m_identifier = new StringBuilder(split[1]); break; default: message = "Too many arguments: " + split.Length; return(null); } message = null; return(mover => VRage.Exceptions.ThrowIf <NotImplementedException>(true)); }
public static Vector3 localToWorldPos(IMyCubeBlock referenceBlock, Vector3 localPosition) { return(Vector3D.Transform(localPosition, referenceBlock.WorldMatrix)); }