Skip to content

Commit

Permalink
disable character collision damage within ring, better ring orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
InvalidArgument3 committed Jul 23, 2024
1 parent 275fba5 commit 6970fbd
Showing 1 changed file with 38 additions and 39 deletions.
77 changes: 38 additions & 39 deletions Layman's SafeZone/Data/Scripts/bob/bobzone_activemeasures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public override void UpdateBeforeSimulation()
{
if (MyIDModule.GetRelationPlayerBlock(zoneblock.OwnerId, player.Identity.IdentityId) == MyRelationsBetweenPlayerAndBlock.Enemies)
{
character.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, Vector3D.Normalize(character.WorldMatrix.Translation - zoneblock.WorldMatrix.Translation) * 1000 * character.Physics.Mass, null, null, applyImmediately: true);
//character.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, Vector3D.Normalize(character.WorldMatrix.Translation - zoneblock.WorldMatrix.Translation) * 1000 * character.Physics.Mass, null, null, applyImmediately: true);
}
MyVisualScriptLogicProvider.SetPlayersHydrogenLevel(player.Identity.IdentityId, 1f);

Expand All @@ -114,7 +114,7 @@ public override void UpdateBeforeSimulation()
var sphere = new BoundingSphereD(zoneblock.WorldMatrix.Translation, radius);
if (grid.WorldAABB.Intersects(ref sphere))
{
grid.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, Vector3D.Normalize(grid.Physics.CenterOfMassWorld - zoneblock.WorldMatrix.Translation) * 1000 * grid.Physics.Mass, null, null, applyImmediately: true);
//grid.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, Vector3D.Normalize(grid.Physics.CenterOfMassWorld - zoneblock.WorldMatrix.Translation) * 1000 * grid.Physics.Mass, null, null, applyImmediately: true);
}
}

Expand All @@ -123,8 +123,30 @@ public override void UpdateBeforeSimulation()
//}
}

public void ProcessDamage(object target, ref MyDamageInformation info)
public void ProcessDamage(object target, ref MyDamageInformation info)
{
// Check if the target is a character
IMyCharacter character = target as IMyCharacter;
if (character != null)
{
// Check if the damage is collision-related
if (info.Type == MyDamageType.Environment || info.Type == MyDamageType.Fall)
{
// Check if the character is within any safe zone
foreach (IMyCubeBlock zoneblock in zoneblocks)
{
double distance = (zoneblock.WorldMatrix.Translation - character.WorldMatrix.Translation).LengthSquared();
if (distance < radius * radius)
{
// Character is within a safe zone, disable collision damage
info.Amount = 0;
return;
}
}
}
}

// Existing code for block damage prevention
IMySlimBlock slim = target as IMySlimBlock;
long idZone = 0;

Expand Down Expand Up @@ -155,7 +177,7 @@ public void ProcessDamage(object target, ref MyDamageInformation info)
if (player != null && MyIDModule.GetRelationPlayerBlock(idZone, player.Identity.IdentityId) == MyRelationsBetweenPlayerAndBlock.Enemies)
{
info.Amount = 0;
// MyAPIGateway.Utilities.ShowNotification("IS ENEMY. OWNER = " + idZone.ToString() + ", ATTACKER = " + player.Identity.IdentityId.ToString(), 600);
// MyAPIGateway.Utilities.ShowNotification("IS ENEMY. OWNER = " + idZone.ToString() + ", ATTACKER = " + player.Identity.IdentityId.ToString(), 600);
}
else
{
Expand All @@ -169,7 +191,7 @@ public void ProcessDamage(object target, ref MyDamageInformation info)
//MyAPIGateway.Utilities.ShowNotification("IS ENEMY GRINDER BLOCK. OWNER = " + idZone.ToString() + ", ATTACKER = " + block.OwnerId.ToString(), 600);
}
//else
//MyAPIGateway.Utilities.ShowNotification("IS FRIENDLY GRINDER BLOCK", 600);
//MyAPIGateway.Utilities.ShowNotification("IS FRIENDLY GRINDER BLOCK", 600);
}
else if (tool != null)
{
Expand All @@ -179,20 +201,18 @@ public void ProcessDamage(object target, ref MyDamageInformation info)
//MyAPIGateway.Utilities.ShowNotification("IS ENEMY GRINDER TOOL. OWNER = " + idZone.ToString() + ", ATTACKER = " + tool.OwnerId.ToString(), 600);
}
//else
//MyAPIGateway.Utilities.ShowNotification("IS FRIENDLY GRINDER TOOl", 600);
//MyAPIGateway.Utilities.ShowNotification("IS FRIENDLY GRINDER TOOl", 600);
}
//else
//MyAPIGateway.Utilities.ShowNotification("IS FRIENDLY", 600);
//MyAPIGateway.Utilities.ShowNotification("IS FRIENDLY", 600);
}
}
else
{
info.Amount = 0;
// MyAPIGateway.Utilities.ShowNotification("IS WEAPON", 600);
// MyAPIGateway.Utilities.ShowNotification("IS WEAPON", 600);
}

}

}

[MyEntityComponentDescriptor(typeof(MyObjectBuilder_UpgradeModule), false, "bobzone")]
Expand All @@ -217,52 +237,31 @@ public override void Init(MyObjectBuilder_EntityBase objectBuilder)

public override void UpdateAfterSimulation()
{
if (ModBlock == null || !ModBlock.IsFunctional || ModBlock.MarkedForClose || ModBlock.Closed || ModBlock.MarkedForClose || !ModBlock.Enabled || !ModGrid.IsStatic)
if (ModBlock == null || !ModBlock.IsFunctional || ModBlock.MarkedForClose || ModBlock.Closed || !ModBlock.Enabled || !ModGrid.IsStatic)
{

lock (Session.zoneblocks)
{
Session.zoneblocks.Remove(ModBlock);
}

return;
}

//MyAPIGateway.Utilities.ShowNotification("ZONEBLOCK: " + ModBlock.OwnerId.ToString(), 1);

lock (Session.zoneblocks)
{
Session.zoneblocks.Add(ModBlock);
}

tock++;
Vector3D storage = matrix.Up;
matrix = ModBlock.WorldMatrix;
double rad = ((double)tock/100) % 360 * Math.PI / 180;
matrix = MatrixD.CreateWorld(matrix.Translation, matrix.Up, matrix.Right * Math.Cos(rad) + matrix.Forward * Math.Sin(rad));
if (!Session.isServer)
{

double renderdistance = (matrix.Translation - MyAPIGateway.Session.Camera.Position).Length();
var factionColor = GetFactionColor(ModBlock.OwnerId);
if (renderdistance < 20*radius)

DrawRing(matrix.Translation, radius, 32, factionColor); // Draw a ring with 32 segments

//MySimpleObjectDraw.DrawTransparentSphere(ref matrix, radius, ref color, MySimpleObjectRasterizer.Solid, 20, MyStringId.GetOrCompute("SafeZoneShield_Material"), null, -1, -1, null, BlendTypeEnum.PostPP, 1);
//MySimpleObjectDraw.DrawTransparentSphere(ref matrix, radius.Value, ref drawColor, MySimpleObjectRasterizer.Solid, 35, shield_mat, null, -1, -1, null, BlendTypeEnum.PostPP, 1);

//if (renderdistance < radius)
//MyAPIGateway.Utilities.ShowNotification("INSIDE " + ModBlock.GetOwnerFactionTag() + "'S BOBZONE", 1);

}
if (!Session.isServer)
{
double renderdistance = (matrix.Translation - MyAPIGateway.Session.Camera.Position).Length();

var factionColor = GetFactionColor(ModBlock.OwnerId);
if (renderdistance < 20 * radius)
{
}
DrawRing(matrix, radius, 32, factionColor); // Draw a ring with 32 segments based on block orientation
}
}
}

Expand All @@ -282,15 +281,15 @@ private Vector3 ColorMaskToRgb(Vector3 colorMask)
return MyColorPickerConstants.HSVOffsetToHSV(colorMask).HSVtoColor();
}

private void DrawRing(Vector3D center, double radius, int segments, Color color)
private void DrawRing(MatrixD blockMatrix, double radius, int segments, Color color)
{
double angleStep = 2 * Math.PI / segments;
for (int i = 0; i < segments; i++)
{
double angle1 = i * angleStep;
double angle2 = (i + 1) * angleStep;
Vector3D start = center + new Vector3D(radius * Math.Cos(angle1), 0, radius * Math.Sin(angle1));
Vector3D end = center + new Vector3D(radius * Math.Cos(angle2), 0, radius * Math.Sin(angle2));
Vector3D start = blockMatrix.Translation + blockMatrix.Right * radius * Math.Cos(angle1) + blockMatrix.Forward * radius * Math.Sin(angle1);
Vector3D end = blockMatrix.Translation + blockMatrix.Right * radius * Math.Cos(angle2) + blockMatrix.Forward * radius * Math.Sin(angle2);
Vector4 colorVector = color.ToVector4();
MySimpleObjectDraw.DrawLine(start, end, MyStringId.GetOrCompute("Square"), ref colorVector, 1f);
}
Expand Down

0 comments on commit 6970fbd

Please sign in to comment.