Exemple #1
0
        public override int GetCreditWithPosition(Troop source, out Point?position)
        {
            //position = 0;
            position = new Point(0, 0);
            TroopList hostileTroopsInView = source.GetHostileTroopsInView();
            TroopList list2 = new TroopList();

            foreach (Troop troop in hostileTroopsInView)
            {
                if ((troop.IsInArchitecture || !troop.DaysToReachPosition(source.Position, 1)) || (troop.Army.Kind.Type == MilitaryType.水军))
                {
                    list2.Add(troop);
                }
            }
            foreach (Troop troop in list2)
            {
                hostileTroopsInView.Remove(troop);
            }
            if (hostileTroopsInView.Count == 0)
            {
                return(0);
            }
            List <Point> orientations = new List <Point>();
            int          num          = 0;

            foreach (Troop troop in hostileTroopsInView)
            {
                orientations.Add(troop.Position);
                num += troop.FightingForce;
            }
            int num2          = 0;
            int fightingForce = source.FightingForce;
            int num4          = source.TroopIntelligence + source.ChanceIncrementOfStratagem;

            if (num4 > 100)
            {
                num4 = 100;
            }
            num2 = (((GameObject.Square(num4) / 60) * num) / fightingForce) / 100;
            if (num2 > 0)
            {
                GameArea area = new GameArea();
                foreach (Point point in source.GetStratagemArea(source.Position).Area)
                {
                    if (!source.Scenario.PositionIsOnFire(point) && (source.Scenario.IsPositionEmpty(point) && source.Scenario.IsFireVaild(point, false, MilitaryType.步兵)))
                    {
                        area.Area.Add(point);
                    }
                }
                if (area.Count > 0)
                {
                    position = source.Scenario.GetClosestPosition(area, orientations);
                }
                else
                {
                    num2 = 0;
                }
            }
            return(num2);
        }
Exemple #2
0
    /// <summary>
    /// returns a new troopList of the combination of both troopLists
    /// </summary>
    /// <param name="theOtherContainerTroops"></param>
    /// <returns></returns>
    public TroopList GetCombinedTroops(TroopList theOtherContainerTroops)
    {
        TroopList returnedList = new TroopList();

        returnedList.AddRange(this);

        int             testedTroopIndex = -1;
        TroopNumberPair checkedTNP;

        foreach (TroopNumberPair tnp in theOtherContainerTroops)
        {
            testedTroopIndex = IndexOfTroopInThisList(tnp.troopTypeID);
            if (testedTroopIndex >= 0)
            {
                checkedTNP                     = returnedList[testedTroopIndex];
                checkedTNP.troopAmount        += tnp.troopAmount;
                returnedList[testedTroopIndex] = checkedTNP;
            }
            else
            {
                returnedList.Add(tnp);
            }
        }

        return(returnedList);
    }
Exemple #3
0
    public void OpenImportOps()
    {
        List <KeyValuePair <string, UnityAction> > importOptions =
            new List <KeyValuePair <string, UnityAction> >();

        GameInterface GI = GameInterface.instance;


        importOptions.Add(new KeyValuePair <string, UnityAction>("JSON Array - Don't use if attackers and defenders share troop types", () => {
            GI.textInputPanel.SetPanelInfo("JSON Text to Import", "insert the JSON string here", "", "Import", () => {
                SerializedTroop[] readTroops = JsonHandlingUtils.JsonToSerializedTroopArray
                                                   (GI.textInputPanel.theInputField.text);
                if (readTroops == null)
                {
                    ModalPanel.Instance().OkBox("Json Import Failed", "Please check your JSON string, it must be something like [{'name':'troop', 'amount':5}]");
                    return;
                }

                TroopList attackersRemaining = new TroopList(),
                defendersRemaining           = new TroopList();

                foreach (SerializedTroop tnp in readTroops)
                {
                    //Debug.Log("got this kvp: " + tnp.name + " : " + tnp.amount);

                    TroopNumberPair convertedTNP = JsonHandlingUtils.SerializedTroopToTroopNumberPair(tnp);
                    if (convertedTNP.troopAmount > 0)
                    {
                        if (battlePhase.battleData.defenderSideInfo.sideArmy.IndexOfTroopInThisList(convertedTNP.troopTypeID) != -1)
                        {
                            defendersRemaining.Add(convertedTNP);
                        }
                        else if (battlePhase.battleData.attackerSideInfo.sideArmy.IndexOfTroopInThisList(convertedTNP.troopTypeID) != -1)
                        {
                            attackersRemaining.Add(convertedTNP);
                        }
                    }
                }

                battlePhase.battleData.defenderSideInfo.SetPostBattleArmyData_RemainingArmy(defendersRemaining);
                battlePhase.battleData.attackerSideInfo.SetPostBattleArmyData_RemainingArmy(attackersRemaining);

                if (!battlePhase.battleData.BattleEndCheck())
                {
                    //we only need to update side info displays if the battle hasn't ended yet,
                    //because the delegate would take care of it otherwise
                    UpdateArmyDisplays();
                }

                GI.textInputPanel.Close();
            });
            GI.textInputPanel.Open();
            GI.exportOpsPanel.gameObject.SetActive(false);
        }));


        //when done preparing options, open the import ops panel
        GI.exportOpsPanel.Open("Remaining Armies: Import Options", importOptions);
    }
    /// <summary>
    /// returns a troopNumberPair list with entries using the provided amounts
    /// </summary>
    /// <returns></returns>
    public TroopList BakeIntoArmy()
    {
        TroopList returnedList = new TroopList();

        for (int i = 0; i < listContainer.childCount; i++)
        {
            Transform entry = listContainer.GetChild(i);
            BattleResolutionRemainingTroopListEntry entryScript =
                entry.GetComponent <BattleResolutionRemainingTroopListEntry>();
            if (entryScript)
            {
                returnedList.Add(entryScript.BakeIntoNewPair());
            }
        }

        return(returnedList);
    }
Exemple #5
0
        private PathResult conflictionPathSearcher_OnCheckPosition(Point position, List <Point> middlePath, MilitaryKind kind)
        {
            TroopList list  = new TroopList();
            TroopList list2 = new TroopList();

            foreach (Troop troop in this.troop.BelongedFaction.KnownTroops.Values)
            {
                if (!troop.IsFriendly(this.troop.BelongedFaction))
                {
                    switch (this.troop.HostileAction)
                    {
                    case HostileActionKind.EvadeEffect:
                        if (troop.OffenceArea.HasPoint(position))
                        {
                            list.Add(troop);
                        }
                        break;

                    case HostileActionKind.EvadeView:
                        if (troop.ViewArea.HasPoint(position))
                        {
                            list.Add(troop);
                        }
                        break;
                    }
                }
                else if (troop.Position == position)
                {
                    list2.Add(troop);
                }
            }
            if ((list.Count > 0) || (list2.Count > 0))
            {
                bool flag = false;
                foreach (Troop troop in list)
                {
                    switch (this.troop.HostileAction)
                    {
                    case HostileActionKind.NotCare:
                        Session.Current.Scenario.SetPenalizedMapDataByPosition(troop.Position, 0xdac);
                        break;

                    case HostileActionKind.Attack:
                        Session.Current.Scenario.SetPenalizedMapDataByPosition(troop.Position, 0xdac);
                        break;

                    case HostileActionKind.EvadeEffect:
                        Session.Current.Scenario.SetPenalizedMapDataByArea(troop.OffenceArea, 1);
                        break;

                    case HostileActionKind.EvadeView:
                        Session.Current.Scenario.SetPenalizedMapDataByArea(troop.ViewArea, 1);
                        break;
                    }
                }

                /*foreach (Troop troop in list2)
                 * {
                 *  switch (this.troop.FriendlyAction)
                 *  {
                 *  }
                 * }*/
                flag = this.ModifyFirstTierPath(this.troop.Position, this.troop.FirstTierDestination, middlePath, kind);
                foreach (Troop troop in list)
                {
                    switch (this.troop.HostileAction)
                    {
                    case HostileActionKind.NotCare:
                        Session.Current.Scenario.ClearPenalizedMapDataByPosition(troop.Position);
                        break;

                    case HostileActionKind.Attack:
                        Session.Current.Scenario.ClearPenalizedMapDataByPosition(troop.Position);
                        break;

                    case HostileActionKind.EvadeEffect:
                        Session.Current.Scenario.ClearPenalizedMapDataByArea(troop.OffenceArea);
                        break;

                    case HostileActionKind.EvadeView:
                        Session.Current.Scenario.ClearPenalizedMapDataByArea(troop.ViewArea);
                        break;
                    }
                }

                /*foreach (Troop troop in list2)
                 * {
                 *  switch (this.troop.FriendlyAction)
                 *  {
                 *  }
                 * }*/
                if (flag)
                {
                    return(PathResult.Found);
                }
                return(PathResult.NotFound);
            }
            return(PathResult.Aborted);
        }