private void RecalcMaxHp(IMySlimBlock obj) { List <IMyTerminalBlock> allTerminalBlocks = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType <IMyCubeBlock>(allTerminalBlocks); double count = 0; foreach (var block in allTerminalBlocks) { count += block.IsWorking || block.IsFunctional ? 100d : 0d; } HealthBlockBase = allTerminalBlocks.Count;//*(runningPercent); }
private void RecalcMaxHp(IMySlimBlock obj) { List<IMyTerminalBlock> allTerminalBlocks = new List<IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType<IMyCubeBlock>(allTerminalBlocks); double count = 0; foreach (var block in allTerminalBlocks) { count += block.IsWorking || block.IsFunctional ? 100d : 0d; } HealthBlockBase = allTerminalBlocks.Count;//*(runningPercent); }
/// <summary> /// Any player who owns a block on the grid can modify it. If noone owns a block everyone can modify it. /// </summary> /// <param name="player"></param> /// <param name="block"></param> /// <returns></returns> public static bool CanModify(IMyPlayer player, IMySlimBlock block) { return CanModify(player, block.CubeGrid); }
private static bool CanDamageBlock(long attackerEntityId, IMySlimBlock block, MyStringHash type) { foreach (ProtectionArea area in Config.Areas) { if (IsProtected(block)) continue; // if we can't find out who attacks and the block is inside the area, we don't apply the damage IMyEntity attackerEntity; if (!MyAPIGateway.Entities.TryGetEntityById(attackerEntityId, out attackerEntity)) return false; if (type == MyDamageType.Grind) { IMyPlayer player; if (attackerEntity is IMyShipGrinder) { player = MyAPIGateway.Players.GetPlayerControllingEntity(attackerEntity.GetTopMostParent()); if (player == null) return false; return CanModify(player, block); } return _handtoolCache.TryGetPlayer(attackerEntity.EntityId, out player) && CanModify(player, block); } // we don't want players to destroy things in protection areas... return false; } return true; }
/// <summary> /// Used to find out whether an block is inside a protected area or not. /// </summary> /// <param name="block"></param> /// <returns>True if the block is inside a protected area. If the block is null it will return false.</returns> public static bool IsProtected(IMySlimBlock block) { if (block == null || Config == null || Config.Areas == null || !Config.ProtectionEnabled) return false; return Config.Areas.Any(area => area.Contains(block)) ^ Config.ProtectionInverted; }
private static bool CanDamageBlock(long attackerEntityId, IMySlimBlock block, MyStringHash type) { if (!IsProtected(block)) return true; IMyEntity attackerEntity; if (!MyAPIGateway.Entities.TryGetEntityById(attackerEntityId, out attackerEntity)) return false; if (type == MyDamageType.Grind) { IMyPlayer player; if (attackerEntity is IMyShipGrinder) { player = MyAPIGateway.Players.GetPlayerControllingEntity(attackerEntity.GetTopMostParent()); if (player == null) return false; return CanModify(player, block); } return _handtoolCache.TryGetPlayer(attackerEntity.EntityId, out player) && CanModify(player, block); } // we don't want players to destroy things in protection areas... return false; }
public void GetMultiblockConfig() { #warning TODO: Restrict barrel placement to directly in front of the main body List <Sandbox.ModAPI.IMySlimBlock> connectedBlocks = new List <Sandbox.ModAPI.IMySlimBlock>(); Sandbox.ModAPI.IMyCubeGrid grid = (Sandbox.ModAPI.IMyCubeGrid)MDBody.CubeGrid; Matrix localMatrix = MDBody.LocalMatrix; List <Vector3I> searchQueue = new List <Vector3I>() { FindOffset(localMatrix, new Vector3I(2, 0, 1)), //right port FindOffset(localMatrix, new Vector3I(-2, 0, 1)), //left port FindOffset(localMatrix, new Vector3I(0, 0, 3)), //front port }; while (searchQueue.Count > 0) { Vector3I searchLocation = searchQueue[0]; Sandbox.ModAPI.IMySlimBlock block = grid.GetCubeBlock(searchLocation); if (block != null) { if (!connectedBlocks.Contains(block)) { if (block.GetObjectBuilder().SubtypeId.ToString().Contains("MassDriver")) { connectedBlocks.Add(block); } switch (block.GetObjectBuilder().SubtypeId.ToString()) { case "MassDriverCord": searchQueue.Add(FindOffset(block.FatBlock.LocalMatrix, new Vector3I(0, 0, 1))); //front port searchQueue.Add(FindOffset(block.FatBlock.LocalMatrix, new Vector3I(0, 0, -1))); //back port break; case "MassDriverCordSupport": searchQueue.Add(FindOffset(block.FatBlock.LocalMatrix, new Vector3I(0, 0, 1))); //front port searchQueue.Add(FindOffset(block.FatBlock.LocalMatrix, new Vector3I(0, 0, -1))); //back port break; case "MassDriverCordTurn": searchQueue.Add(FindOffset(block.FatBlock.LocalMatrix, new Vector3I(1, 0, 0))); //right port searchQueue.Add(FindOffset(block.FatBlock.LocalMatrix, new Vector3I(0, -1, 0))); //bottom port break; case "MassDriverCapacitor": //need to change the translation matrix a little because of the block's even-block-count depth and height Vector3 fixedCapTranslation = block.FatBlock.LocalMatrix.Translation + block.FatBlock.LocalMatrix.Forward + block.FatBlock.LocalMatrix.Down; Matrix fixedCapMatrix = block.FatBlock.LocalMatrix; fixedCapMatrix.Translation = fixedCapTranslation; searchQueue.Add(FindOffset(fixedCapMatrix, new Vector3I(0, 0, 2))); //front port searchQueue.Add(FindOffset(fixedCapMatrix, new Vector3I(0, 0, -3))); //back port searchQueue.Add(FindOffset(fixedCapMatrix, new Vector3I(0, -1, 0))); //bottom port break; case "MassDriverBarrelSector": searchQueue.Add(FindOffset(block.FatBlock.LocalMatrix, new Vector3I(0, 0, 2))); //front port searchQueue.Add(FindOffset(block.FatBlock.LocalMatrix, new Vector3I(0, 0, -2))); //back port break; case "MassDriverBarrelTip": searchQueue.Add(FindOffset(block.FatBlock.LocalMatrix, new Vector3I(0, 0, -2))); //back port break; default: break; } } } searchQueue.RemoveAt(0); } //count attached parts // int barrelCount = connectedBlocks.FindAll(b => b.GetObjectBuilder().SubtypeId.ToString().Contains("MassDriverBarrel")).Count; int compulsatorCount = connectedBlocks.FindAll(b => b.GetObjectBuilder().SubtypeId.ToString() == "MassDriverCapacitor").Count; //build list of connected batteries // compulsators = new List </*Sandbox.ModAPI.*/ IMyBatteryBlock>(); foreach (var batt in connectedBlocks.FindAll(b => b.GetObjectBuilder().SubtypeId.ToString() == "MassDriverCapacitor")) { compulsators.Add(batt.FatBlock as /*Sandbox.ModAPI.*/ IMyBatteryBlock); } //update custom name and info instance // MDBody.SetCustomName("Mass Driver (" + barrelCount.ToString() + "B|" + compulsatorCount.ToString() + "C)"); if (Data.Drivers.Find(d => d.Id == MDBody.EntityId) == null) //add entry for damage handler { Data.Drivers.Add(new MDInfo(MDBody.EntityId, compulsatorCount)); } else { MDInfo existingEntry = Data.Drivers.Find(d => d.Id == MDBody.EntityId); existingEntry.DamageMultiplier = compulsatorCount; } MyAPIGateway.Utilities.ShowMessage("", Data.Drivers.Count().ToString()); }