コード例 #1
0
    public static void ExecuteOptions(Unit[] units, UnitOption option, UnitOptionParams[] param)
    {
        if (units == null || units.Length == 0)
        {
            return;
        }
        if (param != null && param.Length != units.Length)
        {
            Debug.LogError("Not enough parameters for the number of units supplied! (Total {0} units, {1} params). Pass a null array to not execute without options.".Form(units.Length, param.Length));
            return;
        }

        for (int i = 0; i < units.Length; i++)
        {
            var unit = units[i];
            if (units != null)
            {
                UnitOptionParams p = null;
                if (param != null)
                {
                    p = param[i];
                }
                ExecuteOption(unit, option, p);
            }
        }
    }
コード例 #2
0
    public void RequestOptionExecution(Unit[] units, UnitOption option, UnitOptionParams param)
    {
        if (isServer)
        {
            RequestOption_Server(units, option, param);
        }
        else
        {
            // Make game object array from unit array.
            // Validate units at the same time.
            GameObject[] gos = new GameObject[units.Length];
            for (int i = 0; i < units.Length; i++)
            {
                var unit = units[i];
                if (unit != null)
                {
                    if (unit.Faction == Player.Faction)
                    {
                        gos[i] = unit.gameObject;
                    }
                }
            }

            string json = param == null ? null : param.ToJson();

            // Send command request to the server.
            CmdRequestExec(gos, option, json);
        }
    }
コード例 #3
0
            private static List <UnitOption> Evaluate(List <UnitData> options)
            {
                List <UnitOption> list = new List <UnitOption>();

                //Debug.Log("AI Draw Card");
                foreach (UnitData op in options)
                {
                    //Debug.Log("Option [" + op.UnitName + "]");

                    UnitOption option = new UnitOption(op);

                    float score = AIRule.EvaluateUnitData.Evaulate(op);
                    option.score += score;
                    //Debug.Log("\t Unit Evaulate Score: [" + score + "]");

                    score         = AIRule.EvaluateDuplicateInHand.Evaulate(op);
                    option.score += score;
                    //Debug.Log("\t Duplicate Card in Hand Evaulate Score: [" + score + "]");

                    //Debug.Log("Total: " + option.score);

                    list.Add(option);
                }

                return(list);
            }
コード例 #4
0
            public static UnitData Think(List <UnitData> units)
            {
                List <UnitOption> options = Evaluate(units);

                UnitOption op = Common.RandomOptionOfBest <UnitOption>(options);

                return(op.data);
            }
コード例 #5
0
    private void RequestOption_Server(Unit[] units, UnitOption option, UnitOptionParams param)
    {
        if (units == null || units.Length == 0)
        {
            return;
        }

        // No need for validation, server side and already done.
        Unit.ExecuteOptions(units, option, param);
    }
コード例 #6
0
    public static void ExecuteOption(Unit unit, UnitOption option, UnitOptionParams param)
    {
        if (unit == null)
        {
            return;
        }

        unit.ExecOption(new OptionAndParams()
        {
            Option = option, Params = param
        });
    }
コード例 #7
0
            private static List <UnitOption> EvaluateSummon(List <Unit> cards)
            {
                List <UnitOption> list = new List <UnitOption>();

                //check position
                FieldBlock emptyfront = AIView.Instance.EmptyFront;
                FieldBlock emptyback  = AIView.Instance.EmptyBack;

                if (emptyfront == null && emptyback == null)
                {
                    return(list);//no position to summon
                }
                for (int i = cards.Count - 1; i >= 0; i--)
                {
                    UnitData data = cards[i].m_Data;

                    //check mana
                    int mana = AIView.Instance.Mana;
                    if (data.GetStat(UnitStatsProperty.Cost) > mana)
                    {
                        continue;
                    }

                    //check position
                    bool canbefront = emptyfront != null && data.CanBeFrontline;
                    bool canbeback  = emptyback != null && data.CanBeBackline;
                    if (!canbefront && !canbeback)
                    {
                        continue;
                    }

                    //check unique
                    if (data.IsUnique && AIView.Instance.AI.m_UnitsOnBoard.SameUnitExist(data))
                    {
                        continue;
                    }

                    //evaluate
                    //Debug.Log("Summon Option [" + data.UnitName + "]");

                    UnitOption option = new UnitOption(data);

                    float score = AIRule.EvaluateUnitData.Evaulate(data);
                    option.score += score;
                    //Debug.Log("\t Unit Evaulate Score: [" + score + "]");

                    //Debug.Log("Total: " + option.score);

                    list.Add(option);
                }

                return(list);
            }
コード例 #8
0
 public static List <UnitOptionInput> GetInputs(this UnitOption option)
 {
     if (UnitOptionGO.Instance == null)
     {
         return(null);
     }
     else
     {
         var op = UnitOptionGO.Instance.Data[option];
         return(op == null ? null : op.Inputs);
     }
 }
コード例 #9
0
 public static Sprite GetIcon(this UnitOption option)
 {
     if (UnitOptionGO.Instance == null)
     {
         return(null);
     }
     else
     {
         var op = UnitOptionGO.Instance.Data[option];
         return(op == null ? null : op.Icon);
     }
 }
コード例 #10
0
 public static KeyCode GetInputKey(this UnitOption option, int index)
 {
     if (UnitOptionGO.Instance == null)
     {
         return(KeyCode.None);
     }
     else
     {
         var op = UnitOptionGO.Instance.Data[option];
         return(op == null ? KeyCode.None : op.DefaultKey);
     }
 }
コード例 #11
0
 public static string GetString(this UnitOption option)
 {
     if (UnitOptionGO.Instance == null)
     {
         return("<ERROR>");
     }
     else
     {
         var op = UnitOptionGO.Instance.Data[option];
         return(op == null ? "<mssing_name>" : op.Name);
     }
 }
コード例 #12
0
        public void Add(UnitConversion unit)
        {
            var uOp = new UnitOption(unit);

            uOp.MenuItem.AssociatedChannelOption = uOp;
            uOp.MenuItem.Click += MenuItem_Click;
            menuItem.SubOptions.Add(uOp);
            Items.Add(unit);
            if (Items.Count == 1)
            {
                Current = unit;
            }
        }
コード例 #13
0
    public static void ExecuteOptions(Unit[] units, UnitOption option, UnitOptionParams param)
    {
        if (units == null || units.Length == 0)
        {
            return;
        }

        foreach (var unit in units)
        {
            if (unit != null)
            {
                ExecuteOption(unit, option, param);
            }
        }
    }
コード例 #14
0
    private void CmdRequestExecUniqueParams(GameObject[] gos, UnitOption option, string[] param)
    {
        if (gos == null || gos.Length == 0)
        {
            return;
        }

        // Turn gameobjects into units.
        // Validate units too.
        Unit[] units = new Unit[gos.Length];
        for (int i = 0; i < gos.Length; i++)
        {
            var go = gos[i];

            if (go != null)
            {
                var unit = go.GetComponent <Unit>();
                if (unit != null)
                {
                    if (unit.Faction == Player.Faction)
                    {
                        units[i] = unit;
                    }
                }
            }
        }

        // Make the params object from the json. Works even if the json is null or blank.
        // May return null, which is fine.
        UnitOptionParams[] p = null;
        if (param != null)
        {
            p = new UnitOptionParams[param.Length];
            for (int i = 0; i < param.Length; i++)
            {
                Debug.Log("Received {0}".Form(param[i]));
                p[i] = UnitOptionParams.TryDeserialize(param[i]);
            }
        }

        // Run the server version.
        RequestOption_Server(units, option, p);
    }
コード例 #15
0
    public void Selected(UI_UnitOptionItem item)
    {
        if (item == null)
        {
            return;
        }
        if (GatheringInput)
        {
            Debug.LogWarning("Cannot select a new option while already gathering information for the last one. Gathered {0}/{1}".Form(gathered, totalToGather));
            return;
        }

        if (Player.Local != null)
        {
            var inputs = item.Option.GetInputs();
            if (inputs != null && inputs.Count != 0)
            {
                GatheringInput = true;
                totalToGather  = inputs.Count;
                gathered       = 0;
                workingIndex   = 0;
                option         = item.Option;

                this.inputs = inputs;

                var first = inputs[0];
                RunInputCollection(first);
            }
            else
            {
                // Possibly get unit generated params?
                var array = Unit.CurrentlySelected.ToArray();
                Player.Local.UnitOptionExecution.RequestOptionExecution(array, item.Option, null);
            }
        }
    }