/*note In torquescript they used a classname call to the weapon class to perform * the onPickUp and onUse. Unfortunately, we don't have that ability in CSharp. */ public override bool onPickup(Item obj, ShapeBase user, int amount) { if (!base.onPickup(obj, user, amount)) return false; Audio.AudioServerPlay3D("WeaponPickupSound", user.getTransform()); //todo do really like this, I guess they didn't want aiPlayer picking shit up. if (user.getClassName() == "Player" && user.getMountedImage(Constants.WeaponSlot) == 0) return user.Use(this); return false; }
/*note In torquescript they used a classname call to the weapon class to perform * the onPickUp and onUse. Unfortunately, we don't have that ability in CSharp. */ public override bool onPickup(Item obj, ShapeBase user, int amount) { if (!base.onPickup(obj, user, amount)) { return(false); } Audio.AudioServerPlay3D("WeaponPickupSound", user.getTransform()); //todo do really like this, I guess they didn't want aiPlayer picking shit up. if (user.getClassName() == "Player" && user.getMountedImage(Constants.WeaponSlot) == 0) { return(user.Use(this)); } return(false); }
public override void onInventory(ShapeBase user, int value) { //Player can be either a player object or a aiturret... GameConnection client = user["client"]; for (int i = 0; i < 8; i++) { if (user.GetType() == typeof (Player)) { ShapeBaseImageData image = (user).getMountedImage(i); if (image <= 0) continue; if (!image["ammo"].isObject()) continue; if (((SimObject) image["ammo"]).getId() != this.getId()) continue; (user).setImageAmmo(i, value != 0); } else if (user.GetType() == typeof (AITurretShape)) { ShapeBaseImageData image = (user).getMountedImage(i); if (image <= 0) continue; if (!image["ammo"].isObject()) continue; if (((SimObject) image["ammo"]).getId() != getId()) continue; (user).setImageAmmo(i, value != 0); } int currentammo = user.getInventory(this); // ShapeBaseShapeBaseGetInventory(player, thisobj); if (user.getClassName() != "Player") continue; int amountInClips; if (this["clip"].isObject()) { amountInClips = user.getInventory(this["clip"]); // ShapeBaseShapeBaseGetInventory(player, thisobj["clip"]); amountInClips *= this["maxInventory"].AsInt(); amountInClips += user["remaining" + getName()].AsInt(); } else { amountInClips = currentammo; currentammo = 1; } if (user["client"] != string.Empty && !user["isAiControlled"].AsBool()) client.setAmmoAmountHud(currentammo, amountInClips); } }
public override void onWetFire(ShapeBase obj, int slot) { if (!this["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 (!this["infiniteAmmo"].AsBool()) obj.decInventory(this["ammo"], 1); // Get the player's velocity, we'll then add it to that of the projectile int numProjectiles = this["projectileNum"].AsInt(); if (numProjectiles == 0) numProjectiles = 1; TransformF muzzleVector = new TransformF(); for (int i = 0; i < numProjectiles; i++) { if (this["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.mPositionX = (float) ((r.NextDouble() - .5)*2*Math.PI*this["wetProjectileSpread"].AsFloat()); matrix.mPositionY = (float) ((r.NextDouble() - .5)*2*Math.PI*this["wetProjectileSpread"].AsFloat()); matrix.mPositionZ = (float) ((r.NextDouble() - .5)*2*Math.PI*this["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(this["wetProjectile.muzzleVelocity"].AsFloat()); objectVelocity = objectVelocity.vectorScale(this["wetProjectile.velInheritFactor"].AsFloat()); Point3F muzzleVelocity = muzzleVector.GetPosition() + objectVelocity; ObjectCreator tch = new ObjectCreator(this["projectileType"]); tch["dataBlock"] = this["wetProjectile"]; tch["initialVelocity"] = muzzleVelocity; tch["initialPosition"] = obj.getMuzzlePoint(slot); tch["sourceObject"] = obj; tch["sourceSlot"] = slot; tch["client"] = obj["client"]; tch["sourceClass"] = obj.getClassName(); Item projectile = tch.Create(); ((SimSet) "MissionCleanup").pushToBack(projectile); } }