/**********************************************************************************/ // функция зарядки оружия // /**********************************************************************************/ void ChargeWeapon(WEAPON_SLOT slot, WEAPON weaponID, int ammo) { List <WEAPON> weaponIds = null; List <ClassicWeaponCtr> weaponCtrs = null; switch (slot) { case WEAPON_SLOT.MAIN: weaponIds = m_mainWeaponIds; weaponCtrs = m_mainWeaponCollection; break; case WEAPON_SLOT.CAPTURE: weaponIds = m_captureWeaponIds; weaponCtrs = m_captureWeaponCollection; break; case WEAPON_SLOT.EXLOSION: weaponIds = m_explosionWeaponIds; weaponCtrs = m_explosionWeaponCollection; break; case WEAPON_SLOT.SPECIAL: weaponIds = m_specialWeaponIds; weaponCtrs = m_specialWeaponCollection; break; } // пробуем найти нужное оружие и устанавливаем его индекс int index = 0; bool wasFind = false; for (; index < weaponIds.Count; index++) { WEAPON id = weaponIds[index]; if (id == weaponID) { wasFind = true; break; } } if (!wasFind) { Debug.LogError("We cant charge weapon: " + weaponID + " in slot: " + slot); return; } // заряжаем оружие и обновляем UI ClassicWeaponCtr wCtr = weaponCtrs[index]; wCtr.ChargeAmmo(ammo); UpdateWeaponSlot(slot); }
/**********************************************************************************/ // устанавливаем оружие в соответсвующие им слоты // /**********************************************************************************/ private void SetWeaponToSlots() { // настраиваем оружие // тентакли ^_^ ClassicWeaponCtr ctr = WeaponLibrary.GetInstance().GetWeaponById(WEAPON.TENTAKLES, playerId); m_mainWeaponCollection.Add(ctr); m_captureWeaponCollection.Add(ctr); m_explosionWeaponCollection.Add(ctr); m_specialWeaponCollection.Add(ctr); m_mainWeaponIds.Add(WEAPON.TENTAKLES); m_captureWeaponIds.Add(WEAPON.TENTAKLES); m_explosionWeaponIds.Add(WEAPON.TENTAKLES); m_specialWeaponIds.Add(WEAPON.TENTAKLES); // кислотная пушка ctr = WeaponLibrary.GetInstance().GetWeaponById(WEAPON.ACID_GUN, playerId); ctr.ChargeAmmo(ctr.NumberOfBullet); m_mainWeaponCollection.Add(ctr); m_mainWeaponIds.Add(WEAPON.ACID_GUN); // дробовик ctr = WeaponLibrary.GetInstance().GetWeaponById(WEAPON.SHOTGUN, playerId); ctr.ChargeAmmo(0); m_mainWeaponCollection.Add(ctr); m_mainWeaponIds.Add(WEAPON.SHOTGUN); // бластер ctr = WeaponLibrary.GetInstance().GetWeaponById(WEAPON.BLUSTER, playerId); ctr.ChargeAmmo(0); m_mainWeaponCollection.Add(ctr); m_mainWeaponIds.Add(WEAPON.BLUSTER); // слизь ctr = WeaponLibrary.GetInstance().GetWeaponById(WEAPON.MOCUS, playerId); ctr.ChargeAmmo(3); m_captureWeaponCollection.Add(ctr); m_captureWeaponIds.Add(WEAPON.MOCUS); // гранаты РГД ctr = WeaponLibrary.GetInstance().GetWeaponById(WEAPON.RGD_GRENADE, playerId); ctr.ChargeAmmo(0); m_explosionWeaponCollection.Add(ctr); m_explosionWeaponIds.Add(WEAPON.RGD_GRENADE); // гранаты плазменные ctr = WeaponLibrary.GetInstance().GetWeaponById(WEAPON.PLASMA_GRENADE, playerId); ctr.ChargeAmmo(0); m_explosionWeaponCollection.Add(ctr); m_explosionWeaponIds.Add(WEAPON.PLASMA_GRENADE); // строитель турелей ctr = WeaponLibrary.GetInstance().GetWeaponById(WEAPON.TUREL_BUILDER, playerId); ctr.ChargeAmmo(0); m_specialWeaponCollection.Add(ctr); m_specialWeaponIds.Add(WEAPON.TUREL_BUILDER); // обновляем оружейные слоты UpdateWeaponSlot(WEAPON_SLOT.ALL); }
/**********************************************************************************/ // обновляем оружейную систему // /**********************************************************************************/ protected void UpdateWeaponSlot(WEAPON_SLOT slot) { // перебираем коллекцию вооружения с конца к началу // первое (наиболее технологичное) оружие с боезапасом устанавливается в слот // определяемся со списком оружейных слотов на обновление List <WEAPON_SLOT> slotsToUpdate; if (slot == WEAPON_SLOT.ALL) { slotsToUpdate = new List <WEAPON_SLOT> { WEAPON_SLOT.MAIN, WEAPON_SLOT.CAPTURE, WEAPON_SLOT.EXLOSION, WEAPON_SLOT.SPECIAL }; } else { slotsToUpdate = new List <WEAPON_SLOT> { slot }; } // производим обновление foreach (var updatedSlot in slotsToUpdate) { // выбираем элементы, с которыми нам предстоит работать List <ClassicWeaponCtr> weaponCollerction; List <WEAPON> weaponIdsCollection; PlayerInputCtr.CTR_KEY KeyToBlock; switch (updatedSlot) { case WEAPON_SLOT.MAIN: weaponCollerction = m_mainWeaponCollection; weaponIdsCollection = m_mainWeaponIds; KeyToBlock = PlayerInputCtr.CTR_KEY.FIRE_1; break; case WEAPON_SLOT.CAPTURE: weaponCollerction = m_captureWeaponCollection; weaponIdsCollection = m_captureWeaponIds; KeyToBlock = PlayerInputCtr.CTR_KEY.FIRE_2; break; case WEAPON_SLOT.EXLOSION: weaponCollerction = m_explosionWeaponCollection; weaponIdsCollection = m_explosionWeaponIds; KeyToBlock = PlayerInputCtr.CTR_KEY.FIRE_3; break; case WEAPON_SLOT.SPECIAL: weaponCollerction = m_specialWeaponCollection; weaponIdsCollection = m_specialWeaponIds; KeyToBlock = PlayerInputCtr.CTR_KEY.FIRE_4; break; default: Debug.LogError("Unexpected weapon slot: " + updatedSlot); return; } // итерируем по всеми списку вооружения в поисках подходящего элемента for (int i = weaponCollerction.Count - 1; i >= 0; i--) { ClassicWeaponCtr ctr = weaponCollerction[i]; if (ctr.State != WeaponController.WEAPON_STATE.EMPTY) { switch (updatedSlot) { case WEAPON_SLOT.MAIN: m_mainWeaponCtr = ctr; break; case WEAPON_SLOT.CAPTURE: m_captureWeaponCtr = ctr; break; case WEAPON_SLOT.EXLOSION: m_explosionWeaponCtr = ctr; break; case WEAPON_SLOT.SPECIAL: m_specialWeaponCtr = ctr; break; } UIController.GetInstance().SetWeaponInSlot((int)playerId, updatedSlot, weaponIdsCollection[i]); m_inputCtr.BlockButton(KeyToBlock); break; } } } }
/**********************************************************************************/ // GetWeaponById - возвращает копию контроллера по указанному ID // /**********************************************************************************/ public ClassicWeaponCtr GetWeaponById(WEAPON weaponId, PLAYER ownerID) { ClassicWeaponCtr ctr = null; if (weaponId == WEAPON.TENTAKLES && ownerID == PLAYER.PL1) { RegeneratedWeaponCtr tentakles = new RegeneratedWeaponCtr((int)ownerID); tentakles.BulletType = TentaclesWeapon_Pl1.BulletType; tentakles.FireRechargeTime = TentaclesWeapon_Pl1.FireRechargeTime; tentakles.MagazineAmmo = TentaclesWeapon_Pl1.MagazineAmmo; tentakles.NumberOfBullet = TentaclesWeapon_Pl1.NumberOfBullet; tentakles.TimeToRegenerateAmmo = TentaclesWeapon_Pl1.TimeToRegenerateAmmo; ctr = tentakles; } else if (weaponId == WEAPON.TENTAKLES && ownerID == PLAYER.PL2) { RegeneratedWeaponCtr tentakles = new RegeneratedWeaponCtr((int)ownerID); tentakles.BulletType = TentaclesWeapon_Pl2.BulletType; tentakles.FireRechargeTime = TentaclesWeapon_Pl2.FireRechargeTime; tentakles.MagazineAmmo = TentaclesWeapon_Pl2.MagazineAmmo; tentakles.NumberOfBullet = TentaclesWeapon_Pl2.NumberOfBullet; tentakles.TimeToRegenerateAmmo = TentaclesWeapon_Pl2.TimeToRegenerateAmmo; ctr = tentakles; } else if (weaponId == WEAPON.BLUSTER) { ClassicWeaponCtr wCtr = new ClassicWeaponCtr((int)ownerID); wCtr.BulletType = BlusterWeapon.BulletType; wCtr.FireRechargeTime = BlusterWeapon.FireRechargeTime; wCtr.MagazineAmmo = BlusterWeapon.MagazineAmmo; wCtr.NumberOfBullet = BlusterWeapon.NumberOfBullet; ctr = wCtr; } else if (weaponId == WEAPON.ACID_GUN) { ClassicWeaponCtr wCtr = new ClassicWeaponCtr((int)ownerID); wCtr.BulletType = AcidGun.BulletType; wCtr.FireRechargeTime = AcidGun.FireRechargeTime; wCtr.MagazineAmmo = AcidGun.MagazineAmmo; wCtr.NumberOfBullet = AcidGun.NumberOfBullet; ctr = wCtr; } else if (weaponId == WEAPON.SHOTGUN) { ClassicWeaponCtr wCtr = new ClassicWeaponCtr((int)ownerID); wCtr.BulletType = ShotGun.BulletType; wCtr.FireRechargeTime = ShotGun.FireRechargeTime; wCtr.MagazineAmmo = ShotGun.MagazineAmmo; wCtr.NumberOfBullet = ShotGun.NumberOfBullet; ctr = wCtr; } else if (weaponId == WEAPON.MOCUS && ownerID == PLAYER.PL1) { ClassicWeaponCtr wCtr = new ClassicWeaponCtr((int)ownerID); wCtr.BulletType = MocusGun_Pl1.BulletType; wCtr.FireRechargeTime = MocusGun_Pl1.FireRechargeTime; wCtr.MagazineAmmo = MocusGun_Pl1.MagazineAmmo; wCtr.NumberOfBullet = MocusGun_Pl1.NumberOfBullet; ctr = wCtr; } else if (weaponId == WEAPON.MOCUS && ownerID == PLAYER.PL2) { ClassicWeaponCtr wCtr = new ClassicWeaponCtr((int)ownerID); wCtr.BulletType = MocusGun_Pl2.BulletType; wCtr.FireRechargeTime = MocusGun_Pl2.FireRechargeTime; wCtr.MagazineAmmo = MocusGun_Pl2.MagazineAmmo; wCtr.NumberOfBullet = MocusGun_Pl2.NumberOfBullet; ctr = wCtr; } else if (weaponId == WEAPON.PLASMA_GRENADE) { ClassicWeaponCtr wCtr = new ClassicWeaponCtr((int)ownerID); wCtr.BulletType = PlasmaGrenade.BulletType; wCtr.FireRechargeTime = PlasmaGrenade.FireRechargeTime; wCtr.MagazineAmmo = PlasmaGrenade.MagazineAmmo; wCtr.NumberOfBullet = PlasmaGrenade.NumberOfBullet; ctr = wCtr; } else if (weaponId == WEAPON.RGD_GRENADE) { ClassicWeaponCtr wCtr = new ClassicWeaponCtr((int)ownerID); wCtr.BulletType = RGDGrenade.BulletType; wCtr.FireRechargeTime = RGDGrenade.FireRechargeTime; wCtr.MagazineAmmo = RGDGrenade.MagazineAmmo; wCtr.NumberOfBullet = RGDGrenade.NumberOfBullet; ctr = wCtr; } else if (weaponId == WEAPON.TUREL_BUILDER && ownerID == PLAYER.PL1) { ClassicWeaponCtr wCtr = new ClassicWeaponCtr((int)ownerID); wCtr.BulletType = TurelBuilder_Pl1.BulletType; wCtr.FireRechargeTime = TurelBuilder_Pl1.FireRechargeTime; wCtr.MagazineAmmo = TurelBuilder_Pl1.MagazineAmmo; wCtr.NumberOfBullet = TurelBuilder_Pl1.NumberOfBullet; ctr = wCtr; } else if (weaponId == WEAPON.TUREL_BUILDER && ownerID == PLAYER.PL2) { ClassicWeaponCtr wCtr = new ClassicWeaponCtr((int)ownerID); wCtr.BulletType = TurelBuilder_Pl2.BulletType; wCtr.FireRechargeTime = TurelBuilder_Pl2.FireRechargeTime; wCtr.MagazineAmmo = TurelBuilder_Pl2.MagazineAmmo; wCtr.NumberOfBullet = TurelBuilder_Pl2.NumberOfBullet; ctr = wCtr; } return(ctr); }