Пример #1
0
        } // end attempEngage

        private void AttemptShootLauncher()
        {
            if (this.inventory.GetBodyItem((int)Inventory.BodySlot.Ammo) == null)
            {
                // then we have no ammo
                string msg = "" + this.Name + ": I have no ammo equipped to attack with this "
                             + Enum.GetName(typeof(RPGWeapon.WeaponClass), this.inventory.GetWpn().weaponClass) + "!";
                Session.Print(msg);

                // if currentAction is attacking, then stop attacking
                if (currentAction.type == RPGAction.ActionType.Attack)
                {
                    currentAction.Accomplished = true; // this will stop attacking.
                }
            }
            else
            {
                // we have ammo, make sure it matches
                if (this.inventory.GetWpn().GetProjectileType() !=
                    (this.inventory.GetBodyItem((int)Inventory.BodySlot.Ammo) as Projectile).type)
                {
                    // then wrong ammo type
                    string msg = "" + this.Name + ": I have the wrong ammo equipped to attack with this "
                                 + Enum.GetName(typeof(RPGWeapon.WeaponClass), this.inventory.GetWpn().weaponClass) + "!";
                    Session.Print(msg);

                    // if currentAction is attacking, then stop attacking
                    if (currentAction.type == RPGAction.ActionType.Attack)
                    {
                        currentAction.Accomplished = true; // this will stop attacking.
                    }
                }
                else
                {
                    // we have the correct ammo type, shoot one
                    lastAttack = DateTime.Now;

                    // have to create a projectile
                    Projectile p = (inventory.GetBodyItem((int)Inventory.BodySlot.Ammo) as Projectile).GetOneOfStack();
                    if (p != null)
                    {
                        // NOTE: projectile does not start at top-left corner,
                        // but is set to be the center 2/3 of character, set in constructor
                        p.Owner = this;
                        p.UpdateLocation();
                        p.Target   = (Actor)currentAction.target;
                        p.IsFlying = true;
                        Session.thisSession.thisArea.AddObject(p);
                    }
                    // reduce/remove thrown item from inventory
                    (inventory.GetBodyItem((int)Inventory.BodySlot.Ammo) as Projectile).StackQuantity--;
                    if ((inventory.GetBodyItem((int)Inventory.BodySlot.Ammo) as Projectile).StackQuantity == 0)
                    {
                        // remove this throwing weapon.
                        inventory.RemoveBodyItem(Inventory.BodySlot.Ammo);
                    }
                }
            }
        } // end AttemptShootLauncher