public override void damage(ShapeBase obj, Point3F position, GameBase sourceobject, float damage, string damagetype) { Player pobj = obj._ID; if (!pobj.isObject() || pobj.getState() == "Dead" || !damage.AsBool()) { return; } obj.applyDamage(damage); GameConnection client = obj["client"]; if (!client.isObject()) { return; } if (damagetype != "Suicide") { pobj.setDamageDirection(sourceobject, new TransformF(position)); } if (pobj.getState() == "Dead") { client.onDeath(sourceobject, sourceobject["client"].isObject() ? sourceobject["client"] : "0", damagetype, "Body"); } }
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); } }