コード例 #1
0
ファイル: ArmyEntity.cs プロジェクト: DanielKeehn/HistoryHex
 /// <summary>
 /// Combats another unit. Return true if winning combat, false otherwise
 /// </summary>
 public bool Combat(GameObject otherArmyObject)
 {
     if (otherArmyObject != null)
     {
         ArmyEntity otherArmy  = otherArmyObject.GetComponent <ArmyEntity>();
         List <int> myRolls    = ArmyRoll(true);
         List <int> theirRolls = otherArmy.ArmyRoll(false);
         Debug.Log("My rolls " + myRolls);
         Debug.Log("And theirs " + myRolls);
         DisplayRolls(myRolls, transform.position, new Vector3(0, 2, 0), 2);
         DisplayRolls(theirRolls, otherArmyObject.transform.position, new Vector3(0, 2, 0), 2);
         int myDamage = 0, theirDamage = 0;
         for (int i = 0; i < theirRolls.Count && i < myRolls.Count; i++)
         {
             if (myRolls[i] <= theirRolls[i])
             {
                 myDamage++;
             }
             if (myRolls[i] >= theirRolls[i])
             {
                 theirDamage++;
             }
         }
         Manpower           -= myDamage * PowerPerDamage;
         otherArmy.Manpower -= theirDamage * PowerPerDamage;
         CheckDead();
         otherArmy.CheckDead();
     }
     return(otherArmyObject == null);
 }
コード例 #2
0
        /// <summary>
        /// Converts the domain model into an entity.
        /// </summary>
        /// <returns>The entity.</returns>
        /// <param name="army">Army.</param>
        internal static ArmyEntity ToEntity(this Army army)
        {
            ArmyEntity armyEntity = new ArmyEntity
            {
                FactionId = army.FactionId,
                UnitId    = army.UnitId,
                Size      = army.Size
            };

            return(armyEntity);
        }
コード例 #3
0
        /// <summary>
        /// Converts the entity into a domain model.
        /// </summary>
        /// <returns>The domain model.</returns>
        /// <param name="armyEntity">Army entity.</param>
        internal static Army ToDomainModel(this ArmyEntity armyEntity)
        {
            Army army = new Army
            {
                FactionId = armyEntity.FactionId,
                UnitId    = armyEntity.UnitId,
                Size      = armyEntity.Size
            };

            return(army);
        }
コード例 #4
0
ファイル: HexEntity.cs プロジェクト: rhiannanberry/HistoryHex
    //If Activated, run the extended activation methods.
    private void ActiveUpdate()
    {
        // Army spawn code.
        if (Input.GetKeyDown(KeyCode.V))
        {
            Vector3    position = transform.position;
            Quaternion rotation = Quaternion.Euler(0, 0, 0);
            this.army = Instantiate(ArmyPrefab, position, rotation);

            //Set an army up.
            ArmyEntity armyEntity = army.transform.GetComponent <ArmyEntity>();
            armyEntity.Position   = Position;
            armyEntity.Controller = Controller;
        }
    }
コード例 #5
0
        /// <summary>
        /// Adds the specified army.
        /// </summary>
        /// <param name="army">Army.</param>
        public void Add(ArmyEntity army)
        {
            Tuple <string, string> key = new Tuple <string, string>(army.FactionId, army.UnitId);

            try
            {
                armyEntitiesStore.Add(key, army);
            }
            catch
            {
                throw new DuplicateEntityException(
                          $"{army.FactionId}-{army.UnitId}",
                          nameof(ArmyEntity).Replace("Entity", ""));
            }
        }
コード例 #6
0
    public void RaiseArmy()
    {
        // Army spawn code.
        if (allowArmySpawn())
        {
            TotalPopulation -= 100;
            Vector3    position = transform.position;
            Quaternion rotation = Quaternion.Euler(0, 0, 0);
            this.army = Instantiate(ArmyPrefab, position, rotation);

            //Set an army up.
            ArmyEntity armyEntity = army.transform.GetComponent <ArmyEntity>();
            armyEntity.Position   = Position;
            armyEntity.Controller = Controller;
            Controller.armies.Add(armyEntity);
        }
    }
コード例 #7
0
    /// <summary>
    /// Combats another unit. Return true if winning combat, false otherwise
    /// </summary>
    public bool Combat(GameObject otherArmyObject)
    {
        if (otherArmyObject != null)
        {
            ArmyEntity otherArmy  = otherArmyObject.GetComponent <ArmyEntity>();
            List <int> myRolls    = ArmyRoll(true);
            List <int> theirRolls = otherArmy.ArmyRoll(false);
            Debug.Log("My rolls " + myRolls);
            Debug.Log("And theirs " + myRolls);
            //DisplayRolls(myRolls, transform.position, new Vector3(0, 3, 0), 2);
            //DisplayRolls(theirRolls, otherArmyObject.transform.position, new Vector3(0, 3, 0), 2);

            int myDamage = 0, theirDamage = 0;
            for (int i = 0; i < theirRolls.Count && i < myRolls.Count; i++)
            {
                if (myRolls[i] <= theirRolls[i])
                {
                    myDamage++;
                }
                if (myRolls[i] >= theirRolls[i])
                {
                    theirDamage++;
                }
            }

            myDamage    *= PowerPerDamage;
            theirDamage *= PowerPerDamage;
            //DisplayDmg(myDamage, transform.position, new Vector3(0, 2.5f, 0), 2);
            //DisplayDmg(theirDamage, otherArmyObject.transform.position, new Vector3(0, 2.5f, 0), 2);

            Manpower           -= myDamage;
            otherArmy.Manpower -= PowerPerDamage;
            CheckDead();
            otherArmy.CheckDead();
        }

        //Play the movement sound
        GameObject      AudioObj = GameObject.Find("AudioManagerGame");
        ArbitrarySounds sounds   = AudioObj.GetComponentInChildren <ArbitrarySounds>();

        sounds.OnArmyAttack();

        return(otherArmyObject == null);
    }
コード例 #8
0
        /// <summary>
        /// Gets the army with the specified faction and unit identifiers.
        /// </summary>
        /// <returns>The army.</returns>
        /// <param name="factionId">Faction identifier.</param>
        /// <param name="unitId">Unit identifier.</param>
        public ArmyEntity Get(string factionId, string unitId)
        {
            Tuple <string, string> key = new Tuple <string, string>(factionId, unitId);

            if (!armyEntitiesStore.ContainsKey(key))
            {
                return(null);
            }

            ArmyEntity armyEntity = armyEntitiesStore[key];

            if (armyEntity == null)
            {
                throw new EntityNotFoundException(
                          $"{factionId}-{unitId}",
                          nameof(ArmyEntity).Replace("Entity", ""));
            }

            return(armyEntity);
        }