public WeaponItem(WeaponsHolder holder, WeaponIndex weapon, int health, bool isBought) { this.This = weapon; this.holder = holder; this.HealthRef = new RefInt(health); this.IsBought = isBought; }
public InvWeapon(WeaponIndex index, int health, bool isBought, bool isSelected) { Index = index; Health = health; IsBought = isBought; IsSelected = isSelected; }
//public void Deactivate() //{ // gameObject.SetActive(false); //} //public void Activate() //{ // gameObject.SetActive(true); //} //public bool TryGetRenderTexture(out RenderTexture renderTexture) //{ // if (!gameObject.activeInHierarchy) // { // return false; // } //} /// <summary> /// Get render texture of weapon item /// </summary> public RenderTexture GetImage(WeaponIndex w, int width, int height) { if (width > RenderTextureMaxSize) { width = RenderTextureMaxSize; } if (height > RenderTextureMaxSize) { height = RenderTextureMaxSize; } RenderTexture renderTexture = RenderTexture.GetTemporary(width, height, 16); renderTexture.antiAliasing = 4; renderTexture.autoGenerateMips = true; if (thisCamera == null) { thisCamera = GetComponent <Camera>(); } // render to texture thisCamera.targetTexture = renderTexture; thisCamera.Render(); thisCamera.targetTexture = null; return(renderTexture); }
public WeaponData this[WeaponIndex weapon] { get { return(weapons[weapon]); } }
public bool RepairWeapon(WeaponIndex type) { IWeaponItem item = inventory.Weapons.Get(type); if (!CanBeRepaired(type)) { Debug.Log("ShopSystem: weapon must be repairable: " + type); return(false); } if (!EnoughMoneyToRepair(item)) { return(false); } int currentRepairCost = GetRepairCost(item); inventory.Money -= currentRepairCost; item.Health = item.Durability; OnWeaponRepair?.Invoke(item.Index, currentRepairCost); return(true); }
public static string Execute(params string[] args) { int WeaponIndex; DaggerfallWorkshop.DaggerfallUnity daggerfallUnity = DaggerfallWorkshop.DaggerfallUnity.Instance; if (daggerfallUnity == null) { return(error); } if (args == null || args.Length < 1) { return("true or false"); } else if (!int.TryParse(args[0], out WeaponIndex)) { return(error); } else { try { changeWeaponIndex = WeaponIndex; return(string.Format("lerpValue set to:" + WeaponIndex.ToString())); } catch { return("Unspecified error; failed to set lerp"); } } }
void SetWeaponItem(WeaponIndex w) { if (inventory == null || shop == null) { return; } // get current IWeaponItem weaponItem = inventory.Weapons.Get(w); IAmmoItem ammoItem = inventory.Ammo.Get(weaponItem.AmmoType); //// get image //var renderTexture = weaponsWorldUI.GetImage(w); //Texture2D texture2D = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.RGBA32, false); //RenderTexture.active = renderTexture; //texture2D.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0); //texture2D.Apply(); //byte[] png = texture2D.EncodeToPNG(); //System.IO.File.WriteAllBytes("D:/UI/UI_Weapon_" + Enum.GetName(typeof(WeaponIndex), w) + ".png", png); //RenderTexture.active = null; //print("saved"); //// set info //weaponShopItem.SetInfo(shop, weaponItem, ammoItem, renderTexture); weaponShopItem.SetInfo(shop, weaponItem, ammoItem, weaponItem.Icon.texture); }
public bool GetNextAvailable(WeaponIndex weapon, out WeaponIndex availableWeapon, bool shiftToRight = true) { // try to switch to next available int allWeaponsCount = Enum.GetValues(typeof(WeaponIndex)).Length; int current = (int)weapon; int available = current; do { if (shiftToRight) { available = available + 1 >= allWeaponsCount ? 0 : available + 1; } else { available = available - 1 < 0 ? allWeaponsCount - 1 : available - 1; } if (IsAvailableAndHaveAmmo((WeaponIndex)available)) { // if found availableWeapon = (WeaponIndex)available; return(true); } } while (available != current); availableWeapon = weapon; return(false); }
public bool IsAvailableInGame(WeaponIndex w) { //return playerWeapons[w].IsBought; return(!playerWeapons[w].IsBroken && playerWeapons[w].IsBought && playerWeapons[w].IsSelected); }
void Select(WeaponIndex w) { // if none is highlited, do nothing if (isSelected) { inputController.SelectWeapon(w); inputController.OnWeaponSelectorUp(); } }
void Highlight(WeaponIndex w, bool canBeSelected) { IWeaponItem weaponItem = inventory.Weapons.Get(w); IAmmoItem ammoItem = inventory.Ammo.Get(weaponItem.AmmoType); SetName(weaponItem); SetHealth(weaponItem); SetAmmo(ammoItem); isSelected = canBeSelected; }
public bool CanBeRepaired(WeaponIndex type) { IWeaponItem item = inventory.Weapons.Get(type); int currentRepairCost = GetRepairCost(item); return(item.IsBought && item.CanBeDamaged && !item.IsAmmo && inventory.Money >= currentRepairCost); }
public RenderTexture GetImage(WeaponIndex w) { if (container == null) { return(null); } // select weapon container.Select(w); // render it itemCamera.enabled = true; return(itemCamera.GetImage(w, size, size)); }
void Start() { inventoryWeapons = CurrentPlayer.Inventory.Weapons; inventoryAmmo = CurrentPlayer.Inventory.Ammo; // init weapons Weapon[] ws = GetComponentsInChildren <Weapon>(true); weapons = new Dictionary <WeaponIndex, Weapon>(); foreach (Weapon w in ws) { // scene's weapon index is not set // so parse it WeaponIndex index = (WeaponIndex)Enum.Parse(typeof(WeaponIndex), w.gameObject.name); // include it only if available in inventory // if (inventoryWeapons.IsAvailable(index)) { weapons.Add(index, w); w.Init(this, inventoryWeapons.Get(index), inventoryAmmo); } } // get audio sources audioSources = GetComponentsInChildren <AudioSource>(); audioSourceIndex = 0; Debug.Assert(audioSources.Length != 0, "No audio source for weapons"); // animation commonAnimation = GetComponent <Animation>(); Debug.Assert(commonAnimation != null); // states isSwitching = false; canSwitchToAnotherNext = false; currentWeapon = new Maybe <WeaponIndex>(); nextWeapon = new Maybe <WeaponIndex>(); // events SignToEvents(); // set parameters for weapons particles InitParticles(); // to default Reinit(); isInitialized = true; }
public WeaponItem Get(WeaponIndex w) { WeaponItem item = playerWeapons[w]; // check weapon's health, if it's out of bounds, clamp it item.Health = Mathf.Clamp(item.Health, 0, item.Durability); // normalize other values if (item.Health == 0 && !item.IsAmmo) { item.IsBought = false; selectedWeapons.Remove(w); } return(item); }
void FinishShootingWeapon(WeaponIndex finishedWeapon) { //// if there is no current weapon, do nothing //if (!currentWeapon.Exist) //{ // return; //} //// if finished is current //// and player still holds fire button, //// then continue shooting //if (finishedWeapon == currentWeapon.Value // && InputController.FireButton && playerIsActive) //{ // weapons[finishedWeapon].Fire(); //} }
IEnumerator WaitForNewNext(WeaponIndex newNext) { isWaitingForAnotherNext = true; // wait for old switching while (isSwitching) { yield return(null); } // now it's safe to reassign 'nextWeapon' nextWeapon.Exist = true; nextWeapon.Value = newNext; waitingForAnotherNext = null; isWaitingForAnotherNext = false; StartCoroutine(WaitForSwitch()); }
public bool BuyWeapon(WeaponIndex type) { IWeaponItem item = inventory.Weapons.Get(type); if (item.IsAmmo) { bool boughtAsAmmo = BuyAmmo(item.AmmoType, false); if (boughtAsAmmo) { item.IsBought = true; } return(boughtAsAmmo); } if (!CanBeBought(type)) { Debug.Log("ShopSystem: weapon must be buyable: " + type); return(false); } if (!EnoughMoneyToBuy(item)) { return(false); } int price = GetWeaponPrice(item); inventory.Money -= price; item.IsBought = true; item.Health = item.Durability; // weapon is bought, most likely that player // wants to add it to selected inventory.Weapons.Select(item.Index); OnWeaponBuy?.Invoke(item.Index, price); return(true); }
/// <summary> /// Change weapon to next available, /// if there are no such weapons, disables current. /// </summary> void ChangeToNextAvailable(WeaponIndex oldWeapon) { // if there is no current weapon, then ignore if (!currentWeapon.Exist) { return; } // if not current, then ignore if (currentWeapon.Value != oldWeapon) { Debug.Log("Incorrect broken weapon", this); return; } // if already switching to another weapon if (isSwitching) { return; } // try to switch to next available if (GetNextAvailable(oldWeapon, out WeaponIndex available)) { // if found SwitchTo(available); return; } // otherwise: // just disable old weapons[oldWeapon].ForceDisable(); commonAnimation.Play(animHide); // there is no current weapon anymore // note: it's ok not to wait // for actual weapon hiding (i.e. state == Nothing) currentWeapon.Exist = false; }
/// <summary> /// Sets perameters of the weapon. /// If there is no given weapon, it will be added. /// Otherwise, data will be rewritten. /// </summary> public void Set(WeaponIndex weapon, int health, bool isBought, bool isSelected) { if (isSelected) { selectedWeapons.Push(weapon); } else { selectedWeapons.Remove(weapon); } if (playerWeapons.ContainsKey(weapon)) { playerWeapons[weapon].IsBought = isBought; playerWeapons[weapon].HealthRef.Value = health; } else { playerWeapons.Add(weapon, new WeaponItem(this, weapon, health, isBought)); } }
/// <summary> /// Activate weapon item, if exist /// </summary> public void Select(WeaponIndex w) { if (items == null) { Init(); } var values = items.Values; foreach (var v in values) { v.SetActive(false); } if (items.ContainsKey(w)) { GameObject item = items[w]; item.SetActive(true); current = item; } }
public void SetNext() { currentWeapon = GetNextIndex(1); SetWeaponItem(currentWeapon); }
/// <summary> /// Is this weapon available? True, if weapon is bought and not broken. /// Weapon is not broken if health > 0 or weapon is ammo /// </summary> public bool IsAvailable(WeaponIndex w) { return(!playerWeapons[w].IsBroken && playerWeapons[w].IsBought); }
public void SetPrevious() { currentWeapon = GetNextIndex(-1); SetWeaponItem(currentWeapon); }
private void Shop_OnWeaponBuy(WeaponIndex index, int price) { OnlineService?.ReportProgress(GPGSIds.achievement_first_purchase, 100); }
void Update() { if (canSwitchWeapon) { if (Input.GetKeyDown(KeyCode.Alpha1)) { if (inventory[0] == null) return; // canSwitchWeapon = false; SetSlot(1, inventory[0].weaponID); Debug.Log("set wep 1 "); } else if (Input.GetKeyDown(KeyCode.Alpha2)) { if (inventory[1] == null) return; // canSwitchWeapon = false; SetSlot(2, inventory[1].weaponID); Debug.Log("set wep 2"); } else if (Input.GetKeyDown(KeyCode.Alpha3)) { if (inventory[2] == null) return; // canSwitchWeapon = false; SetSlot(3, inventory[2].weaponID); Debug.Log("set wep 3"); } else if (Input.GetKeyDown(KeyCode.E)) { canSwitchWeapon = false; lastWeaponUsed(); } } Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0)); if (Physics.Raycast(ray, out hit, pickDistance, layerWeapons) && canSwitchWeapon) { hitWeaponIndex = hit.transform.GetComponent<WeaponIndex>(); showWeaponText = true; if (inventory[hitWeaponIndex.slotID - 1] != null) { isSlotTaken = true; if (inventory[hitWeaponIndex.slotID - 1].weaponID == hitWeaponIndex.weaponID) isWeaponOwned = true; else isWeaponOwned = false; } else { isSlotTaken = false; isWeaponOwned = false; } // Debug.Log("IS SLOT / WEAPON TAKEN ??" + isSlotTaken + " - " + isWeaponOwned); if (Input.GetKeyDown(KeyCode.F) && canSwitchWeapon) { if (isSlotTaken) { if (isWeaponOwned) { // Debug.Log("shit happens brah."); //just notify the player that he already owns the weapon //-->maybe replace ? to do. } else { DropWeapon(hitWeaponIndex.slotID, inventory[hitWeaponIndex.slotID - 1].weaponID); // inventory[hitWeaponIndex.slotID - 1] = hitWeaponIndex; SetSlot(hitWeaponIndex.slotID, hitWeaponIndex.weaponID, true); Destroy(hit.transform.gameObject); } } else { // inventory[hitWeaponIndex.slotID - 1] = hitWeaponIndex; SetSlot(hitWeaponIndex.slotID, hitWeaponIndex.weaponID); //enable the weapon Destroy(hit.transform.gameObject); } } } else { showWeaponText = false; } // Debug.Log("UPDATE HAPPENED ~!"); }
void EnableWeapon(int slot, int wepId) { for (int i = 0; i < weaponsOnPlayer.Length; i++) { WeaponIndex temp = weaponsOnPlayer[i].GetComponent<WeaponIndex>(); if (temp.slotID == slot && temp.weaponID == wepId) { weaponsOnPlayer[i].SetActive(true); weaponsOnPlayer[i].GetComponent<WeaponIndex>().enabled = true; weaponsOnPlayer[i].GetComponent<WeaponScript>().enabled = true; currentWeapon = temp; inventory[slot - 1] = currentWeapon; weaponsOnPlayer[i].gameObject.SendMessage("PullOutWeapon", SendMessageOptions.DontRequireReceiver); // Debug.Log("ENABLE WEAPON --> " + temp.slotID + " - " + temp.weaponID); // Debug.Log("------ENABLE HAPPENED ------ !"); break; } } }
void DisableWeapon(int slot, int wepId) { canSwitchWeapon = false; for (int i = 0; i < weaponsOnPlayer.Length; i++) { WeaponIndex temp = weaponsOnPlayer[i].GetComponent<WeaponIndex>(); if (temp.slotID == slot && temp.weaponID == wepId) { previousWeapon = temp; weaponsOnPlayer[i].gameObject.SendMessage("HolsterWeapon", SendMessageOptions.DontRequireReceiver); weaponsOnPlayer[i].SetActive(false); weaponsOnPlayer[i].GetComponent<WeaponIndex>().enabled = false; weaponsOnPlayer[i].GetComponent<WeaponScript>().enabled = false; // Debug.Log("DISABLED WEAPON --> " + temp.slotID + " - " + temp.weaponID); break; } } }
/// <summary> /// Called on pointer up from weapon button in weapon selection menu /// </summary> public void SelectWeapon(WeaponIndex w) { OnWeaponSwitch?.Invoke(w); }
IWeaponItem IWeaponsHolder.Get(WeaponIndex w) { return(Get(w)); }
public void Select(WeaponIndex index) { selectedWeapons.Push(index); }
public bool IsSelected(WeaponIndex index) { WeaponItem item = playerWeapons[index]; return(selectedWeapons.Contains(index) && !(item.Health == 0 && !item.IsAmmo)); }
public void Deselect(WeaponIndex index) { selectedWeapons.Remove(index); }