public void GenerateGridFromCurrentCorners() { float minX, maxX, minZ, maxZ; minX = maxX = this.gridCorners[0].x; minZ = maxZ = this.gridCorners[0].y; for (int i = 0; i < this.gridCorners.Length; i++) { if (this.gridCorners [i].x < minX) { minX = this.gridCorners [i].x; } if (this.gridCorners [i].x > maxX) { maxX = this.gridCorners [i].x; } if (this.gridCorners [i].y < minZ) { minZ = this.gridCorners [i].y; } if (this.gridCorners [i].y > maxZ) { maxZ = this.gridCorners [i].y; } } zone = new RectZone(minX, minZ, maxX, maxZ, this.tileSize); }
void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitinfo) { bool blockDamage = false; foreach (GameObject zone in currentZones) { RectZone zoneComponent = zone.GetComponent <RectZone>(); if ((entity is BuildingBlock && zoneComponent.Definition.Options.ContainsKey("nodestroy")) || (entity is BasePlayer && (hitinfo.Initiator is BasePlayer || hitinfo.Initiator is FireBall) && zoneComponent.Definition.Options.ContainsKey("nopvp"))) { if (zoneComponent.GetComponent <Collider>().bounds.Contains(entity.transform.position)) { blockDamage = true; break; } } } if (blockDamage) { hitinfo.damageTypes = new Rust.DamageTypeList(); hitinfo.DoHitEffects = false; hitinfo.HitMaterial = 0; } }
void CreateZoneByDefinition(ZoneDefinition definition) { GameObject zoneObject = new GameObject(GameObjectPrefix + definition.Id); RectZone zoneComponent = zoneObject.AddComponent <RectZone>(); zoneComponent.SetZone(definition); currentZones.Add(zoneObject); }
void OnPlayerDisconnected(BasePlayer player, string reason) { foreach (GameObject zone in currentZones) { RectZone zoneComponent = zone.GetComponent <RectZone>(); zoneComponent.Players.Remove(player); } if (isEditing) { tempPlayers.RemoveAll(x => x.Player.userID == player.userID); } }
RectZone GetCurrentZoneForPlayer(BasePlayer player) { foreach (GameObject zone in currentZones) { RectZone zoneComponent = zone.GetComponent <RectZone>(); if (zoneComponent.Players.Contains(player)) { return(zoneComponent); } } return(null); }
public BidKnowledge(RectZone zone, Sender sender, int myId, KnowledgeBase kb) { openTiles = new ArrayList(); foreach (Tile tile in zone.tiles) { openTiles.Add(new SearchTile(tile.GetID(), tile.GetCenter())); numTiles++; } tilesInAuction = new ArrayList(); claimedTiles = new ArrayList(); searchedTiles = new ArrayList(); this.sender = sender; this.myId = myId; this.kb = kb; }
private Direction[] GetNearbyCells(Point point, Func <CellColor, bool> test) { var fieldZone = new RectZone(0, 0, width, height); var nearby = new List <Direction>(); foreach (var d in directions) { var p = point.Move(d.offset.X, d.offset.Y); if (fieldZone.Contains(p) && (field[point.Y, point.X] & d.wall) == Wall.None && test(colors[p.Y, p.X])) { nearby.Add(d); } } return(nearby.ToArray()); }
// ----------------- For options ----------------- // ----------------------------------------------- void OnEntityBuilt(Planner plan, GameObject go) { foreach (GameObject zone in currentZones) { RectZone zoneComponent = zone.GetComponent <RectZone>(); if (zoneComponent.Players.Count == 0) { continue; } if (zoneComponent.Definition.Options.ContainsKey("nobuild")) { if (zoneComponent.GetComponent <Collider>().bounds.Contains(go.transform.position)) { go.GetComponentInParent <BaseCombatEntity>().Kill(BaseNetworkable.DestroyMode.Gib); if (zoneComponent.Definition.Options["nobuild"] != null) { plan.GetOwnerPlayer().ChatMessage(zoneComponent.Definition.Options["nobuild"]); } break; } } else if (zoneComponent.Definition.Options.ContainsKey("nobuildex")) { if (zoneComponent.GetComponent <Collider>().bounds.Contains(go.transform.position)) { go.GetComponentInParent <BaseCombatEntity>().Kill(BaseNetworkable.DestroyMode.Gib); if (zoneComponent.Definition.Options["nobuildex"] != null) { plan.GetOwnerPlayer().ChatMessage(zoneComponent.Definition.Options["nobuildex"]); } break; } } } }
void OnEntitySpawned(BaseNetworkable entity) { if (!(entity is BuildingBlock)) { return; } BuildingBlock block = (BuildingBlock)entity; foreach (GameObject zone in currentZones) { RectZone zoneComponent = zone.GetComponent <RectZone>(); if (zoneComponent.Definition.Options.ContainsKey("nostability")) { if (zoneComponent.GetComponent <Collider>().bounds.Contains(block.transform.position)) { block.grounded = true; } } } }
public static void EndTrial() { trialOngoing = false; TrialRunner.GetSingletonInstance().EndTrial(); Debug.Log("Trial Ending with time: " + timeElapsed); Debug.Log("Sustained " + numberOfCollisions + " collisions"); // If any agents exist destroy them foreach (Agent a in currentAgents) { Destroy(a.gameObject); } if (zone != null) { zone.DestroyTiles(); zone.CleanUp(); zone = null; } currentAgents.Clear(); foreach (Packet p in packetQueue) { p.CleanUp(); } packetQueue.Clear(); foreach (Packet p in packets) { p.CleanUp(); } packets.Clear(); //Callback to trial runner TrialRunner.GetSingletonInstance().LaunchNextTrial(); }
void cmdChat(BasePlayer player, string command, string[] args) { if (!IsPlayerPermitted(player, PermissionName)) { return; } int length = args.Length; chatHelper.Run(args, () => { player.ChatMessage(Lang("HelpText", player)); }); chatHelper.OnCommand("add", () => { if (CheckIsEditing(player) != null) { player.ChatMessage(Lang("AlreadyEditing", player)); return; } if (chatHelper.NextExists()) { float height = 0.0f; if (float.TryParse(chatHelper.Next(), out height)) { if (chatHelper.NextExists()) { if (chatHelper.Next().Equals("fixed", StringComparison.CurrentCultureIgnoreCase)) { if (chatHelper.NextExists()) // with height, "fixed" and name { CommandAdd(player, height, chatHelper.Next(), true); } else // with height and "fixed" { CommandAdd(player, height, null, true); } } else // with height and name { CommandAdd(player, height, chatHelper.Current()); } } else // with only height { CommandAdd(player, height); } } else { player.ChatMessage(Lang("HeightMustBeNumber", player)); } } else { player.ChatMessage(Lang("InvalidAddCommand", player)); } }); chatHelper.OnCommand("done", () => { TemporaryStorage storage = CheckIsEditing(player); if (storage != null) { if (storage.Zone.Vertices.Count < MinPoints || storage.Zone.Vertices.Count > MaxPoints) { player.ChatMessage(Lang("DonePointsCount", player)); return; } CommandDone(player); player.ChatMessage(Lang("Done", player).Replace("{id}", storage.Zone.Id).Replace("{name}", storage.Zone.Name)); } }); chatHelper.OnCommand("undo", () => { TemporaryStorage storage = CheckIsEditing(player); if (storage != null) { if (storage.Zone.Vertices.Count != 0) { storage.Zone.Vertices.RemoveRange(storage.Zone.Vertices.Count - 2, 2); player.ChatMessage(Lang("UndoComplete", player)); } } }); chatHelper.OnCommand("remove", () => { if (CheckIsEditing(player) != null) { player.ChatMessage(Lang("AlreadyEditing", player)); return; } if (chatHelper.NextExists()) { if (IsDigitsOnly(chatHelper.Next())) { int removed = data.Zones.RemoveWhere(x => x.Id == chatHelper.Current()); if (removed <= 0) { player.ChatMessage(Lang("ZoneNotFound", player)); return; } currentZones.RemoveWhere((GameObject go) => { RectZone rz = go.GetComponent <RectZone>(); if (rz.Definition.Id == chatHelper.Current()) { GameObject.Destroy(go); return(true); } return(false); }); SaveData(); player.ChatMessage(Lang("Removed", player)); } else { int removed = data.Zones.RemoveWhere((ZoneDefinition x) => { if (x.Name == null) { return(false); } return(x.Name.Equals(chatHelper.Current(), StringComparison.CurrentCultureIgnoreCase)); }); if (removed <= 0) { player.ChatMessage(Lang("ZoneNotFound", player)); return; } currentZones.RemoveWhere((GameObject go) => { RectZone rz = go.GetComponent <RectZone>(); if (rz.Definition.Name.Equals(chatHelper.Current(), StringComparison.CurrentCultureIgnoreCase)) { GameObject.Destroy(go); return(true); } return(false); }); SaveData(); player.ChatMessage(Lang("Removed", player)); } } else { player.ChatMessage(Lang("RemoveHelp", player)); } }); chatHelper.OnCommand("list", () => { if (data.Zones.Count == 0) { player.ChatMessage(Lang("Empty", player)); return; } string result = Lang("List", player); foreach (ZoneDefinition zd in data.Zones) { result += zd.Id + (zd.Name != null ? (" (" + zd.Name + ")") : "") + ", "; } player.ChatMessage(result.Substring(0, result.Length - 2)); }); chatHelper.OnCommand("edit", () => { if (CheckIsEditing(player) != null) { player.ChatMessage(Lang("AlreadyEditing", player)); return; } if (args.Length > 1 && IsDigitsOnly(args[1])) { // TODO: editing } }); chatHelper.OnCommand("options", () => { TemporaryStorage storage = CheckIsEditing(player); if (storage == null) { if (chatHelper.NextExists()) { string id = chatHelper.Next(); if (IsDigitsOnly(id)) { ZoneDefinition definition = null; foreach (ZoneDefinition d in data.Zones) { if (d.Id == id) { definition = d; break; } } if (definition == null) { player.ChatMessage(Lang("ZoneNotFound", player)); return; } if (definition.Options.Count == 0) { player.ChatMessage(Lang("NoOptions", player)); return; } string result = string.Empty; foreach (KeyValuePair <string, string> option in definition.Options) { result += option.Key + (option.Value != null ? (" = " + option.Value) : "") + ", "; } player.ChatMessage(result.Substring(0, result.Length - 2)); } else { player.ChatMessage(Lang("OptionsHelp", player)); } } else { string result = string.Empty; foreach (KeyValuePair <string, string> option in availableOptions) { result += "<color=#ffa500ff>" + option.Key + "</color> - " + (option.Value ?? "No description") + "\n"; } player.ChatMessage(result); } } else { if (chatHelper.NextExists()) { if (chatHelper.Next() == "list") { string result = string.Empty; foreach (KeyValuePair <string, string> option in availableOptions) { result += "<color=#ffa500ff>" + option.Key + "</color> - " + (option.Value ?? "No description") + "\n"; } player.ChatMessage(result); return; } for (int i = 1; i < args.Length; i++) { string[] option = args[i].Split(new char[] { '=' }, 2); storage.Zone.Options.Add(option[0], (option.Length > 1 ? option[1] : null)); } } else { if (storage.Zone.Options.Count != 0) { string result = string.Empty; foreach (KeyValuePair <string, string> option in storage.Zone.Options) { result += option.Key + " = " + option.Value + ", \n"; } player.ChatMessage(result.Substring(0, result.Length - 2)); } else { player.ChatMessage(Lang("NoOptions", player)); } } } }); chatHelper.OnCommand("show", () => { if (chatHelper.NextExists() && IsDigitsOnly(chatHelper.Next())) { foreach (GameObject zone in currentZones) { RectZone component = zone.GetComponent <RectZone>(); if (component.Definition.Id == chatHelper.Current()) { component.ShowZone(player, 10f); return; } } player.ChatMessage(Lang("ZoneNotFound", player)); } else if (chatHelper.Current().Equals("current", StringComparison.CurrentCultureIgnoreCase)) { RectZone zone = GetCurrentZoneForPlayer(player); zone.ShowZone(player, 10f); } else { if (currentZones.Count == 0) { player.ChatMessage(Lang("ShowEmpty", player)); return; } foreach (GameObject zone in currentZones) { zone.GetComponent <RectZone>().ShowZone(player, 10f); } } }); chatHelper.OnCommand("current", () => { RectZone zone = GetCurrentZoneForPlayer(player); if (zone != null) { player.ChatMessage(Lang("CurrentZone", player).Replace("{id}", zone.Definition.Id)); } else { player.ChatMessage(Lang("CurrentZoneNoZone", player)); } }); chatHelper.OnCommand("clear", () => { foreach (GameObject zone in currentZones) { GameObject.Destroy(zone); } currentZones.Clear(); data.Zones.Clear(); SaveData(); player.ChatMessage(Lang("Cleared", player)); }); }
public void CheckSymmetry(int width, int height, int left, int top, int rw, int rh) { var mazeGenerator = new MazeGeneratorMock(); var field = mazeGenerator.CreateFieldWrapper(width, height); var seed = DateTime.Now.Millisecond; TestContext.WriteLine($"seed: {seed}"); var winZone = new RectZone(left, top, rw, rh); mazeGenerator.GenerateWaysWrapper(field, winZone, new Random(seed)); for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { Wall cell = field[y, x]; if (winZone.Contains(new Point(x, y)) == false) { Assert.That(cell, Is.Not.EqualTo(Wall.Full)); } Wall symmetryCell = field[height - y - 1, width - x - 1]; if ((cell & Wall.Top) == Wall.Top && (symmetryCell & Wall.Bottom) == Wall.Bottom) { Assert.That(symmetryCell & Wall.Bottom, Is.EqualTo(Wall.Bottom)); } else { Assert.That(symmetryCell & Wall.Bottom, Is.EqualTo(Wall.None)); } if ((cell & Wall.Bottom) == Wall.Bottom) { Assert.That(symmetryCell & Wall.Top, Is.EqualTo(Wall.Top)); } else { Assert.That(symmetryCell & Wall.Top, Is.EqualTo(Wall.None)); } if ((cell & Wall.Left) == Wall.Left) { Assert.That(symmetryCell & Wall.Right, Is.EqualTo(Wall.Right)); } else { Assert.That(symmetryCell & Wall.Right, Is.EqualTo(Wall.None)); } if ((cell & Wall.Right) == Wall.Right) { Assert.That(symmetryCell & Wall.Left, Is.EqualTo(Wall.Left)); } else { Assert.That(symmetryCell & Wall.Left, Is.EqualTo(Wall.None)); } } } }
public void GenerateWaysWrapper(Wall[,] field, RectZone winZone, Random random) { GenerateWays(field, winZone, random); }
public void EraseWinZoneWrapper(Wall[,] field, RectZone winZone) { EraseWinZone(field, winZone); }
public void RunTrial() { trialOngoing = true; taskCompleted = false; /* * Reset agents and other stuff */ //Reset collisions for this run numberOfCollisions = 0; timeElapsed = 0.0f; numberOfTilesSearched = 0; // If any agents exist destroy them foreach (Agent a in currentAgents) { Destroy(a.gameObject); } currentAgents.Clear(); foreach (Packet p in packetQueue) { p.CleanUp(); } packetQueue.Clear(); foreach (Packet p in packets) { p.CleanUp(); } packets.Clear(); if (zone != null) { zone.DestroyTiles(); zone.CleanUp(); zone = null; } GenerateGridFromCurrentCorners(); // Debug.Log ("Packetqueue Count: " +packetQueue.Count); // Debug.Log ("Packets Count: " + packets.Count); /* * Spawn agents and necesssary things */ // TODO: change starting positions such that they take off and maybe so they're actually on the base station int j = 0; for (int i = 0; i < AgentsToGenerate; i++) { Vector3 pos = this.transform.position; if (i % 2 == 0) { j++; } pos.y += (i % 2) * 100 + 300; pos.x += j * 50; pos.z += j * 50; GameObject go = Instantiate(agentPrefab, pos, Quaternion.Euler(0, 180, 0)) as GameObject; go.GetComponent <Agent>().ID = i; } }
void Init() { LoadData(); permission.RegisterPermission(PluginPermission, this); cmdr = new Commander(/*PlayerHasPermission*/); cmdr.Add(null, null, (player, args) => { player.ChatMessage(Lang("HelpText", player)); }); cmdr.Add("add", null, (player, args) => { if (CheckIsEditing(player) != null) { player.ChatMessage(Lang("AlreadyEditing", player)); return; } if (args["height"].Value == null) { player.ChatMessage(Lang("InvalidAddCommand", player)); return; } if (args["height"].IsInvalid) { player.ChatMessage(Lang("HeightMustBeNumber", player)); return; } if (args.Count == 1) { CommandAdd(player, args["height"].Get <float>()); return; } if (args["fixed"].String == "fixed") { if (args["name"].Value == null) { CommandAdd(player, args["height"].Single, null, true); } else { CommandAdd(player, args["height"].Single, args["name"].String, true); } } else { CommandAdd(player, args["height"].Single, args["fixed"].String); } }).AddParam("height", Commander.ParamType.Float) .AddParam("fixed") .AddParam("name"); cmdr.Add("finish", null, (player, args) => { TemporaryStorage storage = CheckIsEditing(player); if (storage != null) { if (storage.Zone.Vertices.Count < MinPoints || storage.Zone.Vertices.Count > MaxPoints) { player.ChatMessage(Lang("DonePointsCount", player)); return; } CommandFinish(player); player.ChatMessage(Lang("Done", player).Replace("{id}", storage.Zone.Id).Replace("{name}", storage.Zone.Name)); } }); cmdr.Add("undo", null, (player, args) => { TemporaryStorage storage = CheckIsEditing(player); if (storage != null) { if (storage.Zone.Vertices.Count != 0) { storage.Zone.Vertices.RemoveRange(storage.Zone.Vertices.Count - 2, 2); player.ChatMessage(Lang("UndoComplete", player)); } } }); cmdr.Add("list", null, (player, args) => { if (data.Zones.Count == 0) { player.ChatMessage(Lang("Empty", player)); return; } var result = new StringBuilder(Lang("List", player).Length); result.Append(Lang("List", player)); foreach (ZoneDefinition zd in data.Zones) { result.Append(zd.Id + (zd.Name != null ? (" (" + zd.Name + ")") : "") + ", "); } player.ChatMessage(result.Remove(result.Length - 2, 2).ToString()); }); cmdr.Add("current", null, (player, args) => { RectZone zone = GetCurrentZoneForPlayer(player); if (zone != null) { player.ChatMessage(Lang("CurrentZone", player).Replace("{id}", zone.Definition.Id)); } else { player.ChatMessage(Lang("CurrentZoneNoZone", player)); } }); cmdr.Add("clear", null, (player, args) => { foreach (GameObject zone in currentZones) { GameObject.Destroy(zone); } currentZones.Clear(); data.Zones.Clear(); player.ChatMessage(Lang("Cleared", player)); }); cmdr.Add("show", null, (player, args) => // TODO show by name { if (args["id"].Value != null) { if (args["id"].String.Equals("current", StringComparison.CurrentCultureIgnoreCase)) { RectZone zone = GetCurrentZoneForPlayer(player); zone.ShowZone(player, 10f); } else { var zone = currentZones.First((z) => z.GetComponent <RectZone>().Definition.Id.Equals(args["id"].String)); if (zone != null) { zone.GetComponent <RectZone>().ShowZone(player, 10f); } else { player.ChatMessage(Lang("ZoneNotFound", player)); } } } else { if (currentZones.Count == 0) { player.ChatMessage(Lang("ShowEmpty", player)); return; } foreach (GameObject zone in currentZones) { zone.GetComponent <RectZone>().ShowZone(player, 10f); } } }).AddParam("id"); cmdr.Add("remove", null, (player, args) => { if (CheckIsEditing(player) != null) { player.ChatMessage(Lang("AlreadyEditing", player)); return; } if (args["nameOrId"].Value != null) { if (IsDigitsOnly(args["nameOrId"].String)) { int removed = data.Zones.RemoveWhere(x => x.Id == args["nameOrId"].String); if (removed <= 0) { player.ChatMessage(Lang("ZoneNotFound", player)); return; } currentZones.RemoveWhere((GameObject go) => { RectZone rz = go.GetComponent <RectZone>(); if (rz.Definition.Id == args["nameOrId"].String) { GameObject.Destroy(go); return(true); } return(false); }); player.ChatMessage(Lang("Removed", player)); } else { int removed = data.Zones.RemoveWhere((ZoneDefinition x) => { if (x.Name == null) { return(false); } return(x.Name.Equals(args["nameOrId"].String, StringComparison.CurrentCultureIgnoreCase)); }); if (removed <= 0) { player.ChatMessage(Lang("ZoneNotFound", player)); return; } currentZones.RemoveWhere((GameObject go) => { RectZone rz = go.GetComponent <RectZone>(); if (rz.Definition.Name.Equals(args["nameOrId"].String, StringComparison.CurrentCultureIgnoreCase)) { GameObject.Destroy(go); return(true); } return(false); }); player.ChatMessage(Lang("Removed", player)); } } else { player.ChatMessage(Lang("RemoveHelp", player)); } }).AddParam("nameOrId"); cmdr.Add("options", null, (player, args) => { TemporaryStorage storage = CheckIsEditing(player); if (storage == null) { if (args["command"].Value != null) { if (IsDigitsOnly(args["command"].String)) { ZoneDefinition definition = null; foreach (ZoneDefinition d in data.Zones) { if (d.Id == args["command"].String) { definition = d; break; } } if (definition == null) { player.ChatMessage(Lang("ZoneNotFound", player)); return; } if (definition.Options.Count == 0) { player.ChatMessage(Lang("NoOptions", player)); return; } string result = string.Empty; foreach (KeyValuePair <string, string> option in definition.Options) { result += option.Key + (option.Value != null ? (" = " + option.Value) : "") + ", "; } player.ChatMessage(result.Substring(0, result.Length - 2)); } else { player.ChatMessage(Lang("OptionsHelp", player)); } } else { string result = string.Empty; foreach (KeyValuePair <string, string> option in availableOptions) { result += "<color=#ffa500ff>" + option.Key + "</color> - " + (option.Value ?? "No description") + "\n"; } player.ChatMessage(result); } } else { if (args["command"].Value != null) { if (args["command"].String == "list") { string result = string.Empty; foreach (KeyValuePair <string, string> option in availableOptions) { result += "<color=#ffa500ff>" + option.Key + "</color> - " + (option.Value ?? "") + "\n"; } player.ChatMessage(result); return; } string[] opts = args["command"].String.Split(' '); for (int i = 1; i < opts.Length; i++) { string[] option = opts[i].Split(new char[] { '=' }, 2); storage.Zone.Options.Add(option[0], (option.Length > 1 ? option[1] : null)); } } else { if (storage.Zone.Options.Count != 0) { string result = string.Empty; foreach (KeyValuePair <string, string> option in storage.Zone.Options) { result += option.Key + " = " + option.Value + ", \n"; } player.ChatMessage(result.Substring(0, result.Length - 2)); } else { player.ChatMessage(Lang("NoOptions", player)); } } } }).AddParam("command", Commander.ParamType.String, true); }