Ejemplo n.º 1
0
 public override ResourceData FromFileToAdd(Stream stream,
                                            string extension,
                                            ushort langId,
                                            ResourceSource currentSource)
 {
     return(FromFile(stream, extension));
 }
Ejemplo n.º 2
0
    private IEnumerator GatherResources(ResourceSource source)
    {
        source.StartGathering();
        while (source.resourceAmount > 0 && this.currentResourceAmount < this.m_ResourceCarryCapacity)
        {
            this.currentResourceAmount += source.GatherResource(m_GatherSpeed, this.m_ResourceCarryCapacity - this.currentResourceAmount);
            if (source.resourceAmount > 0)
            {
                yield return(new WaitForSeconds(1));
            }
        }
        source.StopGathering();

        lockedTrees.Remove(source.transform);

        if (this.currentResourceAmount == this.m_ResourceCarryCapacity)
        {
            SetNewState(State.GotoWoodBuilding);
            StartCoroutine(GotoWoodBuilding(this.m_ClosestWoodBuilding));
        }
        else
        {
            SetNewState(State.LookingForTarget);
        }
    }
Ejemplo n.º 3
0
        /// <summary>Prompts the user to save the current source (if open) then opens a Save File dialog for the new empty ResourceSource then loads it.</summary>
        private void SourceNew()
        {
            if (!SourceUnload())
            {
                return;
            }

            IList <ResourceSourceFactory> factories = ResourceSourceFactory.GetFactories();

            String filter = String.Empty;

            foreach (ResourceSourceFactory factory in factories)
            {
                filter += factory.NewFileFilter + '|';
            }
            if (filter.EndsWith("|"))
            {
                filter = filter.Substring(0, filter.Length - 1);
            }

            __sfd.Filter = filter;

            if (__sfd.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            ResourceSourceFactory selectedFactory = factories[__sfd.FilterIndex - 1];

            ResourceSource source = selectedFactory.CreateNew(__sfd.FileName, false, ResourceSourceLoadMode.LazyLoadData);

            SourceLoad(source, __sfd.FileName);
        }
Ejemplo n.º 4
0
    // gets the closest resource to the position (random between nearest 3 for some variance)
    public ResourceSource GetClosestResource(Vector3 pos)
    {
        ResourceSource[] closest     = new ResourceSource[3];
        float[]          closestDist = new float[3];

        foreach (ResourceSource resource in resources)
        {
            if (resource != null)
            {
                float dist = Vector3.Distance(pos, resource.transform.position);

                for (int x = 0; x < closest.Length; x++)
                {
                    if (closest[x] == null)
                    {
                        closest[x]     = resource;
                        closestDist[x] = dist;
                        break;
                    }
                    else
                    {
                        if (dist < closestDist[x])
                        {
                            closest[x]     = resource;
                            closestDist[x] = dist;
                            break;
                        }
                    }
                }
            }
        }

        return(closest[Random.Range(0, closest.Length)]);
    }
Ejemplo n.º 5
0
        private static Anolis.Core.Data.VersionResourceData GetVSVersion(String fileName)
        {
            using (ResourceSource src = ResourceSource.Open(fileName, true, ResourceSourceLoadMode.LazyLoadData)) {
                ResourceType vsType = null;
                foreach (ResourceType type in src.AllTypes)
                {
                    if (type.Identifier.KnownType == Win32ResourceType.Version)
                    {
                        vsType = type;
                        break;
                    }
                }

                if (vsType == null)
                {
                    return(null);
                }

                foreach (ResourceName name in vsType.Names)
                {
                    foreach (ResourceLang lang in name.Langs)
                    {
                        return(lang.Data as Anolis.Core.Data.VersionResourceData);
                    }
                }

                return(null);
            }
        }
Ejemplo n.º 6
0
        private ResourceSource OpenSource(FileInfo file, out int nofNames)
        {
            nofNames = 0;

            try
            {
                var source = ResourceSource.Open(file.FullName, true, ResourceSourceLoadMode.LazyLoadData);

                // quickly get a count of all the names
                foreach (var type in source.AllTypes)
                {
                    foreach (var name in type.Names)
                    {
                        nofNames++;
                    }
                }

                return(source);
            }
            catch (AnolisException aex)
            {
                Log.Add(LogSeverity.Error, "Couldn't open " + file.FullName + ", " + aex.Message);

                return(null);
            }
        }
Ejemplo n.º 7
0
    public void OnSelectionChanged()
    {
        var selectable = SelectionManager.Instance.GetLastSelected <Selectable>();

        if (!selectable)
        {
            this.panelAnimator.SetBool("Out", true);

            this.selectedPerson = null;
            this.selectedSource = null;
            return;
        }
        this.panelAnimator.SetBool("Out", false);

        this.nameText.text = selectable.menuName;
        this.icon.sprite   = selectable.menuSprite;

        this.selectedPerson = selectable.GetComponent <Person>();
        this.personInfo.SetActive(this.selectedPerson);
        this.selectedSource = selectable.GetComponent <ResourceSource>();
        this.resourceInfo.SetActive(this.selectedSource);
        this.selectedBuilding = selectable.GetComponent <Building>();
        this.buildingInfo.SetActive(this.selectedBuilding);

        this.LateUpdate();
    }
Ejemplo n.º 8
0
 public override ResourceData FromFileToAdd(Stream stream,
                                            string extension,
                                            ushort langId,
                                            ResourceSource currentSource)
 {
     throw new NotSupportedException();
 }
Ejemplo n.º 9
0
        public override void LoadParameters(System.IO.BinaryReader reader)
        {
            //GameManager.DebugLog("Loading Modify");

            base.LoadParameters(reader);

            target_resource_index    = reader.ReadInt32();
            operation_resource_index = reader.ReadInt32();

            target = (ResourceSource)reader.ReadInt32();
            param1 = (ResourceSource)reader.ReadInt32();
            param2 = (ResourceSource)reader.ReadInt32();;

            operation = (ModifyOperation)reader.ReadInt32();

            action_mod = reader.ReadString();
            bool_mod   = reader.ReadBoolean();
            text_mod   = reader.ReadString();
            number_mod = reader.ReadInt32();

            action_mod2 = reader.ReadString();
            bool_mod2   = reader.ReadBoolean();
            text_mod2   = reader.ReadString();
            number_mod2 = reader.ReadInt32();
            //trigger = (CGME.InterfaceEvent)Enum.Parse(typeof(InterfaceEvent),reader.ReadString());
        }
Ejemplo n.º 10
0
        public void Run(UnitAction action)
        {
            if (action.target != null && action.target == m_action.target)
            {
                // continue action;
                m_action.status = UnitAction.ActionStatus.Planned;
                return;
            }
            else
            {
                // reserve a new cell for the interaction

                /*if (m_action.interactionCell != action.interactionCell)
                 * {
                 *  World.instance.ReleaseCell(m_controller.unit, m_action.interactionCell);
                 *  World.instance.ReserveCell(m_controller.unit, action.interactionCell);
                 * }*/
                m_action = action;
                m_navigation.isStopped = false;
                m_action.status        = UnitAction.ActionStatus.Planned;

                m_time = 0;
                if (action.target)
                {
                    building = action.target as BuildingBase;
                    unit     = action.target as Unit;
                    resource = action.target as ResourceSource;
                }
            }
        }
Ejemplo n.º 11
0
        private static StatelessResult OneOffUpdate(string sourceFilename,
                                                    ResourceTypeIdentifier typeId,
                                                    ResourceIdentifier nameId,
                                                    string dataFilename)
        {
            var source = ResourceSource.Open(sourceFilename, false, ResourceSourceLoadMode.LazyLoadData);

            // for each lang in name, update
            var name = source.GetName(typeId, nameId);

            if (name == null)
            {
                return(new StatelessResult("Could not find name " + GetResPath(typeId, nameId, null) + " to extract."));
            }

            foreach (var lang in name.Langs)
            {
                var newData = ResourceData.FromFileToUpdate(dataFilename, lang);
                lang.SwapData(newData);
            }

            source.CommitChanges();

            return(StatelessResult.Success);
        }
Ejemplo n.º 12
0
    private IEnumerator FindPathToTargetCoroutine()
    {
        bool pathFound = false;

        while (this.currentTargetIndex < this.allNearbyTargets.Count)
        {
            var nextTarget = this.allNearbyTargets[this.currentTargetIndex];
            var path       = new NavMeshPath();
            if (this._agent.CalculatePath(nextTarget.position, path) && !lockedTrees.Contains(nextTarget))
            {
                lockedTrees.Add(nextTarget);
                this._agent.SetPath(path);
                this.target = nextTarget.GetComponent <ResourceSource>();
                SetNewState(State.FollowingPath);
                pathFound = true;
                break;
            }
            else
            {
                this.currentTargetIndex++;
                yield return(null);
            }
        }

        if (!pathFound)
        {
            Debug.LogError("Tried all nearby targets and couldn't path to any.");
            SetNewState(State.Idle);
        }
    }
        public Task <Resource> CreateResourceAsync <T> (ResourceSource source, string name, T value)
        {
            var r = new Resource <T> (source, name, value);

            ((ObservableLookup <ResourceSource, Resource>) this.resources).Add(source, r);
            return(Task.FromResult <Resource> (r));
        }
Ejemplo n.º 14
0
 public Data(ResourceSource source)
 {
     this.prefabName = source.savedPrefabName;
     this.position   = source.transform.position;
     this.type       = (int)source.type;
     this.amount     = source.amount;
 }
        public Task <ResourceCreateError> CheckNameErrorsAsync(object target, ResourceSource source, string name)
        {
            ResourceCreateError error = null;

            if (this.resources[source].Any(r => r.Name == name))
            {
                error = new ResourceCreateError("Name in use", isWarning: false);
            }
            else
            {
                var order = new List <ResourceSourceType> {
                    ResourceSourceType.Document,
                    ResourceSourceType.ResourceDictionary,
                    ResourceSourceType.Application,
                    ResourceSourceType.System,
                };

                // Simplistic example of hierarchy override checking
                for (int i = order.IndexOf(source.Type) + 1; i < order.Count; i++)
                {
                    if (this.resources.Where(ig => ig.Key.Type == order[i]).SelectMany(ig => ig).Any(r => r.Name == name))
                    {
                        error = new ResourceCreateError("Resource would override another resource", isWarning: true);
                        break;
                    }
                }
            }

            return(Task.FromResult(error));
        }
Ejemplo n.º 16
0
        private void SourceLoad(ResourceSource source, String path)
        {
            try {
                if (source == null)
                {
                    MessageBox.Show(this, "Unable to load the file " + Path.GetFileName(path), "Anolis Resourcer", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    return;
                }

                CurrentPath = path;

                CurrentSource = source;

                Mru.Push(path);

                ToolbarUpdate(true, true, false);
                StatusbarUpdate();

                TreePopulate();

                ListLoad();
            } catch (AnolisException aex) {
                SourceLoadCatch(aex, path, false);
            }
        }
Ejemplo n.º 17
0
    void OnFocus()
    {
        {
            string version = PlayerPrefs.GetString(__KeyVersion);
            if (!string.IsNullOrEmpty(version))
            {
                mCurrentVersion = Frame.GameVersion.Parse(version);
            }
        }
        {
            string target = PlayerPrefs.GetString(__KeyPlatform);
            if (!string.IsNullOrEmpty(target))
            {
                ABExporter.buildTarget = (BuildTarget)Enum.Parse(typeof(BuildTarget), target);
            }
        }

        {
            int toolPanelOpen = PlayerPrefs.GetInt(__KeyToolPanelOpen);
            mToolPanelOpen = toolPanelOpen > 0 ? true : false;
        }

        {
            string target = PlayerPrefs.GetString(__KeyResourceSource);
            if (!string.IsNullOrEmpty(target))
            {
                mResourceSource = (ResourceSource)Enum.Parse(typeof(ResourceSource), target);
            }
        }

        ABExporter.OnFocus();
    }
Ejemplo n.º 18
0
        private static StatelessResult OneOffDelete(string sourceFilename,
                                                    ResourceTypeIdentifier typeId,
                                                    ResourceIdentifier nameId)
        {
            var source = ResourceSource.Open(sourceFilename, false, ResourceSourceLoadMode.EnumerateOnly);

            // delete all the ResourceLangs that match this typeId/nameId criterion. When reloaded the ResourceName should no-longer exist

            var name = source.GetName(typeId, nameId);

            if (name == null)
            {
                return(new StatelessResult("Could not find name " + GetResPath(typeId, nameId, null) + " to delete."));
            }
            ;

            foreach (var lang in name.Langs)
            {
                source.Remove(lang);
            }

            source.CommitChanges();

            return(StatelessResult.Success);
        }
Ejemplo n.º 19
0
    void CollectResource(GameObject obj)
    {
        ResourceSource source = obj.GetComponent <ResourceSource>();

        switch (CurrentState)
        {
        case PlayerState.EmptyHand:
            if (source.GetTypeOfSource() == TypeOfSource.Feed)
            {
                GameObject held = source.GetHeldObject();
                if (held == null)
                {
                    break;
                }

                held.GetComponent <HeldObject>().SetNumUnitsHeld(source.UnitsTakenFromSource());
                PickupObject(held);
            }
            break;

        case PlayerState.HoldingObject:
            if (source.GetTypeOfSource() == TypeOfSource.Water)
            {
                HeldObject held = ObjectInHand.GetComponent <HeldObject>();
                if (held.GetTypeOfObject() != TypeOfObject.Bucket || held.IsCarryingUnits())
                {
                    break;
                }
                held.SetNumUnitsHeld(source.UnitsTakenFromSource());
                held.ChangeObjectState();
                FindObjectOfType <AudioManager>().Play("wellSFX");
            }
            break;
        }
    }
Ejemplo n.º 20
0
    public void OnTargetReached(GameObject destination)
    {
        if (destination == null || !this.IsInRange(destination))
        {
            return;
        }

        // interact with building
        var building = destination.GetComponent <Building>();

        if (building)
        {
            if (building.IsFinished)
            {
                // store the resource we are currently holding
                if (this.CarryingResource != null && building.storeableTypes.Contains(this.CarryingResource.type))
                {
                    ResourceManager.Instance.Add(this.CarryingResource.type, this.CarryingResource.amount);
                    this.CarryingResource = null;
                }

                // if a building is currently being constructed, pick up the required ingredients
                if (this.constructingBuilding != null)
                {
                    foreach (var res in this.constructingBuilding.requiredResources)
                    {
                        if (!building.storeableTypes.Contains(res.type))
                        {
                            continue;
                        }
                        var taken = ResourceManager.Instance.Take(res.type, Mathf.Min(res.amount, this.maxCarryAmount));
                        if (taken > 0)
                        {
                            this.CarryingResource = new Resource {
                                type   = res.type,
                                amount = taken
                            };
                            break;
                        }
                    }
                }
            }
            else
            {
                this.shouldContructBuilding = true;
                this.constructingBuilding   = building;
            }
            return;
        }

        // interact with resource source
        var source = destination.GetComponent <ResourceSource>();

        if (source)
        {
            this.resourceToBeGathered = source.type;
            this.interactingSource    = source;
        }
    }
Ejemplo n.º 21
0
        public MyObjectBuilder_Battery GetObjectBuilder()
        {
            MyObjectBuilder_Battery builder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Battery>();

            builder.ProducerEnabled = ResourceSource.Enabled;
            builder.CurrentCapacity = ResourceSource.RemainingCapacityByType(MyResourceDistributorComponent.ElectricityId);
            return(builder);
        }
Ejemplo n.º 22
0
        public ResIconDir(Boolean isIcon, UInt16 lang, ResourceSource source)
        {
            _members = new List <IDirectoryMember>();

            IsIcon = isIcon;
            Source = source;
            Lang   = lang;
        }
Ejemplo n.º 23
0
    // move to a resource and begin to gather it
    public void GatherResource(ResourceSource resource, Vector3 pos)
    {
        curResourceSource = resource;
        SetState(UnitState.MoveToResource);

        navAgent.isStopped = false;
        navAgent.SetDestination(pos);
    }
Ejemplo n.º 24
0
 public override ResourceData FromFileToAdd(Stream stream,
                                            string extension,
                                            ushort langId,
                                            ResourceSource currentSource)
 {
     LastErrorMessage = "Not supported";
     return(null);
 }
Ejemplo n.º 25
0
        public void CreateCollectJob(ResourceSource source)
        {
            var job = new CollectJob(source);

            Assert.AreEqual(source, job.Resource);
            Assert.AreEqual(source.Amount, job.Limit);
            Assert.AreEqual(source.Amount <= 0, job.LimitReached);
        }
Ejemplo n.º 26
0
        public void CreateCollectJobWithLimit(ResourceSource source, int limit)
        {
            var job = new CollectJob(source, limit);

            Assert.AreEqual(source, job.Resource);
            Assert.AreEqual(limit, job.Limit);
            Assert.AreEqual(limit <= 0, job.LimitReached);
        }
Ejemplo n.º 27
0
        public float Sink_ComputeRequiredPower()
        {
            float inputRequiredToFillIn100Updates = (MyEnergyConstants.BATTERY_MAX_CAPACITY - ResourceSource.RemainingCapacityByType(MyResourceDistributorComponent.ElectricityId)) * VRage.Game.MyEngineConstants.UPDATE_STEPS_PER_SECOND / m_productionUpdateInterval * ResourceSource.ProductionToCapacityMultiplierByType(MyResourceDistributorComponent.ElectricityId);
            float currentOutput = ResourceSource.CurrentOutputByType(MyResourceDistributorComponent.ElectricityId);

            currentOutput *= MySession.Static.CreativeMode ? 0f : 1f;
            return(Math.Min(inputRequiredToFillIn100Updates + currentOutput, MyEnergyConstants.BATTERY_MAX_POWER_INPUT));
        }
            public override bool Equals(ResourceSource other)
            {
                if (!base.Equals(other))
                {
                    return(false);
                }

                return(other is ObjectResourceSource ors && ReferenceEquals(ors.target, this.target));
            }
Ejemplo n.º 29
0
        public Finder(ResourceSource source, String text, FinderOptions options)
        {
            Source   = source;
            FindText = text;
            Options  = options;

            HasStarted  = false;
            _enumerator = Source.AllLangs.GetEnumerator();
        }
Ejemplo n.º 30
0
 void Start()
 {
     entity = GetComponent <Entity>();
     entity.AddUpdateAction(TickUpdate);
     powerSink      = GetComponent <PowerSink>();
     source         = Utility.GetThingAt <ResourceSource>(entity.position);
     source.hasMine = true;
     resourceMan    = FindObjectOfType <ResourceManager>();
 }