//Here we find the components we need. void Awake() { playersinv = FindObjectOfType(typeof(Inventory)) as Inventory; //finding the players inv. if (playersinv == null) { canGet = false; Debug.LogWarning("No 'Inventory' found in game. The Item " + transform.name + " has been disabled for pickup (canGet = false)."); } else { gameObject.SendMessage("RetrievePlayer", playersinv, SendMessageOptions.DontRequireReceiver); } if (isEquipment == false && GetComponent <ItemEffect>() == null) { Debug.LogError(gameObject.name + " is not equipment so please assign an ItemEffect script to it"); } if (GetComponent <EquipmentEffect>()) { equipmentEffect = GetComponent <EquipmentEffect>(); } if (GetComponent <FirstPersonPickUp>() != null) { FPPickUpFound = true; } else if (transform.GetComponentInChildren <FirstPersonPickUp>() != null) { FPPickUpFound = true; } }
public bool BuyItem(EquipmentType type) { if (TakeFromBalance(type)) { // Creates a new empty equipment object, assigns a random profile to determine which type it will become, and gives it a name. Equipment newModule = new Equipment(); for (int i = 0; i < equipmentProfiles.Count; i++) { if (equipmentProfiles[i].equipmentType == type) { newModule.equipmentProfile = equipmentProfiles[i]; break; } } if (newModule.equipmentProfile == null) { Debug.LogError("There was an error in generating an item. newModule.equipmentProfile should not be null."); return(false); } // TO DO: Pick name from a list of pre-generated names newModule.name = newModule.equipmentProfile.equipmentType.ToString(); // Determine the effects this module should provide as according to the random profile picked and assigned. // Add guaranteed effects as defined in equipment profile. foreach (EquipmentEffectProfile effectProfile in newModule.equipmentProfile.guaranteedEffects) { // Generate the strength of the effect and add the effect to the equipment module's effects list EquipmentEffect thisEffect = GenerateNewEffect(effectProfile, newModule); thisEffect.wasGuaranteed = true; } // Test if secondary effect(s) should be added (based on their chance value) foreach (EquipmentEffectProfile effectProfile in newModule.equipmentProfile.possibleSecondaryEffects) { float randomFloat = Utility.GenerateRandomFloat(0, 100); if (effectProfile.chanceOfBeingAdded >= randomFloat) { GenerateNewEffect(effectProfile, newModule); } } playerInventory.Add(newModule); UpdateModulePrice(newModule.EquipmentType); ProfileManager.instance.SaveProfile(); EventManager.TriggerEvent("ItemPurchased"); EventManager.TriggerEvent("UpdateInventory"); EventManager.TriggerEvent("UpdateBalance"); return(true); } else { EventManager.TriggerEvent("CantAffordItem"); return(false); } }
//BALLISTICS - can be SLASHED REFLECTED DEFLECTED and BLOCKED //ENERGY - can be ESLASHED EREFLECTED and BLOCKED //ROCKETS - can be BASHED DEFLECTED and BLOCKED, will detonate if SLASHED void OnTriggerEnter2D(Collider2D other) { if (!playerAligned && other.gameObject.layer == 12) { return; } if (playerAligned && other.gameObject.layer == 11) { return; } if (other.gameObject.layer == 2) { return; } if (other.gameObject.layer == 10) { return; } EquipmentEffect e = other.GetComponent <EquipmentEffect>(); if (e != null) { switch (e.State) { case (EffectState.DEFLECT): direction += Random.Range(-0.5f, 0.5f) * Vector2.up; FlipAlignment(2f); return; case (EffectState.REFLECT): e.PlaySound(a); FlipAlignment(4f); return; case (EffectState.SLASH): case (EffectState.ESLASH): case (EffectState.BLOCK): gameObject.SetActive(false); return; default: return; } } else { if (other.GetComponent <IDamageable>() != null) { other.GetComponent <IDamageable>().TakeDamage(damage); } gameObject.SetActive(false); } }
void OnTriggerEnter2D(Collider2D other) { Debug.Log("ouch"); EquipmentEffect e = other.GetComponent <EquipmentEffect>(); if (e != null) { switch (e.State) { case (EffectState.STAB): case (EffectState.BASH): case (EffectState.SLASH): case (EffectState.ESLASH): TakeDamage(e.Damage); return; case (EffectState.BLOCK): default: return; } } }
private EquipmentEffect GenerateNewEffect(EquipmentEffectProfile effectProfile, Equipment newModule) { // Get a value from the curve. float rarityValue = strengthRarityCurve.Evaluate(Utility.GenerateRandomFloat(0f, 1f)); // Find out the difference between the max strength and min strength before multiplying this difference by the item rarity. float thisItemRarity = (effectProfile.maxStrength - effectProfile.minStrength) * rarityValue; // The strength of our item is now the minimum value + the rarity determination float strength = effectProfile.minStrength + thisItemRarity; // Create the new effect object by applying the profile and strength. EquipmentEffect newEffect = new EquipmentEffect(effectProfile, strength, rarityValue); //Debug.Log($"Generating new effect named {effectProfile.name} with strength {strength} at {rarityValue * 100}% rarity."); // Add the effect to the list of effects for the equipment module. newModule.effects.Add(newEffect); return(newEffect); }