public void LoadGame() { LoadData(); Inventory.PlayerInventory.Gold = save.PlayerGold; Inventory.PlayerInventory.Items.Clear(); foreach (string itemName in save.Items) { Item item = Resources.Load("Items/" + itemName) as Item; Inventory.PlayerInventory.Items.Add(item); } UnitList.instance.units.Clear(); for (int i = 0; i < save.UnitIconName.Count; i++) { //TODO normal constructor CreachureStats unit = new CreachureStats(); unit.MaxHealth = save.UnitHealth[i]; unit.icon = Resources.Load <Sprite>("UnitsIcons/" + save.UnitIconName[i]); UnitList.instance.isOnBattleField[i] = save.UnitIsOnBattleField[i]; unit.Speed = save.UnitSpeed[i]; unit.status = (Status)save.UnitStatus[i]; unit.Damage = save.UnitDamage[i]; UnitList.instance.BattleFieldIndex[i] = save.UnitBattleIndex[i]; UnitList.instance.AddUnit(unit); } }
public void SpawnPlayerUnits() { int offsetX = (map.mapSizeX / 2) - (map.mapSizeX / 4); int offsetZ = 7; for (int i = 0; i < playerUnits.units.Count; i++) { if (playerUnits.isOnBattleField[i]) { CreachureStats creachure = playerUnits.units[i]; GameObject spawned = GameObject.Instantiate(Resources.Load("BattlePlayerUnit")) as GameObject; BattleUnit battleUnit = spawned.GetComponent <BattleUnit>(); PlayerBattleList.Add(battleUnit); BattleOrder.Add(battleUnit); int tileX = playerUnits.BattleFieldIndex[i] / 6 + offsetX; int tileZ = playerUnits.BattleFieldIndex[i] % 6 + offsetZ; battleUnit.tileX = tileX; battleUnit.tileZ = tileZ; battleUnit.UnitStats = creachure; battleUnit.visionRange = creachure.VisionRange; spawned.transform.position = BattleMap.ConvertTileCoordToWorld(battleUnit.tileX, battleUnit.tileZ); map.tiles[tileX, tileZ].mapObjects.Add(battleUnit); map.visibleObjects.Add(battleUnit); } } }
private void ReforceUnits() { for (int i = 0; i <= Random.Range(1, 5); i++) { CreachureStats unit = new CreachureStats(); unit.icon = Resources.Load <Sprite>("UnitsIcons/Helmet"); unitsToBuy.Add(unit); } }
public void AddUnit(CreachureStats unit) { if (globalMapUI == null) { globalMapUI = UIGlobalMap.instance; } units.Add(unit); isOnBattleField.Add(false); BattleFieldIndex.Add(0); globalMapUI.AddUnitOnUI(units.Count - 1, unit.icon, isOnBattleField[units.Count - 1], BattleFieldIndex[units.Count - 1]); }
public void SetInfo(CreachureStats unit) { levelText.text = "LVL: " + unit.Level.ToString(); healthText.text = "HP: " + unit.MaxHealth.ToString(); strengthText.text = "STR: " + unit.Strength.ToString(); agilityText.text = "AGI: " + unit.Agility.ToString(); speedText.text = "SPD: " + unit.Speed.ToString(); costText.text = unit.Cost.ToString(); icon.sprite = unit.icon; }
public bool BuyUnit(int index) { CreachureStats unit = selectedCity.unitsToBuy[index]; if (Inventory.PlayerInventory.Gold >= unit.Cost) { Inventory.PlayerInventory.Gold -= unit.Cost; UnitList.instance.AddUnit(unit); selectedCity.unitsToBuy.RemoveAt(index); return(true); } return(false); }
public void SpawnEnemyUnits() { //TEST int index = 0; int offsetX = (map.mapSizeX / 2) + (map.mapSizeX / 4); int x = 0; int z = 0; foreach (UnitPreset preset in GameSettings.instance.Enemies) { CreachureStats creachure = new CreachureStats(preset); GameObject spawned = GameObject.Instantiate(Resources.Load("EnemyBattle")) as GameObject; spawned.name = "Enemy " + index; index++; BattleUnit battleUnit = spawned.GetComponent <BattleUnit>(); EnemyBattleList.Add(battleUnit); BattleOrder.Add(battleUnit); //UNDONE Check to melee go first int offsetZ = (z / 2); if (z % 2 != 0) { offsetZ++; offsetZ *= -1; } int tileZ = (map.mapSizeZ / 2) - 1 + offsetZ; int tileX = offsetX + x; z++; if (z == 8) { z = 0; x++; } battleUnit.tileX = tileX; battleUnit.tileZ = tileZ; battleUnit.UnitStats = creachure; battleUnit.visionRange = creachure.VisionRange; spawned.transform.position = BattleMap.ConvertTileCoordToWorld(battleUnit.tileX, battleUnit.tileZ); map.tiles[tileX, tileZ].mapObjects.Add(battleUnit); } }
void Update() { float distance = Vector3.Distance(target.position, transform.position); if (distance <= lookRadius) { agent.SetDestination(target.position); if (distance <= agent.stoppingDistance) { CreachureStats targetStats = target.GetComponent <CreachureStats>(); if (targetStats != null) { combat.Attack(targetStats); } FaceTarget(); } } }
public void Attack(CreachureStats targetStats) { if (attackCoolDown <= 0) { int fameForFrag = targetStats.TakeDamage(myStats.Damage); if (fameForFrag > 0) { PlayerStats playerStats = GetComponent <PlayerStats>(); if (playerStats != null) { playerStats.Fame += fameForFrag; } } if (OnAttack != null) { OnAttack(); } //StartCoroutine(DoDamage(targetStats, 1f)); attackCoolDown = 1f / myStats.attackSpeed; } }
// public DataNPC() { //LevelGeneration level = PlayerManager.instance.levelGeneration; GameObject[] sceneObjects = GameObject.FindGameObjectsWithTag("NPC"); length = sceneObjects.Length; NPC = new string[length]; position = new float[length, 3]; rotation = new float[length, 3]; Name = new string[length]; maxHp = new int[length]; hp = new int[length]; attackSpeed = new float[length]; fameForKill = new int[length]; damage = new int[length]; armor = new int[length]; hasInventory = new bool[length]; inventoryType = new InventoryType[length]; inventoryGold = new int[length]; inventoryMaxSpace = new int[length]; inventoryCurrentSpace = new int[length]; //FIX that's fail to hardcode here 100 inventoryItems = new string[length, 100]; for (int i = 0; i < length; i++) { NPC[i] = SaveSystem.GetPrefabName(sceneObjects[i].name); position[i, 0] = sceneObjects[i].transform.position.x; position[i, 1] = sceneObjects[i].transform.position.y; position[i, 2] = sceneObjects[i].transform.position.z; rotation[i, 0] = sceneObjects[i].transform.rotation.eulerAngles.x; rotation[i, 1] = sceneObjects[i].transform.rotation.eulerAngles.y; rotation[i, 2] = sceneObjects[i].transform.rotation.eulerAngles.z; CreachureStats stats = sceneObjects[i].GetComponent <CreachureStats>(); Name[i] = stats.Name; maxHp[i] = stats.maxHealth; hp[i] = stats.CurrentHealth; attackSpeed[i] = stats.attackSpeed; fameForKill[i] = stats.fameForKill; damage[i] = stats.Damage; armor[i] = stats.Armor; Inventory inventory = sceneObjects[i].GetComponent <Inventory>(); hasInventory[i] = false; if (inventory != null) { hasInventory[i] = true; } if (hasInventory[i]) { inventoryType[i] = inventory.inventoryType; inventoryMaxSpace[i] = inventory.space; inventoryGold[i] = inventory.gold; inventoryCurrentSpace[i] = inventory.items.Count; for (int j = 0; j < inventoryCurrentSpace[i]; j++) { inventoryItems[i, j] = inventory.items[j].name; } } } }
void Start() { myStats = GetComponent <CreachureStats>(); }
void Start() { playertarget = PlayerManager.instance.player; myStats = GetComponent <CreachureStats>(); playerCombat = playertarget.GetComponent <CharacterCombat>(); }