public static (int, int) GetUpgradeCost(UnitUpgrades upgrade, Player _player) { Upgrade myupgrade = UpgradePool.Upgrades.Where(x => x.Race == _player.Race && x.Name == upgrade).FirstOrDefault(); if (myupgrade == null) { return(0, 0); } if (_player.Upgrades != null && _player.Upgrades.Count() > 0) { UnitUpgrade plup = _player.Upgrades.Where(x => x.Upgrade == myupgrade.Name).FirstOrDefault(); if (plup != null) { if (plup.Level == 3) { return(0, plup.Level); } else { return(myupgrade.Cost.SingleOrDefault(x => x.Key == plup.Level + 1).Value, plup.Level + 1); } } } return(myupgrade.Cost[0].Value, 1); }
public static int UpgradeUnit(UnitUpgrades upgrade, Player _player) { (int cost, int lvl) = GetUpgradeCost(upgrade, _player); Upgrade myupgrade = UpgradePool.Upgrades.Where(x => x.Race == _player.Race && x.Name == upgrade).FirstOrDefault(); if (myupgrade == null) { return(0); } UnitUpgrade plup = _player.Upgrades.Where(x => x.Upgrade == myupgrade.Name).FirstOrDefault(); if (plup != null) { if (plup.Level < 3) { plup.Level++; } } else { UnitUpgrade newup = new UnitUpgrade(); newup.Upgrade = myupgrade.Name; newup.Level = 1; _player.Upgrades.Add(newup); } return(cost); }
public static Dictionary <int, Dictionary <int, List <UnitUpgrade> > > GetUpgrades(dsreplay replay) { Dictionary <int, Dictionary <int, List <UnitUpgrade> > > Upgrades = new Dictionary <int, Dictionary <int, List <UnitUpgrade> > >(); foreach (dsplayer pl in replay.PLAYERS) { Upgrades[pl.POS] = new Dictionary <int, List <UnitUpgrade> >(); foreach (var ent in pl.Upgrades) { int gameloop = ent.Key; foreach (var upgrades in ent.Value) { UnitUpgrade u = UpgradePool.Map(upgrades); if (u != null) { if (!Upgrades[pl.POS].ContainsKey(gameloop)) { Upgrades[pl.POS][gameloop] = new List <UnitUpgrade>(); } Upgrades[pl.POS][gameloop].Add(u); } } } } return(Upgrades); }
protected virtual void Awake() { myAttackRange = FindObjectOfType <AttackRange>().GetComponent <AttackRange>(); myAnimator = GetComponent <tk2dSpriteAnimator>(); projectileParent = GameObject.Find("ProjectilePool").GetComponent <Transform>(); upgradeLevel = 1; upgrade = new UnitUpgrade(firstUpgradePrice, 1); }
public void GiveUnitUpgrade(UnitUpgrade? upgrade, int numLevels) { if (upgrade == UnitUpgrade.Firepower) FirepowerLevel = Math.Min(FirepowerLevel + numLevels, info.FirepowerMaxLevel); else if (upgrade == UnitUpgrade.Armor) ArmorLevel = Math.Min(ArmorLevel + numLevels, info.ArmorMaxLevel); else if (upgrade == UnitUpgrade.Speed) SpeedLevel = Math.Min(SpeedLevel + numLevels, info.SpeedMaxLevel); }
public void Upgrade(Spawner spawner, UnitUpgrade upgrade) { // if there are more tiers, and we have the money, upgrade the selected spawner if ( spawner!=null && upgrade!=null && currentMoney > upgrade.cost ) { currentMoney -= upgrade.cost; spawner.currentUpgrade= upgrade; spawner.transform.FindChild("Barrack").renderer.material.color = upgrade.barrackColor; } }
public bool CanGainUnitUpgrade(UnitUpgrade? upgrade) { if (upgrade == UnitUpgrade.Firepower) return FirepowerLevel < info.FirepowerMaxLevel; if (upgrade == UnitUpgrade.Armor) return ArmorLevel < info.ArmorMaxLevel; if (upgrade == UnitUpgrade.Speed) return SpeedLevel < info.SpeedMaxLevel; return false; }
public bool CanUpgrade(UnitUpgrade upgrate) { if (unitUpgrades[(int)upgrate] + 1 <= maxUpgradeLevels[(int)upgrate]) { switch (upgrate) { //case UnitUpgrade.Efficiency://можно всегда // break; case UnitUpgrade.MiningBoost: if (!unitModules[(int)UnitModule.Mining]) { return(false); } break; case UnitUpgrade.MeleeBoost: if (!unitModules[(int)UnitModule.MeleeAttack]) { return(false); } break; case UnitUpgrade.DistantBoost: if (!unitModules[(int)UnitModule.RangeAttack]) { return(false); } break; //case UnitUpgrade.MovingBoost://можно всегда // break; case UnitUpgrade.BuildingBoost: if (!unitModules[(int)UnitModule.Building]) { return(false); } break; //case UnitUpgrade.VisibilityRadiusIncrease://можно всегда // break; //case UnitUpgrade.HeavyArmor://можно всегда // break; case UnitUpgrade.RepairBoost: if (!unitModules[(int)UnitModule.Repair]) { return(false); } break; } return(true); } return(false); }
void AddFirstButtonAction(Unit unit, UnitUpgrade upgr) { FirstButton.transform.GetComponentInChildren<Text>().text = "Add Upgrade"; FirstButton.onClick.RemoveAllListeners(); FirstButton.onClick.AddListener(()=> { unit.Upgrades.Add(new UnitUpgrade(upgr.Workname)); XMLWorker.SaveSC(Controller.CurrentCitadel); ShowUnit(unit); FirstButton.transform.GetComponentInChildren<Text>().text = ""; Controller.UpgradeChange(unit); unit.RecountProps(); RefreshInfo(unit); FirstButton.onClick.RemoveAllListeners(); }); }
void AddSecondButtonAction(Unit unit, UnitUpgrade upgr) { SecondButton.transform.GetComponentInChildren<Text>().text = "Remove Upgrade"; SecondButton.onClick.RemoveAllListeners(); SecondButton.onClick.AddListener(() => { unit.Upgrades.Remove(upgr); //XMLWorker.RemoveUpgrade(Controller.CurrentCitadel); ShowUnit(unit); SecondButton.transform.GetComponentInChildren<Text>().text = ""; Controller.UpgradeChange(unit); unit.RecountProps(); RefreshInfo(unit); SecondButton.onClick.RemoveAllListeners(); }); }
static void GenerateFactions() { UnitStats stats = new UnitStats(); stats.SoftAttack = 4; stats.SoftDefence = 4; stats.HardAttack = 3; stats.HardDefence = 3; stats.BombardmentDefence = 3; stats.Movement = 3; stats.Flags.Add(UnitFlag.Infantry); UnitStats bonus = new UnitStats(); bonus.HardAttack = 1; bonus.HardDefence = 1; UnitUpgrade upgrade = new UnitUpgrade(); upgrade.Name = "Upgrade"; upgrade.Points = 5; upgrade.Slot = 0; UnitType unit = new UnitType(); unit.Name = "Name"; unit.Points = 20; unit.Hardness = 0.0; unit.Stats = stats;; unit.Upgrades.Add(upgrade); Faction faction = new Faction(); faction.Name = "Faction"; faction.Description = "Description"; faction.Units.Add(unit); FactionConfiguration factions = new FactionConfiguration(); factions.Factions.Add(faction); var serialiser = new Nil.Serialiser <FactionConfiguration>("Factions.xml"); serialiser.Store(factions); }
//Initialize Unit upgrades private void InitUnitUpgrade() { for (int i = 0; i < numUnitUpgrades; ++i) { //create new unit upgrade object UnitUpgrade uu = new UnitUpgrade(); uu.overlord = overlord; uu.unit = unit; uu.ID = i; uu.upgrade = this; uu.cost = unitUpgradeCosts[i]; uu.upgradeImage = UnitUpgradeImages[i]; //set overlord action uu.overlordAction = () => { overlord.SetUnitUpgrade(unit.BaseStats().unitID, i); }; //set in array unitUpgrades[i] = uu; } }
public static BuildingOperation NewUpgrade(Building building, Unit unit, UnitUpgrade up) { return(new NewUpgrade(building, unit, (int)up)); }
public int GetUpgrade(UnitUpgrade upgrade) { return(unitUpgrades[(int)upgrade]); }
public void SetUpgrade(UnitUpgrade upgrade, int value) { unitUpgrades[(int)upgrade] = value; }
public void Upgrade(UnitUpgrade upgrade) { switch (upgrade) { case UnitUpgrade.Damage: Damage += DAMAGE_UPGRADE; break; case UnitUpgrade.Hitpoints: MaxHitpoints += HITPOINTS_UPGRADE; break; } }
private static void Set(UnitUpgrade up, UnitStats v) { dat[(int)up] = v; }
public static UnitStats Get(UnitUpgrade up) { return(dat[(int)up]); }
public static UnitUpgrade Map(string repUpgrade) { UnitUpgrade myupgrade = null; string race = ""; int level = 0; string type = ""; string add = ""; Match match = rxUpgrade.Match(repUpgrade); if (match.Success) { race = match.Groups[1].Value.ToString(); type = match.Groups[2].Value.ToString(); level = int.Parse(match.Groups[3].Value); add = match.Groups[4].Value; UnitRace myrace = UnitRace.Terran; if (race == "Protoss") { myrace = UnitRace.Protoss; } else if (race == "Terran") { myrace = UnitRace.Terran; } else if (race == "Zerg") { myrace = UnitRace.Zerg; } UnitUpgrades upgradename = UnitUpgrades.GroundArmor; // Protoss if (type == "AirArmor") { upgradename = UnitUpgrades.AirArmor; } else if (type == "AirWeapons") { upgradename = UnitUpgrades.AirAttac; } else if (type == "GroundArmor") { upgradename = UnitUpgrades.GroundArmor; } else if (type == "GroundWeapons") { upgradename = UnitUpgrades.GroundAttac; } else if (type == "Shields") { upgradename = UnitUpgrades.ShieldArmor; } // Terran else if (type == "InfantryArmor") { upgradename = UnitUpgrades.GroundArmor; } else if (type == "InfantryWeapons") { upgradename = UnitUpgrades.GroundAttac; } else if (type == "VehicleandShipPlating" || type == "VehicleAndShipPlating") { upgradename = UnitUpgrades.VehicelArmor; } else if (type == "VehicleWeapons") { upgradename = UnitUpgrades.VehicelAttac; } // Zerg else if (type == "FlyerAttacks") { upgradename = UnitUpgrades.AirAttac; } else if (type == "FlyerCarapace") { upgradename = UnitUpgrades.AirArmor; } else if (type == "GroundCarapace") { upgradename = UnitUpgrades.GroundArmor; } else if (type == "MeleeAttacks") { upgradename = UnitUpgrades.GroundMeleeAttac; } else if (type == "MissileAttacks") { upgradename = UnitUpgrades.GroundAttac; } Upgrade u = UpgradePool.Upgrades.SingleOrDefault(x => x.Race == myrace && x.Name == upgradename); if (u != null) { myupgrade = new UnitUpgrade(); myupgrade.Upgrade = u.Name; myupgrade.Level = level; } } return(myupgrade); }
/// <summary> /// 改良情報の追加ボタン押下時の処理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnUpgradeAddButtonClick(object sender, EventArgs e) { // 選択中のユニットクラスがなければ何もしない UnitClass unit = classListBox.SelectedItem as UnitClass; if (unit == null) { return; } UnitClass selected = upgradeTypeComboBox.SelectedItem as UnitClass; UnitUpgrade upgrade = new UnitUpgrade { Type = selected?.Type ?? unit.Type }; double val; if (DoubleHelper.TryParse(upgradeCostTextBox.Text, out val)) { upgrade.UpgradeCostFactor = val; } if (DoubleHelper.TryParse(upgradeTimeTextBox.Text, out val)) { upgrade.UpgradeTimeFactor = val; } Log.Info("[Unit] Added upgrade info: {0} {1} {2} ({3})", Units.Items[(int) upgrade.Type], DoubleHelper.ToString(upgrade.UpgradeCostFactor), DoubleHelper.ToString(upgrade.UpgradeTimeFactor), unit); // 改良情報を追加する unit.Upgrades.Add(upgrade); // 編集済みフラグを設定する upgrade.SetDirtyAll(); unit.SetDirtyFile(); // 改良リストビューに項目を追加する AddUpgradeListItem(upgrade); }
/// <summary> /// 改良リストの項目を追加する /// </summary> /// <param name="upgrade">追加対象の改良設定</param> private void AddUpgradeListItem(UnitUpgrade upgrade) { // 改良リストビューの項目を追加する upgradeListView.Items.Add(CreateUpgradeListItem(upgrade)); // 追加した項目を選択する int index = upgradeListView.Items.Count - 1; upgradeListView.Items[index].Focused = true; upgradeListView.Items[index].Selected = true; upgradeListView.EnsureVisible(index); // 改良の編集項目を有効化する EnableUpgradeItems(); }
/// <summary> /// 改良リストの項目を作成する /// </summary> /// <param name="upgrade">改良設定</param> /// <returns>改良リストの項目</returns> private static ListViewItem CreateUpgradeListItem(UnitUpgrade upgrade) { ListViewItem item = new ListViewItem { Text = Units.Items[(int) upgrade.Type].ToString() }; item.SubItems.Add(DoubleHelper.ToString(upgrade.UpgradeCostFactor)); item.SubItems.Add(DoubleHelper.ToString(upgrade.UpgradeTimeFactor)); return item; }
public void UpgradeUnit(Unit pUnit, UnitUpgrade upgrade) { if (CheckResources(UPGRADE_COST, 0, 0, pUnit.Owner)) { pUnit.Upgrade(upgrade); pUnit.Owner.Resources.Gold += -UPGRADE_COST; UiScript.Instance.UpdateUi(); } else Debug.Log("Nog enough resources"); }