Exemplo n.º 1
0
        /*
         * public bool AttemptGiveItem(ItemBase item, int amount) {
         *  foreach (MassCrateModule mcm in modules) {
         *      VicisMod.log(LOGGER_PREFIX, "Attempting to give " + item.GetDisplayString() + " to a module");
         *      if (mcm.AttemptGiveItem(item, amount)) return true;
         *      VicisMod.log(LOGGER_PREFIX, "Failed, will attempt again");
         *  }
         *  VicisMod.log(LOGGER_PREFIX, "Could not give item " + item.GetDisplayString());
         *  return false;
         * }
         *
         * public ItemBase AttemptTakeItem(ItemBase item) {
         *  foreach (MassCrateModule mcm in modules) {
         *      VicisMod.log(LOGGER_PREFIX, "Attempting to take " + item.GetDisplayString() + " to a module");
         *      ItemBase ret = mcm.AttemptTakeItem(item);
         *      if (ret != null) return ret;
         *
         *      VicisMod.log(LOGGER_PREFIX, "Failed, will attempt again");
         *  }
         *  VicisMod.log(LOGGER_PREFIX, "Could not give take " + item.GetDisplayString());
         *  return null;
         * }
         */

        public MassCrateModule provideCrateDropoff(ItemBase item, MassTaker taker, int amount)
        {
            float           dist                 = float.MaxValue;
            MassCrateModule ret                  = null;
            bool            itemIsClaimed        = false;
            bool            claimedCrateAccepted = false;

            for (int i = 0; i < modules.Count; ++i)  // (MassCrateModule mcm in modules) {
            {
                if (modules[i].shouldSkip())
                {
                    continue;
                }
                MassCrateModule mcm = modules[i];
                bool            thisCrateClaimed = mcm.HasClaimed(item);
                if (thisCrateClaimed && !itemIsClaimed)
                {
                    dist          = float.MaxValue;
                    ret           = null;
                    itemIsClaimed = true;
                }
                itemIsClaimed |= thisCrateClaimed;
                if (mcm.AttemptGiveItem(item, amount, false))
                {
                    // Check if this crate has claimed this item. If so, need to disregard other successful searches
                    if (mcm.HasClaimed(item) && !claimedCrateAccepted)
                    {
                        claimedCrateAccepted = true;
                        dist = calcDist(mcm, taker);
                        ret  = mcm;
                        continue;
                    }

                    // If this item has been claimed by at least 1 crate, skip the rest of the searches.
                    if (!thisCrateClaimed && itemIsClaimed)
                    {
                        continue;
                    }

                    float tdist = calcDist(mcm, taker);
                    if (tdist < dist)
                    {
                        ret  = mcm;
                        dist = tdist;
                    }
                }
            }
            return(ret);
        }
Exemplo n.º 2
0
        public MassCrateModule provideCrateDropoff(ItemBase item, MassTaker taker, int amount)
        {
            float           dist = 99999999999;
            MassCrateModule ret  = null;

            foreach (MassCrateModule mcm in modules)
            {
                if (mcm.AttemptGiveItem(item, amount, false))
                {
                    float tdist = calcDist(mcm, taker);
                    if (tdist < dist)
                    {
                        ret  = mcm;
                        dist = tdist;
                    }
                }
            }
            return(ret);
        }