Hello everyone. Please be patient with your unworthy servant.
Still trying to wrap my head around how classes work. Making progress but have hit a stumbling block.
I have a script, monobehaviour, that I want to use to control random item(armor weapons etc)
A couple scripts, non monobehavior, to actually do the random generating.
A UI Control script, MonoBehavior, to display stats, allow selections etc.
It all works fine (as much as I have prototyped so far) when I use key input from the loot generation script.
Problem occurs when I made a prototype chest with the script, monobehavior, to set the arguments to pass to the loot generator script, I can not figure out how to make it work.
So, in theory;
Player opens chest, chest randomly picks armor, weapon or item and passes those arguments to LootGenControl.ArmorGeneration which randomizes equipment slot, type bonuses etc.
Here are the main scripts. Any help pointing me in the correct direction would be most greatly appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LootGenController : MonoBehaviour
{
private int lootIdentifier; // use to generate unique number for loot items
private Inventory inventory;
private ArmorGeneration armorGen; // Armor Generation Script
private bool armorGenCheck;
private WeaponGeneration weaponGen; // Weapon Generation Script
private bool weaponGenCheck;
//private ItemGeneration itemGen; // Item Generation Script
// private bool itemGenCheck;
public UI_Controller uiControl; // UI Control Script
void Start()
{
lootIdentifier = 0;
inventory = new Inventory();
armorGen = new ArmorGeneration();
armorGenCheck = false;
weaponGen = new WeaponGeneration();
weaponGenCheck = false;
//itemGen = new ItemGeneration();
//itemGenCheck = false;
}
void Update()
{
//use for testing loot generation - temporary
if (Input.GetKeyDown("z"))
{
ArmorGeneration(1);
}
if (Input.GetKeyDown("x"))
{
WeaponGeneration(1);
}
}
public void ArmorGeneration(int armorChestLevel)
{
Debug.Log("Inside Armor Gen");
lootIdentifier = inventory.AdvanceIdentifier(lootIdentifier); // increase loot identifier
armorGenCheck = armorGen.Generate(armorChestLevel, lootIdentifier); // generate random armor
if (armorGenCheck)
{
uiControl.DisplayArmorGenStats(armorGen); // display armor stats
}
else Debug.Log("ArmorGenCheck Failed!");
}
public void WeaponGeneration(int weaponChestLevel)
{
lootIdentifier = inventory.AdvanceIdentifier(lootIdentifier); // increase loot identifier
weaponGenCheck = weaponGen.Generate(weaponChestLevel, lootIdentifier);
if (weaponGenCheck)
{
uiControl.DisplayWeaponGenStats(weaponGen);
}
else Debug.Log("WeaponGenCheck Failed!");
}
public void Discard() // discard random item
{
uiControl.DeactivateInvButtons();
uiControl.StatsTextReset();
}
public void PlaceInInventory() // place item in inventory, call inventory management
{
uiControl.DeactivateInvButtons();
inventory.InventoryIn();
}
public void EquipItem() // equip item, call inventory management
{
uiControl.DeactivateInvButtons();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChestLevelOne : MonoBehaviour
{
private bool isOpen = false;
private int chestLevel = 1;
private int chestType;
// public GameObject lootGenControl; // No worky
private LootGenController lootGenControl;
void Start ()
{
chestType = (int)Random.Range(1.1f, 3.9f);
//lootGenControl = new LootGenController(); No worky
//lootGenControl = GetComponent<LootGenController>(); // Cannot Implicitly Convert Type "LootGenController
// to type "Unity Game Object"
lootGenControl = GetComponent<LootGenController>();
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
Debug.Log("Player opens chest!");
lootGenControl.ArmorGeneration(chestLevel);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ArmorGeneration
{
// variables to be passed to armor class after generation
public int armorIdentifier;
public int level;
public int protection;
public string itemName;
public string itemSlot;
public int meleeDef;
public int magicDef;
public int iceRes;
public int fireRes;
public int poisonRes;
public int electricRes;
private bool assignment;
public bool Generate(int lootLevel, int identify) // armor loot generator control
{
level = lootLevel;
armorIdentifier = identify; // use as unique identifier for instances
Reset();
GenerateArmor();
return assignment;
}
void Reset() // resets stats prior to generation
{
protection = 0;
itemName = "";
itemSlot = "";
meleeDef = 0;
magicDef = 0;
iceRes = 0;
fireRes = 0;
poisonRes = 0;
electricRes = 0;
assignment = false;
}
void GenerateArmor() // set useable slot for generated armor
{
int slot = (int)(Random.Range(1.1f, 6.9f));
switch (slot)
{
case 1:
itemSlot = "head";
HeadArmor();
break;
case 2:
itemSlot = "body";
BodyArmor();
break;
case 3:
itemSlot = "legs";
LegArmor();
break;
case 4:
itemSlot = "hands";
HandArmor();
break;
case 5:
itemSlot = "feet";
FeetArmor();
break;
case 6:
itemSlot = "shield";
ShieldArmor();
break;
default:
Debug.Log("armorSlot undefined!");
break;
}
}
void HeadArmor()
{
if (level == 1)
{
itemName = "Small Leather Cap";
meleeDef = 1;
}
if (level == 2)
{
itemName = "Studded Leather Cap";
meleeDef = 2;
}
if (level == 3)
{
itemName = "Tin Helmet";
meleeDef = 3;
}
if (level == 4)
{
itemName = "Bronze Helmet";
meleeDef = 4;
}
if (level == 5)
{
itemName = "Steel Helmet";
meleeDef = 6;
}
if (itemName == "")
{
Debug.Log("Helmet Level Unidentified!"); //debug if helmet generation fails.
}
else assignment = true;
}
void BodyArmor()
{
if (level == 1)
{
itemName = "Worn Leather Armor";
meleeDef = 2;
}
if (level == 2)
{
itemName = "Sturdy Leather Armor";
meleeDef = 4;
}
if (level == 3)
{
itemName = "Studded Leather Armor";
meleeDef = 6;
}
if (level == 4)
{
itemName = "Bronze Armor";
meleeDef = 8;
}
if (level == 5)
{
itemName = "Steel Armor";
meleeDef = 12;
}
if (itemName == "")
{
Debug.Log("Armor Level Unidentified!"); // debug if armor generation fails.
}
else assignment = true;
}
void LegArmor()
{
if (level == 1)
{
itemName = "Worn Leather Leggings";
meleeDef = 2;
}
if (level == 2)
{
itemName = "Sturdy Leather Leggings";
meleeDef = 3;
}
if (level == 3)
{
itemName = "Studded Leather Leggings";
meleeDef = 4;
}
if (level == 4)
{
itemName = "Bronze Leggings";
meleeDef = 5;
}
if (level == 5)
{
itemName = "Steel Leggings";
meleeDef = 7;
}
if (itemName == "")
{
Debug.Log("Legging Level Unidentified!"); //debug if legging generation fails.
}
else assignment = true;
}
void HandArmor()
{
if (level == 1)
{
itemName = "Torn Leather Gloves";
meleeDef = 1;
}
if (level == 2)
{
itemName = "Good Leather Gloves";
meleeDef = 2;
}
if (level == 3)
{
itemName = "Padded Leather Gloves";
meleeDef = 3;
}
if (level == 4)
{
itemName = "Chain Gloves";
meleeDef = 4;
}
if (level == 5)
{
itemName = "Steel Gauntlets";
meleeDef = 6;
}
if (itemName == "")
{
Debug.Log("Glove Level Unidentified!"); //debug if glove generation fails.
}
else assignment = true;
}
void FeetArmor()
{
if (level == 1)
{
itemName = "Worn Leather Sandals";
meleeDef = 1;
}
if (level == 2)
{
itemName = "Quality Leather Sandals";
meleeDef = 2;
}
if (level == 3)
{
itemName = "Leather Boots";
meleeDef = 3;
}
if (level == 4)
{
itemName = "Bronze Boots";
meleeDef = 4;
}
if (level == 5)
{
itemName = "Steel Boots";
meleeDef = 6;
}
if (itemName == "")
{
Debug.Log("Boot Level Unidentified!"); //debug if boot generation fails.
}
else assignment = true;
}
void ShieldArmor()
{
if (level == 1)
{
itemName = "Damaged Wooden Shield";
meleeDef = 2;
}
if (level == 2)
{
itemName = "Good Wooden Shield";
meleeDef = 3;
}
if (level == 3)
{
itemName = "Tin Shield";
meleeDef = 4;
}
if (level == 4)
{
itemName = "Bronze Shield";
meleeDef = 5;
}
if (level == 5)
{
itemName = "Steel Shield";
meleeDef = 7;
}
if (itemName == "")
{
Debug.Log("Shield Level Unidentified!"); //debug if shield generation fails.
}
else assignment = true;
}
}