Ejemplo n.º 1
0
 private BigInteger CalculateFinalyValue(Resource.Type type, ulong value)
 {
     _tempBigInt = BigInteger.Pow(value, SpaceshipsLevelling.Instance.CurrentLevel);
     _tempInt    = Convert.ToInt32(_resourceRarity.GetResourceRare(type) * 100);
     _tempBigInt = (_tempBigInt * _tempInt) / 100;
     return(_tempBigInt);
 }
Ejemplo n.º 2
0
 public PlanetResource(Resource.Type type, float max, float current, float replenPeriod)
 {
     this.type                = type;
     this.max                 = max;
     this.current             = current;
     this.secondsToNextReplen = this.replenPeriod = replenPeriod;
 }
    //Adds random resources to the geography.
    private static void AddRandomResourcesToGeography(Geography geography)
    {
        List <ResourceDeposit> resourceDepositsToAdd = new List <ResourceDeposit>();

        if (geography.GetBiome() == Geography.Biome.water) //If the biome is a water biome, there is a 50% chance of adding a sea animals deposit.
        {
            int spawnChance = 49;                          //There will be a 50% chance of spawning. 0-49, 50-99.
            if (spawnChance > Random.Range(0, 100))
            {
                int yield = Random.Range(1, 3); //Creates a yield of either 1 or 2.
                resourceDepositsToAdd.Add(new ResourceDeposit(Resource.Type.SeaAnimals, yield));
                geography.AddResourceDeposits(resourceDepositsToAdd);
            }
        }
        else //Spawns any type of resource on any other tile.
        {
            int spawnChance = 60; //60% chance of spwaning any natural resource except sea animals
            for (int i = 0; i < 3; i++) //There can be up to three different bonus resources added to a tile.
            {
                if (spawnChance > Random.Range(0, 100))
                {
                    Resource.Type resourceType = (Resource.Type)Random.Range(0, 9); //Sea animals are in position 9 so it cannot be chosen. Random.range(0,x) returns numbers from 0 to x-1.
                    int           yield        = Random.Range(1, 3);                //The yield will either be one or two.
                    resourceDepositsToAdd.Add(new ResourceDeposit(resourceType, yield));
                    spawnChance /= 2;                                               //The spawn chance of another deposit is cut in half.
                }
            }
            if (resourceDepositsToAdd.Count > 0) //If there are any bonus resources to add to a tile, call the add resource deposits function.
            {
                geography.AddResourceDeposits(resourceDepositsToAdd);
            }
        }
    }
Ejemplo n.º 4
0
    Image MakeResource(Resource.Type resourceType)
    {
        GameObject resource;

        switch (resourceType)
        {
        default:
        case Resource.Type.KettlerFactory:
        {
            resource = Instantiate(kettlerResource) as GameObject;
            kettlerFactories.Add(resource);
            break;
        }

        case Resource.Type.Potato: resource = Instantiate(potatoResource) as GameObject; break;

        case Resource.Type.SunflowerOil: resource = Instantiate(sunflowerResource) as GameObject; break;

        case Resource.Type.Salt: resource = Instantiate(saltResource) as GameObject; break;

        case Resource.Type.Onion: resource = Instantiate(onionResource) as GameObject; break;

        case Resource.Type.Cheese: resource = Instantiate(cheeseResource) as GameObject; break;
        }
        return(resource.GetComponent <Image>());
    }
Ejemplo n.º 5
0
    public bool PurchaseItem(float price, Resource.Type resourceType)
    {
        if (price > currentMoney)
        {
            uiController.DisplayError("Can't buy that, you're too poor!", 3f);
            uiController.CloseCurrentMessageBox();
            return(false);
        }
        if (currentPressedGridButton.GetComponent <GridSpace>().Occupied())
        {
            uiController.DisplayError("There's no room for that here!", 3f);
            uiController.CloseCurrentMessageBox();
            return(false);
        }

        currentMoney -= price;
        resources.Add(MakeResource(resourceType));
        resources[resources.Count - 1].name = GetResourceName(resourceType);
        resources[resources.Count - 1].transform.SetParent(currentPressedGridButton.transform);
        resources[resources.Count - 1].rectTransform.position = Vector3.zero;
        ResetBuildingPosition.ResetRectTransform(resources[resources.Count - 1].GetComponent <RectTransform>());
        uiController.CloseCurrentMessageBox();

        return(true);
    }
Ejemplo n.º 6
0
        public AIStateCraftTool(Game game, Player player, Resource.Type tool)
            : base(AI.State.CraftTool)
        {
            this.tool = tool;

            previousCount = (tool == Resource.Type.None) ? 0 : GetCurrentToolCount(game, player);
        }
Ejemplo n.º 7
0
    void MakeChips(Resource.Type input1, Resource.Type input2, Resource.Type input3 = Resource.Type.Empty,
                   Resource.Type input4 = Resource.Type.Empty, Resource.Type input5 = Resource.Type.Empty)
    {
        List <Resource.Type> inputs = new List <Resource.Type>();

        inputs.Add(input1);
        inputs.Add(input2);
        if (input3 != Resource.Type.Empty)
        {
            inputs.Add(input3);
        }
        if (input4 != Resource.Type.Empty)
        {
            inputs.Add(input4);
        }
        if (input5 != Resource.Type.Empty)
        {
            inputs.Add(input5);
        }

        if (CanMakeChips(inputs))
        {
            GameController.controller.DisplayError("Chips++", 3f, false);
            GameController.controller.TotalChipCount = 1;
            GameController.controller.chipProduction.MakeChips(inputs);
            TakeResources(inputs);
        }
        else
        {
            GameController.controller.DisplayError("You can't afford chips!", 3f, false);
        }
    }
Ejemplo n.º 8
0
 public static bool GrupsGlobally(Resource.Type resourceType)
 {
     return((new bool[]
     {
         default(bool),
         default(bool),
         true
     })[(int)resourceType]);
 }
Ejemplo n.º 9
0
        protected override void ReadFrom(Game game, AI ai, string name, SaveReaderText reader)
        {
            base.ReadFrom(game, ai, name, reader);

            tool = reader.Value($"{name}.tool").ReadResource();
            triesBuildToolmaker = reader.Value($"{name}.tries_build_toolmaker").ReadInt();
            tries         = reader.Value($"{name}.tries").ReadInt();
            previousCount = reader.Value($"{name}.previous_count").ReadInt();
        }
Ejemplo n.º 10
0
 public static string GetResourceUnit(Resource.Type resourceType)
 {
     return((new string[]
     {
         "t",
         "t",
         string.Empty
     })[(int)resourceType]);
 }
Ejemplo n.º 11
0
 public Resource.Type[] AllowedTypes()
 {
     Resource.Type[] types = new Resource.Type[stores.Length];
     for (int i = 0; i < types.Length; i++)
     {
         types[i] = stores[i].type;
     }
     return(types);
 }
Ejemplo n.º 12
0
 public static string GetResourceName(Resource.Type resourceType)
 {
     return((new string[]
     {
         "Fuel",
         "Solid Fuel",
         "Electric Power"
     })[(int)resourceType]);
 }
Ejemplo n.º 13
0
    public int AddResourceFrom(Resource.Type type, int value, ref ResourceStorage other)
    {
        if (other.CanStore(type))
        {
            stores[StoreIndexOf(type)].currAmount += value;
            return(-value);
        }

        return(0);
    }
Ejemplo n.º 14
0
        public void SendCargo(IPirate pirate, Resource.Type resourceType)
        {
            var tempCargo = _cargoGenerator.GenerateCargo(resourceType,
                                                          _minGeneratedResource,
                                                          _maxGeneratedResource,
                                                          MultiplierCalculator.CalculateGeneratedResourceMultiplier(_factoryLevel.GetLevel()));

            pirate.StealCargo(tempCargo);
            IsRobbed = true;
        }
Ejemplo n.º 15
0
    public bool CanStore(Resource.Type type)
    {
        int index = StoreIndexOf(type);

        if (index == -1)
        {
            return(false);
        }
        return(stores[index].currAmount < stores[index].maxAmount);
    }
Ejemplo n.º 16
0
 public float GatherFactor(Resource.Type type)
 {
     if (_gatherFactor.ContainsKey(type))
     {
         return(_gatherFactor [type]);
     }
     else
     {
         return(-1);
     }
 }
Ejemplo n.º 17
0
 private int StoreIndexOf(Resource.Type type)
 {
     for (int i = 0; i < stores.Length; i++)
     {
         if (stores[i].type == type)
         {
             return(i);
         }
     }
     return(-1);
 }
Ejemplo n.º 18
0
 public int GetResourceAmount(Resource.Type type)
 {
     foreach (var res in this.Resources)
     {
         if (res.type == type)
         {
             return(res.amount);
         }
     }
     return(0);
 }
Ejemplo n.º 19
0
 public float GetResourceRare(Resource.Type type)
 {
     for (int i = 0; i < _resourceInfo.Length; i++)
     {
         if (_resourceInfo[i].GetResourceType() == type)
         {
             return(_resourceInfo[i].GetRare());
         }
     }
     return(0f);
 }
Ejemplo n.º 20
0
 public void Add(Resource.Type type, int amount)
 {
     foreach (var res in this.Resources)
     {
         if (res.type == type)
         {
             res.amount += amount;
             break;
         }
     }
 }
Ejemplo n.º 21
0
 public BigInteger GetResourceValue(Resource.Type type)
 {
     try
     {
         return(_resources[type]);
     }
     catch
     {
         throw new Exception($"ResourceType {nameof(type)} don`t found.");
     }
 }
Ejemplo n.º 22
0
    //Attempts to consume the desired amount of resources. If it can, it will consume those resources and return true. If not, it will return false.
    bool UseStockpiledResource(Resource.Type type, int amount)
    {
        Resource resource = stockpiledResources[(int)type];

        if (resource.GetYield() >= amount)
        {
            resource.DecreaseYield(amount);
            return(true);
        }
        return(false);
    }
Ejemplo n.º 23
0
    public ResourceDeposit(Resource.Type _type, int _size)
    {
        type = _type;
        size = _size;
        int highYieldNumber = Random.Range(0, 100);

        if (highYieldNumber < 10)
        {
            highYield = true;
            yield    += 20;
        }
    }
Ejemplo n.º 24
0
        public ulong GetMaxCost(Resource.Type type)
        {
            for (int i = 0; i < _resourceInfo.Count; i++)
            {
                if (_resourceInfo[i].GetResourceType() == type)
                {
                    return(_resourceInfo[i].GetMaxCost());
                }
            }

            throw new Exception("Ошибка. Не найден тип ресурса, либо стоимость.");
        }
Ejemplo n.º 25
0
    public string resourceName(Resource.Type t)
    {
        switch (t)
        {
        case Resource.Type.WOOD: return("Wood");

        case Resource.Type.ORE: return("Ore");

        case Resource.Type.OIL: return("Oil");
        }
        return("");
    }
Ejemplo n.º 26
0
    public Storage(Resource.Type t)
    {
        switch (t)
        {
        case Resource.Type.OIL: nameof = "refinery"; break;

        case Resource.Type.ORE: nameof = "foundry"; break;

        case Resource.Type.WOOD: nameof = "sawmill"; break;
        }
        type = t;
        anim = Animation.IDLE;
    }
Ejemplo n.º 27
0
 public int Take(Resource.Type type, int amount)
 {
     foreach (var res in this.Resources)
     {
         if (res.type == type)
         {
             var taken = Mathf.Min(amount, res.amount);
             res.amount -= taken;
             return(taken);
         }
     }
     return(0);
 }
Ejemplo n.º 28
0
        public BigInteger GetResourceToTrade(Resource.Type type, BigInteger value)
        {
            BigInteger returnValue = 0;

            if (value <= _resources[type])
            {
                returnValue       = value;
                _resources[type] -= returnValue;
                ResourceChange?.Invoke();
                ResourceSalesAccount.AddSoldValue(type, value);
                ResourceSalesAccount.AddAllResourceSoldValue(value);
            }
            return(returnValue);
        }
Ejemplo n.º 29
0
    //Iterates through the resource deposits in the tile and returns the number of building resources (wood and stone).
    int YieldOfBuildingResource(Tile tile)
    {
        int yield = 0;

        foreach (ResourceDeposit deposit in tile.GetResourceDeposits())
        {
            Resource.Type type = deposit.GetDepositType();
            if (type == Resource.Type.Wood || type == Resource.Type.Stone)
            {
                yield += deposit.GetDepositSize();
            }
        }
        return(yield);
    }
Ejemplo n.º 30
0
    //Iterates through the resource deposits in the tile and returns the number of food resources (animals, grains, vegetables, and fruit).
    int YieldOfFoodResource(Tile tile)
    {
        int yield = 0;

        foreach (ResourceDeposit deposit in tile.GetResourceDeposits())
        {
            Resource.Type type = deposit.GetDepositType();
            if (type == Resource.Type.Animals || type == Resource.Type.Grains || type == Resource.Type.Vegetables || type == Resource.Type.Fruit)
            {
                yield += deposit.GetDepositSize();
            }
        }
        return(yield);
    }