public bool ConsumeAmmo(AmmunitionTypes ammunitionType) { if (ammunitionCounts[ammunitionType] > 0) { ammunitionCounts[ammunitionType]--; return(true); } else { return(false); } }
public bool ConsumeAmmo(AmmunitionTypes ammunitionType) { if (ammoCounts[ammunitionType] > 0) { ammoCounts[ammunitionType]--; UpdatedAmmoCountUI(); return(true); //we have ammo and we reduced it by one } else { return(false);//if no ammo left return false } }
// Function to be called by ammunitions on hitting this type //this object checks if the ammuntion belongs to the player. //If so, since it is a PlayerCanKill type it accepts the hit. public void OnHit <T>(T hitMessage) { if (typeof(T) == typeof(Ammunition)) { Ammunition ammunition = hitMessage as Ammunition; foreach (PlayerAmmunition ammo in Enum.GetValues(typeof(PlayerAmmunition))) { if (ammo.CastToArtifact <PlayerAmmunition>() == ammunition.AmmunitionType.CastToArtifact <AmmunitionTypes>()) { hitByAmmo = ammunition.AmmunitionType; PlayerTypes playerType = ammunition.ownerType.CastFromArtifact <PlayerTypes>(PlayerTypes.NULL); if (playerType != PlayerTypes.NULL) { hitByPlayer = playerType; hitPower = ammunition.Strength; ReceivePlayerKill(hitByPlayer, hitPower);; } break; } } } }
public IEnumerator DemonTests_TreeDemon_HitByPlayerAmmunition_CorrectAmmoDetection() { //Actual Behavior GameObject testDemon = new GameObject(); testDemon.AddComponent <TreeDemon>(); var playerPrefab = Resources.Load("Tests/Player", typeof(GameObject)) as GameObject; testDemon.GetComponent <TreeDemon>().InitializeDemon(DemonTypes.TreeDemon, 5, playerPrefab, 5.0f); GameObject testAmmo = new GameObject(); testAmmo.AddComponent <Bullet>(); testAmmo.GetComponent <IPlayerAmmunition>().SetPlayerInfo(PlayerTypes.ManRelax, 0.0f); testDemon.GetComponent <TreeDemon>().OnHit(testAmmo); yield return(null); AmmunitionTypes returnedAmmo = testDemon.GetComponent <TreeDemon>().hitByAmmo; //Expected Behavior AmmunitionTypes sentAmmoType = AmmunitionTypes.Bullet; //Assert Assert.AreEqual(returnedAmmo, sentAmmoType); yield return(null); }
public void AddAmmunition(int value, AmmunitionTypes ammunitionType) { ammunitionCounts[ammunitionType] += value; }
public void AddAmmo(int value, AmmunitionTypes ammunitionType) { ammoCounts[ammunitionType] += value; //passing in a type to the dictionary which gives back an int, then add that to value UpdatedAmmoCountUI(); }