public void RadiusDamage(coShapeBase sourceobject, Point3F position, float radius, float damage, string damageType, float impulse) { // Use the container system to iterate through all the objects // within our explosion radius. We'll apply damage to all ShapeBase // objects. Dictionary <uint, float> r = console.initContainerRadiusSearch(new Point3F(position), radius, (uint)SceneObjectTypesAsUint.ShapeBaseObjectType); float halfRadius = radius / (float)2.0; foreach (coPlayer targetObject in r.Keys) { // Calculate how much exposure the current object has to // the explosive force. The object types listed are objects // that will block an explosion. If the object is totally blocked, // then no damage is applied. UInt32 mask = (uint)SceneObjectTypesAsUint.TerrainObjectType | (uint)SceneObjectTypesAsUint.StaticShapeObjectType | (uint)SceneObjectTypesAsUint.VehicleObjectType; float coverage = Util.calcExplosionCoverage(new Point3F(position), targetObject, mask); if (!coverage.AsBool()) { continue; } float dist = r[targetObject]; // Calculate a distance scale for the damage and the impulse. // Full damage is applied to anything less than half the radius away, // linear scale from there. float distScale = (float)((dist < halfRadius) ? 1.0 : 1 - ((dist - halfRadius) / halfRadius)); // Apply the damage ShapeBaseDamage(targetObject, sourceobject, position, (((damage) * coverage * distScale)), damageType); // Apply the impulse if (!impulse.AsBool()) { continue; } TransformF impulseVec = new TransformF(targetObject.getWorldBoxCenter()) - new TransformF(position); impulseVec = impulseVec.normalizeSafe(); impulseVec = impulseVec.vectorScale(impulse * distScale); targetObject.applyImpulse(new Point3F(position), impulseVec.MPosition); } }
public void setDamageDirection(GameBase sourceObject, TransformF damagePos) { if (sourceObject.isObject()) { damagePos = console.isField(sourceObject, "initialPosition") ? new TransformF(sourceObject["initialPosition"]) : sourceObject.getTransform(); } TransformF dp = damagePos; Point3F wbc = getWorldBoxCenter(); TransformF damagevec = dp - new TransformF(wbc); damagevec = damagevec.normalizeSafe(); GameConnection client = this["client"]; if (!client.isObject()) { return; } ShapeBase cameraobject = client.getCameraObject(); TransformF inverseTransform = cameraobject.getInverseTransform(); damagevec = math.MatrixMulVector(inverseTransform, damagevec.GetPosition()); float[] components = new float[6]; string[] directions = new string[6]; directions[0] = "Left"; directions[1] = "Right"; directions[2] = "Bottom"; directions[3] = "Front"; directions[4] = "Bottom"; directions[5] = "Top"; components[0] = -damagevec.mPositionX; components[1] = damagevec.mPositionX; components[2] = -damagevec.mPositionY; components[3] = damagevec.mPositionY; components[4] = -damagevec.mPositionZ; components[5] = damagevec.mPositionZ; string damagedirection = string.Empty; float max = 0; for (int i = 0; i < 6; i++) { if (components[i] <= max) { continue; } damagedirection = directions[i]; max = components[i]; } if (console.isObject(client)) { // Util._commandToClient(client, console.addTaggedString("setDamageDirection"), damagedirection); console.commandToClient(client, console.addTaggedString("setDamageDirection"), new[] { damagedirection }); } }