예제 #1
0
 private void UpdateLineItemText(Widget LineItem, ResourceAmount Resource)
 {
     LineItem.GetChild(1).Text = String.Format("{0} at ${1}e",
                                               Resource.NumResources,
                                               ValueSourceEntity.ComputeValue(Resource.ResourceType));
     LineItem.GetChild(1).Invalidate();
 }
예제 #2
0
        internal double GetModifiedAmount(ResourceAmount startingAmount, ResourceCheckpoint lastCheckpoint)
        {
            Resource resource = startingAmount.Resource;

            double modifiedAmount = startingAmount.Count;

            foreach (ModifierDuration modifier in GetModifierDurations(resource.id))
            {
                double percentageModifiedTime = 1d;

                if (modifier.ExpirationTimeUTC is DateTime expirationTime)
                {
                    if (expirationTime < DateTime.UtcNow)
                    {
                        TimeSpan modifiedTime = expirationTime - lastCheckpoint.CheckpointTimeUTC;
                        TimeSpan totalTime    = DateTime.UtcNow - lastCheckpoint.CheckpointTimeUTC;
                        percentageModifiedTime = modifiedTime.TotalSeconds / totalTime.TotalSeconds;
                    }
                }

                double amountToBeModified = startingAmount.Count * percentageModifiedTime;
                modifiedAmount += amountToBeModified * modifier.Modifier.percentageIncrease;
            }

            return(modifiedAmount);
        }
예제 #3
0
 public TextEvent(string text, ResourceAmount[] toDisplay, ResourceAmount extraToDisplay, ResourceAmount extraToDisplay2)
 {
     this.text            = text;
     this.toDisplay       = toDisplay;
     this.extraToDisplay  = extraToDisplay;
     this.extraToDisplay2 = extraToDisplay2;
 }
    private void Awake()
    {
        transform.Find("button").GetComponent <Button>().onClick.AddListener(() => {
            int missingHealth = healthSystem.GetHealthAmountMax() - healthSystem.GetHealthAmount();
            int repairCost    = missingHealth / 4;

            ResourceAmount[] resourceAmountCost = new ResourceAmount[] {
                new ResourceAmount {
                    resourceType = goldResourceType, amount = repairCost
                }
            };

            if (ResourceManager.Instance.CanAfford(resourceAmountCost))
            {
                // Congrats for the Repair
                ResourceManager.Instance.SpendResouces(resourceAmountCost);
                healthSystem.HealFull();
            }
            else
            {
                // You are f****d dude...
                TooltipUI.Insntace.Show("You are short on cash... Too Bad!", new TooltipUI.TooltipTimer {
                    timer = 3f
                });
            }
        });
    }
예제 #5
0
    public bool CanBuild()
    {
        bool hasEnoughResources = false;
        List <ResourceAmount> resourceAmounts = new List <ResourceAmount>();

        for (int i = 0; i < resourceCosts.Count; i++)
        {
            ResourceAmount currentAmount = Resource.Instance.GetResourceAmount(resourceCosts[i].resourceType);
            ResourceAmount cost          = resourceCosts[i];
            if (currentAmount.resourceAmount >= cost.resourceAmount)
            {
                resourceAmounts.Add(currentAmount);
            }
        }
        if (resourceAmounts.Count >= resourceCosts.Count)
        {
            hasEnoughResources = true;
            // resourceAmounts has the same order as resourceCosts
            for (int i = 0; i < resourceCosts.Count; i++)
            {
                resourceAmounts[i].resourceAmount -= resourceCosts[i].resourceAmount;
            }
            buildingState = BuildingState.Building;
            GameEvents.BuildingStarted(this);
            GameEvents.OnTimePassed += CheckBuildingTime;
        }
        return(hasEnoughResources);
    }
예제 #6
0
        private void MoveRandomValue(IEnumerable <ResourceAmount> source, List <ResourceAmount> destination,
                                     ITradeEntity trader)
        {
            foreach (var amount in source)
            {
                Resource r = ResourceLibrary.GetResourceByName(amount.ResourceType);
                if (trader.TraderRace.HatedResources.Any(tag => r.Tags.Contains(tag)))
                {
                    continue;
                }
                if (amount.NumResources == 0)
                {
                    continue;
                }
                ResourceAmount destAmount =
                    destination.FirstOrDefault(resource => resource.ResourceType == amount.ResourceType);
                if (destAmount == null)
                {
                    destAmount = new ResourceAmount(amount.ResourceType, 0);
                    destination.Add(destAmount);
                }

                int numToMove = MathFunctions.RandInt(1, amount.NumResources + 1);
                amount.NumResources     -= numToMove;
                destAmount.NumResources += numToMove;
                break;
            }
        }
예제 #7
0
    public bool CanTrain(int amountToTrain)
    {
        bool hasEnoughResources = false;
        List <ResourceAmount> resourceAmounts = new List <ResourceAmount>();

        for (int i = 0; i < resourceCosts.Count; i++)
        {
            ResourceAmount currentAmount = Resource.Instance.GetResourceAmount(resourceCosts[i].resourceType);
            ResourceAmount cost          = resourceCosts[i];
            if (currentAmount.resourceAmount >= (cost.resourceAmount * amountToTrain))
            {
                resourceAmounts.Add(currentAmount);
            }
        }
        if (resourceAmounts.Count >= resourceCosts.Count)
        {
            hasEnoughResources = true;
            // resourceAmounts has the same order as resourceCosts
            for (int i = 0; i < resourceCosts.Count; i++)
            {
                resourceAmounts[i].resourceAmount -= (resourceCosts[i].resourceAmount * amountToTrain);
            }
            availabilityState = Troop.AvailabilityState.Training;
            GameEvents.TrainingStarted(this);
            GameEvents.OnTimePassed += CheckTrainingTime;
        }
        return(hasEnoughResources);
    }
예제 #8
0
        public void RemoveInput(ResourceAmount input)
        {
            foreach (var item in Units)
            {
                try
                {
                    var converterUnit = item as ConverterUnit;
                    converterUnit.RemoveInput(input);
                    break;//sikerült elvenni valamelyik unit-tól ezt az input-ot
                }
                catch (Exception ex)
                {
                    if (ex.Message == "Too many input remove from converter!")
                    {
                        if (item == Units.Last())
                        {
                            throw ex; //nem sikerült elvenni az input-ot és ez volt az utolsó unit az épületnél
                        }
                        continue;     //nem sikerült elvenni az input-ot, nézzük a következő unit-ot
                    }

                    if (ex.Message == "Invalid input for converter!")
                    {
                        throw ex;
                    }
                }
            }
        }
예제 #9
0
    public bool StartResearching()
    {
        bool hasEnoughResources = false;
        List <ResourceAmount> resourceAmounts = new List <ResourceAmount>();

        for (int i = 0; i < resourceCosts.Count; i++)
        {
            ResourceAmount currentAmount = Resource.Instance.GetResourceAmount(resourceCosts[i].resourceType);
            ResourceAmount cost          = resourceCosts[i];
            if (currentAmount.resourceAmount >= cost.resourceAmount)
            {
                resourceAmounts.Add(currentAmount);
            }
        }
        if (resourceAmounts.Count >= resourceCosts.Count)
        {
            hasEnoughResources = true;
            // resourceAmounts has the same order as resourceCosts
            for (int i = 0; i < resourceCosts.Count; i++)
            {
                resourceAmounts[i].resourceAmount -= resourceCosts[i].resourceAmount;
            }
            availabilityState = AvailabilityState.Researching;
            GameEvents.TechResearchStarted(this);
            //GameEvents.OnTurnPassed += NewTurn;
            GameEvents.OnTimePassed += CheckTime;
        }
        return(hasEnoughResources);
    }
예제 #10
0
    public void UpdateResourceAmountText(ResourceAmount rAmount)
    {
        TextMeshProUGUI rText = rAmount.resourceType.resourceAmountText;

        rText.text = rAmount.amount.ToString();
        SetResourceValueColor(rAmount);
    }
예제 #11
0
        private Widget CreateLineItem(ResourceAmount Resource)
        {
            var r = Root.ConstructWidget(new Gum.Widget
            {
                MinimumSize = new Point(1, 32),
                MaximumSize = new Point(1, 32)
            });

            var resourceInfo = ResourceLibrary.GetResourceByName(Resource.ResourceType);

            r.AddChild(new Gum.Widget
            {
                MinimumSize     = new Point(32, 32),
                MaximumSize     = new Point(32, 32),
                Background      = new TileReference("resources", resourceInfo.NewGuiSprite),
                AutoLayout      = AutoLayout.DockLeft,
                BackgroundColor = resourceInfo.Tint.ToVector4()
            });

            r.AddChild(new Gum.Widget
            {
                AutoLayout = AutoLayout.DockFill,
                //Text = String.Format("{0} at ${1}e", Resource.NumResources, resourceInfo.MoneyValue),
                //Font = "outline-font",
                //TextColor = new Vector4(1,1,1,1),
                TextVerticalAlign = VerticalAlign.Center
            });

            UpdateLineItemText(r, Resource);

            return(r);
        }
예제 #12
0
파일: Battle.cs 프로젝트: cnavas88/ES2015A
 public PlayerInformation(Storage.Races race)
 {
     _race     = race;
     buildings = new List <PlayableEntity>();
     units     = new List <PlayableEntity>();
     resources = new ResourceAmount();
 }
예제 #13
0
    private void Awake()
    {
        transform.Find("button").GetComponent <Button>().onClick.AddListener(() => {
            int missingHealth = healthSystem.GetHealthAmountMax() - healthSystem.GetHealthAmount();
            int repairCost    = missingHealth / 2;

            ResourceAmount[] resourceAmountCost = new ResourceAmount[] {
                new ResourceAmount {
                    resourcetype = goldResourceType, amount = repairCost
                }
            };

            if (ResourceManager.Instance.CanAfford(resourceAmountCost))
            {
                // Can afford the repairs
                ResourceManager.Instance.SpendResources(resourceAmountCost);
                healthSystem.HealFull();
            }
            else
            {
                // Cannot afford repairs
                TooltipUI.Instance.Show("Cannot afford repair cost!", new TooltipUI.TooltipTimer {
                    timer = 2f
                });
            }
        });
    }
예제 #14
0
        private void UpdateLineItemText(Widget LineItem, ResourceAmount Resource)
        {
            var resourceInfo = ResourceLibrary.GetResourceByName(Resource.ResourceType);

            LineItem.GetChild(1).Text = resourceInfo.ShortName ?? resourceInfo.ResourceName;
            LineItem.GetChild(1).Invalidate();
            LineItem.GetChild(2).Text = String.Format("{0}",
                                                      ValueSourceEntity.ComputeValue(Resource.ResourceType));
            var counter = LineItem.GetChild(0).Children.Last();

            counter.Text = Resource.NumResources.ToString();
            counter.Invalidate();
            LineItem.GetChild(0).Invalidate();
            LineItem.Tooltip = resourceInfo.ResourceName + "\n" + resourceInfo.Description;
            for (int i = 0; i < 3; i++)
            {
                if (i > 0)
                {
                    LineItem.GetChild(i).TextColor = Resource.NumResources > 0
                        ? Color.Black.ToVector4()
                        : new Vector4(0.5f, 0.5f, 0.5f, 0.5f);
                }
                LineItem.GetChild(i).BackgroundColor = Resource.NumResources > 0
                    ? resourceInfo.Tint.ToVector4()
                    : new Vector4(0.5f, 0.5f, 0.5f, 0.5f);
                LineItem.GetChild(i).Tooltip = resourceInfo.ResourceName + "\n" + resourceInfo.Description;
                LineItem.GetChild(i).Invalidate();
            }
        }
예제 #15
0
 // Set starting resource amounts
 public void InitializeResourceAmounts()
 {
     foreach (ResourceType rType in availableResources)
     {
         ResourceAmount newResourceAmount = new ResourceAmount(rType, rType.startAmount);
         currentResourceAmounts.Add(newResourceAmount);
     }
 }
예제 #16
0
파일: TownHall.cs 프로젝트: Glecun/automata
    public void depositResource(ResourceAmount resourceAmount)
    {
        var currentResourceAmount = resourceStorage.get(resourceAmount.resourceEnum);

        currentResourceAmount.amount += resourceAmount.amount;
        resourceStorage.set(currentResourceAmount);
        InfoPopupController.Create(infoPopupPrefab, Utils.getTopPosition(transform, HEIGHT, 0.2f),
                                   "+" + resourceAmount.amount);
    }
예제 #17
0
 public SkillPartInfo(String name, String description, String description2, String description3, ResourceAmount cost)
 {
     this.Id           = GetNextId();
     this.Name         = name;
     this.Description  = description;
     this.Description2 = description2;
     this.Description3 = description3;
     this.Cost         = cost;
 }
        public void AddInput(ResourceAmount input)
        {
            foreach (var item in Units)
            {
                if (item is ConverterUnit)
                {
                    try
                    {
                        var converterUnit = item as ConverterUnit;
                        converterUnit.AddInput(input);
                        break;//sikerült hozzáadni valamelyik unit inputjai-hoz
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message == "Too many input for converter!")
                        {
                            if (item == Units.Last())
                            {
                                throw ex; //nem sikerült hozzáadni az input-ot és ez volt az utolsó unit az épületnél
                            }
                            continue;     //nem sikerült hozzáadni az input-ot, nézzük a következő unit-ot
                        }

                        if (ex.Message == "Invalid input for converter!")
                        {
                            throw ex;
                        }
                    }
                }
                else if (item is ProducerAndConverterUnit)
                {
                    try
                    {
                        var producerAndConverterUnit = item as ProducerAndConverterUnit;
                        producerAndConverterUnit.AddInput(input);
                        break;//sikerült hozzáadni valamelyik unit inputjai-hoz
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message == "Too many input for converter!")
                        {
                            if (item == Units.Last())
                            {
                                throw ex; //nem sikerült hozzáadni az input-ot és ez volt az utolsó unit az épületnél
                            }
                            continue;     //nem sikerült hozzáadni az input-ot, nézzük a következő unit-ot
                        }

                        if (ex.Message == "Invalid input for converter!")
                        {
                            throw ex;
                        }
                    }
                }
            }
        }
예제 #19
0
    public void SetResourceAmount(int resourceId, int amount)
    {
        ResourceAmount rAmount = GetCurrentResourceAmountByID(resourceId);

        if (rAmount != null)
        {
            rAmount.amount = amount;
            UpdateResourceAmountText(rAmount);
        }
    }
예제 #20
0
 public void UpgradeProducerAmount(ResourceAmount resourceAmount)
 {
     foreach (var item in Products)
     {
         if (item.Type == resourceAmount.Type)
         {
             item.Amount += resourceAmount.Amount;
         }
     }
 }
예제 #21
0
        private Widget CreateLineItem(ResourceAmount Resource)
        {
            var r = Root.ConstructWidget(new Gui.Widget
            {
                MinimumSize = new Point(1, 32),
                Background  = new TileReference("basic", 0)
            });

            var resourceInfo = Library.GetResourceType(Resource.Type);

            var icon = r.AddChild(new ResourceIcon()
            {
                MinimumSize         = new Point(32 + 16, 32 + 16),
                MaximumSize         = new Point(32 + 16, 32 + 16),
                Layers              = resourceInfo.GuiLayers,
                AutoLayout          = AutoLayout.DockLeft,
                BackgroundColor     = Resource.Count > 0 ? resourceInfo.Tint.ToVector4() : new Vector4(0.5f, 0.5f, 0.5f, 0.5f),
                TextColor           = Color.White.ToVector4(),
                TextHorizontalAlign = HorizontalAlign.Right,
                TextVerticalAlign   = VerticalAlign.Bottom
            });

            r.AddChild(new Gui.Widget
            {
                AutoLayout          = AutoLayout.DockLeft,
                MinimumSize         = new Point(128 / GameSettings.Default.GuiScale, 0),
                MaximumSize         = new Point(128 / GameSettings.Default.GuiScale, 32),
                TextColor           = Resource.Count > 0 ? Color.Black.ToVector4() : new Vector4(0.5f, 0.5f, 0.5f, 0.5f),
                TextVerticalAlign   = VerticalAlign.Center,
                TextHorizontalAlign = HorizontalAlign.Left,
                HoverTextColor      = GameSettings.Default.Colors.GetColor("Highlight", Color.DarkRed).ToVector4(),
                Font = GameSettings.Default.GuiScale == 1 ? "font10" : "font8",
                ChangeColorOnHover = true,
                WrapText           = true
            });

            r.AddChild(new Gui.Widget
            {
                AutoLayout = AutoLayout.DockRight,
                //Text = String.Format("{0} at ${1}e", Resource.NumResources, resourceInfo.MoneyValue),
                //Font = "font18-outline",
                //TextColor = new Vector4(1,1,1,1),
                TextColor         = Resource.Count > 0 ? Color.Black.ToVector4() : new Vector4(0.5f, 0.5f, 0.5f, 0.5f),
                TextVerticalAlign = VerticalAlign.Center,
                HoverTextColor    = GameSettings.Default.Colors.GetColor("Highlight", Color.DarkRed).ToVector4(),
                Font = GameSettings.Default.GuiScale == 1 ? "font10" : "font8",
                ChangeColorOnHover = true,
            });


            r.Layout();
            UpdateLineItemText(r, Resource);

            return(r);
        }
예제 #22
0
    private void Awake()
    {
        spriteRenderer        = GetComponent <SpriteRenderer>();
        spriteRenderer.sprite = initialSprite;

        _currentTreeState = TreeStateEnum.FULL;

        countdown = gameObject.AddComponent <Countdown>();

        resourceAmount = new ResourceAmount(10, ResourceEnum.FOOD);
    }
예제 #23
0
 // Returns all ResourceDepots which are owned by the given player and have some amount of the given resource stored
 public static List<ResourceDepot> FindAllDepotsWithResource(Resource resource, Player player)
 {
     ResourceAmount resourceAsAmount = new ResourceAmount(resource, 0);
     List<ResourceDepot> allDepots = new List<ResourceDepot>();
     foreach(ResourceDepot resourceDepot in GameUtil.FindAllOwnedInstancesOf<ResourceDepot>(player)) {
         if(resourceDepot.storableResources.Contains(resourceAsAmount) && resourceDepot.StoredResources[resource] > 0) {
             allDepots.Add(resourceDepot);
         }
     }
     return allDepots;
 }
예제 #24
0
 public void SetResourceValueColor(ResourceAmount rAmount)
 {
     if ((rAmount.amount * (1 + maxResourcesMargin) > rAmount.resourceType.maxAmount))
     {
         rAmount.resourceType.resourceAmountText.color = maxResourceAmountReachedColor;
     }
     else
     {
         rAmount.resourceType.resourceAmountText.color = maxResourceAmountNotReachedColor;
     }
 }
예제 #25
0
        /// <summary>
        /// 槍兵を生産します。
        /// </summary>
        public TrainSpearmanLine(short count)
            : base(unit.spearman_line, count)
        {
            Conditions unitCondition = new players_unit_type_count(
                player_number.any_enemy, unit.knight_line, relop.ge, 10);

            Conditions costCondition = new ResourceAmount(building.house, building.lumber_camp)
                                       & new ResourceAmount(unit.villager);

            Facts.Add(unitCondition, costCondition);
        }
예제 #26
0
 public virtual void AddInput(ResourceAmount input)
 {
     if (!CurrentInput.Any(i => i.Type == input.Type))
     {
         throw new Exception("Invalid input for converter!");
     }
     if (CurrentInput.Any(i => i.Amount + input.Amount > MaxInput))
     {
         throw new Exception("Too many input for converter!");
     }
     CurrentInput.Where(i => i.Type == input.Type).Single().Amount += input.Amount;
 }
예제 #27
0
    public static ResourceAmount operator +(ResourceAmount a, ResourceAmount b)
    {
        ResourceAmount result = new ResourceAmount
        {
            materials = a.materials + b.materials,
            gems      = a.gems + b.gems,
            gold      = a.gold + b.gold,
            energy    = a.energy + b.energy
        };

        return(result);
    }
예제 #28
0
 /// <summary>
 /// Try to subtract a resource amount from the player's resources. Will return false if insufficient funds.
 /// </summary>
 /// <param name="cost">The amount to subtract.</param>
 /// <returns></returns>
 public bool Pay(ResourceAmount cost)
 {
     if (CanAfford(cost))
     {
         this.playerResources -= cost;
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #29
0
 public virtual void RemoveInput(ResourceAmount input)
 {
     if (CurrentInput.SingleOrDefault(i => i.Type == input.Type) == null)
     {
         throw new Exception("Invalid input remove from converter!");
     }
     if (CurrentInput.Any(i => i.Type == input.Type && i.Amount - input.Amount < 0))
     {
         throw new Exception("Too many input remove from converter!");
     }
     CurrentInput.Where(i => i.Type == input.Type).Single().Amount -= input.Amount;
 }
예제 #30
0
    public ResourceAmount GetCurrentResourceAmountByID(int rID)
    {
        ResourceAmount rAmount = null;

        foreach (var resourceAmount in currentResourceAmounts)
        {
            if (resourceAmount.resourceType.id.Equals(rID))
            {
                rAmount = resourceAmount;
            }
        }
        return(rAmount);
    }
예제 #31
0
        public bool ConsumedFood(ResourceAmount resource)
        {
            if (resource == null)
            {
                return(false);
            }
            if (resource.Amount >= FoodNeeded)
            {
                return(false);
            }

            return(true);
        }
예제 #32
0
 // Returns the nearest ResourceDepot to the given point which is owned by the given player and has some amount of the given resource stored
 public static ResourceDepot FindNearestDepotWithResource(Resource resource, Player player, Vector3 point)
 {
     ResourceAmount resourceAsAmount = new ResourceAmount(resource, 0);
     float minDist = Mathf.Infinity;
     ResourceDepot minDepot = null;
     foreach(ResourceDepot resourceDepot in GameUtil.FindAllOwnedInstancesOf<ResourceDepot>(player)) {
         if(resourceDepot.storableResources.Contains(resourceAsAmount) && resourceDepot.StoredResources[resource] > 0) {
             float dist = Vector3.Distance(point, resourceDepot.transform.position);
             if(dist < minDist) {
                 minDist = dist;
                 minDepot = resourceDepot;
             }
         }
     }
     return minDepot;
 }
예제 #33
0
 // Holds the given amount of the given resource. The hold is only successful if the same or no resource is already held
 public void HoldResource(Resource resource, int amount)
 {
     if(HeldResource != null && HeldResource.resource != resource) {
         Debug.LogError("Trying to hold resource "+resource+" while already holding "+HeldResource.resource);
     }
     if(HeldResource == null && amount > 0) {
         HeldResource = new ResourceAmount(resource, amount);
     } else if(HeldResource.resource == resource) {
         HeldResource.amount += amount;
     }
     if(HeldResource.amount > heldResourceLimit) {
         Debug.LogError("Held resource amount is greater than limit. "+HeldResource.resource+" is "+HeldResource.amount+" over "+heldResourceLimit);
     }
 }
예제 #34
0
파일: Battle.cs 프로젝트: srferran/ES2015A
 public Battle ()
 {
     players = new List<PlayerInformation>();
     worldResources = new ResourceAmount();
     missions = new List<MissionDefinition>();
 }
예제 #35
0
파일: Battle.cs 프로젝트: srferran/ES2015A
 public PlayerInformation(Storage.Races race)
 {
     _race = race;
     buildings = new List<PlayableEntity>();
     units = new List<PlayableEntity>();
     resources = new ResourceAmount();
 }