Example #1
0
 public void initialize(TroopType type, int number, int rank = 0, float morale = MAX_STAT)
 {
     this.type = type;
     this.rank = rank;
     this.number = number;
     this.morale = morale;
 }
Example #2
0
    void makeParty(Party npcParty)
    {
        TroopType tt = npcParty.randomTroopType(20, 20, 10, 30, 10, 10);
        Ranking   rk = npcParty.randomRanking(0, 10, 10, 10);

        if (tt == TroopType.recruitType)
        {
            rk = Ranking.recruit;
        }
        Person p = npcParty.makeGenericPerson(tt, rk);

        if (npcParty.battleValue >= p.battleValue)
        {
            if (npcParty.addToParty(npcParty.makeGenericPerson(tt, rk)))
            {
                npcParty.battleValue -= p.battleValue;
            }
            if (npcParty.battleValue > 20)
            {
                makeParty(npcParty);
            }
        }
        else
        {
            if (npcParty.battleValue > 20)
            {
                makeParty(npcParty);
            }
        }
    }
Example #3
0
    /// <summary>
    /// true if at least 1 troop was successfully recruited
    /// </summary>
    /// <returns></returns>
    public override bool RecruitTroops()
    {
        Zone    curZone  = GameController.GetZoneByID(zoneIAmIn);
        Faction ownerFac = GameController.GetFactionByID(ownerFaction);

        if (troopsContained.TotalTroopAmount < MaxTroopsCommanded && curZone.multRecruitmentPoints > 0)
        {
            //recruitment!

            TroopType recruitableTroopType = GetTroopTypeRecruitedWhereIAm(ownerFac);
            if (recruitableTroopType == null)
            {
                return(false);
            }

            int recruitableTroopsAmount = 0;

            recruitableTroopsAmount =
                Mathf.Min(Mathf.RoundToInt(pointsToSpend * curZone.multRecruitmentPoints) / recruitableTroopType.pointCost,
                          MaxTroopsCommanded - troopsContained.TotalTroopAmount);

            troopsContained.AddTroop(recruitableTroopType.ID, recruitableTroopsAmount);
            pointsToSpend -=
                Mathf.RoundToInt(recruitableTroopType.pointCost * recruitableTroopsAmount / curZone.multRecruitmentPoints);
            WorldFXManager.instance.EmitParticle(WorldFXManager.instance.recruitParticle, MeIn3d.transform.position,
                                                 GameController.GetFactionByID(ownerFaction).color);
            troopsContained.Sort(TroopNumberPair.CompareTroopNumberPairsByAutocalcPower);
            return(true);
        }

        return(false);
    }
Example #4
0
        public TroopStats(string _name, TroopType _type, int _hp, int _dmg, float _range, int _blockChance)
        {
            troopName   = _name;
            type        = _type;
            health      = _hp;
            damage      = _dmg;
            attackRange = _range;

            if (_blockChance > 100)
            {
                blockChance = 100;
            }
            else if (_blockChance < 0)
            {
                blockChance = 0;
            }
            else
            {
                blockChance = _blockChance;
            }

            sprite = Resources.Load <Sprite>(_type.ToString());

            relations = new SerializableDictionary <TroopStats, Relationship>();
        }
Example #5
0
    public static string troopTypeToString(TroopType tt)
    {
        switch (tt)
        {
        case TroopType.recruitType:
            return("Recruit");

        case TroopType.crossbowman:
            return("Crossbowman");

        case TroopType.musketeer:
            return("Musketeer");

        case TroopType.swordsman:
            return("Swordsman");

        case TroopType.halberdier:
            return("Halberdier");

        case TroopType.cavalry:
            return("Cavalry");

        case TroopType.mainCharType:
            return("");
        }
        return("Recruit");
    }
Example #6
0
        /// <summary>
        /// Get a Trooptype from a JSON
        /// </summary>
        /// <param name="contents"></param>
        /// <returns></returns>
        public static TroopType ReadJson(string contents)
        {
            TroopType t = JsonConvert.DeserializeObject <TroopType>(contents);

            t.Metadata = JsonConvert.DeserializeObject <Dictionary <string, string> >(contents);
            return(t);
        }
Example #7
0
        public static void HandleMoveTroops(int fromClient, Packet packet)
        {
            int clientIDCheck = packet.ReadInt();

            if (fromClient != clientIDCheck)
            {
                Console.WriteLine($"Player with ID: \"{fromClient}\" has assumed the wrong client ID: \"{clientIDCheck}\"!");
            }

            HexCoordinates coordinates = packet.ReadHexCoordinates();
            TroopType      troopType   = (TroopType)packet.ReadByte();
            int            amount      = packet.ReadInt();

            Player         player            = Server.clients[fromClient].Player;
            TroopInventory buildingInventory = ((ProtectedBuilding)GameLogic.grid.GetCell(coordinates).Structure).TroopInventory;

            if (GameLogic.MoveTroops(player, coordinates, troopType, amount))
            {
                ServerSend.BroadcastMoveTroops(player, coordinates, troopType, amount);
                Console.WriteLine("Player: " + player.Name + "of tribe " + player.Tribe.Id.ToString() + " successfully exchanged " + amount.ToString() + troopType.ToString() + " with a building at" + coordinates.ToString() + ".");
            }
            else
            {
                Console.WriteLine("Player: " + player.Name + "of tribe " + player.Tribe.Id.ToString() + " failed to exchange " + amount.ToString() + troopType.ToString() + " with building at " + coordinates.ToString() + ".");
            }
        }
Example #8
0
        public TroopTab ConvertTroopTypeToTab(TroopType type)
        {
            TroopTab result = TroopTab.All;

            switch (type)
            {
            case TroopType.Infantry:
                result = TroopTab.Infantry;
                break;

            case TroopType.Vehicle:
                result = TroopTab.Vehicle;
                break;

            case TroopType.Mercenary:
                result = TroopTab.Mercenary;
                break;

            case TroopType.Hero:
                result = TroopTab.Hero;
                break;

            default:
                Service.Get <StaRTSLogger>().WarnFormat("Cannot convert TroopType {0} to TroopTab", new object[]
                {
                    type
                });
                break;
            }
            return(result);
        }
        public void UpgradeTroopsOrStarships(string uid, bool isStarship)
        {
            IDataController  dataController = Service.Get <IDataController>();
            IUpgradeableVO   upgradeableVO;
            InventoryStorage storage;

            if (isStarship)
            {
                upgradeableVO = dataController.Get <SpecialAttackTypeVO>(uid);
                this.Starships.SetLevel(upgradeableVO);
                storage = GameUtils.GetWorldOwner().Inventory.SpecialAttack;
            }
            else
            {
                upgradeableVO = dataController.Get <TroopTypeVO>(uid);
                this.Troops.SetLevel(upgradeableVO);
                TroopType type = ((TroopTypeVO)upgradeableVO).Type;
                if (type != TroopType.Hero)
                {
                    if (type != TroopType.Champion)
                    {
                        storage = GameUtils.GetWorldOwner().Inventory.Troop;
                    }
                    else
                    {
                        storage = GameUtils.GetWorldOwner().Inventory.Champion;
                    }
                }
                else
                {
                    storage = GameUtils.GetWorldOwner().Inventory.Hero;
                }
            }
            UnlockedLevelData.UpgradeTroopsOrStarshipsInventory(storage, isStarship, upgradeableVO.UpgradeGroup, upgradeableVO.Uid);
        }
Example #10
0
        public TrainTroopTypeObjectiveProcessor(ObjectiveVO vo, ObjectiveManager parent) : base(vo, parent)
        {
            TroopType troopType = StringUtils.ParseEnum <TroopType>(vo.Item);

            if (troopType == TroopType.Champion)
            {
                this.deliveryType = DeliveryType.Champion;
            }
            else if (troopType == TroopType.Hero)
            {
                this.deliveryType = DeliveryType.Hero;
            }
            else if (troopType == TroopType.Infantry)
            {
                this.deliveryType = DeliveryType.Infantry;
            }
            else if (troopType == TroopType.Mercenary)
            {
                this.deliveryType = DeliveryType.Mercenary;
            }
            else if (troopType == TroopType.Vehicle)
            {
                this.deliveryType = DeliveryType.Vehicle;
            }
            Service.Get <EventManager>().RegisterObserver(this, EventId.TroopRecruited);
            Service.Get <EventManager>().RegisterObserver(this, EventId.HeroMobilized);
        }
Example #11
0
        public TroopStats GetStatsForType(TroopType _type)
        {
            TroopStats _newStats = null;

            switch (_type)
            {
            case TroopType.RegularViking:
                _newStats = new TroopStats("NewRegularViking", TroopType.RegularViking, 100, 10, 2, 40);
                break;

            case TroopType.Beserker:
                _newStats = new TroopStats("NewBeserker", TroopType.Beserker, 80, 25, 2, 10);
                break;
            }

            if (_newStats != null)
            {
                return(_newStats);
            }
            else
            {
                Debug.LogError("Requested trooptype not setup in the GetStatsForType method!");
                return(null);
            }
        }
Example #12
0
 public Troop(TroopType TypeOfTroop, int Price, int Year, string Power)
 {
     this.TypeOfTroop = TypeOfTroop;
     this.Price       = Price;
     this.Year        = Year;
     this.Power       = Power;
 }
 internal Troop(CharacterObject characterObject, Party partyModel, TroopType troopType)
 {
     CharacterObject = characterObject;
     Health          = CharacterObject.MaxHitPoints();
     PartyModel      = partyModel;
     TroopType       = troopType;
 }
 public static TrapCondition GenerateTrapCondition(string trapType, params string[] args)
 {
     if (trapType == "radius")
     {
         uint radius = Convert.ToUInt32(args[0], CultureInfo.InvariantCulture);
         return(new RadiusTrapCondition(radius));
     }
     if (trapType == "intrudertype")
     {
         TroopType intruderType = StringUtils.ParseEnum <TroopType>(args[0]);
         return(new IntruderTypeTrapCondition(intruderType));
     }
     if (trapType == "armornot")
     {
         List <ArmorType> list = new List <ArmorType>();
         int i   = 0;
         int num = args.Length;
         while (i < num)
         {
             list.Add(StringUtils.ParseEnum <ArmorType>(args[i]));
             i++;
         }
         return(new ArmorNotTrapCondition(list));
     }
     return(null);
 }
Example #15
0
 public void RemoveUnit(TroopType type, int amount)
 {
     if (amount < 0)
     {
         return;
     }
     this.Troops[type] -= Mathf.Min(amount, this.Troops[type]);
 }
Example #16
0
        public void TroopFactorySetup()
        {
            troopTypes = new Dictionary <string, TroopType>();
            string    json   = "{ 'Id':1,'Name':'Monkey','Type':'Ground','Damage':'6','Health':'50','PreferredTarget':'Ground','Template':'Basic'}";
            TroopType monkey = TroopReader.ReadJson(json);

            troopTypes.Add(monkey.Name, monkey);
        }
Example #17
0
    public void InitTroopAs(TroopType type, int number)
    {
        HP         = number * 10;
        _troopType = type;

        AntInstance.InitAnts(number);
        MoveInstance.Init();
        FightInstance.Init();
    }
Example #18
0
 public static void BroadcastChangeStrategyActivePlayer(string playerName, TroopType type, bool newValue)
 {
     using (Packet packet = new Packet((int)ServerPackets.broadcastChangeStrategyActivePlayer))
     {
         packet.Write(playerName);
         packet.Write((byte)type);
         packet.Write(newValue);
         SendTCPDataToAll(packet);
     }
 }
Example #19
0
 public bool MoveTroops(TroopInventory destination, TroopType troopType, int amount)
 {
     if (this.Troops[troopType] - amount >= 0 && destination.GetTroopCount() + amount <= destination.TroopLimit)
     {
         //Move troops
         this.Troops[troopType]        -= amount;
         destination.Troops[troopType] += amount;
         return(true);
     }
     return(false);
 }
Example #20
0
 public Texture2D getTroopProfile(Faction f, TroopType tt, Ranking rk)
 {
     if (f == Faction.mercenary)
     {
         return(getTroopInfo(f, tt, rk).profile);
     }
     else
     {
         return(defaultProfile);
     }
 }
Example #21
0
    /// <summary>
    /// true if at least 1 troop was upgraded
    /// </summary>
    /// <returns></returns>
    public override bool TrainTroops()
    {
        if (pointsToSpend <= 0)
        {
            return(false);
        }

        Zone curZone = GameController.GetZoneByID(zoneIAmIn);

        if (curZone.multTrainingPoints > 0)
        {
            Faction   ownerFac             = GameController.GetFactionByID(ownerFaction);
            bool      hasTrained           = false;
            int       trainableTroops      = 0;
            int       troopIndexInGarrison = -1;
            int       pointsForTraining;
            TroopType curTTBeingTrained = null, curTTUpgradeTo = null;
            for (int i = 0; i < ownerFac.troopLine.Count - 1; i++)               //the last one can't upgrade, so...

            {
                pointsForTraining    = Mathf.RoundToInt(pointsToSpend * curZone.multTrainingPoints);
                troopIndexInGarrison = troopsContained.IndexOfTroopInThisList(ownerFac.troopLine[i]);
                if (troopIndexInGarrison >= 0)
                {
                    curTTBeingTrained = GameController.GetTroopTypeByID(ownerFac.troopLine[i]);
                    curTTUpgradeTo    = GameController.GetTroopTypeByID(ownerFac.troopLine[i + 1]);

                    trainableTroops = Mathf.Min(pointsForTraining / curTTUpgradeTo.pointCost,
                                                troopsContained[troopIndexInGarrison].troopAmount);

                    if (trainableTroops > 0)
                    {
                        troopsContained.RemoveTroop(curTTBeingTrained.ID, trainableTroops);
                        troopsContained.AddTroop(curTTUpgradeTo.ID, trainableTroops);
                        pointsToSpend -= Mathf.RoundToInt(trainableTroops * curTTUpgradeTo.pointCost / curZone.multTrainingPoints);
                        hasTrained     = true;
                    }
                }
            }

            if (hasTrained)
            {
                WorldFXManager.instance.EmitParticle(WorldFXManager.instance.bolsterParticle, MeIn3d.transform.position,
                                                     GameController.GetFactionByID(ownerFaction).color);
                troopsContained.Sort(TroopNumberPair.CompareTroopNumberPairsByAutocalcPower);
            }

            return(hasTrained);
        }
        else
        {
            return(false);
        }
    }
    public static TroopNumberPair SerializedTroopToTroopNumberPair(SerializedTroop serialized)
    {
        TroopType foundType = GameController.GetTroopTypeByName(serialized.name);

        if (foundType != null)
        {
            return(new TroopNumberPair(foundType.ID, serialized.amount));
        }

        return(default(TroopNumberPair));
    }
Example #23
0
        public static bool ChangeActiveStrategyOfPlayer(String playerName, TroopType type, bool newValue)
        {
            Player player = GetPlayer(playerName);

            if (player != null)
            {
                int index = player.TroopInventory.Strategy.FindIndex(tpl => tpl.Item1 == type);
                player.TroopInventory.Strategy[index] = new Tuple <TroopType, bool>(type, newValue);
                return(true);
            }
            return(false);
        }
Example #24
0
 protected string TroopTypeString(TroopType type)
 {
     switch (type)
     {
         case TroopType.Ram:
             return "lính giáo";
         case TroopType.Catapult:
             return "lính kiếm";
         default:
             return "";
     }
 }
Example #25
0
 /// <summary>
 ///     Initializes a new copy of the <see cref="Research" /> struct.
 /// </summary>
 /// <param name="troop">Troop type.</param>
 /// <param name="trainable">Researched or not.</param>
 /// <param name="armoury">Armoury level.</param>
 /// <param name="blacksmith">Blacksmith level.</param>
 public Research(
     TroopType troop,
     bool trainable,
     int armoury,
     int blacksmith)
     : this()
 {
     TroopType = troop;
     Trainable = trainable;
     Armoury = armoury;
     Blacksmith = blacksmith;
 }
Example #26
0
 /// <summary>
 ///     Initializes a new copy of the <see cref="Research" /> struct.
 /// </summary>
 /// <param name="troop">Troop type.</param>
 /// <param name="trainable">Researched or not.</param>
 /// <param name="armoury">Armoury level.</param>
 /// <param name="blacksmith">Blacksmith level.</param>
 public Research(
     TroopType troop,
     bool trainable,
     int armoury,
     int blacksmith)
     : this()
 {
     TroopType  = troop;
     Trainable  = trainable;
     Armoury    = armoury;
     Blacksmith = blacksmith;
 }
 public Troop()
 {
     troopType                 = TroopType.Swordsman;
     IsAlive                   = true;
     _damage                   = 1;
     _health                   = 5;
     _speed                    = 3.5f;
     _minEnemyDistToNotice     = 2;
     isControlled              = false;
     attackSpeedWaitForSeconds = new WaitForSeconds(1.0f);
     _canAttack                = true;
 }
Example #28
0
 protected string GetTroopText(TroopType type)
 {
     switch (type)
     {
         case TroopType.Spear:
             return "lính giáo";
         case TroopType.Sword:
             return "lính kiếm";
         case TroopType.Axe:
             return "lính rìu";
     }
     return "";
 }
Example #29
0
 protected string TroopTypeString(TroopType type)
 {
     switch (type)
     {
         case TroopType.Scout:
             return "siêu điệp viên";
         case TroopType.Light:
             return "kỵ binh";
         case TroopType.Heavy:
             return "hiệp sỹ";
     }
     return "";
 }
Example #30
0
        public void ReadTemplateTest_NoBaseTroopError()
        {
            string contents = File.ReadAllText(flyingMonkeyJson);

            //Setup base monkey troop
            TroopReader    troopReader = new TroopReader();
            TemplateReader reader      = new TemplateReader(contents, troopReader.TroopTypes);

            Assert.Throws <InvalidOperationException>(() =>
            {
                TroopType flyingMonkey = reader.Read();
            });
        }
Example #31
0
        public static bool MoveTroops(Player player, HexCoordinates coordinates, TroopType troopType, int amount)
        {
            ProtectedBuilding building = (ProtectedBuilding)grid.GetCell(coordinates).Structure;

            if (amount > 0)
            {
                return(building.TroopInventory.MoveTroops(player.TroopInventory, troopType, Mathf.Abs(amount)));
            }
            else
            {
                return(player.TroopInventory.MoveTroops(building.TroopInventory, troopType, Mathf.Abs(amount)));
            }
        }
Example #32
0
    /// <summary>
    /// if we're not neutral, uses the pointsToSpend to add more troops to the garrison... or train them
    /// and upgrade them
    /// </summary>
    public void SpendPoints(bool useGraphicFX = false, bool ignoreGarrisonTierLimit = false)
    {
        if (ownerFaction >= 0 && pointsToSpend > 0)
        {
            RecruitTroops();

            //if we still have points left... training time
            if (pointsToSpend > 0 && multTrainingPoints > 0)
            {
                bool      hasTrained      = false;
                Faction   ownerFac        = GameController.GetFactionByID(ownerFaction);
                int       trainableTroops = 0;
                int       pointsForTraining;
                int       troopIndexInGarrison = -1;
                int       tierLimit = ignoreGarrisonTierLimit ? ownerFac.troopLine.Count - 1 : ownerFac.maxGarrisonedTroopTier - 1;
                TroopType curTTBeingTrained = null, curTTUpgradeTo = null;
                for (int i = 0; i < tierLimit; i++)
                {
                    pointsForTraining = Mathf.RoundToInt(pointsToSpend * multTrainingPoints);

                    troopIndexInGarrison = troopsContained.IndexOfTroopInThisList(ownerFac.troopLine[i]);
                    if (troopIndexInGarrison >= 0)
                    {
                        curTTBeingTrained = GameController.GetTroopTypeByID(ownerFac.troopLine[i]);
                        curTTUpgradeTo    = GameController.GetTroopTypeByID(ownerFac.troopLine[i + 1]);
                        trainableTroops   = Mathf.Min(pointsForTraining / curTTBeingTrained.pointCost,
                                                      troopsContained[troopIndexInGarrison].troopAmount);
                        if (trainableTroops > 0)
                        {
                            troopsContained.RemoveTroop(curTTBeingTrained.ID, trainableTroops);
                            troopsContained.AddTroop(curTTUpgradeTo.ID, trainableTroops);
                            pointsToSpend -=
                                Mathf.RoundToInt(trainableTroops * curTTBeingTrained.pointCost / multTrainingPoints);
                            hasTrained = true;
                        }
                    }
                }

                if (useGraphicFX)
                {
                    if (hasTrained)
                    {
                        WorldFXManager.instance.EmitParticle(WorldFXManager.instance.bolsterParticle, MyZoneSpot.transform.position,
                                                             GameController.GetFactionByID(ownerFaction).color);
                    }
                }
            }

            troopsContained.Sort(TroopNumberPair.CompareTroopNumberPairsByAutocalcPower);
        }
    }
Example #33
0
        public void CreateTroop_Valid()
        {
            Dictionary <string, TroopType> troopTypes = new Dictionary <string, TroopType>();
            string    json   = "{ 'Id':1,'Name':'Monkey','Type':'Ground','Damage':'6','Health':'50','PreferredTarget':'Ground','Template':'Basic'}";
            TroopType monkey = TroopReader.ReadJson(json);

            troopTypes.Add(monkey.Name, monkey);

            TroopFactory factory = new TroopFactory(troopTypes);
            Troop        t       = factory.Create("Monkey");

            Assert.AreEqual(t.Info, monkey);
            Assert.AreEqual(t.CurrentHealth, monkey.Health);
        }
Example #34
0
 private bool loadType()
 {
     troopTypes = new List<TroopType>();
     TextAsset text = Resources.Load(troopTypeFileName) as TextAsset;
     string[] lines = text.text.Split('\n');
     for(int i = 1; i < lines.Length; i++)
     {
         if (lines[i] == null || lines[i] == "")
             continue;
         TroopType newType = new TroopType(lines[i]);
         troopTypes.Add(newType);
     }
     return true;
 }
Example #35
0
        public TroopType Read()
        {
            TroopType t = new TroopType();

            t.Id              = Int32.Parse(metadata["Id"]);
            t.Name            = metadata["Name"];
            t.Type            = GetStringProperty("Type");
            t.Damage          = Int32.Parse(GetStringProperty("Damage"));
            t.Health          = Int32.Parse(GetStringProperty("Health"));
            t.PreferredTarget = GetStringProperty("PreferredTarget");
            t.Template        = metadata["Template"];

            return(t);
        }
Example #36
0
    /// <summary>
    /// returns the percentage compared to the cmder's MAX amount of troops that would be upgraded if
    /// the cmder trained instead of moving or recruiting
    /// </summary>
    /// <returns></returns>
    public float GetPercentOfTroopsUpgradedIfTrained()
    {
        if (pointsToSpend <= 0)
        {
            return(0.0f);
        }

        Zone curZone = GameController.GetZoneByID(zoneIAmIn);

        if (curZone.multTrainingPoints > 0)
        {
            Faction   cmderFac = GameController.GetFactionByID(ownerFaction);
            int       totalTrainableTroops = 0;
            int       trainableTroops = 0;
            int       troopTrainingCostHere = 0;
            int       troopIndexInGarrison = -1;
            int       fakePointsToSpend = pointsToSpend;
            TroopType curTTBeingTrained = null, curTTUpgradeTo = null;
            for (int i = 0; i < cmderFac.troopLine.Count - 1; i++)               //the last one can't upgrade, so...
            {
                troopIndexInGarrison = troopsContained.IndexOfTroopInThisList(cmderFac.troopLine[i]);
                if (troopIndexInGarrison >= 0)
                {
                    curTTBeingTrained     = GameController.GetTroopTypeByID(cmderFac.troopLine[i]);
                    curTTUpgradeTo        = GameController.GetTroopTypeByID(cmderFac.troopLine[i + 1]);
                    troopTrainingCostHere = Mathf.RoundToInt(curTTUpgradeTo.pointCost / curZone.multTrainingPoints);
                    if (troopTrainingCostHere == 0)
                    {
                        trainableTroops = troopsContained[troopIndexInGarrison].troopAmount;
                    }
                    else
                    {
                        trainableTroops = Mathf.Min(fakePointsToSpend / troopTrainingCostHere,
                                                    troopsContained[troopIndexInGarrison].troopAmount);
                    }
                    if (trainableTroops > 0)
                    {
                        totalTrainableTroops += trainableTroops;
                        fakePointsToSpend    -= trainableTroops * troopTrainingCostHere;
                    }
                }
            }

            //Debug.Log("GetPercentOfTroopsUpgradedIfTrained = " + ((float)totalTrainableTroops / MaxTroopsCommanded));
            return((float)totalTrainableTroops / MaxTroopsCommanded);
        }

        return(0.0f);
    }
Example #37
0
        public static DateTime LandingTime (TroopType troop, int sourceX, int sourceY, int desX, int desY, DateTime start, double speedIncrease)
        {
            string type = "Map.merchant_speed";
            switch (troop)
            {
                case TroopType.Axe:
                    type = "Map.axe_speed";
                    break;
                case TroopType.Spear:
                    type = "Map.spear_speed";
                    break;
                case TroopType.Sword:
                    type = "Map.sword_speed";
                    break;
                case TroopType.Heavy:
                    type = "Map.heavy_cavalry_speed";
                    break;
                case TroopType.Light:
                    type = "Map.light_cavalry_speed";
                    break;
                case TroopType.Scout:
                    type = "Map.scout_speed";
                    break;
                case TroopType.Nobleman:
                    type = "Map.noble_speed";
                    break;
                case TroopType.Ram:
                    type = "Map.ram_speed";
                    break;
                case TroopType.Catapult:
                    type = "Map.catapult_speed";
                    break;
                default:
                    type = "Map.merchant_speed";
                    break;
            }

            Configuration config = Configuration.TribalWarsConfiguration;
            NumericConfiguration troopSpeedConfiguration = config.GetNumericConfigurationItem(type);

            return start.AddMilliseconds(RangeCalculator(sourceX, sourceY, desX, desY) * (troopSpeedConfiguration.Value - troopSpeedConfiguration.Value * speedIncrease));
        }
Example #38
0
        public static double MovingTime(int sourceX, int sourceY, int desX, int desY, TroopType troop)
        {
            string type = "Map.merchant_speed";
            switch (troop)
            {
                case TroopType.Axe:
                    type = "Map.axe_speed";
                    break;
                case TroopType.Spear:
                    type = "Map.spear_speed";
                    break;
                case TroopType.Sword:
                    type = "Map.sword_speed";
                    break;
                case TroopType.Heavy:
                    type = "Map.heavy_cavalry_speed";
                    break;
                case TroopType.Light:
                    type = "Map.light_cavalry_speed";
                    break;
                case TroopType.Scout:
                    type = "Map.scout_speed";
                    break;
                case TroopType.Nobleman:
                    type = "Map.noble_speed";
                    break;
                case TroopType.Ram:
                    type = "Map.ram_speed";
                    break;
                case TroopType.Catapult:
                    type = "Map.catapult_speed";
                    break;
                default:
                    type = "Map.merchant_speed";
                    break;
            }

            Configuration config = Configuration.TribalWarsConfiguration;
            NumericConfiguration troopSpeedConfiguration = config.GetNumericConfigurationItem(type);
            return RangeCalculator(sourceX, sourceY, desX, desY) * troopSpeedConfiguration.Value;
        }
Example #39
0
        public static long RecruitTime(TroopType troop, int quantity, int level)
        {
            if (level==0)
                return int.MaxValue;
            if (quantity == 0)
                return 0;

            return Recruit.GetPrice(troop).BuildTime * quantity;
        }
Example #40
0
 public virtual int this[TroopType troopType]
 {
     get
     {
         switch (troopType)
         {
             case TroopType.Axe:
                 return this.VillageTroopData.AxeInVillage;
             case TroopType.Catapult:
                 return this.VillageTroopData.CatapultInVillage;
             case TroopType.Heavy:
                 return this.VillageTroopData.HeavyCavalryInVillage;
             case TroopType.Light:
                 return this.VillageTroopData.LightCavalryInVillage;
             case TroopType.Nobleman:
                 return this.VillageTroopData.NobleInVillage;
             case TroopType.Ram:
                 return this.VillageTroopData.RamInVillage;
             case TroopType.Scout:
                 return this.VillageTroopData.ScoutInVillage;
             case TroopType.Spear:
                 return this.VillageTroopData.SpearInVillage;
             case TroopType.Sword:
                 return this.VillageTroopData.SwordInVillage;
             default:
                 return -1;
         }
     }
 }
Example #41
0
        public static bool CanRecruit(TroopType troop, int quantity, int wood, int clay, int iron) 
        {
            Price price = null;
            switch (troop)
            {
                case TroopType.Spear:
                    price = Recruit.Spear;
                    break;
                case TroopType.Sword:
                    price = Recruit.Sword;
                    break;
                case TroopType.Axe:
                    price = Recruit.Axe;
                    break;
                case TroopType.Scout:
                    price = Recruit.Scout;
                    break;
                case TroopType.Light:
                    price = Recruit.Light;
                    break;
                case TroopType.Heavy:
                    price = Recruit.Heavy;
                    break;
                case TroopType.Ram:
                    price = Recruit.Ram;
                    break;
                case TroopType.Catapult:
                    price = Recruit.Catapult;
                    break;
                case TroopType.Nobleman:
                    price = Recruit.Noble;
                    break;
                default:
                    break;
                    
            }

            if (object.Equals(price, null))
                return false;
 
            if (quantity * price.Clay > clay)
                return false;
            if (quantity * price.Wood > wood)
                return false;
            if (quantity * price.Iron > iron)
                return false;
            return true;
        }
Example #42
0
        public static int MaxRecruit(TroopType troop, int wood, int clay, int iron)
        {
            Price price = null;
            switch (troop)
            {
                case TroopType.Spear:
                    price = Recruit.Spear;
                    break;
                case TroopType.Sword:
                    price = Recruit.Sword;
                    break;
                case TroopType.Axe:
                    price = Recruit.Axe;
                    break;
                case TroopType.Scout:
                    price = Recruit.Scout;
                    break;
                case TroopType.Light:
                    price = Recruit.Light;
                    break;
                case TroopType.Heavy:
                    price = Recruit.Heavy;
                    break;
                case TroopType.Ram:
                    price = Recruit.Ram;
                    break;
                case TroopType.Catapult:
                    price = Recruit.Catapult;
                    break;
                case TroopType.Nobleman:
                    price = Recruit.Noble;
                    break;
                default:
                    break;

            }

            int maxRecruit = clay / price.Clay;
            if (maxRecruit > iron / price.Iron)
                maxRecruit = iron / price.Iron;
            if (maxRecruit > wood / price.Wood)
                maxRecruit = wood / price.Wood;

            return maxRecruit;
        }
Example #43
0
        public static Price GetPrice(TroopType troop, int level)
        {
            if (level <= 1)
                return Recruit.GetPrice(troop);

            int key = (int)troop*1000 + level;
            if (Recruit.PriceDictionary.ContainsKey(key))
                return Recruit.PriceDictionary[key];

            Price basePrice = Recruit.GetPrice(troop);
            int time = basePrice.BuildTime;

            for (int i = 1; i < level; i++)
                time -= (int)(time * 0.05);
            Price price = new Price(basePrice.Name, time, basePrice.Wood, basePrice.Clay, basePrice.Iron, basePrice.Population);
            Recruit.PriceDictionary.Add(key, price);
            return price;
        }
Example #44
0
        public static bool CanRecruit(TroopType troop, int quantity, Village village)
        {
            switch (troop)
            {
                case TroopType.Spear:
                    if (village.VillageBuildingData.Barracks == 0)
                        return false;
                    break;
                case TroopType.Sword:
                    if (village.VillageBuildingData.Barracks == 0 || village.VillageBuildingData.Smithy < 1)
                        return false;
                    break;
                case TroopType.Axe:
                    if (village.VillageBuildingData.Barracks == 0 || village.VillageBuildingData.Smithy < 2)
                        return false;
                    break;
                case TroopType.Scout:
                    if (village.VillageBuildingData.Stable == 0)
                        return false;
                    break;
                case TroopType.Light:
                    if (village.VillageBuildingData.Stable < 3 || village.VillageBuildingData.Stable < 3)
                        return false;
                    break;
                case TroopType.Heavy:
                    if (village.VillageBuildingData.Stable < 10 || village.VillageBuildingData.Smithy < 15)
                        return false;
                    break;
                case TroopType.Ram:
                    if (village.VillageBuildingData.Workshop == 0)
                        return false;
                    break;
                case TroopType.Catapult:
                    if (village.VillageBuildingData.Workshop < 2 || village.VillageBuildingData.Smithy < 12)
                        return false;
                    break;
                case TroopType.Nobleman:
                    if (village.VillageBuildingData.Academy == 0 || village.VillageBuildingData.Smithy < 20)
                        return false;
                    break;
                default:
                    return false;
            }

            return Recruit.CanRecruit(troop, quantity, village.VillageResourceData.Wood, village.VillageResourceData.Clay, village.VillageResourceData.Iron);

        }
Example #45
0
 public static DateTime LandingTime(TroopType troop, Village from, Village to, DateTime start)
 {
     return Map.LandingTime(troop, from.X, from.Y, to.X, to.Y, start, 0);
 }
Example #46
0
 public static Price GetPrice(TroopType troop)
 {
     switch (troop)
     {
         case TroopType.Spear:
             return Recruit.Spear;
         case TroopType.Sword:
             return Recruit.Sword;
         case TroopType.Axe:
             return Recruit.Axe;
         case TroopType.Scout:
             return Recruit.Scout;
         case TroopType.Light:
             return Recruit.Light;
         case TroopType.Heavy:
             return Recruit.Heavy;
         case TroopType.Ram:
             return Recruit.Ram;
         case TroopType.Catapult:
             return Recruit.Catapult;
         case TroopType.Nobleman:
             return Recruit.Noble;
         default:
             throw new Exception("Báo động: HACK!!!");
     }
 }
Example #47
0
 public static DateTime LandingTime(TroopType troop, Village from, Village to, DateTime start, double speedIncrease)
 {
     return Map.LandingTime(troop, from.X, from.Y, to.X, to.Y, start, speedIncrease);
 }
        public virtual Recruit BeginRecruit(TroopType troop, int quantity, ISession session)
        {
            if (!Recruit.CanRecruit(troop, quantity, this.Village.VillageResourceData.Wood, this.Village.VillageResourceData.Clay, this.Village.VillageResourceData.Iron))
                return null;
            Recruit lastRecruit = null;
            BuildingType building = BuildingType.Barracks;
            int level = 0;
            if ((troop == TroopType.Axe) || (troop == TroopType.Spear) || (troop == TroopType.Sword))
            {
                level = this.Village[BuildingType.Barracks];
                lastRecruit = (from r in this.InfantryRecruits
                               orderby r.ID descending
                               select r).FirstOrDefault<Recruit>();
            }
            else if ((troop == TroopType.Light) || (troop == TroopType.Scout) || (troop == TroopType.Heavy))
            {
                level = this.Village[BuildingType.Stable];
                building = BuildingType.Stable;
                lastRecruit = (from r in this.CavalryRecruits
                               orderby r.ID descending
                               select r).FirstOrDefault<Recruit>();
            }
            else if (troop == TroopType.Ram || troop == TroopType.Catapult)
            {
                building = BuildingType.Workshop;
                level = this.Village[BuildingType.Workshop];
                lastRecruit = (from r in this.CarRecruits
                               orderby r.ID descending
                               select r).FirstOrDefault<Recruit>();
            }

            Recruit recruit = new Recruit();
            recruit.InVillage = this.Village;
            recruit.Quantity = quantity;
            recruit.Troop = troop;
            if (lastRecruit == null)
                recruit.LastUpdate = DateTime.Now;
            else
                recruit.LastUpdate = lastRecruit.FinishTime;

            Price p = Recruit.GetPrice(troop, this.Village[building]);
            this.Village.VillageResourceData.Clay -= p.Clay * quantity;
            this.Village.VillageResourceData.Wood -= p.Wood * quantity;
            this.Village.VillageResourceData.Iron -= p.Iron * quantity;
            this.Village.Population += p.Population * quantity;
            recruit.FinishTime = recruit.LastUpdate.AddMilliseconds(p.BuildTime * quantity);
            this.Village.Recruits.Add(recruit);
            session.Save(recruit);
            session.Update(this.Village);

            if ((troop == TroopType.Axe) || (troop == TroopType.Spear) || (troop == TroopType.Sword))
            {
                this.InfantryRecruits.Add(recruit);
            }
            else if ((troop == TroopType.Light) || (troop == TroopType.Scout) || (troop == TroopType.Heavy))
            {
                this.CavalryRecruits.Add(recruit);
            }
            else if (troop == TroopType.Ram || troop == TroopType.Catapult)
            {
                this.CarRecruits.Add(recruit);
            }

            return recruit;

        }
 public virtual int MaxRecruit(TroopType troop)
 {
     return Recruit.MaxRecruit(troop, this.Village.VillageResourceData.Wood, this.Village.VillageResourceData.Clay, this.Village.VillageResourceData.Iron);
 }
Example #50
0
 /// <summary>
 /// Determines whether the Troop is a specified Troop Type.
 /// </summary>
 /// <param name="troop">The troop.</param>
 /// <param name="type">The troop type.</param>
 /// <returns><c>true</c> if the troop is the specified troop type; otherwise, <c>false</c>.</returns>
 public static bool IsTroopType(this Troop troop, TroopType type)
 {
     switch (type)
     {
         case TroopType.Tier1:
             return troop <= Troop.Goblin && troop >= Troop.Barbarian;
         case TroopType.Tier2:
             return troop <= Troop.Wizard && troop >= Troop.Giant;
         case TroopType.Tier3:
             return troop <= Troop.Pekka && troop >= Troop.Healer;
         case TroopType.DarkTroops:
             return troop <= Troop.LavaHound && troop >= Troop.Minion;
         case TroopType.Heroes:
             return troop == Troop.King || troop == Troop.Queen;
         default:
             return false; // Unknown
     }
 }
Example #51
0
 protected string TroopTypeString(TroopType type)
 {
     switch (type)
     {
         case TroopType.Spear:
             return "lính giáo";
         case TroopType.Sword:
             return "lính kiếm";
         case TroopType.Axe:
             return "lính rìu";
         default:
             return "";
     }
 }
Example #52
0
 /// <summary>
 ///     Initializes a new copy of the <see cref="Troop" /> struct.
 /// </summary>
 /// <param name="type">Troop type.</param>
 /// <param name="count">Troop count.</param>
 public Troop(TroopType type, int count)
     : this()
 {
     Type = type;
     Count = count;
 }
Example #53
0
 public static double MovingTime(Village fromVillage, Village toVillage, TroopType troop)
 {
     return MovingTime(fromVillage.X, fromVillage.Y, toVillage.X, toVillage.Y, troop);
 }
Example #54
0
 public static DateTime LandingTime(TroopType troop, int sourceX, int sourceY, int desX, int desY, DateTime start)
 {
     return LandingTime(troop, sourceX, sourceY, desX, desY, start, 0);
 }
Example #55
0
    public void init(TroopType type, Player team, Level.LevelInstance level)
    {
        attributes = attributesList[type];
        health = attributes[TroopAttributeType.baseHealth];
        this.team = team;
        this.level = Level.getLevel (level);

        Troop.troops[team].Add(this);

        transform.position = pointAt (0f);
        distanceTraveled = 0f;
    }