コード例 #1
0
ファイル: WorldMap.cs プロジェクト: yazici/FRONTIERS
        //searches chunks and loads location data into the locationData list
        //only searches for locations added using the SetMapData function
        public IEnumerator LocationsForChunks(string chunkName, int chunkID, Queue <WorldMapLocation> locationData, List <MapMarker> activeMapMarkers)
        {               //Debug.Log ("WorldMap: LocationsForChunks");
            List <MobileReference> locationList = null;

            if (!mRevealableToShow.TryGetValue(chunkName, out locationList))
            {
                //Debug.Log ("WorldMap: We have no locations for this chunk from SetMapData, returning immediately");
                yield break;
            }
            Vector3 chunkPosition;

            //add markers
            for (int i = 0; i < activeMapMarkers.Count; i++)
            {
                if (activeMapMarkers [i].ChunkID == chunkID)
                {
                    chunkPosition = activeMapMarkers [i].ChunkPosition;
                    WorldMapLocation wml = new WorldMapLocation(
                        null,
                        1,
                        "Marker",
                        string.Empty,
                        string.Empty,
                        true,
                        false,
                        "MapIconMapMarker",
                        Color.white,
                        MapIconStyle.Medium,
                        MapLabelStyle.None,
                        Vector3.zero,
                        chunkPosition,
                        false,
                        false,
                        LocationTypesToDisplay);
                    locationData.Enqueue(wml);
                }
            }

            MobileReference currentLocation = null;

            for (int i = 0; i < locationList.Count; i++)
            {
                if (!LoadData)
                {
                    //Debug.Log ("WorldMap: Load data is false, returning");
                    yield break;
                }
                currentLocation = locationList [i];
                StackItem stackItem = null;
                if (WIGroups.LoadStackItem(currentLocation, out stackItem))
                {
                    chunkPosition = stackItem.ChunkPosition;
                    //Debug.Log ("WorldMap: found stack item " + stackItem.DisplayName);
                    //next we need to get the location state from the stack item
                    LocationState   ls            = null;
                    RevealableState rs            = null;
                    VisitableState  vs            = null;
                    bool            isNewLocation = false;
                    bool            isMarked      = false;
                    if (NewLocations.Count > 0)
                    {
                        for (int j = NewLocations.LastIndex(); j >= 0; j--)
                        {
                            if (NewLocations [j] == currentLocation)
                            {
                                NewLocations.RemoveAt(j);
                                isNewLocation = true;
                                break;
                            }
                        }
                    }
                    //Debug.Log ("current location " + currentLocation.FullPath + " is marked? " + isMarked.ToString ( ));
                    isMarked = MarkedLocations.Contains(currentLocation);

                    if (stackItem.GetStateData <RevealableState> (out rs))
                    {
                        stackItem.GetStateData <LocationState> (out ls);
                        stackItem.GetStateData <VisitableState> (out vs);
                        //now convert it into a world map location
                        WorldMapLocation wml = null;
                        if (rs.CustomMapSettings || ls == null)
                        {
                            //non-custom settings come from the location
                            //so we can only use custom settings if ls is not null
                            //Debug.Log ("Custom settings for revealable with " + rs.IconName + " icon name");
                            wml = new WorldMapLocation(
                                currentLocation,
                                stackItem.Props.Local.ActiveRadius,
                                ls != null ? ls.Name.CommonName : string.Empty,
                                ls != null ? ls.Name.ProperName : string.Empty,
                                ls != null ? ls.Name.NickName : string.Empty,
                                vs != null ? vs.HasBeenVisited : true,
                                rs.MarkedForTriangulation,
                                rs.IconName,
                                rs.IconColor,
                                rs.IconStyle,
                                rs.LabelStyle,
                                rs.IconOffset,
                                chunkPosition,
                                isNewLocation,
                                isMarked,
                                LocationTypesToDisplay);
                            locationData.Enqueue(wml);
                        }
                        else
                        {
                            string        iconName   = "Outpost";
                            MapIconStyle  iconStyle  = MapIconStyle.None;
                            MapLabelStyle labelStyle = MapLabelStyle.None;
                            Color32       iconColor  = Color.gray;
                            Vector3       iconOffset = Vector3.zero;

                            GetIconProperties(stackItem, ls, rs, vs, ref iconName, ref iconStyle, ref labelStyle, ref iconColor, ref iconOffset);

                            wml = new WorldMapLocation(
                                currentLocation,
                                stackItem.Props.Local.ActiveRadius,
                                ls != null ? ls.Name.CommonName : string.Empty,
                                ls != null ? ls.Name.ProperName : string.Empty,
                                ls != null ? ls.Name.NickName : string.Empty,
                                vs != null ? vs.HasBeenVisited : true,
                                rs.MarkedForTriangulation,
                                iconName,
                                iconColor,
                                iconStyle,
                                labelStyle,
                                iconOffset,
                                chunkPosition,
                                isNewLocation,
                                isMarked,
                                LocationTypesToDisplay);
                            locationData.Enqueue(wml);
                        }
                    }
                    else
                    {
                        //Debug.Log ("Didn't get revealable state data in " + currentLocation.FileName);
                    }
                }
                else
                {
                    //Debug.Log ("Didin't get stack item for location " + currentLocation.FullPath);
                }
                //clear the stack item, we don't need it any more
                if (stackItem != null)
                {
                    stackItem.Clear();
                }
                yield return(null);
            }
            locationList.Clear();
            yield break;
        }
コード例 #2
0
        IEnumerator FillContainerOverTime(bool immediately)
        {
            if (!immediately)
            {
                yield return(null);               //wait for a tick to let recepticles etc. update properties
            }

            State.LastFillTime = WorldClock.AdjustedRealTime;
            //fill container
            WIStackError     error                   = WIStackError.None;
            WIStackContainer container               = worlditem.StackContainer;
            int              numDesired              = State.NumberOfItems;
            int              numAdded                = 0;
            int              lastItemIndex           = 0;
            int              maxDuplicates           = 3;
            bool             continueFilling         = true;
            int              hashCode                = Mathf.Abs((worlditem.Group.Props.UniqueID + worlditem.FileName).GetHashCode());
            int              numDuplicates           = 0;
            bool             belowDuplicateThreshold = true;
            GenericWorldItem genericItem             = null;
            WICategory       category                = null;

            IBank bank = null;

            if (State.FillBank)
            {
                Character character = null;
                if (worlditem.Is <Character> (out character) && character.HasBank)
                {
                    bank = character.InventoryBank;
                    Bank.FillWithRandomCurrency(bank, character.State.Flags.Wealth);
                }
            }

            switch (State.NumberOfItemsRandomness)
            {
            case ContainerFillRandomness.Slight:
            default:
                numDesired = Mathf.Max(1, numDesired + UnityEngine.Random.Range(-1, 1));
                break;

            case ContainerFillRandomness.Moderate:
                numDesired = Mathf.Max(1, numDesired + UnityEngine.Random.Range(-5, 5));
                break;

            case ContainerFillRandomness.Extreme:
                numDesired = Mathf.Max(1, numDesired + UnityEngine.Random.Range(-10, 10));
                break;
            }

            yield return(null);

            switch (State.FillMethod)
            {
            case ContainerFillMethod.AllRandomItemsFromCategory:
            default:
                if (WorldItems.Get.Category(State.WICategoryName, out category))
                {
                    Dictionary <string, int> itemsSoFar = new Dictionary <string, int> ();
                    if (category.HasMinInstanceItems)
                    {
                        gMinInstanceItems.Clear();
                        category.GetMinInstanceItems(gMinInstanceItems);
                        for (int i = 0; i < gMinInstanceItems.Count; i++)
                        {
                            if (itemsSoFar.TryGetValue(gMinInstanceItems [i].PrefabName, out numDuplicates))
                            {
                                numDuplicates++;
                                itemsSoFar [gMinInstanceItems [i].PrefabName] = numDuplicates;
                            }
                            else
                            {
                                itemsSoFar.Add(gMinInstanceItems [i].PrefabName, 1);
                            }

                            StackItem item = gMinInstanceItems [i].ToStackItem();

                            if (item != null)
                            {
                                if (State.AddCurrencyToBank && bank != null && item.Is("Currency"))
                                {
                                    bank.Add(Mathf.FloorToInt(item.BaseCurrencyValue), item.CurrencyType);
                                    item.Clear();
                                }
                                else
                                {
                                    //add the generic item to the container as a stack item
                                    if (!Stacks.Add.Items(item, container, ref error))
                                    {
                                        continueFilling = false;
                                    }
                                    else
                                    {
                                        numAdded++;
                                    }
                                }
                            }
                        }
                        gMinInstanceItems.Clear();
                    }

                    yield return(null);

                    while (continueFilling && category.GetItem(State.Flags, hashCode, ref lastItemIndex, out genericItem))
                    {
                        //make sure we don't have a duplicate
                        if (itemsSoFar.TryGetValue(genericItem.PrefabName, out numDuplicates))
                        {
                            numDuplicates++;
                            if (numDuplicates < maxDuplicates)
                            {
                                itemsSoFar [genericItem.PrefabName] = numDuplicates;
                            }
                            else
                            {
                                belowDuplicateThreshold = false;
                            }
                        }
                        else
                        {
                            itemsSoFar.Add(genericItem.PrefabName, 1);
                        }

                        yield return(null);

                        if (belowDuplicateThreshold)
                        {
                            //this might be a currency item - if it is, add it to the bank
                            StackItem item = genericItem.ToStackItem();

                            if (State.AddCurrencyToBank && bank != null && item.Is("Currency"))
                            {
                                bank.Add(Mathf.FloorToInt(item.BaseCurrencyValue), item.CurrencyType);
                                item.Clear();
                            }
                            else
                            {
                                //add the generic item to the container as a stack item
                                if (!Stacks.Add.Items(item, container, ref error))
                                {
                                    continueFilling = false;
                                }
                                else
                                {
                                    numAdded++;
                                }
                            }
                        }

                        //are we done yet?
                        if (numAdded >= numDesired || container.IsFull || !belowDuplicateThreshold)
                        {
                            continueFilling = false;
                        }
                        //wait a tick unless we need to finish this immediately
                        //if (!immediately) {
                        yield return(null);
                        //}
                    }
                }
                break;

            case ContainerFillMethod.OneRandomItemFromCategory:
                if (WorldItems.Get.Category(State.WICategoryName, out category))
                {
                    if (category.GetItem(State.Flags, hashCode, ref lastItemIndex, out genericItem))
                    {
                        for (int i = 0; i < numDesired; i++)
                        {
                            if (!Stacks.Add.Items(genericItem.ToStackItem(), container, ref error))
                            {
                                break;
                            }
                            else
                            {
                                numAdded++;
                            }

                            if (container.IsFull)
                            {
                                break;
                            }
                        }
                    }
                }
                break;

            case ContainerFillMethod.SpecificItems:
                if (WorldItems.Get.Category(State.WICategoryName, out category))
                {
                    for (int i = 0; i < State.SpecificItems.Count; i++)
                    {
                        GenericWorldItem specificItem = State.SpecificItems [i];
                        Stacks.Add.Items(specificItem.ToStackItem(), container, ref error);
                    }
                }
                break;
            }

            State.NumTimesFilled++;
            mIsFilling = false;

            yield return(null);

            if (worlditem.Is <Stolen> ())
            {
                //the goods in a stolen container are also marked as stolen
                Stacks.Add.ScriptToItems(container, "Stolen");
            }

            yield break;
        }