private void Test_Shoot_NullArgs() { GunStatus status = new GunStatus(always1, blunderbuss); Assert.Throws <ArgumentNullException>(() => status.Shoot(null, combatStats)); Assert.Throws <ArgumentNullException>(() => status.Shoot(enemy, null)); }
private void Test_Cost_SingleShotMiss() { Rng always3 = new Rng(3); enemy = new Enemy(30); GunStatus palmPistolStatus = new GunStatus(always3, palmPistol); GunStatus artificerPalmPistolStatus = new GunStatus(always3, artificerPalmPistol); GunStatus pistolStatus = new GunStatus(always3, pistol); GunStatus musketStatus = new GunStatus(always3, musket); GunStatus pepperboxStatus = new GunStatus(always3, pepperbox); GunStatus blunderbussStatus = new GunStatus(always3, blunderbuss); Assert.AreEqual(0, palmPistolStatus.Cost); Assert.AreEqual(0, artificerPalmPistolStatus.Cost); Assert.AreEqual(0, pistolStatus.Cost); Assert.AreEqual(0, musketStatus.Cost); Assert.AreEqual(0, pepperboxStatus.Cost); Assert.AreEqual(0, blunderbussStatus.Cost); palmPistolStatus.Shoot(enemy, combatStats); artificerPalmPistolStatus.Shoot(enemy, combatStats); pistolStatus.Shoot(enemy, combatStats); musketStatus.Shoot(enemy, combatStats); pepperboxStatus.Shoot(enemy, combatStats); blunderbussStatus.Shoot(enemy, combatStats); Assert.AreEqual(10, palmPistolStatus.Cost); Assert.AreEqual(0, artificerPalmPistolStatus.Cost); Assert.AreEqual(20, pistolStatus.Cost); Assert.AreEqual(25, musketStatus.Cost); Assert.AreEqual(20, pepperboxStatus.Cost); Assert.AreEqual(100, blunderbussStatus.Cost); }
private void Test_Cost_Broken() { GunStatus palmPistolStatus = new GunStatus(always1, palmPistol); GunStatus artificerPalmPistolStatus = new GunStatus(always1, artificerPalmPistol); GunStatus pistolStatus = new GunStatus(always1, pistol); GunStatus musketStatus = new GunStatus(always1, musket); GunStatus pepperboxStatus = new GunStatus(always1, pepperbox); GunStatus blunderbussStatus = new GunStatus(always1, blunderbuss); palmPistolStatus.Shoot(enemy, combatStats); artificerPalmPistolStatus.Shoot(enemy, combatStats); pistolStatus.Shoot(enemy, combatStats); musketStatus.Shoot(enemy, combatStats); pepperboxStatus.Shoot(enemy, combatStats); blunderbussStatus.Shoot(enemy, combatStats); palmPistolStatus.FixMisfire(0); artificerPalmPistolStatus.FixMisfire(0); pistolStatus.FixMisfire(0); musketStatus.FixMisfire(0); pepperboxStatus.FixMisfire(0); blunderbussStatus.FixMisfire(0); Assert.AreEqual(1260, palmPistolStatus.Cost); Assert.AreEqual(1250, artificerPalmPistolStatus.Cost); Assert.AreEqual(3770, pistolStatus.Cost); Assert.AreEqual(7525, musketStatus.Cost); Assert.AreEqual(6270, pepperboxStatus.Cost); Assert.AreEqual(7600, blunderbussStatus.Cost); }
void LockMissileInit()//ロックオンミサイルの初期化 { p_RigiTank = gTank.GetComponent <Rigidbody>(); p_RigiBattery = gBattery.GetComponent <Rigidbody>(); p_GunStatus = GetComponent <GunStatus>(); p_GunStatus.isEnemyShot = true; }
private void Test_Cost_MultipleShots() { GunStatus palmPistolStatus = new GunStatus(always10, palmPistol); GunStatus artificerPalmPistolStatus = new GunStatus(always10, artificerPalmPistol); GunStatus pistolStatus = new GunStatus(always10, pistol); GunStatus musketStatus = new GunStatus(always10, musket); GunStatus pepperboxStatus = new GunStatus(always10, pepperbox); GunStatus blunderbussStatus = new GunStatus(always10, blunderbuss); MultipleFire(enemy, combatStats, palmPistolStatus, 10); //clip size 1 -> 10 rnds for (int i = 0; i < 10; i++) //Never reloads! { artificerPalmPistolStatus.Shoot(enemy, combatStats); } MultipleFire(enemy, combatStats, pistolStatus, 10); //clip size 4 -> 40 rnds MultipleFire(enemy, combatStats, musketStatus, 10); //clip size 1 -> 10 rnds MultipleFire(enemy, combatStats, pepperboxStatus, 10); //clip size 6 -> 60 rnds MultipleFire(enemy, combatStats, blunderbussStatus, 10); //clip size 1 -> 10 rnds Assert.AreEqual(100, palmPistolStatus.Cost); Assert.AreEqual(0, artificerPalmPistolStatus.Cost); //free ammo :D Assert.AreEqual(800, pistolStatus.Cost); Assert.AreEqual(250, musketStatus.Cost); Assert.AreEqual(1200, pepperboxStatus.Cost); Assert.AreEqual(1000, blunderbussStatus.Cost); }
public void AimDownSights(bool aim) { if (status == GunStatus.reloading) { return; } status = (aim) ? GunStatus.aiming : GunStatus.idle; }
private void Test_ReloadChamber_GunMisfired() { GunStatus status = new GunStatus(always1, pepperbox); status.Shoot(enemy, combatStats); //shoot, will misfire Assert.Throws <ArgumentException>(() => status.ReloadChamber()); }
private void Test_CanFire_GunMisfired() { GunStatus status = new GunStatus(always1, pepperbox); status.Shoot(enemy, combatStats); //shoot, will misfire Assert.IsTrue(!status.CanFire()); }
private void Test_HasShotLoaded_NoAmmo() { GunStatus status = new GunStatus(always10, palmPistol); status.Shoot(enemy, combatStats); Assert.IsTrue(!status.HasShotLoaded()); }
private void Test_Shoot_NoShotLoaded() { GunStatus status = new GunStatus(always1, palmPistol); status.Shoot(enemy, combatStats); Assert.Throws <ArgumentException>(() => status.Shoot(enemy, combatStats)); Assert.IsTrue(!status.HasShotLoaded()); }
private void Test_FixMisfire_GunBroken() { GunStatus status = new GunStatus(always1, pepperbox); status.Shoot(enemy, combatStats); //shoot, will misfire status.FixMisfire(0); //try fix, will get broke Assert.Throws <ArgumentException>(() => status.FixMisfire(3)); }
private void Test_CanFire_GunBroken() { GunStatus status = new GunStatus(always1, pepperbox); status.Shoot(enemy, combatStats); //shoot, will misfire status.FixMisfire(0); //try fix, will get broke Assert.IsTrue(!status.CanFire()); }
private void Test_FixMisfire_Fail() { GunStatus status = new GunStatus(always1, pepperbox); status.Shoot(enemy, combatStats); //shoot, will misfire Assert.DoesNotThrow(() => status.FixMisfire(0)); Assert.AreEqual(GunFiringStatus.Broken, status.Status); Assert.IsTrue(!status.CanFire()); }
private void Test_FixMisfire_NegativeProf() { GunStatus status = new GunStatus(always1, pepperbox); status.Shoot(enemy, combatStats); //shoot, will misfire Assert.Throws <ArgumentException>(() => status.FixMisfire(-1)); Assert.Throws <ArgumentException>(() => status.FixMisfire(-63)); Assert.Throws <ArgumentException>(() => status.FixMisfire(int.MinValue)); }
private void Test_Shoot_SuccessiveShootsDoNotChangeMods() { GunStatus status = new GunStatus(always20, pepperbox); status.Shoot(enemy, combatStats); status.Shoot(enemy, combatStats); status.Shoot(enemy, combatStats); Assert.AreEqual(0, pepperbox.HitModifier.Get()); }
private void Test_Shoot_Misfire() { GunStatus status = new GunStatus(always1, pepperbox); AttackSummary summary = null; Assert.DoesNotThrow(() => summary = status.Shoot(enemy, combatStats)); Assert.AreEqual(GunFiringStatus.Misfired, status.Status); Assert.IsTrue(!status.CanFire()); Assert.IsNotNull(summary); }
public override void OnInspectorGUI() { GunStatus p_Gun = target as GunStatus; p_Gun.isEnemy = EditorGUILayout.Toggle("敵用ですか?", p_Gun.isEnemy); if (p_Gun.isEnemy == false) { p_Gun.strInput[0] = EditorGUILayout.TextField("左のコントローラーの名前", p_Gun.strInput[0]); p_Gun.strTagName[0] = EditorGUILayout.TextField("左手で持ったときのTag名", p_Gun.strTagName[0]); p_Gun.strInput[1] = EditorGUILayout.TextField("右のコントローラーの名前", p_Gun.strInput[1]); p_Gun.strTagName[1] = EditorGUILayout.TextField("右手で持ったときのTag名", p_Gun.strTagName[1]); } else { p_Gun.isEnemyShot = EditorGUILayout.Toggle("敵用のトリガー", p_Gun.isEnemyShot); } p_Gun.fFireRate = EditorGUILayout.FloatField("弾の間隔", p_Gun.fFireRate); EditorGUILayout.LabelField("拡散度"); p_Gun.fSpread = EditorGUILayout.Slider(p_Gun.fSpread, 0.0f, 1.0f); p_Gun.fRange = EditorGUILayout.FloatField("射程", p_Gun.fRange); p_Gun.fDamage = EditorGUILayout.FloatField("ダメージ", p_Gun.fDamage); p_Gun.fBulletSpeed = EditorGUILayout.FloatField("弾の速度", p_Gun.fBulletSpeed); p_Gun.eShotType = (ShotType)EditorGUILayout.EnumPopup("銃の種類", p_Gun.eShotType); p_Gun.fReloadTime = EditorGUILayout.FloatField("リロードにかかる時間", p_Gun.fReloadTime); p_Gun.clipSize = EditorGUILayout.IntField("最大装填数", p_Gun.clipSize); p_Gun.ammoMax = EditorGUILayout.IntField("弾の最大所持数", p_Gun.ammoMax); p_Gun.ammo = EditorGUILayout.IntField("現在の装填数", p_Gun.ammo); p_Gun.ammoHave = EditorGUILayout.IntField("現在の弾の所持数", p_Gun.ammoHave); p_Gun.ammoUsep = EditorGUILayout.IntField("一発あたりの消費弾数", p_Gun.ammoUsep); p_Gun.shotPerRound = EditorGUILayout.IntField("発射弾数", p_Gun.shotPerRound); p_Gun.Bullet = EditorGUILayout.ObjectField("発射する弾", p_Gun.Bullet, typeof(GameObject), true) as GameObject; p_Gun.isHitScan = EditorGUILayout.Toggle("ヒットスキャンにするか", p_Gun.isHitScan); p_Gun.tMuzzle = EditorGUILayout.ObjectField("発射位置を指定", p_Gun.tMuzzle, typeof(Transform), true) as Transform; p_Gun.tStartRay = EditorGUILayout.ObjectField("Rayの開始位置", p_Gun.tStartRay, typeof(Transform), true) as Transform; p_Gun.isShell = EditorGUILayout.Toggle("薬莢を出すか", p_Gun.isShell); if (p_Gun.isShell == true) { p_Gun.Shell = EditorGUILayout.ObjectField("薬莢", p_Gun.Shell, typeof(GameObject), true) as GameObject; p_Gun.tShellOuter = EditorGUILayout.ObjectField("薬莢の排出口", p_Gun.tShellOuter, typeof(Transform), true) as Transform; } p_Gun.MuzzleFX = EditorGUILayout.ObjectField("発射エフェクト", p_Gun.MuzzleFX, typeof(GameObject), true) as GameObject; p_Gun.isShotSE = EditorGUILayout.Toggle("弾の発射音を鳴らすか", p_Gun.isShotSE); if (p_Gun.isShotSE == true) { p_Gun.ShotSE = EditorGUILayout.ObjectField("発射時の音", p_Gun.ShotSE, typeof(AudioClip), true) as AudioClip; p_Gun.ShotEndSE = EditorGUILayout.ObjectField("弾切れの音", p_Gun.ShotEndSE, typeof(AudioClip), true) as AudioClip; } }
public void TakeOutWeapon(UnityAction <int> call) { status = GunStatus.takingOut; animator.Play(motions.takeOut, -1, 0); if (listener) { listener.onTakeOut.Invoke(); } onTakeOut.RemoveAllListeners(); onTakeOut.AddListener(call); }
private void Test_HasShotLoaded_InfAmmo() { GunStatus status = new GunStatus(always10, artificerPalmPistol); status.Shoot(enemy, combatStats); //keep shooting status.Shoot(enemy, combatStats); status.Shoot(enemy, combatStats); status.Shoot(enemy, combatStats); status.Shoot(enemy, combatStats); Assert.IsTrue(status.HasShotLoaded()); }
public void PutAwayWeapon(UnityAction call) { forceReload = (status == GunStatus.reloading || NoAmmo()); status = GunStatus.putAway; animator.Play(motions.putAway, -1, 0); if (listener) { listener.onPutAway.Invoke(); } onPutAway.RemoveAllListeners(); onPutAway.AddListener(call); }
IEnumerator RecoverNormalStatus() { yield return(new WaitForEndOfFrame()); if (currentStatus == GunStatus.Fire || currentStatus == GunStatus.Reload) { currentStatus = GunStatus.Normal; } else if (currentStatus == GunStatus.PropFire) { currentStatus = GunStatus.PropNormal; } }
private void Test_Shoot_CannotFire() { GunStatus status = new GunStatus(always1, pepperbox); status.Shoot(enemy, combatStats); //shoot, will misfire Assert.Throws <ArgumentException>(() => status.Shoot(enemy, combatStats)); //shoot, will misfire Assert.AreEqual(GunFiringStatus.Misfired, status.Status); status.FixMisfire(0); //try fix, will get broke Assert.Throws <ArgumentException>(() => status.Shoot(enemy, combatStats)); Assert.AreEqual(GunFiringStatus.Broken, status.Status); }
public bool ReloadGun() { if (CantContinueShooting()) { return(false); } status = GunStatus.reloading; animator.Play(motions.reload, -1, reloadStartPoint); if (gun.looseAmmoOnReload) { ammoInClip = 0; } return(true); }
//id为子弹类型BulletType中的索引值, num为特殊子弹数量 void ChangeAfterBullet(int id, int num) { currentStatus = GunStatus.PropNormal; specialNum = num; exBulletObjs = new GameObject[num]; exBulletRigs = new Rigidbody2D[num]; for (int i = 0; i < num; i++) { exBulletObjs[i] = GameObject.Instantiate(bulletPrefabs[id]); exBulletRigs[i] = exBulletObjs[i].GetComponent <Rigidbody2D>(); exBulletObjs[i].transform.position = this.transform.position; exBulletObjs[i].transform.parent = this.transform; exBulletObjs[i].SetActive(false); } }
private void Test_ReloadChamber_OutOfAmmo() { GunStatus status = new GunStatus(always10, pistol); //shoot x4 to run out of ammo status.Shoot(enemy, combatStats); status.Shoot(enemy, combatStats); status.Shoot(enemy, combatStats); status.Shoot(enemy, combatStats); Assert.IsTrue(!status.HasShotLoaded()); Assert.DoesNotThrow(() => status.ReloadChamber()); Assert.IsTrue(status.HasShotLoaded()); Assert.IsTrue(status.CanFire()); }
private void Test_Shoot_Miss() { GunStatus status = new GunStatus(always3, pepperbox); status.Shoot(enemy, combatStats); AttackSummary summary = null; Assert.DoesNotThrow(() => summary = status.Shoot(enemy, combatStats)); Assert.AreEqual(GunFiringStatus.Okay, status.Status); Assert.IsTrue(status.CanFire()); Assert.IsNotNull(summary); Assert.AreEqual(6, summary.AttackRoll); Assert.AreEqual(0, summary.Damage); Assert.IsTrue(!summary.Hit); Assert.IsTrue(!summary.Crit); }
public void ReloadAmmo() { reloadStartPoint = 0; status = GunStatus.idle; totalAmmo += ammoInClip; totalAmmo -= gun.ammoClip; ammoInClip = gun.ammoClip; if (totalAmmo < 0) { ammoInClip += totalAmmo; totalAmmo = 0; } if (listener) { listener.onReload.Invoke(); } }
private void Test_Shoot_Crit() { GunStatus status = new GunStatus(always20, pepperbox); status.Shoot(enemy, combatStats); AttackSummary summary = null; Assert.DoesNotThrow(() => summary = status.Shoot(enemy, combatStats)); Assert.AreEqual(GunFiringStatus.Okay, status.Status); Assert.IsTrue(status.CanFire()); Assert.IsNotNull(summary); Assert.AreEqual(23, summary.AttackRoll); Assert.AreEqual(42, summary.Damage); //dmg kinda wonky because of always20 Assert.IsTrue(summary.Hit); Assert.IsTrue(summary.Crit); }
private void Start() { MakeBullets(); playerMove = GameObject.Find("Player").GetComponent <PlayerMove>(); currentStatus = GunStatus.Normal; }
private void Update() { mousePos2World = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (Input.GetButtonDown("Fire1") && Time.time > nextShoot) { nextShoot = Time.time + shootDelay; if (currentStatus == GunStatus.Normal) { currentStatus = GunStatus.Fire; StartCoroutine(RecoverNormalStatus()); } else if (currentStatus == GunStatus.PropNormal) { currentStatus = GunStatus.PropFire; StartCoroutine(RecoverNormalStatus()); } } if (Input.GetKeyDown(KeyCode.R) && currentStatus != GunStatus.PropNormal) { currentStatus = GunStatus.Reload; //装弹动画 Animator reloadAnimator = GameObject.Find("ReloadProgress").GetComponent <Animator>(); reloadAnimator.SetTrigger("ReloadStart"); } //开发测试 if (testMode) { //道具测试 if (Input.GetKeyDown(KeyCode.E)) { ChangeAfterBullet(1, 3); } } //有限状态机 switch (currentStatus) { case GunStatus.Fire: hitValue = 1; //获得射击方向 shootDir = (mousePos2World - (Vector2)transform.position).normalized; Launch(shootDir); break; case GunStatus.PropFire: hitValue = 2; shootDir = (mousePos2World - (Vector2)transform.position).normalized; SpecialLaunch(shootDir); break; case GunStatus.Reload: //当弹匣容量满时不能装弹 if (currentNum < bulletsNum) { StartCoroutine(WaitReload()); } else { currentStatus = GunStatus.Normal; } break; case GunStatus.PropNormal: //如果特殊子弹耗尽,转换为Normal状态 if (specialNum == 0) { currentStatus = GunStatus.Normal; } break; default: break; } //Debug.Log("CurrentCharacterStatus = " + currentStatus); }