public void nextWeapon() { weaponsArsenal[activeWeaponIndex].deactivate(); BasicWeapon findedWeapon = null; int cycleCount = 0; while (cycleCount < cycleTotalCount) { cycleCount++; activeWeaponIndex++; if (activeWeaponIndex == weaponsArsenal.Count) { activeWeaponIndex = 0; } if (weaponsArsenal[activeWeaponIndex].getLevel() > 0) { findedWeapon = weaponsArsenal[activeWeaponIndex]; break; } } if (findedWeapon != null) { findedWeapon.activate(); findedWeapon.prepareWeapon(); } else { //Error Loger } }
// Switches to the given weapon index in weapon slots if the new index is a valid weapon that is different from our current one public void SwitchToWeaponIndex(int newWeaponIndex, bool force = false) { if (force || (newWeaponIndex != activeWeaponIndex && newWeaponIndex >= 0)) { // Store data related to weapon switching animation m_WeaponSwitchNewWeaponIndex = newWeaponIndex; m_TimeStartedWeaponSwitch = Time.time; // Handle case of switching to a valid weapon for the first time (simply put it up without putting anything down first) if (GetActiveWeapon() == null) { m_WeaponMainLocalPosition = downWeaponPosition.localPosition; m_WeaponSwitchState = WeaponSwitchState.PutUpNew; activeWeaponIndex = m_WeaponSwitchNewWeaponIndex; BasicWeapon newWeapon = GetWeaponAtSlotIndex(m_WeaponSwitchNewWeaponIndex); if (onSwitchedToWeapon != null) { onSwitchedToWeapon.Invoke(newWeapon); } } // otherwise, remember we are putting down our current weapon for switching to the next one else { m_WeaponSwitchState = WeaponSwitchState.PutDownPrevious; } } }
void Start() { EventManager.onEnemyDeath += EnemyDied; EventManager.onEnemyArrivedInTown += EnemyArrivedInTown; itemsCol = GameManager.instance.itemsCollection.items; weapon = weaponGO.GetComponent <BasicWeapon>(); }
void StartShooting(BasicWeapon weapon) { //If we have more GUNS!!!! than we can do //here a fancy swicht but for to guns....NOT if (weapon.getWeaponType() == BasicWeapon.Type.SHOTGUN) { if (canPlayShotSound) { canPlayShotSound = false; StartCoroutine(waitForNextShotSound(playTime)); audioSources [1].clip = shotgun; audioSources [1].Play(); } } else { if (canPlayShotSound) { canPlayShotSound = false; StartCoroutine(waitForNextShotSound(0.5f)); audioSources [1].clip = pistol; audioSources [1].Play(); } } }
public override void SetComponents() { base.SetComponents(); _weapon = transform.parent.GetComponent <NetworkElement> ().weapon; _weapon.Damage *= 2; _lateTime = _weapon.BulletPerShoot * _weapon.WaitTime + 1f; }
void OnPickupWeapon(BasicWeapon BasicWeapon, int index) { if (index != 0) { CreateNotification("Picked up weapon : " + BasicWeapon.weaponName); } }
void OnWeaponSwitched(BasicWeapon newWeapon) { if (newWeapon != null) { newWeapon.ShowWeapon(true); } }
public bool RemoveWeapon(BasicWeapon weaponInstance) { // Look through our slots for that weapon for (int i = 0; i < m_WeaponSlots.Length; i++) { // when weapon found, remove it if (m_WeaponSlots[i] == weaponInstance) { m_WeaponSlots[i] = null; if (onRemovedWeapon != null) { onRemovedWeapon.Invoke(weaponInstance, i); } Destroy(weaponInstance.gameObject); // Handle case of removing active weapon (switch to next weapon) if (i == activeWeaponIndex) { SwitchWeapon(true); } return(true); } } return(false); }
public void GetWeaponInfo() { BasicWeapon localWeapon = Weapons[WeaponID]; NameWeaponText.text = localWeapon.CorrectName; DamageText.text = localWeapon.Damage + " | " + localWeapon.BulletPerShoot; DistantText.text = localWeapon.NormalDist + " | " + localWeapon.MaxDist; WeaponImage.sprite = localWeapon.GetComponent <SpriteRenderer>().sprite; }
public void SetElements() { transform.position = GridABS.NodeFromWorldPoint(transform.position).UnitPosition; GridABS.NodeFromWorldPoint(transform.position).UnitOnNode = this; unit = GetComponentInChildren <BasicUnit> (); weapon = GetComponentInChildren <BasicWeapon> (); unit.gameObject.name = unit.CorrectName; weapon.gameObject.name = weapon.CorrectName; unit.SetComponents(); }
// Use this for initialization void Start() { if (playerObject == null) { Debug.LogError("You forgett the player, dick ass!"); } this.currentGun = new Shotgun(); this.controller = GetComponent <CharacterController>(); this.txt = GetComponent <Text>(); }
void AddWeapon(BasicWeapon newWeapon, int weaponIndex) { GameObject ammoCounterInstance = Instantiate(ammoCounterPrefab, ammosPanel); AmmoCounter newAmmoCounter = ammoCounterInstance.GetComponent <AmmoCounter>(); DebugUtility.HandleErrorIfNullGetComponent <AmmoCounter, WeaponHUDManager>(newAmmoCounter, this, ammoCounterInstance.gameObject); newAmmoCounter.Initialize(newWeapon, weaponIndex); m_AmmoCounters.Add(newAmmoCounter); }
public override void LoadContent() { Texture2D playerSprite = game.Content.Load <Texture2D>("PlayerSpriteSheet"); background = game.Content.Load <Texture2D>("RightBG"); Controls controls = Game1.rightControls; Control = controls; BasicWeapon = new BasicWeapon(game.Content.Load <Texture2D>("Bullet"), game.Content.Load <SoundEffect>("GameSounds/playershoot")); player = new RightPlayer(playerSprite, controls); MobSpawner.LoadContent(game); }
public void Shoot(BasicWeapon controller) { owner = controller.owner; initialPosition = transform.position; initialDirection = transform.forward; inheritedMuzzleVelocity = controller.muzzleWorldVelocity; initialCharge = controller.currentCharge; if (onShoot != null) { onShoot.Invoke(); } }
public bool HasWeapon(BasicWeapon weaponPrefab) { // Checks if we already have a weapon coming from the specified prefab foreach (var w in m_WeaponSlots) { if (w != null && w.sourcePrefab == weaponPrefab.gameObject) { return(true); } } return(false); }
public void Initialize(BasicWeapon weapon, int weaponIndex) { m_Weapon = weapon; weaponCounterIndex = weaponIndex; weaponImage.sprite = weapon.weaponIcon; m_PlayerWeaponsManager = FindObjectOfType <PlayerWeaponsManager>(); DebugUtility.HandleErrorIfNullFindObject <PlayerWeaponsManager, AmmoCounter>(m_PlayerWeaponsManager, this); weaponIndexText.text = (weaponCounterIndex + 1).ToString(); FillBarColorChange.Initialize(1f, m_Weapon.GetAmmoNeededToShoot()); }
// Adds a weapon to our inventory public bool AddWeapon(BasicWeapon weaponPrefab) { // if we already hold this weapon type (a weapon coming from the same source prefab), don't add the weapon if (HasWeapon(weaponPrefab)) { return(false); } // search our weapon slots for the first free one, assign the weapon to it, and return true if we found one. Return false otherwise for (int i = 0; i < m_WeaponSlots.Length; i++) { // only add the weapon if the slot is free if (m_WeaponSlots[i] == null) { // spawn the weapon prefab as child of the weapon socket BasicWeapon weaponInstance = Instantiate(weaponPrefab, weaponParentSocket); weaponInstance.transform.localPosition = Vector3.zero; weaponInstance.transform.localRotation = Quaternion.identity; // Set owner to this gameObject so the weapon can alter projectile/damage logic accordingly weaponInstance.owner = gameObject; weaponInstance.sourcePrefab = weaponPrefab.gameObject; weaponInstance.ShowWeapon(false); // Assign the first person layer to the weapon int layerIndex = Mathf.RoundToInt(Mathf.Log(FPSWeaponLayer.value, 2)); // This function converts a layermask to a layer index foreach (Transform t in weaponInstance.gameObject.GetComponentsInChildren <Transform>(true)) { t.gameObject.layer = layerIndex; } m_WeaponSlots[i] = weaponInstance; if (onAddedWeapon != null) { onAddedWeapon.Invoke(weaponInstance, i); } return(true); } } // Handle auto-switching to weapon if no weapons currently if (GetActiveWeapon() == null) { SwitchWeapon(true); } return(false); }
private WorldLoader makeWorld(List <ChallengeStats> blockStats, Size realityBubbleSize) { double worldHeight = 2000; double worldWidth = 0; foreach (ChallengeStats stats in blockStats) { worldWidth += stats.Width; } Size size = new Size(worldWidth, worldHeight);; WorldLoader worldLoader = new WorldLoader(size, realityBubbleSize); double blockX = 0; Dictionary <int, WeaponStats> weaponsByLevel = new Dictionary <int, WeaponStats>(); foreach (ChallengeStats stats in blockStats) { double blockWidth = stats.Width; int numEnemies = stats.NumEnemies; BasicWeapon basicWeapon = new BasicWeapon(); int weaponLevel = (int)stats.EnemyWeaponLevel; if (!weaponsByLevel.ContainsKey(weaponLevel)) { weaponsByLevel[weaponLevel] = this.makeWeapon(weaponLevel); } WeaponStats weaponStats = weaponsByLevel[weaponLevel]; for (int i = 0; i < stats.NumEnemies; i++) { double enemyX = this.randomGenerator.NextDouble() * blockWidth + blockX; double enemyY = this.randomGenerator.NextDouble() * worldHeight / 4; int enemyIntelligence = (int)stats.EnemyIntelligence; enemyIntelligence = Math.Max(Math.Min(enemyIntelligence, 1), 0); double enemyHitpoints = stats.EnemyHitpoints; Enemy enemy = new Enemy(ImageLoader.loadImage("archer.png"), new Point(enemyX, enemyY), new GameRectangle(26, 41), new double[] { stats.EnemyAcceleration, 0 }, stats.EnemyHitpoints, 950, enemyIntelligence); worldLoader.addItem(enemy); } blockX += blockWidth; } return(worldLoader); }
static public int GetIdFromWeapon(BasicWeapon weapon) { if (weaponNamesArray.Length == 0) { GetWeaponArray(); } for (int i = 0; i < weaponNamesArray.Length; i++) { if (weapon.CorrectName == weaponNamesArray[i]) { return(i); } } return(-1); }
private WeaponStats makeWeapon(int numAugments) { BasicWeapon basicWeapon = this.weaponAugmentFactory.BasicWeapon; List <WeaponAugmentTemplate> augmentTemplates = new List <WeaponAugmentTemplate>(); List <WeaponAugmentTemplate> choices = new List <WeaponAugmentTemplate>(this.weaponAugmentFactory.All); for (int i = 0; i < numAugments; i++) { int index = this.randomGenerator.Next(choices.Count); WeaponAugmentTemplate template = choices[index]; augmentTemplates.Add(template); } WeaponStats stats = basicWeapon.WithAugments(augmentTemplates); return(stats); }
// Updates weapon position and camera FoV for the aiming transition void UpdateWeaponAiming() { if (m_WeaponSwitchState == WeaponSwitchState.Up) { BasicWeapon activeWeapon = GetActiveWeapon(); if (isAiming && activeWeapon) { m_WeaponMainLocalPosition = Vector3.Lerp(m_WeaponMainLocalPosition, aimingWeaponPosition.localPosition + activeWeapon.aimOffset, aimingAnimationSpeed * Time.deltaTime); SetFOV(Mathf.Lerp(m_PlayerCharacterController.playerCamera.fieldOfView, activeWeapon.aimZoomRatio * defaultFOV, aimingAnimationSpeed * Time.deltaTime)); } else { m_WeaponMainLocalPosition = Vector3.Lerp(m_WeaponMainLocalPosition, defaultWeaponPosition.localPosition, aimingAnimationSpeed * Time.deltaTime); SetFOV(Mathf.Lerp(m_PlayerCharacterController.playerCamera.fieldOfView, defaultFOV, aimingAnimationSpeed * Time.deltaTime)); } } }
void Start() { m_PlayerWeaponsManager = FindObjectOfType <PlayerWeaponsManager>(); DebugUtility.HandleErrorIfNullFindObject <PlayerWeaponsManager, WeaponHUDManager>(m_PlayerWeaponsManager, this); BasicWeapon activeWeapon = m_PlayerWeaponsManager.GetActiveWeapon(); if (activeWeapon) { AddWeapon(activeWeapon, m_PlayerWeaponsManager.activeWeaponIndex); ChangeWeapon(activeWeapon); } m_PlayerWeaponsManager.onAddedWeapon += AddWeapon; m_PlayerWeaponsManager.onRemovedWeapon += RemoveWeapon; m_PlayerWeaponsManager.onSwitchedToWeapon += ChangeWeapon; }
void RemoveWeapon(BasicWeapon newWeapon, int weaponIndex) { int foundCounterIndex = -1; for (int i = 0; i < m_AmmoCounters.Count; i++) { if (m_AmmoCounters[i].weaponCounterIndex == weaponIndex) { foundCounterIndex = i; Destroy(m_AmmoCounters[i].gameObject); } } if (foundCounterIndex >= 0) { m_AmmoCounters.RemoveAt(foundCounterIndex); } }
// Update is called once per frame void Update() { if (basicWeapon != null && Input.GetButton("Fire1")) { basicWeapon.Fire(getFireDirection()); } else if (basicWeapon != null && Input.GetButton("Reload")) { if (!basicWeapon.IsReloading() && basicWeapon.getMagazineSize() != basicWeapon.getCurrentAmmunition()) { basicWeapon.ForceReload(); } } else { //Falls ein Fehler bei Awake passieren sollte basicWeapon = GetComponent <BasicWeapon>(); } }
public override void LevelUp() { if (Level == 10) { return; } base.LevelUp(); basic = new BasicWeapon("Slice and Dice", this); intermediate = new IntermediateWeapon("Great Cleave", this); decimal scale = 1 + (decimal)(.2 * (Level - 1)); advanced = new AmplifyAttack(new AdvancedWeapon("Limit Break", this), scale); advanced.UpdateDamage(this); if (Level >= 5) { intermediate = new AreaOfEffect(intermediate); intermediate.UpdateDamage(this); } }
void OnWeaponChanged(BasicWeapon newWeapon) { if (newWeapon) { crosshairImage.enabled = true; m_CrosshairDataDefault = newWeapon.crosshairDataDefault; m_CrosshairDataTarget = newWeapon.crosshairDataTargetInSight; m_CrosshairRectTransform = crosshairImage.GetComponent <RectTransform>(); DebugUtility.HandleErrorIfNullGetComponent <RectTransform, CrosshairManager>(m_CrosshairRectTransform, this, crosshairImage.gameObject); } else { if (nullCrosshairSprite) { crosshairImage.sprite = nullCrosshairSprite; } else { crosshairImage.enabled = false; } } UpdateCrosshairPointingAtEnemy(true); }
void ChangeWeapon(BasicWeapon weapon) { UnityEngine.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(ammosPanel); }
// Update is called once per frame void Update() { if (Input.GetKey(KeyCode.UpArrow)) { //this.controller.SimpleMove(Vector3.forward * speed); playerObject.transform.Translate(Vector3.forward * speed * Time.deltaTime); playerObject.BroadcastMessage("StartMove"); } if (Input.GetKey(KeyCode.DownArrow)) { //this.controller.SimpleMove(Vector3.back * speed); playerObject.transform.Translate(Vector3.back * speed * Time.deltaTime); playerObject.BroadcastMessage("StartMove"); } if (Input.GetKey(KeyCode.LeftArrow)) { playerObject.transform.Rotate(Vector3.down * turnSpeed * Time.deltaTime); // playerObject.BroadcastMessage("StartMove"); } if (Input.GetKey(KeyCode.RightArrow)) { playerObject.transform.Rotate(Vector3.up * turnSpeed * Time.deltaTime); // playerObject.BroadcastMessage("StartMove"); } if (Input.GetKeyUp(KeyCode.Alpha1)) { if (this.currentGun.getWeaponType() != BasicWeapon.Type.GUN) { this.currentGun = new Gun(); GameObjectHelper.FindObject(playerObject, "Shotgun").SetActive(false); GameObjectHelper.FindObject(playerObject, "Pistol").SetActive(true); } } if (Input.GetKeyUp(KeyCode.Alpha2)) { if (this.currentGun.getWeaponType() != BasicWeapon.Type.SHOTGUN) { this.currentGun = new Shotgun(); GameObjectHelper.FindObject(playerObject, "Pistol").SetActive(false); GameObjectHelper.FindObject(playerObject, "Shotgun").SetActive(true); } } if (Input.GetKeyUp(KeyCode.DownArrow) || Input.GetKeyUp(KeyCode.UpArrow)) { playerObject.BroadcastMessage("StopMove"); } if (Input.GetKeyDown(KeyCode.Space)) { Vector3 fwd = playerObject.transform.TransformDirection(Vector3.forward) * 10; Debug.DrawRay(playerObject.transform.position, fwd, Color.red); playerObject.BroadcastMessage("shoot", "Enemy"); playerObject.BroadcastMessage("StartShooting", this.currentGun); } }
// Start is called before the first frame update private void Start() { basicWeapon = GetComponent <BasicWeapon>(); }
public WeaponProvider(BasicWeapon template) { this.template = template; }