public void ArmorOnDisabled(coPlayerData datablock, coPlayer player, string state) { player.setImageTrigger(0, false); coItem item = (((coItemData)(player.getMountedImage(WeaponSlot)))["item"]); if (item.isObject()) { int amount = ShapeBaseShapeBaseGetInventory(player, (item["image.ammo"])); if (amount.AsBool()) { ShapeBaseShapeBaseThrow(player, (item["image.clip"]), 1); } } ShapeBaseTossPatch(player); PlayerPlayDeathCry(player); PlayerPlayDeathAnimation(player); //If it's a player check..... coGameConnection client = player["client"]; if (client.isObject()) { console.commandToClient(client, console.addTaggedString("toggleVehicleMap"), new[] { "false" }); } int ctov = iGlobal["$CorpseTimeoutValue"]; player.schedule((ctov - 1000).AsString(), "startFade", "1000", "0", "true"); player.schedule(ctov.AsString(), "delete"); }
public void ServerCmdUse(coGameConnection client, coItem data) { if (((coPlayer)client.getControlObject()).isObject()) { ((coPlayer)client.getControlObject()).call("use", data); } }
public void ItemschedulePop(coItem item) { // This method deletes the object after a default duration. Dynamic // items such as thrown or drop weapons are usually popped to avoid // world clutter. item.schedule((ItemPopTime - 1000).AsString(), "startFade", "1000", "0", "true"); item.schedule(ItemPopTime.AsString(), "delete"); }
public string ShapeBaseDataShapeBaseDataOnPickup(coShapeBaseData thisobj, coItem obj, coPlayer user, int amount) { // Invoked when the user attempts to pickup this datablock object. // The %amount argument is the space in the user's inventory for // this type of datablock. This method is responsible for // incrementing the user's inventory is something is addded. // Should return true if something was added to the inventory. return("0"); }
public bool ShapeBaseShapeBaseHasAmmo(coShapeBase thisob, coItem weapon) { coItemData weaponimageammo = weapon["image.ammo"]; if (weaponimageammo == "") { return(true); } return(ShapeBaseShapeBaseGetInventory(thisob, weaponimageammo) > 0); }
public void ItemRespawn(coItem item) { // This method is used to respawn static ammo and weapon items // and is usually called when the item is picked up. // Instant fade... item.startFade(0, 0, true); item.setHidden(true); item.schedule(ItemRespawnTime.AsString(), "setHidden", "false"); item.schedule((ItemRespawnTime + 100).AsString(), "startFade", "1000", "0", "false"); }
public bool ItemDataOnPickUp(coItemData datablock, coItem item, coPlayer player, string amount) { int count = item["count"].AsInt(); //string count = console.GetVarString(item + ".count"); if (count == 0) { count = datablock["count"].AsInt(); if (count == 0) { if (datablock["maxInventory"] != "") { if (count != datablock["maxInventory"].AsInt()) { return(false); } } else { count = 1; } } } ShapeBaseShapeBaseIncInventory(player, (((coItemData)datablock).getName()), count); coGameConnection client = player["client"]; if (client.isObject()) { MessageClient(client, "MsgItemPickup", console.ColorEncode(@"\c0You picked up %1"), datablock["pickupName"]); } // If the item is a static respawn item, then go ahead and // respawn it, otherwise remove it from the world. // Anything not taken up by inventory is lost. if (item.isStatic()) { item.call("respawn"); } else { item.delete(); } return(true); }
public void AmmoClipOnPickup(coItem thisobj, string obj, coPlayer shape, string amount, int nameSpaceDepth) { int nsd = nameSpaceDepth + 1; if (!console.ParentExecute(thisobj, "onPickup", nsd, new string[] { thisobj, obj, shape, amount }).AsBool()) { return; } AudioServerPlay3D("WeaponPickupSound", shape.getTransform()); coItemData image = shape.getMountedImage(WeaponSlot); if (image == 0) { return; } if (!console.isField(image, "clip") || console.Call(string.Format("{0}.clip", image), "getID") != console.Call(thisobj, "getID")) { return; } bool outOfAmmo = !shape.getImageAmmo(WeaponSlot); int amountInClips = 0; int currentAmmo = ShapeBaseShapeBaseGetInventory(shape, image["ammo"]); if (console.isObject(image["clip"])) { amountInClips = ShapeBaseShapeBaseGetInventory(shape, image["clip"]); } int t = console.GetVarInt(string.Format("{0}.ammo.maxInventory", image)); amountInClips *= t; int amountloadedingun = console.GetVarInt(string.Format("{0}.remaining{1}", obj, console.GetVarString(string.Format("{0}.ammo", this)))); amountInClips += amountloadedingun; GameConnectionSetAmmoAmountHud(shape["client"], currentAmmo, amountInClips); if (outOfAmmo) { console.Call(image, "onClipEmpty", new string[] { shape, WeaponSlot.AsString() }); } }
public string RocketLauncherImageOnAltFire(coItem thisobj, coPlayer obj, string slot) { int currentAmmo = ShapeBaseShapeBaseGetInventory(obj, (thisobj["ammo"])); if (currentAmmo < thisobj["loadCount"].AsInt()) { thisobj["loadCount"] = currentAmmo.AsString(); } coProjectile projectile = null; for (int shotCount = 0; shotCount < thisobj["loadCount"].AsInt(); shotCount++) { // Decrement inventory ammo. The image's ammo state is updated // automatically by the ammo inventory hooks. ShapeBaseShapeBaseDecInventory(obj, (thisobj["ammo"]), 1); // We fire our weapon using the straight ahead aiming point of the gun // We'll need to "skew" the projectile a little bit. We start by getting // the straight ahead aiming point of the gun Point3F vec = obj.getMuzzleVector(slot.AsInt()); Random r = new Random(); TransformF matrix = new TransformF(); matrix.MPosition.x = (float)((r.NextDouble() - .5) * 2 * Math.PI * 0.008); matrix.MPosition.y = (float)((r.NextDouble() - .5) * 2 * Math.PI * 0.008); matrix.MPosition.z = (float)((r.NextDouble() - .5) * 2 * Math.PI * 0.008); TransformF mat = math.MatrixCreateFromEuler(matrix); // Which we'll use to alter the projectile's initial vector with TransformF muzzleVector = math.MatrixMulVector(mat, vec); // Get the player's velocity, we'll then add it to that of the projectile TransformF objectVelocity = new TransformF(obj.getVelocity()); muzzleVector = muzzleVector.vectorScale(thisobj["projectile.muzzleVelocity"].AsFloat()); objectVelocity = objectVelocity.vectorScale(thisobj["projectile.velInheritFactor"].AsFloat()); TransformF muzzleVelocity = muzzleVector + objectVelocity; Torque_Class_Helper tch = new Torque_Class_Helper(thisobj["projectileType"], ""); tch.Props.Add("dataBlock", thisobj["projectile"]); tch.Props.Add("initialVelocity", '"' + muzzleVelocity.ToString() + '"'); tch.Props.Add("initialPosition", '"' + obj.getMuzzlePoint(slot.AsInt()).AsString() + '"'); tch.Props.Add("sourceObject", obj); tch.Props.Add("sourceSlot", slot); tch.Props.Add("client", obj["client"]); projectile = tch.Create(); ((coSimSet)"MissionCleanup").pushToBack(projectile); } return(projectile); }
public void ShapeBaseShapeBaseThrowObject(coShapeBase thisobj, coItem obj) { // Throw the given object in the direction the shape is looking. // The force value is hardcoded according to the current default // object mass and mission gravity (20m/s^2). float throwforce = (( coSimDataBlock)thisobj.getDataBlock())["throwForce"].AsFloat(); if (throwforce == 0) { throwforce = 20; } // Start with the shape's eye vector... Point3F eye = thisobj.getEyeVector(); Point3F vec = eye.vectorScale(throwforce); // Add a vertical component to give the object a better arc double verticalForce = throwforce / 2.0; float dot = Point3F.vectorDot(new Point3F("0 0 1"), eye); if (dot < 0) { dot = dot * -1; } vec = vec + Point3F.vectorScale(new Point3F(string.Format("0 0 {0}", verticalForce)), 1 - dot); vec = vec + thisobj.getVelocity(); // Set the object's position and initial velocity TransformF pos = new TransformF(Util.getBoxCenter(thisobj.getWorldBox())); obj.setTransform(pos); obj.applyImpulse(pos.MPosition, vec); // Since the object is thrown from the center of the shape, // the object needs to avoid colliding with it's thrower. obj.setCollisionTimeout(thisobj); if ((obj.getClassName() != "AITurretShape") && (obj.getClassName() != "ProximityMine")) { obj.schedule(ItemPopTime.AsString(), "delete"); } }
public string ShapeBaseTossPatch(coShapeBase thisobj) { if (!thisobj.isObject()) { return(string.Empty); } coItem item = console.Call_Classname("ItemData", "CreateItem", new[] { "HealthKitPatch" }); item["istemp"] = true.AsString(); item["sourceObject"] = thisobj; item["static"] = false.AsString(); (( coSimSet)"MissionCleanup").pushToBack(item); Random r = new Random(); Point3F vec = new Point3F(-1 + (float)r.NextDouble() * 2, -1 * (float)r.NextDouble() * 2, (float)r.NextDouble()); vec = vec.vecotrScale(10); Point3F eye = thisobj.getEyeVector(); float dot = new Point3F("0 0 1 ").vectorDot(eye); if (dot < 0) { dot = -dot; } vec = vec + new Point3F("0 0 8").vecotrScale(1 - dot); vec = vec + thisobj.getVelocity(); TransformF pos = new TransformF(thisobj.getWorldBox().minExtents); item.setTransform(pos); item.applyImpulse(pos.MPosition, vec); item.setCollisionTimeout(thisobj); item.call("schedulePop"); return(item); }
public bool ShapeBaseShapeBasePickup(coShapeBase thisobj, coItem obj, int amount) { coItemData data = obj.getDataBlock(); if (amount == 0) { int maxamount = ShapeBaseShapeBaseMaxInventory(thisobj, data); int curamount = ShapeBaseShapeBaseGetInventory(thisobj, data); amount = (maxamount - curamount); } if (amount > 0) { return(data.call("onPickUp", obj, thisobj, amount.AsString()).AsBool()); } return(false); }
public string ItemDataOnThrow(coItemData datablock, coPlayer player, int amount) { if (amount == 0) { amount = 1; } if (amount > datablock["maxInventory"].AsInt()) { amount = datablock["maxInventory"].AsInt(); } if (!amount.AsBool()) { return("0"); } ShapeBaseShapeBaseDecInventory(player, datablock, amount); // Construct the actual object in the world, and add it to // the mission group so it's cleaned up when the mission is // done. The object is given a random z rotation. Torque_Class_Helper tch = new Torque_Class_Helper("Item", ""); tch.Props.Add("datablock", datablock); tch.Props.Add("rotation", @"""0 0 1 " + (new Random().Next(0, 360)) + @""""); tch.Props.Add("count", amount.AsString()); coItem item = tch.Create(); ((coSimSet)"MissionGroup").pushToBack(item); ItemschedulePop(item); return(item); }
public void RocketLauncherImageReadyLoad(coItem thisobj) { thisobj["loadCount"] = "1"; }
public string ShapeBaseShapeBaseOnInventory(coShapeBase thisobj, coItem data, string value) { // Invoked on ShapeBase objects whenever their inventory changes // for the given datablock. return("0"); }
public void WeaponImageonWetFire(coScriptObject thisobj, coPlayer obj, int slot) { if (!thisobj["projectile"].isObject()) { console.error("WeaponImage::onFire() - Invalid projectile datablock"); return; } // Decrement inventory ammo. The image's ammo state is updated // automatically by the ammo inventory hooks. if (!thisobj["infiniteAmmo"].AsBool()) { ShapeBaseShapeBaseDecInventory(obj, thisobj["ammo"], 1); } // Get the player's velocity, we'll then add it to that of the projectile int numProjectiles = thisobj["projectileNum"].AsInt(); if (numProjectiles == 0) { numProjectiles = 1; } TransformF muzzleVector = new TransformF(); for (int i = 0; i < numProjectiles; i++) { if (thisobj["wetProjectileSpread"].AsBool()) { // We'll need to "skew" this projectile a little bit. We start by // getting the straight ahead aiming point of the gun Point3F vec = obj.getMuzzleVector(slot); // Then we'll create a spread matrix by randomly generating x, y, and z // points in a circle Random r = new Random(); TransformF matrix = new TransformF(); matrix.MPosition.x = (float)((r.NextDouble() - .5) * 2 * Math.PI * thisobj["wetProjectileSpread"].AsFloat()); matrix.MPosition.y = (float)((r.NextDouble() - .5) * 2 * Math.PI * thisobj["wetProjectileSpread"].AsFloat()); matrix.MPosition.z = (float)((r.NextDouble() - .5) * 2 * Math.PI * thisobj["wetProjectileSpread"].AsFloat()); TransformF mat = math.MatrixCreateFromEuler(matrix); muzzleVector = math.MatrixMulVector(mat, vec); } else { muzzleVector = new TransformF(obj.getMuzzleVector(slot)); } Point3F objectVelocity = obj.getVelocity(); muzzleVector = muzzleVector.vectorScale(thisobj["wetProjectile.muzzleVelocity"].AsFloat()); objectVelocity = objectVelocity.vectorScale(thisobj["wetProjectile.velInheritFactor"].AsFloat()); Point3F muzzleVelocity = muzzleVector.MPosition + objectVelocity; Torque_Class_Helper tch = new Torque_Class_Helper(thisobj["projectileType"]); tch.Props.Add("dataBlock", thisobj["wetProjectile"]); tch.Props.Add("initialVelocity", '"' + muzzleVelocity.AsString() + '"'); tch.Props.Add("initialPosition", '"' + obj.getMuzzlePoint(slot).AsString() + '"'); tch.Props.Add("sourceObject", obj); tch.Props.Add("sourceSlot", slot.AsString()); tch.Props.Add("client", obj["client"]); tch.Props.Add("sourceClass", obj.getClassName()); coItem projectile = tch.Create(); ((coSimSet)"MissionCleanup").pushToBack(projectile); } }
public void RocketLauncerincLoad(coItem thisobj) { thisobj["loadCount"] = (thisobj["loadCount"].AsInt() + 1).AsString(); }