コード例 #1
0
 public bool GetItem(int hashCode, out GenericWorldItem genericItem)
 {
     genericItem = null;
     if (GenericWorldItems.Count > 0)
     {
         genericItem = GenericWorldItems [Mathf.Abs(hashCode) % GenericWorldItems.Count];
     }
     return(genericItem != null);
 }
コード例 #2
0
ファイル: Creatures.cs プロジェクト: yazici/FRONTIERS
        public override void WakeUp()
        {
            base.WakeUp();

            Get = this;

            gDarkrotSpawner            = new GenericWorldItem();
            gDarkrotSpawner.PackName   = "Oblox";
            gDarkrotSpawner.PrefabName = "DarkrotSpawner";

            mTemplateLookup = new Dictionary <string, CreatureTemplate> ();
            mBodyLookup     = new Dictionary <string, CreatureBody> ();
        }
コード例 #3
0
ファイル: LiquidContainer.cs プロジェクト: yazici/FRONTIERS
        public bool TryToFillWith(GenericWorldItem item, int numItems, out int numFilled, out string errorMessage)
        {
            int availableCapacity = 0;

            numFilled = 0;
            if (CanFillWith(item, out availableCapacity, out errorMessage))
            {
                Contents.CopyFrom(item);
                numFilled = availableCapacity;
                if (numFilled > numItems)
                {
                    numFilled = numItems;
                }
                Contents.InstanceWeight = numFilled;
                return(true);
            }
            return(false);
        }
コード例 #4
0
ファイル: LiquidContainer.cs プロジェクト: yazici/FRONTIERS
        public bool CanFillWith(GenericWorldItem item, out int availableCapacity, out string errorMessage)
        {
            availableCapacity = 0;
            errorMessage      = string.Empty;
            if (IsFilled)
            {
                errorMessage = "Already full";
                return(false);
            }

            if (!IsEmpty)                                       //if we have some filled, see if the items are compatible
            {
                availableCapacity = Capacity - Contents.InstanceWeight;
                return(Stacks.Can.Stack(Contents.PrefabName, item.PrefabName));
            }

            if (CanContain.Count > 0)                                           //if we have restrictions, check them
            {
                bool canContain = false;
                foreach (string canContainType in CanContain)
                {
                    if (Stacks.Can.Stack(canContainType, item.PrefabName))                                                                      //if any item is compatible, yay we can fill
                    {
                        canContain = true;
                        break;
                    }
                }
                if (!canContain)
                {
                    errorMessage = "This container can't hold " + item.DisplayName;
                    return(false);
                }
            }
            availableCapacity = Capacity;
            return(true);
        }
コード例 #5
0
        public bool GetItem(WIFlags flags, int hashCode, ref int lastIndex, out GenericWorldItem genericItem)
        {
            genericItem = null;

            if (IsEmpty)
            {
                //Debug.Log ("Category was empty");
                return(false);
            }
            //use the hashcode and index to get a random lookup table index
            int indexLookup              = 0;
            int objectIndex              = 0;
            int searchOffset             = Mathf.Abs(hashCode + lastIndex);
            GenericWorldItem currentItem = null;

            for (int i = 0; i < indexTable.Count; i++)
            {
                //go for the entire length of the array
                //get an index - this will increment the last index
                indexLookup = (searchOffset + i) % indexTable.Count;
                objectIndex = indexTable [indexLookup];
                currentItem = GenericWorldItems [objectIndex];

                if (flags.Check(currentItem.Flags))
                {
                    if (Stacks.Can.Fit(currentItem.Flags.Size, flags.Size))
                    {
                        genericItem = currentItem;
                        lastIndex   = indexLookup + 1;
                        break;
                    }
                }
            }

            return(genericItem != null);
        }
コード例 #6
0
        public void Initialize()
        {
            HasMinInstanceItems = false;

            if ((DefaultItem == null || DefaultItem.IsEmpty) && GenericWorldItems.Count > 0)
            {
                DefaultItem = GenericWorldItems [0];
            }

            //get the flags for our items
            WorldItem prefab = null;

            for (int i = GenericWorldItems.LastIndex(); i >= 0; i--)
            {
                GenericWorldItem genericWorldItem = GenericWorldItems [i];
                if (genericWorldItem == null)
                {
                    GenericWorldItems.RemoveAt(i);
                }
                else if (WorldItems.Get.PackPrefab(genericWorldItem.PackName, genericWorldItem.PrefabName, out prefab))
                {
                    genericWorldItem.Flags = prefab.Flags;
                }
                else
                {
                    GenericWorldItems.RemoveAt(i);
                }
            }

            //generate our lookup tables
            indexTable = new List <int> ();
            //randomTable = new List <uint> ();
            WorldItem template = null;

            for (int i = 0; i < GenericWorldItems.Count; i++)
            {
                GenericWorldItem gwi = GenericWorldItems [i];
                int itemProbability  = Globals.WIRarityCommonProbability;

                if (gwi.MinInstances > 0)
                {
                    HasMinInstanceItems = true;
                }

                if (WorldItems.Get.PackPrefab(gwi.PackName, gwi.PrefabName, out template))
                {
                    switch (template.Props.Global.Flags.BaseRarity)
                    {
                    case WIRarity.Common:
                    default:
                        break;

                    case WIRarity.Uncommon:
                        itemProbability = Globals.WIRarityUncommonProbability;
                        break;

                    case WIRarity.Rare:
                        itemProbability = Globals.WIRarityRareProbability;
                        break;

                    case WIRarity.Exclusive:
                        break;
                    }

                    itemProbability *= gwi.InstanceWeight;

                    for (int j = 0; j < itemProbability; j++)
                    {
                        indexTable.Add(i);                         //add this item's index number
                    }
                }
            }

            //now shuffle the index list
            indexTable.Shuffle(new System.Random(Name.GetHashCode()));

            //now build the randomized lookup list

            /*
             *                      for (uint i = 0; i < indexTable.Count; i++) {
             *                              for (uint j = 0; j < Globals.WICategoryRandomTableProbability; j++) {
             *                                      //add an instance if the randomized index
             *                                      randomTable.Add (indexTable [(int) i]);
             *                              }
             *                      }
             */

            //finally, randomize the random table list
            //randomTable.Shuffle (new System.Random (Name.GetHashCode ()));

            mInitialized = true;
        }