Example #1
0
    public PlayerAction GetAction(string line)
    {
        PlayerAction.Type[] actionTypes = System.Enum.GetValues(typeof(PlayerAction.Type)) as PlayerAction.Type[];

        // check parameters
        bool   hasParameters = line.Contains("(");
        string function_str  = line;

        if (hasParameters)
        {
            function_str = line.Remove(line.IndexOf('('));
        }

        // get action type
        PlayerAction.Type actionType = System.Array.Find(actionTypes, x => function_str.ToLower() == x.ToString().ToLower());

        if (actionType == PlayerAction.Type.None)
        {
            Debug.LogError("Couldn't find action type : " + function_str);
            return(null);
        }

        // create action
        PlayerAction newAction = new PlayerAction();

        newAction.type = actionType;

        // check parameters
        if (hasParameters)
        {
            string parameters_str = line.Remove(0, actionType.ToString().Length);

            // remove parentheses
            parameters_str = parameters_str.Remove(0, 1);
            parameters_str = parameters_str.Remove(parameters_str.Length - 1);

            string[] stringSeparators = new string[] { ", " };
            string[] args             = parameters_str.Split(stringSeparators, StringSplitOptions.None);

            foreach (var arg in args)
            {
                int i = 0;

                newAction.AddContent(arg);

                /*if (int.TryParse(arg, out i))
                 * {
                 *  newAction.values.Add(i);
                 * }
                 * else
                 * {
                 *  newAction.contents.Add(arg);
                 * }*/
            }
        }

        return(newAction);
    }
Example #2
0
 /// AI attempts to use an item; if an item should be used, wantsToUseItemAI is set to true.
 private void useItemAttemptAI()
 {
     if (UnityEngine.Random.value > 0.75 && playerBelongings[activePlayer].hasAnItem())
     {
         PlayerAction.Type useItemAction = itemDB.getItem(playerBelongings[activePlayer].getFirstItem()).associatedAction;
         if (interactions.canUse(useItemAction))
         {
             wantsToUseItemAI = true;
         }
     }
     else
     {
         wantsToUseItemAI = false;
     }
 }
Example #3
0
 /// whether the given action can be used right now
 public bool canUse(PlayerAction.Type action)
 {
     for (int i = 0; i < actions.Length; i++)
     {
         if (actions[i].type == action)
         {
             if (action == PlayerAction.Type.SET_TRAP)
             {
                 return(isActive(i) && canAfford(actions[i]) && isValidTile());
             }
             else
             {
                 return(isActive(i) && canAfford(actions[i]));
             }
         }
     }
     return(false);
 }
Example #4
0
    private void executeActionAI(PlayerAction.Type action)
    {
        if (!interactions.anActionIsSelected())
        {
            return;
        }

        if (interactions.getSelectedAction().type == action)
        {
            // buy the golden brick
            executeAction(interactions.getSelectedAction());
            wantsToUseItemAI = false;
        }
        else
        {
            // wrong action is selected, next action
            interactions.nextAction();
        }
    }
Example #5
0
 /// AI uses an item
 private void useItemAI()
 {
     PlayerAction.Type useItemAction = itemDB.getItem(playerBelongings[activePlayer].getFirstItem()).associatedAction;
     // use an item
     executeActionAI(useItemAction);
 }