Ejemplo n.º 1
0
    public void PutItem(SpiceName name, int value)
    {
        if (items.TryGetValue(name, out int v))
        {
            items.Remove(name);
            items.Add(name, value + v);
        }
        else
        {
            items.Add(name, value);
        }

        value++;
        caravanText      = GameObject.FindGameObjectWithTag(SpiceNames.ToString(name) + "_c").GetComponent <Text>();
        caravanText.text = "" + value;
    }
Ejemplo n.º 2
0
    //For "CarToInventory"
    private List <KeyValuePair <string, object> > ApplyStateChange(List <KeyValuePair <string, object> > state, KeyValuePair <string, object> goal, GoapAction action)
    {
        List <KeyValuePair <string, object> > currentState = new List <KeyValuePair <string, object> >();

        foreach (KeyValuePair <string, object> s in state)
        {
            currentState.Add(new KeyValuePair <string, object>(s.Key, s.Value));
        }

        KeyValuePair <string, object> inState, caState, capa;

        foreach (KeyValuePair <string, object> s in state)
        {
            if (s.Key.Contains("Ca"))
            {
                if ((int)s.Value > 6)
                {
                    caState = s;
                    break;
                }
            }
        }
        inState = state.Find(e => e.Key.Equals("In" + caState.Key.Substring(2)));
        capa    = state.Find(e => e.Key.Equals("Capacity"));

        //if ((int)inState.Value > 4) {
        int caValue   = (int)caState.Value;
        int capacity  = (int)capa.Value;
        int takeValue = 4;     //inValue <= capacity ? inValue : capacity;

        KeyValuePair <string, object> updatedG = new KeyValuePair <string, object>(caState.Key, caValue - takeValue);
        KeyValuePair <string, object> updatedI = new KeyValuePair <string, object>(inState.Key, 4); //inValue - takeValue);
        KeyValuePair <string, object> updatedC = new KeyValuePair <string, object>("Capacity", 0);  //capacity - takeValue);

        currentState.Remove(caState);
        currentState.Remove(inState);
        currentState.Remove(capa);

        currentState.Add(updatedG);
        currentState.Add(updatedI);
        currentState.Add(updatedC);

        action.takeout.Add(new KeyValuePair <SpiceName, int>(SpiceNames.Get(inState.Key.Substring(2)), takeValue));
        //}

        return(currentState);
    }
Ejemplo n.º 3
0
    public void RemoveItemByOne(SpiceName name)
    {
        int value = 0;

        if (items.TryGetValue(name, out value))
        {
            if (value != 0)
            {
                value--;
                items.Remove(name);
                items.Add(name, value);

                caravanText      = GameObject.FindGameObjectWithTag(SpiceNames.ToString(name) + "_c").GetComponent <Text>();
                caravanText.text = string.Format("{0}", value);
            }
        }
    }
Ejemplo n.º 4
0
    public void PutItem(SpiceName name)
    {
        int value = 0;

        if (capacity >= 0)
        {
            if (items.TryGetValue(name, out value))
            {
                items.Remove(name);
                items.Add(name, value + 1);
            }
            else
            {
                items.Add(name, 1);
            }

            value++;
            inventoryText      = GameObject.FindGameObjectWithTag(SpiceNames.ToString(name)).GetComponent <Text>();
            inventoryText.text = "" + value;
            capacity--;
        }
    }
Ejemplo n.º 5
0
    public bool RemoveItemByQuanlity(SpiceName name, int quanlity)
    {
        int value = 0;

        if (capacity >= 0)
        {
            if (items.TryGetValue(name, out value))
            {
                if (value != 0 && value >= quanlity)
                {
                    value -= quanlity;
                    items.Remove(name);
                    items.Add(name, value);

                    capacity          += quanlity;
                    inventoryText      = GameObject.FindGameObjectWithTag(SpiceNames.ToString(name)).GetComponent <Text>();
                    inventoryText.text = string.Format("{0}", value);
                    return(true);
                }
            }
        }
        return(false);
    }