示例#1
0
        internal void DisperseSeeds()
        {
            if (!m_nview ||
                !m_nview.IsOwner() ||
                !m_nview.IsValid() ||
                Player.m_localPlayer == null)
            {
                return;
            }

            bool dispersed   = false;
            int  totalPlaced = 0;
            int  maxRetries  = configMaxRetries.Value;

            while (GetQueueSize() > 0)
            {
                string currentSeed  = GetQueuedSeed();
                int    currentCount = GetQueuedSeedCount();
                if (!seedPrefabMap.ContainsKey(currentSeed))
                {
                    logger.LogWarning("Key '" + currentSeed + "' not found in seedPrefabMap");
                    DumpQueueDetails();
                    logger.LogWarning("Shifting queue to remove invalid entry");
                    ShiftQueueDown();
                    return;
                }

                ItemConversion  conversion = seedPrefabMap[currentSeed];
                PlacementStatus status     = TryPlacePlant(conversion, maxRetries);
                SetStatus(status);
                if (status == PlacementStatus.Planting)
                {
                    totalPlaced += 1;
                    dispersed    = true;
                }
                else if (status == PlacementStatus.WrongBiome)
                {
                    logger.LogDebug("Wrong biome deteced, moving " + currentSeed + " to end of queue");

                    MoveToEndOfQueue(currentSeed, currentCount, status);
                    break;
                }
                else if (status == PlacementStatus.NoRoom)
                {
                    break;
                }
                if (totalPlaced >= configDispersionCount.Value)
                {
                    break;
                }
            }
            ;

            if (dispersed)
            {
                m_disperseEffects.Create(transform.position, Quaternion.Euler(0f, Random.Range(0, 360), 0f), transform, configRadius.Value / 5f);
            }
        }
示例#2
0
        private void UpdateHoverText()
        {
            StringBuilder sb = new StringBuilder(GetHoverName() + " (" + GetTotalSeedCount() + ")\n");

            string restrict       = GetRestrict();
            string seedName       = messageSeedGenericSingular;
            string seedNamePlural = messageSeedGenericPlural;

            if (restrict != "")
            {
                seedName       = restrict;
                seedNamePlural = restrict;
            }

            if (restrict != "")
            {
                sb.Append("<color=grey>$message_seed_totem_restricted_to</color> <color=green>" + restrict + "</color>\n");
            }

            sb.Append("[<color=yellow><b>$KEY_Use</b></color>] $piece_smelter_add " + seedName + "\n");
            sb.Append("[Hold <color=yellow><b>$KEY_Use</b></color>] $piece_smelter_add " + messageAll + " " + seedNamePlural + "\n");
            sb.Append("[<color=yellow><b>1-8</b></color>] $message_seed_totem_restrict");

            if (configShowQueue.Value)
            {
                sb.Append("\n\n");
                for (int queuePosition = 0; queuePosition < GetQueueSize(); queuePosition++)
                {
                    string          queuedSeed   = GetQueuedSeed(queuePosition);
                    int             queuedAmount = GetQueuedSeedCount(queuePosition);
                    PlacementStatus status       = GetQueuedStatus(queuePosition);

                    sb.Append(queuedAmount + " " + queuedSeed);
                    switch (status)
                    {
                    case PlacementStatus.Init:
                        //Show nothing for new seeds
                        break;

                    case PlacementStatus.NoRoom:
                        sb.Append(" <color=grey>[</color><color=green>$message_seed_totem_status_looking_for_space</color><color=grey>]</color>");
                        break;

                    case PlacementStatus.Planting:
                        sb.Append(" <color=grey>[</color><color=green>$message_seed_totem_status_planting</color><color=grey>]</color>");
                        break;

                    case PlacementStatus.WrongBiome:
                        sb.Append(" <color=grey>[</color><color=red>$message_seed_totem_status_wrong_biome</color><color=grey>]</color>");
                        break;
                    }
                    sb.Append("\n");
                }
            }

            m_hoverText = sb.ToString();
        }
示例#3
0
        private void MoveToEndOfQueue(string currentSeed, int currentCount, PlacementStatus status)
        {
            logger.LogDebug("Moving " + currentSeed + " to end of queue");
            DumpQueueDetails();

            ShiftQueueDown();
            QueueSeed(currentSeed, currentCount, status);

            logger.LogDebug("After move");
            DumpQueueDetails();
        }
示例#4
0
        private PlacementStatus TryPlacePlant(ItemConversion conversion, int maxRetries)
        {
            int             tried  = 0;
            PlacementStatus result = PlacementStatus.Planting;

            do
            {
                tried++;
                Vector3 position     = transform.position + Vector3.up + Random.onUnitSphere * configRadius.Value;
                float   groundHeight = ZoneSystem.instance.GetGroundHeight(position);
                position.y = groundHeight;

                if (conversion.plant.m_biome != 0 && configCheckBiome.Value && !IsCorrectBiome(position, conversion.plant.m_biome))
                {
                    result = PlacementStatus.WrongBiome;
                    continue;
                }

                if (conversion.plant.m_needCultivatedGround && configCheckCultivated.Value && !IsCultivated(position))
                {
                    result = PlacementStatus.NoRoom;
                    continue;
                }

                if (!HasGrowSpace(position, conversion.plant.m_growRadius))
                {
                    result = PlacementStatus.NoRoom;
                    continue;
                }

                logger.LogDebug("Placing new plant " + conversion.plantPiece + " at " + position);

                Quaternion rotation    = Quaternion.Euler(0f, Random.Range(0, 360), 0f);
                GameObject placedPlant = Instantiate(conversion.plantPiece.gameObject, position, rotation);
                if (placedPlant)
                {
                    result = PlacementStatus.Planting;
                    conversion.plantPiece.m_placeEffect.Create(position, rotation, placedPlant.transform);
                    RemoveOneSeed();
                    break;
                }
                else
                {
                    logger.LogWarning("No object returned?");
                }
                break;
            } while (tried <= maxRetries);

            logger.LogDebug("Max retries reached, result " + result);

            return(result);
        }
示例#5
0
        private void DumpQueueDetails()
        {
            StringBuilder builder = new StringBuilder("QueueDetails:");

            for (int queuePosition = 0; queuePosition < GetQueueSize(); queuePosition++)
            {
                string          queuedSeed   = GetQueuedSeed(queuePosition);
                int             queuedAmount = GetQueuedSeedCount(queuePosition);
                PlacementStatus queuedStatus = GetQueuedStatus(queuePosition);
                builder.AppendLine("Position " + queuePosition + " -> " + queuedSeed + " -> " + queuedAmount + " -> " + queuedStatus);
            }

            logger.LogWarning(builder.ToString());
        }
示例#6
0
        private void QueueSeed(string name, int amount = 1, PlacementStatus status = PlacementStatus.Init)
        {
            int    queueSize     = GetQueueSize();
            string currentQueued = GetQueuedSeed(queueSize - 1);

            if (currentQueued == name)
            {
                SetQueueSeedCount(queueSize - 1, GetQueuedSeedCount(queueSize - 1) + amount);
            }
            else
            {
                m_nview.GetZDO().Set("item" + queueSize, name);
                m_nview.GetZDO().Set("item" + queueSize + "count", amount);
                m_nview.GetZDO().Set("item" + queueSize + "status", (int)status);
                m_nview.GetZDO().Set(ZDO_queued, queueSize + 1);
            }

            m_nview.GetZDO().Set(ZDO_total, m_nview.GetZDO().GetInt(ZDO_total) + amount);
        }
示例#7
0
 private void SetStatus(PlacementStatus status)
 {
     m_nview.GetZDO().Set("item0status", (int)status);
 }