コード例 #1
0
ファイル: Player.cs プロジェクト: Chupaflor/Cronkpit_Samples
        public void acquire_potion(Potion pt)
        {
            //search for a potion stack with a matching ID + fullness value and add to that stack.
            //If there isn't one, just add it to the inventory.
            bool stacked = false;

            for (int i = 0; i < inventory.Count; i++)
            {
                if (inventory[i] is Potion)
                {
                    Potion po = (Potion)inventory[i];
                    if (po.get_potion_code() == pt.get_potion_code() &&
                        po.is_potion_empty() == pt.is_potion_empty() &&
                        po.get_my_quantity() < 7)
                    {
                        po.adjust_quantity(pt.get_my_quantity());
                        stacked = true;
                    }
                }
            }

            if (!stacked)
            {
                int potion_type_id = -1;

                for (int i = 0; i < reserved_potion_ids.Count; i++)
                    if (reserved_potion_ids[i].Item1 == pt.get_potion_code())
                        potion_type_id = reserved_potion_ids[i].Item2;

                pt.set_ID_number(potion_type_id);

                inventory.Add(pt);
            }
        }