/// <summary> /// Gets the available unit to produce for type. /// How many unit can produce for type. /// This is base on how much resource and available unit space /// </summary> public int GetAvaliableUnitToProduceForType(CombatUnitType type) { CombatUnit unit = GetCombatUnitInfoByType(type); Dictionary <ResourceType, float> costResource = unit.GetResourceCost; if (costResource != null) { int unitMinProduction = availableUnitToProduce; foreach (ResourceType rType in costResource.Keys) { ResourceStorage rs = Player.Instance.GetResourceStorage(rType); unitMinProduction = Mathf.Min(Mathf.FloorToInt(rs.currentResource / costResource[rType]), unitMinProduction); } return(unitMinProduction); } else { Debug.LogError("Combat unit type " + type.ToString() + " has no resource cost setup"); return(0); } }
/// <summary> /// Decreases the combat unit. /// </summary> /// <returns><c>true</c>, if combat unit was decreased, <c>false</c> otherwise.</returns> /// <param name="type">Type.</param> /// <param name="decreaseAmount">Decrease amount.</param> public bool DecreaseCombatUnit(CombatUnitType type, int decreaseAmount) { if (numberOfCombatUnit.Count <= 0) { return(false); } for (int i = 0; i < availableCombatUnit.Count; i++) { if (type == availableCombatUnit[i]) { if ((numberOfCombatUnit[i] - decreaseAmount) >= 0) { numberOfCombatUnit[i] -= decreaseAmount; } else { numberOfCombatUnit[i] = 0; } Save(); return(true); } } Debug.LogError("No unit type found " + type.ToString()); return(false); }
public UnitLostInfo(CombatUnitType type, int originalUnit, int unitLost) { unitType = type; from = originalUnit; lost = unitLost; to = Mathf.Clamp(from - lost, 0, from); }
/// <summary> /// Adds the combat unit. /// </summary> /// <param name="type">Type.</param> /// <param name="produceAmount">Produce amount.</param> public void AddCombatUnit(CombatUnitType type, int produceAmount) { int addAmount = produceAmount; if ((CurrentCombatUnit + addAmount) > maxCombatUnit) { Debug.LogError("Add combat unit overflow"); addAmount = maxCombatUnit - CurrentCombatUnit; } for (int i = 0; i < availableCombatUnit.Count; i++) { if (type == availableCombatUnit[i]) { numberOfCombatUnit[i] += addAmount; Save(); return; } } availableCombatUnit.Add(type); numberOfCombatUnit.Add(addAmount); Save(); }
bool CheckDuplicateFearUnitType(int unitIndex) { CombatUnit unit = _target.combatUnitInfo [unitIndex]; for (int i = 0; i < unit.fearUnit.Count; i++) { CombatUnitType compareType = unit.fearUnit[i]; int duplicateTime = 0; for (int j = 0; j < unit.fearUnit.Count; j++) { if (compareType == unit.fearUnit[j]) { ++duplicateTime; } } if (duplicateTime > 1) { return(true); } } return(false); }
public void SetUnitInfo(CombatUnit info) { unitInfo = info; SetContentTitle = info.unitName; unitType = info.unitType; }
public static ProduceUnitTask CreateTask(CombatUnitType unitType, int unitAmount, OnProduceUnitComplete completeCallBack = null, OnTimeLeftToComplete timeLeftCallBack = null, int duration = 1) { ProduceUnitTask task = new ProduceUnitTask(); task.InitTask(unitType, unitAmount, completeCallBack, timeLeftCallBack, duration); return(task); }
public void SetInfo(CombatUnitType type, int unitNumber) { _unitType = type; unitAvatar.spriteName = ImageManager.Instance.CombatUnitSpriteNameForHead(type); valueSlider.Evt_OnValueChange = OnValueChange; valueSlider.SetupValueSlider(unitNumber, unitNumber); }
public void InitTask(CombatUnitType unitType, int unitAmount, OnProduceUnitComplete completeCallBack = null, OnTimeLeftToComplete timeLeftCallBack = null, int duration = 1) { base.InitTask(duration, timeLeftCallBack); _producingUnitType = unitType; _producingUnitAmount = unitAmount; Evt_OnProduceUnitComplete += completeCallBack; }
void OnValueChange(CombatUnitType unitType, int unitNumber) { if (deployInfos.ContainsKey(unitType)) { deployInfos[unitType] = unitNumber; } else { deployInfos.Add(unitType, unitNumber); } }
/* * bool IsTaskComplete() * { * CombatUnitManagerMetaData data = CombatUnitManagerMetaData.Load (); * * return data.IsProduceUnitComplete (); * } * * IEnumerator CompleteTask() * { * while(!IsTaskComplete()) * { * Debug.Log("Wait for server task complete"); * * yield return new WaitForSeconds(1f); * } * * UITimePopupController.Instance.HideTimePopup (transform); * * UpdateCombatUnitManager (); * * Architecture archi = GetComponent<Architecture> (); * * if(archi.isSelected) * { * UIArchitectureMenuController.Instance.GetMenu(transform, ArchitectureMenuType.Normal); * } * * } */ /// <summary> /// Handle producing unit complete event. /// </summary> /// <param name="task">Task.</param> /// <param name="unitType">Unit type.</param> /// <param name="amount">Amount.</param> void OnProducingUnitComplete(ProduceUnitTask task, CombatUnitType unitType, int amount) { //StartCoroutine (CompleteTask()); _task = null; UITimePopupController.Instance.HideTimePopup(transform); UpdateCombatUnitManager(); EventManager.GetInstance().ExecuteEvent <EventProduceCombatUnitComplete> (new EventProduceCombatUnitComplete(this)); }
/// <summary> /// Gets the type of the combat unit info by unit type. /// </summary> /// <returns>The combat unit info by type.</returns> /// <param name="type">Type.</param> public CombatUnit GetCombatUnitInfoByType(CombatUnitType type) { for (int i = 0; i < combatUnitInfo.Count; i++) { if (combatUnitInfo[i].unitType == type) { return(combatUnitInfo[i]); } } return(null); }
public int NumberOfUnitByType(CombatUnitType type) { for (int i = 0; i < availableCombatUnit.Count; i++) { if (type == availableCombatUnit[i]) { return(numberOfCombatUnit[i]); } } return(0); }
/// <summary> /// Gets the type of the all unit. /// </summary> /// <returns>The all unit type.</returns> /// <param name="unitKeys">Unit keys.</param> CombatUnitType[] GetAllUnitType(Dictionary <CombatUnit, int> .KeyCollection unitKeys) { CombatUnitType[] retVal = new CombatUnitType[unitKeys.Count]; int index = 0; foreach (CombatUnit theUnit in unitKeys) { retVal[index] = theUnit.unitType; ++index; } return(retVal); }
/// <summary> /// Gets the type of the unit quantity for unit type. /// Return 0 if can't find unit type /// </summary> /// <returns>The unit quantity for type.</returns> /// <param name="type">Type.</param> public int GetUnitQuantityForType(CombatUnitType type) { CombatUnitManagerMetaData data = CombatUnitManagerMetaData.Load(); _unitTypeAndNumber = data.GetAllUnit(); foreach (CombatUnitType unitType in _unitTypeAndNumber.Keys) { if (type == unitType) { return(_unitTypeAndNumber[unitType]); } } return(0); }
public string CombatUnitSpriteNameForFullBody(CombatUnitType type) { if (combatUnitType.Contains(type)) { for (int i = 0; i < combatUnitType.Count; i++) { if (combatUnitType[i] == type) { return(combatUnitFullBodySpriteName[combatUnitType.IndexOf(type)]); } } return(""); } return(""); }
/* * public bool DecreaseCombatUnit(int decreaseAmount) * { * if(numberOfCombatUnit.Count <= 0) * { * return false; * } * * if((CurrentCombatUnit-decreaseAmount) < 0) * { * return false; * } * * numberOfCombatUnit [0] -= decreaseAmount; * * Save (); * * return true; * } */ /* * public void AddCombatUnit(int amount) * { * if(numberOfCombatUnit.Count <= 0) * { * return; * } * * int addAmount = amount; * * if((CurrentCombatUnit+amount) > maxCombatUnit) * { * addAmount = maxCombatUnit - CurrentCombatUnit; * } * * numberOfCombatUnit [0] += addAmount; * * Save (); * } */ /// <summary> /// Produces combat unit. /// </summary> /// <returns><c>true</c>, if combat unit was produced, <c>false</c> otherwise.</returns> /// <param name="unitType">Unit type.</param> /// <param name="produceAmount">Produce amount.</param> /// <param name="duration">Duration.</param> /// <param name="resourceCost">Resource cost.</param> public bool ProduceCombatUnit(CombatUnitType unitType, int produceAmount, int duration, Dictionary <ResourceType, float> resourceCost) { if (producingUnit) { return(false); } PlayerResourceStorageMetaData data = PlayerResourceStorageMetaData.Load(); if (duration <= 0) { AddCombatUnit(unitType, produceAmount); foreach (ResourceType type in resourceCost.Keys) { data.CostResource(type, produceAmount * resourceCost[type]); } Save(); return(true); } producingUnit = true; producingUnitType = unitType; producingAmount = produceAmount; producingDuration = duration; producingStartTime = DateTime.Now; producingEndTime = DateTime.Now.AddSeconds(producingDuration); //todo: cost resource foreach (ResourceType type in resourceCost.Keys) { data.CostResource(type, produceAmount * resourceCost[type]); } Save(); return(true); }
void DisplayAIPlayer() { EditorGUILayout.BeginVertical(); for (int i = 0; i < _target.aiPlayers.Count; i++) { EditorGUILayout.BeginHorizontal(); AIPlayer player = _target.aiPlayers[i]; _foldout[i] = EditorGUILayout.Foldout(_foldout[i], player.playerName); GUI.color = Color.red; if (GUILayout.Button("X", GUILayout.Width(30f))) { if (EditorUtility.DisplayDialogComplex("Delete AI Player", "Delete AI player " + player.playerName, "Ok", "Cancel", "") == 0) { _removedAIPlayers.Add(i); } } GUI.color = Color.white; EditorGUILayout.EndHorizontal(); if (_foldout[i]) { ++EditorGUI.indentLevel; EditorGUILayout.TextField(new GUIContent("ID:", "AI player id"), player.playerId); player.playerName = EditorGUILayout.TextField(new GUIContent("Name:", "AI player name"), player.playerName); if (string.IsNullOrEmpty(player.playerName)) { EditorGUILayout.HelpBox("You must give name", MessageType.Error); } player.attackDuration = EditorGUILayout.IntField(new GUIContent("Attack duratoin:", "How long does it take to attack this player"), player.attackDuration); if (player.attackDuration <= 0) { player.attackDuration = 1; } _combatUnitFoldout[i] = EditorGUILayout.Foldout(_combatUnitFoldout[i], "CombatUnit"); //render combat unit gui if (_combatUnitFoldout[i]) { ++EditorGUI.indentLevel; for (int j = 0; j < player.combatUnitType.Count; j++) { EditorGUILayout.BeginHorizontal(); player.combatUnitType[j] = (CombatUnitType)EditorGUILayout.EnumPopup(player.combatUnitType[j]); player.combatUnitNumber[j] = EditorGUILayout.IntField(player.combatUnitNumber[j]); GUI.color = Color.red; if (GUILayout.Button("X", GUILayout.Width(30f))) { _removedUnitIndex.Add(j); } GUI.color = Color.white; EditorGUILayout.EndHorizontal(); } foreach (int rIndex in _removedUnitIndex) { player.combatUnitType.RemoveAt(rIndex); player.combatUnitNumber.RemoveAt(rIndex); } _removedUnitIndex.Clear(); for (int k = 0; k < player.combatUnitType.Count; k++) { int duplicateCout = 0; CombatUnitType compareType = player.combatUnitType[k]; for (int f = 0; f < player.combatUnitType.Count; f++) { if (compareType == player.combatUnitType[f]) { ++duplicateCout; } } if (duplicateCout > 1) { EditorGUILayout.HelpBox("You need to fix duplicate unit type", MessageType.Error); break; } } GUI.color = Color.yellow; if (GUILayout.Button(new GUIContent("+", "Add new unit"))) { player.combatUnitType.Add(CombatUnitType.Unknow); player.combatUnitNumber.Add(1); } GUI.color = Color.white; --EditorGUI.indentLevel; } _resourceAwardFoldout[i] = EditorGUILayout.Foldout(_resourceAwardFoldout[i], "ResourceAward"); //render resource award gui if (_resourceAwardFoldout[i]) { --EditorGUI.indentLevel; for (int j = 0; j < player.resourceAwardType.Count; j++) { EditorGUILayout.BeginHorizontal(); player.resourceAwardType[j] = (ResourceType)EditorGUILayout.EnumPopup(player.resourceAwardType[j]); player.resourceAwardAmount[j] = (float)EditorGUILayout.IntField((int)player.resourceAwardAmount[j]); GUI.color = Color.red; if (GUILayout.Button("X", GUILayout.Width(30f))) { _removedResourceAwardIndex.Add(j); } GUI.color = Color.white; EditorGUILayout.EndHorizontal(); } foreach (int rIndex in _removedResourceAwardIndex) { player.resourceAwardType.RemoveAt(rIndex); player.resourceAwardAmount.RemoveAt(rIndex); } _removedResourceAwardIndex.Clear(); for (int k = 0; k < player.resourceAwardType.Count; k++) { int duplicateCout = 0; ResourceType compareType = player.resourceAwardType[k]; for (int f = 0; f < player.resourceAwardType.Count; f++) { if (compareType == player.resourceAwardType[f]) { ++duplicateCout; } } if (duplicateCout > 1) { EditorGUILayout.HelpBox("You need to fix duplicate resource type", MessageType.Error); break; } } GUI.color = Color.yellow; if (GUILayout.Button(new GUIContent("+", "Add new resource award"))) { player.resourceAwardType.Add(ResourceType.Unknow); player.resourceAwardAmount.Add(1f); } GUI.color = Color.white; ++EditorGUI.indentLevel; } --EditorGUI.indentLevel; } } RemoveAIPlayers(); GUI.color = Color.green; if (GUILayout.Button("Add new AI player")) { CreateNewAIPlayer(); } GUI.color = Color.white; EditorGUILayout.EndVertical(); }
protected CombatUnit(int hp, int strength, CombatUnitType unitType) { Health = hp; Strength = strength; UnitType = unitType; }
/// <summary> /// Produces combat unit. /// </summary> /// <returns><c>true</c>, if combat unit was produced, <c>false</c> otherwise.</returns> /// <param name="unitType">Unit type.</param> /// <param name="produceAmount">Produce amount.</param> public bool ProduceCombatUnit(CombatUnitType unitType, int produceAmount) { if ((combatUnitInfo != null) && (_task == null)) { CombatUnitManagerMetaData data = CombatUnitManagerMetaData.Load(); CombatUnit unitInfo = null; for (int i = 0; i < combatUnitInfo.Count; i++) { if (unitType == combatUnitInfo[i].unitType) { unitInfo = combatUnitInfo[i]; break; } } if (unitInfo != null) { //todo:check if resource is enough bool canProduceUnit = true; for (int i = 0; i < unitInfo.costResourceTypes.Count; i++) { if (!Player.Instance.IsResourceEnough(unitInfo.costResourceTypes[i], unitInfo.costResources[i] * produceAmount)) { EventManager.GetInstance().ExecuteEvent <EventAlert>(new EventAlert("Warning", "Not enough resources")); canProduceUnit = false; break; } } if (canProduceUnit) { Dictionary <ResourceType, float> resourceCost = new Dictionary <ResourceType, float>(); for (int i = 0; i < unitInfo.costResourceTypes.Count; i++) { resourceCost.Add(unitInfo.costResourceTypes[i], unitInfo.costResources[i]); } if (data.ProduceCombatUnit(unitInfo.unitType, produceAmount, unitInfo.generateDuration * produceAmount, resourceCost)) { _task = ProduceUnitTask.CreateTask(unitInfo.unitType, produceAmount, OnProducingUnitComplete, OnTimeLeftToComplete, unitInfo.generateDuration * produceAmount); TaskManager.Instance.AddTask(_task); //todo:post produce unit event List <ResourceType> costType = new List <ResourceType>(); foreach (ResourceType type in resourceCost.Keys) { costType.Add(type); } Architecture archi = GetComponent <Architecture> (); if (archi.isSelected) { UIArchitectureMenuController.Instance.GetMenu(transform, ArchitectureMenuType.OnTask); } EventManager.GetInstance().ExecuteEvent <EventProduceCombatUnit>(new EventProduceCombatUnit(costType)); return(true); } } else { return(false); } } else { Debug.LogError(gameObject.name + " unable to produce combat unit, no unit definition"); } } return(false); }
/// <summary> /// Instants produce combat unit. /// </summary> /// <returns><c>true</c>, if produce combat unit was instanted, <c>false</c> otherwise.</returns> /// <param name="unitType">Unit type.</param> /// <param name="produceAmount">Produce amount.</param> public bool InstantProduceCombatUnit(CombatUnitType unitType, int produceAmount) { if ((combatUnitInfo != null) && (_task == null)) { CombatUnitManagerMetaData data = CombatUnitManagerMetaData.Load(); CombatUnit unitInfo = null; for (int i = 0; i < combatUnitInfo.Count; i++) { if (unitType == combatUnitInfo[i].unitType) { unitInfo = combatUnitInfo[i]; break; } } if (unitInfo != null) { bool canProduceUnit = true; for (int i = 0; i < unitInfo.costResourceTypes.Count; i++) { if (!Player.Instance.IsResourceEnough(unitInfo.costResourceTypes[i], unitInfo.costResources[i] * produceAmount)) { EventManager.GetInstance().ExecuteEvent <EventAlert>(new EventAlert("Warning", "Not enough resources")); canProduceUnit = false; break; } } if (canProduceUnit) { Dictionary <ResourceType, float> resourceCost = new Dictionary <ResourceType, float>(); for (int i = 0; i < unitInfo.costResourceTypes.Count; i++) { resourceCost.Add(unitInfo.costResourceTypes[i], unitInfo.costResources[i]); } if (data.ProduceCombatUnit(unitInfo.unitType, produceAmount, 0, resourceCost)) { List <ResourceType> costType = new List <ResourceType>(); foreach (ResourceType type in resourceCost.Keys) { costType.Add(type); } EventManager.GetInstance().ExecuteEvent <EventProduceCombatUnit>(new EventProduceCombatUnit(costType)); return(true); } } } else { Debug.LogError(gameObject.name + " unable to produce combat unit, no unit definition"); } } return(false); }
public EventUIProduceUnitClick(CombatUnitType type, int amount) { unitType = type; produceAmount = amount; }
/// <summary> /// Sets the unit info. /// </summary> /// <param name="avatarName">Avatar name.</param> /// <param name="unitNumber">Unit number.</param> public void SetUnitInfo(CombatUnitType type, int unitNumber) { unitAvatar.spriteName = ImageManager.Instance.CombatUnitSpriteNameForHead(type); unitNumberLabel.text = unitNumber.ToString(); }