// Ammo checks
 private void SafetyAmmo(GunDefinition gun)
 {
     if (!_ammo.ContainsKey(gun))
     {
         _ammo.Add(gun, 0);
     }
 }
        protected override void ActionLocal(CommandCaller caller, Player player, string input, string[] args)
        {
            CSPlayer csPlayer = CSPlayer.Get(player);

            if (args.Length == 0)
            {
                Main.NewTextMultiline(Usage, c: Color.Red);
                return;
            }

            args[0] = args[0].ToLower();

            if (args[0].Equals("-a"))
            {
                List <string> ammo = new List <string>();

                foreach (GunDefinition gun in csPlayer.OwnedAmmo())
                {
                    ammo.Add($"{gun.UnlocalizedName}:{csPlayer.GetAmmo(gun)}");
                }
            }
            else
            {
                GunDefinition definition = GunDefinitions.Instance.FindGeneric(g => g.UnlocalizedName.Equals(args[0], StringComparison.CurrentCultureIgnoreCase));

                if (definition == default)
                {
                    Main.NewText($"Specified gun `{args[0]}` doesn't exist.", Color.Red);
                    return;
                }

                Main.NewText($"{definition.UnlocalizedName}:{csPlayer.GetAmmo(definition)}");
            }
        }
        protected override void ActionLocal(CommandCaller caller, Player player, string input, string[] args)
        {
            if (args.Length == 0)
            {
                Main.NewText(Usage, Color.Red);
                return;
            }


            GunDefinition definition = GunDefinitions.Instance.FindGeneric(g => g.UnlocalizedName.Equals(args[0], StringComparison.CurrentCultureIgnoreCase));

            if (definition == default)
            {
                Main.NewText($"Gun name '{args[0]} is invalid. Use /cs_guns for a list of guns.");
                return;
            }


            CSPlayer csPlayer = CSPlayer.Get(player);

            if (csPlayer.Money < definition.Price)
            {
                Main.NewText($"Specified gun '{args[0]}' is too costly. Use /cs_guns -a for a list of guns you can buy.");
                return;
            }


            csPlayer.TryBuyGun(definition);
        }
Exemple #4
0
    IEnumerator FireSequence(GunDefinition gun)
    {
        while (true)
        {
            yield return(new WaitForSeconds(gun.GetNextFire()));

            gun.Fire();
        }
    }
Exemple #5
0
 public static NewFireEvent FromEnemy(Vector2 startPosition, GunDefinition gunDefinition)
 {
     return(new NewFireEvent
     {
         eventName = NewFireFromEnemyEvent,
         StartPosition = startPosition,
         GunDefinition = gunDefinition
     });
 }
        public bool TryBuyAmmo(GunDefinition gun)
        {
            if (!HasSpaceForAmmo(gun) || gun.BulletCost > Money)
            {
                return(false);
            }

            BuyAmmo(gun);
            return(true);
        }
Exemple #7
0
 public EnemyViewModel(string id, string name, int speed, int scorePoints, int health,
                       PathDefinition pathDefinition, GunDefinition gunDefinition)
 {
     Id             = id;
     Name           = name;
     Speed          = speed;
     ScorePoints    = scorePoints;
     Health         = health;
     PathDefinition = pathDefinition;
     GunDefinition  = gunDefinition;
 }
        public void ConsumeAmmo(GunDefinition gun, int amount)
        {
            var current = GetAmmo(gun);

            if (current - amount < 0)
            {
                throw new Exception("Tried consumming more ammo than the player has!");
            }

            _ammo[gun]--;
        }
Exemple #9
0
 public void Execute(Vector2 startPosition, GunDefinition gunDefinition)
 {
     for (var i = 0; i < gunDefinition.AmountBullets; i++)
     {
         var gunView = collisionInstantiator.Execute <GunView>(gunDefinition);
         gunView.MainRectTransform.SetParent(GameProvider.GetGameView().GetShootsContainer());
         gunView.MainRectTransform.anchoredPosition = gunView.MainRectTransform.InverseTransformPoint(startPosition);
         gunView.MainRectTransform.ScaleOne();
         gunView.Init(gunDefinition, false);
     }
 }
Exemple #10
0
 private static GunDto ToGunDto(Func <Object, string> getAssetPath, GunDefinition gun)
 {
     return(new GunDto
     {
         Name = gun.Name,
         Damage = gun.Damage,
         ResourcePath = getAssetPath(gun.Prefab),
         ToPosition = gun.ToPosition,
         Speed = gun.Speed,
         AmountBullets = gun.AmountBullets
     });
 }
        public int BuyMostAmmo(GunDefinition gun)
        {
            int toBuy = GetMissingAmmo(gun);

            while (toBuy * gun.BulletCost > Money && toBuy > 0)
            {
                toBuy--;
            }

            BuyAmmo(gun, toBuy);
            return(toBuy);
        }
        private void DrawGun(GunDefinition gunDefinition)
        {
            var serializedObject = new SerializedObject(gunDefinition);

            EditorGUILayout.PropertyField(serializedObject.FindProperty("Name"), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("Damage"), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("AmountBullets"), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("Prefab"), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("ToPosition"), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("Speed"), true);
            serializedObject.ApplyModifiedProperties();
        }
        private void LoadAmmo(TagCompound tag)
        {
            foreach (KeyValuePair <string, object> ammoTag in tag.GetCompound(AMMO_TAG))
            {
                GunDefinition gun = GunDefinitions.Instance.FindGeneric(g => g.UnlocalizedName.Equals(ammoTag.Key, StringComparison.CurrentCultureIgnoreCase));

                if (gun == default)
                {
                    continue;
                }

                _ammo.Add(gun, int.Parse(ammoTag.Value.ToString()));
            }
        }
Exemple #14
0
        public void Init(GunDefinition gunDefinition, bool enhancedGun)
        {
            this.enhancedGun = enhancedGun;
            presenter.Init(gunDefinition);

            if (enhancedGun)
            {
                CollisionTarget.gameObject.SetActive(false);
                for (var i = 0; i < EnhancedGunContainer.childCount; i++)
                {
                    EnhancedGunContainer.GetChild(i).gameObject.SetActive(true);
                }
                EnhancedGunContainer.gameObject.SetActive(true);
            }
        }
        public bool TryFillAmmo(GunDefinition gun)
        {
            GetAmmoCost(gun, out var buyable, out var cost);

            // HasSpaceForAmmo is redundant since it uses GetBuyableAmmo.
            if (!HasSpaceForAmmo(gun, buyable) || cost > Money)
            {
                return(false);
            }

            if (cost == 0)
            {
                return(true);
            }

            BuyAmmo(gun, buyable);
            Money -= (int)Math.Ceiling(cost);

            return(true);
        }
    public void OnChange(GunDefinition newGunDef)
    {
        currentGun    = newGunDef;
        usingAds      = false;
        continousFire = 0;
        currentAcc    = currentGun.maxAccuracy;
        if (currentGun.burstOnly)
        {
            usingBurst = true;
        }
        else
        {
            usingBurst = false;
        }

        rateOfFire = 1 / currentGun.firingRate;
        fireTimer  = rateOfFire;
        ammoLeft   = true;
        // Debug.Log("Gun name " + currentGun.gunName + ". Max ammo = " + currentGun.maxAmmo + ". FireTimer " + fireTimer);
    }
 public BuyMenuButton(string text, GunDefinition gun) : base(Main.magicPixel)
 {
     OptionName = text;
     Gun        = gun;
 }
 public void Init(GunDefinition gunDefinition, bool enhancedGun)
 {
     presenter.Init(gunDefinition);
 }
 public bool HasAmmo(GunDefinition gun) => GetAmmo(gun) > 0;
 public void Start()
 {
     currentGun = allGuns[currentGunIndex];
     egb        = egb.GetComponent <EquippedGunBehaviour>();
     egb.OnChange(allGuns[currentGunIndex]);
 }
 public bool UIBuyGun(GunDefinition gun)
 {
     if (player.inventory.Find <GunItem>(i => i.modItem is GunItem item && item.Definition == gun) == default)
 public int GetMaxAmmo(GunDefinition gun) => GetMaxClips(gun) * gun.MagazineSize;
 public BuyOption(string optionName, GunDefinition gun) : base(optionName, gun)
 {
     Gun = gun;
 }
 public int GetMaxClips(GunDefinition gun) => gun.StartingMagazineCount + SpareClips;
Exemple #25
0
 public void Init(GunDefinition gunDefinition)
 {
     this.gunDefinition = gunDefinition;
 }
 public float GetMaxMagazines(GunDefinition gun) => GetMaxAmmo(gun) / (float)gun.MagazineSize;
        public int GetMissingAmmo(GunDefinition gun)
        {
            SafetyAmmo(gun);

            return(GetMaxAmmo(gun) - GetAmmo(gun));
        }
 public bool HasSpaceForAmmo(GunDefinition gun, int ammoCount = 1) => GetMissingAmmo(gun) >= ammoCount;
        // Buying
        private void BuyAmmo(GunDefinition gun, int count = 1)
        {
            SafetyAmmo(gun);

            _ammo[gun] += count;
        }
 public void GetAmmoCost(GunDefinition gun, out int buyable, out float cost)
 {
     buyable = GetMissingAmmo(gun);
     cost    = gun.BulletCost * buyable;
 }