public bool CanBuy(Unit.Name unitName) { if (!army) { return(false); } var king = King.dict[army.color]; if (King.kingNames.Contains(unitName)) { if (unitName != king.name) { throw new Exception("Cannot buy King of other army but the Castle's Army !"); } else if (king.gameObject.activeSelf) { return(false); } } else if (unitName == Unit.Name.SKELETON || unitName == Unit.Name.CRYSTAL) { return(false); } var unit = unitName == king.name ? king : R.asset.prefab.units[unitName]; unit.transform.position = transform.position; var pos = transform.position.WorldToArray(); return(army.money >= unit.cost && (!Unit.array[pos.x][pos.y] || UnitAlgorithm.FindMove(unit, army).Count > 0)); }
private void PrepareToBuy() { var king = King.dict[currentCastle.army.color]; // Calculate canBuyList var tmp = new List <Unit.Name>(); foreach (var name in allNormalNamesCanBuy) { if (currentCastle.CanBuy(name)) { tmp.Add(name); } } castleKingName = king.name; if (currentCastle.CanBuy(castleKingName)) { tmp.Add(castleKingName); } canBuyList = tmp; if (!king.gameObject.activeSelf) { kingButton.gameObject.SetActive(true); kingButton.image.sprite = canBuyList.Contains(castleKingName) ? R.asset.prefab.units[castleKingName].spriteRenderer.sprite : king.sleepSprite; } else { kingButton.gameObject.SetActive(false); } // Modify all buttons by current battle conditions foreach (var name in allNormalNamesCanBuy) { buttons[name].image.sprite = canBuyList.Contains(name) ? R.asset.sprite.units[name][currentCastle.army.color] : R.asset.prefab.units[name].sleepSprite; } }
public Unit Buy(Unit.Name unitName) { var pos = transform.position.WorldToArray(); bool hasUnit = Unit.array[pos.x][pos.y]; var king = King.dict[army.color]; if (unitName == king.name) { army.units.Add(king); king.transform.position = transform.position; if (!hasUnit) { Unit.array[pos.x][pos.y] = king; } king.gameObject.SetActive(true); return(king); } var unit = Unit.New(unitName, army, transform.position); unit.Use(); army.money -= unit.cost; return(unit); }
public BuyAction(Vector3Int currentPos, Unit.Name unitName) : base(currentPos) { this.unitName = unitName; }