Good afternoon everyone and sorry for my probably bad english, also… i’m having a “problem” i want to implement a elemental damage system to my mmorpg game, but the problem is, that i already programmed everyting and i din’t prepared anyting for this, and i really don’t want to remake everyting, here it is what i got…
public enum Element
//elemental Enum...
{
Sacred = 0,
Darkness = 1,
Fire = 2,
Plant = 3,
Water = 6,
Ice = 7,
Thunder = 8,
Wind = 9,
Earth = 10,
Order = 11,
Chaos = 12,
Overlord = 13,
Brave = 14,
Creator = 15
}
//Npc "intestines"
void Awake () {
transform.localEulerAngles = Vector3.zero; // We always set our npc to zero rotation at start because if set otherwife it will not follow player as billboard
if (npcFaction == NPCFaction.Merchants) {
if (merchantTopic == null) {
Debug.LogError (gameObject.name + " merchant needs merchantTopic assigned.");
}
}
if(GameObject.FindGameObjectWithTag("GameManager")) {
gameManager = GameObject.FindGameObjectWithTag("GameManager").GetComponent<GameManager>();
genLoot = gameManager.gameObject.GetComponentInChildren<GenericLootAssigner>();
}
ai = GetComponent<NPCAiNavmesh>();
npcOutfiter = GetComponent<NPCOutfiter>();
if (GameObject.Find("[Player]")) {
playerStats = GameObject.Find("[Player]").GetComponent<PlayerStats>();
pcSkills = GameObject.Find("[Player]").GetComponent<PlayerSkillsAndAttributes>();
}
animBase.enabled = true;
animHair.enabled = true;
animFacialHair.enabled = true;
animHelmHat.enabled = true;
animOutfit.enabled = true;
animWeapon.enabled = true;
npcOutfiter.hairSr.material.color = hairColor;
npcOutfiter.facialHairSr.material.color = hairColor;
if (npcDifficulity == NPCDifficultyLevel.VeryEasy) {
float tmp = pcSkills.body * 0.7f;
npcHealth = (int)tmp;
}
else if (npcDifficulity == NPCDifficultyLevel.Easy) {
float tmp = pcSkills.body * 0.95f;
npcHealth = (int)tmp;
}
else if (npcDifficulity == NPCDifficultyLevel.Medium) {
float tmp = pcSkills.body * 1.5f;
npcHealth = (int)tmp;
}
else if (npcDifficulity == NPCDifficultyLevel.Hard) { //Very hard
float tmp = pcSkills.body * 1.8f;
npcHealth = (int)tmp;
}
else if (npcDifficulity == NPCDifficultyLevel.Deadly) { //Very very hard
float tmp = pcSkills.body * 2.8f;
npcHealth = (int)tmp;
}
if (race == CharacterRace.Werewolf) {
transform.localScale = new Vector3(2.2f, 2.2f, 2.2f);
}
else if (race == CharacterRace.AnimalDeer) {
transform.localScale = new Vector3(2.5f, 2.5f, 2.5f);
}
else {
transform.localScale = new Vector3(2f, 2f, 2f);
}
npcMaxHealth = npcHealth;
nma = GetComponent<UnityEngine.AI.NavMeshAgent> ();
npcScale = npcOutfiter.baseSr.transform.localScale.x;
if(!gameObject.name.Contains("Beast") && lootBag.Length <= 0) {
if (npcDifficulity == NPCDifficultyLevel.VeryEasy) {
if (genLoot.lowLvlLoot.Length > 0) {
float randFloat = Random.Range(0f, 1f);
if (randFloat >= 0f && randFloat <= 0.5f) {
List<GameObject> tmpList = lootBag.ToList();
tmpList.Add(genLoot.lowLvlLoot[Random.Range(0, genLoot.lowLvlLoot.Length)]);
lootBag = tmpList.ToArray();
}
}
}
else if (npcDifficulity == NPCDifficultyLevel.Easy) {
if (genLoot.mediumLvlLoot.Length > 0) {
float randFloat = Random.Range(0f, 1f);
if (randFloat >= 0f && randFloat <= 0.5f) {
List<GameObject> tmpList = lootBag.ToList();
tmpList.Add(genLoot.mediumLvlLoot[Random.Range(0, genLoot.mediumLvlLoot.Length)]);
lootBag = tmpList.ToArray();
}
}
}
else if (npcDifficulity == NPCDifficultyLevel.Medium) {
if (genLoot.highLvlLoot.Length > 0) {
float randFloat = Random.Range(0f, 1f);
if (randFloat >= 0f && randFloat <= 0.5f) {
List<GameObject> tmpList = lootBag.ToList();
tmpList.Add(genLoot.highLvlLoot[Random.Range(0, genLoot.highLvlLoot.Length)]);
lootBag = tmpList.ToArray();
}
}
}
else if (npcDifficulity == NPCDifficultyLevel.Hard) {
if (genLoot.extraLvlLoot.Length > 0) {
float randFloat = Random.Range(0f, 1f);
if (randFloat >= 0f && randFloat <= 0.5f) {
List<GameObject> tmpList = lootBag.ToList();
tmpList.Add(genLoot.extraLvlLoot[Random.Range(0, genLoot.extraLvlLoot.Length)]);
lootBag = tmpList.ToArray();
}
}
}
else if (npcDifficulity == NPCDifficultyLevel.Deadly) {
float randFloat = Random.Range(0f, 1f);
if (randFloat >= 0f && randFloat <= 0.5f) {
List<GameObject> tmpList = lootBag.ToList();
foreach(GameObject go in tmpList) {
if(go.name == "CoinsBagRich") {
tmpList.Add(genLoot.extraLvlLoot[Random.Range(0, genLoot.extraLvlLoot.Length)]);
lootBag = tmpList.ToArray();
}
}
}
}
}
if(willNpcRespawn == false) {
Destroy(GetComponent<NPCRespawner>());
}
else {
if(respawnAfterDays <= 0) {
respawnAfterDays = Random.Range(2, 14);
}
GetComponent<NPCRespawner>().daysUntilRespawn = respawnAfterDays;
}
}
void Update() {
if (npcHealth > 0) {
if (npcFaction == NPCFaction.Merchants && !gameObject.name.Contains("STABLER")) {
merchantCounter++;
if (merchantCounter > 2400f) {
merchantTopic.shopGold += 40;
merchantCounter = 0;
}
}
localVelocity = transform.InverseTransformDirection(nma.velocity);
rightOrLeft = localVelocity.x;
if (rightOrLeft > 0.5f) {
if (npcDirection == NPCDirection.Left) {
npcDirection = NPCDirection.Right;
}
}
else if (rightOrLeft < 0.5f) {
if (npcDirection == NPCDirection.Right) {
npcDirection = NPCDirection.Left;
}
}
if (gameObject.name.Contains("BEAST")) {
if (npcDirection == NPCDirection.Left) {
npcOutfiter.baseSr.transform.localScale = new Vector3(npcScale, npcScale, npcScale);
}
else {
npcOutfiter.baseSr.transform.localScale = new Vector3(-npcScale, npcScale, npcScale);
}
}
else if (gameObject.name.Contains("ANIMAL")) {
if (npcDirection == NPCDirection.Left) {
npcOutfiter.baseSr.transform.localScale = new Vector3(npcScale, npcScale, npcScale);
}
else {
npcOutfiter.baseSr.transform.localScale = new Vector3(-npcScale, npcScale, npcScale);
}
}
if (setLooks == false) {
SetUpLooks();
setLooks = true;
}
if (ai.engagedInCombat == true && npcFaction != NPCFaction.Guards) { //Ovo stavljamo ovako da bi strazari uvek imali isukano oruzje
if (weapon == NPCWeapon.None) {
animWeapon.SetBool("equiped", false);
}
else {
animWeapon.SetBool("equiped", true);
}
}
else if (npcFaction == NPCFaction.Guards) {
animWeapon.SetBool("equiped", true);
}
else {
animWeapon.SetBool("equiped", false);
}
i was thinking in put all elements system on the npc, since adding this “system” on player probably will be more dificult… probably it would be easy to show than explain…
PLAYER
public Element Elemento;
public bool weaponDrawn = false;
public bool torchDrawn = false;
private PlayerSkillsAndAttributes skillsAttributes;
private UIManager uiManager;
public int weaponDamage;
public int shieldScore;
public int armorScore;
private int armorTmp;
public int missileDamage;
public GameObject weaponSlot;
public Slot weaponSlott;
public GameObject shieldSlot;
public Slot shieldSlott;
public GameObject torchSlot;
public Slot torchSlott;
public GameObject headSlot;
public Slot headSlott;
public GameObject chestSlot;
public Slot chestSlott;
public GameObject necklaceSlot;
public Slot necklaceSlott;
public GameObject missileSlot;
public Slot missileSlott;
public bool weapon = false;
public bool shield = false;
public bool torch = false;
public bool head = false;
public bool chest = false;
public bool necklace = false;
public bool missile = false;
public int missileCount;
///void Awake() {
/// DisableEquipment();
///}
void Start() {
skillsAttributes = GameObject.Find("[Player]").GetComponent<PlayerSkillsAndAttributes>();
if (GameObject.Find ("_UICanvasGame") != null) {
uiManager = GameObject.Find ("_UICanvasGame").GetComponent<UIManager> ();
}
}
void Update() {
if (uiManager != null) {
if (Input.GetButtonDown("DrawWeapon")) {
if (weapon == true && !uiManager.alchemyUI.activeSelf && !uiManager.bookUI.activeSelf && !uiManager.inventoryUI.activeSelf &&
!uiManager.consoleUI.activeSelf && !uiManager.dialogUI.activeSelf && !uiManager.pauseUI.activeSelf && !uiManager.specialTopicerUI.activeSelf &&
!uiManager.storeUI.activeSelf && !uiManager.waiterUI.activeSelf && !uiManager.questPopupWindow.activeSelf) {
weaponDrawn = !weaponDrawn;
}
}
}
if(weapon == false) {
weaponDrawn = false;
}
if (torch == true) {
torchDrawn = true;
}
else {
torchDrawn = false;
}
if(weaponSlot != null) {
if(skillsAttributes.melee < 25) {
float tmpDamageBase = (weaponSlot.GetComponent<Item>().powerScore * 0.7f) + (skillsAttributes.body * 0.125f);
weaponDamage = (int)tmpDamageBase;
}
else if(skillsAttributes.melee >= 25 && skillsAttributes.melee < 50) {
float tmpDamageBase = (weaponSlot.GetComponent<Item>().powerScore * 0.7f) + (skillsAttributes.body * 0.125f);
float tmpDamagePercent = tmpDamageBase * 0.15f;
weaponDamage = (int)tmpDamageBase + (int)tmpDamagePercent;
}
else if(skillsAttributes.melee >= 50) {
float tmpDamageBase = (weaponSlot.GetComponent<Item>().powerScore * 0.8f) + (skillsAttributes.body * 0.125f);
float tmpDamagePercent = tmpDamageBase * 0.25f;
weaponDamage = (int)tmpDamageBase + (int)tmpDamagePercent;
}
if (torch == true && torchDrawn == true) {
if(torchSlot != null) {
if(torchSlot.GetComponent<Item>().itemName.Contains("Torch")) {
torchSlot.GetComponent<Item>().itemGO.SetActive(true);
if(torchSlot.gameObject.activeSelf == true) {
torchSlot.GetComponent<Item>().itemGO.GetComponentInChildren<Light>().enabled = true;
}
}
}
}
else {
if(torchSlot != null) {
if(torchSlot.GetComponent<Item>().itemName.Contains("Torch")) {
torchSlot.GetComponent<Item>().itemGO.SetActive(false);
if(torchSlot.gameObject.activeSelf == true) {
torchSlot.GetComponent<Item>().itemGO.GetComponentInChildren<Light>().enabled = false;
}
}
}
}
}
else {
weaponDamage = 0;
}
if(shieldSlot != null) {
shieldScore = shieldSlot.GetComponent<Item>().powerScore;
}
else {
shieldScore = 0;
}
if(missileSlot != null) {
if(weaponSlot != null) {
missileDamage = missileSlot.GetComponent<Item>().powerScore + weaponDamage;
}
}
else {
missileDamage = 0;
}
if(chestSlot != null && headSlot != null && shieldSlot != null) {
if(chestSlot.GetComponent<Item>().armorType == headSlot.GetComponent<Item>().armorType) {
if(chestSlot.GetComponent<Item>().armorType == ArmorType.LightArmor) {
if(skillsAttributes.lightArmor < 25) {
int armorSkill = skillsAttributes.lightArmor;
float armorExtra = (chestSlot.GetComponent<Item>().powerScore + headSlot.GetComponent<Item>().powerScore +
shieldSlot.GetComponent<Item>().powerScore) * ((armorSkill / 200f) + 2f);
armorScore = (int)armorExtra;
}
else if(skillsAttributes.lightArmor >= 25 && skillsAttributes.lightArmor < 80) {
int armorSkill = skillsAttributes.lightArmor;
float armorExtra = (chestSlot.GetComponent<Item>().powerScore + headSlot.GetComponent<Item>().powerScore +
shieldSlot.GetComponent<Item>().powerScore) * ((armorSkill / 200f) + 2f);
float eightPercent = armorExtra * 0.08f;
float calculatedAS = ((int)armorExtra) + (int)eightPercent;
armorScore = (int)calculatedAS;
}
else if(skillsAttributes.lightArmor >= 80) {
int armorSkill = skillsAttributes.lightArmor;
float armorExtra = (chestSlot.GetComponent<Item>().powerScore + headSlot.GetComponent<Item>().powerScore +
shieldSlot.GetComponent<Item>().powerScore) * ((armorSkill / 200f) + 2f);
float fortyPercent = armorExtra * 0.4f;
float calculatedAS = ((int)armorExtra) + (int)fortyPercent;
armorScore = (int)calculatedAS;
}
}
else if(chestSlot.GetComponent<Item>().armorType == ArmorType.HeavyArmor) {
if(skillsAttributes.heavyArmor < 25) {
int armorSkill = skillsAttributes.heavyArmor;
float armorExtra = (chestSlot.GetComponent<Item>().powerScore + headSlot.GetComponent<Item>().powerScore +
shieldSlot.GetComponent<Item>().powerScore) * ((armorSkill / 200f) + 2f);
armorScore = (int)armorExtra;
}
else if(skillsAttributes.heavyArmor >= 25 && skillsAttributes.heavyArmor < 80) {
int armorSkill = skillsAttributes.heavyArmor;
float armorExtra = (chestSlot.GetComponent<Item>().powerScore + headSlot.GetComponent<Item>().powerScore +
shieldSlot.GetComponent<Item>().powerScore) * ((armorSkill / 200f) + 2f);
float eightPercent = armorExtra * 0.15f;
float calculatedAS = ((int)armorExtra) + (int)eightPercent;
armorScore = (int)calculatedAS;
}
}
}
//Also the item "stuff"
public enum Element
{
Sacred = 0,
Darkness = 1,
Fire = 2,
Plant = 3,
Water = 6,
Ice = 7,
Thunder = 8,
Wind = 9,
Earth = 10,
Order = 11,
Chaos = 12,
Overlord = 13,
Brave =14,
Creator =15
}
[AddComponentMenu("[Eventyr]/Items/Set Item")]
[RequireComponent(typeof (BoxCollider))]
[RequireComponent(typeof (Rigidbody))]
[RequireComponent(typeof (PickupItem))]
public class Item : MonoBehaviour {
public int itemId;
[Header("Ownership and Quest values")]
public GameObject owner;
public bool questItem = false;
public string questId;
public QuestPhase questPhase;
public ItemQuestUse effectScript;
[Header("Visual values")]
public string itemName;
public Sprite itemIcon;
[Space(10f)]
public string itemGOName = "/";
[HideInInspector]
public Transform weaponsGO;
private Transform shieldsGO;
[Header("Essential values")]
public ItemType type;
[Tooltip("Damage/Magic. Leave ZERO if this item has no damage, because we do not wont inventory to show the value.")]
public int powerScore;
[Tooltip("Dark, light etc... affects power score(It should at least...)")]
public Element Element;
public float health;
public int vendorPrice;
[HideInInspector]
public int merchantPrice = 0;
public float itemWeight;
[Tooltip("If this is part of the armor we must set its type.")]
public ArmorType armorType;
public GameObject itemGO;
[Space(10f)]
public int maxStackSize;
public int currentStackSize;
[HideInInspector]
public bool stolen;
[HideInInspector]
public bool equiped;
void Awake() {
Item[] allItems = GameObject.FindObjectsOfType<Item>();
for (int i = 0; i < allItems.Length; i++) {
if (allItems[i] != this && allItems[i].itemId == itemId) {
itemId = Random.Range(0, 1000);
Debug.Log("We are having two items using the same ID. Changin ID of item "+gameObject.name+" to ID "+itemId);
}
}
if (itemGOName.Contains("Bow")) {
weaponsGO = GameObject.Find("[Player]").transform.Find("FPCameraGO/FPCamera/EquipmentGO/WeaponsRangedGO");
}
else {
weaponsGO = GameObject.Find("[Player]").transform.Find("FPCameraGO/FPCamera/EquipmentGO/WeaponsMeleeGO");
}
shieldsGO = GameObject.Find("[Player]").transform.Find("FPCameraGO/FPCamera/EquipmentGO/ShieldsGO");
if(itemGOName == "/") {
itemGO = null;
}
else {
if(type == ItemType.Weapon) {
itemGO = weaponsGO.Find(itemGOName).gameObject;
}
if(type == ItemType.Shield) {
itemGO = shieldsGO.Find(itemGOName).gameObject;
}
if(type == ItemType.Torch) {
itemGO = shieldsGO.Find(itemGOName).gameObject;
}
}
if(currentStackSize > maxStackSize) {
currentStackSize = maxStackSize;
}
if(currentStackSize < 1) {
currentStackSize = 1;
}
}
void Update() {
if(merchantPrice <= 0) {
float percent20 = vendorPrice * 0.2f;
int tmp = (int)percent20;
merchantPrice = tmp + vendorPrice;
}
}
}
so what i need?
i want to know what will be the best way to add the element system, since i’m “starter” programmer i don’t know at all how to fully implement that at this point of the code development