public override Construction.Placement DoPlacement(Construction.Target target) { if (!Object.op_Implicit((Object)target.entity) || !Object.op_Implicit((Object)((Component)target.entity).get_transform())) { return((Construction.Placement)null); } Vector3 worldPosition = target.GetWorldPosition(); Quaternion worldRotation = target.GetWorldRotation(true); if (this.rotationDegrees > 0) { Construction.Placement placement = new Construction.Placement(); float num1 = float.MaxValue; float num2 = 0.0f; for (int index = 0; index < 360; index += this.rotationDegrees) { Quaternion quaternion1 = Quaternion.Euler(0.0f, (float)(this.rotationOffset + index), 0.0f); Vector3 direction = ((Ray) ref target.ray).get_direction(); Quaternion quaternion2 = worldRotation; Vector3 vector3 = Quaternion.op_Multiply(Quaternion.op_Multiply(quaternion1, quaternion2), Vector3.get_up()); float num3 = Vector3.Angle(direction, vector3); if ((double)num3 < (double)num1) { num1 = num3; num2 = (float)index; } } for (int index = 0; index < 360; index += this.rotationDegrees) { Quaternion quaternion1 = Quaternion.op_Multiply(worldRotation, Quaternion.Inverse(this.rotation)); Quaternion quaternion2 = Quaternion.op_Multiply(Quaternion.op_Multiply(Quaternion.Euler(target.rotation), Quaternion.Euler(0.0f, (float)(this.rotationOffset + index) + num2, 0.0f)), quaternion1); Vector3 vector3 = Quaternion.op_Multiply(quaternion2, this.position); placement.position = Vector3.op_Subtraction(worldPosition, vector3); placement.rotation = quaternion2; if (this.CheckSocketMods(placement)) { return(placement); } } } Construction.Placement placement1 = new Construction.Placement(); Quaternion quaternion = Quaternion.op_Multiply(worldRotation, Quaternion.Inverse(this.rotation)); Vector3 vector3_1 = Quaternion.op_Multiply(quaternion, this.position); placement1.position = Vector3.op_Subtraction(worldPosition, vector3_1); placement1.rotation = quaternion; if (!this.TestRestrictedAngles(worldPosition, worldRotation, target)) { return((Construction.Placement)null); } return(placement1); }
public override Construction.Placement DoPlacement(Construction.Target target) { if (!target.entity || !target.entity.transform) { return(null); } Vector3 worldPosition = target.GetWorldPosition(); Quaternion worldRotation = target.GetWorldRotation(true); if (this.rotationDegrees > 0) { Construction.Placement placement = new Construction.Placement(); float single = Single.MaxValue; float single1 = 0f; for (int i = 0; i < 360; i += this.rotationDegrees) { Quaternion quaternion = Quaternion.Euler(0f, (float)(this.rotationOffset + i), 0f); Vector3 vector3 = target.ray.direction; Vector3 vector31 = (quaternion * worldRotation) * Vector3.up; float single2 = Vector3.Angle(vector3, vector31); if (single2 < single) { single = single2; single1 = (float)i; } } for (int j = 0; j < 360; j += this.rotationDegrees) { Quaternion quaternion1 = worldRotation * Quaternion.Inverse(this.rotation); Quaternion quaternion2 = Quaternion.Euler(target.rotation); Quaternion quaternion3 = Quaternion.Euler(0f, (float)(this.rotationOffset + j) + single1, 0f); Quaternion quaternion4 = (quaternion2 * quaternion3) * quaternion1; placement.position = worldPosition - (quaternion4 * this.position); placement.rotation = quaternion4; if (this.CheckSocketMods(placement)) { return(placement); } } } Construction.Placement placement1 = new Construction.Placement(); Quaternion quaternion5 = worldRotation * Quaternion.Inverse(this.rotation); placement1.position = worldPosition - (quaternion5 * this.position); placement1.rotation = quaternion5; if (!this.TestRestrictedAngles(worldPosition, worldRotation, target)) { return(null); } return(placement1); }
protected override bool CanConnectToEntity(Construction.Target target) { Elevator elevator; if ((object)(elevator = target.entity as Elevator) != null && elevator.Floor >= MaxFloor) { return(false); } Vector3 vector = target.GetWorldPosition(); Quaternion quaternion = target.GetWorldRotation(true); if (GamePhysics.CheckOBB(new OBB(vector, new Vector3(2f, 0.5f, 2f), quaternion), 2097152)) { return(false); } return(base.CanConnectToEntity(target)); }
private object CanBuild(Planner planner, Construction prefab, Construction.Target target) { Vector3 position = target.position.y == 0 ? target.GetWorldPosition() : target.position; //differs if youre attaching the block to an existing building or creating a new building if (planner.GetOwnerPlayer().IPlayer.HasPermission("worldshops.build")) { return(null); } KeyValuePair <WorldShopsSettings.Shop, float>[] distances = _activeShops.Select(x => new KeyValuePair <WorldShopsSettings.Shop, float>(x.Value, Vector3.Distance(x.Key.CenterPoint(), position))).ToArray(); WorldShopsSettings.Shop[] closeShops = distances.Where(x => x.Value < x.Key.BuildingBlockedDistance).OrderBy(x => x.Value).Select(x => x.Key).ToArray(); if (closeShops.Length > 0) { BasePlayer player = planner.GetOwnerPlayer(); player.ChatMessage(this.Lang("ShopTooClose", player, string.Join(", ", closeShops.Select(x => x.WorldName).ToArray()))); return(false); } return(null); }
public override Construction.Placement DoPlacement(Construction.Target target) { if (!target.entity || !target.entity.transform) { return(null); } if (!CanConnectToEntity(target)) { return(null); } ConstructionSocket constructionSocket = target.socket as ConstructionSocket; Vector3 vector = target.GetWorldPosition(); Quaternion quaternion = target.GetWorldRotation(true); if (constructionSocket != null && !IsCompatible(constructionSocket)) { return(null); } if (rotationDegrees > 0 && (constructionSocket == null || !constructionSocket.restrictPlacementRotation)) { Construction.Placement placement = new Construction.Placement(); float num = float.MaxValue; float num2 = 0f; for (int i = 0; i < 360; i += rotationDegrees) { Quaternion quaternion2 = Quaternion.Euler(0f, rotationOffset + i, 0f); Vector3 direction = target.ray.direction; Vector3 to = quaternion2 * quaternion * Vector3.up; float num3 = Vector3.Angle(direction, to); if (num3 < num) { num = num3; num2 = i; } } for (int j = 0; j < 360; j += rotationDegrees) { Quaternion quaternion3 = quaternion * Quaternion.Inverse(rotation); Quaternion quaternion4 = Quaternion.Euler(target.rotation); Quaternion quaternion5 = Quaternion.Euler(0f, (float)(rotationOffset + j) + num2, 0f); Quaternion quaternion6 = quaternion4 * quaternion5 * quaternion3; Vector3 vector2 = quaternion6 * position; placement.position = vector - vector2; placement.rotation = quaternion6; if (CheckSocketMods(placement)) { return(placement); } } } Construction.Placement placement2 = new Construction.Placement(); Quaternion quaternion7 = quaternion * Quaternion.Inverse(rotation); Vector3 vector3 = quaternion7 * position; placement2.position = vector - vector3; placement2.rotation = quaternion7; if (!TestRestrictedAngles(vector, quaternion, target)) { return(null); } return(placement2); }
object CanBuild(Planner planner, Construction prefab, Construction.Target target) { if (!constructions.ContainsKey(prefab) || constructions[prefab].CanBypass || permission.UserHasPermission(target.player.UserIDString, bypassPerm)) { return(null); } var buildPos = target.entity && target.entity.transform && target.socket ? target.GetWorldPosition() : target.position; if (target.player.IsBuildingBlocked(new OBB(buildPos, default(Quaternion), default(Bounds)))) { target.player.ChatMessage(msg("Building is blocked!", target.player.UserIDString)); return(false); } return(null); }