コード例 #1
0
    /// <summary>
    /// Initializes the combat system.
    /// </summary>
    /// <param name="offensiveSquad">GameObject for the squad performing the attack.</param>
    /// <param name="defensiveSquad">GameObject for the squad on defense.</param>
    /// <param name="grid">Grid behavior on which the combat is taking place.</param>
    public void BeginCombat(CombatSquadBehavior offensiveSquad, CombatSquadBehavior defensiveSquad, GridBehavior grid)
    {
        if (offensiveSquad.Squad == null || defensiveSquad.Squad == null)
        {
            Debug.LogError("Combat was started with either the offensive or defense squad being null!");
            return;
        }

        combatRange = (int)Mathf.Ceil(Vector3.Distance(offensiveSquad.transform.position, defensiveSquad.transform.position));

        this.grid = grid;

        GridBehavior.inCombat  = true;
        AudioBehavior.inCombat = true;

        this.offensiveSquad = offensiveSquad;
        this.defensiveSquad = defensiveSquad;

        int unitCount = offensiveSquad.Squad.Units.Count + defensiveSquad.Squad.Units.Count;

        unitPrefabs = new List <NodeSkeletonBehavior>(unitCount);

        createUnits(offensiveSquad.Squad.Units, true, 0.0f);
        createUnits(defensiveSquad.Squad.Units, false, 1.0f);

        currentAttacker = CurrentAttacker.OffensiveFront;
    }
コード例 #2
0
    /// <summary>
    /// Initializes the combat system.
    /// </summary>
    /// <param name="offensiveSquad">GameObject for the squad performing the attack.</param>
    /// <param name="defensiveSquad">GameObject for the squad on defense.</param>
    public void BeginCombat(CombatSquadBehavior offensiveSquad, CombatSquadBehavior defensiveSquad)
    {
        if (offensiveSquad.Squad == null || defensiveSquad.Squad == null)
        {
            Debug.LogError("Combat was started with either the offensive or defense squad being null!");
            return;
        }

        GridBehavior.inCombat = true;
        InCombat = true;

        this.offensiveSquad = offensiveSquad;
        this.defensiveSquad = defensiveSquad;

        Debug.Log("Combat between " + offensiveSquad.ToString() + " and " + defensiveSquad.ToString() + " begin.");

        Debug.Log("Offensive size: " + offensiveSquad.Squad.Units.Count);
        Debug.Log("Defensive size: " + defensiveSquad.Squad.Units.Count);

        int unitCount = offensiveSquad.Squad.Units.Count + defensiveSquad.Squad.Units.Count;
        unitPrefabs = new List<NodeSkeletonBehavior>(unitCount);

        foreach(UnitData data in offensiveSquad.Squad.Units)
        {
            float x = -1.0f + (0.33f * data.Position.Row);
            float y = 0.7f - (0.33f * data.Position.Column);
            float z = 0.9f - (0.05f * data.Position.Column);

            NodeSkeletonBehavior skele = (NodeSkeletonBehavior)Instantiate(unitSkeleton);

            skele.transform.parent = transform;
            skele.transform.localScale = (Vector3.one / 2.0f);
            skele.transform.localPosition = Vector3.zero;

            skele.transform.Translate(x, y, z);
        }

        foreach (UnitData data in defensiveSquad.Squad.Units)
        {
            float x = 1.0f - (0.33f * data.Position.Row);
            float y = 0.7f - (0.33f * data.Position.Column);
            float z = 0.9f - (0.05f * data.Position.Column);

            NodeSkeletonBehavior skele = (NodeSkeletonBehavior)Instantiate(unitSkeleton);

            skele.transform.parent = transform;
            skele.transform.localScale = new Vector3(-0.5f, 0.5f, 0.5f);
            skele.transform.localPosition = Vector3.zero;

            skele.transform.Translate(x, y, z);
        }

        currentAttacker = CurrentAttacker.OffensiveFront;
    }
コード例 #3
0
    // Update is called once per frame
    /// <summary>
    /// Function that checks whether your in combat aand enambles the proper camera. 
    /// </summary>
    void Update()
    {
        if (InCombat && !combatCamera.enabled)
            combatCamera.enabled = true;
        else if (!InCombat && combatCamera.enabled)
            combatCamera.enabled = false;

        if (!InCombat)
            return;

        // TODO: REPLACE HACK, CRAP CODE.
        hackTimeImpl += Time.deltaTime;
        if (hackTimeImpl <= 1.0f)
            return;
        hackTimeImpl = 0.0f;

        // Perform combat logic.
        IEnumerable<CombatUnit> offFirstRow = offensiveSquad.Squad.Units.Where(l => l.Position.Row == 0).Select(l => l.Unit);
        IEnumerable<CombatUnit> offSecondRow = offensiveSquad.Squad.Units.Where(l => l.Position.Row == 1).Select(l => l.Unit);
        IEnumerable<CombatUnit> defFirstRow = defensiveSquad.Squad.Units.Where(l => l.Position.Row == 0).Select(l => l.Unit);
        IEnumerable<CombatUnit> defSecondRow = defensiveSquad.Squad.Units.Where(l => l.Position.Row == 1).Select(l => l.Unit);

        // Ensure there is actually somebody remaining!
        if (offensiveSquad.Squad.Units.Count == 0)
            endCombat(offensiveSquad);

        if (defensiveSquad.Squad.Units.Count == 0)
            endCombat(defensiveSquad);

        switch (currentAttacker)
        {
            case CurrentAttacker.OffensiveFront:
                {
                    if (offFirstRow.Count() > 0)
                    {
                        int totalStrength = offFirstRow.Sum(l => l.Strength);

                        int damagePerUnit = totalStrength / (defFirstRow.Count() > 0 ? defFirstRow.Count() : defSecondRow.Count());
                        foreach (CombatUnit unit in (defFirstRow.Count() > 0 ? defFirstRow : defSecondRow))
                        {
                            unit.Health -= Mathf.Max(damagePerUnit - unit.Toughness, 0);

                            Debug.Log(string.Format("{0}:{1} took {2} damage, {3} remaining.", defensiveSquad.ToString(), unit.Name, damagePerUnit, unit.Health));

                            if (unit.Health <= 0)
                                Debug.Log(string.Format("{0} was destroyed! {1} units remaining in squad.", unit.Name, defensiveSquad.Squad.Units.Count));
                        }

                        removeDeadUnits();
                    }

                    currentAttacker = CurrentAttacker.DefensiveFront;
                } break;

            case CurrentAttacker.DefensiveFront:
                {
                    if (defFirstRow.Count() > 0)
                    {
                        int totalStrength = defFirstRow.Sum(l => l.Strength);

                        int damagePerUnit = totalStrength / (offFirstRow.Count() > 0 ? offFirstRow.Count() : offSecondRow.Count());
                        foreach (CombatUnit unit in (offFirstRow.Count() > 0 ? offFirstRow : offSecondRow))
                        {
                            unit.Health -= Mathf.Max(damagePerUnit - unit.Toughness, 0);

                            Debug.Log(string.Format("{0}:{1} took {2} damage, {3} remaining.", offensiveSquad.ToString(), unit.Name, damagePerUnit, unit.Health));

                            if (unit.Health <= 0)
                                Debug.Log(string.Format("{0} was destroyed! {1} units remaining in squad.", unit.Name, offensiveSquad.Squad.Units.Count));
                        }

                        removeDeadUnits();
                    }

                    currentAttacker = CurrentAttacker.OffensiveBack;
                } break;

            case CurrentAttacker.OffensiveBack:
                {
                    if (offSecondRow.Count() > 0)
                    {
                        int totalStrength = offSecondRow.Sum(l => l.Strength);

                        int damagePerUnit = totalStrength / (defFirstRow.Count() > 0 ? defFirstRow.Count() : defSecondRow.Count());
                        foreach (CombatUnit unit in (defFirstRow.Count() > 0 ? defFirstRow : defSecondRow))
                        {
                            unit.Health -= Mathf.Max(damagePerUnit - unit.Toughness, 0);

                            Debug.Log(string.Format("{0}:{1} took {2} damage, {3} remaining.", defensiveSquad.ToString(), unit.Name, damagePerUnit, unit.Health));

                            if (unit.Health <= 0)
                                Debug.Log(string.Format("{0} was destroyed! {1} units remaining in squad.", unit.Name, defensiveSquad.Squad.Units.Count));
                        }

                        removeDeadUnits();
                    }

                    currentAttacker = CurrentAttacker.DefensiveBack;
                } break;

            case CurrentAttacker.DefensiveBack:
                {
                    if (defSecondRow.Count() > 0)
                    {
                        int totalStrength = defSecondRow.Sum(l => l.Strength);

                        int damagePerUnit = totalStrength / (offFirstRow.Count() > 0 ? offFirstRow.Count() : offSecondRow.Count());
                        foreach (CombatUnit unit in (offFirstRow.Count() > 0 ? offFirstRow : offSecondRow))
                        {
                            unit.Health -= Mathf.Max(damagePerUnit - unit.Toughness, 0);

                            Debug.Log(string.Format("{0}:{1} took {2} damage, {3} remaining.", offensiveSquad.ToString(), unit.Name, damagePerUnit, unit.Health));

                            if (unit.Health <= 0)
                                Debug.Log(string.Format("{0} was destroyed! {1} units remaining in squad.", unit.Name, offensiveSquad.Squad.Units.Count));
                        }

                        removeDeadUnits();
                    }

                    currentAttacker = CurrentAttacker.None;
                } break;

            case CurrentAttacker.None:
                endCombat(null);
                break;
        }
    }
コード例 #4
0
	/// <summary>
	/// Initializes the combat system.
	/// </summary>
	/// <param name="offensiveSquad">GameObject for the squad performing the attack.</param>
	/// <param name="defensiveSquad">GameObject for the squad on defense.</param>
	/// <param name="grid">Grid behavior on which the combat is taking place.</param>
	public void BeginCombat(CombatSquadBehavior offensiveSquad, CombatSquadBehavior defensiveSquad, GridBehavior grid)
	{
		if (offensiveSquad.Squad == null || defensiveSquad.Squad == null)
		{
			Debug.LogError("Combat was started with either the offensive or defense squad being null!");
			return;
		}

		combatRange = (int)Mathf.Ceil(Vector3.Distance(offensiveSquad.transform.position, defensiveSquad.transform.position));

		this.grid = grid;

		GridBehavior.inCombat = true;
        AudioBehavior.inCombat = true;

		this.offensiveSquad = offensiveSquad;
		this.defensiveSquad = defensiveSquad;

		int unitCount = offensiveSquad.Squad.Units.Count + defensiveSquad.Squad.Units.Count;
		unitPrefabs = new List<NodeSkeletonBehavior>(unitCount);

		createUnits (offensiveSquad.Squad.Units, true, 0.0f);
		createUnits (defensiveSquad.Squad.Units, false, 1.0f);

		currentAttacker = CurrentAttacker.OffensiveFront;
	}
コード例 #5
0
	// Update is called once per frame
	/// <summary>
	/// Function that checks whether your in combat and enables the proper camera. 
	/// </summary>
	void Update () 
	{
		if (GridBehavior.inCombat && !combatCamera.enabled)
			combatCamera.enabled = true;
		else if (!GridBehavior.inCombat && combatCamera.enabled)
			combatCamera.enabled = false;

		if (!GridBehavior.inCombat)
			return;

		// TODO: REPLACE HACK, CRAP CODE.
		hackTimeImpl += Time.deltaTime;
		if (hackTimeImpl <= 1.0f)
			return;
		hackTimeImpl = 0.0f;

		// Perform combat logic.
		IEnumerable<CombatUnit> offFirstRow = offensiveSquad.Squad.Units.Where(l => l.Position.Row == 0 && l.Unit.Range <= combatRange).Select(l => l.Unit);
		IEnumerable<CombatUnit> offSecondRow = offensiveSquad.Squad.Units.Where(l => l.Position.Row == 1 && l.Unit.Range <= combatRange).Select(l => l.Unit);
		IEnumerable<CombatUnit> defFirstRow = defensiveSquad.Squad.Units.Where(l => l.Position.Row == 0 && l.Unit.Range <= combatRange).Select(l => l.Unit);
		IEnumerable<CombatUnit> defSecondRow = defensiveSquad.Squad.Units.Where(l => l.Position.Row == 1 && l.Unit.Range <= combatRange).Select(l => l.Unit);

		// Ensure there is actually somebody remaining!
		if (offensiveSquad.Squad.Units.Count == 0)
			endCombat(offensiveSquad);

		if (defensiveSquad.Squad.Units.Count == 0)
			endCombat(defensiveSquad);

		switch (currentAttacker)
		{
			case CurrentAttacker.OffensiveFront:
				{
					if (offFirstRow.Count() > 0)
					{
						int totalStrength = offFirstRow.Sum(l => l.Strength);

						int damagePerUnit = totalStrength / (defFirstRow.Count() > 0 ? defFirstRow.Count() : defSecondRow.Count());
						foreach (CombatUnit unit in (defFirstRow.Count() > 0 ? defFirstRow : defSecondRow))
						{
							int damageReceived = (unit.Toughness != 0 ? (int)Mathf.Ceil((float)damagePerUnit * (1.0f - (1.0f / (float)unit.Toughness))) : damagePerUnit);
							unit.CurrentHealth -= Mathf.Max(damageReceived, 0);
                            if (unit.CurrentHealth <= 0)
                            {
                                HonorSystemBehavior.inCombat = true;
                                HonorSystemBehavior.honorPenalty = unit.HonorMod;
                                HonorSystemBehavior.offensiveHonor++;
                            }
						}

						removeDeadUnits();
					}

					currentAttacker = CurrentAttacker.DefensiveFront;
				} break;

			case CurrentAttacker.DefensiveFront:
				{
					if (defFirstRow.Count() > 0)
					{
						int totalStrength = defFirstRow.Sum(l => l.Strength);

						int damagePerUnit = totalStrength / (offFirstRow.Count() > 0 ? offFirstRow.Count() : offSecondRow.Count());
						foreach (CombatUnit unit in (offFirstRow.Count() > 0 ? offFirstRow : offSecondRow))
						{
							int damageReceived = (unit.Toughness != 0 ? (int)Mathf.Ceil((float)damagePerUnit * (1.0f - (1.0f / (float)unit.Toughness))) : damagePerUnit);
							unit.CurrentHealth -= Mathf.Max(damageReceived, 0);

                            if (unit.CurrentHealth <= 0)
                            {
                                HonorSystemBehavior.inCombat = true;
                                HonorSystemBehavior.honorPenalty = unit.HonorMod;
                                HonorSystemBehavior.defensiveHonor++;
                            }
						}

						removeDeadUnits();
					}

					currentAttacker = CurrentAttacker.OffensiveBack;
				} break;

			case CurrentAttacker.OffensiveBack:
				{
					if (offSecondRow.Count() > 0)
					{
						int totalStrength = offSecondRow.Sum(l => l.Strength);

						int damagePerUnit = totalStrength / (defFirstRow.Count() > 0 ? defFirstRow.Count() : defSecondRow.Count());
						foreach (CombatUnit unit in (defFirstRow.Count() > 0 ? defFirstRow : defSecondRow))
						{
							int damageReceived = (unit.Toughness != 0 ? (int)Mathf.Ceil((float)damagePerUnit * (1.0f - (1.0f / (float)unit.Toughness))) : damagePerUnit);
							unit.CurrentHealth -= Mathf.Max(damageReceived, 0);
                            if (unit.CurrentHealth <= 0)
                            {
                                HonorSystemBehavior.inCombat = true;
                                HonorSystemBehavior.honorPenalty = unit.HonorMod;
                                HonorSystemBehavior.offensiveHonor++;
                            }
						}

						removeDeadUnits();
					}

					currentAttacker = CurrentAttacker.DefensiveBack;
				} break;

			case CurrentAttacker.DefensiveBack:
				{
					if (defSecondRow.Count() > 0)
					{
						int totalStrength = defSecondRow.Sum(l => l.Strength);

						int damagePerUnit = totalStrength / (offFirstRow.Count() > 0 ? offFirstRow.Count() : offSecondRow.Count());
						foreach (CombatUnit unit in (offFirstRow.Count() > 0 ? offFirstRow : offSecondRow))
						{
							int damageReceived = (unit.Toughness != 0 ? (int)Mathf.Ceil((float)damagePerUnit * (1.0f - (1.0f / (float)unit.Toughness))) : damagePerUnit);
							unit.CurrentHealth -= Mathf.Max(damageReceived, 0);
                            if (unit.CurrentHealth <= 0)
                            {
                                HonorSystemBehavior.inCombat = true;
                                HonorSystemBehavior.honorPenalty = unit.HonorMod;
                                HonorSystemBehavior.defensiveHonor++;
                            }
						}

						removeDeadUnits();
					}

					currentAttacker = CurrentAttacker.None;
				} break;

			case CurrentAttacker.None:
				endCombat(null);
				break;
		}
	}
コード例 #6
0
    /// <summary>
    /// Initializes the combat system.
    /// </summary>
    /// <param name="offensiveSquad">GameObject for the squad performing the attack.</param>
    /// <param name="defensiveSquad">GameObject for the squad on defense.</param>
    public void BeginCombat(CombatSquadBehavior offensiveSquad, CombatSquadBehavior defensiveSquad)
    {
        if (offensiveSquad.Squad == null || defensiveSquad.Squad == null)
        {
            Debug.LogError("Combat was started with either the offensive or defense squad being null!");
            return;
        }

        GridBehavior.inCombat = true;
        InCombat = true;

        this.offensiveSquad = offensiveSquad;
        this.defensiveSquad = defensiveSquad;

        Debug.Log("Combat between " + offensiveSquad.ToString() + " and " + defensiveSquad.ToString() + " begin.");

        Debug.Log("Offensive size: " + offensiveSquad.Squad.Units.Count);
        Debug.Log("Defensive size: " + defensiveSquad.Squad.Units.Count);

        int unitCount = offensiveSquad.Squad.Units.Count + defensiveSquad.Squad.Units.Count;
        unitPrefabs = new List<NodeSkeletonBehavior>(unitCount);

        createUnits(offensiveSquad.Squad.Units, true, 0.0f);
        createUnits (defensiveSquad.Squad.Units, false, 1.0f);

        currentAttacker = CurrentAttacker.OffensiveFront;
    }
コード例 #7
0
    // Update is called once per frame
    /// <summary>
    /// Function that checks whether your in combat and enables the proper camera.
    /// </summary>
    void Update()
    {
        if (GridBehavior.inCombat && !combatCamera.enabled)
        {
            combatCamera.enabled = true;
        }
        else if (!GridBehavior.inCombat && combatCamera.enabled)
        {
            combatCamera.enabled = false;
        }

        if (!GridBehavior.inCombat)
        {
            return;
        }

        // TODO: REPLACE HACK, CRAP CODE.
        hackTimeImpl += Time.deltaTime;
        if (hackTimeImpl <= 1.0f)
        {
            return;
        }
        hackTimeImpl = 0.0f;

        // Perform combat logic.
        IEnumerable <CombatUnit> offFirstRow  = offensiveSquad.Squad.Units.Where(l => l.Position.Row == 0 && l.Unit.Range <= combatRange).Select(l => l.Unit);
        IEnumerable <CombatUnit> offSecondRow = offensiveSquad.Squad.Units.Where(l => l.Position.Row == 1 && l.Unit.Range <= combatRange).Select(l => l.Unit);
        IEnumerable <CombatUnit> defFirstRow  = defensiveSquad.Squad.Units.Where(l => l.Position.Row == 0 && l.Unit.Range <= combatRange).Select(l => l.Unit);
        IEnumerable <CombatUnit> defSecondRow = defensiveSquad.Squad.Units.Where(l => l.Position.Row == 1 && l.Unit.Range <= combatRange).Select(l => l.Unit);

        // Ensure there is actually somebody remaining!
        if (offensiveSquad.Squad.Units.Count == 0)
        {
            endCombat(offensiveSquad);
        }

        if (defensiveSquad.Squad.Units.Count == 0)
        {
            endCombat(defensiveSquad);
        }

        switch (currentAttacker)
        {
        case CurrentAttacker.OffensiveFront:
        {
            if (offFirstRow.Count() > 0)
            {
                int totalStrength = offFirstRow.Sum(l => l.Strength);

                int damagePerUnit = totalStrength / (defFirstRow.Count() > 0 ? defFirstRow.Count() : defSecondRow.Count());
                foreach (CombatUnit unit in (defFirstRow.Count() > 0 ? defFirstRow : defSecondRow))
                {
                    int damageReceived = (unit.Toughness != 0 ? (int)Mathf.Ceil((float)damagePerUnit * (1.0f - (1.0f / (float)unit.Toughness))) : damagePerUnit);
                    unit.CurrentHealth -= Mathf.Max(damageReceived, 0);
                    if (unit.CurrentHealth <= 0)
                    {
                        HonorSystemBehavior.inCombat     = true;
                        HonorSystemBehavior.honorPenalty = unit.HonorMod;
                        HonorSystemBehavior.offensiveHonor++;
                    }
                }

                removeDeadUnits();
            }

            currentAttacker = CurrentAttacker.DefensiveFront;
        } break;

        case CurrentAttacker.DefensiveFront:
        {
            if (defFirstRow.Count() > 0)
            {
                int totalStrength = defFirstRow.Sum(l => l.Strength);

                int damagePerUnit = totalStrength / (offFirstRow.Count() > 0 ? offFirstRow.Count() : offSecondRow.Count());
                foreach (CombatUnit unit in (offFirstRow.Count() > 0 ? offFirstRow : offSecondRow))
                {
                    int damageReceived = (unit.Toughness != 0 ? (int)Mathf.Ceil((float)damagePerUnit * (1.0f - (1.0f / (float)unit.Toughness))) : damagePerUnit);
                    unit.CurrentHealth -= Mathf.Max(damageReceived, 0);

                    if (unit.CurrentHealth <= 0)
                    {
                        HonorSystemBehavior.inCombat     = true;
                        HonorSystemBehavior.honorPenalty = unit.HonorMod;
                        HonorSystemBehavior.defensiveHonor++;
                    }
                }

                removeDeadUnits();
            }

            currentAttacker = CurrentAttacker.OffensiveBack;
        } break;

        case CurrentAttacker.OffensiveBack:
        {
            if (offSecondRow.Count() > 0)
            {
                int totalStrength = offSecondRow.Sum(l => l.Strength);

                int damagePerUnit = totalStrength / (defFirstRow.Count() > 0 ? defFirstRow.Count() : defSecondRow.Count());
                foreach (CombatUnit unit in (defFirstRow.Count() > 0 ? defFirstRow : defSecondRow))
                {
                    int damageReceived = (unit.Toughness != 0 ? (int)Mathf.Ceil((float)damagePerUnit * (1.0f - (1.0f / (float)unit.Toughness))) : damagePerUnit);
                    unit.CurrentHealth -= Mathf.Max(damageReceived, 0);
                    if (unit.CurrentHealth <= 0)
                    {
                        HonorSystemBehavior.inCombat     = true;
                        HonorSystemBehavior.honorPenalty = unit.HonorMod;
                        HonorSystemBehavior.offensiveHonor++;
                    }
                }

                removeDeadUnits();
            }

            currentAttacker = CurrentAttacker.DefensiveBack;
        } break;

        case CurrentAttacker.DefensiveBack:
        {
            if (defSecondRow.Count() > 0)
            {
                int totalStrength = defSecondRow.Sum(l => l.Strength);

                int damagePerUnit = totalStrength / (offFirstRow.Count() > 0 ? offFirstRow.Count() : offSecondRow.Count());
                foreach (CombatUnit unit in (offFirstRow.Count() > 0 ? offFirstRow : offSecondRow))
                {
                    int damageReceived = (unit.Toughness != 0 ? (int)Mathf.Ceil((float)damagePerUnit * (1.0f - (1.0f / (float)unit.Toughness))) : damagePerUnit);
                    unit.CurrentHealth -= Mathf.Max(damageReceived, 0);
                    if (unit.CurrentHealth <= 0)
                    {
                        HonorSystemBehavior.inCombat     = true;
                        HonorSystemBehavior.honorPenalty = unit.HonorMod;
                        HonorSystemBehavior.defensiveHonor++;
                    }
                }

                removeDeadUnits();
            }

            currentAttacker = CurrentAttacker.None;
        } break;

        case CurrentAttacker.None:
            endCombat(null);
            break;
        }
    }