private static void AttachWeapon_UnhookPrevious(ref JointBase weaponAttachJoint) { if (weaponAttachJoint != null) { weaponAttachJoint.Dispose(); } weaponAttachJoint = null; }
private static void AttachWeapon_HookupNew(MapObjectTransferArgs args, ref JointBase weaponAttachJoint, ref Weapon weapon, Weapon newWeapon) { weapon = newWeapon; if (weapon != null) { Point3D position = args.Bot.PositionWorld; // Move the weapon into position weapon.MoveToAttachPoint(position); JointBallAndSocket ballAndSocket = JointBallAndSocket.CreateBallAndSocket(args.World, position, args.Bot.PhysicsBody, weapon.PhysicsBody); ballAndSocket.ShouldLinkedBodiesCollideEachOther = false; weaponAttachJoint = ballAndSocket; weapon.Gravity = args.Gravity; } }
//TODO: Make this function more generic so it's not just arcanorum weapons /// <summary> /// This attaches the weapon passed in, and returns the previous weapon. Also optionally manages the weapon's states within /// the map or inventory /// </summary> /// <param name="newFrom">If from map or inventory, this will remove it from those places</param> /// <param name="existingTo">If told to, will add the existing back into inventory or map</param> public static void AttachWeapon(MapObjectTransferArgs args, ref JointBase weaponAttachJoint, ref Weapon weapon, Weapon newWeapon, ItemToFrom newFrom = ItemToFrom.Nowhere, ItemToFrom existingTo = ItemToFrom.Nowhere) { // Pause the world bool shouldResume = false; if (!args.World.IsPaused) { shouldResume = true; args.World.Pause(); } // Unhook previous weapon (remove joint) AttachWeapon_UnhookPrevious(ref weaponAttachJoint); // Hand off existing weapon if (weapon != null) { AttachWeapon_HandOffWeapon(args, weapon, existingTo); } // Take new weapon AttachWeapon_TakeNewWeapon(args, ref newWeapon, newFrom); // Hook up new weapon (add joint) AttachWeapon_HookupNew(args, ref weaponAttachJoint, ref weapon, newWeapon); // In order for semitransparency to work, this bot's visuals must be added to the viewport last if (newWeapon != null && args.Viewport != null && args.Visuals3D != null) { args.Viewport.Children.RemoveAll(args.Visuals3D); args.Viewport.Children.AddRange(args.Visuals3D); } // Resume the world if (shouldResume) { args.World.UnPause(); } }