public override void equipItem() { this.gameObject.GetComponentInParent <PersonWeaponController>().setWeapon(this); Inventory i = this.gameObject.GetComponentInParent <Inventory> (); i.equipItem(this, slot); ammoItem = i.getAmmoForGun(WeaponName); this.gameObject.GetComponent <SpriteRenderer> ().sprite = holding; this.gameObject.SetActive(true); ArtemAnimationController ac = this.gameObject.transform.root.gameObject.GetComponentInChildren <ArtemAnimationController> (); if (melee == true) { this.transform.rotation = Quaternion.Euler(0, 0, ac.rightHand.transform.rotation.eulerAngles.z + 35); } else { this.transform.rotation = ac.rightHand.transform.rotation; } this.gameObject.transform.parent = ac.rightHand.transform; this.gameObject.transform.position = ac.rightHand.transform.position; this.gameObject.transform.localPosition = ac.myAesthetic.handgunOffset; this.gameObject.SetActive(true); inUse = true; this.GetComponent <SpriteRenderer> ().sortingOrder = 3; }
public void TestCreateItemsAndSaveToSqlite() { ResourceItem = new ResourceItem(); ResourceItem.BaseData.Name = "Wood"; ResourceItem.BaseData.UniqueUUID = System.Guid.NewGuid().ToString(); StringProperty myString = new StringProperty("some_key", "This is a custom string property"); ResourceItem.BaseData.Properties.Add(myString); Debug.Log("The original value is [" + ResourceItem.BaseData.Properties.Get <string>("some_key") + "]"); ResourceItem.BaseData.Properties.Set("some_key", "This is the updated value of a custom property"); string propValue = ResourceItem.BaseData.Properties.Get <string>("some_key"); Debug.Log("This is the value [" + propValue + "]"); Bullet = new AmmoItem(); Bullet.BaseData.Name = "9mm"; Bullet.BaseData.UniqueUUID = System.Guid.NewGuid().ToString(); (Bullet.BaseData as AmmoSData).TravelDistance = 100; Items.Add(Bullet); Items.Add(ResourceItem); foreach (BaseItem item in Items) { Debug.Log("The item name is [" + item.BaseData.Name + "]"); DBModel.CreateItem(item); } }
public void SwitchCannon(CannonItem ci, AmmoItem ai) { cannonSwitch = true; cannonSwitchTimer = 0f; maxSwitchTime = ci.switchTime; cannon = ci; ammo = WeaponData.Instance.ammos[ci.ammoType]; }
private IEnumerable <AmmoItem> GetAmmoItems(string file) { var ammoCore = IoC.Archiver.LoadGameFile(file); var entities = ammoCore.GetTypes <AmmoResource>() //ammo entities .Select(x => (x.Name, x.ObjectUUID, x.EntityComponentResources)); entities = entities.Concat(ammoCore.GetTypes <InventoryActionAbilityResource>() //potion entities .Select(x => (x.Name, x.ObjectUUID, x.EntityComponentResources))); foreach (var entity in entities) { var ammo = new AmmoItem() { Name = entity.Name, MainId = entity.ObjectUUID, MainFile = file }; foreach (var comp in entity.EntityComponentResources) { var core = HzdCoreUtility.GetRefCore(ammoCore, comp); var resource = core.GetTypeById(comp.GUID); if (resource is InventoryItemComponentResource item) { ammo.LocalName = item.LocalizedItemName; } else if (resource is UpgradableStackableComponentResource stackable) { ammo.StackableId = stackable.ObjectUUID; ammo.StackableFile = core.Source; ammo.FactId = stackable.UpgradeLevelFact.GUID; ammo.FactFile = stackable.UpgradeLevelFact.ExternalFile; ammo.Upgradeable = true; } else if (resource is StackableComponentResource singleStackable) { ammo.StackableId = singleStackable.ObjectUUID; ammo.StackableFile = core.Source; ammo.Upgradeable = false; } } if (ammo.StackableId != null) { yield return(ammo); //only take 1 entity from file break; } } }
void createItems() { if (ItemDatabase.me.getItem(weaponToGet) == null) { } else { GameObject pistolObj = (GameObject)Instantiate(ItemDatabase.me.getItem(weaponToGet), this.transform.position, this.transform.rotation); Weapon w = pistolObj.GetComponent <Weapon> (); if (w.melee == false) { GameObject ammoObj = (GameObject)Instantiate(ItemDatabase.me.getAmmoItem(w), this.transform.position, this.transform.rotation); AmmoItem ai = ammoObj.GetComponent <AmmoItem> (); c.addItemToContainer(ai); } c.addItemToContainer(w); } foreach (string st in itemsToAdd) { if (ItemDatabase.me.getItem(st) == null) { } else { GameObject obj = (GameObject)Instantiate(ItemDatabase.me.getItem(st), this.transform.position, this.transform.rotation); Item i = obj.GetComponent <Item> (); c.addItemToContainer(i); } } foreach (string st in randomItems) { int r = Random.Range(0, 100); if (r < 25) { if (ItemDatabase.me.getItem(st) == null) { } else { GameObject obj = (GameObject)Instantiate(ItemDatabase.me.getItem(st), this.transform.position, this.transform.rotation); Item i = obj.GetComponent <Item> (); c.addItemToContainer(i); } } } }
private void OnTimedEvent(SpawnLocation l) { string itemType = ""; switch (l.itemType) { case "DamageBoost": Item damageBoost = new Item(l); l.addItem(damageBoost); cmdManager.InitializeItem(damageBoost); break; case "SpeedBoost": Item speedBoost = new Item(l); l.addItem(speedBoost); cmdManager.InitializeItem(speedBoost); break; case "AHA": Random random = new Random(); string[] itemOptions = new string[] { "HealthItem", "HealthItem", "ArmourItem", "AmmoItem", "AmmoItem" }; itemType = itemOptions[random.Next(5)]; break; } if (itemType == "HealthItem") { l.changeItem(itemType); HealthItem newHItem = new HealthItem(l); l.addItem(newHItem); cmdManager.InitializeItem(newHItem); l.changeItem("AHA"); } if (itemType == "ArmourItem") { l.changeItem(itemType); ArmourItem newAItem = new ArmourItem(l); l.addItem(newAItem); cmdManager.InitializeItem(newAItem); l.changeItem("AHA"); } if (itemType == "AmmoItem") { l.changeItem(itemType); AmmoItem newAmmoItem = new AmmoItem(l); l.addItem(newAmmoItem); cmdManager.InitializeItem(newAmmoItem); l.changeItem("AHA"); } }
public bool CanLoadAmmoIntoWeapon(ItemSlot ammoSlot, Item weapon) { if (ammoSlot.amount > 0 && ammoSlot.item.data is AmmoItem && weapon.data is RangedWeaponItem) { AmmoItem ammoData = (AmmoItem)ammoSlot.item.data; RangedWeaponItem weaponData = (RangedWeaponItem)weapon.data; if (weaponData.requiredAmmo == ammoData) { return(weapon.ammo < weaponData.magazineSize); } } return(false); }
public GameObject getAmmoItem(Weapon w) { foreach (GameObject g in items) { AmmoItem ai = g.GetComponent <AmmoItem> (); if (ai == null) { } else { if (ai.canWeUseAmmoInWeapon(w.itemName) == true) { return(g); } } } return(null); }
public AmmoItem getAmmoForGun(string curWep) { foreach (Item i in inventoryItems) { AmmoItem ai = i.gameObject.GetComponent <AmmoItem> (); if (ai == null) { continue; } else { if (ai.canWeUseAmmoInWeapon(curWep) == true) { return(ai); } } } return(null); }
public void manualReload(AmmoItem ai) { reloadTimer -= Time.deltaTime; reloading = true; //Debug.Log ("Reloading true 6"); if (playedReloadAnim == false) { playedReloadAnim = true; } if (reloadTimer <= 0) { if (this.gameObject.tag == "NPC") { GameObject g = (GameObject)Instantiate(ItemDatabase.me.getAmmoItem(currentWeapon), this.transform.position, this.transform.rotation); ai.ammoCount = 0; currentWeapon.ammoItem.ammoCount = currentWeapon.ammoItem.maxAmmo; RoomScript r = LevelController.me.getRoomObjectIsIn(g); if (r == null) { } else { r.itemsInRoomAtStart.Add(ai); } //myInv.dropItem (currentWeapon.ammoItem); } else { currentWeapon.ammoItem = ai; } ////////Debug.Log ("Setting new ammo to be " + currentWeapon.ammoItem.getItemName ()); reloading = false; //Debug.LogError ("reloading set false 2"); reloadTimer = currentWeapon.reloadTime; playedReloadAnim = false; ai.gameObject.GetComponent <SpriteRenderer> ().enabled = true; ai.gameObject.SetActive(false); } }
public bool canWeReloadGun(string curWep) { foreach (Item i in inventoryItems) { AmmoItem ai = i.gameObject.GetComponent <AmmoItem> (); if (ai == null) { continue; } else { ////////Debug.Log (ai.gunsAmmoFitsIn [0]); if (ai.canWeUseAmmoInWeapon(curWep) == true) { return(true); } } } return(false); }
void getAmmo() { AmmoItem ai = myController.inv.getAmmoForGun(myController.pwc.currentWeapon.WeaponName); if (ai == null) { target = ItemMoniter.me.getAmmoForWeapon(myController.pwc.currentWeapon, this.transform.position); } else { target = ai.gameObject; } if (ai == null) { } else { ////////Debug.Log ("DROPPING EMPTY MAG"); myController.inv.dropItem(myController.pwc.currentWeapon.ammoItem); } }
public void SetDamage(int _ammoID) { AmmoItem ai = WeaponData.Instance.ammos[_ammoID]; float base_dmg = ai.damage * ai.target.body; float team_dmg = ai.damage * ai.target.team; float ctrl_dmg = ai.damage * ai.target.control; bool isMiss = (Random.Range(0f, 1f) <= ai.missChance) ? true : false; bool isCrit = (Random.Range(0f, 1f) <= ai.critChance) ? true : false; if (isCrit) { base_dmg *= ai.critMultiplier; team_dmg *= ai.critMultiplier; ctrl_dmg *= ai.critMultiplier; Debug.Log("Crit!"); } if (!isMiss) { health_body = health_body - base_dmg; health_team = Mathf.Clamp(health_team - team_dmg, 0f, health_team_max); health_control = Mathf.Clamp(health_control - ctrl_dmg, 0f, health_control_max); } }
public void setItem(Item i) { toDisplay = i; if (toDisplay.gameObject.GetComponent <AmmoItem> () == false) { itemName.text = i.getItemName(); } else { AmmoItem ai = i.gameObject.GetComponent <AmmoItem> (); itemName.text = ai.getItemName();; } icon.sprite = i.itemTex; itemDescription.text = i.getBriefDescription(); if (equip == null) { return; } if (i.itemTex.texture.width > 70) { icon.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, i.itemTex.texture.width); icon.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, i.itemTex.texture.height); } else { icon.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, i.itemTex.texture.width * 2); icon.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, i.itemTex.texture.height * 2); } if (InventoryUI.me.myUIs.Contains(this)) { equip.gameObject.SetActive(i.canEquip); use.gameObject.SetActive(i.canConsume); } }
public GameObject getAmmoForWeapon(Weapon w, Vector3 pos) { foreach (Item i in itemsInWorld) { if (i.gameObject.activeInHierarchy == true) { if (Vector3.Distance(pos, i.gameObject.transform.position) < 20.0f) { AmmoItem ai = i.gameObject.GetComponent <AmmoItem> (); if (ai == null) { } else { if (ai.canWeUseAmmoInWeapon(w.WeaponName) == true) { return(i.gameObject); } } } } } return(null); }
public void fireWeapon() { if (currentWeapon == null) { if (canWeFireWeapon() == false) { return; } if (canWeFireWeapon() == true) { //Punch (); if (startedAttack == false) { this.gameObject.GetComponent <AudioController> ().playSound(SFXDatabase.me.swing); } ac.setMeleeAttack(); isPunch = true; startedAttack = true; } } else { if (currentWeapon.melee == false) { //Debug.Log ("Trying to fire gun"); if (canWeFireWeapon() == false) { //fireRateTimer -= Time.deltaTime; if (this.gameObject.tag == "NPC") { if (currentWeapon == null) { } else { if (currentWeapon.ammoItem == null) { } else { if (currentWeapon.ammoItem.ammoCount <= 0) { playGunClick(); reloading = true; //Debug.Log ("Reloading true 3"); } } } } return; } if (currentWeapon.ammoItem == null || currentWeapon.ammoItem.ammoCount == 0) { playGunClick(); if (myInv.canWeReloadGun(currentWeapon.WeaponName) || this.gameObject.tag == "NPC") { reloading = true; //Debug.Log ("Reloading true 4"); } ////Debug.Break (); return; //currentWeapon.ammoItem = myInv.getAmmoForGun (currentWeapon.WeaponName); } if (reloading == true) { playGunClick(); return; } if (canWeFireWeapon() == false || areWeDrawingWeapon() == true || currentWeapon.WeaponName == "Unarmed" || currentWeapon.ammoItem == null) { playGunClick(); return; } if (currentWeapon.ammoItem.ammoCount > 0) { Quaternion rotation = Quaternion.Euler(this.transform.rotation.x, this.transform.rotation.y, Random.Range(this.transform.rotation.eulerAngles.z - currentWeapon.recoilMax, this.transform.rotation.eulerAngles.z + currentWeapon.recoilMax)); if (aimDownSight == true) { rotation = Quaternion.Euler(this.transform.rotation.x, this.transform.rotation.y, Random.Range(this.transform.rotation.eulerAngles.z - (currentWeapon.recoilMax / 2), this.transform.rotation.eulerAngles.z + (currentWeapon.recoilMax / 2))); } else { rotation = Quaternion.Euler(this.transform.rotation.x, this.transform.rotation.y, Random.Range(this.transform.rotation.eulerAngles.z - currentWeapon.recoilMax, this.transform.rotation.eulerAngles.z + currentWeapon.recoilMax)); } GameObject g = (GameObject)Instantiate(currentWeapon.projectile, currentWeapon.bulletSpawnPos.position, currentWeapon.gameObject.transform.rotation); Bullet b = g.GetComponent <Bullet> (); b.shooter = this.gameObject; if (this.gameObject.tag != "Player") { b.isAiBullet = true; } currentWeapon.playMeleeAnim = true; currentWeapon.meleeCounter = 0; bulletFire(); //} currentWeapon.ammoItem.decrementAmmo(); this.gameObject.GetComponent <AudioController> ().playSound(currentWeapon.attackNoise); CameraController.me.bulletRecoilEffect(currentWeapon); fireRateTimer = currentWeapon.fireRate; } else { if (reloading == false) { playGunClick(); AmmoItem ai = myInv.getAmmoForGun(currentWeapon.WeaponName); if (ai == null) { } else { } reloadTimer = currentWeapon.reloadTime; reloading = true; //Debug.Log ("Reloading true 5"); } } } else { if (canWeFireWeapon() == true) { ac.setMeleeAttack(); isPunch = false; if (startedAttack == false) { this.gameObject.GetComponent <AudioController> ().playSound(currentWeapon.attackNoise); } startedAttack = true; ////////Debug.Break (); } //meleeAttack (); } } }
/// <summary> /// Initializes a new instance of the <see cref="Ammo"/> class. /// </summary> /// <param name="itemBase">The base <see cref="AmmoItem"/> class.</param> public Ammo(AmmoItem itemBase) : base(itemBase) { Base = itemBase; }
public void OpenAmmoScreen(AmmoItem selectedAmmo) { InventoryScreenObject.gameObject.SetActive(false); AmmoImage.sprite = selectedAmmo.ammoImage; AmmoName.text = selectedAmmo.ammoName; AmmoDescription.text = selectedAmmo.ammoDescription; //If an ammo has a skill (or other) requirement or not if (selectedAmmo.hasRequirement == true) { AmmoRequirement.text = selectedAmmo.ammoRequirement; AmmoRequirement.color = new Color32(123, 6, 27, 255); Lock.color = new Color32(255, 255, 255, 255); } else { AmmoRequirement.text = "none"; AmmoRequirement.color = new Color32(255, 255, 255, 255); Lock.color = new Color32(255, 255, 255, 0); } firstItemImage.sprite = selectedAmmo.firstItem.resourceImage; firstItemCost.text = selectedAmmo.firstItemCost.ToString(); firstItemQuantity.text = selectedAmmo.firstItem.playerQuantity.ToString(); secondItemImage.sprite = selectedAmmo.secondItem.resourceImage; secondItemCost.text = selectedAmmo.secondItemCost.ToString(); secondItemQuantity.text = selectedAmmo.secondItem.playerQuantity.ToString(); //If an ammo requires or not a third item to craft if (selectedAmmo.thirdItem != null) { thirdItemCostDisplay.gameObject.SetActive(true); thirdItemQuantityDisplay.gameObject.SetActive(true); thirdItemImage.sprite = selectedAmmo.thirdItem.resourceImage; thirdItemCost.text = selectedAmmo.thirdItemCost.ToString(); thirdItemQuantity.text = selectedAmmo.thirdItem.playerQuantity.ToString(); } else { thirdItemCostDisplay.gameObject.SetActive(false); thirdItemQuantityDisplay.gameObject.SetActive(false); } //If ammo cost is higher then player quantity if (selectedAmmo.thirdItem != null) { if (selectedAmmo.firstItemCost > selectedAmmo.firstItem.playerQuantity) { firstItemImage.color = new Color32(123, 6, 27, 255); firstItemCost.color = new Color32(123, 6, 27, 255); } if (selectedAmmo.secondItemCost > selectedAmmo.secondItem.playerQuantity) { secondItemImage.color = new Color32(123, 6, 27, 255); secondItemCost.color = new Color32(123, 6, 27, 255); } if (selectedAmmo.thirdItemCost > selectedAmmo.thirdItem.playerQuantity) { thirdItemImage.color = new Color32(123, 6, 27, 255); thirdItemCost.color = new Color32(123, 6, 27, 255); } else { firstItemImage.color = new Color32(255, 255, 255, 255); firstItemCost.color = new Color32(255, 255, 255, 255); secondItemImage.color = new Color32(255, 255, 255, 255); secondItemCost.color = new Color32(255, 255, 255, 255); thirdItemImage.color = new Color32(255, 255, 255, 255); thirdItemCost.color = new Color32(255, 255, 255, 255); } } else { if (selectedAmmo.firstItemCost > selectedAmmo.firstItem.playerQuantity) { firstItemImage.color = new Color32(123, 6, 27, 255); firstItemCost.color = new Color32(123, 6, 27, 255); } if (selectedAmmo.secondItemCost > selectedAmmo.secondItem.playerQuantity) { secondItemImage.color = new Color32(123, 6, 27, 255); secondItemCost.color = new Color32(123, 6, 27, 255); } else { firstItemImage.color = new Color32(255, 255, 255, 255); firstItemCost.color = new Color32(255, 255, 255, 255); secondItemImage.color = new Color32(255, 255, 255, 255); secondItemCost.color = new Color32(255, 255, 255, 255); } } AmmoIcon.sprite = selectedAmmo.ammoIcon; AmmoQuantity.text = selectedAmmo.playerAmmoQnty + "/" + selectedAmmo.maxAmmo; //Craft button interactable or not if (selectedAmmo.thirdItem != null) { if (selectedAmmo.hasRequirement == false && selectedAmmo.firstItem.playerQuantity > selectedAmmo.firstItemCost && selectedAmmo.secondItem.playerQuantity > selectedAmmo.secondItemCost && selectedAmmo.thirdItem.playerQuantity > selectedAmmo.thirdItemCost) { CraftButton.GetComponent <Button>().interactable = true; CraftButton.GetComponentInChildren <TextMeshProUGUI>().color = new Color32(255, 255, 255, 255); } } else if (selectedAmmo.thirdItem = null) { if (selectedAmmo.hasRequirement == false && selectedAmmo.firstItem.playerQuantity > selectedAmmo.firstItemCost && selectedAmmo.secondItem.playerQuantity > selectedAmmo.secondItemCost) { CraftButton.GetComponent <Button>().interactable = true; CraftButton.GetComponentInChildren <TextMeshProUGUI>().color = new Color32(255, 255, 255, 255); } } else { CraftButton.GetComponent <Button>().interactable = false; CraftButton.GetComponentInChildren <TextMeshProUGUI>().color = new Color32(255, 255, 255, 125); } AmmoScreenObject.gameObject.SetActive(true); }
public void reload() { if (currentWeapon == null) { //Debug.LogError ("reloading set false 1"); reloading = false; return; } if (this.gameObject.tag == "Player") { if (myInv.canWeReloadGun(currentWeapon.WeaponName)) { reloadTimer -= Time.deltaTime; if (playedReloadAnim == false) { playedReloadAnim = true; } //////////Debug.Log ("Reloading"); if (reloadTimer <= 0) { //need to add some kind of timer, have it on update and just have the ammo reaching 0 setting the bool to start reloading to true if (this.gameObject.tag == "NPC") { GameObject g = (GameObject)Instantiate(ItemDatabase.me.getAmmoItem(currentWeapon), this.transform.position, this.transform.rotation); AmmoItem ai = g.GetComponent <AmmoItem> (); ai.ammoCount = 0; currentWeapon.ammoItem.ammoCount = currentWeapon.ammoItem.maxAmmo; RoomScript r = LevelController.me.getRoomObjectIsIn(g); if (r == null) { } else { r.itemsInRoomAtStart.Add(ai); } //myInv.dropItem (currentWeapon.ammoItem); } else { currentWeapon.ammoItem = myInv.getAmmoForGun(currentWeapon.WeaponName); } ////////Debug.Log ("Setting new ammo to be " + currentWeapon.ammoItem.getItemName ()); reloading = false; //Debug.LogError ("reloading set false 2"); reloadTimer = currentWeapon.reloadTime; playedReloadAnim = false; } } else { ////////Debug.Log ("Couldnt find ammo for weapon, cancelling reload"); reloading = false; //Debug.LogError ("reloading set false 3"); } } else { reloadTimer -= Time.deltaTime; if (playedReloadAnim == false) { playedReloadAnim = true; } //////////Debug.Log ("Reloading"); if (reloadTimer <= 0) { //need to add some kind of timer, have it on update and just have the ammo reaching 0 setting the bool to start reloading to true if (this.gameObject.tag == "NPC") { GameObject g = (GameObject)Instantiate(ItemDatabase.me.getAmmoItem(currentWeapon), this.transform.position, this.transform.rotation); AmmoItem ai = g.GetComponent <AmmoItem> (); ai.ammoCount = 0; currentWeapon.ammoItem.ammoCount = currentWeapon.ammoItem.maxAmmo; RoomScript r = LevelController.me.getRoomObjectIsIn(g); if (r == null) { } else { r.itemsInRoomAtStart.Add(ai); } //myInv.dropItem (currentWeapon.ammoItem); } else { currentWeapon.ammoItem = myInv.getAmmoForGun(currentWeapon.WeaponName); } reloading = false; //Debug.LogError ("reloading set false 2"); reloadTimer = currentWeapon.reloadTime; playedReloadAnim = false; } } }