Пример #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
 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
    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
 public Battle ()
 {
     players = new List<PlayerInformation>();
     worldResources = new ResourceAmount();
     missions = new List<MissionDefinition>();
 }
Пример #35
0
 public PlayerInformation(Storage.Races race)
 {
     _race = race;
     buildings = new List<PlayableEntity>();
     units = new List<PlayableEntity>();
     resources = new ResourceAmount();
 }