Beispiel #1
0
 public void AddAmmo(AmmunitionType type, int count)
 {
     if (ammunition[type] + count <= _MaxAmmoCount)
     {
         ammunition[type] += count;
     }
 }
Beispiel #2
0
        public int CanBeBought(AmmunitionType type)
        {
            IAmmoItem item = inventory.Ammo.Get(type);

            Debug.Assert(item.MaxAmount >= item.CurrentAmount, "Ammo item must be <= than max amount" + item.This);
            return(item.MaxAmount - item.CurrentAmount);
        }
        private IAmmunition CreateAmmo(IAmmunitionGetter a, AmmunitionMaterial am, AmmunitionType at, string ammoName,
                                       string?ammoDesc,
                                       Action <Ammunition>?ammoFn = null, Action <Projectile>?projectileFn = null)
        {
            var na = Patch.Ammunitions.DuplicateInAsNewRecord(a);

            na.EditorID = SPrefixPatcher + SPrefixAmmunition + a.EditorID + ammoName + a.FormKey;
            na.Name     = $"{a.NameOrThrow()} - {Storage.GetOutputString(ammoName)}";

            if (ammoDesc != null)
            {
                na.Description = Storage.GetOutputString(ammoDesc);
            }

            var p  = _projectiles[na.Projectile.FormKey];
            var np = Patch.Projectiles.DuplicateInAsNewRecord(p);

            _projectiles[np.FormKey] = np;
            np.EditorID = SPrefixPatcher + SPrefixProjectile + na.EditorID + a.FormKey;
            na.Projectile.SetTo(np);

            var amod = Storage.GetAmmunitionModifiers(na).ToArray();

            projectileFn?.Invoke(np);

            if (Storage.UseWarrior)
            {
                na.Damage = at.DamageBase + am.DamageModifier + amod.Sum(m => m.DamageModifier);
                PatchProjectile(na, am, at, amod);
            }

            return(na);
        }
    public override void Pickup(PlayerHandler ph)
    {
        AmmunitionInventory ai = ph.ammo;

        if (ai != null)
        {
            bool hasBeenConsumed = false;
            for (int i = 0; i < System.Enum.GetValues(typeof(AmmunitionType)).Length; i++)
            {
                AmmunitionType a = (AmmunitionType)i;
                if (ai.GetStock(a) < ai.GetMax(a))
                {
                    int amountToRestore = Mathf.RoundToInt(ai.GetMax(a) * (percentageValue / 100));
                    amountToRestore = Mathf.Clamp(amountToRestore, 1, ai.GetMax(a));
                    ai.Collect(a, amountToRestore);
                    hasBeenConsumed = true;
                }
            }

            if (hasBeenConsumed == true)
            {
                Destroy(gameObject);
            }
        }
    }
Beispiel #5
0
    void fire(AmmunitionType ammType, int button)
    {
        float fireRate = 0;

        switch (ammType)
        {
        case AmmunitionType.VERTICAL:
            ammu     = (button == 1)? verticalGun : verticalDownGun;
            fireRate = fireRateCopyGun;
            break;

        case AmmunitionType.GRAVITY:
            ammu     = (button == 1)? gravityGun : gravityActiveGun;
            fireRate = fireRateCopyGun;
            break;

        case AmmunitionType.HORIZONTAL:
            ammu     = (button == 1)? horizontalGun : horizontalLeftGun;
            fireRate = fireRateCopyGun;
            break;
        }
        if (Time.time > nextFire)
        {
            nextFire = Time.time + fireRate;
            if (facingRight)
            {
                Instantiate(ammu, gunTip.position + rightShootingCorrection, Quaternion.Euler(new Vector3(0, 0, 0)));
            }
            else
            {
                Instantiate(ammu, gunTip.position, Quaternion.Euler(new Vector3(0, 0, 180f)));
            }
        }
    }
Beispiel #6
0
        public void Add(AmmunitionType type, int toAdd)
        {
            int max       = ammo[type].MaxAmount;
            int newAmount = ammo[type].CurrentAmount + toAdd;

            ammo[type].CurrentAmount = Mathf.Clamp(newAmount, 0, max);
        }
Beispiel #7
0
        /// <summary>
        /// Is this ammo type necessary for at least one weapon from the list?
        /// </summary>
        bool IsNecessary(AmmunitionType type, List <WeaponIndex> weapons)
        {
            var weaponsStats = GameController.Instance.WeaponsStats;

            bool forAmmo = false;

            foreach (WeaponIndex w in weapons)
            {
                if (weaponsStats[w].AmmoType == type)
                {
                    // if weapon is ammo too (f.e. grenades)
                    if (weaponsStats[w].IsAmmo)
                    {
                        // then it's necessary if amount > 0;
                        // don't return here, as there are other weapons,
                        // and maybe one of them use this ammo but not IsAmmo

                        forAmmo = forAmmo || ammo[type].CurrentAmount > 0;

                        continue;
                    }

                    return(true);
                }
            }

            return(forAmmo);
        }
Beispiel #8
0
 public AmmoData this[AmmunitionType a]
 {
     get
     {
         return(ammoStats[a]);
     }
 }
Beispiel #9
0
    private void CreateProjectilesPool()
    {
        projectiles = new Dictionary <AmmunitionType, List <GameObject> >();

        var values = AmmunitionType.GetValues(typeof(AmmunitionType));

        foreach (AmmunitionType value in values)
        {
            // for each ammo type create list of bullets

            List <GameObject> projectilesList = new List <GameObject>();

            for (int i = 0; i < projectilesCount; i++)
            {
                GameObject template = Resources.Load <GameObject>(value.ToString());
                GameObject instance = Instantiate(template);
                instance.transform.SetParent(this.transform);
                instance.SetActive(false);
                projectilesList.Add(instance);

                instance.GetComponent <ProjectileController>().player = pc;
            }

            projectiles.Add(value, projectilesList);
        }
    }
Beispiel #10
0
        public AmmunitionData ConsumeAmmunition(AmmunitionType ammunitionType)
        {
            AmmunitionData ammunitionData = new AmmunitionData();

            foreach (ItemSlot itemSlot in ItemSlots)
            {
                AmmunitionItem ammunitionItem = itemSlot.item as AmmunitionItem;

                if (ammunitionItem == null)
                {
                    continue;
                }

                if (ammunitionItem.AmmunitionType != ammunitionType)
                {
                    continue;
                }

                ammunitionData.ammunitionPrefab = ammunitionItem.AmmunitionPrefab;

                RemoveItem(itemSlot.item);

                break;
            }

            return(ammunitionData);
        }
Beispiel #11
0
 public AmmunitionInventory(AvatarInventory parentInventory, AmmunitionType ammunitionType)
     : base(parentInventory)
 {
     Amount         = 0;
     AmmunitionType = ammunitionType;
     CapacityLevels = GetCapacityLevelByAmmunitionType(ammunitionType);
 }
        private void PatchProjectile(Ammunition na, AmmunitionMaterial am, AmmunitionType at, AmmunitionModifier[] amod)
        {
            var p = Patch.Projectiles.GetOrAddAsOverride(_projectiles[na.Projectile.FormKey]);

            p.Speed   = at.SpeedBase + am.SpeedModifier + amod.Sum(m => m.SpeedModifier);
            p.Gravity = at.GravityBase + am.GravityModifier + amod.Sum(m => m.GravityModifier);
            p.Range   = at.RangeBase + am.RangeModifier + amod.Sum(m => m.RangeModifier);
        }
    public int GetMax(AmmunitionType type) // Since our enum is "really" an integer, we can use it as an index to jump straight to the entry we want.
    {
        if (type == AmmunitionType.None)
        {
            return(int.MaxValue);
        }

        return(inventory[(int)type].max);
    }
Beispiel #14
0
 protected void InitializeGun(AmmunitionType ammunitionType, int bulletDamage, double reloadTime, double firingDelay, int bulletCapacity, int bulletsLoaded)
 {
     this.AmmunitionType = ammunitionType;
     this.BulletDamage   = bulletDamage;
     this.ReloadTime     = reloadTime;
     this.FiringDelay    = firingDelay;
     this.BulletCapacity = bulletCapacity;
     this.BulletsLoaded  = bulletsLoaded;
 }
    public int Spend(AmmunitionType type, int amount) // Returns the amount actually spent, in case firing a full round would drop us below 0 ammo, you can scale down the last shot. You could also implement a TrySpend that aborts for insufficient ammo.
    {
        Resource held  = ammoTypes[(int)type];
        int      spend = Mathf.Min(amount, held.current);

        held.current        -= spend;
        ammoTypes[(int)type] = held;
        return(spend);
    }
Beispiel #16
0
 public AmmunitionType(AmmunitionType ammo)
 {
     if (ammo != null)
     {
         Capacity = ammo.Capacity;
         Amount   = ammo.Capacity;
         ReloadPA = ammo.ReloadPA;
     }
 }
    public int Collect(AmmunitionType type, int amount) // Returns amount collected, so you can choose to not consume pickups if you're already full (ie. return value is zero).
    {
        Resource held    = ammoTypes[(int)type];
        int      collect = Mathf.Min(amount, held.max - held.current);

        held.current        += collect;
        ammoTypes[(int)type] = held;
        return(collect);
    }
Beispiel #18
0
 // Use this for initialization
 void Start()
 {
     character   = GetComponent <Rigidbody2D>();
     animator    = GetComponent <Animator>();
     facingRight = true;
     ammunition  = AmmunitionType.HORIZONTAL;
     fixBulletSpeeds();
     gunMenu.SetActive(false);
     isShowingMenu = false;
 }
    public void Init(AmmunitionType type, float strength)
    {
        ammoType = type;
        GetComponent <Rigidbody2D>().AddForce(Vector2.up * strength * Time.deltaTime * Mathf.Clamp(player.gameObject.GetComponent <Rigidbody2D>().velocity.y, 1.0f, 50.0f));

        Vector2 velocity = new Vector2(0.0f, player.GetComponent <Rigidbody2D>().velocity.y + (strength * Time.deltaTime));

        GetComponent <Rigidbody2D>().velocity = velocity;

        Invoke("Deactivate", 3.0f);
    }
Beispiel #20
0
 private AmmunitionSlot GetAmmunitionSlot(AmmunitionType ammunitionType)
 {
     foreach (AmmunitionSlot ammunitionSlot in ammunitionSlots)
     {
         if (ammunitionSlot.ammunitionType.Equals(ammunitionType))
         {
             return(ammunitionSlot);
         }
     }
     return(null);
 }
Beispiel #21
0
    public GameObject GetProjectileAndActivate(AmmunitionType type)
    {
        GameObject go = GetProjectile(type);

        go.SetActive(true);
        go.GetComponent <Rigidbody2D>().velocity        = Vector3.zero;
        go.GetComponent <Rigidbody2D>().angularVelocity = 0.0f;
        go.transform.rotation = Quaternion.identity;

        return(go);
    }
Beispiel #22
0
        private void Start()
        {
            _currentAmmoType = AmmunitionType1;
            for (var i = 0; i <= _countClip; i++)
            {
                AddClip(new Clip {
                    CountAmmunition = Random.Range(_minCountAmmunition, _maxCountAmmunition)
                });
            }

            ReloadClip();
        }
Beispiel #23
0
        public static AmmoInfo GetAmmoInfo(AmmunitionType ammoType)
        {
            foreach (var i in Infos.Values)
            {
                if (i.AmmoType == ammoType)
                {
                    return(i);
                }
            }

            return(null);
        }
        public PoolObjectAmmunition(AmmunitionType ammunitionType)
        {
            PoolObjectsAmmunition = new Dictionary <int, Ammunition>(10);
            TimeRemainings        = new HashSet <ITimeRemaining>();
            Ammunitions           = new HashSet <Ammunition>();

            _ammunitionType    = ammunitionType;
            _ammunitionFactory = new AmmunitionFactory();
            _sizePool          = 50;
            _root = new GameObject("Root Pool Object Ammunition").transform;
            InitializationPool();
        }
    public bool TrySpend(AmmunitionType type, int amount)
    {
        Resource held = ammoTypes[(int)type];

        if (held.current >= amount)
        {
            held.current        -= amount;
            ammoTypes[(int)type] = held;
            return(true);
        }
        return(false);
    }
Beispiel #26
0
        void Set(AmmunitionType t, int amount)
        {
            var a = ammo[t];

            a.Obj.SetActive(true);

            // set text
            a.Txt.text = amount.ToString();

            // set color
            a.Img.color = a.Txt.color =
                amount > 0 ? ammoAvailable : ammoEmpty;
        }
Beispiel #27
0
        public bool HasAmmunition(IItemManager itemManager, AmmunitionType ammunitionType)
        {
            var ammunitionSlot = Equipment.Slots[EquipmentSlot.LeftHand];

            if (ammunitionSlot.Empty)
            {
                return(false);
            }

            var ammunition = itemManager.GetItem(ammunitionSlot.ItemIndex);

            return(ammunition.Type == ItemType.Ammunition && ammunition.AmmunitionType == ammunitionType);
        }
Beispiel #28
0
    void AddAmmo()
    {
        AmmunitionType ammoType = AmmunitionType.Bullet9mm;

        foreach (AmmunitionType type in AmmunitionType.GetValues(typeof(AmmunitionType)))
        {
            if (type.ToString() == value)
            {
                ammoType = type;
            }
        }

        player.gameObject.GetComponent <PlayerResources>().AddAmmo(ammoType, UnityEngine.Random.Range(1, 100));
    }
Beispiel #29
0
        public bool ReceiveAmmoPickup(AmmunitionType type, int amount)
        {
            IAmmoItem ammo = playerInventory.Ammo.Get(type);

            // if ammo is not max
            if (ammo.CurrentAmount < ammo.MaxAmount)
            {
                // then add
                ammo.CurrentAmount += amount;
                return(true);
            }

            return(false);
        }
Beispiel #30
0
        public Ammunition GetAmmunition(AmmunitionType type)
        {
            Ammunition result;

            switch (type)
            {
            case AmmunitionType.Bullet:
                result = GetBullet(GetListAmmunition(type));
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }

            return(result);
        }
Beispiel #31
0
 private static TopicMetadata AlienAmmunition(AmmunitionType ammunition, params ResearchType[] requiredResearch)
 {
     return new TopicMetadata
     {
         Name = ammunition.Metadata().Name,
         Category = TopicCategory.AlienArtifacts,
         Background = Backgrounds.InfoItem,
         BackgroundPalette = 4,
         Scheme = ColorScheme.Yellow,
         RequiredResearch = requiredResearch,
         Subject = ammunition
     };
 }
Beispiel #32
0
		private static BattleItemMetadata MetadataOf(AmmunitionType ammunitionType) => ammunitionType.Metadata();
Beispiel #33
0
		private void AddTopicControls(AmmunitionType ammunition)
		{
			var metadata = ammunition.Metadata();
			AddControl(new Item(4 + 8 * (3 - metadata.Height), 158 + 8 * (2 - metadata.Width), metadata.Image));
			AddControl(new WrappedLabel(24, 5, 150, metadata.Name, Font.Large, ColorScheme.White));

			AddControl(new Label(24, Label.CenterOf(195, 90), metadata.DamageType.Metadata().Name, Font.Normal, ColorScheme.White));
			AddControl(new Label(40, Label.CenterOf(195, 90), metadata.Damage.FormatNumber(), Font.Large, ColorScheme.Red));

			var nextTop = 67;
			foreach (var descriptionLine in metadata.DescriptionLines)
			{
				var top = nextTop;
				nextTop += 8;
				AddControl(new Label(top, 8, descriptionLine, Font.Normal, ColorScheme.White));
			}
		}