Exemplo n.º 1
0
        public static int FindUnitIndexInUnitProduction(UnitType unitType, SUnitBuilding unitProduction)
        {
            string typeName;

            switch (unitType)
            {
            case UnitType.Worker:
                typeName = "Goblin";
                break;

            case UnitType.DonkeyGun:
                typeName = "DonkeyGun";
                break;

            case UnitType.WraithRaider:
                typeName = "WraithRaider";
                break;

            default:
                throw new Exception("Unknown Unit Type name");
            }
            for (var unitIndex = 0; unitIndex < unitProduction.units.Length; unitIndex++)
            {
                if (typeName == unitProduction.units[unitIndex].customName)
                {
                    return(unitIndex);
                }
            }
            throw new Exception(
                      "Cannot determine " + unitType + "'s unit index for the Unit Production from its custom name");
        }
Exemplo n.º 2
0
        private static bool IsUnitOfType(string unitName, UnitType unitType)
        {
            switch (unitType)
            {
            case UnitType.Worker:
                return(unitName.Equals("Goblin"));

            case UnitType.DonkeyGun:
                return(unitName.Equals("DonkeyGun"));

            case UnitType.WraithRaider:
                return(unitName.Equals("WraithRaiderStarship"));

            default:
                return(false);
            }
        }
Exemplo n.º 3
0
        public static Type DetermineUnitType(UnitType unitType)
        {
            switch (unitType)
            {
            case UnitType.Worker:
                return(typeof(Worker));

            case UnitType.DonkeyGun:
                return(typeof(DonkeyGun));

            case UnitType.WraithRaider:
                return(typeof(WraithRaider));

            default:
                throw new InvalidEnumArgumentException();
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Finds a Unit representation of a chosen UnitType within current Player's Faction.
 /// </summary>
 /// <param name="unitType">Type that the Unit has to represent.</param>
 /// <param name="buildingController">If not null, will assert that the building can produce the Unit.</param>
 /// <returns>Unit representation index in the Faction.</returns>
 /// <exception cref="InvalidOperationException">Unit of the chosen type isn't valid in the context.</exception>
 public static int FindUnitIndexInFaction(UnitType unitType, BuildingController buildingController)
 {
     for (var index = 0; index < Player.CurrentPlayer.Faction.UnitList.Length; index++)
     {
         var unit = Player.CurrentPlayer.Faction.UnitList[index];
         if (!IsUnitOfType(unit.obj.name, unitType))
         {
             continue;
         }
         if (buildingController != null &&
             !buildingController.unitProduction.canProduce &&
             !buildingController.unitProduction.units[index].canProduce)
         {
             throw new InvalidOperationException(
                       "Unit " + unitType + " cannot be produced by this Building");
         }
         return(index);
     }
     throw new InvalidOperationException(
               "Unit " + unitType + " is not available in your Faction");
 }