示例#1
0
    public bool CanPerformAttack(Unit attackerUnit, Unit targetUnit, LevelTile targetTile)
    {
        if (!isActive)
        {
            return(false);
        }
        AttackTargets allowedTargets = targets;

        bool canAttackSelf                    = allowedTargets == AttackTargets.Self;
        bool canAttackAllies                  = allowedTargets == AttackTargets.Allies;
        bool canAttackEnemies                 = allowedTargets == AttackTargets.Enemies;
        bool canAttackSameClassAlly           = allowedTargets == AttackTargets.SameClassAlly;
        bool canAttackEnemiesAndSameClassAlly = allowedTargets == AttackTargets.EnemiesOrSameClassAlly;

        List <Unit> attackerAllies              = attackerUnit.Player.Units;
        bool        clickedSelf                 = targetUnit == attackerUnit;
        bool        clickedEnemy                = !attackerAllies.Contains(targetUnit);
        bool        clickedAlly                 = !clickedSelf && !clickedEnemy;
        bool        clickedSameClassAlly        = clickedAlly && targetUnit.unitClass.Type == attackerUnit.unitClass.Type;
        bool        clickedEnemyOrSameClassAlly = clickedEnemy || clickedSameClassAlly;

        bool canAttackEnvironment = targetTile != null && targetTile.CanBeAttacked;
        bool canAttackUnit        = targetUnit != null &&
                                    (
            allowedTargets == AttackTargets.Both ||
            canAttackSelf && clickedSelf ||
            canAttackAllies && clickedAlly ||
            canAttackEnemies && clickedEnemy ||
            canAttackSameClassAlly && clickedSameClassAlly ||
            canAttackEnemiesAndSameClassAlly && clickedEnemyOrSameClassAlly
                                    );

        return(canAttackUnit || canAttackEnvironment);
    }
 public DefensiveBuilding(string id, string label, int gridWidth, int gridHeight, int maxAttackRange, int minAttackRange, AttackTargets targets)
     : base(id, label, Colors.PaleGoldenrod, gridWidth, gridHeight)
 {
     this.MaxAttackRange = maxAttackRange;
     this.MinAttackRange = minAttackRange;
     this.Targets = targets;
 }
    void Start()
    {
        attackTargets = GetComponent <AttackTargets>();
        enemyMovement = GetComponent <EnemyMovement>();

        SetMoveState();
    }
示例#4
0
        static public AttackTargets GetDataJson(string path)
        {
            log.Info($"Opening {path}");
            string rawJson = ReadFile(path);

            AttackTargets dataObject = JsonConvert.DeserializeObject <AttackTargets>(rawJson);

            return(dataObject);
        }
 public DefensiveBuilding(string id, string label, int gridWidth, int gridHeight, int attackRange, AttackTargets targets)
     : this(id, label, gridWidth, gridHeight, attackRange, 0, targets)
 {
 }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        CheckAndInitialize(property);
        position.height = fieldHeight;

        EditorGUI.LabelField(position, label);
        position.y += fieldHeight;

        EditorGUI.indentLevel++;

        // IsActive field
        bool isActiveVal = _SkillConfig.isActive;

        EditorGUI.BeginChangeCheck();
        bool newIsActiveVal = EditorGUI.Toggle(position, "Is active?", isActiveVal);

        position.y += fieldHeight;
        if (EditorGUI.EndChangeCheck())
        {
            try
            {
                _SkillConfig.isActive = newIsActiveVal;
            }
            catch (Exception e)
            {
                Debug.Log(e.Message);
            }
        }

        if (_SkillConfig.isActive)
        {
            // Damage field
            float damageVal = _SkillConfig.baseDamage;
            EditorGUI.BeginChangeCheck();
            float newDamageVal = EditorGUI.FloatField(position, "Base damage", damageVal);
            position.y += fieldHeight;
            if (EditorGUI.EndChangeCheck())
            {
                try
                {
                    _SkillConfig.baseDamage = newDamageVal;
                }
                catch (Exception e)
                {
                    Debug.Log(e.Message);
                }
            }

            // Targets field
            AttackTargets targetsVal = _SkillConfig.targets;
            EditorGUI.BeginChangeCheck();
            AttackTargets newTargetsVal = (AttackTargets)EditorGUI.EnumPopup(position, "Targets", (Enum)(object)targetsVal);
            position.y += fieldHeight;
            if (EditorGUI.EndChangeCheck())
            {
                try
                {
                    _SkillConfig.targets = newTargetsVal;
                }
                catch (Exception e)
                {
                    Debug.Log(e.Message);
                }
            }

            // Effect field
            AttackEffect effectVal = _SkillConfig.effect;
            EditorGUI.BeginChangeCheck();
            AttackEffect newEffectVal =
                (AttackEffect)EditorGUI.ObjectField(position, "Effect", (UnityObject)(object)effectVal, typeof(AttackEffect), true);
            position.y += fieldHeight;
            if (EditorGUI.EndChangeCheck())
            {
                try
                {
                    _SkillConfig.effect = newEffectVal;
                }
                catch (Exception e)
                {
                    Debug.Log(e.Message);
                }
            }

            // Trajectory field
            DamageTrajectory trajectoryVal = _SkillConfig.trajectory;
            EditorGUI.BeginChangeCheck();
            DamageTrajectory newTrajectoryVal = (DamageTrajectory)EditorGUI.EnumPopup(
                position,
                "Trajectory",
                (Enum)(object)trajectoryVal
                );;
            position.y += fieldHeight;
            if (EditorGUI.EndChangeCheck())
            {
                try
                {
                    _SkillConfig.trajectory = newTrajectoryVal;
                }
                catch (Exception e)
                {
                    Debug.Log(e.Message);
                }
            }

            if (_SkillConfig.trajectory == DamageTrajectory.Straight)
            {
                // Straight range field
                int straightRangeVal = _SkillConfig.straightRange;
                EditorGUI.BeginChangeCheck();
                int newStraightRangeVal = EditorGUI.IntField(position, "Range", straightRangeVal);
                position.y += fieldHeight;
                if (EditorGUI.EndChangeCheck())
                {
                    try
                    {
                        _SkillConfig.straightRange = newStraightRangeVal;
                    }
                    catch (Exception e)
                    {
                        Debug.Log(e.Message);
                    }
                }
            }

            if (_SkillConfig.trajectory == DamageTrajectory.Curve)
            {
                position.y += fieldHeight;
                // Curve range expand
                Rect expandButtonRect = position;
                expandButtonRect.width = position.width / 2;
                if (GUI.Button(expandButtonRect, "Expand"))
                {
                    ExpandArea();
                }

                // Curve range shrink
                Rect shrinkButtonRect = position;
                shrinkButtonRect.width = position.width / 2;
                shrinkButtonRect.x     = position.x + expandButtonRect.width;
                if (GUI.Button(shrinkButtonRect, "Shrink"))
                {
                    ShrinkArea();
                }
                position.y += fieldHeight;

                int       cellWidth  = 20;
                int       cellHeight = 20;
                BoundsInt bounds     = _SkillConfig.patternBounds;

                Rect patternAreaRect = position;
                patternAreaRect.width  = bounds.size.x * cellWidth;
                patternAreaRect.height = bounds.size.y * cellHeight;
                patternHeight          = patternAreaRect.height;

                foreach (KeyValuePair <Vector2Int, AttackPatternField> cell in _SkillConfig.pattern)
                {
                    Vector2Int cellPos = cell.Key;

                    Rect cellRect = new Rect(
                        patternAreaRect.x + position.width / 2 + (cellPos.x - .5f) * cellWidth,
                        patternAreaRect.y + 5 - (cellPos.y - bounds.yMax) * cellHeight,
                        cellWidth,
                        cellHeight
                        );
                    GUI.color = Color.gray;

                    if (cell.Value == AttackPatternField.Player)
                    {
                        GUI.color = Color.magenta;
                        GUI.Button(cellRect, "");
                    }
                    else
                    {
                        if (cell.Value == AttackPatternField.On)
                        {
                            GUI.color = Color.green;
                        }
                        if (GUI.Button(cellRect, ""))
                        {
                            ToggleField(cellPos);
                            break;
                        }
                        ;
                    }
                }
                GUI.color = Color.white;
            }
        }

        if (GUI.changed)
        {
            var target = property.serializedObject.targetObject;
            EditorUtility.SetDirty(target);
        }
    }
	// Use this for initialization
	void Start () 
	{
		instance = this;

		layerMask = 1 << LayerMask.NameToLayer ("AttackCollider");

		isAttacking = false;
		isSpecial = false;

		myTransform = transform;

		AudioSource[] audioSources = GetComponents<AudioSource>();
		audioSourceAttack = audioSources[0];
		audioSourceSpecial = audioSources[1];

		targets = new List<Transform> ();
		enemiesInRange = new List<Transform> ();

		foreach(CircleCollider2D col in GetComponents<CircleCollider2D>())
		{
			if(col.isTrigger)
			{
				range = col;
				break;
			}
		}

		gameObject.SetActive (false);
	}
示例#8
0
 public Functionalities()
 {
     targets = Utilities.GetDataJson(System.IO.Path.GetFullPath(@"..\..\Ressources\data.json"));
     TroopsToSave.Praetorian.Amount = 0;
     TroopsToSave.Settlers.Amount   = 3;
 }
 public DefensiveBuilding(string id, string label, int gridWidth, int gridHeight, int maxAttackRange, int minAttackRange, AttackTargets targets)
     : base(id, label, Colors.PaleGoldenrod, gridWidth, gridHeight)
 {
     this.MaxAttackRange = maxAttackRange;
     this.MinAttackRange = minAttackRange;
     this.Targets        = targets;
 }
 public DefensiveBuilding(string id, string label, int gridWidth, int gridHeight, int attackRange, AttackTargets targets)
     : this(id, label, gridWidth, gridHeight, attackRange, 0, targets)
 {
 }