本文整理汇总了C#中ZACommons.GetBlockGroupsWithPrefix方法的典型用法代码示例。如果您正苦于以下问题:C# ZACommons.GetBlockGroupsWithPrefix方法的具体用法?C# ZACommons.GetBlockGroupsWithPrefix怎么用?C# ZACommons.GetBlockGroupsWithPrefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZACommons
的用法示例。
在下文中一共展示了ZACommons.GetBlockGroupsWithPrefix方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public void Run(ZACommons commons, EventDriver eventDriver)
{
var groups = commons.GetBlockGroupsWithPrefix(SIMPLE_AIRLOCK_GROUP_PREFIX);
for (var e = groups.GetEnumerator(); e.MoveNext();)
{
var doors = ZACommons.GetBlocksOfType<IMyDoor>(e.Current.Blocks,
door => door.CubeGrid == commons.Me.CubeGrid &&
door.IsFunctional);
var opened = IsAnyDoorOpen(doors);
for (var f = doors.GetEnumerator(); f.MoveNext();)
{
var door = (IMyDoor)f.Current;
if (door.OpenRatio == 0.0f && opened)
{
// This door is not open and some other door in the group is, lock it down
if (door.Enabled) door.SetValue<bool>("OnOff", false);
}
else
{
if (!door.Enabled) door.SetValue<bool>("OnOff", true);
}
}
}
eventDriver.Schedule(RunDelay, Run);
}
示例2: Run
public void Run(ZACommons commons, EventDriver eventDriver)
{
var groups = commons.GetBlockGroupsWithPrefix(DOOR_AUTO_CLOSER_PREFIX);
if (groups.Count > 0)
{
groups.ForEach(group => {
// Determine open duration
var parts = group.Name.Split(new char[] { DURATION_DELIMITER }, 2);
var duration = DEFAULT_DOOR_OPEN_DURATION;
if (parts.Length == 2)
{
if (!double.TryParse(parts[1], out duration))
{
duration = DEFAULT_DOOR_OPEN_DURATION;
}
}
var doors = ZACommons.GetBlocksOfType<IMyDoor>(group.Blocks,
block => block.IsFunctional);
CloseDoors(commons, eventDriver, doors, duration);
});
}
else
{
// Default behavior (all doors except vanilla Airtight Hangar Doors and tagged doors)
var doors = ZACommons
.GetBlocksOfType<IMyDoor>(commons.Blocks,
block => block.IsFunctional &&
block.CustomName.IndexOf("[Excluded]", ZACommons.IGNORE_CASE) < 0 &&
block.DefinitionDisplayNameText != "Airtight Hangar Door");
CloseDoors(commons, eventDriver, doors, DEFAULT_DOOR_OPEN_DURATION);
}
eventDriver.Schedule(RunDelay, Run);
}
示例3: Run
public void Run(ZACommons commons, EventDriver eventDriver)
{
if (!Active) return;
TotalPower = 0.0f;
var solarGroups = commons.GetBlockGroupsWithPrefix(MAX_POWER_GROUP_PREFIX);
for (var e = solarGroups.GetEnumerator(); e.MoveNext();)
{
var group = e.Current;
var rotor = GetRotor(group);
if (rotor == null)
{
commons.Echo(string.Format("Group {0} ignored; needs exactly 1 rotor", group.Name));
continue;
}
else if (rotor.CubeGrid != commons.Me.CubeGrid)
{
// Skip if rotor is on a different grid than this programmable block
continue;
}
var solarPanelDetails = new SolarPanelDetails(group);
var currentMaxPower = solarPanelDetails.MaxPowerOutput;
float maxPower;
if (!MaxPowers.TryGetValue(group.Name, out maxPower)) maxPower = -100.0f;
var minError = solarPanelDetails.DefinedPowerOutput * SOLAR_ROTOR_MIN_ERROR;
var delta = currentMaxPower - maxPower;
MaxPowers[group.Name] = currentMaxPower;
if (delta > minError || currentMaxPower < minError /* failsafe */)
{
// Keep going
rotor.SetValue<bool>("OnOff", true);
}
else if (delta < -minError)
{
// Back up
rotor.SetValue<bool>("OnOff", true);
rotor.ApplyAction("Reverse");
}
else
{
// Hold still for a moment
rotor.SetValue<bool>("OnOff", false);
}
TotalPower += currentMaxPower;
}
eventDriver.Schedule(RunDelay, Run);
}
示例4: Run
public void Run(ZACommons commons)
{
for (var e = commons.GetBlockGroupsWithPrefix(REDUNDANCY_PREFIX).GetEnumerator(); e.MoveNext();)
{
var group = e.Current;
// Figure out how many to maintain
var parts = group.Name.Split(new char[] { COUNT_DELIMITER }, 2);
var count = 1;
if (parts.Length == 2)
{
if (int.TryParse(parts[1], out count))
{
count = Math.Max(count, 1);
}
else
{
count = 1;
}
}
var running = 0;
var spares = new LinkedList<IMyTerminalBlock>();
for (var f = group.Blocks.GetEnumerator(); f.MoveNext();)
{
var block = f.Current as IMyFunctionalBlock;
if (block != null && block.CubeGrid == commons.Me.CubeGrid &&
block.IsFunctional)
{
if (block.IsWorking && block.Enabled)
{
running++;
}
else
{
spares.AddLast(block);
}
}
}
while (running < count && spares.First != null)
{
var block = spares.First.Value;
spares.RemoveFirst();
block.SetValue<bool>("OnOff", true);
running++;
}
}
}
示例5: Run
public void Run(ZACommons commons, EventDriver eventDriver)
{
for (var e = commons.GetBlockGroupsWithPrefix(DOCKING_ACTION_PREFIX).GetEnumerator(); e.MoveNext();)
{
var group = e.Current;
// Figure out action
var parts = group.Name.Split(new char[] { ACTION_DELIMETER }, 2);
string action = "on";
if (parts.Length == 2)
{
action = parts[1];
}
// Determine state of first connector (should only have 1)
bool connected = false;
var connectors = ZACommons.GetBlocksOfType<IMyShipConnector>(group.Blocks);
if (connectors.Count > 0)
{
var connector = (IMyShipConnector)connectors[0];
connected = connector.IsLocked && connector.IsConnected;
}
if ("on".Equals(action, ZACommons.IGNORE_CASE) ||
"off".Equals(action, ZACommons.IGNORE_CASE))
{
bool enable;
if ("on".Equals(action, ZACommons.IGNORE_CASE))
{
enable = connected;
}
else
{
enable = !connected;
}
// Set state according to action
group.Blocks.ForEach(block =>
{
if (!(block is IMyShipConnector)) // ignore connectors
{
block.SetValue<bool>("OnOff", enable);
}
});
}
// Ignore anything else for now
}
eventDriver.Schedule(RunDelay, Run);
}
示例6: Init
private void Init(ZACommons commons)
{
var groups = commons.GetBlockGroupsWithPrefix("Airlock");
// Classify each group
for (var e = groups.GetEnumerator(); e.MoveNext();)
{
var group = e.Current;
if (string.Equals("AirlockDoorInner", group.Name, ZACommons.IGNORE_CASE))
{
innerDoors.UnionWith(ToDoors(ZACommons.GetBlocksOfType<IMyDoor>(group.Blocks)));
}
else if (string.Equals("AirlockDoorSpace", group.Name, ZACommons.IGNORE_CASE))
{
spaceDoors.UnionWith(ToDoors(ZACommons.GetBlocksOfType<IMyDoor>(group.Blocks)));
}
else if (group.Name.StartsWith("AirlockDoor", ZACommons.IGNORE_CASE))
{
doorVentGroups.Add(group.Name, group);
var vents = ToVents(ZACommons.GetBlocksOfType<IMyAirVent>(group.Blocks));
var doors = ToDoors(ZACommons.GetBlocksOfType<IMyDoor>(group.Blocks));
for (var f = doors.GetEnumerator(); f.MoveNext();)
{
doorVentMap.Add(f.Current, vents);
}
}
else
{
rooms.Add(group);
roomsMap.Add(group.Name, group);
var doors = ToDoors(ZACommons.GetBlocksOfType<IMyDoor>(group.Blocks));
for (var f = doors.GetEnumerator(); f.MoveNext();)
{
doorVentRooms.Add(f.Current, group);
}
}
}
}
示例7: GetProjector
private static IMyProjector GetProjector(ZACommons commons, string name,
out string rest)
{
var groupPrefix = PROJECTOR_ACTION_PREFIX + name + ACTION_DELIMITER;
var groups = commons.GetBlockGroupsWithPrefix(groupPrefix);
if (groups.Count > 0)
{
var blocks = ZACommons.GetBlocksOfType<IMyProjector>(groups[0].Blocks);
for (var e = blocks.GetEnumerator(); e.MoveNext();)
{
var block = e.Current;
// Just take first one
if (block.IsFunctional)
{
rest = groups[0].Name.Substring(groupPrefix.Length);
return (IMyProjector)blocks[0];
}
}
}
rest = default(string);
return null;
}
示例8: DoActions
private void DoActions(ZACommons commons, EventDriver eventDriver,
double currentSpeed)
{
for (var e = commons.GetBlockGroupsWithPrefix(SPEED_ACTION_PREFIX).GetEnumerator(); e.MoveNext();)
{
var group = e.Current;
// Break it up and parse each part
var parts = group.Name.Split(new char[] { ACTION_DELIMETER }, 3);
if (parts.Length < 2) continue; // Need at least speed
double speed;
if (!double.TryParse(parts[1], out speed)) continue; // And it needs to be parsable
string action = "on";
if (parts.Length == 3)
{
action = parts[2];
}
var rising = false;
var falling = false;
switch (action[0])
{
case '>':
rising = true;
action = action.Substring(1);
break;
case '<':
falling = true;
action = action.Substring(1);
break;
}
var onFlag = "on".Equals(action, ZACommons.IGNORE_CASE);
var offFlag = "off".Equals(action, ZACommons.IGNORE_CASE);
if (onFlag || offFlag)
{
if (!rising && !falling)
{
bool enable;
if (onFlag)
{
enable = currentSpeed >= speed;
}
else
{
enable = currentSpeed < speed;
}
group.Blocks.ForEach(block =>
block.SetValue<bool>("OnOff", enable));
}
else if ((rising && LastSpeed < speed && currentSpeed >= speed) ||
(falling && LastSpeed >= speed && currentSpeed < speed))
{
group.Blocks.ForEach(block =>
block.SetValue<bool>("OnOff", onFlag));
}
}
}
}
示例9: _Run
private void _Run(ZACommons commons, EventDriver eventDriver)
{
// No source, don't bother
var stockGroup = commons.GetBlockGroupWithName(STOCKER_SOURCE_NAME);
if (stockGroup == null) return;
var toCheck = new Dictionary<IMyTerminalBlock, Dictionary<string, int>>();
for (var e = commons.GetBlockGroupsWithPrefix(STOCKER_PREFIX).GetEnumerator(); e.MoveNext();)
{
var group = e.Current;
if (group.Name == STOCKER_SOURCE_NAME) continue;
// Determine count
var parts = group.Name.Split(new char[] { COUNT_DELIMITER }, 2);
var count = 1;
if (parts.Length == 2)
{
if (int.TryParse(parts[1], out count))
{
count = Math.Max(count, 1);
}
else
{
count = 1;
}
}
// Determine SubtypeName
var subtypeName = parts[0].Substring(STOCKER_PREFIX.Length).Trim();
if (subtypeName.Length == 0) continue;
// Gather destinations and wanted subtypes/counts
group.Blocks.ForEach(block => {
if (!block.IsFunctional || block.GetInventoryCount() == 0) return;
Dictionary<string, int> wantedStocks;
if (!toCheck.TryGetValue(block, out wantedStocks))
{
wantedStocks = new Dictionary<string, int>();
toCheck.Add(block, wantedStocks);
}
int wanted;
if (wantedStocks.TryGetValue(subtypeName, out wanted))
{
// Use biggest request
wanted = Math.Max(wanted, count);
}
else
{
wanted = count;
}
wantedStocks[subtypeName] = wanted;
});
}
// Determine how many are missing from all destinations
var missingStocks = new Dictionary<string, LinkedList<MissingStock>>();
for (var e = toCheck.GetEnumerator(); e.MoveNext();)
{
var block = e.Current.Key;
var wantedStocks = e.Current.Value;
// Gather current item counts
var currents = new Dictionary<string, VRage.MyFixedPoint>();
for (int i = 0; i < block.GetInventoryCount(); i++)
{
var inventory = block.GetInventory(i);
var items = inventory.GetItems();
items.ForEach(item => {
// Only care about wanted items for this block
var subtypeName = item.Content.SubtypeName;
if (wantedStocks.ContainsKey(subtypeName))
{
VRage.MyFixedPoint current;
if (!currents.TryGetValue(subtypeName, out current))
{
current = (VRage.MyFixedPoint)0.0f;
}
current += item.Amount;
currents[subtypeName] = current;
}
});
}
// Now figure out what's missing
for (var f = wantedStocks.GetEnumerator(); f.MoveNext();)
{
var subtypeName = f.Current.Key;
var count = f.Current.Value;
VRage.MyFixedPoint current;
if (!currents.TryGetValue(subtypeName, out current))
{
current = (VRage.MyFixedPoint)0.0f;
}
//.........这里部分代码省略.........
示例10: HandleCommand
public void HandleCommand(ZACommons commons, EventDriver eventDriver,
string argument)
{
// Handle commands
argument = argument.Trim().ToLower();
if (argument == "pause")
{
Active = false;
SaveActive(commons);
var solarGroups = commons.GetBlockGroupsWithPrefix(MAX_POWER_GROUP_PREFIX);
solarGroups.ForEach(group => {
var rotor = GetRotor(group);
if (rotor != null) rotor.SetValue<bool>("OnOff", false);
});
}
else if (argument == "resume")
{
if (!Active) Init(commons, eventDriver);
}
}