Exemple #1
0
    /// <summary>
    /// 根据wayPointType初始化路径点
    /// </summary>
    public WayPointsUnit(WayPointEnum WayPointType, UnitFaction unitFaction)
    {
        switch (WayPointType)
        {
        case WayPointEnum.UpRoad:
            wayPoints = WayPointsManager.Instance.upRoadPoints;
            break;

        case WayPointEnum.MiddleRoad:
            wayPoints = WayPointsManager.Instance.middleRoadPoints;
            break;

        case WayPointEnum.DownRoad:
            wayPoints = WayPointsManager.Instance.downRoadPoints;
            break;
        }
        this.unitFaction = unitFaction;
        switch (unitFaction)
        {
        case UnitFaction.Blue:
            nowIndex = wayPoints.Count - 1;
            break;

        case UnitFaction.Red:
            nowIndex = 0;
            break;
        }
    }
Exemple #2
0
        // Helpers
        private VMFact FromUnitFact(UnitFaction f)
        {
            if (f != UnitFaction.USA)
            {
                return((VMFact)((int)f));
            }

            return(VMFact.USA);
        }
Exemple #3
0
 public void CheckUnitFaction(UnitFaction unitFaction)
 {
     for (int i = 0; i < unitsInventory.Items.Count; i++)
     {
         if (unitFaction.CheckClass(unitsInventory.Items[i].Item.UnitClass) == true)
         {
             InstantiateUnitCardPrefab(i);
         }
     }
 }
Exemple #4
0
    public int getNumUnitsByFlag(string flag, UnitFaction targetfaction)
    {
        int returnNum = 0;

        for (int i = 0; i < unitsInGroupScripts.Count; i++)
        {
            if (unitsInGroupScripts[i] != null)
            {
                if (unitsInGroupScripts[i].gameObject.tag.Contains(flag) && unitsInGroupScripts[i].flagScript.Faction == targetfaction)
                {
                    returnNum++;
                }
            }
        }
        return(returnNum);
    }
Exemple #5
0
        public GameUnit(Texture2D texture_l, Texture2D texture_r, UnitType type,
            UnitFaction faction, int level, bool immune)
        {
            Texture_L = texture_l;
            Texture_R = texture_r;

            Type = type;
            Faction = faction;
            Level = level;
            Immune = immune;

            Target = new Vector2(-1, -1);
            NextMove = new Vector2(-1, -1);

            InitStats();
        }
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            // We only care about converting from UnitFaction
            if (value is UnitFaction)
            {
                UnitFaction tempFact = (UnitFaction)value;

                if (tempFact != UnitFaction.USA)
                {
                    return((VMFact)((int)tempFact));
                }

                return(VMFact.USA);
            }

            return(base.ConvertFrom(context, culture, value));
        }
Exemple #7
0
    protected Unit ScanClosest(UnitFaction factionMask, float maxRange, bool includeDeadUnits = false)
    {
        Unit[] allUnits            = FindObjectsOfType <Unit>();
        float  closestUnitDistance = -1;
        Unit   closestUnit         = null;

        for (int i = 0; i < allUnits.Length; i++)
        {
            Unit unit = allUnits[i];
            if (unit == this)
            {
                continue;
            }

            if (unit.dead && !includeDeadUnits)
            {
                continue;
            }

            bool maskContainsUnitFaction = (unit.faction & factionMask) == unit.faction;
            if (!maskContainsUnitFaction)
            {
                continue;
            }

            float distance = DistanceTo(unit);
            if (distance > maxRange)
            {
                continue;
            }

            if (closestUnitDistance < 0)
            {
                closestUnitDistance = distance;
                closestUnit         = unit;
            }
            else if (distance < closestUnitDistance)
            {
                closestUnit = unit;
            }
        }

        return(closestUnit);
    }
Exemple #8
0
    public int getNumUnitsInRangeByFlag(string flag, UnitFaction targetfaction, bool includeOwn)
    {
        int returnNum = 0;

        for (int i = 0; i < unitsInGroupRange.Count; i++)
        {
            if (unitsInGroupRange[i] != null)
            {
                if (unitsInGroupRange[i].gameObject.tag.Contains(flag) && unitsInGroupRange[i].GetComponent <FlagScript>().Faction == targetfaction)
                {
                    returnNum++;
                }
            }
        }

        if (includeOwn)
        {
            returnNum += getNumUnitsByFlag(flag, targetfaction);
        }

        return(returnNum);
    }
Exemple #9
0
    protected Unit[] Scan(UnitFaction factionMask, float maxRange, bool includeDeadUnits = false)
    {
        Unit[]      allUnits   = FindObjectsOfType <Unit>();
        List <Unit> foundUnits = new List <Unit>(allUnits.Length);

        for (int i = 0; i < allUnits.Length; i++)
        {
            Unit unit = allUnits[i];

            if (unit == this)
            {
                continue;
            }

            if (unit.dead && !includeDeadUnits)
            {
                continue;
            }

            bool maskContainsUnitFaction = (unit.faction & factionMask) == unit.faction;
            if (!maskContainsUnitFaction)
            {
                continue;
            }

            float distance = DistanceTo(unit);
            if (distance > maxRange)
            {
                continue;
            }

            foundUnits.Add(unit);
        }

        return(foundUnits.ToArray());
    }
    public int getNumUnitsInRangeByFlag(string flag, UnitFaction targetfaction, bool includeOwn)
    {
        int returnNum = 0;
        for(int i =0; i < unitsInGroupRange.Count; i++) {
            if(unitsInGroupRange[i] != null) {
                if(unitsInGroupRange[i].gameObject.tag.Contains(flag) && unitsInGroupRange[i].GetComponent<FlagScript>().Faction == targetfaction) {
                    returnNum++;
                }
            }
        }

        if(includeOwn) {
            returnNum += getNumUnitsByFlag(flag, targetfaction);
        }

        return returnNum;
    }
 public int getNumUnitsByFlag(string flag, UnitFaction targetfaction)
 {
     int returnNum = 0;
     for(int i =0; i < unitsInGroupScripts.Count; i++) {
         if(unitsInGroupScripts[i] != null) {
             if(unitsInGroupScripts[i].gameObject.tag.Contains(flag) && unitsInGroupScripts[i].flagScript.Faction == targetfaction) {
                 returnNum++;
             }
         }
     }
     return returnNum;
 }
Exemple #12
0
 public Boolean Has(UnitFaction faction) => this.Has(u => u.Faction == faction);
Exemple #13
0
 // Returns an instance of a unit of the given type and faction
 public GameUnit createUnit(UnitType type, UnitFaction faction, int level, Vector2 pos, bool immune)
 {
     GameUnit enemy;
         switch (type)
         {
             case UnitType.TANK:
                 enemy = new GameUnit(faction == UnitFaction.ALLY? textures[ALLY_TANK_l] : textures[ENEMY_TANK_l],
                     faction == UnitFaction.ALLY? textures[ALLY_TANK_r] : textures[ENEMY_TANK_r], type, faction, level, immune);
                 break;
             case UnitType.RANGED:
                 enemy = new GameUnit(faction == UnitFaction.ALLY ? textures[ALLY_RANGED] : textures[ENEMY_RANGED],
                     faction == UnitFaction.ALLY ? textures[ALLY_TANK_r] : textures[ENEMY_TANK_r], type, faction, level, immune);
                 break;
             case UnitType.FLYING:
                 enemy = new GameUnit(faction == UnitFaction.ALLY ? textures[ALLY_FLYING] : textures[ENEMY_FLYING],
                     faction == UnitFaction.ALLY ? textures[ALLY_TANK_r] : textures[ENEMY_TANK_r], type, faction, level, immune);
                 break;
             case UnitType.BOSS:
                 enemy = new GameUnit(textures[PLASMID], textures[PLASMID], type, faction, level, immune);
                 break;
             default:
                 enemy = null;
                 break;
         }
         if (enemy != null)
         {
             enemy.Position = pos;
         }
         return enemy;
 }