Beispiel #1
0
        public void StackAddStack()
        {
            ResourceStack   stack1 = new ResourceStack(ResourceElement.ResourceType.Water);
            ResourceElement elem1  = new ResourceElement(ResourceElement.ResourceType.Water, station, 100, 1);
            ResourceElement elem2  = new ResourceElement(ResourceElement.ResourceType.Water, station, 50, 2);

            stack1.Add(elem1);
            stack1.Add(elem2);

            ResourceStack   stack2 = new ResourceStack(ResourceElement.ResourceType.Water);
            ResourceElement elem3  = new ResourceElement(ResourceElement.ResourceType.Water, station, 25, 3);

            stack2.Add(elem3);

            stack1.Add(stack2);

            Assert.AreEqual(175, stack1.Qte);
            Assert.AreEqual(0, stack2.Qte);

            ResourceElement elem4  = new ResourceElement(ResourceElement.ResourceType.ToxicWaste, station, 1, 1);
            ResourceStack   stack3 = new ResourceStack(elem4);

            stack1.Add(stack3);
            Assert.AreEqual(175, stack1.Qte);
            Assert.AreEqual(1, stack3.Qte);
        }
Beispiel #2
0
        public void StackAddStackRandom()
        {
            System.Random _rand = new System.Random();
            for (int i = 0; i < 50000; i++)   // Faire 50.000 tests aléatoires
            {
                int quantityElem1 = _rand.Next(0, int.MaxValue / 4);
                int quantityElem2 = _rand.Next(0, int.MaxValue / 4);
                int quantityElem3 = _rand.Next(0, int.MaxValue / 4);

                ResourceStack   stack1 = new ResourceStack(ResourceElement.ResourceType.Water);
                ResourceElement elem1  = new ResourceElement(ResourceElement.ResourceType.Water, station, quantityElem1, 1);
                ResourceElement elem2  = new ResourceElement(ResourceElement.ResourceType.Water, station, quantityElem2, 2);
                stack1.Add(elem1);
                stack1.Add(elem2);

                ResourceStack   stack2 = new ResourceStack(ResourceElement.ResourceType.Water);
                ResourceElement elem3  = new ResourceElement(ResourceElement.ResourceType.Water, station, quantityElem3, 3);
                stack2.Add(elem3);

                stack1.Add(stack2);

                Assert.AreEqual(quantityElem1 + quantityElem2 + quantityElem3, stack1.Qte);
                Assert.AreEqual(0, stack2.Qte);

                ResourceElement elem4  = new ResourceElement(ResourceElement.ResourceType.ToxicWaste, station, 10, 1);
                ResourceStack   stack3 = new ResourceStack(elem4);
                stack1.Add(stack3);
                Assert.AreEqual(quantityElem1 + quantityElem2 + quantityElem3, stack1.Qte);
                Assert.AreEqual(10, stack3.Qte);
            }
        }
Beispiel #3
0
        public void StackAdd()
        {
            ResourceStack   stack = new ResourceStack(ResourceElement.ResourceType.Wastes);
            ResourceElement elem1 = new ResourceElement(ResourceElement.ResourceType.Wastes, station, 100, 200);

            stack.Add(elem1);
            Assert.AreEqual(100, stack.Qte);
            Assert.AreEqual(ResourceElement.ResourceType.Wastes, stack.Type);
            Assert.AreEqual(0, elem1.Quantity);

            ResourceElement elem2 = new ResourceElement(ResourceElement.ResourceType.Water, station, 50, 201);

            stack.Add(elem2);

            Assert.AreEqual(100, stack.Qte);
            Assert.AreEqual(ResourceElement.ResourceType.Wastes, stack.Type);
            Assert.AreEqual(50, elem2.Quantity);

            ResourceElement elem3 = new ResourceElement(ResourceElement.ResourceType.Wastes, station, 200, 300);

            stack.Add(elem3);
            Assert.AreEqual(300, stack.Qte);
            Assert.AreEqual(ResourceElement.ResourceType.Wastes, stack.Type);
            Assert.AreEqual(0, elem3.Quantity);
        }
        public void ThenIExpectTheExchangeContractActorToHaveTheFollowingForOffer(string exchangeContract, Table table)
        {
            var exchangeActorRef = _state.ExchangeContractActors[exchangeContract];
            var queryTask        = exchangeActorRef.Ask <InvitationToTreat>(new ExchangeContract.QueryInvitationToTreat(),
                                                                            TimeSpan.FromMilliseconds(50));

            queryTask.Wait();
            var invitation = queryTask.Result;

            var exchangeType  = Enum.Parse(typeof(OfferType), table.GetField("ExchangeType"));
            var resource      = _state.GetResourceFromName(table.GetField("Resource"));
            var resourceStack = new ResourceStack(resource, int.Parse(table.GetField("Quantity")));
            var dateTime      = DateTime.Parse(table.GetField("CompletionTime"));

            resource = _state.GetResourceFromName(table.GetField("SuggestedOfferResourceName"));
            var suggestedResource = new ResourceStack(resource,
                                                      int.Parse(table.GetField("SuggestedOfferResourceQuantity")));

            resource = _state.GetResourceFromName(table.GetField("LiabilityResourceName"));
            var liabilityResource = new ResourceStack(resource, int.Parse(table.GetField("LiabilityResourceQuantity")));

            Assert.AreEqual(exchangeType, invitation.ExchangeType);
            Assert.AreEqual(resourceStack, invitation.InvitationStack);
            Assert.AreEqual(dateTime, invitation.InvitationDeadline);
            Assert.AreEqual(suggestedResource, invitation.SuggestedOffer);
            Assert.AreEqual(liabilityResource, invitation.LiabilityStack);
        }
        private ResourceStack ConstructLiabilityResourceStack(Table table)
        {
            var resource      = _state.GetResourceFromName(table.GetField("LiabilityResource"));
            var resourceStack = new ResourceStack(resource, int.Parse(table.GetField("LiabilityQuantity")));

            return(resourceStack);
        }
Beispiel #6
0
        public void StandingTest1()
        {
            Universe        universe = new Universe(0);
            Station         s        = universe.GetStation(1);
            Corporation     corp     = universe.CreateCorp(1);
            Ship            ship     = s.CreateShip(corp);
            ShipDestination dest     = ship.AddDestination(s);

            dest.AddLoad(ResourceElement.ResourceType.Wastes, 1000);
            ship.Start();

            Hangar corpHangar = s.CreateHangar(corp);

            ResourceElement elem  = new ResourceElement(ResourceElement.ResourceType.Wastes, s, 2000, 1);
            ResourceStack   stack = new ResourceStack(elem);

            corpHangar.Add(stack);

            Assert.IsTrue(s.Type == Station.StationType.City);
            Assert.IsTrue(System.Math.Abs(s.GetStanding(ResourceElement.ResourceType.Water, 1) - Station.defaultStanding) < 0.0001);
            Assert.IsTrue(System.Math.Abs(s.GetStanding(ResourceElement.ResourceType.Wastes, 1) - Station.defaultStanding) < 0.0001);

            //simuler une augmentation de standing
            for (int i = 0; i < 10; i++)
            {
                universe.Update();
            }

            //apres 2 jours de chargement...
            // day1 : 0.0 + (1 * 0.05) = 0.05
            // day2 : 0.05 + ((1-0.05) * 0.05) = 0.0975
            Assert.IsTrue(System.Math.Abs(s.GetStanding(ResourceElement.ResourceType.Wastes, 1) - 0.0975) < 0.0001);
        }
Beispiel #7
0
    public void SetUp(BuildingStats _stats)
    {
        isConstructing        = true;
        patron                = _stats;
        spriteRenderer.sprite = _stats.building_sprite;
        if (construction == null)
        {
            construction = new Construction();
        }
        construction.stockRequired = _stats.buildCost.Copy();
        construction.stockCurrent  = new ResourceStack(0, 0, 0);
        construction.needRessource = true;

        if (currentStock == null)
        {
            currentStock = new ResourceStack(0, 0, 0);
        }
        maxStock = _stats.stock.Copy();
        workers  = new Worker[_stats.workerRequired];
        for (int x = 0; x < workers.Length; x++)
        {
            if (workers[x] == null)
            {
                workers[x] = new Worker();
            }
        }
        workerSize            = _stats.workerRequired;
        structurePointCurrent = 1;
        GameState.instance.buildingsOnMap.Add(this);
        isActive = true;
    }
Beispiel #8
0
        public ResourceStack[] FilterInventory(IInventory incoming)
        {
            // This needs to iterate across the filter inventory
            // And remove a percentage weighted volume of the filter resources
            float filterVolume = Filter.CurrentVolume();

            ResourceStack[] resources = new ResourceStack[filterArray.Length];

            int i = 0;

            foreach (ResourceStack stack in filterArray)
            {
                // Otherwise the long way:
                if ((float)incoming.GetResource(stack.type).volume > 0)
                {
                    resources[i] = new ResourceStack()
                    {
                        type = stack.type, volume = stack.volume * (stack.volume / filterVolume)
                    };
                }
                i++;
            }

            return(resources);
        }
Beispiel #9
0
        public ResourceStack[] FilterResourceStackArray(ResourceStack[] incoming)
        {
            // This needs to iterate across the filter inventory
            // And remove a percentage weighted volume of the filter resources
            float filterVolume = Filter.CurrentVolume();

            ResourceStack[] resources = new ResourceStack[filterArray.Length];

            int i = 0;

            foreach (ResourceStack stack in filterArray)
            {
                int j = 0;
                foreach (ResourceStack incStack in incoming)
                {
                    if (incStack.type == stack.type)
                    {
                        if ((float)incoming[j].volume > 0)
                        {
                            resources[i] = new ResourceStack()
                            {
                                type = stack.type, volume = stack.volume * (stack.volume / filterVolume)
                            };
                        }
                    }
                    j++;
                }
                i++;
            }

            return(resources);
        }
Beispiel #10
0
    public void AddResourceToHanger(int hangarID, int type, int qte)
    {
        Hangar h = _container._hangars[hangarID];

        ResourceStack stack = null;

        foreach (int id in h.StacksIDs)
        {
            ResourceStack tmp = _container._resourceStacks[id];
            if (tmp.Type == type)
            {
                stack = tmp;
                break;
            }
        }
        if (null == stack)
        {
            stack        = new ResourceStack(_container._resourceStackIDs++);
            stack.Qte    = 0;
            stack.Type   = type;
            stack.Loaded = true;
            _container._resourceStacks.Add(stack.ID, stack);
            h.StacksIDs.Add(stack.ID);
        }

        stack.Qte += qte;

        ServerUpdate update = new ServerUpdate();

        update.stacks.Add(stack);
        update.hangars.Add(h);
        _manager.SendServerUpdate(update);
    }
Beispiel #11
0
        public void ShipUnloadingSelling()
        {
            Universe        u      = new Universe(0);
            Station         city   = u.GetStation(1);
            Station         city2  = u.GetStation(2);
            Corporation     player = u.CreateCorp(1);
            Ship            ship   = city.CreateShip(player);
            ResourceElement e      = new ResourceElement(ResourceElement.ResourceType.Food, city2, 100, 1);
            ResourceStack   stack  = new ResourceStack(e);

            ship.Cargo.Add(stack);

            Hangar h = city.CreateHangar(player);

            ShipDestination dest = ship.AddDestination(city);

            dest.AddUnload(ResourceElement.ResourceType.Food, 100);
            ship.Start();

            //ca prend 10 fois pour decharger
            for (int i = 0; i < 11; i++)
            {
                u.Update();
            }

            Assert.AreEqual(0, ship.Cargo.GetResourceQte(ResourceElement.ResourceType.Food));
            Assert.AreEqual(15000, ship.Owner.ICU);
            Assert.AreEqual(100, city.GetHangar(-1).GetResourceQte(ResourceElement.ResourceType.Food));
        }
Beispiel #12
0
    // Update is called once per frame
    void Update()
    {
        ResourceStack stack = handler.getStack();

        food.text  = stack.foodCount.ToString();
        wood.text  = stack.woodCount.ToString();
        stone.text = stack.stoneCount.ToString();
    }
Beispiel #13
0
 public void Gather(ResourceStack stack)
 {
     if (!Inventory.Add(stack))
     {
         Info.Log("Inventory full!");
     }
     else
     {
         Info.Log("Gathered " + stack.Amount + " of " + stack.Resource);
     }
 }
Beispiel #14
0
 private void ResourceStackUpdate(ResourceStack r)
 {
     if (null == r)
     {
         return;
     }
     if (!stacks.ContainsKey(r.ID))
     {
         stacks.Add(r.ID, r);
     }
     eventHolder.AddRange(stacks[r.ID].Update(r));
 }
    void Init(AsteroidPixelInitParams initParams)
    {
        Parent             = initParams.Parent;
        Health             = initParams.Health;
        YieldResourceStack = initParams.YieldResourceStack;
        Index = initParams.Index;

        healthMax     = Parent.DefaultHealth;
        lastHitID     = new UniqueID();
        originalColor = GetComponent <SpriteRenderer> ().color;
        colorChanged  = true;
    }
Beispiel #16
0
    private IEnumerator UpdateVisuRoutine()
    {
        waiting.SetActive(true);

        Hangars.options.Clear();
        Hangars.RefreshShownValue();

        _hangars.Clear();

        if (_resType == null)
        {
            waiting.SetActive(false);
            yield break;
        }
        else
        {
            resourceName.text = _resType.Name;

            int localCorp = LocalDataManager.instance.LocalCharacter.Corp;

            foreach (Station s in LocalDataManager.instance.GetStations())
            {
                if (s.Hangars.ContainsKey(localCorp))
                {
                    Hangar h = LocalDataManager.instance.GetHangarInfo(s.Hangars[localCorp]);
                    while (!h.Loaded)
                    {
                        yield return(null);
                    }
                    foreach (int stackID in h.StacksIDs)
                    {
                        ResourceStack r = LocalDataManager.instance.GetResourceStackInfo(stackID);
                        while (!r.Loaded)
                        {
                            yield return(null);
                        }
                        if (r.Type == _resType.Type)
                        {
                            Hangars.options.Add(new Dropdown.OptionData(s.Name));
                            _hangars.Add(h);
                            break;
                        }
                    }
                }
            }
        }

        Hangars.RefreshShownValue();
        OnHangarSelectChange(Hangars.value);
        waiting.SetActive(false);
        yield break;
    }
Beispiel #17
0
 /// <summary>
 /// Calculates the quantity of resources necessary to bring this system to the desired pressure at the desired temperature.
 /// </summary>
 /// <param name="resources">The resources present in the system.</param>
 /// <param name="composition">The gas composition of the system.</param>
 /// <param name="molesOfGasDesired">The number of moles of gas desired in the system.</param>
 /// <returns></returns>
 public static ResourceStack[] ResourcesDesired(ResourceStack[] resources, ResourceComposition[] composition, Mole molesOfGasDesired)
 {
     // Calculate resources desired
     ResourceStack[] resourcesDesired = new ResourceStack[resources.Length];
     for (int i = 0; i < resources.Length; i++)
     {
         resourcesDesired[i] = new ResourceStack()
         {
             type = resources[i].type, volume = molesOfGasDesired * composition[i].percentage / resources[i].type.MolarMass * resources[i].type.Density
         };
     }
     return(resourcesDesired);
 }
Beispiel #18
0
        public void StackConstruction()
        {
            //test d'un constructeur avec parametres
            ResourceStack stack = new ResourceStack(ResourceElement.ResourceType.Wastes);

            Assert.AreEqual(0, stack.Qte);
            Assert.AreEqual(ResourceElement.ResourceType.Wastes, stack.Type);

            ResourceElement elem   = new ResourceElement(ResourceElement.ResourceType.Water, station, 100, 200);
            ResourceStack   stack2 = new ResourceStack(elem);

            Assert.AreEqual(100, stack2.Qte);
            Assert.AreEqual(ResourceElement.ResourceType.Water, stack2.Type);
            Assert.AreEqual(0, elem.Quantity);
        }
Beispiel #19
0
    private void UpdateResources()
    {
        while (resourcesGrid.transform.childCount > 0)
        {
            Destroy(resourcesGrid.transform.GetChild(0).gameObject);
            resourcesGrid.transform.GetChild(0).SetParent(null);
        }

        foreach (int i in _hangar.StacksIDs)
        {
            ResourceIcon  icon = Instantiate(resourceIconPrefab, resourcesGrid.transform);
            ResourceStack r    = LocalDataManager.instance.GetResourceStackInfo(i);
            icon.SetStack(r);
        }
    }
Beispiel #20
0
    public void SetStack(ResourceStack stack)
    {
        Stack    = stack;
        Qte.text = stack.Qte.ToString();
        ResourceInfos i = LocalDataManager.instance.ResourceDataManager.GetResourceInfos(stack.Type);

        if (i != null)
        {
            Name.text = i.Name;
        }
        else
        {
            return;
        }
    }
Beispiel #21
0
    private IEnumerator WaitForHangar()
    {
        Window w = GetComponentInParent <Window>();

        w.SetLoading(true);
        float time = 3.0f;

        while (!_hangar.Loaded)
        {
            if (time > 2.0f)
            {
                WideDataManager.wideDataManager.SendRequest(new LoadHangarRequest(_hangar.ID));
                time = 0.0f;
            }
            time += Time.deltaTime;
            yield return(null);
        }
        foreach (int i in _hangar.StacksIDs)
        {
            ResourceStack r = LocalDataManager.instance.GetResourceStackInfo(i);
            while (!r.Loaded)
            {
                yield return(null);
            }
        }
        long?id   = -1;
        bool loop = true;

        WideDataManager.RequestCB frameMethCB = delegate(Request r) {
            if (r.RequestID == id)
            {
                loop = false;
            }
        };
        WideDataManager.wideDataManager.OnRequestResult += frameMethCB;
        id = WideDataManager.Request(new GetFlightPlanRequest(LocalDataManager.instance.LocalCorporation.FlightPlans));
        while (loop)
        {
            yield return(null);
        }
        WideDataManager.wideDataManager.OnRequestResult -= frameMethCB;

        UpdateShips();
        UpdateResources();

        w.SetLoading(false);
        yield break;
    }
Beispiel #22
0
    public ResourceStack AddRessources(ResourceStack _ajout)
    {
        ResourceStack surplus = carrying.AddWithinCapacity(_ajout, maxCarry);

        return(surplus);

        if (surplus.GetSize() > 0)
        {
            //GameState.instance.itemDrop.CreateRessourceStack()
            //return false;
        }
        else
        {
            //return true;
        }
    }
Beispiel #23
0
    public ResourceDrop CreateRessourceStack(ResourceStack _stack, Vector2Int _position)
    {
        GameObject   obj  = Instantiate(ressourcesPrefab);
        ResourceDrop drop = obj.GetComponent <ResourceDrop>();

        if (drop != null)
        {
            drop.ressources = _stack;
            GameState.instance.map.GetTile(_position.x, _position.y).relatedObject = drop;
            return(drop);
        }
        else
        {
            return(null);
        }
    }
Beispiel #24
0
        public void HangarStackRemove()
        {
            Hangar h = new Hangar(station, corporation);

            ResourceElement elem1  = new ResourceElement(ResourceElement.ResourceType.Wastes, station, 100, 1);
            ResourceStack   stack1 = new ResourceStack(elem1);

            bool eventTrigered = false;

            h.Add(stack1);
            h.onRemoveStack += (s) => { eventTrigered = true; };
            h.GetStack(ResourceElement.ResourceType.Wastes, 100);

            Assert.IsTrue(eventTrigered);
            Assert.AreEqual(0, h.ResourceStacks.Count);
        }
Beispiel #25
0
 public bool Equals(ResourceStack that)
 {
     if (Object.ReferenceEquals(that, null))
     {
         return(false);
     }
     if (Object.ReferenceEquals(this, that))
     {
         return(true);
     }
     if (this.GetType() != that.GetType())
     {
         return(false);
     }
     return((Type.Equals(that.Type)) && (Amount.Equals(that.Amount)));
 }
Beispiel #26
0
    public float Divide(ResourceStack other)
    {
        float res = 10000000000;

        if (other.woodCount > 0)
        {
            res = Mathf.Min(res, woodCount / other.woodCount);
        }
        if (other.foodCount > 0)
        {
            res = Mathf.Min(res, foodCount / other.foodCount);
        }
        if (other.stoneCount > 0)
        {
            res = Mathf.Min(res, stoneCount / other.stoneCount);
        }
        return(res);
    }
Beispiel #27
0
    public ResourceStack GetResourceStackInfo(int stackID)
    {
        ResourceStack result = null;

        if (!stacks.ContainsKey(stackID))
        {
            result = new ResourceStack(stackID);
            stacks.Add(stackID, result);
            AddObject(result);
        }
        result = stacks[stackID];

        if (!result.Loaded)
        {
            WideDataManager.Request(new LoadResourceStackRequest(stackID));
        }
        return(result);
    }
Beispiel #28
0
        public void StackSubStack()
        {
            ResourceElement elem1 = new ResourceElement(ResourceElement.ResourceType.Water, station, 100, 1);
            ResourceStack   stack = new ResourceStack(elem1);
            ResourceElement elem2 = new ResourceElement(ResourceElement.ResourceType.Water, station, 100, 2);

            stack.Add(elem2);

            ResourceStack s1 = stack.GetSubStack(25);

            Assert.AreEqual(25, s1.Qte);
            Assert.AreEqual(ResourceElement.ResourceType.Water, s1.Type);
            Assert.AreEqual(175, stack.Qte);
            Assert.AreEqual(ResourceElement.ResourceType.Water, stack.Type);
            foreach (ResourceElement e in s1.GetElements())
            {
                Assert.AreEqual(1, e.DateProd);
            }

            ResourceStack s2 = stack.GetSubStack(200);

            Assert.AreEqual(null, s2);
            Assert.AreEqual(175, stack.Qte);

            //retirer un stack composé de 2 elements
            ResourceStack s3 = stack.GetSubStack(100);

            Assert.AreEqual(100, s3.Qte);
            Assert.AreEqual(ResourceElement.ResourceType.Water, s3.Type);
            Assert.AreEqual(75, stack.Qte);
            List <ResourceElement> elemsStack = stack.GetElements();

            Assert.AreEqual(1, elemsStack.Count);
            Assert.AreEqual(2, elemsStack[0].DateProd);
            List <ResourceElement> elems = s3.GetElements();

            Assert.AreEqual(2, elems.Count);
            Assert.AreEqual(1, elems[0].DateProd);
            Assert.AreEqual(75, elems[0].Quantity);
            Assert.AreEqual(2, elems[1].DateProd);
            Assert.AreEqual(25, elems[1].Quantity);
        }
Beispiel #29
0
        public void HangarTransactions1()
        {
            Hangar h = new Hangar(station, corporation);

            ResourceElement elem1  = new ResourceElement(ResourceElement.ResourceType.Wastes, station, 100, 1);
            ResourceStack   stack1 = new ResourceStack(elem1);

            h.Add(stack1);
            Assert.AreEqual(100, h.GetResourceQte(ResourceElement.ResourceType.Wastes));
            Assert.AreEqual(0, stack1.Qte);

            ResourceElement elem2  = new ResourceElement(ResourceElement.ResourceType.ToxicWaste, station, 50, 2);
            ResourceStack   stack2 = new ResourceStack(elem2);

            h.Add(stack2);
            Assert.AreEqual(100, h.GetResourceQte(ResourceElement.ResourceType.Wastes));
            Assert.AreEqual(0, stack1.Qte);
            Assert.AreEqual(50, h.GetResourceQte(ResourceElement.ResourceType.ToxicWaste));
            Assert.AreEqual(0, stack2.Qte);
        }
Beispiel #30
0
    public override List <EventHolder> Update(DataObject o)
    {
        List <EventHolder> result = new List <EventHolder>();
        ResourceStack      r      = o as ResourceStack;

        if (null == r || r.ID != ID)
        {
            return(result);
        }

        string data = Newtonsoft.Json.JsonConvert.SerializeObject(r);
        var    serializerSettings = new Newtonsoft.Json.JsonSerializerSettings {
            ObjectCreationHandling = Newtonsoft.Json.ObjectCreationHandling.Replace
        };

        Newtonsoft.Json.JsonConvert.PopulateObject(data, this, serializerSettings);

        result.Add(new ResourceStackChangeEvent(this, LocalDataManager.instance.OnResourceStackChange));

        return(result);
    }