Esempio n. 1
0
    public static Unit CreateUnit(UnitGameObject unit, bool isHero, UnitTypes type)
    {
        string   unitType   = isHero ? type + "Hero" : type.ToString();
        string   jsonString = Resources.Load <TextAsset>("JSON/Units/" + unitType).text;
        JSONNode jsonUnit   = JSON.Parse(jsonString);

        int       attackRange        = jsonUnit["attackRange"].AsInt;
        int       moveRange          = jsonUnit["moveRange"].AsInt;
        bool      canAttackAfterMove = jsonUnit["canAttackAfterMove"].AsBool;
        float     maxHealth          = jsonUnit["maxHealth"].AsFloat;
        float     damage             = jsonUnit["damage"].AsFloat;
        int       cost     = jsonUnit["cost"].AsInt;
        int       fowLos   = jsonUnit["fowLos"].AsInt;
        float     baseLoot = jsonUnit["baseLoot"].AsFloat;
        JSONArray a        = jsonUnit["unitModifiers"].AsArray;

        var modifiers = new Dictionary <UnitTypes, float>();

        foreach (UnitTypes suit in (UnitTypes[])Enum.GetValues(typeof(UnitTypes)))
        {
            foreach (JSONNode item in a)
            {
                if (!String.IsNullOrEmpty(item[suit.ToString()]) && item[suit.ToString()] != suit.ToString())
                {
                    modifiers.Add(suit, item[suit.ToString()].AsFloat);
                }
            }
        }
        return(new Unit(unit, isHero, attackRange, moveRange, canAttackAfterMove, maxHealth, damage, cost, fowLos, baseLoot, modifiers));
    }
Esempio n. 2
0
        //This method prints the main string representations and some basic information for all the named units.
        //In any case, note that UnitParser supports a wide range of variations which aren't referred here.
        //Examples: plurals of string representation other than symbols or ignoring certain invalid characters
        //(e.g., blank spaces or conventionally-used characters like "^").
        //Additionally, bear in mind that these are just the members of the Units enum, a small fraction of
        //all the units supported by UnitParser. Any unit belonging to a supported type (UnitTypes enum) which
        //is formed by the combination of one or more named units (Units enum) is also supported. For example,
        //the named unit Units.Foot can be part of many other unnamed units like ft/h (velocity), rood*ft (volume)
        //or tn*ft/s2 (force).
        private static void PrintAllNamedUnits()
        {
            foreach (Units unit in Enum.GetValues(typeof(Units)))
            {
                if (unit == Units.None || unit == Units.Unitless)
                {
                    continue;
                }

                UnitTypes   type   = UnitP.GetUnitType(unit);
                UnitSystems system = UnitP.GetUnitSystem(unit);

                if (type == UnitTypes.None)
                {
                    continue;
                }

                Console.WriteLine("Unit: " + unit.ToString());
                Console.WriteLine("Type: " + type.ToString());
                Console.WriteLine("System: " + system.ToString());

                string representations = "";
                foreach (string representation in UnitP.GetStringsForUnit(unit, true))
                {
                    if (representations != "")
                    {
                        representations += ", ";
                    }
                    representations += representation;
                }

                Console.WriteLine("Representations: " + representations);
                Console.WriteLine();
            }
        }
Esempio n. 3
0
        public KeyValue ToKV(string key)
        {
            KeyValue kv = new KeyValue(key);

            if (Preset != PresetType.NONE)
            {
                kv += Preset.ToString();
                return(kv);
            }
            kv += new KeyValue("Center") + Center.ToString();
            if (this.Shape == ShapeE.CIRCLE)
            {
                kv += new KeyValue("Radius") + Radius.ToString();
            }
            if (this.Shape == ShapeE.LINE)
            {
                KeyValue linechild = new KeyValue("Line");
                linechild += new KeyValue("Length") + Length.ToString();
                linechild += new KeyValue("Thickness") + Thickness.ToString();
                kv        += linechild;
            }

            kv += new KeyValue("Teams") + Teams.ToString().Replace(",", " |");
            kv += new KeyValue("Types") + UnitTypes.ToString().Replace(",", " |");
            kv += new KeyValue("Flags") + Flags.ToString().Replace(",", " |");

            if (MaxTargets.Value != "-1")
            {
                kv += new KeyValue("MaxTargets") + MaxTargets.ToString();
                kv += new KeyValue("Random") + Random.ToString();
            }


            return(kv);
        }
 // I'd recommend using string parameters for your buttons instead
 // of enum parameters, but you can do it either way
 public void ModifyUnitButtonHandler(ArmyTypes army, UnitTypes unit, AttributeTypes attribute, int value)
 {
     // I'm not sure if the ? operator exists in Unity's default .NET version.
     // If not, you can use a few if/then statements to make sure that nothing
     // returns null
     GetArmy(army.ToString())?
     .GetUnit(unit.ToString())?
     .GetAttribute(attribute.ToString())?
     .Add(value);
 }
Esempio n. 5
0
 /// <summary>
 /// Get image url for a unit
 /// </summary>
 public string GetUnitImageUrl(UnitTypes type)
 {
     return string.Format(UnitGraphicsUrlFormat, type.ToString().ToLowerInvariant());
 }
Esempio n. 6
0
 public override string ToString()
 {
     return(_unitType.ToString());
 }
Esempio n. 7
0
    void OnGUI()
    {
        //Use PreExisting Prefab
        /*
        if(isEdit)
        {
            newTitle = newUnit.title;
            newName = newUnit.title;
            //
            newHealth = newUnit.health;
            newSpeed = newUnit.speed;
            newDefenseType = newUnit.defenseType;
            newDefenseRating = newUnit.defenseRating;
            newSprite = newUnit.sprite;
            newAnimator = newUnit.animator;
            isEdit = false;
        }
        */

        prefabType = (PrefabTypes)EditorGUILayout.EnumPopup (prefabType);
        EditorGUILayout.Space ();

        switch (prefabType)
        {
        case PrefabTypes.Tower:
            type = "Tower";
            isUnit = false;
            /*hasSecondAtk = true;
            atk2IsActive = false;
            canMine = true;
            mineIsActive = true;*/
            break;
        case PrefabTypes.Unit:
            EditorGUILayout.BeginHorizontal ();
            unitType = (UnitTypes)EditorGUILayout.EnumPopup (unitType);
            type = unitType.ToString ();
            EditorGUILayout.Space ();
            EditorGUILayout.EndHorizontal ();
            EditorGUILayout.Space ();

            isUnit = true;
            /*hasSecondAtk = false;
            atk2IsActive = false;
            canMine = false;
            mineIsActive = false;*/
            break;
        }

        EditorGUILayout.BeginHorizontal ();
        EditorGUI.indentLevel = 0;
        EditorGUILayout.LabelField ("Title: ", GUILayout.Width (35));
        newTitle = EditorGUILayout.TextField (newTitle, GUILayout.Width (200), GUILayout.ExpandWidth(true));
        EditorGUILayout.LabelField ("Unique:", GUILayout.Width (50), GUILayout.ExpandWidth(false));
        isUnique = EditorGUILayout.Toggle(isUnique, GUILayout.Width (10), GUILayout.ExpandWidth(false));
        EditorGUILayout.Space ();
        EditorGUILayout.EndHorizontal ();

        EditorGUILayout.Space ();

        if (isUnique)
        {
            EditorGUILayout.BeginHorizontal ();
            EditorGUI.indentLevel = 1;
            EditorGUILayout.LabelField ("Name: ", GUILayout.Width (60));
            newName = EditorGUILayout.TextField (newName,GUILayout.Width (200), GUILayout.ExpandWidth(true));
            EditorGUILayout.EndHorizontal ();
            EditorGUI.indentLevel = 0;
        }
        else
        {
            newName = newTitle;
        }

        EditorGUILayout.Space ();
        newSprite = (Sprite)EditorGUILayout.ObjectField ("Sprite: ", newSprite, typeof(Sprite), true);
        EditorGUILayout.Space ();

        //Animator???
        newAnimator = (Animator)EditorGUILayout.ObjectField ("Animator: ", newAnimator, typeof(Animator), true);
        EditorGUILayout.Space ();

        EditorGUILayout.BeginHorizontal ();
        EditorGUI.indentLevel = 1;
        EditorGUILayout.LabelField ("Health: ", GUILayout.Width (80));
        newHealth = EditorGUILayout.IntField (newHealth);
        EditorGUILayout.Space ();
        if (isUnit)
        {
            EditorGUILayout.LabelField ("Speed:", GUILayout.Width (80));
            newSpeed = EditorGUILayout.FloatField (newSpeed);
            EditorGUILayout.Space ();
        }
        EditorGUILayout.EndHorizontal ();

        EditorGUILayout.Space ();

        EditorGUILayout.BeginHorizontal ();
        EditorGUI.indentLevel = 1;
        EditorGUILayout.LabelField ("Defense: ", GUILayout.Width (80));
        newDefenseType = (Defenses)EditorGUILayout.EnumPopup (newDefenseType, GUILayout.Width (100));
        //EditorGUILayout.Space ();
        EditorGUILayout.LabelField ("Rating:", GUILayout.Width (60));
        newDefenseRating = EditorGUILayout.FloatField (newDefenseRating, GUILayout.Width (40));
        EditorGUILayout.Space ();
        EditorGUILayout.EndHorizontal ();

        EditorGUILayout.Space ();
        EditorGUILayout.Space ();

        EditorGUILayout.BeginHorizontal ();
        EditorGUI.indentLevel = 0;
        EditorGUILayout.LabelField ("Attack :", GUILayout.Width (150));
        EditorGUILayout.Space ();
        atk1IsActive = EditorGUILayout.Toggle (atk1IsActive, GUILayout.Width (30));
        EditorGUILayout.EndHorizontal ();

        EditorGUILayout.BeginHorizontal ();
        EditorGUI.indentLevel = 1;
        EditorGUILayout.LabelField ("Object: ", GUILayout.Width (80));
        newAttack1Projectile = (GameObject)EditorGUILayout.ObjectField (newAttack1Projectile, typeof(GameObject), true);//, GUILayout.Width(100));
        EditorGUILayout.LabelField ("Damage: ", GUILayout.Width(80));
        atk1Damage = EditorGUILayout.FloatField (atk1Damage);
        EditorGUILayout.EndHorizontal ();

        atk1Type = (AttackTypes)EditorGUILayout.EnumPopup("Type: ", atk1Type);

        EditorGUILayout.BeginHorizontal ();
        EditorGUILayout.LabelField ("Range: ", GUILayout.Width (80));
        atk1Range = EditorGUILayout.FloatField (atk1Range);
        EditorGUILayout.LabelField ("CoolDown: ",GUILayout.Width (80));
        atk1CD = EditorGUILayout.FloatField (atk1CD);
        EditorGUILayout.EndHorizontal ();

        EditorGUILayout.BeginHorizontal ();
        EditorGUILayout.LabelField ("Accuracy: ", GUILayout.Width (80));
        atk1Accuracy = EditorGUILayout.FloatField (atk1Accuracy);
        EditorGUILayout.LabelField ("Speed: ", GUILayout.Width (80));
        atk1Speed = EditorGUILayout.FloatField (atk1Speed);
        EditorGUILayout.EndHorizontal ();

        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal ();
        EditorGUILayout.Space ();
        hasSecondAtk = EditorGUILayout.Toggle ("Has Second Attack: ", hasSecondAtk);
        EditorGUILayout.EndHorizontal ();
        EditorGUILayout.Space ();
        EditorGUILayout.Space ();

        if(hasSecondAtk)
        {
            EditorGUILayout.BeginHorizontal ();
            EditorGUI.indentLevel = 0;
            EditorGUILayout.LabelField ("Attack 2 :", GUILayout.Width (150));
            EditorGUILayout.Space ();
            atk2IsActive = EditorGUILayout.Toggle (atk2IsActive, GUILayout.Width (30));
            EditorGUILayout.EndHorizontal ();

            EditorGUILayout.BeginHorizontal ();
            EditorGUI.indentLevel = 1;
            EditorGUILayout.LabelField ("Object: ", GUILayout.Width (80));
            newAttack2Projectile = (GameObject)EditorGUILayout.ObjectField (newAttack1Projectile, typeof(GameObject), true);
            EditorGUILayout.LabelField ("Damage: ", GUILayout.Width(80));
            atk2Damage = EditorGUILayout.FloatField (atk1Damage);
            EditorGUILayout.EndHorizontal ();

            atk2Type = (AttackTypes)EditorGUILayout.EnumPopup ("Type: ", atk2Type);

            EditorGUILayout.BeginHorizontal ();
            EditorGUILayout.LabelField ("Range: ", GUILayout.Width(80));
            atk2Range = EditorGUILayout.FloatField (atk2Range);
            EditorGUILayout.LabelField ("CoolDown: ", GUILayout.Width (80));
            atk2CD = EditorGUILayout.FloatField (atk2CD);
            EditorGUILayout.EndHorizontal ();

            EditorGUILayout.BeginHorizontal ();
            EditorGUILayout.LabelField ("Accuracy: ", GUILayout.Width (80));
            atk2Accuracy = EditorGUILayout.FloatField (atk2Accuracy);
            EditorGUILayout.LabelField ("Speed: ", GUILayout.Width (80));
            atk2Speed = EditorGUILayout.FloatField (atk2Speed);
            EditorGUILayout.EndHorizontal ();

            atk2OnGC = EditorGUILayout.Toggle ("On GC: ", atk2OnGC);
        }

        EditorGUI.indentLevel = 1;
        EditorGUILayout.Space ();
        EditorGUILayout.BeginHorizontal ();
        EditorGUILayout.Space ();
        canMine = EditorGUILayout.Toggle ("Can Mine: ", canMine);
        EditorGUILayout.EndHorizontal ();
        EditorGUILayout.Space ();

        if(canMine)
        {
            ///Needs to Include:
            /// Mining Range, Mining Cooldown, Mining Efficiency x4
            ///
            EditorGUILayout.BeginHorizontal ();
            EditorGUI.indentLevel= 0;
            EditorGUILayout.LabelField ("Mining: ", GUILayout.Width (150));
            EditorGUILayout.Space ();
            mineIsActive = EditorGUILayout.Toggle (mineIsActive, GUILayout.Width (30));
            EditorGUILayout.EndHorizontal ();

            EditorGUILayout.BeginHorizontal ();
            EditorGUI.indentLevel = 1;
            EditorGUILayout.LabelField ("Range: ", GUILayout.Width (80));
            mineRange = EditorGUILayout.FloatField (mineRange);
            EditorGUILayout.LabelField ("CoolDown: ", GUILayout.Width (80));
            mineCD = EditorGUILayout.FloatField (mineCD);
            EditorGUILayout.EndHorizontal ();

            EditorGUILayout.BeginHorizontal ();
            EditorGUI.indentLevel = 2;
            EditorGUILayout.LabelField ("Iron:    ", GUILayout.Width (80));
            mineEffIron = EditorGUILayout.FloatField (mineEffIron);
            EditorGUILayout.LabelField ("Lode:    ", GUILayout.Width (80));
            mineEffLode = EditorGUILayout.FloatField (mineEffLode);
            EditorGUILayout.Space ();
            EditorGUILayout.EndHorizontal ();

            EditorGUILayout.BeginHorizontal ();
            EditorGUILayout.LabelField ("Brin:    ", GUILayout.Width (80));
            mineEffBrin = EditorGUILayout.FloatField (mineEffBrin);
            EditorGUILayout.LabelField ("Mithril: ", GUILayout.Width (80));
            mineEffMith = EditorGUILayout.FloatField (mineEffMith);
            EditorGUILayout.Space ();
            EditorGUILayout.EndHorizontal ();
        }

        EditorGUILayout.Space ();

        if(GUILayout.Button ("Register " + type))
        {
            //Build a New Prefab
            GameObject newUnit = (GameObject.Find ("UnitPrefab"));
            newUnit.name = newName;
            string folder = "Tower";
            if(isUnit)
            {
                folder = "Units";
            }
            string path = AssetDatabase.GenerateUniqueAssetPath ("Assets/Prefabs/" + folder + "/" + newUnit.name + ".prefab");
            PrefabUtility.CreatePrefab (path, newUnit);

            //if(size == medium)
            var capsule = newUnit.GetComponent<CapsuleCollider>();

            capsule.radius = 1;
            capsule.height = 4;

            var body = newUnit.AddComponent<BodyScript>();

            body.title = newTitle;
            //body.speed = newSpeed;
            body.maxHealth = newHealth;
            body.health = newHealth;
            body.defenseRating = newDefenseRating;
            body.defenseType = newDefenseType.ToString ();

            if(isUnit)
            {
                //var seeker = newUnit.AddComponent<Seeker>();

                var controller = newUnit.AddComponent<CharacterController>();

                controller.radius = 0;
                controller.height = 0;

                var walker = newUnit.AddComponent<WalkScript>();
                walker.baseSpeed = newSpeed;

                var funnelMod = newUnit.AddComponent<Pathfinding.FunnelModifier>();
                //funnelMod.priority = 2;
                var alternMod = newUnit.AddComponent<Pathfinding.AlternativePath>();
                //alternMod.priority = 3;
            }

            var attack = newUnit.AddComponent<AttackScript>();

            attack.attackIsActive = atk1IsActive;
            attack.attackProjectile = newAttack1Projectile;
            attack.attackDamage = atk1Damage;
            attack.attackType = atk1Type;
            attack.attackRange = atk1Range;
            attack.attackCooldown = atk1CD;
            attack.attackAccuracy = atk1Accuracy;
            attack.attackSpeed = atk1Speed;

            if(hasSecondAtk)
            {
                attack.attack2IsActive = atk2IsActive;
                attack.attack2Projectile = newAttack2Projectile;
                attack.attack2Damage = atk2Damage;
                attack.attack2Type = atk2Type;
                attack.attack2Range = atk2Range;
                attack.attack2Cooldown = atk2CD;
                attack.attack2Accuracy = atk2Accuracy;
                attack.attack2Speed = atk2Speed;
                attack.attack2OnGC = atk2OnGC;
            }

            if(canMine)
            {
                var mine = newUnit.AddComponent<MiningScript>();

                mine.miningRange = mineRange;
                mine.miningCooldown = mineCD;
                mine.ironMiningRate = mineEffIron;
                mine.lodestoneMiningRate = mineEffLode;
                mine.brinmistrMiningRate = mineEffBrin;
                mine.mithrilMiningRate = mineEffMith;
            }
        }
    }
Esempio n. 8
0
 /// <summary>
 /// Get image url for a unit
 /// </summary>
 public string GetUnitImageUrl(UnitTypes type)
 {
     return(string.Format(UnitGraphicsUrlFormat, type.ToString().ToLowerInvariant()));
 }
Esempio n. 9
0
 public IEnumerator ConstructingUnit(UnitTypes unitType, Squad squadToDeployto)
 {
     GameObject g = PoolMaster.SpawnReference("Units", unitType.ToString(), new Vector3(999, 999, 999), Quaternion.identity);
      yield return new WaitForSeconds(unitPrefabs[(int)unitType].GetComponent<Unit>().buildTime);
     squadToDeployto.AddNewUnit(g);
 }
Esempio n. 10
0
 // Ctor creates a unit of passed type at passed location. using matrix notation
 public UnitController(float posX, float posY, UnitTypes unit)
     : base(posX,posY,unit.ToString())
 {
 }
Esempio n. 11
0
        /// <summary>
        /// Spawns a unit with the given parameters and adds it to battle.
        /// </summary>
        /// <param name="type">The type of unit to spawn</param>
        /// <param name="side">The Faction that the unit should 'fight for'</param>
        /// <param name="spawnPos">The GridPoint at which the created unit should spawn</param>
        public void SpawnCombatantOfType(UnitTypes type, Faction side, GridPoint spawnPos = null)
        {
            IMovementBehavior movement = null;
            IAttackBehavior attack = null;
            ITargetBehavior target = null;
            Unit testUnit = null;

            switch (type)
            {
                case UnitTypes.Caveman:
                    // movement
                    movement = MovementBehaviorFactory.SpawnBehavior(UnitMoverType.Walker, 1, spawnPos);
                    // attack
                    attack = AttackBehaviorFactory.SpawnBehavior(UnitAttackType.NeverAttacks, side);
                    // target
                    target = TargetBehaviorFactory.SpawnBehavior(UnitArmorType.Armored);
                    break;
                case UnitTypes.Knight:
                    // movement
                    movement = MovementBehaviorFactory.SpawnBehavior(UnitMoverType.Walker, 1, spawnPos);
                    // attack
                    attack = AttackBehaviorFactory.SpawnBehavior(UnitAttackType.NeverAttacks, side);
                    // target
                    target = TargetBehaviorFactory.SpawnBehavior(UnitArmorType.Armored);
                    break;
                case UnitTypes.Soldier:
                    // movement
                    movement = MovementBehaviorFactory.SpawnBehavior(UnitMoverType.Walker, 1, spawnPos);
                    // attack
                    attack = AttackBehaviorFactory.SpawnBehavior(UnitAttackType.NeverAttacks, side);
                    // target
                    target = TargetBehaviorFactory.SpawnBehavior(UnitArmorType.Armored);
                    break;
                case UnitTypes.Swat:
                    // movement
                    movement = MovementBehaviorFactory.SpawnBehavior(UnitMoverType.Walker, 1, spawnPos);
                    // attack
                    attack = AttackBehaviorFactory.SpawnBehavior(UnitAttackType.NeverAttacks, side);
                    // target
                    target = TargetBehaviorFactory.SpawnBehavior(UnitArmorType.Armored);
                    break;
                case UnitTypes.Tric:
                    // movement
                    movement = MovementBehaviorFactory.SpawnBehavior(UnitMoverType.Walker, 1, spawnPos);
                    // attack
                    attack = AttackBehaviorFactory.SpawnBehavior(UnitAttackType.NeverAttacks, side);
                    // target
                    target = TargetBehaviorFactory.SpawnBehavior(UnitArmorType.Armored);
                    break;
                case UnitTypes.Boss:
                    // movement
                    movement = MovementBehaviorFactory.SpawnBehavior(UnitMoverType.Walker, 1, spawnPos);
                    // attack
                    attack = AttackBehaviorFactory.SpawnBehavior(UnitAttackType.NeverAttacks, side);
                    // target
                    target = TargetBehaviorFactory.SpawnBehavior(UnitArmorType.Armored);
                    break;
                case UnitTypes.FlyingKappa:
                    // movement
                    movement = MovementBehaviorFactory.SpawnBehavior(UnitMoverType.Flyer, 1, spawnPos);
                    // attack
                    attack = AttackBehaviorFactory.SpawnBehavior(UnitAttackType.NeverAttacks, side);
                    // target
                    target = TargetBehaviorFactory.SpawnBehavior(UnitArmorType.Armored);
                    break;
                case UnitTypes.WalkingKappa:
                    // movement
                    movement = MovementBehaviorFactory.SpawnBehavior(UnitMoverType.Walker, 2, spawnPos);
                    // attack
                    attack = AttackBehaviorFactory.SpawnBehavior(UnitAttackType.NeverAttacks, side);
                    // target
                    target = TargetBehaviorFactory.SpawnBehavior(UnitArmorType.Armored);
                    break;
                case UnitTypes.DummyTower:
                    // movement
                    movement = MovementBehaviorFactory.SpawnBehavior(UnitMoverType.NoMovement, 5, spawnPos);
                    // attack
                    attack = AttackBehaviorFactory.SpawnBehavior(UnitAttackType.StopsToAttack, side, .5f, 10, 10);
                    // target
                    target = TargetBehaviorFactory.SpawnBehavior(UnitArmorType.Armored);
                    break;
                default:
                    Debug.LogError("Did you forget to add a unit type to SpawnCombatant?");
                    break;
            }

            if (movement == null || attack == null || target == null) Debug.LogError("Unit didn't instantiate correctly :(");

            _spawnedUnits[type]++;

            if (spawnPos == null) spawnPos = NavigationController.Instance.FirstTile;

            // TODO: this is here until units can decide where to go themselves
            movement.PathTo(NavigationController.Instance.LastTile);

            testUnit = new Unit(String.Format(type.ToString() + "-" + _spawnedUnits[type]), type, side, movement, attack, target);

            spawnPos.AddToTile(testUnit);
            AddCombatantToActiveBattle(testUnit);

            if (type == UnitTypes.DummyTower)
                SoundPlayer.getInstance ().Play (sounds.tower);
            else
                SoundPlayer.getInstance().Play (sounds.spawn);
        }